]> Pileus Git - ~andy/rsl/blob - radar.c
RSL v1.44
[~andy/rsl] / radar.c
1 /*
2     NASA/TRMM, Code 910.1.
3     This is the TRMM Office Radar Software Library.
4     Copyright (C) 1996, 1997
5             John H. Merritt
6             Space Applications Corporation
7             Vienna, Virginia
8
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.
13
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.
18
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.
22 */
23 /*
24  * Radar routines coded in this file:
25  *
26  *   RSL_radar_verbose_on();  
27  *   RSL_radar_verbose_off();
28  *   Radar *RSL_new_radar(int nvolumes);
29  *   void RSL_free_radar(Radar *r);
30  *   Radar *RSL_clear_radar(Radar *r);
31  *   Volume *RSL_get_volume(Radar *r, int type_wanted);
32  *   Radar *RSL_wsr88d_to_radar(char *infile, unsigned int data_mask);
33  *
34  * Internal routines:
35  *   print_vect(float v[], int istart, int istop);
36  *   void radar_load_date_time(Radar *radar);
37  *   int wsr88d_load_sweep_into_volume(Wsr88d_sweep ws,
38  *                                         Volume *v, int nsweep, unsigned int vmask);
39  *
40  * Radar routines not coded in this file:
41  *
42  *   Radar *RSL_read_radar(char *infile);
43  *   int RSL_write_radar(Radar *radar, char *outfile);
44  *   Radar *RSL_clear_radar(Radar *r);
45  *   void RSL_radar_to_uf(Radar *r, char *outfile);
46  *   Radar *RSL_uf_to_radar(char *infile);
47  *
48  * See the file radar.ez and version.notes for more detailed documentation.
49  *
50  * All routines herein coded, unless otherwise stated, by:
51  *     John Merritt
52  *     Space Applications Corporation
53  *
54  */
55 #include <stdio.h>
56 #include <string.h>
57 #include <stdlib.h>
58
59 #include "rsl.h"
60
61 void RSL_print_version()
62 {
63   printf("RSL version %s.\n", RSL_VERSION_STR);
64 }
65
66 /* Debug printing global variable: radar_verbose_flag */
67 int radar_verbose_flag = 0;
68
69 void RSL_radar_verbose_on()
70 {
71   radar_verbose_flag = 1;
72 }
73 void RSL_radar_verbose_off()
74 {
75   radar_verbose_flag = 0;
76 }
77
78 void print_vect(float v[], int istart, int istop)
79 {
80   int i;
81   for (i=istart; i<=istop; i++)
82         fprintf(stderr,"v[%d] = %f\n", i, v[i]);
83 }
84
85
86 /**********************************************************************/
87 /*                                                                    */
88 /*               RSL_get_nyquist_from_radar                           */
89 /*                                                                    */
90 /**********************************************************************/
91 float RSL_get_nyquist_from_radar(Radar *radar)
92 {
93   /* Find a velocity volume.
94    * Find first sweep in that volume.
95    * Find first ray in that sweep.
96    * Return the nyquist velocity.
97    *
98    * This code required for loading nyquist value in non-velocity
99    * volumes;  UF output is affected by this in a good way.
100    */
101   Volume *vol;
102   Ray *ray;
103   
104   if (radar == NULL) return 0.0;
105   if (radar->h.nvolumes <= VR_INDEX) return 0.0;
106
107   vol = radar->v[VR_INDEX];
108   ray = RSL_get_first_ray_of_volume(vol);
109   if (ray == NULL) return 0.0;
110   return ray->h.nyq_vel;
111 }
112
113 /**********************************************************************/
114 /*                                                                    */
115 /* done 3/30         new_radar()                                      */
116 /* done 3/30         free_radar()                                     */
117 /* done 4/21         clear_radar()                                    */
118 /*                                                                    */
119 /**********************************************************************/
120 Radar *RSL_new_radar(int nvolumes)
121 {
122   Radar *r;
123   r = (Radar *) calloc(1, sizeof(Radar));
124   r->v = (Volume **) calloc(nvolumes, sizeof(Volume *));
125   r->h.nvolumes = nvolumes;
126   r->h.scan_mode = PPI; /* default PPI is enum constant defined in rsl.h */
127   return r;
128 }
129
130 void RSL_free_radar(Radar *r)
131 {
132   int i;
133
134   /* Chase down all the pointers and free everything in sight. */
135   if (r) {
136         for (i=0; i<r->h.nvolumes; i++)
137           RSL_free_volume(r->v[i]);
138         if (r->v) free(r->v);
139         free(r);
140   }
141 }
142
143 Radar *RSL_clear_radar(Radar *r)
144 {
145   int i;
146
147   if (r == NULL) return r;
148   for (i=0; i<r->h.nvolumes; i++)
149         RSL_clear_volume(r->v[i]);
150
151   return r;
152 }
153
154 /**********************************************************************/
155 /*                                                                    */
156 /* done 8/26         radar_load_date_time                             */
157 /*                                                                    */
158 /**********************************************************************/
159 void radar_load_date_time(Radar *radar)
160 {
161   /* Search for the first existing ray of the first sweep of the first
162    * volume; steal that information.
163    */
164
165   int i;
166   Ray *first_ray;
167
168   radar->h.month = 0;
169   radar->h.day   = 0;
170   radar->h.year  = 0;
171   radar->h.hour  = 0;
172   radar->h.minute= 0;
173   radar->h.sec= 0.0;
174   first_ray = NULL;
175
176   for (i=0; i<MAX_RADAR_VOLUMES; i++) {
177         if (radar->v[i] != NULL) {
178           first_ray = RSL_get_first_ray_of_volume(radar->v[i]);
179           if (first_ray) {
180                 radar->h.month = first_ray->h.month;
181                 radar->h.day   = first_ray->h.day;
182                 radar->h.year  = first_ray->h.year;
183                 radar->h.hour  = first_ray->h.hour;
184                 radar->h.minute= first_ray->h.minute;
185                 radar->h.sec   = first_ray->h.sec;
186                 return;
187           }
188         }
189   }
190 }
191
192 /**********************************************************************/
193 /*                                                                    */
194 /* done 3/30     Volume *RSL_get_volume                               */
195 /*                                                                    */
196 /**********************************************************************/
197 Volume *RSL_get_volume(Radar *r, int type_wanted)
198 {
199   return r->v[type_wanted];
200 }