15 void RSL_rebin_ray(Ray *r, int width);
16 void RSL_rebin_sweep(Sweep *s, int width);
17 void RSL_rebin_volume(Volume *v, int width);
18 void adjust_gate_size(Radar *radar, float gate_size_adjustment);
20 void process_args(int argc, char **argv, char *in_file, int *verbose,
21 char *site_id, char *tape_id,
22 int *qc_reflectivity, int *total_reflectivity,
23 int *differential_reflectivity,
24 int *velocity, int *spectral_width,
25 int *make_gif, int *make_pgm, int *make_bscan, int *make_uf,
26 int *num_sweeps, float *dbz_offset,
27 int *xdim, int *ydim, float *range,
28 float *gate_size_adjustment, int *print_azim,
29 char *gifdir, char *pgmdir, char *ufdir);
31 void make_pathname(char *filename, char *dir, char *pathname)
33 /* Make pathname by combining directory name, if given, with filename. */
36 strcpy(pathname, filename);
39 strcpy(pathname, dir);
40 strcat(pathname, "/");
41 strcat(pathname, filename);
45 /***********************************************************************/
46 /* This program uses the NASA TRMM Office Radar Software Library (RSL) */
47 /***********************************************************************/
48 /*** DBW ***************************************************************/
49 /***********************************************************************/
50 main(int argc, char **argv) {
53 Volume *dz_volume, *vr_volume;
54 Volume *dr_volume, *zt_volume;
55 Volume *sw_volume, *qc_volume, *volume;
58 Sweep *dz_sweep, *qc_sweep;
59 Sweep *dr_sweep, *zt_sweep;
60 Sweep *vr_sweep, *sw_sweep;
63 int reflectivity, qc_reflectivity, nvolumes;
64 int differential_reflectivity, total_reflectivity;
65 int velocity, spectral_width;
66 int make_catalog, make_gif, make_pgm;
67 int make_uf, make_bscan;
68 int xdim, ydim, num_sweeps;
69 int i,j,k,l,n, verbose, kk;
70 int month, day, year, hour, min;
73 float scale, dbz_offset;
74 float latitude, longitude;
78 float nyquist, max_range, gate_size_adjustment;
81 char in_file[100], site_id[100];
82 char filename[100], outfile[100], nexfile[100];
83 char command[100], file_prefix[100], file_suffix[3];
84 char dir_string[100], red[120], grn[120], blu[120];
85 char time_string[14], site_string[10],img_base[20];
86 char pathname[256], gifdir[100], pgmdir[100], ufdir[100];
90 /* Set default values */
92 /*strcpy(site_id, "KMLB");*/
93 strcpy(tape_id, "WSR88D");
97 qc_reflectivity = FALSE;
98 total_reflectivity = FALSE;
99 differential_reflectivity = FALSE;
101 spectral_width = FALSE;
104 make_catalog = FALSE;
111 gate_size_adjustment = 1.0;
112 *gifdir = *pgmdir = *ufdir = '\0';
115 /* Process command_line arguments */
117 process_args(argc, argv, in_file, &verbose,
119 &qc_reflectivity, &total_reflectivity,
120 &differential_reflectivity,
121 &velocity, &spectral_width,
122 &make_gif, &make_pgm, &make_bscan, &make_uf,
123 &num_sweeps, &dbz_offset,
124 &xdim, &ydim, &maxr, &gate_size_adjustment,
125 &print_azim, gifdir, pgmdir, ufdir);
127 /* If site_id empty, use first 4 characters of file name. */
130 inpath = strdup(in_file);
131 strncpy(site_id, basename(inpath), 4);
133 if (strcmp(site_id, "KWA0") == 0) strcpy(site_id, "KWAJ");
136 /* Be a chatty Kathy? */
139 RSL_radar_verbose_on();
141 RSL_radar_verbose_off();
143 /* Read data into radar */
145 if(verbose) printf("Calling any_format_to_radar\n");
146 radar = RSL_anyformat_to_radar(in_file, site_id);
147 if(verbose) printf("Called any_format_to_radar\n");
150 printf("No radar loaded, bye\n");
154 /* Print command line parameters */
157 printf("Site ID = %s\n",site_id);
158 printf("Tape ID = %s\n",tape_id);
159 printf("Do reflectivity = %d\n",reflectivity);
160 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
161 printf("Do differential_reflectivity = %d\n",
162 differential_reflectivity);
163 printf("Do total_reflectivity = %d\n",
165 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
166 printf("Do velocity = %d\n",velocity);
167 printf("Do spectral_width = %d\n",spectral_width);
168 printf("Make gif = %d\n",make_gif);
169 printf("Make pgm = %d\n",make_pgm);
170 printf("Make UF file = %d\n",make_uf);
171 if (ufdir != NULL) printf("UF output dir = %s\n",ufdir);
172 if (gifdir != NULL) printf("GIF output dir = %s\n",gifdir);
173 if (pgmdir != NULL) printf("PGM output dir = %s\n",pgmdir);
174 printf("dBZ Offset = %.2f\n",dbz_offset);
175 printf("Gate Size Adjust = %.2f\n",gate_size_adjustment);
176 printf("Print Azimuths = %d\n",print_azim);
181 If Gate Size Adjustment is not unity, then we must change the
183 old_gs = radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size
184 radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size =
185 old_gs*gate_size_adjustment
187 Here are some comments from Sandra Yuter on the necessity of this fix.
188 > I dug into the revelant code and it looks like we can do a relatively
189 > simple workaround for the SIGMET raw product file range bin size
190 > errors for the RHB data pulses widths of 0.5 usec and 2.0 usec as follows.
192 > Since we are all converting from sigmet to UF I suggest we resize
193 > the range bin size values in the ray headers in the qlook step
194 > where the sigmet to UF conversion occurs.
196 > The resize requires only 1 additional line of code (I have included
197 > a few others for context) in qlook.c
199 > rangeToFirstGate = 0.001 *
200 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.range_bin1;
202 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size;
203 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size=
206 > I have used 0.6 adjustment factor since that is 75/125 which corresponds
207 > to the error in my 0.5 usec data, for the SUR scans, this adjustment
208 > factor is 133.33/125 or 1.067.
210 The following is from Joe Holmes from SIGMET
213 > I think you have experienced a problem with the RVP7 range resolution
214 > configuration. Both in IRIS and in the RVP7 you manually type in
215 > the range resolution. The RVP7 allows a separate resolution for
216 > each pulsewidth, while IRIS only allows 1 value. There is no feedback
217 > if these values are not typed in the same. Based on setup information
218 > we have here from the RH Brown from Oct 23, 1998, you had the following
229 > I think the error at PW#0 was corrected a while back, but
230 > the error in PW#3 was never corrected. Next time someone is
231 > at the ship, they should check this, fix the long pulse, and remake
232 > the bandpass filter for the long pulse.
234 > In the short term, you can correct the error by taking all your
235 > long pulse data and changing the header to correctly document the
236 > range resolution. We have a program to do this, it is called "change_raw".
237 > The source is on any IRIS system, which was installed with the
238 > source, headers, and objects turned on. It is in the
239 > ${IRIS_ROOT}utils/examples directory. We can supply you with
240 > a compiled version of this program, if you want. Available platforms
241 > are Linux, HP-UX, and IRIX.
245 if(gate_size_adjustment != 1.0) {
246 printf("Adjusting Gate Size by Factor: %.3f\n",gate_size_adjustment);
247 adjust_gate_size(radar, gate_size_adjustment);
251 Create the filename prefix. Consists of the Site ID,
252 and time string (YYMMDD_hhmm). The file suffix is
253 like MIME type (e.g, .gif, .pgm, .uf, etc.)
255 sprintf(time_string,"%4d/%2.2d%2.2d %2.2d:%2.2d UTC",
256 radar->h.year, radar->h.month, radar->h.day,
257 radar->h.hour, radar->h.minute);
259 Determine the location (lat/lon) of the radar.
261 latitude = radar->h.latd + radar->h.latm/60. + radar->h.lats/3600.;
262 longitude = radar->h.lond + radar->h.lonm/60. + radar->h.lons/3600.;
264 printf("%s %s %s %.6f %.6f \n",
265 in_file, radar->h.radar_name, time_string, longitude, latitude);
267 sprintf(time_string,"%4d_%2.2d%2.2d_%2.2d%2.2d",
268 radar->h.year, radar->h.month, radar->h.day,
269 radar->h.hour, radar->h.minute);
272 Print the radar/volume info.
276 * DZ Reflectivity (dBZ), may contain some DZ_INDEX
277 * signal-processor level QC and/or
278 * filters. This field would contain
279 * Darwin's CZ, or WSR88D's standard
280 * reflectivity. In other words, unless
281 * the field is described otherwise, it
282 * should always go here. In essence, this
283 * is the "cleanest" reflectivity field
286 * VR Radial Velocity (m/s) VR_INDEX
288 * SW Spectral Width (m2/s2) SW_INDEX
290 * CZ QC Reflectivity (dBZ), contains
291 * post-processed QC'd data CZ_INDEX
293 * ZT Total Reflectivity (dBZ) ZT_INDEX
294 * May be uncommon, but important
296 * DR Differential reflectivity DR_INDEX
297 * DR and LR are for dual-polarization
298 * radars only. Unitless or in dB.
300 * LR Another form of differential ref LR_INDEX
301 * called LDR, not sure of units
303 * ZD ZDR: Reflectivity Depolarization Ratio ZD_INDEX
304 * ZDR = 10log(ZH/ZV) (dB)
306 * DM Received power measured by the radar. DM_INDEX
309 * RH Rho : Correlation coefficient RH_INDEX
311 * PH Phi (MCTEX parameter) PH_INDEX
313 * XZ X-band reflectivity XZ_INDEX
315 * CR Corrected DR reflectivity (differential) CR_INDEX
317 * MZ DZ mask volume for HDF 1C-51 product. MZ_INDEX
319 * MR DR mask volume for HDF 1C-51 product. MR_INDEX
321 * ZE Edited Reflectivity. ZE_INDEX
323 * VE Edited Velocity. VE_INDEX
326 * 0 = DZ_INDEX = reflectivity.
327 * 1 = VR_INDEX = velocity.
328 * 2 = SW_INDEX = spectrum_width.
329 * 3 = CZ_INDEX = corrected reflectivity.
330 * 4 = ZT_INDEX = uncorrected reflectivity.
331 * 5 = DR_INDEX = differential refl.
332 * 6 = LR_INDEX = another differential refl.
333 * 7 = ZD_INDEX = another differential refl.
334 * 8 = DM_INDEX = received power.
335 * 9 = RH_INDEX = RhoHV: Horz-Vert power corr coeff
336 *10 = PH_INDEX = PhiDP: Differential phase angle
337 *11 = XZ_INDEX = X-band reflectivity.
338 *12 = CR_INDEX = Corrected DR.
339 *13 = MZ_INDEX = DZ mask for 1C-51 HDF.
340 *14 = MR_INDEX = DR mask for 1C-51 HDF.
341 *15 = ZE_INDEX = Edited reflectivity.
342 *16 = VE_INDEX = Edited velocity.
343 *17 = KD_INDEX = KDP deg/km.
344 *18 = TI_INDEX = TIME (unknown) for MCTEX data.
354 for(i=0; i< radar->h.nvolumes; i++) {
355 if(radar->v[i] != NULL) {
356 printf("Vol[%2.2d] has %d sweeps\n",i,radar->v[i]->h.nsweeps);
358 printf("Vol[%2.2d] == NULL\n",i);
361 printf("--------------------------------------------\n");
362 printf("Number of volumes in radar: %d\n",radar->h.nvolumes);
366 if(radar->v[DZ_INDEX] == NULL) {
367 printf("DZ_INDEX == NULL\n");
368 reflectivity = FALSE;
370 dz_volume = radar->v[DZ_INDEX];
371 if(verbose) printf("Number of sweeps in dz_volume = %d\n",
372 dz_volume->h.nsweeps);
376 if(radar->v[CZ_INDEX] == NULL) {
377 if(verbose) printf("CZ_INDEX == NULL\n");
378 qc_reflectivity = FALSE;
380 qc_volume = radar->v[CZ_INDEX];
381 if(verbose) printf("Number of sweeps in qc_volume = %d\n",
382 qc_volume->h.nsweeps);
386 if(radar->v[ZT_INDEX] == NULL) {
387 if(verbose) printf("ZT_INDEX == NULL\n");
388 total_reflectivity = FALSE;
390 zt_volume = radar->v[ZT_INDEX];
391 if(verbose) printf("Number of sweeps in zt_volume = %d\n",
392 zt_volume->h.nsweeps);
395 if(radar->v[DR_INDEX] == NULL) {
396 if(verbose) printf("DR_INDEX == NULL\n");
397 differential_reflectivity = FALSE;
399 dr_volume = radar->v[DR_INDEX];
400 if(verbose) printf("Number of sweeps in dr_volume = %d\n",
401 dr_volume->h.nsweeps);
404 if(radar->v[VR_INDEX] == NULL) {
405 if(verbose) printf("VR_INDEX == NULL\n");
408 vr_volume = radar->v[VR_INDEX];
409 if(verbose) printf("Number of sweeps in vr_volume = %d\n",
410 vr_volume->h.nsweeps);
414 if(radar->v[SW_INDEX] == NULL) {
415 if(verbose) printf("SW_INDEX == NULL\n");
416 spectral_width = FALSE;
418 sw_volume = radar->v[SW_INDEX];
419 if(verbose) printf("Number of sweeps in sw_volume = %d\n",
420 sw_volume->h.nsweeps);
422 if(verbose) printf("--------------------------------------------\n");
425 Print out the elevation angles
429 printf("Reflectivity Tilts\n");
430 printf("----------------------\n");
431 if(dz_volume != NULL) {
432 for(i=0; i<dz_volume->h.nsweeps; i++) {
433 sweep = dz_volume->sweep[i];
435 printf("sweep[%d]==NULL\n",i);
438 printf("Tilt %2d, Elev=%4.1f\n",i,sweep->h.elev);
440 printf("----------------------\n");
445 Print out the values of the rays in each sweep requsted
449 printf("Ray angles\n");
451 for(i=0; i<dz_volume->h.nsweeps; i++) {
452 if(dz_volume->sweep[i] != NULL) sweep = dz_volume->sweep[i];
453 printf("Elevation angle: %f\n",sweep->h.elev);
454 printf("Number of rays in sweep[%d] = %d\n",i,sweep->h.nrays);
456 for(j=0; j<sweep->h.nrays-1; j++) {
457 if(sweep->ray[j] != NULL) {
459 printf("%d: %7.2f\n ",j,sweep->ray[j]->h.azimuth);
466 Write out some volume statistics
469 printf("******************* Volume Statistics *******************\n");
471 sweep = RSL_get_first_sweep_of_volume(dz_volume);
473 printf("Number rays = %d\n", sweep->h.nrays);
474 printf("Beam width = %.2f deg\n", sweep->h.beam_width);
475 ray = RSL_get_first_ray_of_sweep(sweep);
477 max_range = ray->h.range_bin1/1000.0 +
478 ray->h.nbins*ray->h.gate_size/1000.0;
479 printf("Number of bins = %d\n",ray->h.nbins);
480 printf("Max range = %.1f km\n", max_range);
481 printf("Range to first bin = %d m\n",ray->h.range_bin1);
482 printf("Gate size = %d m\n",ray->h.gate_size);
483 printf("Pulse Rep. Freq. = %d Hz\n",ray->h.prf);
484 printf("Pulse width = %.2f us\n",ray->h.pulse_width);
485 printf("Wavelength = %.2f m\n",ray->h.wavelength);
486 printf("Frequency = %.2f \n",ray->h.frequency);
493 Add a dBZ offset if requested. The offset can be positive or negative.
494 if(dbz_offset != 0.0) {
495 printf("Adding dbz_offset to dz_volume: %.2f\n", dbz_offset);
496 RSL_add_dbzoffset_to_volume(dz_volume, dbz_offset);
497 printf("Added dbz_offset to dz_volume: %.2f\n", dbz_offset);
503 ****************************************************************
505 ****************************************************************
510 if(qc_reflectivity) {
511 if(verbose) printf("Loading refl colortable...\n");
512 RSL_load_refl_color_table();
513 for(i=0; i<num_sweeps; i++) {
514 sweep = qc_volume->sweep[i];
516 printf("sweep[%d]==NULL\n",i);
520 sprintf(file_suffix,"pgm");
521 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
522 printf("Creating: %s\n", filename);
523 make_pathname(filename, pgmdir, pathname);
524 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
527 sprintf(file_suffix,"gif");
528 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
529 printf("Creating: %s\n", filename);
530 make_pathname(filename, gifdir, pathname);
531 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
538 if(verbose) printf("Loading refl colortable...\n");
539 RSL_load_refl_color_table();
540 for(i=0; i<num_sweeps; i++) {
541 sweep = dz_volume->sweep[i];
543 printf("sweep[%d]==NULL\n",i);
547 sprintf(file_suffix,"pgm");
548 sprintf(filename,"dz_%s_%2.2d.%s",
549 time_string,i,file_suffix);
550 printf("Creating: %s\n", filename);
551 make_pathname(filename, pgmdir, pathname);
552 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
555 sprintf(file_suffix,"gif");
556 sprintf(filename,"dz_%s_%2.2d.%s", time_string,i,file_suffix);
558 sprintf(filename,"dz_%s.%s.%s", time_string,in_file,file_suffix);
560 printf("Creating: %s\n", filename);
561 make_pathname(filename, gifdir, pathname);
562 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
568 if(total_reflectivity) {
569 if(verbose) printf("Loading refl colortable...\n");
570 RSL_load_refl_color_table();
571 for(i=0; i<num_sweeps; i++) {
572 sweep = zt_volume->sweep[i];
574 printf("sweep[%d]==NULL\n",i);
578 sprintf(file_suffix,"pgm");
579 sprintf(filename,"zt_%s_%2.2d.%s",
580 time_string,i,file_suffix);
581 printf("Creating: %s\n", filename);
582 make_pathname(filename, pgmdir, pathname);
583 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
586 sprintf(file_suffix,"gif");
587 sprintf(filename,"zt_%s_%2.2d.%s",
588 time_string,i,file_suffix);
589 printf("Creating: %s\n", filename);
590 make_pathname(filename, gifdir, pathname);
591 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
597 if(differential_reflectivity) {
601 printf("Calling RSL_rebin, %d %d %.2f\n", width);
602 RSL_rebin_volume(dr_volume, width);
603 if(verbose) printf("Loading zdr colortable...\n");
604 RSL_load_zdr_color_table();
605 for(i=0; i<num_sweeps; i++) {
606 sweep = dr_volume->sweep[i];
608 printf("sweep[%d]==NULL\n",i);
612 sprintf(file_suffix,"pgm");
613 sprintf(filename,"dr_%s_%2.2d.%s",
614 time_string,i,file_suffix);
615 printf("Creating: %s\n", filename);
616 make_pathname(filename, pgmdir, pathname);
617 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
620 sprintf(file_suffix,"gif");
621 sprintf(filename,"dr_%s_%2.2d.%s",
622 time_string,i,file_suffix);
623 printf("Creating: %s\n", filename);
624 make_pathname(filename, gifdir, pathname);
625 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
633 if(verbose) printf("Loading vel colortable...\n");
634 RSL_load_vel_color_table();
635 for(i=0; i<num_sweeps; i++) {
636 sweep = vr_volume->sweep[i];
638 printf("sweep[%d]==NULL\n",i);
642 sprintf(file_suffix,"pgm");
643 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
644 printf("Creating: %s\n", filename);
645 make_pathname(filename, pgmdir, pathname);
646 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
649 sprintf(file_suffix,"gif");
650 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
651 printf("Creating: %s\n", filename);
652 make_pathname(filename, gifdir, pathname);
653 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
660 if(verbose) printf("Loading sw colortable...\n");
661 RSL_load_sw_color_table();
662 for(i=0; i<num_sweeps; i++) {
663 sweep = sw_volume->sweep[i];
665 printf("sweep[%d]==NULL\n",i);
669 sprintf(file_suffix,"pgm");
670 sprintf(filename,"sw_%s_%2.2d.%s",
671 time_string,i,file_suffix);
672 printf("Creating: %s\n", filename);
673 make_pathname(filename, pgmdir, pathname);
674 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
677 sprintf(file_suffix,"gif");
678 sprintf(filename,"sw_%s_%2.2d.%s",
679 time_string,i,file_suffix);
680 printf("Creating: %s\n", filename);
681 make_pathname(filename, gifdir, pathname);
682 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
688 Write uf file if requested
691 sprintf(file_suffix,"uf.gz");
692 sprintf(filename,"%s_%s.%s",site_id, time_string,file_suffix);
693 printf("Creating UF file: %s\n", filename);
694 make_pathname(filename, ufdir, pathname);
695 RSL_radar_to_uf_gzip(radar, pathname);
698 printf("-->> FIELDS: [ ");
699 /* Modified to use RSL_ftype from rsl.h (#define USE_RSL_VARS) and to
700 * loop through volumes. 10/16/2009, BLK
702 for (i=0; i < MAX_RADAR_VOLUMES; i++)
703 if (radar->v[i] != NULL) printf("%s ", RSL_ftype[i]);
705 if(radar->v[0] != NULL) printf("DZ ");
706 if(radar->v[1] != NULL) printf("VR ");
707 if(radar->v[2] != NULL) printf("SW ");
708 if(radar->v[3] != NULL) printf("CZ ");
709 if(radar->v[4] != NULL) printf("ZT ");
710 if(radar->v[5] != NULL) printf("DR ");
711 if(radar->v[6] != NULL) printf("LR ");
712 if(radar->v[7] != NULL) printf("ZD ");
713 if(radar->v[8] != NULL) printf("DM ");
714 if(radar->v[9] != NULL) printf("RH ");
715 if(radar->v[10] != NULL) printf("PH ");
716 if(radar->v[11] != NULL) printf("XZ ");
717 if(radar->v[12] != NULL) printf("CR ");
718 if(radar->v[13] != NULL) printf("MZ ");
719 if(radar->v[14] != NULL) printf("MR ");
720 if(radar->v[15] != NULL) printf("ZE ");
721 if(radar->v[16] != NULL) printf("VE ");
722 if(radar->v[17] != NULL) printf("KD ");
723 if(radar->v[18] != NULL) printf("TI ");
724 if(radar->v[19] != NULL) printf("DX ");
725 if(radar->v[20] != NULL) printf("CH ");
726 if(radar->v[21] != NULL) printf("AH ");
727 if(radar->v[22] != NULL) printf("CV ");
728 if(radar->v[23] != NULL) printf("AV ");
729 if(radar->v[24] != NULL) printf("SQ ");
737 printf("Finished!\n");