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 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);
271 if (radar->h.vcp > 0) printf("VCP %d\n", radar->h.vcp);
273 Print the radar/volume info.
277 * DZ Reflectivity (dBZ), may contain some DZ_INDEX
278 * signal-processor level QC and/or
279 * filters. This field would contain
280 * Darwin's CZ, or WSR88D's standard
281 * reflectivity. In other words, unless
282 * the field is described otherwise, it
283 * should always go here. In essence, this
284 * is the "cleanest" reflectivity field
287 * VR Radial Velocity (m/s) VR_INDEX
289 * SW Spectral Width (m2/s2) SW_INDEX
291 * CZ QC Reflectivity (dBZ), contains
292 * post-processed QC'd data CZ_INDEX
294 * ZT Total Reflectivity (dBZ) ZT_INDEX
295 * May be uncommon, but important
297 * DR Differential reflectivity DR_INDEX
298 * DR and LR are for dual-polarization
299 * radars only. Unitless or in dB.
301 * LR Another form of differential ref LR_INDEX
302 * called LDR, not sure of units
304 * ZD ZDR: Reflectivity Depolarization Ratio ZD_INDEX
305 * ZDR = 10log(ZH/ZV) (dB)
307 * DM Received power measured by the radar. DM_INDEX
310 * RH Rho : Correlation coefficient RH_INDEX
312 * PH Phi (MCTEX parameter) PH_INDEX
314 * XZ X-band reflectivity XZ_INDEX
316 * CR Corrected DR reflectivity (differential) CR_INDEX
318 * MZ DZ mask volume for HDF 1C-51 product. MZ_INDEX
320 * MR DR mask volume for HDF 1C-51 product. MR_INDEX
322 * ZE Edited Reflectivity. ZE_INDEX
324 * VE Edited Velocity. VE_INDEX
327 * 0 = DZ_INDEX = reflectivity.
328 * 1 = VR_INDEX = velocity.
329 * 2 = SW_INDEX = spectrum_width.
330 * 3 = CZ_INDEX = corrected reflectivity.
331 * 4 = ZT_INDEX = uncorrected reflectivity.
332 * 5 = DR_INDEX = differential refl.
333 * 6 = LR_INDEX = another differential refl.
334 * 7 = ZD_INDEX = another differential refl.
335 * 8 = DM_INDEX = received power.
336 * 9 = RH_INDEX = RhoHV: Horz-Vert power corr coeff
337 *10 = PH_INDEX = PhiDP: Differential phase angle
338 *11 = XZ_INDEX = X-band reflectivity.
339 *12 = CR_INDEX = Corrected DR.
340 *13 = MZ_INDEX = DZ mask for 1C-51 HDF.
341 *14 = MR_INDEX = DR mask for 1C-51 HDF.
342 *15 = ZE_INDEX = Edited reflectivity.
343 *16 = VE_INDEX = Edited velocity.
344 *17 = KD_INDEX = KDP deg/km.
345 *18 = TI_INDEX = TIME (unknown) for MCTEX data.
355 for(i=0; i< radar->h.nvolumes; i++) {
356 if(radar->v[i] != NULL) {
357 printf("Vol[%2.2d] has %d sweeps\n",i,radar->v[i]->h.nsweeps);
359 printf("Vol[%2.2d] == NULL\n",i);
362 printf("--------------------------------------------\n");
363 printf("Number of volumes in radar: %d\n",radar->h.nvolumes);
367 if(radar->v[DZ_INDEX] == NULL) {
368 printf("DZ_INDEX == NULL\n");
369 reflectivity = FALSE;
371 dz_volume = radar->v[DZ_INDEX];
372 if(verbose) printf("Number of sweeps in dz_volume = %d\n",
373 dz_volume->h.nsweeps);
377 if(radar->v[CZ_INDEX] == NULL) {
378 if(verbose) printf("CZ_INDEX == NULL\n");
379 qc_reflectivity = FALSE;
381 qc_volume = radar->v[CZ_INDEX];
382 if(verbose) printf("Number of sweeps in qc_volume = %d\n",
383 qc_volume->h.nsweeps);
387 if(radar->v[ZT_INDEX] == NULL) {
388 if(verbose) printf("ZT_INDEX == NULL\n");
389 total_reflectivity = FALSE;
391 zt_volume = radar->v[ZT_INDEX];
392 if(verbose) printf("Number of sweeps in zt_volume = %d\n",
393 zt_volume->h.nsweeps);
396 if(radar->v[DR_INDEX] == NULL) {
397 if(verbose) printf("DR_INDEX == NULL\n");
398 differential_reflectivity = FALSE;
400 dr_volume = radar->v[DR_INDEX];
401 if(verbose) printf("Number of sweeps in dr_volume = %d\n",
402 dr_volume->h.nsweeps);
405 if(radar->v[VR_INDEX] == NULL) {
406 if(verbose) printf("VR_INDEX == NULL\n");
409 vr_volume = radar->v[VR_INDEX];
410 if(verbose) printf("Number of sweeps in vr_volume = %d\n",
411 vr_volume->h.nsweeps);
415 if(radar->v[SW_INDEX] == NULL) {
416 if(verbose) printf("SW_INDEX == NULL\n");
417 spectral_width = FALSE;
419 sw_volume = radar->v[SW_INDEX];
420 if(verbose) printf("Number of sweeps in sw_volume = %d\n",
421 sw_volume->h.nsweeps);
423 if(verbose) printf("--------------------------------------------\n");
426 Print out the elevation angles
430 printf("Reflectivity Tilts\n");
431 printf("----------------------\n");
432 if(dz_volume != NULL) {
433 for(i=0; i<dz_volume->h.nsweeps; i++) {
434 sweep = dz_volume->sweep[i];
436 printf("sweep[%d]==NULL\n",i);
439 printf("Tilt %2d, Elev=%4.1f\n",i,sweep->h.elev);
441 printf("----------------------\n");
446 Print out the values of the rays in each sweep requsted
450 printf("Ray angles\n");
452 for(i=0; i<dz_volume->h.nsweeps; i++) {
453 if(dz_volume->sweep[i] != NULL) sweep = dz_volume->sweep[i];
454 printf("Elevation angle: %f\n",sweep->h.elev);
455 printf("Number of rays in sweep[%d] = %d\n",i,sweep->h.nrays);
457 for(j=0; j<sweep->h.nrays-1; j++) {
458 if(sweep->ray[j] != NULL) {
460 printf("%d: %7.2f\n ",j,sweep->ray[j]->h.azimuth);
467 Write out some volume statistics
470 printf("******************* Volume Statistics *******************\n");
472 sweep = RSL_get_first_sweep_of_volume(dz_volume);
474 printf("Number rays = %d\n", sweep->h.nrays);
475 printf("Beam width = %.2f deg\n", sweep->h.beam_width);
476 ray = RSL_get_first_ray_of_sweep(sweep);
478 max_range = ray->h.range_bin1/1000.0 +
479 ray->h.nbins*ray->h.gate_size/1000.0;
480 printf("Number of bins = %d\n",ray->h.nbins);
481 printf("Max range = %.1f km\n", max_range);
482 printf("Range to first bin = %d m\n",ray->h.range_bin1);
483 printf("Gate size = %d m\n",ray->h.gate_size);
484 printf("Pulse Rep. Freq. = %d Hz\n",ray->h.prf);
485 printf("Pulse width = %.2f us\n",ray->h.pulse_width);
486 printf("Wavelength = %.2f m\n",ray->h.wavelength);
487 printf("Frequency = %.2f \n",ray->h.frequency);
494 Add a dBZ offset if requested. The offset can be positive or negative.
495 if(dbz_offset != 0.0) {
496 printf("Adding dbz_offset to dz_volume: %.2f\n", dbz_offset);
497 RSL_add_dbzoffset_to_volume(dz_volume, dbz_offset);
498 printf("Added dbz_offset to dz_volume: %.2f\n", dbz_offset);
504 ****************************************************************
506 ****************************************************************
511 if(qc_reflectivity) {
512 if(verbose) printf("Loading refl colortable...\n");
513 RSL_load_refl_color_table();
514 for(i=0; i<num_sweeps; i++) {
515 sweep = qc_volume->sweep[i];
517 printf("sweep[%d]==NULL\n",i);
521 sprintf(file_suffix,"pgm");
522 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
523 printf("Creating: %s\n", filename);
524 make_pathname(filename, pgmdir, pathname);
525 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
528 sprintf(file_suffix,"gif");
529 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
530 printf("Creating: %s\n", filename);
531 make_pathname(filename, gifdir, pathname);
532 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
539 if(verbose) printf("Loading refl colortable...\n");
540 RSL_load_refl_color_table();
541 for(i=0; i<num_sweeps; i++) {
542 sweep = dz_volume->sweep[i];
544 printf("sweep[%d]==NULL\n",i);
548 sprintf(file_suffix,"pgm");
549 sprintf(filename,"dz_%s_%2.2d.%s",
550 time_string,i,file_suffix);
551 printf("Creating: %s\n", filename);
552 make_pathname(filename, pgmdir, pathname);
553 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
556 sprintf(file_suffix,"gif");
557 sprintf(filename,"dz_%s_%2.2d.%s", time_string,i,file_suffix);
559 sprintf(filename,"dz_%s.%s.%s", time_string,in_file,file_suffix);
561 printf("Creating: %s\n", filename);
562 make_pathname(filename, gifdir, pathname);
563 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
569 if(total_reflectivity) {
570 if(verbose) printf("Loading refl colortable...\n");
571 RSL_load_refl_color_table();
572 for(i=0; i<num_sweeps; i++) {
573 sweep = zt_volume->sweep[i];
575 printf("sweep[%d]==NULL\n",i);
579 sprintf(file_suffix,"pgm");
580 sprintf(filename,"zt_%s_%2.2d.%s",
581 time_string,i,file_suffix);
582 printf("Creating: %s\n", filename);
583 make_pathname(filename, pgmdir, pathname);
584 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
587 sprintf(file_suffix,"gif");
588 sprintf(filename,"zt_%s_%2.2d.%s",
589 time_string,i,file_suffix);
590 printf("Creating: %s\n", filename);
591 make_pathname(filename, gifdir, pathname);
592 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
598 if(differential_reflectivity) {
602 printf("Calling RSL_rebin, %d\n", width);
603 RSL_rebin_volume(dr_volume, width);
604 if(verbose) printf("Loading zdr colortable...\n");
605 RSL_load_zdr_color_table();
606 for(i=0; i<num_sweeps; i++) {
607 sweep = dr_volume->sweep[i];
609 printf("sweep[%d]==NULL\n",i);
613 sprintf(file_suffix,"pgm");
614 sprintf(filename,"dr_%s_%2.2d.%s",
615 time_string,i,file_suffix);
616 printf("Creating: %s\n", filename);
617 make_pathname(filename, pgmdir, pathname);
618 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
621 sprintf(file_suffix,"gif");
622 sprintf(filename,"dr_%s_%2.2d.%s",
623 time_string,i,file_suffix);
624 printf("Creating: %s\n", filename);
625 make_pathname(filename, gifdir, pathname);
626 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
634 if(verbose) printf("Loading vel colortable...\n");
635 RSL_load_vel_color_table();
636 for(i=0; i<num_sweeps; i++) {
637 sweep = vr_volume->sweep[i];
639 printf("sweep[%d]==NULL\n",i);
643 sprintf(file_suffix,"pgm");
644 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
645 printf("Creating: %s\n", filename);
646 make_pathname(filename, pgmdir, pathname);
647 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
650 sprintf(file_suffix,"gif");
651 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
652 printf("Creating: %s\n", filename);
653 make_pathname(filename, gifdir, pathname);
654 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
661 if(verbose) printf("Loading sw colortable...\n");
662 RSL_load_sw_color_table();
663 for(i=0; i<num_sweeps; i++) {
664 sweep = sw_volume->sweep[i];
666 printf("sweep[%d]==NULL\n",i);
670 sprintf(file_suffix,"pgm");
671 sprintf(filename,"sw_%s_%2.2d.%s",
672 time_string,i,file_suffix);
673 printf("Creating: %s\n", filename);
674 make_pathname(filename, pgmdir, pathname);
675 RSL_sweep_to_pgm(sweep, pathname, xdim, ydim, maxr);
678 sprintf(file_suffix,"gif");
679 sprintf(filename,"sw_%s_%2.2d.%s",
680 time_string,i,file_suffix);
681 printf("Creating: %s\n", filename);
682 make_pathname(filename, gifdir, pathname);
683 RSL_sweep_to_gif(sweep,pathname,xdim, ydim, maxr);
689 Write uf file if requested
692 sprintf(filename,"%s_%s.%s",site_id, time_string,"uf.gz");
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");