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.
23 /**********************************************************************/
24 /* By: John Merritt */
25 /* Space Applications Corporation */
27 /**********************************************************************/
33 /**********************************************************************/
35 /* RSL_fraction_of_ray */
36 /* RSL_fraction_of_sweep */
37 /* RSL_fraction_of_volume */
39 /* Compute fraction of dBz within a specified range. */
40 /* Loops are unrolled in each higher function because we are */
41 /* computing fractiion. I thought about a returning a Ratio */
42 /* structure, but dismissed it. */
44 /**********************************************************************/
51 Frac_ratio RSL_ratio_of_ray(Ray *r, float lo, float hi, float range)
54 int ibin_range; /* Maximum bin include, based on range. */
59 if (r == NULL) return fr;
61 ibin_range = range /( (float)r->h.gate_size / 1000.0 );
62 if (ibin_range > r->h.nbins) ibin_range = r->h.nbins;
63 for (i=0; i<ibin_range; i++) {
64 if (lo <= r->h.f(r->range[i]) && r->h.f(r->range[i]) <= hi) fr.n++;
70 float RSL_fraction_of_ray(Ray *r, float lo, float hi, float range)
74 fr = RSL_ratio_of_ray(r, lo, hi, range);
75 return (float)fr.n / (float)fr.ntotal;
79 Frac_ratio RSL_ratio_of_sweep(Sweep *s, float lo, float hi, float range)
81 Frac_ratio total_ratio;
85 total_ratio.n = total_ratio.ntotal = 0;
86 if (s == NULL) return total_ratio;
87 for (i = 0; i<s->h.nrays; i++) {
88 ray_ratio = RSL_ratio_of_ray(s->ray[i], lo, hi, range);
89 total_ratio.n += ray_ratio.n;
90 total_ratio.ntotal += ray_ratio.ntotal;
96 float RSL_fraction_of_sweep(Sweep *s, float lo, float hi, float range)
100 fr = RSL_ratio_of_sweep(s, lo, hi, range);
101 return (float)fr.n / (float)fr.ntotal;
106 Frac_ratio RSL_ratio_of_volume(Volume *v, float lo, float hi, float range)
108 Frac_ratio total_ratio;
109 Frac_ratio sweep_ratio;
112 total_ratio.n = total_ratio.ntotal = 0;
113 if (v == NULL) return total_ratio;
114 for (i = 0; i<v->h.nsweeps; i++) {
115 sweep_ratio = RSL_ratio_of_sweep(v->sweep[i], lo, hi, range);
116 total_ratio.n += sweep_ratio.n;
117 total_ratio.ntotal += sweep_ratio.ntotal;
123 float RSL_fraction_of_volume(Volume *v, float lo, float hi, float range)
127 fr = RSL_ratio_of_volume(v, lo, hi, range);
128 return (float)fr.n / (float)fr.ntotal;