3 This is the TRMM Office Radar Software Library.
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.
29 static void ymd(int jday, int yy, int *mm, int *dd);
31 static int daytab[2][13] = {
32 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
33 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
36 static void ymd(int jday, int year, int *mm, int *dd)
38 /* Input: jday, yyyy */
43 leap = (year%4 == 0 && year%100 != 0) || year%400 == 0;
44 for (i=0; daytab[leap][i]<jday; i++) continue;
47 *dd = jday - daytab[leap][i];
50 extern int radar_verbose_flag;
52 Radar *RSL_africa_to_radar(char *infile)
59 int hour, min=0, sec=0, month, day, year, jday;
60 float elev, azim, s_azim, e_azim;
61 int iray, ielev, isite;
72 fp = fdopen(save_fd, "r");
74 fp = fopen(infile, "r");
76 fp = uncompress_pipe(fp);
79 radar = RSL_new_radar(MAX_RADAR_VOLUMES);
80 radar->v[DZ_INDEX] = RSL_new_volume(20);
81 v = radar->v[DZ_INDEX];
83 for(i=0; (sweep = africa_read_sweep(fp)); i++) {
85 /* Load the sweep into the radar volume */
86 v->sweep[i] = RSL_new_sweep((int)sweep->nrays);
88 if (radar_verbose_flag) printf("NUMBER OF RAYS: %d\n", sweep->nrays);
89 for (n=0; n < sweep->nrays; n++) {
91 if (ray == NULL) continue;
92 year = ray->yearjday/512;
93 jday = ray->yearjday & 0x1ff;
95 if (year < 1970) year += 100; /* >=2000 */
96 ymd(jday, year, &month, &day);
98 min = ray->minute_sec/60;
99 sec = ray->minute_sec - min*60;
101 elev = africa_bcd_convert (ray->bcd_elevation);
102 azim = africa_bcd_convert (ray->bcd_azimuth);
103 s_azim = africa_bcd_convert (ray->bcd_start_azim);
104 e_azim = africa_bcd_convert (ray->bcd_end_azim);
106 /* Values that I CANNOT trust.
110 * Usually, 10 ray groups for each field type. Field type is in
111 * ray->xmit_power_site (Doc wrong?)
112 * iray == 0 when at the end of the sweep. (Don't need lookahead)
115 ielev = ray->raycount/512;
116 iray = ray->raycount - ielev*512;
117 isite = ray->xmit_power_site & 0x1f;
118 printf("Record %d, time = %.2d:%.2d:%.2d %.2d/%.2d/%.2d --> elev,azim = %f, %f. Start: %f, %f, iray/ielev %d %d, site=%d\n", n,
119 hour, min, sec, month, day, year-1900, elev, azim, s_azim, e_azim, iray, ielev, isite);
122 if (isite != 22) continue;
123 /* ONLY LOAD from isite==22, for now. */
124 r = RSL_new_ray(224);
135 r->h.elev_num = ielev;
136 r->h.beam_width = 1.0;
137 r->h.gate_size = 1000;
139 /* What are the others? */
143 s->h.horz_half_bw = 0.5;
144 s->h.vert_half_bw = 0.5;
145 s->h.beam_width = r->h.beam_width;
147 for (ibin=0; ibin<r->h.nbins; ibin++) {
148 r->range[ibin] = r->h.invf(ray->bin[ibin]/8.0/100.0 + 0.5);
154 sprintf(radar->h.radar_type, "south_africa");
155 sprintf(radar->h.name, "SAFRICA");
156 sprintf(radar->h.radar_name, "SAFRICA");
157 sprintf(radar->h.city, "I don't know");
158 sprintf(radar->h.state, "??");
159 sprintf(radar->h.country, "South Africa");
161 radar_load_date_time(radar);