]> Pileus Git - ~andy/rsl/blob - cappi.c
RSL v1.44
[~andy/rsl] / cappi.c
1 /*
2     NASA/TRMM, Code 910.1.
3     This is the TRMM Office Radar Software Library.
4     Copyright (C) 1995  Dennis F. Flanigan Jr. of Applied Research Corporation,
5                         Landover, Maryland, a NASA/GSFC on-site contractor.
6
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16
17     You should have received a copy of the GNU Library General Public
18     License along with this library; if not, write to the Free
19     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20         */
21 /* File: cappi.c 
22  * 
23  * 1/9/95 DFF
24  * Version 0.29 updates 
25  */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <math.h>
30 #include "rsl.h"
31
32 extern int radar_verbose_flag;
33
34
35 /*********************************************************************/
36 /*                                                                   */
37 /*                RSL_get_value_from_cappi                           */
38 /*                                                                   */
39 /*********************************************************************/
40 float RSL_get_value_from_cappi(Cappi *cappi, float rng, float azm)
41    {
42    return RSL_get_value_from_sweep(cappi->sweep, azm, rng);
43    }
44
45 /*********************************************************************/
46 /*                                                                   */
47 /*                        RSL_new_cappi                              */
48 /*                        RSL_free_cappi                             */
49 /*                                                                   */
50 /* Dennis Flanigan                                                   */
51 /* Mods by John Merritt 6/14/95                                      */
52 /*********************************************************************/
53
54 Cappi *RSL_new_cappi(Sweep *sweep, float height)
55    {
56    /* Modeled after a sweep structure. */
57    int   a;
58    Cappi *c;
59    float grange;
60    Ray *ray;
61    int num_bin;
62    float start_bin, size_bin;
63
64    if((c = (Cappi  *)calloc(1, sizeof(Cappi))) == NULL)
65       {
66       fprintf(stderr,"RSL_new_cappi: Calloc failed for Cappi data structure.\n");
67       return(NULL);
68       }
69
70    c->height    = height;
71    ray = RSL_get_first_ray_of_sweep(sweep);
72    num_bin   = ray->h.nbins;
73    start_bin = ray->h.range_bin1/1000.0;
74    size_bin  = ray->h.gate_size/1000.0;
75
76    /* Allocate space for elev angle,range array */
77    if((c->loc =(Er_loc *)calloc(num_bin,sizeof(Er_loc))) == NULL)
78       {
79       fprintf(stderr,"RSL_new_cappi: Calloc failed for er_loc array. \n");
80       free(c);
81       return(NULL);
82       }
83
84    /* Calculate elevation angle verse range array */
85    for(a=0;a<num_bin;a++)
86       {
87       grange = start_bin + (a * size_bin);
88       RSL_get_slantr_and_elev(grange,height,
89                               &c->loc[a].srange,&c->loc[a].elev);
90       }
91
92    /* Allocate Space for the data */
93    c->sweep = RSL_copy_sweep(sweep);
94    RSL_clear_sweep(c->sweep); /* This maintains header info. */
95
96    return c;
97    }  
98
99 void RSL_free_cappi(Cappi *c)
100    {
101    if (c == NULL) return;
102    RSL_free_sweep(c->sweep);
103    free(c->loc);
104    free(c);
105
106    return;
107    }  
108
109
110 /*********************************************************************/
111 /*                                                                   */
112 /*                        RSL_cappi_at_h                             */
113 /*                                                                   */
114 /* DFF 10/28/94                                                      */
115 /* Modified by John Merritt 6/14/95                                  */
116 /*********************************************************************/
117 Cappi *RSL_cappi_at_h(Volume  *v, float height, float max_range)
118    /*
119  * h and max_range in KM.
120  */
121    {
122    int n;
123    Cappi *c;
124    Sweep *sweep;
125    
126    if (v == NULL) return NULL;
127    sweep     = RSL_get_first_sweep_of_volume(v); /* 1st non-NULL sweep */
128    
129    if((c = RSL_new_cappi(sweep, height)) == NULL)
130       {
131       fprintf(stderr,"RSL_cappi_at_h: Vnew_cappi failed\n");
132       return (NULL);
133       }
134    
135    if((n = RSL_fill_cappi(v,c,0)) < 0)
136       {
137       fprintf(stderr,"RSL_cappi_at_h: Vfill_cappi_at_h failed: returned: %d\n",n);
138       RSL_free_cappi(c);
139       return(NULL);
140       }
141    
142    return(c);
143    }
144
145  
146 /*********************************************************************/
147 /*                                                                   */
148 /*                        RSL_fill_cappi                             */
149 /* DFF 10/28/94                                                      */
150 /*********************************************************************/
151 int RSL_fill_cappi(Volume *v, Cappi *cap, int method)
152    {
153    int a,b;
154    float x;
155    Ray *ray;
156    Sweep *sweep;
157    
158    if (v == NULL) return(-1);
159    if (cap == NULL) return(-1);
160
161    /* get data from frist ray. */
162    ray = RSL_get_first_ray_of_volume(v);
163    cap->month = ray->h.month;
164    cap->day        = ray->h.day;
165    cap->year       = ray->h.year;
166    cap->hour       = ray->h.hour;
167    cap->minute     = ray->h.minute;
168    cap->sec        = ray->h.sec;
169    cap->field_type = 1; /** default setting  -- PAK **/
170    cap->interp_method = method;    /* ?? nearest neighbor */
171    
172    ray = RSL_get_first_ray_of_sweep(cap->sweep);
173    sweep = cap->sweep;
174    for(a=0;a < sweep->h.nrays; a++)
175       {
176       ray = sweep->ray[a];
177       for(b=0; b < ray->h.nbins; b++)
178          {
179          x = RSL_get_value(v,
180                            cap->loc[b].elev,
181                            cap->sweep->ray[a]->h.azimuth,
182                            cap->loc[b].srange);
183                    
184          ray->range[b] = ray->h.invf(x);
185          }
186       }
187
188    return 1;
189    }
190
191
192