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. */
35 if (!dir || !dir[0]) {
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 int main(int argc, char **argv) {
53 Volume *dz_volume, *vr_volume;
54 Volume *dr_volume, *zt_volume;
55 Volume *sw_volume, *qc_volume;
60 int reflectivity, qc_reflectivity;
61 int differential_reflectivity, total_reflectivity;
62 int velocity, spectral_width;
63 int make_catalog, make_gif, make_pgm;
64 int make_uf, make_bscan;
65 int xdim, ydim, num_sweeps;
69 float scale, dbz_offset;
70 float latitude, longitude;
73 float max_range, gate_size_adjustment;
76 char in_file[100], site_id[100];
80 char pathname[256], gifdir[100], pgmdir[100], ufdir[100];
83 /* Set default values */
85 /*strcpy(site_id, "KMLB");*/
86 strcpy(tape_id, "WSR88D");
90 qc_reflectivity = FALSE;
91 total_reflectivity = FALSE;
92 differential_reflectivity = FALSE;
94 spectral_width = FALSE;
104 gate_size_adjustment = 1.0;
105 *gifdir = *pgmdir = *ufdir = '\0';
108 /* Process command_line arguments */
110 process_args(argc, argv, in_file, &verbose,
112 &qc_reflectivity, &total_reflectivity,
113 &differential_reflectivity,
114 &velocity, &spectral_width,
115 &make_gif, &make_pgm, &make_bscan, &make_uf,
116 &num_sweeps, &dbz_offset,
117 &xdim, &ydim, &maxr, &gate_size_adjustment,
118 &print_azim, gifdir, pgmdir, ufdir);
120 /* If site_id empty, use first 4 characters of file name. */
123 inpath = strdup(in_file);
124 strncpy(site_id, basename(inpath), 4);
126 if (strcmp(site_id, "KWA0") == 0) strcpy(site_id, "KWAJ");
129 /* Be a chatty Kathy? */
132 RSL_radar_verbose_on();
134 RSL_radar_verbose_off();
136 /* Read data into radar */
138 if(verbose) printf("Calling any_format_to_radar\n");
139 radar = RSL_anyformat_to_radar(in_file, site_id);
140 if(verbose) printf("Called any_format_to_radar\n");
143 printf("No radar loaded, bye\n");
147 /* Print command line parameters */
150 printf("Site ID = %s\n",site_id);
151 printf("Tape ID = %s\n",tape_id);
152 printf("Do reflectivity = %d\n",reflectivity);
153 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
154 printf("Do differential_reflectivity = %d\n",
155 differential_reflectivity);
156 printf("Do total_reflectivity = %d\n",
158 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
159 printf("Do velocity = %d\n",velocity);
160 printf("Do spectral_width = %d\n",spectral_width);
161 printf("Make gif = %d\n",make_gif);
162 printf("Make pgm = %d\n",make_pgm);
163 printf("Make UF file = %d\n",make_uf);
164 if (ufdir != NULL) printf("UF output dir = %s\n",ufdir);
165 if (gifdir != NULL) printf("GIF output dir = %s\n",gifdir);
166 if (pgmdir != NULL) printf("PGM output dir = %s\n",pgmdir);
167 printf("dBZ Offset = %.2f\n",dbz_offset);
168 printf("Gate Size Adjust = %.2f\n",gate_size_adjustment);
169 printf("Print Azimuths = %d\n",print_azim);
174 If Gate Size Adjustment is not unity, then we must change the
176 old_gs = radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size
177 radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size =
178 old_gs*gate_size_adjustment
180 Here are some comments from Sandra Yuter on the necessity of this fix.
181 > I dug into the revelant code and it looks like we can do a relatively
182 > simple workaround for the SIGMET raw product file range bin size
183 > errors for the RHB data pulses widths of 0.5 usec and 2.0 usec as follows.
185 > Since we are all converting from sigmet to UF I suggest we resize
186 > the range bin size values in the ray headers in the qlook step
187 > where the sigmet to UF conversion occurs.
189 > The resize requires only 1 additional line of code (I have included
190 > a few others for context) in qlook.c
192 > rangeToFirstGate = 0.001 *
193 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.range_bin1;
195 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size;
196 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size=
199 > I have used 0.6 adjustment factor since that is 75/125 which corresponds
200 > to the error in my 0.5 usec data, for the SUR scans, this adjustment
201 > factor is 133.33/125 or 1.067.
203 The following is from Joe Holmes from SIGMET
206 > I think you have experienced a problem with the RVP7 range resolution
207 > configuration. Both in IRIS and in the RVP7 you manually type in
208 > the range resolution. The RVP7 allows a separate resolution for
209 > each pulsewidth, while IRIS only allows 1 value. There is no feedback
210 > if these values are not typed in the same. Based on setup information
211 > we have here from the RH Brown from Oct 23, 1998, you had the following
222 > I think the error at PW#0 was corrected a while back, but
223 > the error in PW#3 was never corrected. Next time someone is
224 > at the ship, they should check this, fix the long pulse, and remake
225 > the bandpass filter for the long pulse.
227 > In the short term, you can correct the error by taking all your
228 > long pulse data and changing the header to correctly document the
229 > range resolution. We have a program to do this, it is called "change_raw".
230 > The source is on any IRIS system, which was installed with the
231 > source, headers, and objects turned on. It is in the
232 > ${IRIS_ROOT}utils/examples directory. We can supply you with
233 > a compiled version of this program, if you want. Available platforms
234 > are Linux, HP-UX, and IRIX.
238 if(gate_size_adjustment != 1.0) {
239 printf("Adjusting Gate Size by Factor: %.3f\n",gate_size_adjustment);
240 adjust_gate_size(radar, gate_size_adjustment);
244 Create the filename prefix. Consists of the Site ID,
245 and time string (YYMMDD_hhmm). The file suffix is
246 like MIME type (e.g, .gif, .pgm, .uf, etc.)
248 sprintf(time_string,"%4d/%2.2d%2.2d %2.2d:%2.2d UTC",
249 radar->h.year, radar->h.month, radar->h.day,
250 radar->h.hour, radar->h.minute);
252 Determine the location (lat/lon) of the radar.
254 latitude = radar->h.latd + radar->h.latm/60. + radar->h.lats/3600.;
255 longitude = radar->h.lond + radar->h.lonm/60. + radar->h.lons/3600.;
257 printf("%s %s %s %.6f %.6f \n",
258 in_file, radar->h.radar_name, time_string, longitude, latitude);
260 sprintf(time_string,"%4d_%2.2d%2.2d_%2.2d%2.2d",
261 radar->h.year, radar->h.month, radar->h.day,
262 radar->h.hour, radar->h.minute);
265 Print the radar/volume info.
269 * DZ Reflectivity (dBZ), may contain some DZ_INDEX
270 * signal-processor level QC and/or
271 * filters. This field would contain
272 * Darwin's CZ, or WSR88D's standard
273 * reflectivity. In other words, unless
274 * the field is described otherwise, it
275 * should always go here. In essence, this
276 * is the "cleanest" reflectivity field
279 * VR Radial Velocity (m/s) VR_INDEX
281 * SW Spectral Width (m2/s2) SW_INDEX
283 * CZ QC Reflectivity (dBZ), contains
284 * post-processed QC'd data CZ_INDEX
286 * ZT Total Reflectivity (dBZ) ZT_INDEX
287 * May be uncommon, but important
289 * DR Differential reflectivity DR_INDEX
290 * DR and LR are for dual-polarization
291 * radars only. Unitless or in dB.
293 * LR Another form of differential ref LR_INDEX
294 * called LDR, not sure of units
296 * ZD ZDR: Reflectivity Depolarization Ratio ZD_INDEX
297 * ZDR = 10log(ZH/ZV) (dB)
299 * DM Received power measured by the radar. DM_INDEX
302 * RH Rho : Correlation coefficient RH_INDEX
304 * PH Phi (MCTEX parameter) PH_INDEX
306 * XZ X-band reflectivity XZ_INDEX
308 * CR Corrected DR reflectivity (differential) CR_INDEX
310 * MZ DZ mask volume for HDF 1C-51 product. MZ_INDEX
312 * MR DR mask volume for HDF 1C-51 product. MR_INDEX
314 * ZE Edited Reflectivity. ZE_INDEX
316 * VE Edited Velocity. VE_INDEX
319 * 0 = DZ_INDEX = reflectivity.
320 * 1 = VR_INDEX = velocity.
321 * 2 = SW_INDEX = spectrum_width.
322 * 3 = CZ_INDEX = corrected reflectivity.
323 * 4 = ZT_INDEX = uncorrected reflectivity.
324 * 5 = DR_INDEX = differential refl.
325 * 6 = LR_INDEX = another differential refl.
326 * 7 = ZD_INDEX = another differential refl.
327 * 8 = DM_INDEX = received power.
328 * 9 = RH_INDEX = RhoHV: Horz-Vert power corr coeff
329 *10 = PH_INDEX = PhiDP: Differential phase angle
330 *11 = XZ_INDEX = X-band reflectivity.
331 *12 = CR_INDEX = Corrected DR.
332 *13 = MZ_INDEX = DZ mask for 1C-51 HDF.
333 *14 = MR_INDEX = DR mask for 1C-51 HDF.
334 *15 = ZE_INDEX = Edited reflectivity.
335 *16 = VE_INDEX = Edited velocity.
336 *17 = KD_INDEX = KDP deg/km.
337 *18 = TI_INDEX = TIME (unknown) for MCTEX data.
347 for(i=0; i< radar->h.nvolumes; i++) {
348 if(radar->v[i] != NULL) {
349 printf("Vol[%2.2d] has %d sweeps\n",i,radar->v[i]->h.nsweeps);
351 printf("Vol[%2.2d] == NULL\n",i);
354 printf("--------------------------------------------\n");
355 printf("Number of volumes in radar: %d\n",radar->h.nvolumes);
359 if(radar->v[DZ_INDEX] == NULL) {
360 printf("DZ_INDEX == NULL\n");
361 reflectivity = FALSE;
363 dz_volume = radar->v[DZ_INDEX];
364 if(verbose) printf("Number of sweeps in dz_volume = %d\n",
365 dz_volume->h.nsweeps);
369 if(radar->v[CZ_INDEX] == NULL) {
370 if(verbose) printf("CZ_INDEX == NULL\n");
371 qc_reflectivity = FALSE;
373 qc_volume = radar->v[CZ_INDEX];
374 if(verbose) printf("Number of sweeps in qc_volume = %d\n",
375 qc_volume->h.nsweeps);
379 if(radar->v[ZT_INDEX] == NULL) {
380 if(verbose) printf("ZT_INDEX == NULL\n");
381 total_reflectivity = FALSE;
383 zt_volume = radar->v[ZT_INDEX];
384 if(verbose) printf("Number of sweeps in zt_volume = %d\n",
385 zt_volume->h.nsweeps);
388 if(radar->v[DR_INDEX] == NULL) {
389 if(verbose) printf("DR_INDEX == NULL\n");
390 differential_reflectivity = FALSE;
392 dr_volume = radar->v[DR_INDEX];
393 if(verbose) printf("Number of sweeps in dr_volume = %d\n",
394 dr_volume->h.nsweeps);
397 if(radar->v[VR_INDEX] == NULL) {
398 if(verbose) printf("VR_INDEX == NULL\n");
401 vr_volume = radar->v[VR_INDEX];
402 if(verbose) printf("Number of sweeps in vr_volume = %d\n",
403 vr_volume->h.nsweeps);
407 if(radar->v[SW_INDEX] == NULL) {
408 if(verbose) printf("SW_INDEX == NULL\n");
409 spectral_width = FALSE;
411 sw_volume = radar->v[SW_INDEX];
412 if(verbose) printf("Number of sweeps in sw_volume = %d\n",
413 sw_volume->h.nsweeps);
415 if(verbose) printf("--------------------------------------------\n");
418 Print out the elevation angles
422 printf("Reflectivity Tilts\n");
423 printf("----------------------\n");
424 if(dz_volume != NULL) {
425 for(i=0; i<dz_volume->h.nsweeps; i++) {
426 sweep = dz_volume->sweep[i];
428 printf("sweep[%d]==NULL\n",i);
431 printf("Tilt %2d, Elev=%4.1f\n",i,sweep->h.elev);
433 printf("----------------------\n");
438 Print out the values of the rays in each sweep requsted
442 printf("Ray angles\n");
444 for(i=0; i<dz_volume->h.nsweeps; i++) {
445 if(dz_volume->sweep[i] != NULL) sweep = dz_volume->sweep[i];
446 printf("Elevation angle: %f\n",sweep->h.elev);
447 printf("Number of rays in sweep[%d] = %d\n",i,sweep->h.nrays);
449 for(j=0; j<sweep->h.nrays-1; j++) {
450 if(sweep->ray[j] != NULL) {
452 printf("%d: %7.2f\n ",j,sweep->ray[j]->h.azimuth);
459 Write out some volume statistics
462 printf("******************* Volume Statistics *******************\n");
464 sweep = RSL_get_first_sweep_of_volume(dz_volume);
466 printf("Number rays = %d\n", sweep->h.nrays);
467 printf("Beam width = %.2f deg\n", sweep->h.beam_width);
468 ray = RSL_get_first_ray_of_sweep(sweep);
470 max_range = ray->h.range_bin1/1000.0 +
471 ray->h.nbins*ray->h.gate_size/1000.0;
472 printf("Number of bins = %d\n",ray->h.nbins);
473 printf("Max range = %.1f km\n", max_range);
474 printf("Range to first bin = %d m\n",ray->h.range_bin1);
475 printf("Gate size = %d m\n",ray->h.gate_size);
476 printf("Pulse Rep. Freq. = %d Hz\n",ray->h.prf);
477 printf("Pulse width = %.2f us\n",ray->h.pulse_width);
478 printf("Wavelength = %.2f m\n",ray->h.wavelength);
479 printf("Frequency = %.2f \n",ray->h.frequency);
486 Add a dBZ offset if requested. The offset can be positive or negative.
487 if(dbz_offset != 0.0) {
488 printf("Adding dbz_offset to dz_volume: %.2f\n", dbz_offset);
489 RSL_add_dbzoffset_to_volume(dz_volume, dbz_offset);
490 printf("Added dbz_offset to dz_volume: %.2f\n", dbz_offset);
496 ****************************************************************
498 ****************************************************************
503 if(qc_reflectivity) {
504 if(verbose) printf("Loading refl colortable...\n");
505 RSL_load_refl_color_table();
506 for(i=0; i<num_sweeps; i++) {
507 sweep = qc_volume->sweep[i];
509 printf("sweep[%d]==NULL\n",i);
513 sprintf(file_suffix,"pgm");
514 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
515 printf("Creating: %s\n", filename);
516 make_pathname(filename, pgmdir, pathname);
517 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
520 sprintf(file_suffix,"gif");
521 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
522 printf("Creating: %s\n", filename);
523 make_pathname(filename, gifdir, pathname);
524 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
531 if(verbose) printf("Loading refl colortable...\n");
532 RSL_load_refl_color_table();
533 for(i=0; i<num_sweeps; i++) {
534 sweep = dz_volume->sweep[i];
536 printf("sweep[%d]==NULL\n",i);
540 sprintf(file_suffix,"pgm");
541 sprintf(filename,"dz_%s_%2.2d.%s",
542 time_string,i,file_suffix);
543 printf("Creating: %s\n", filename);
544 make_pathname(filename, pgmdir, pathname);
545 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
548 sprintf(file_suffix,"gif");
549 sprintf(filename,"dz_%s_%2.2d.%s", time_string,i,file_suffix);
551 sprintf(filename,"dz_%s.%s.%s", time_string,in_file,file_suffix);
553 printf("Creating: %s\n", filename);
554 make_pathname(filename, gifdir, pathname);
555 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
561 if(total_reflectivity) {
562 if(verbose) printf("Loading refl colortable...\n");
563 RSL_load_refl_color_table();
564 for(i=0; i<num_sweeps; i++) {
565 sweep = zt_volume->sweep[i];
567 printf("sweep[%d]==NULL\n",i);
571 sprintf(file_suffix,"pgm");
572 sprintf(filename,"zt_%s_%2.2d.%s",
573 time_string,i,file_suffix);
574 printf("Creating: %s\n", filename);
575 make_pathname(filename, pgmdir, pathname);
576 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
579 sprintf(file_suffix,"gif");
580 sprintf(filename,"zt_%s_%2.2d.%s",
581 time_string,i,file_suffix);
582 printf("Creating: %s\n", filename);
583 make_pathname(filename, gifdir, pathname);
584 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
590 if(differential_reflectivity) {
594 printf("Calling RSL_rebin, %d\n", width);
595 RSL_rebin_volume(dr_volume, width);
596 if(verbose) printf("Loading zdr colortable...\n");
597 RSL_load_zdr_color_table();
598 for(i=0; i<num_sweeps; i++) {
599 sweep = dr_volume->sweep[i];
601 printf("sweep[%d]==NULL\n",i);
605 sprintf(file_suffix,"pgm");
606 sprintf(filename,"dr_%s_%2.2d.%s",
607 time_string,i,file_suffix);
608 printf("Creating: %s\n", filename);
609 make_pathname(filename, pgmdir, pathname);
610 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
613 sprintf(file_suffix,"gif");
614 sprintf(filename,"dr_%s_%2.2d.%s",
615 time_string,i,file_suffix);
616 printf("Creating: %s\n", filename);
617 make_pathname(filename, gifdir, pathname);
618 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
626 if(verbose) printf("Loading vel colortable...\n");
627 RSL_load_vel_color_table();
628 for(i=0; i<num_sweeps; i++) {
629 sweep = vr_volume->sweep[i];
631 printf("sweep[%d]==NULL\n",i);
635 sprintf(file_suffix,"pgm");
636 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
637 printf("Creating: %s\n", filename);
638 make_pathname(filename, pgmdir, pathname);
639 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
642 sprintf(file_suffix,"gif");
643 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
644 printf("Creating: %s\n", filename);
645 make_pathname(filename, gifdir, pathname);
646 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
653 if(verbose) printf("Loading sw colortable...\n");
654 RSL_load_sw_color_table();
655 for(i=0; i<num_sweeps; i++) {
656 sweep = sw_volume->sweep[i];
658 printf("sweep[%d]==NULL\n",i);
662 sprintf(file_suffix,"pgm");
663 sprintf(filename,"sw_%s_%2.2d.%s",
664 time_string,i,file_suffix);
665 printf("Creating: %s\n", filename);
666 make_pathname(filename, pgmdir, pathname);
667 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
670 sprintf(file_suffix,"gif");
671 sprintf(filename,"sw_%s_%2.2d.%s",
672 time_string,i,file_suffix);
673 printf("Creating: %s\n", filename);
674 make_pathname(filename, gifdir, pathname);
675 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
681 Write uf file if requested
684 sprintf(filename,"%s_%s.%s",site_id, time_string,"uf.gz");
685 printf("Creating UF file: %s\n", filename);
686 make_pathname(filename, ufdir, pathname);
687 RSL_radar_to_uf_gzip(radar, pathname);
690 printf("-->> FIELDS: [ ");
691 /* Modified to use RSL_ftype from rsl.h (#define USE_RSL_VARS) and to
692 * loop through volumes. 10/16/2009, BLK
694 for (i=0; i < MAX_RADAR_VOLUMES; i++)
695 if (radar->v[i] != NULL) printf("%s ", RSL_ftype[i]);
697 if(radar->v[0] != NULL) printf("DZ ");
698 if(radar->v[1] != NULL) printf("VR ");
699 if(radar->v[2] != NULL) printf("SW ");
700 if(radar->v[3] != NULL) printf("CZ ");
701 if(radar->v[4] != NULL) printf("ZT ");
702 if(radar->v[5] != NULL) printf("DR ");
703 if(radar->v[6] != NULL) printf("LR ");
704 if(radar->v[7] != NULL) printf("ZD ");
705 if(radar->v[8] != NULL) printf("DM ");
706 if(radar->v[9] != NULL) printf("RH ");
707 if(radar->v[10] != NULL) printf("PH ");
708 if(radar->v[11] != NULL) printf("XZ ");
709 if(radar->v[12] != NULL) printf("CR ");
710 if(radar->v[13] != NULL) printf("MZ ");
711 if(radar->v[14] != NULL) printf("MR ");
712 if(radar->v[15] != NULL) printf("ZE ");
713 if(radar->v[16] != NULL) printf("VE ");
714 if(radar->v[17] != NULL) printf("KD ");
715 if(radar->v[18] != NULL) printf("TI ");
716 if(radar->v[19] != NULL) printf("DX ");
717 if(radar->v[20] != NULL) printf("CH ");
718 if(radar->v[21] != NULL) printf("AH ");
719 if(radar->v[22] != NULL) printf("CV ");
720 if(radar->v[23] != NULL) printf("AV ");
721 if(radar->v[24] != NULL) printf("SQ ");
729 printf("Finished!\n");