14 void RSL_rebin_ray(Ray *r, int width);
15 void RSL_rebin_sweep(Sweep *s, int width);
16 void RSL_rebin_volume(Volume *v, int width);
17 void adjust_gate_size(Radar *radar, float gate_size_adjustment);
19 void process_args(int argc, char **argv, char *in_file, int *verbose,
20 char *site_id, char *tape_id,
21 int *qc_reflectivity, int *total_reflectivity,
22 int *differential_reflectivity,
23 int *velocity, int *spectral_width,
24 int *make_gif, int *make_pgm, int *make_bscan, int *make_uf,
25 int *num_sweeps, float *dbz_offset,
26 int *xdim, int *ydim, float *range,
27 float *gate_size_adjustment, int *print_azim,
28 char *gifdir, char *pgmdir, char *ufdir);
30 void make_pathname(char *filename, char *dir, char *pathname)
32 /* Make pathname by combining directory name, if given, with filename. */
34 if (!dir || !dir[0]) {
35 strcpy(pathname, filename);
38 strcpy(pathname, dir);
39 strcat(pathname, "/");
40 strcat(pathname, filename);
44 /***********************************************************************/
45 /* This program uses the NASA TRMM Office Radar Software Library (RSL) */
46 /***********************************************************************/
47 /*** DBW ***************************************************************/
48 /***********************************************************************/
49 int main(int argc, char **argv) {
52 Volume *dz_volume = NULL, *vr_volume = NULL;
53 Volume *dr_volume = NULL, *zt_volume = NULL;
54 Volume *sw_volume = NULL, *qc_volume = NULL;
59 int reflectivity, qc_reflectivity;
60 int differential_reflectivity, total_reflectivity;
61 int velocity, spectral_width;
62 int make_catalog, make_gif, make_pgm;
63 int make_uf, make_bscan;
64 int xdim, ydim, num_sweeps;
68 float scale, dbz_offset;
69 float latitude, longitude;
72 float max_range, gate_size_adjustment;
75 char in_file[100], site_id[100];
79 char pathname[256], gifdir[100], pgmdir[100], ufdir[100];
82 /* Set default values */
84 /*strcpy(site_id, "KMLB");*/
85 strcpy(tape_id, "WSR88D");
89 qc_reflectivity = FALSE;
90 total_reflectivity = FALSE;
91 differential_reflectivity = FALSE;
93 spectral_width = FALSE;
103 gate_size_adjustment = 1.0;
104 *gifdir = *pgmdir = *ufdir = '\0';
107 /* Process command_line arguments */
109 process_args(argc, argv, in_file, &verbose,
111 &qc_reflectivity, &total_reflectivity,
112 &differential_reflectivity,
113 &velocity, &spectral_width,
114 &make_gif, &make_pgm, &make_bscan, &make_uf,
115 &num_sweeps, &dbz_offset,
116 &xdim, &ydim, &maxr, &gate_size_adjustment,
117 &print_azim, gifdir, pgmdir, ufdir);
119 /* If site_id empty, use first 4 characters of file name. */
122 inpath = strdup(in_file);
123 strncpy(site_id, basename(inpath), 4);
125 if (strcmp(site_id, "KWA0") == 0) strcpy(site_id, "KWAJ");
128 /* Be a chatty Kathy? */
131 RSL_radar_verbose_on();
133 RSL_radar_verbose_off();
135 /* Read data into radar */
137 if(verbose) printf("Calling any_format_to_radar\n");
138 radar = RSL_anyformat_to_radar(in_file, site_id);
139 if(verbose) printf("Called any_format_to_radar\n");
142 printf("No radar loaded, bye\n");
146 /* Print command line parameters */
149 printf("Site ID = %s\n",site_id);
150 printf("Tape ID = %s\n",tape_id);
151 printf("Do reflectivity = %d\n",reflectivity);
152 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
153 printf("Do differential_reflectivity = %d\n",
154 differential_reflectivity);
155 printf("Do total_reflectivity = %d\n",
157 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
158 printf("Do velocity = %d\n",velocity);
159 printf("Do spectral_width = %d\n",spectral_width);
160 printf("Make gif = %d\n",make_gif);
161 printf("Make pgm = %d\n",make_pgm);
162 printf("Make UF file = %d\n",make_uf);
163 if (ufdir != NULL) printf("UF output dir = %s\n",ufdir);
164 if (gifdir != NULL) printf("GIF output dir = %s\n",gifdir);
165 if (pgmdir != NULL) printf("PGM output dir = %s\n",pgmdir);
166 printf("dBZ Offset = %.2f\n",dbz_offset);
167 printf("Gate Size Adjust = %.2f\n",gate_size_adjustment);
168 printf("Print Azimuths = %d\n",print_azim);
173 If Gate Size Adjustment is not unity, then we must change the
175 old_gs = radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size
176 radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size =
177 old_gs*gate_size_adjustment
179 Here are some comments from Sandra Yuter on the necessity of this fix.
180 > I dug into the revelant code and it looks like we can do a relatively
181 > simple workaround for the SIGMET raw product file range bin size
182 > errors for the RHB data pulses widths of 0.5 usec and 2.0 usec as follows.
184 > Since we are all converting from sigmet to UF I suggest we resize
185 > the range bin size values in the ray headers in the qlook step
186 > where the sigmet to UF conversion occurs.
188 > The resize requires only 1 additional line of code (I have included
189 > a few others for context) in qlook.c
191 > rangeToFirstGate = 0.001 *
192 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.range_bin1;
194 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size;
195 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size=
198 > I have used 0.6 adjustment factor since that is 75/125 which corresponds
199 > to the error in my 0.5 usec data, for the SUR scans, this adjustment
200 > factor is 133.33/125 or 1.067.
202 The following is from Joe Holmes from SIGMET
205 > I think you have experienced a problem with the RVP7 range resolution
206 > configuration. Both in IRIS and in the RVP7 you manually type in
207 > the range resolution. The RVP7 allows a separate resolution for
208 > each pulsewidth, while IRIS only allows 1 value. There is no feedback
209 > if these values are not typed in the same. Based on setup information
210 > we have here from the RH Brown from Oct 23, 1998, you had the following
221 > I think the error at PW#0 was corrected a while back, but
222 > the error in PW#3 was never corrected. Next time someone is
223 > at the ship, they should check this, fix the long pulse, and remake
224 > the bandpass filter for the long pulse.
226 > In the short term, you can correct the error by taking all your
227 > long pulse data and changing the header to correctly document the
228 > range resolution. We have a program to do this, it is called "change_raw".
229 > The source is on any IRIS system, which was installed with the
230 > source, headers, and objects turned on. It is in the
231 > ${IRIS_ROOT}utils/examples directory. We can supply you with
232 > a compiled version of this program, if you want. Available platforms
233 > are Linux, HP-UX, and IRIX.
237 if(gate_size_adjustment != 1.0) {
238 printf("Adjusting Gate Size by Factor: %.3f\n",gate_size_adjustment);
239 adjust_gate_size(radar, gate_size_adjustment);
243 Create the filename prefix. Consists of the Site ID,
244 and time string (YYMMDD_hhmm). The file suffix is
245 like MIME type (e.g, .gif, .pgm, .uf, etc.)
247 sprintf(time_string,"%4d/%2.2d%2.2d %2.2d:%2.2d UTC",
248 radar->h.year, radar->h.month, radar->h.day,
249 radar->h.hour, radar->h.minute);
251 Determine the location (lat/lon) of the radar.
253 latitude = radar->h.latd + radar->h.latm/60. + radar->h.lats/3600.;
254 longitude = radar->h.lond + radar->h.lonm/60. + radar->h.lons/3600.;
256 printf("%s %s %s %.6f %.6f \n",
257 in_file, radar->h.radar_name, time_string, longitude, latitude);
259 sprintf(time_string,"%4d_%2.2d%2.2d_%2.2d%2.2d",
260 radar->h.year, radar->h.month, radar->h.day,
261 radar->h.hour, radar->h.minute);
264 Print the radar/volume info.
268 * DZ Reflectivity (dBZ), may contain some DZ_INDEX
269 * signal-processor level QC and/or
270 * filters. This field would contain
271 * Darwin's CZ, or WSR88D's standard
272 * reflectivity. In other words, unless
273 * the field is described otherwise, it
274 * should always go here. In essence, this
275 * is the "cleanest" reflectivity field
278 * VR Radial Velocity (m/s) VR_INDEX
280 * SW Spectral Width (m2/s2) SW_INDEX
282 * CZ QC Reflectivity (dBZ), contains
283 * post-processed QC'd data CZ_INDEX
285 * ZT Total Reflectivity (dBZ) ZT_INDEX
286 * May be uncommon, but important
288 * DR Differential reflectivity DR_INDEX
289 * DR and LR are for dual-polarization
290 * radars only. Unitless or in dB.
292 * LR Another form of differential ref LR_INDEX
293 * called LDR, not sure of units
295 * ZD ZDR: Reflectivity Depolarization Ratio ZD_INDEX
296 * ZDR = 10log(ZH/ZV) (dB)
298 * DM Received power measured by the radar. DM_INDEX
301 * RH Rho : Correlation coefficient RH_INDEX
303 * PH Phi (MCTEX parameter) PH_INDEX
305 * XZ X-band reflectivity XZ_INDEX
307 * CR Corrected DR reflectivity (differential) CR_INDEX
309 * MZ DZ mask volume for HDF 1C-51 product. MZ_INDEX
311 * MR DR mask volume for HDF 1C-51 product. MR_INDEX
313 * ZE Edited Reflectivity. ZE_INDEX
315 * VE Edited Velocity. VE_INDEX
318 * 0 = DZ_INDEX = reflectivity.
319 * 1 = VR_INDEX = velocity.
320 * 2 = SW_INDEX = spectrum_width.
321 * 3 = CZ_INDEX = corrected reflectivity.
322 * 4 = ZT_INDEX = uncorrected reflectivity.
323 * 5 = DR_INDEX = differential refl.
324 * 6 = LR_INDEX = another differential refl.
325 * 7 = ZD_INDEX = another differential refl.
326 * 8 = DM_INDEX = received power.
327 * 9 = RH_INDEX = RhoHV: Horz-Vert power corr coeff
328 *10 = PH_INDEX = PhiDP: Differential phase angle
329 *11 = XZ_INDEX = X-band reflectivity.
330 *12 = CR_INDEX = Corrected DR.
331 *13 = MZ_INDEX = DZ mask for 1C-51 HDF.
332 *14 = MR_INDEX = DR mask for 1C-51 HDF.
333 *15 = ZE_INDEX = Edited reflectivity.
334 *16 = VE_INDEX = Edited velocity.
335 *17 = KD_INDEX = KDP deg/km.
336 *18 = TI_INDEX = TIME (unknown) for MCTEX data.
346 for(i=0; i< radar->h.nvolumes; i++) {
347 if(radar->v[i] != NULL) {
348 printf("Vol[%2.2d] has %d sweeps\n",i,radar->v[i]->h.nsweeps);
350 printf("Vol[%2.2d] == NULL\n",i);
353 printf("--------------------------------------------\n");
354 printf("Number of volumes in radar: %d\n",radar->h.nvolumes);
358 if(radar->v[DZ_INDEX] == NULL) {
359 printf("DZ_INDEX == NULL\n");
360 reflectivity = FALSE;
362 dz_volume = radar->v[DZ_INDEX];
363 if(verbose) printf("Number of sweeps in dz_volume = %d\n",
364 dz_volume->h.nsweeps);
368 if(radar->v[CZ_INDEX] == NULL) {
369 if(verbose) printf("CZ_INDEX == NULL\n");
370 qc_reflectivity = FALSE;
372 qc_volume = radar->v[CZ_INDEX];
373 if(verbose) printf("Number of sweeps in qc_volume = %d\n",
374 qc_volume->h.nsweeps);
378 if(radar->v[ZT_INDEX] == NULL) {
379 if(verbose) printf("ZT_INDEX == NULL\n");
380 total_reflectivity = FALSE;
382 zt_volume = radar->v[ZT_INDEX];
383 if(verbose) printf("Number of sweeps in zt_volume = %d\n",
384 zt_volume->h.nsweeps);
387 if(radar->v[DR_INDEX] == NULL) {
388 if(verbose) printf("DR_INDEX == NULL\n");
389 differential_reflectivity = FALSE;
391 dr_volume = radar->v[DR_INDEX];
392 if(verbose) printf("Number of sweeps in dr_volume = %d\n",
393 dr_volume->h.nsweeps);
396 if(radar->v[VR_INDEX] == NULL) {
397 if(verbose) printf("VR_INDEX == NULL\n");
400 vr_volume = radar->v[VR_INDEX];
401 if(verbose) printf("Number of sweeps in vr_volume = %d\n",
402 vr_volume->h.nsweeps);
406 if(radar->v[SW_INDEX] == NULL) {
407 if(verbose) printf("SW_INDEX == NULL\n");
408 spectral_width = FALSE;
410 sw_volume = radar->v[SW_INDEX];
411 if(verbose) printf("Number of sweeps in sw_volume = %d\n",
412 sw_volume->h.nsweeps);
414 if(verbose) printf("--------------------------------------------\n");
417 Print out the elevation angles
421 printf("Reflectivity Tilts\n");
422 printf("----------------------\n");
423 if(dz_volume != NULL) {
424 for(i=0; i<dz_volume->h.nsweeps; i++) {
425 sweep = dz_volume->sweep[i];
427 printf("sweep[%d]==NULL\n",i);
430 printf("Tilt %2d, Elev=%4.1f\n",i,sweep->h.elev);
432 printf("----------------------\n");
437 Print out the values of the rays in each sweep requsted
441 printf("Ray angles\n");
443 for(i=0; i<dz_volume->h.nsweeps; i++) {
444 if(dz_volume->sweep[i] != NULL) sweep = dz_volume->sweep[i];
445 printf("Elevation angle: %f\n",sweep->h.elev);
446 printf("Number of rays in sweep[%d] = %d\n",i,sweep->h.nrays);
448 for(j=0; j<sweep->h.nrays-1; j++) {
449 if(sweep->ray[j] != NULL) {
451 printf("%d: %7.2f\n ",j,sweep->ray[j]->h.azimuth);
458 Write out some volume statistics
461 printf("******************* Volume Statistics *******************\n");
463 sweep = RSL_get_first_sweep_of_volume(dz_volume);
465 printf("Number rays = %d\n", sweep->h.nrays);
466 printf("Beam width = %.2f deg\n", sweep->h.beam_width);
467 ray = RSL_get_first_ray_of_sweep(sweep);
469 max_range = ray->h.range_bin1/1000.0 +
470 ray->h.nbins*ray->h.gate_size/1000.0;
471 printf("Number of bins = %d\n",ray->h.nbins);
472 printf("Max range = %.1f km\n", max_range);
473 printf("Range to first bin = %d m\n",ray->h.range_bin1);
474 printf("Gate size = %d m\n",ray->h.gate_size);
475 printf("Pulse Rep. Freq. = %d Hz\n",ray->h.prf);
476 printf("Pulse width = %.2f us\n",ray->h.pulse_width);
477 printf("Wavelength = %.2f m\n",ray->h.wavelength);
478 printf("Frequency = %.2f \n",ray->h.frequency);
485 Add a dBZ offset if requested. The offset can be positive or negative.
486 if(dbz_offset != 0.0) {
487 printf("Adding dbz_offset to dz_volume: %.2f\n", dbz_offset);
488 RSL_add_dbzoffset_to_volume(dz_volume, dbz_offset);
489 printf("Added dbz_offset to dz_volume: %.2f\n", dbz_offset);
495 ****************************************************************
497 ****************************************************************
502 if(qc_reflectivity) {
503 if(verbose) printf("Loading refl colortable...\n");
504 RSL_load_refl_color_table();
505 for(i=0; i<num_sweeps; i++) {
506 sweep = qc_volume->sweep[i];
508 printf("sweep[%d]==NULL\n",i);
512 sprintf(file_suffix,"pgm");
513 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
514 printf("Creating: %s\n", filename);
515 make_pathname(filename, pgmdir, pathname);
516 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
519 sprintf(file_suffix,"gif");
520 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
521 printf("Creating: %s\n", filename);
522 make_pathname(filename, gifdir, pathname);
523 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
530 if(verbose) printf("Loading refl colortable...\n");
531 RSL_load_refl_color_table();
532 for(i=0; i<num_sweeps; i++) {
533 sweep = dz_volume->sweep[i];
535 printf("sweep[%d]==NULL\n",i);
539 sprintf(file_suffix,"pgm");
540 sprintf(filename,"dz_%s_%2.2d.%s",
541 time_string,i,file_suffix);
542 printf("Creating: %s\n", filename);
543 make_pathname(filename, pgmdir, pathname);
544 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
547 sprintf(file_suffix,"gif");
548 sprintf(filename,"dz_%s_%2.2d.%s", time_string,i,file_suffix);
550 sprintf(filename,"dz_%s.%s.%s", time_string,in_file,file_suffix);
552 printf("Creating: %s\n", filename);
553 make_pathname(filename, gifdir, pathname);
554 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
560 if(total_reflectivity) {
561 if(verbose) printf("Loading refl colortable...\n");
562 RSL_load_refl_color_table();
563 for(i=0; i<num_sweeps; i++) {
564 sweep = zt_volume->sweep[i];
566 printf("sweep[%d]==NULL\n",i);
570 sprintf(file_suffix,"pgm");
571 sprintf(filename,"zt_%s_%2.2d.%s",
572 time_string,i,file_suffix);
573 printf("Creating: %s\n", filename);
574 make_pathname(filename, pgmdir, pathname);
575 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
578 sprintf(file_suffix,"gif");
579 sprintf(filename,"zt_%s_%2.2d.%s",
580 time_string,i,file_suffix);
581 printf("Creating: %s\n", filename);
582 make_pathname(filename, gifdir, pathname);
583 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
589 if(differential_reflectivity) {
593 printf("Calling RSL_rebin, %d\n", width);
594 RSL_rebin_volume(dr_volume, width);
595 if(verbose) printf("Loading zdr colortable...\n");
596 RSL_load_zdr_color_table();
597 for(i=0; i<num_sweeps; i++) {
598 sweep = dr_volume->sweep[i];
600 printf("sweep[%d]==NULL\n",i);
604 sprintf(file_suffix,"pgm");
605 sprintf(filename,"dr_%s_%2.2d.%s",
606 time_string,i,file_suffix);
607 printf("Creating: %s\n", filename);
608 make_pathname(filename, pgmdir, pathname);
609 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
612 sprintf(file_suffix,"gif");
613 sprintf(filename,"dr_%s_%2.2d.%s",
614 time_string,i,file_suffix);
615 printf("Creating: %s\n", filename);
616 make_pathname(filename, gifdir, pathname);
617 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
625 if(verbose) printf("Loading vel colortable...\n");
626 RSL_load_vel_color_table();
627 for(i=0; i<num_sweeps; i++) {
628 sweep = vr_volume->sweep[i];
630 printf("sweep[%d]==NULL\n",i);
634 sprintf(file_suffix,"pgm");
635 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
636 printf("Creating: %s\n", filename);
637 make_pathname(filename, pgmdir, pathname);
638 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
641 sprintf(file_suffix,"gif");
642 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
643 printf("Creating: %s\n", filename);
644 make_pathname(filename, gifdir, pathname);
645 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
652 if(verbose) printf("Loading sw colortable...\n");
653 RSL_load_sw_color_table();
654 for(i=0; i<num_sweeps; i++) {
655 sweep = sw_volume->sweep[i];
657 printf("sweep[%d]==NULL\n",i);
661 sprintf(file_suffix,"pgm");
662 sprintf(filename,"sw_%s_%2.2d.%s",
663 time_string,i,file_suffix);
664 printf("Creating: %s\n", filename);
665 make_pathname(filename, pgmdir, pathname);
666 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
669 sprintf(file_suffix,"gif");
670 sprintf(filename,"sw_%s_%2.2d.%s",
671 time_string,i,file_suffix);
672 printf("Creating: %s\n", filename);
673 make_pathname(filename, gifdir, pathname);
674 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
680 Write uf file if requested
683 sprintf(filename,"%s_%s.%s",site_id, time_string,"uf.gz");
684 printf("Creating UF file: %s\n", filename);
685 make_pathname(filename, ufdir, pathname);
686 RSL_radar_to_uf_gzip(radar, pathname);
689 printf("-->> FIELDS: [ ");
690 /* Modified to use RSL_ftype from rsl.h (#define USE_RSL_VARS) and to
691 * loop through volumes. 10/16/2009, BLK
693 for (i=0; i < MAX_RADAR_VOLUMES; i++)
694 if (radar->v[i] != NULL) printf("%s ", RSL_ftype[i]);
696 if(radar->v[0] != NULL) printf("DZ ");
697 if(radar->v[1] != NULL) printf("VR ");
698 if(radar->v[2] != NULL) printf("SW ");
699 if(radar->v[3] != NULL) printf("CZ ");
700 if(radar->v[4] != NULL) printf("ZT ");
701 if(radar->v[5] != NULL) printf("DR ");
702 if(radar->v[6] != NULL) printf("LR ");
703 if(radar->v[7] != NULL) printf("ZD ");
704 if(radar->v[8] != NULL) printf("DM ");
705 if(radar->v[9] != NULL) printf("RH ");
706 if(radar->v[10] != NULL) printf("PH ");
707 if(radar->v[11] != NULL) printf("XZ ");
708 if(radar->v[12] != NULL) printf("CR ");
709 if(radar->v[13] != NULL) printf("MZ ");
710 if(radar->v[14] != NULL) printf("MR ");
711 if(radar->v[15] != NULL) printf("ZE ");
712 if(radar->v[16] != NULL) printf("VE ");
713 if(radar->v[17] != NULL) printf("KD ");
714 if(radar->v[18] != NULL) printf("TI ");
715 if(radar->v[19] != NULL) printf("DX ");
716 if(radar->v[20] != NULL) printf("CH ");
717 if(radar->v[21] != NULL) printf("AH ");
718 if(radar->v[22] != NULL) printf("CV ");
719 if(radar->v[23] != NULL) printf("AV ");
720 if(radar->v[24] != NULL) printf("SQ ");
728 printf("Finished!\n");