20char get_DBP_scan_mode(
unsigned char hd[8][4])
23 return (hd [0][1]>>1 & 0x03);
28float get_DBP_rot_vel(
unsigned char hd[8][4])
33 return ( ( ((hd[0][1]>>3)&0x1f) + ((hd[2][2]>>6)&0x03)*0.1 ));
39char get_DBP_pulse_lenght(
unsigned char hd[8][4])
42 return (hd [0][3]>>6 & 0x03);
47float get_DBP_el_min(
unsigned char hd[8][4])
52 return ( ( hd[1][1] | ((hd[1][2] &0x0f) <<8) ) *(360./4096.) );
57float get_DBP_el_max(
unsigned char hd[8][4])
62 return ( ( hd[2][1] | ((hd[2][2] &0x0f) <<8) ) *(360./4096.) );
67float get_DBP_az_min(
unsigned char hd[8][4])
72 return ( ( hd[4][1] | ((hd[4][2] &0x0f) <<8) ) *(360./4096.) );
77float get_DBP_az_max(
unsigned char hd[8][4])
82 return ( (hd[5][1] | ( (hd[5][2] &0x0f) <<8)) *(360./4096.) );
87short get_DBP_pulse_number(
unsigned char hd[8][4])
90 return ( (
short)( ((hd[4][2]>>4) & 0x0f) | ((hd[4][3] &0x1f) <<4) ));
95void get_DBP_flag_quantities (
unsigned char hd[8][4],
char *flag_quantities)
99 flag_quantities[0] = hd[1][3] & 0x01;
101 flag_quantities[1] = hd[1][3]>>1 & 0x01;
103 flag_quantities[2] = hd[1][3]>>2 & 0x01;
105 flag_quantities[3] = hd[1][3]>>3 & 0x01;
114char get_DBP_cell_size (
unsigned char hd[8][4])
117 return ( (hd[1][3]>>4) & 0x07);
123char get_DBP_Dual_PRF (
unsigned char hd[8][4])
126 return ( (hd[1][3]>>7) & 0x01);
132char get_DBP_tipo_filtro(
unsigned char hd[8][4])
135 return ( (
char) ((hd[2][3]>>4)&0x0f) );
139char get_DBP_corr_clutter (
unsigned char hd[8][4])
142 return ( (
char) ((hd[2][3]>>2)&0x01) );
146char get_DBP_filtro_clutter (
unsigned char hd[8][4])
149 return ( (
char) ((hd[2][3]>>3)&0x01) );
153char get_DBP_anticlutter_mappato (
unsigned char hd[8][4])
156 return ( (
char) ((hd[2][3])>>1 &0x01) );
161char get_DBP_Z_range (
unsigned char hd[8][4])
164 return ( (
char) (hd[3][2]>>6)&0x03 );
169char get_DBP_calibration_factor (
unsigned char hd[8][4])
172 return( (
char) (hd[3][3]&0x0f) + (((hd[3][3]>>4)&0x0f)*10) );
178char get_DBP_stalo_code (
unsigned char hd[8][4])
183 return ( hd[7][3] & 0x07 );
192void decode_header_DBP_SP20 (HD_DBP_SP20_RAW *hd_raw, HD_DBP_SP20_DECOD *hd_decod)
198 hd_decod->scan_mode = get_DBP_scan_mode(hd_raw->frame);
199 hd_decod->rot_vel = get_DBP_rot_vel(hd_raw->frame);
200 hd_decod->pulse_lenght = get_DBP_pulse_lenght(hd_raw->frame);
201 hd_decod->el_min = get_DBP_el_min(hd_raw->frame);
202 hd_decod->el_max = get_DBP_el_max(hd_raw->frame);
203 hd_decod->az_min = get_DBP_az_min(hd_raw->frame);
204 hd_decod->az_max = get_DBP_az_max(hd_raw->frame);
206 get_DBP_flag_quantities (hd_raw->frame, hd_decod->flag_quantities);
208 hd_decod->cell_size = get_DBP_cell_size(hd_raw->frame);
209 hd_decod->Dual_PRF = get_DBP_Dual_PRF(hd_raw->frame);
210 hd_decod->filtro_clutter = get_DBP_filtro_clutter(hd_raw->frame);
211 hd_decod->tipo_filtro = get_DBP_tipo_filtro(hd_raw->frame);
212 hd_decod->anticlutter_mappato = get_DBP_anticlutter_mappato(hd_raw->frame);
213 hd_decod->corr_clutter = get_DBP_corr_clutter(hd_raw->frame);
214 hd_decod->Z_range = get_DBP_Z_range(hd_raw->frame);
215 hd_decod->calibration_factor = get_DBP_calibration_factor(hd_raw->frame);
216 hd_decod->pulse_number = get_DBP_pulse_number(hd_raw->frame);
217 hd_decod->stalo_code = get_DBP_stalo_code(hd_raw->frame);
218 if (hd_raw->num_ele >= 41 )
219 hd_decod->num_ele=hd_raw->num_ele-41;
221 hd_decod->num_ele=hd_raw->num_ele;
223 hd_decod->corr_pot=hd_raw->corr_pot;
225 for(i=0; i<hd_decod->num_ele; i++)
226 hd_decod->ele[i]=hd_raw->ele[i]*0.0879;
236void convert_format(HD_DBP_SP20_DECOD *hd_decod, BEAM_HD_SP20_INFO *beam_info, T_MDB_data_header *old_header)
241 old_header->norm.maq.acq_date=beam_info->time;
242 old_header->norm.maq.scans_type=hd_decod->scan_mode;
243 old_header->norm.maq.rot_vel=hd_decod->rot_vel;
244 old_header->norm.maq.imp_duration=hd_decod->pulse_lenght;
246 old_header->norm.maq.grand=0;
249 old_header->norm.maq.grand=old_header->norm.maq.grand +
250 (int)( pow((
double)2,(
double)k) * (int)hd_decod->flag_quantities[k]);
253 old_header->norm.maq.resolution=hd_decod->cell_size;
254 old_header->norm.maq.vel_range=hd_decod->Dual_PRF;
255 old_header->norm.maq.declutter_rsp=hd_decod->filtro_clutter;
259 old_header->norm.maq.filter_value=hd_decod->tipo_filtro;
260 old_header->norm.maq.type_declutter=hd_decod->anticlutter_mappato;
261 old_header->norm.maq.corr_Z=hd_decod->corr_clutter;
262 old_header->norm.maq.spare[1]=hd_decod->Z_range;
263 if(hd_decod->Z_range ==0)
264 old_header->norm.maq.spare[0]=2;
265 if(hd_decod->Z_range ==1)
266 old_header->norm.maq.spare[0]=1;
267 if(hd_decod->Z_range ==2)
268 old_header->norm.maq.spare[0]=3;
270 old_header->norm.maq.num_imp=hd_decod->pulse_number;
271 old_header->norm.maq.num_el=hd_decod->num_ele;
273 for(i=0; i<old_header->norm.maq.num_el ;i++)
274 old_header->norm.maq.value[i]=hd_decod->ele[i]/FATT_MOLT_EL;
280void PrintHeaderDBP(HD_DBP_SP20_DECOD *hd_decod)
285 printf(
"HEADER DBP:\n");
286 printf(
"%2d ",hd_decod->scan_mode);
287 printf(
"%2d ",hd_decod->flag_quantities[0]);
288 printf(
"%1d ",hd_decod->flag_quantities[1]);
289 printf(
"%1d ",hd_decod->flag_quantities[2]);
290 printf(
"%1d ",hd_decod->flag_quantities[3]);
291 printf(
"%2d ",hd_decod->Z_range);
292 printf(
"%2d ",hd_decod->Dual_PRF);
293 printf(
"%2d ",hd_decod->pulse_lenght);
294 printf(
"%2d ",hd_decod->pulse_number);
295 printf(
"%2d\n ",hd_decod->cell_size);
296 printf(
"%9.5f ",hd_decod->az_min);
297 printf(
"%9.5f ",hd_decod->az_max);
298 printf(
"%8.5f ",hd_decod->el_min);
299 printf(
"%8.5f\n ",hd_decod->el_max);
300 printf(
"%5.2f ",hd_decod->rot_vel);
301 printf(
"%2d ",hd_decod->filtro_clutter);
302 printf(
"%2d ",hd_decod->tipo_filtro);
303 printf(
"%2d ",hd_decod->anticlutter_mappato);
304 printf(
"%2d ",hd_decod->corr_clutter);
305 printf(
"%2d ",hd_decod->calibration_factor);
306 printf(
"%3d ",hd_decod->stalo_code);
307 printf(
"%3d ",hd_decod->num_ele);
308 printf(
"%3d\n ",hd_decod->corr_pot);
310 for(i=0;i<hd_decod->num_ele;i++)
311 printf(
"%9.5f ",hd_decod->ele[i]);
320void PrintOldHeader (T_MDB_data_header *old_header)
325 printf(
"OLD HEADER :\n");
326 printf(
"%2d ", old_header->norm.maq.scans_type);
327 printf(
"%2d ", old_header->norm.maq.grand );
328 printf(
"%2d ", old_header->norm.maq.spare[0]);
329 printf(
"%2d ", old_header->norm.maq.vel_range);
330 printf(
"%2d ", old_header->norm.maq.imp_duration);
331 printf(
"%2d ", old_header->norm.maq.num_imp);
332 printf(
"%2d\n ", old_header->norm.maq.resolution);
333 printf(
"%5.2f ", (
double)old_header->norm.maq.rot_vel);
334 printf(
"%2d ", old_header->norm.maq.declutter_rsp);
335 printf(
"%2d ", old_header->norm.maq.filter_value);
336 printf(
"%2d ", old_header->norm.maq.type_declutter);
337 printf(
"%2d ", old_header->norm.maq.corr_Z);
338 printf(
"%2d ", old_header->norm.maq.num_el);
342 for(i=0; i<old_header->norm.maq.num_el; i++)
344 printf(
"%9.5f ", old_header->norm.maq.value[i] * FATT_MOLT_EL);
361short check_flag(
unsigned char hd[])
364 if (hd[0]|hd[1]|hd[2])
370short BCD_decoding(
char byte)
373 unsigned char units,tenths;
375 tenths=(
byte>>4)&0x0f;
376 return ((
short)(tenths*10+units));
380time_t get_date(
unsigned char hd[],
struct tm *tm_date)
383 time_t differenza = 10000;
387 tm_date->tm_year=BCD_decoding(hd[24]);
388 if (tm_date->tm_year < 50)
389 tm_date->tm_year=tm_date->tm_year+100;
391 tm_date->tm_mon=BCD_decoding(hd[23])-1;
392 tm_date->tm_mday=BCD_decoding(hd[22]);
398 tm_date->tm_hour=BCD_decoding(hd[20]);
399 tm_date->tm_min=BCD_decoding(hd[19]);
400 tm_date->tm_sec=BCD_decoding(hd[18]);
406 tm_date->tm_gmtoff=0;
418 differenza = differenza-mktime(gmtime(&differenza));
419 UTC_time= mktime(tm_date)-differenza;
420 tm_date=gmtime(&UTC_time);
429void get_asc_date(
struct tm *tm_date,
char *asc_date)
432 const char *mese[12]={
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
434 const char *weekday[7]={
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"};
436 sprintf(asc_date,
"%s %s %2d %2.2d:%2.2d:%2.2d %4d",weekday[tm_date->tm_wday],
437 mese[tm_date->tm_mon],tm_date->tm_mday,tm_date->tm_hour,
438 tm_date->tm_min,tm_date->tm_sec,tm_date->tm_year+1900);
448char check_data_validity(
unsigned char hd[])
451 if ((hd[12]>>1)&0x01)
457short get_real_power(
unsigned char hd[])
460 return((
short)(hd[15]*4));
464short get_eval_power(
unsigned char hd[])
467 return((
short)(hd[16]*4));
471char get_scan_mode(
unsigned char hd[])
474 switch ((hd[8]>>2)&0x03)
495float get_elevation(
unsigned char hd[])
498 return((
float)((hd[5] |(hd[6] &0x1f)<<8 )*ACF));
504float get_azimuth(
unsigned char hd[])
507 return((
float)((hd[3] |(hd[4] &0x1f)<<8 )*ACF));
512void get_quantities(
unsigned char hd[],
char quantities[5])
515 strcpy(quantities,
"");
517 strcat(quantities,
"Z");
519 strcat(quantities,
"D");
521 strcat(quantities,
"V");
523 strcat(quantities,
"S");
528void get_flag_quantities(
unsigned char hd[],
char flag_quantities[])
532 flag_quantities[0]=hd[9]&0x01;
535 flag_quantities[1]=(hd[9]>>1)&0x01;
538 flag_quantities[2]=(hd[9]>>2)&0x01;
541 flag_quantities[3]=(hd[9]>>7)&0x01;
547int check_dualPRF(
unsigned char hd[])
550 return ((hd[9]>>3)&0x01);
554char get_Z_range(
unsigned char hd[])
574char get_pulse_len(
unsigned char hd[])
594 short get_pulse_num(
unsigned char hd[])
597 return((
short)(hd[13] |(hd[14]>>6 &0x03)<<8 ));
601 char get_cell_size(
unsigned char hd[])
604 return((hd[9]>>4)&0x07);
608 short get_cell_num(
unsigned char hd[])
611 return((
short)(hd[10] |(hd[11]>>6 &0x03)<<8 ));
615 char get_channel(
unsigned char hd[])
618 return((hd[11]>>3)&0x07);
622 void get_controller_identity(
unsigned char hd[],
char controller[4])
625 switch ((hd[8]>>5)&0x03)
628 strcpy(controller,
"LOC");
631 strcpy(controller,
"RM1");
634 strcpy(controller,
"RM2");
637 strcpy(controller,
"ERR");
643char get_filtro_clutter(
unsigned char *hd)
646 return((hd[12]>>7)&0x01);
650char get_tipo_filtro(
unsigned char *hd)
653 return((hd[12]>>2)&0x0f);
657char get_anticlutter_mappato(
unsigned char *hd)
664char get_corr_clutter(
unsigned char *hd)
667 return((hd[12]>>6)&0x01);
672BEAM_HD_SP20_INFO * decode_header_sp20(
unsigned char* hd_char, BEAM_HD_SP20_INFO *beam_info)
678 beam_info->time=get_date(hd_char,&(beam_info->tm_date));
684 memcpy(&(beam_info->tm_date),gmtime(&beam_info->time),
sizeof(beam_info->tm_date));
685 get_asc_date(&(beam_info->tm_date),&(beam_info->date[0]));
687 beam_info->valid_data=check_data_validity(hd_char);
689 beam_info->real_power=get_real_power(hd_char);
691 beam_info->eval_power=get_eval_power(hd_char);
693 beam_info->scan_mode=get_scan_mode(hd_char);
696 beam_info->azimuth=get_azimuth(hd_char);
698 beam_info->elevation=get_elevation(hd_char);
700 get_quantities(hd_char,quantities);
702 strcpy(beam_info->quantities,quantities);
704 get_flag_quantities(hd_char, beam_info->flag_quantities);
707 beam_info->Z_range=get_Z_range(hd_char);
709 beam_info->pulse_lenght=get_pulse_len(hd_char);
711 beam_info->pulse_number=get_pulse_num(hd_char);
713 beam_info->cell_size=get_cell_size(hd_char);
715 beam_info->cell_num=get_cell_num(hd_char);
717 beam_info->channel=get_channel(hd_char);
720 get_controller_identity(hd_char,controller);
722 strcpy(beam_info->controller,controller);
724 if (check_dualPRF(hd_char))
730 beam_info->filtro_clutter=get_filtro_clutter(hd_char);
731 beam_info->tipo_filtro=get_tipo_filtro(hd_char);
732 beam_info->anticlutter_mappato=get_anticlutter_mappato(hd_char);
734 beam_info->corr_clutter=get_corr_clutter(hd_char);
742BEAM_HD_SP20_INFO * decode_header_sp20_date_real_eo_name(
unsigned char *hd_char, BEAM_HD_SP20_INFO *beam_info,
char *nome_file)
750 beam_info->time=get_date(hd_char,&(beam_info->tm_date));
751 if (beam_info->time == -1)
752 beam_info->time=get_date_from_name((T_MDB_data_header*)hd_char,&(beam_info->tm_date),nome_file);
758 memcpy(&(beam_info->tm_date),gmtime(&beam_info->time),
sizeof(beam_info->tm_date));
760 get_asc_date(&(beam_info->tm_date),&(beam_info->date[0]));
761 beam_info->valid_data=check_data_validity(hd_char);
762 beam_info->real_power=get_real_power(hd_char);
763 beam_info->eval_power=get_eval_power(hd_char);
764 beam_info->scan_mode=get_scan_mode(hd_char);
766 beam_info->azimuth=get_azimuth(hd_char);
767 beam_info->elevation=get_elevation(hd_char);
769 get_quantities(hd_char,quantities);
770 strcpy(beam_info->quantities,quantities);
771 get_flag_quantities(hd_char, beam_info->flag_quantities);
773 beam_info->Z_range=get_Z_range(hd_char);
774 beam_info->pulse_lenght=get_pulse_len(hd_char);
775 beam_info->pulse_number=get_pulse_num(hd_char);
776 beam_info->cell_size=get_cell_size(hd_char);
777 beam_info->cell_num=get_cell_num(hd_char);
778 beam_info->channel=get_channel(hd_char);
780 get_controller_identity(hd_char,controller);
781 strcpy(beam_info->controller,controller);
782 if (check_dualPRF(hd_char))
787 beam_info->filtro_clutter=get_filtro_clutter(hd_char);
788 beam_info->tipo_filtro=get_tipo_filtro(hd_char);
789 beam_info->anticlutter_mappato=get_anticlutter_mappato(hd_char);
790 beam_info->corr_clutter=get_corr_clutter(hd_char);
796BEAM_HD_SP20_INFO * decode_header_sp20_date_from_name(
unsigned char *hd_char, BEAM_HD_SP20_INFO *beam_info,
char *nome_file)
810 beam_info->time=get_date_from_name((T_MDB_data_header*)hd_char,&(beam_info->tm_date),nome_file);
822 memcpy(&(beam_info->tm_date),gmtime(&beam_info->time),
sizeof(beam_info->tm_date));
828 get_asc_date(&(beam_info->tm_date),&(beam_info->date[0]));
830 beam_info->valid_data=check_data_validity(hd_char);
831 beam_info->real_power=get_real_power(hd_char);
832 beam_info->eval_power=get_eval_power(hd_char);
833 beam_info->scan_mode=get_scan_mode(hd_char);
835 beam_info->azimuth=get_azimuth(hd_char);
836 beam_info->elevation=get_elevation(hd_char);
838 get_quantities(hd_char,quantities);
839 strcpy(beam_info->quantities,quantities);
840 get_flag_quantities(hd_char, beam_info->flag_quantities);
842 beam_info->Z_range=get_Z_range(hd_char);
843 beam_info->pulse_lenght=get_pulse_len(hd_char);
844 beam_info->pulse_number=get_pulse_num(hd_char);
845 beam_info->cell_size=get_cell_size(hd_char);
846 beam_info->cell_num=get_cell_num(hd_char);
847 beam_info->channel=get_channel(hd_char);
849 get_controller_identity(hd_char,controller);
850 strcpy(beam_info->controller,controller);
851 if (check_dualPRF(hd_char))
856 beam_info->filtro_clutter=get_filtro_clutter(hd_char);
857 beam_info->tipo_filtro=get_tipo_filtro(hd_char);
858 beam_info->anticlutter_mappato=get_anticlutter_mappato(hd_char);
859 beam_info->corr_clutter=get_corr_clutter(hd_char);
865void PrintHeader(BEAM_HD_SP20_INFO *beam_info)
868 printf(
"HEADER BEAM:\n");
869 printf(
"%s ",beam_info->date);
870 printf(
"%li ",beam_info->time);
871 printf(
"%c ",beam_info->scan_mode);
872 printf(
"%s ",beam_info->quantities);
873 printf(
"%c ",beam_info->Z_range);
874 printf(
"%c ",beam_info->PRF);
875 printf(
"%c ",beam_info->pulse_lenght);
876 printf(
"%i ",beam_info->pulse_number);
877 printf(
"%i ",beam_info->cell_size);
878 printf(
"%i ",beam_info->cell_num);
879 printf(
"%c ",beam_info->valid_data);
880 printf(
"%i ",beam_info->real_power);
881 printf(
"%i ",beam_info->eval_power);
882 printf(
"%9.5f ",beam_info->azimuth);
883 printf(
"%8.5f ",beam_info->elevation);
884 printf(
"%1d ",beam_info->channel);
885 printf(
"%2d ",beam_info->filtro_clutter);
886 printf(
"%2d ",beam_info->tipo_filtro);
887 printf(
"%2d ",beam_info->anticlutter_mappato);
888 printf(
"%2d ",beam_info->corr_clutter);