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.
27 int africa_read_buffer(FILE *fp, Africa_buffer *buffer)
31 n = fread(buffer, 1, sizeof(Africa_buffer), fp);
35 float africa_bcd_convert(unsigned short bcd)
40 ((bcd >> 12) & 0xf) * 1000
41 + ((bcd >> 8) & 0xf) * 100
42 + ((bcd >> 4) & 0xf) * 10
47 Africa_sweep * africa_new_sweep(int nray)
51 sweep = (Africa_sweep *)calloc(nray, sizeof(Africa_sweep));
53 perror("africa_new_sweep:sweep");
57 sweep->ray = (Africa_ray **) calloc(nray, sizeof(Africa_ray *));
59 perror("africa_new_sweep:ray");
65 Africa_ray *africa_new_ray(void)
68 ray = (Africa_ray *)calloc(1, sizeof(Africa_ray));
70 perror("africa_new_ray:ray");
76 void africa_free_ray(Africa_ray *r)
82 void africa_free_sweep(Africa_sweep *s)
87 for (i=0; i<s->nrays; i++) {
88 africa_free_ray(s->ray[i]);
94 Africa_sweep *africa_read_sweep(FILE *fp)
96 /* This contains the next ray of data, except
97 * when this is the first ray. This is a
100 static Africa_buffer *buf = NULL; /* The read ahead buffer, too. */
101 Africa_sweep *sweep = NULL;
102 int cur_elev, ielev, iray;
103 Africa_ray *ray = NULL;
107 buf = (Africa_buffer *) calloc(1, sizeof(Africa_buffer));
109 perror("allocate buf in read_sweep");
112 /* (pre)Read a record */
113 africa_read_buffer(fp, buf); /* allocates space for buffer */
116 /* Allocate 500 (should be enough) ray pointers. */
118 sweep = africa_new_sweep(1000); /* 500 times 2 field types ? */
119 /* Determine the elevation step we're on so we know when to
120 * return the sweep. Basically, the last read will be the
121 * data for the next sweep; the meaning of the above code.
123 cur_elev = ielev = buf->raycount/512;
125 while(cur_elev == ielev) {
126 iray = buf->raycount - cur_elev*512;
128 ray = sweep->ray[nray];
129 if (!ray) sweep->ray[nray] = ray = africa_new_ray();
130 memcpy(ray, buf, sizeof(Africa_buffer));
133 if (africa_read_buffer(fp, buf) == 0) break;
134 cur_elev = buf->raycount/512;
135 /* isite = buf->xmit_power_site & 0x1f; */
137 if (nray == 0) return NULL;