#include "stdio.h" #include #include #include #include "dcp3rd.h" void p3_read(char *bullx, int *lenbx, int *ibxptr, int *iunbfo, int *iret) /************************************************************************ * p3_read(bullx, lenbx, ibxptr, iret) * * * * This program reads binary p3 radar data and write them into BUFR * * output. * * Input parameters: * * bullx char* Bulletin * * lenbx int Length of bullx * * ibxptr int Pointer within bullx * * * * Output parameters: * * iret int Return code * * 0 = normal return * * -1 = no more reports in * * bulletin * * * ** * * Log: * * S. Guan/NCEP 06/09 Initial version * ***********************************************************************/ { FILE *in; char buf[80], message[120]; P3_header_t *p3h; double *dpt; float *fpt; short *spt; int *ipt; P3_header_t vp3h; double time_stamp; struct tm *current; time_t time_secs; int lunout, tref, tspeed, twidth; int hrs; int mins; int secs; int year; int month; int day; /* array[5] = Radar Latitude, Radar Longitude, Radar Altitude, Earth Relative Azimuth, Earth Relative Incidence */ float lat, lon, altitude, azimuth, incidence, array[5]; char acid[14], acrn[10], stmid[10]; int lacid, lacrn, lstmid; short ref[NMSGSIZE], refws[3][NMSGSIZE]; int i, j, ier, blength, totlenth; short vshort; *iret = 0; totlenth = *lenbx; blength = *ibxptr; if ( (blength + 22) > totlenth) { *iret = 0; sprintf(message, "End of this report \n"); dc_wclg ( 0, "DC", 2, message, &ier ); return; } p3h = &vp3h; dpt = &time_stamp; fpt = ⪫ spt = &vshort; ipt = &i; lunout = *iunbfo; ipt = (int *) (bullx + blength ); vp3h.flight_date = *ipt; spt = ( short * ) (bullx + blength + 4 ); vp3h.aircraft_id = *spt; spt = ( short * ) (bullx + blength + 6 ); vp3h.storm_no = *spt; spt = ( short * ) (bullx + blength + 8 ); vp3h.bins = *spt; fpt = (float * ) (bullx + blength + 10 ); vp3h.range_delay = *fpt; fpt = (float * ) (bullx + blength + 14 ); vp3h.bin_resolution = *fpt; spt = ( short * ) (bullx + blength + 18 ); vp3h.data_type = *spt; spt = ( short * ) (bullx + blength + 20 ); vp3h.antenna_no = *spt; blength = blength + 22; vp3h.flight_date = reverse_int4(vp3h.flight_date); vp3h.aircraft_id = reverse_int2(vp3h.aircraft_id); vp3h.storm_no = reverse_int2(vp3h.storm_no); vp3h.bins = reverse_int2(vp3h.bins); vp3h.range_delay = reverse_float(vp3h.range_delay); vp3h.bin_resolution = reverse_float(vp3h.bin_resolution); vp3h.data_type = reverse_int2(vp3h.data_type); vp3h.antenna_no = reverse_int2(vp3h.antenna_no); if ( (vp3h.aircraft_id == 42) || (vp3h.aircraft_id == 43) || (vp3h.aircraft_id == 49)) { if ( (vp3h.antenna_no < 0) || (vp3h.antenna_no > 10)) { sprintf(message, "Wrong Antenna Number. \n"); dc_wclg ( 0, "DC", 2, message, &ier ); *iret = -1; return; } } else { sprintf(message, "Data are not from N42RF or N43RF or N49RF. \n"); dc_wclg ( 0, "DC", 2, message, &ier ); *iret = -1; return; } /* Decide data type from Radial Data Type Flag */ tref = 0; tspeed = 0; twidth = 0; if (vp3h.data_type == 1 || vp3h.data_type == 3 || vp3h.data_type == 5 || vp3h.data_type == 7) { tref = 1; } if (vp3h.data_type == 2 || vp3h.data_type == 3 || vp3h.data_type == 6 || vp3h.data_type == 7) { tspeed = 1; } if (vp3h.data_type >= 4 ) { twidth = 1; } for(i=0; i<3; i++) for (j=0; j