3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996-1999
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.
32 extern int radar_verbose_flag;
34 /********************************************************************/
36 /* find_rsl_field_index */
38 /********************************************************************/
39 int find_rsl_field_index(char *dorade_field_name)
42 * Dorade: VE, DM, SW, DZ, ZDR, PHI, RHO, LDR, DX, CH, AH, CV, AV
43 * RSL: VR, DM, SW, DZ, ZD, PH, RH, LR, *DX, *CH, *AH, *CV, *AV.
45 if (strncasecmp(dorade_field_name, "ve", 2) == 0) return VR_INDEX;
46 if (strncasecmp(dorade_field_name, "dm", 2) == 0) return DM_INDEX;
47 if (strncasecmp(dorade_field_name, "sw", 2) == 0) return SW_INDEX;
48 if (strncasecmp(dorade_field_name, "dz", 2) == 0) return DZ_INDEX;
49 if (strncasecmp(dorade_field_name, "zdr", 3) == 0) return ZD_INDEX;
50 if (strncasecmp(dorade_field_name, "phi", 3) == 0) return PH_INDEX;
51 if (strncasecmp(dorade_field_name, "rho", 3) == 0) return RH_INDEX;
52 if (strncasecmp(dorade_field_name, "ldr", 3) == 0) return LR_INDEX;
53 if (strncasecmp(dorade_field_name, "dx", 2) == 0) return DX_INDEX;
54 if (strncasecmp(dorade_field_name, "ch", 2) == 0) return CH_INDEX;
55 if (strncasecmp(dorade_field_name, "ah", 2) == 0) return AH_INDEX;
56 if (strncasecmp(dorade_field_name, "cv", 2) == 0) return CV_INDEX;
57 if (strncasecmp(dorade_field_name, "av", 2) == 0) return AV_INDEX;
59 fprintf(stderr, "Unknown DORADE type <%s>\n", dorade_field_name);
63 /* Secretly defined in uf_to_radar.c */
64 Volume *copy_sweeps_into_volume(Volume *new_volume, Volume *old_volume);
66 Radar *RSL_dorade_to_radar(char *infile)
93 fp = fdopen(save_fd, "r");
95 if((fp=fopen(infile, "r"))==(FILE *)NULL) {
100 fp = uncompress_pipe(fp); /* Transparently, use gunzip. */
102 /**********************************************************************/
104 vd = dorade_read_volume_desc(fp); /* R E A D */
105 if (radar_verbose_flag) dorade_print_volume_desc(vd); /* P R I N T */
108 sd = (Sensor_desc **) calloc(vd->nsensors, sizeof(Sensor_desc *));
109 for (i=0; i<vd->nsensors; i++) {
110 sd[i] = dorade_read_sensor(fp);
114 if (radar_verbose_flag) {
115 for (i=0; i<vd->nsensors; i++) {
116 fprintf(stderr, "============ S E N S O R # %d =====================\n", i);
117 dorade_print_sensor(sd[i]);
120 /* R E A D sweeps. */
121 if (vd->nsensors > 1) {
122 fprintf(stderr, "RSL_dorade_to_radar: Unable to process for more than 1 sensor.\n");
123 fprintf(stderr, "RSL_dorade_to_radar: Number of sensors is %d\n", vd->nsensors);
127 /* Use sensor 0 for vitals. */
128 rd = sd[0]->radar_desc;
130 radar = RSL_new_radar(MAX_RADAR_VOLUMES);
131 radar->h.month = vd->month;
132 radar->h.day = vd->day;
133 radar->h.year = vd->year;
134 radar->h.hour = vd->hour;
135 radar->h.minute = vd->minute;
136 radar->h.sec = vd->second;
137 sprintf(radar->h.radar_type, "dorade");
139 strncpy(radar->h.name, vd->flight_num, sizeof(radar->h.name));
140 strncpy(radar->h.radar_name, rd->radar_name, sizeof(radar->h.radar_name));
141 strncpy(radar->h.project, vd->project_name, sizeof(radar->h.project));
142 sprintf(radar->h.city, "Unknown");
143 strncpy(radar->h.state, "UKN", 3);
144 sprintf(radar->h.country, "Unknown");
145 /* Convert lat to d:m:s */
146 degree = (int)rd->latitude;
147 minute = (int)((rd->latitude - degree) * 60);
148 second = (rd->latitude - degree - minute/60.0) * 3600.0;
149 radar->h.latd = degree;
150 radar->h.latm = minute;
151 radar->h.lats = second;
152 /* Convert lat to d:m:s */
153 degree = (int)rd->longitude;
154 minute = (int)((rd->longitude - degree) * 60);
155 second = (rd->longitude - degree - minute/60.0) * 3600.0;
156 radar->h.lond = degree;
157 radar->h.lonm = minute;
158 radar->h.lons = second;
159 radar->h.height = rd->altitude * 1000.0;
160 radar->h.spulse = 0; /* FIXME */
161 radar->h.lpulse = 0; /* FIXME */
163 /* Begin volume code. */
164 /* We don't know how many sweeps per volume exist, until we read
165 * the file. So allocate a large number of pointers, hope we don't
166 * exceed it, and adjust the pointer array at the end. This is
167 * efficient because we'll be manipulating pointers to the sweeps and
168 * not the sweeps themselves.
171 if (radar_verbose_flag)
172 fprintf(stderr, "Number of parameters: %d\n", rd->nparam_desc);
174 /* All the parameters are together, however, their order within
175 * the ray is not guarenteed. For instance, VE could appear after
176 * DM. For this we'll keep a list of parameter names and perform
177 * a (linear) search. The result will be an index into the RSL
178 * volume array (radar->v[i]). It is likely that the order will
179 * consistant within a file, therefore, we'll keep track of the index of
180 * our previous parameter type and begin the search from there; the next
181 * index should be a match.
183 * The dorade parameter names and the rsl mapping is:
185 * Dorade: VE, DM, SW, DZ, ZDR, PHI, RHO, LDR, DX, CH, AH, CV, AV
186 * RSL: VR, DM, SW, DZ, ZD, PH, RH, LR, *DX, *CH, *AH, *CV, *AV.
188 * * means this is a new RSL name.
191 #define DORADE_MAX_SWEEP 20
193 while((sr = dorade_read_sweep(fp, sd))) {
194 for(iray = 0; iray < sr->nrays; iray++) {
195 dray = sr->data_ray[iray];
197 /* Now, loop through the parameters and fill the rsl structures. */
198 for (iparam = 0; iparam < dray->nparam; iparam++) {
199 pd = dray->parameter_data[iparam];
200 iv = find_rsl_field_index(pd->name);
201 if (radar->v[iv] == NULL) {
202 radar->v[iv] = RSL_new_volume(DORADE_MAX_SWEEP); /* Expandable */
203 } else if (nsweep >= radar->v[iv]->h.nsweeps) {
204 /* Must expand the number of sweeps. */
205 /* Expand by another DORADE_MAX_SWEEP. */
206 if (radar_verbose_flag) {
207 fprintf(stderr, "nsweeps (%d) exceeds radar->v[%d]->h.nsweeps (%d).\n", nsweep, iv, radar->v[iv]->h.nsweeps);
208 fprintf(stderr, "Increading it to %d sweeps\n", radar->v[iv]->h.nsweeps+DORADE_MAX_SWEEP);
210 new_volume = RSL_new_volume(radar->v[iv]->h.nsweeps+DORADE_MAX_SWEEP);
211 /* Look in uf_to_radar.c for 'copy_sweeps_into_volume' */
212 new_volume = copy_sweeps_into_volume(new_volume, radar->v[iv]);
213 radar->v[iv] = new_volume;
216 /* Allocate the ray and load the parameter data. */
217 if ((sweep = radar->v[iv]->sweep[nsweep]) == NULL) {
218 sweep = radar->v[iv]->sweep[nsweep] = RSL_new_sweep(sr->s_info->nrays);
219 sweep->h.sweep_num = sr->s_info->sweep_num;
220 sweep->h.elev = sr->s_info->fixed_angle;
221 sweep->h.beam_width = rd->horizontal_beam_width;
222 sweep->h.vert_half_bw = radar->v[iv]->sweep[nsweep]->h.beam_width / 2.0;
223 sweep->h.horz_half_bw = rd->horizontal_beam_width / 2.0;
224 sweep->h.f = RSL_f_list[iv];
225 sweep->h.invf = RSL_invf_list[iv];
229 if ((ray = sweep->ray[iray]) == NULL) {
230 if (radar_verbose_flag)
231 fprintf(stderr, "Allocating %d bins for ray %d\n", dray->data_len[iparam], iray);
232 ray = sweep->ray[iray] = RSL_new_ray(dray->data_len[iparam]);
235 /* Copy the ray data into the RSL ray. */
237 /* .... fill here .... */
241 if (radar_verbose_flag) fprintf(stderr, "______NEW SWEEP__<%d>____\n", nsweep);
242 /* Save for loading into volume structure. */
243 dorade_free_sweep(sr);
246 /* The following avoids a broken pipe message, since a VOLD at the end
249 while(fread(buf, sizeof(buf), 1, fp)) continue; /* Read til EOF */