13 void rebin_ray(Ray *r, int width);
14 void rebin_sweep(Sweep *s, int width);
15 void rebin_volume(Volume *v, int width);
16 void adjust_gate_size(Radar *radar, float gate_size_adjustment);
18 void process_args(int argc, char **argv, char *in_file, int *verbose,
19 char *site_id, char *tape_id,
20 int *qc_reflectivity, int *total_reflectivity,
21 int *differential_reflectivity,
22 int *velocity, int *spectral_width,
23 int *make_gif, int *make_pgm, int *make_bscan, int *make_uf,
24 int *num_sweeps, float *dbz_offset,
25 int *xdim, int *ydim, float *range,
26 float *gate_size_adjustment, int *print_azim);
28 /***********************************************************************/
29 /* This program uses the NASA TRMM Office Radar Software Library (RSL) */
30 /***********************************************************************/
31 /*** DBW ***************************************************************/
32 /***********************************************************************/
33 main(int argc, char **argv) {
36 Volume *dz_volume, *vr_volume;
37 Volume *dr_volume, *zt_volume;
38 Volume *sw_volume, *qc_volume, *volume;
41 Sweep *dz_sweep, *qc_sweep;
42 Sweep *dr_sweep, *zt_sweep;
43 Sweep *vr_sweep, *sw_sweep;
46 int reflectivity, qc_reflectivity, nvolumes;
47 int differential_reflectivity, total_reflectivity;
48 int velocity, spectral_width;
49 int make_catalog, make_gif, make_pgm;
50 int make_uf, make_bscan;
51 int xdim, ydim, num_sweeps;
52 int i,j,k,l,n, verbose, kk;
53 int month, day, year, hour, min;
56 float scale, dbz_offset;
57 float latitude, longitude;
61 float nyquist, max_range, gate_size_adjustment;
64 char in_file[100], site_id[100];
65 char filename[100], outfile[100], nexfile[100];
66 char command[100], file_prefix[100], file_suffix[3];
67 char dir_string[100], red[120], grn[120], blu[120];
68 char time_string[14], site_string[10],img_base[20];
71 /* Set default values */
73 strcpy(site_id, "KMLB");
74 strcpy(tape_id, "WSR88D");
78 qc_reflectivity = FALSE;
79 total_reflectivity = FALSE;
80 differential_reflectivity = FALSE;
82 spectral_width = FALSE;
92 gate_size_adjustment = 1.0;
94 /* Process command_line arguments */
96 process_args(argc, argv, in_file, &verbose,
98 &qc_reflectivity, &total_reflectivity,
99 &differential_reflectivity,
100 &velocity, &spectral_width,
101 &make_gif, &make_pgm, &make_bscan, &make_uf,
102 &num_sweeps, &dbz_offset,
103 &xdim, &ydim, &maxr, &gate_size_adjustment,
106 /* Be a chatty Kathy? */
109 RSL_radar_verbose_on();
111 RSL_radar_verbose_off();
113 /* Read data into radar */
115 if(verbose) printf("Calling any_format_to_radar\n");
116 radar = RSL_anyformat_to_radar(in_file, site_id);
117 if(verbose) printf("Called any_format_to_radar\n");
120 printf("No radar loaded, bye\n");
124 /* Print command line parameters */
127 printf("Site ID = %s\n",site_id);
128 printf("Tape ID = %s\n",tape_id);
129 printf("Do reflectivity = %d\n",reflectivity);
130 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
131 printf("Do differential_reflectivity = %d\n",
132 differential_reflectivity);
133 printf("Do total_reflectivity = %d\n",
135 printf("Do qc_reflectivity = %d\n",qc_reflectivity);
136 printf("Do velocity = %d\n",velocity);
137 printf("Do spectral_width = %d\n",spectral_width);
138 printf("Make gif = %d\n",make_gif);
139 printf("Make pgm = %d\n",make_pgm);
140 printf("Make UF file = %d\n",make_uf);
141 printf("dBZ Offset = %.2f\n",dbz_offset);
142 printf("Gate Size Adjust = %.2f\n",gate_size_adjustment);
143 printf("Print Azimuths = %d\n",print_azim);
148 If Gate Size Adjustment is not unity, then we must change the
150 old_gs = radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size
151 radar->v[i]->sweep[sweepIndex]->ray[rayIndex=]->h.gate_size =
152 old_gs*gate_size_adjustment
154 Here are some comments from Sandra Yuter on the necessity of this fix.
155 > I dug into the revelant code and it looks like we can do a relatively
156 > simple workaround for the SIGMET raw product file range bin size
157 > errors for the RHB data pulses widths of 0.5 usec and 2.0 usec as follows.
159 > Since we are all converting from sigmet to UF I suggest we resize
160 > the range bin size values in the ray headers in the qlook step
161 > where the sigmet to UF conversion occurs.
163 > The resize requires only 1 additional line of code (I have included
164 > a few others for context) in qlook.c
166 > rangeToFirstGate = 0.001 *
167 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.range_bin1;
169 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size;
170 > radar->v[i]->sweep[sweepIndex]->ray[rayIndex]->h.gate_size=
173 > I have used 0.6 adjustment factor since that is 75/125 which corresponds
174 > to the error in my 0.5 usec data, for the SUR scans, this adjustment
175 > factor is 133.33/125 or 1.067.
177 The following is from Joe Holmes from SIGMET
180 > I think you have experienced a problem with the RVP7 range resolution
181 > configuration. Both in IRIS and in the RVP7 you manually type in
182 > the range resolution. The RVP7 allows a separate resolution for
183 > each pulsewidth, while IRIS only allows 1 value. There is no feedback
184 > if these values are not typed in the same. Based on setup information
185 > we have here from the RH Brown from Oct 23, 1998, you had the following
196 > I think the error at PW#0 was corrected a while back, but
197 > the error in PW#3 was never corrected. Next time someone is
198 > at the ship, they should check this, fix the long pulse, and remake
199 > the bandpass filter for the long pulse.
201 > In the short term, you can correct the error by taking all your
202 > long pulse data and changing the header to correctly document the
203 > range resolution. We have a program to do this, it is called "change_raw".
204 > The source is on any IRIS system, which was installed with the
205 > source, headers, and objects turned on. It is in the
206 > ${IRIS_ROOT}utils/examples directory. We can supply you with
207 > a compiled version of this program, if you want. Available platforms
208 > are Linux, HP-UX, and IRIX.
212 if(gate_size_adjustment != 1.0) {
213 printf("Adjusting Gate Size by Factor: %.3f\n",gate_size_adjustment);
214 adjust_gate_size(radar, gate_size_adjustment);
218 Create the filename prefix. Consists of the Site ID,
219 and time string (YYMMDD_hhmm). The file suffix is
220 like MIME type (e.g, .gif, .pgm, .uf, etc.)
222 sprintf(time_string,"%4d/%2.2d%2.2d %2.2d:%2.2d UTC",
223 radar->h.year, radar->h.month, radar->h.day,
224 radar->h.hour, radar->h.minute);
226 Determine the location (lat/lon) of the radar.
228 latitude = radar->h.latd + radar->h.latm/60. + radar->h.lats/3600.;
229 longitude = radar->h.lond + radar->h.lonm/60. + radar->h.lons/3600.;
231 printf("%s %s %s %.6f %.6f \n",
232 in_file, radar->h.radar_name, time_string, longitude, latitude);
234 sprintf(time_string,"%4d_%2.2d%2.2d_%2.2d%2.2d",
235 radar->h.year, radar->h.month, radar->h.day,
236 radar->h.hour, radar->h.minute);
239 Print the radar/volume info.
243 * DZ Reflectivity (dBZ), may contain some DZ_INDEX
244 * signal-processor level QC and/or
245 * filters. This field would contain
246 * Darwin's CZ, or WSR88D's standard
247 * reflectivity. In other words, unless
248 * the field is described otherwise, it
249 * should always go here. In essence, this
250 * is the "cleanest" reflectivity field
253 * VR Radial Velocity (m/s) VR_INDEX
255 * SW Spectral Width (m2/s2) SW_INDEX
257 * CZ QC Reflectivity (dBZ), contains
258 * post-processed QC'd data CZ_INDEX
260 * ZT Total Reflectivity (dBZ) ZT_INDEX
261 * May be uncommon, but important
263 * DR Differential reflectivity DR_INDEX
264 * DR and LR are for dual-polarization
265 * radars only. Unitless or in dB.
267 * LR Another form of differential ref LR_INDEX
268 * called LDR, not sure of units
270 * ZD ZDR: Reflectivity Depolarization Ratio ZD_INDEX
271 * ZDR = 10log(ZH/ZV) (dB)
273 * DM Received power measured by the radar. DM_INDEX
276 * RH Rho : Correlation coefficient RH_INDEX
278 * PH Phi (MCTEX parameter) PH_INDEX
280 * XZ X-band reflectivity XZ_INDEX
282 * CR Corrected DR reflectivity (differential) CR_INDEX
284 * MZ DZ mask volume for HDF 1C-51 product. MZ_INDEX
286 * MR DR mask volume for HDF 1C-51 product. MR_INDEX
288 * ZE Edited Reflectivity. ZE_INDEX
290 * VE Edited Velocity. VE_INDEX
293 * 0 = DZ_INDEX = reflectivity.
294 * 1 = VR_INDEX = velocity.
295 * 2 = SW_INDEX = spectrum_width.
296 * 3 = CZ_INDEX = corrected reflectivity.
297 * 4 = ZT_INDEX = uncorrected reflectivity.
298 * 5 = DR_INDEX = differential refl.
299 * 6 = LR_INDEX = another differential refl.
300 * 7 = ZD_INDEX = another differential refl.
301 * 8 = DM_INDEX = received power.
302 * 9 = RH_INDEX = RhoHV: Horz-Vert power corr coeff
303 *10 = PH_INDEX = PhiDP: Differential phase angle
304 *11 = XZ_INDEX = X-band reflectivity.
305 *12 = CR_INDEX = Corrected DR.
306 *13 = MZ_INDEX = DZ mask for 1C-51 HDF.
307 *14 = MR_INDEX = DR mask for 1C-51 HDF.
308 *15 = ZE_INDEX = Edited reflectivity.
309 *16 = VE_INDEX = Edited velocity.
310 *17 = KD_INDEX = KDP deg/km.
311 *18 = TI_INDEX = TIME (unknown) for MCTEX data.
321 for(i=0; i< radar->h.nvolumes; i++) {
322 if(radar->v[i] != NULL) {
323 printf("Vol[%2.2d] has %d sweeps\n",i,radar->v[i]->h.nsweeps);
325 printf("Vol[%2.2d] == NULL\n",i);
328 printf("--------------------------------------------\n");
329 printf("Number of volumes in radar: %d\n",radar->h.nvolumes);
333 if(radar->v[DZ_INDEX] == NULL) {
334 printf("DZ_INDEX == NULL\n");
335 reflectivity = FALSE;
337 dz_volume = radar->v[DZ_INDEX];
338 if(verbose) printf("Number of sweeps in dz_volume = %d\n",
339 dz_volume->h.nsweeps);
343 if(radar->v[CZ_INDEX] == NULL) {
344 if(verbose) printf("CZ_INDEX == NULL\n");
345 qc_reflectivity = FALSE;
347 qc_volume = radar->v[CZ_INDEX];
348 if(verbose) printf("Number of sweeps in qc_volume = %d\n",
349 qc_volume->h.nsweeps);
353 if(radar->v[ZT_INDEX] == NULL) {
354 if(verbose) printf("ZT_INDEX == NULL\n");
355 total_reflectivity = FALSE;
357 zt_volume = radar->v[ZT_INDEX];
358 if(verbose) printf("Number of sweeps in zt_volume = %d\n",
359 zt_volume->h.nsweeps);
362 if(radar->v[ZD_INDEX] == NULL) {
363 if(verbose) printf("ZD_INDEX == NULL\n");
364 differential_reflectivity = FALSE;
366 dr_volume = radar->v[ZD_INDEX];
367 if(verbose) printf("Number of sweeps in dr_volume = %d\n",
368 dr_volume->h.nsweeps);
371 if(radar->v[VR_INDEX] == NULL) {
372 if(verbose) printf("VR_INDEX == NULL\n");
375 vr_volume = radar->v[VR_INDEX];
376 if(verbose) printf("Number of sweeps in vr_volume = %d\n",
377 vr_volume->h.nsweeps);
381 if(radar->v[SW_INDEX] == NULL) {
382 if(verbose) printf("SW_INDEX == NULL\n");
383 spectral_width = FALSE;
385 sw_volume = radar->v[SW_INDEX];
386 if(verbose) printf("Number of sweeps in sw_volume = %d\n",
387 sw_volume->h.nsweeps);
389 if(verbose) printf("--------------------------------------------\n");
392 Print out the elevation angles
396 printf("Reflectivity Tilts\n");
397 printf("----------------------\n");
398 if(dz_volume != NULL) {
399 for(i=0; i<dz_volume->h.nsweeps; i++) {
400 sweep = dz_volume->sweep[i];
402 printf("sweep[%d]==NULL\n",i);
405 printf("Tilt %2d, Elev=%4.1f\n",i,sweep->h.elev);
407 printf("----------------------\n");
412 Print out the values of the rays in each sweep requsted
416 printf("Ray angles\n");
418 for(i=0; i<dz_volume->h.nsweeps; i++) {
419 if(dz_volume->sweep[i] != NULL) sweep = dz_volume->sweep[i];
420 printf("Elevation angle: %f\n",sweep->h.elev);
421 printf("Number of rays in sweep[%d] = %d\n",i,sweep->h.nrays);
423 for(j=0; j<sweep->h.nrays-1; j++) {
424 if(sweep->ray[j] != NULL) {
426 printf("%d: %7.2f\n ",j,sweep->ray[j]->h.azimuth);
433 Write out some volume statistics
436 printf("******************* Volume Statistics *******************\n");
438 sweep = RSL_get_first_sweep_of_volume(dz_volume);
440 printf("Number rays = %d\n", sweep->h.nrays);
441 printf("Beam width = %.2f deg\n", sweep->h.beam_width);
442 ray = RSL_get_first_ray_of_sweep(sweep);
444 max_range = ray->h.range_bin1/1000.0 +
445 ray->h.nbins*ray->h.gate_size/1000.0;
446 printf("Number of bins = %d\n",ray->h.nbins);
447 printf("Max range = %.1f km\n", max_range);
448 printf("Range to first bin = %d m\n",ray->h.range_bin1);
449 printf("Gate size = %d m\n",ray->h.gate_size);
450 printf("Pulse Rep. Freq. = %d Hz\n",ray->h.prf);
451 printf("Pulse width = %.2f us\n",ray->h.pulse_width);
452 printf("Wavelength = %.2f m\n",ray->h.wavelength);
453 printf("Frequency = %.2f \n",ray->h.frequency);
460 Add a dBZ offset if requested. The offset can be positive or negative.
461 if(dbz_offset != 0.0) {
462 printf("Adding dbz_offset to dz_volume: %.2f\n", dbz_offset);
463 RSL_add_dbzoffset_to_volume(dz_volume, dbz_offset);
464 printf("Added dbz_offset to dz_volume: %.2f\n", dbz_offset);
470 ****************************************************************
472 ****************************************************************
477 if(qc_reflectivity) {
478 if(verbose) printf("Loading refl colortable...\n");
479 RSL_load_refl_color_table();
480 for(i=0; i<num_sweeps; i++) {
481 sweep = qc_volume->sweep[i];
483 printf("sweep[%d]==NULL\n",i);
487 sprintf(file_suffix,"pgm");
488 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
489 printf("Creating: %s\n", filename);
490 RSL_sweep_to_pgm(sweep, filename, xdim, ydim, maxr);
493 sprintf(file_suffix,"gif");
494 sprintf(filename,"qc_%s_%2.2d.%s", time_string,i,file_suffix);
495 printf("Creating: %s\n", filename);
496 RSL_sweep_to_gif(sweep,filename,xdim, ydim, maxr);
503 if(verbose) printf("Loading refl colortable...\n");
504 RSL_load_refl_color_table();
505 for(i=0; i<num_sweeps; i++) {
506 sweep = dz_volume->sweep[i];
508 printf("sweep[%d]==NULL\n",i);
512 sprintf(file_suffix,"pgm");
513 sprintf(filename,"dz_%s_%2.2d.%s",
514 time_string,i,file_suffix);
515 printf("Creating: %s\n", filename);
516 RSL_sweep_to_pgm(sweep, filename, xdim, ydim, maxr);
519 sprintf(file_suffix,"gif");
520 sprintf(filename,"dz_%s_%2.2d.%s", time_string,i,file_suffix);
522 sprintf(filename,"dz_%s.%s.%s", time_string,in_file,file_suffix);
524 printf("Creating: %s\n", filename);
525 RSL_sweep_to_gif(sweep,filename,xdim, ydim, maxr);
531 if(total_reflectivity) {
532 if(verbose) printf("Loading refl colortable...\n");
533 RSL_load_refl_color_table();
534 for(i=0; i<num_sweeps; i++) {
535 sweep = zt_volume->sweep[i];
537 printf("sweep[%d]==NULL\n",i);
541 sprintf(file_suffix,"pgm");
542 sprintf(filename,"zt_%s_%2.2d.%s",
543 time_string,i,file_suffix);
544 printf("Creating: %s\n", filename);
545 RSL_sweep_to_pgm(sweep, filename, xdim, ydim, maxr);
548 sprintf(file_suffix,"gif");
549 sprintf(filename,"zt_%s_%2.2d.%s",
550 time_string,i,file_suffix);
551 printf("Creating: %s\n", filename);
552 RSL_sweep_to_gif(sweep,filename,xdim, ydim, maxr);
558 if(differential_reflectivity) {
562 printf("Calling RSL_rebin, %d %d %.2f\n", width);
563 RSL_rebin_volume(dr_volume, width);
564 if(verbose) printf("Loading zdr colortable...\n");
565 RSL_load_zdr_color_table();
566 for(i=0; i<num_sweeps; i++) {
567 sweep = dr_volume->sweep[i];
569 printf("sweep[%d]==NULL\n",i);
573 sprintf(file_suffix,"pgm");
574 sprintf(filename,"dr_%s_%2.2d.%s",
575 time_string,i,file_suffix);
576 printf("Creating: %s\n", filename);
577 RSL_sweep_to_pgm(sweep, filename, xdim, ydim, maxr);
580 sprintf(file_suffix,"gif");
581 sprintf(filename,"dr_%s_%2.2d.%s",
582 time_string,i,file_suffix);
583 printf("Creating: %s\n", filename);
584 RSL_sweep_to_gif(sweep,filename,xdim, ydim, maxr);
592 if(verbose) printf("Loading vel colortable...\n");
593 RSL_load_vel_color_table();
594 for(i=0; i<num_sweeps; i++) {
595 sweep = vr_volume->sweep[i];
597 printf("sweep[%d]==NULL\n",i);
601 sprintf(file_suffix,"pgm");
602 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
603 printf("Creating: %s\n", filename);
604 RSL_sweep_to_pgm(sweep, filename, xdim, ydim, maxr);
607 sprintf(file_suffix,"gif");
608 sprintf(filename,"vr_%s_%2.2d.%s", time_string,i,file_suffix);
609 printf("Creating: %s\n", filename);
610 RSL_sweep_to_gif(sweep,filename,xdim, ydim, maxr);
617 if(verbose) printf("Loading sw colortable...\n");
618 RSL_load_sw_color_table();
619 for(i=0; i<num_sweeps; i++) {
620 sweep = sw_volume->sweep[i];
622 printf("sweep[%d]==NULL\n",i);
626 sprintf(file_suffix,"pgm");
627 sprintf(filename,"sw_%s_%2.2d.%s",
628 time_string,i,file_suffix);
629 printf("Creating: %s\n", filename);
630 RSL_sweep_to_pgm(sweep, filename, xdim, ydim, maxr);
633 sprintf(file_suffix,"gif");
634 sprintf(filename,"sw_%s_%2.2d.%s",
635 time_string,i,file_suffix);
636 printf("Creating: %s\n", filename);
637 RSL_sweep_to_gif(sweep,filename,xdim, ydim, maxr);
643 Write uf file if requested
646 sprintf(file_suffix,"uf.gz");
647 sprintf(filename,"%s_%s.%s",site_id, time_string,file_suffix);
648 printf("Creating UF file: %s\n", filename);
649 RSL_radar_to_uf_gzip(radar, filename);
652 printf("-->> FIELDS: [ ");
653 if(radar->v[0] != NULL) printf("DZ ");
654 if(radar->v[1] != NULL) printf("VR ");
655 if(radar->v[2] != NULL) printf("SW ");
656 if(radar->v[3] != NULL) printf("CZ ");
657 if(radar->v[4] != NULL) printf("ZT ");
658 if(radar->v[5] != NULL) printf("DR ");
659 if(radar->v[6] != NULL) printf("LR ");
660 if(radar->v[7] != NULL) printf("ZD ");
661 if(radar->v[8] != NULL) printf("DM ");
662 if(radar->v[9] != NULL) printf("RH ");
663 if(radar->v[10] != NULL) printf("PH ");
664 if(radar->v[11] != NULL) printf("XZ ");
665 if(radar->v[12] != NULL) printf("CR ");
666 if(radar->v[13] != NULL) printf("MZ ");
667 if(radar->v[14] != NULL) printf("MR ");
668 if(radar->v[15] != NULL) printf("ZE ");
669 if(radar->v[16] != NULL) printf("VE ");
670 if(radar->v[17] != NULL) printf("KD ");
671 if(radar->v[18] != NULL) printf("TI ");
672 if(radar->v[19] != NULL) printf("DX ");
673 if(radar->v[20] != NULL) printf("CH ");
674 if(radar->v[21] != NULL) printf("AH ");
675 if(radar->v[22] != NULL) printf("CV ");
676 if(radar->v[23] != NULL) printf("AV ");
677 if(radar->v[24] != NULL) printf("SQ ");
684 printf("Finished!\n");