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.
28 int africa_read_buffer(FILE *fp, Africa_buffer *buffer)
32 n = fread(buffer, 1, sizeof(Africa_buffer), fp);
36 float africa_bcd_convert(unsigned short bcd)
41 ((bcd >> 12) & 0xf) * 1000
42 + ((bcd >> 8) & 0xf) * 100
43 + ((bcd >> 4) & 0xf) * 10
48 Africa_sweep * africa_new_sweep(int nray)
52 sweep = (Africa_sweep *)calloc(nray, sizeof(Africa_sweep));
54 perror("africa_new_sweep:sweep");
58 sweep->ray = (Africa_ray **) calloc(nray, sizeof(Africa_ray *));
60 perror("africa_new_sweep:ray");
66 Africa_ray *africa_new_ray(void)
69 ray = (Africa_ray *)calloc(1, sizeof(Africa_ray));
71 perror("africa_new_ray:ray");
77 void africa_free_ray(Africa_ray *r)
83 void africa_free_sweep(Africa_sweep *s)
88 for (i=0; i<s->nrays; i++) {
89 africa_free_ray(s->ray[i]);
95 Africa_sweep *africa_read_sweep(FILE *fp)
97 /* This contains the next ray of data, except
98 * when this is the first ray. This is a
101 static Africa_buffer *buf = NULL; /* The read ahead buffer, too. */
102 Africa_sweep *sweep = NULL;
103 int cur_elev, ielev, iray;
104 Africa_ray *ray = NULL;
108 buf = (Africa_buffer *) calloc(1, sizeof(Africa_buffer));
110 perror("allocate buf in read_sweep");
113 /* (pre)Read a record */
114 africa_read_buffer(fp, buf); /* allocates space for buffer */
117 /* Allocate 500 (should be enough) ray pointers. */
119 sweep = africa_new_sweep(1000); /* 500 times 2 field types ? */
120 /* Determine the elevation step we're on so we know when to
121 * return the sweep. Basically, the last read will be the
122 * data for the next sweep; the meaning of the above code.
124 cur_elev = ielev = buf->raycount/512;
126 while(cur_elev == ielev) {
127 iray = buf->raycount - cur_elev*512;
129 ray = sweep->ray[nray];
130 if (!ray) sweep->ray[nray] = ray = africa_new_ray();
131 memcpy(ray, buf, sizeof(Africa_buffer));
134 if (africa_read_buffer(fp, buf) == 0) break;
135 cur_elev = buf->raycount/512;
136 /* isite = buf->xmit_power_site & 0x1f; */
138 if (nray == 0) return NULL;