3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996, 1997
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.
26 # define M_PI 3.14159265358979323846
29 /**********************************************************************/
32 /* RSL_fractional_area_of_sweep */
34 /* Compute fractional area of a sweep given a range of dBZ and */
35 /* a maximum range in km. */
37 /* By: John Merritt */
38 /* Space Applications Corporation */
40 /**********************************************************************/
42 float get_pixel_area(Ray *r, float min_range, float max_range)
44 float h1, h2, r1, r2; /* height and radius in km*/
46 float theta; /* in radian */
48 /* returns volume area of ray between min range and max range
50 if (r == NULL) return 0.0;
54 /* convert from degree to radian */
55 theta = (r->h.beam_width/2) * 2 * M_PI / 360;
59 volume = (M_PI/3) * (pow((double)r2, (double) 2) * h2 - pow((double) r1, (double) 2) *h1);
62 } /* get_pixel_area */
65 float RSL_area_of_ray(Ray *r, float lo, float hi, float min_range, float max_range)
74 if (r == NULL) return 0.0;
75 /* Check if min_range is closer to the radar than the first bin.
76 * If so, we can't use it.
80 hi = 100.0; /* default to max dbz*/
81 start_km = r->h.range_bin1/1000.0;
82 binsize = r->h.gate_size/1000.0;
84 nbins = ((max_range - start_km) / binsize);
85 bin1 = (min_range - start_km) / binsize;
87 if (bin1 < 0) bin1 = 0;
88 if (nbins > r->h.nbins) nbins = r->h.nbins;
90 /* Compute the number of pixels with lo < dBZ <= hi */
93 for(i=bin1; i<nbins-1; i++) {
94 xdBZ = r->h.f(r->range[i]);
95 if(lo < xdBZ && xdBZ <= hi) { /*MAX_DBZ = hi (typically 70?) */
96 /* get r1 and r2 in km */
97 r1 = i * binsize + start_km;
98 r2 = (i+1) * binsize + start_km;
99 area += get_pixel_area(r, r1, r2);
101 r1 = i * binsize + start_km;
109 float RSL_fractional_area_of_sweep(Sweep *s, float lo, float hi, float min_rng, float max_rng)
112 * Compute the fractional area of the Sweep.
114 * This doesn't take care of a sector (window). The caller will
115 * have to multiply the answer by some appropriate constant.
123 float total_sys_area=0.0;
126 if (s == NULL) return 0.0;
129 for (iazm=0; iazm<s->h.nrays; iazm++) {
130 /* get total system volume area */
131 total_sys_area += RSL_area_of_ray(s->ray[iazm], -71, 0.0, min_rng, max_rng);
132 area = RSL_area_of_ray(s->ray[iazm], lo, hi, min_rng, max_rng);
135 fprintf(stderr,"iazm = %d, totalsysarea = %f, area = %f, sweep_area = %f\n",
136 iazm, total_sys_area, area, sweep_area);
139 frac_area = sweep_area / total_sys_area;
140 return (float) frac_area;