3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996, 1997, 1998
6 Space Applications Corporation
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this library; if not, write to the Free
21 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #ifdef HAVE_LIBIMPLODE
30 extern int radar_verbose_flag;
32 static void fill_ray_header(Ray_header *h, Radtec_header *rh, Radtec_ray_header *rrh)
35 /* Fill the limited ray header information. */
36 h->month = rh->month; /* Time for this ray; month (1-12). */
37 h->day = rh->day; /* Time for this ray; day (1-31). */
38 h->year = rh->year; /* Time for this ray; year (eg. 1993). */
39 h->hour = rrh->hour; /* Date for this ray; hour (0-23). */
40 h->minute = rrh->min;/* Date for this ray; minute (0-59).*/
41 h->sec = rrh->sec; /* Date for this ray; second + fraction of second. */
42 h->azimuth = rrh->azim_angle; /* Azimuth angle. (degrees). Must be positive
43 * 0=North, 90=east, -90/270=west.
44 * This angle is the mean azimuth for the whole ray.
45 * Eg. for NSIG the beginning and end azimuths are
48 h->ray_num = rrh->ray_num; /* Ray no. within elevation scan. */
49 h->elev = rrh->elev_angle; /* Elevation angle. (degrees). */
51 h->gate_size = rh->range_bin_size * RSL_SPEED_OF_LIGHT / 1e6; /* Data gate size (meters)*/
52 h->lat = rh->site_latitude; /* Latitude (degrees) */
53 h->lon = rh->site_longitude; /* Longitude (degrees) */
54 h->alt = rh->site_elevation; /* Altitude (m) */
55 h->nbins = rh->num_range_bins; /* Number of array elements for 'Range'. */
56 h->beam_width = rh->azim_resolution; /* Beamwidth in degrees. */
59 h->unam_rng = 0; /* Unambiguous range. (KM). */
60 h->elev_num = 0; /* Elevation no. within volume scan. */
61 h->range_bin1 = 0; /* Range to first gate.(meters) */
62 h-> vel_res = 0; /* Doppler velocity resolution */
63 h->sweep_rate = 0; /* Sweep rate. Full sweeps/min. */
64 h->prf = 0; /* Pulse repetition frequency, in Hz. */
65 h->azim_rate; /* degrees/sec */
67 h->pitch; /* Pitch angle. */
68 h->roll; /* Roll angle. */
69 h->heading; /* Heading. */
70 h->pitch_rate; /* (angle/sec) */
71 h->roll_rate; /* (angle/sec) */
72 h->heading_rate; /* (angle/sec) */
73 h->rvc; /* Radial velocity correction (m/sec) */
74 h->vel_east; /* Platform velocity to the east (m/sec) */
75 h->vel_north; /* Platform velocity to the north (m/sec) */
76 h->vel_up; /* Platform velocity toward up (m/sec) */
77 h->pulse_count; /* Pulses used in a single dwell time. */
78 h->pulse_width; /* Pulse width (micro-sec). */
79 h->frequency; /* Carrier freq. GHz. */
80 h->wavelength; /* Wavelength. Meters. */
81 h->nyq_vel; /* Nyquist velocity. m/s */
88 Radar *RSL_radtec_to_radar(char *infile)
94 float (*f)(Range x); /* Data conversion function. f(x). */
95 Range (*invf)(float x); /* Data conversion function. invf(x). */
99 int nsweeps, nrays, nbins;
100 int isweep, iray, ibin;
103 rfile = radtec_read_file(infile);
105 if (radar_verbose_flag) {
106 radtec_print_header(&rfile->h);
109 /* Have the entire radtec file; headers and data.
110 * Initialize the RSL radar and load it up.
112 * Handles both RHI and PPI scan types.
115 /* Only one field type per file. */
116 radar = RSL_new_radar(MAX_RADAR_VOLUMES);
118 if (rfile->h.scan_type == 1) { /* PPI */
119 nrays = (int)(360.0 / rfile->h.azim_resolution + 0.5);
120 nsweeps = (int)(rfile->h.num_rays / nrays + 0.5);
123 nsweeps = (int)(rfile->h.num_rays / nrays + 0.5);
124 /* Each sweep will contain one ray for RHI scans. */
126 nbins = rfile->h.num_range_bins;
128 if (radar_verbose_flag) {
129 fprintf(stderr,"Expecting %d sweeps.\n", nsweeps);
130 fprintf(stderr,"Expecting %d rays.\n", nrays);
131 fprintf(stderr,"Expecting %d bins.\n", nbins);
134 if (rfile->h.scan_mode == 0) { /* Log video == Reflectivity. */
137 volume = radar->v[DZ_INDEX] = RSL_new_volume(nsweeps);
138 volume->h.type_str = strdup("Reflectivity");
139 } else { /* Doppler */
142 volume = radar->v[VR_INDEX] = RSL_new_volume(nsweeps);
143 volume->h.type_str = strdup("Velocity");
146 volume->h.invf = invf;
148 /* Load the radar header information. */
149 radar->h.month = rfile->h.month;
150 radar->h.day = rfile->h.day;
151 radar->h.year = rfile->h.year;
152 radar->h.hour = rfile->h.hour;
153 radar->h.minute = rfile->h.min;
154 radar->h.sec = rfile->h.sec; /* Second plus fractional part. */
155 sprintf(radar->h.radar_type,"radtec");
157 radar->h.number = rfile->h.version; /* arbitrary number of this radar site */
158 sprintf(radar->h.name,"radtec"); /* Nexrad site name */
159 sprintf(radar->h.radar_name,"RADTEC"); /* Radar name. */
160 sprintf(radar->h.city,"Unknown"); /* nearest city to radar site */
161 sprintf(radar->h.state,"??"); /* state of radar site */
162 sprintf(radar->h.country,"???");
164 /** Latitude deg, min, sec **/
165 radar->h.latd = (int)rfile->h.site_latitude;
166 tmp = (rfile->h.site_latitude - radar->h.latd) * 60.0;
167 radar->h.latm = (int)tmp;
168 radar->h.lats = (int)((tmp - radar->h.latm) * 60.0);
169 /** Longitude deg, min, sec **/
170 radar->h.lond = (int)rfile->h.site_longitude;
171 tmp = (rfile->h.site_longitude - radar->h.lond) * 60.0;
172 radar->h.lonm = (int)tmp;
173 radar->h.lons = (int)((tmp - radar->h.lonm) * 60.0);
174 radar->h.height = rfile->h.site_elevation; /* height of site in meters above sea level*/
175 radar->h.spulse = 0; /* length of short pulse (ns)*/
176 radar->h.lpulse = 0; /* length of long pulse (ns) */
178 /* Loop through the RSL number of sweeps and attach the data. */
179 for (isweep = 0; isweep < nsweeps; isweep++) {
180 sweep = volume->sweep[isweep] = RSL_new_sweep(nrays);
182 sweep->h.invf = invf;
184 for (iray = 0; iray < nrays; iray++) {
185 ray = sweep->ray[iray] = RSL_new_ray(nbins);
188 fill_ray_header(&ray->h, &rfile->h, rfile->ray[iray].h);
190 sum_elev += ray->h.elev;
192 for (ibin=0; ibin < nbins; ibin++) {
193 /* printf ("ray[%d].dbz[%d] = %f\n", iray, ibin, rfile->ray[iray].dbz[ibin]); */
194 ray->range[ibin] = invf(rfile->ray[iray].dbz[ibin]);
197 sweep->h.elev = sum_elev / nrays;
198 sweep->h.beam_width = rfile->h.azim_resolution; /* This is in the ray header too. */
199 sweep->h.vert_half_bw = sweep->h.beam_width/2; /* Vertical beam width divided by 2 */
200 sweep->h.horz_half_bw = sweep->h.beam_width/2; /* Horizontal beam width divided by 2 */
203 radtec_free_file(rfile);
209 Radar *RSL_radtec_to_radar(char *infile)
211 fprintf(stderr, "RADTEC is not installed in this version of RSL.\n");
212 fprintf(stderr, "The library libimplode.a (or .so) was not found during\n");
213 fprintf(stderr, "the RSL configuration.\n");