]> Pileus Git - ~andy/rsl/blob - prune.c
RSL v1.44
[~andy/rsl] / prune.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  * The PRUNE functions eliminate NULL or non-present (no data present)
25  * substructures.  This tightens the structures for output.  Development
26  * was sparked by failing NCAR UF ingest programs; they cannot handle
27  * 0 sized volumes/sweeps/rays dispite conformity to the UF specification.
28  *
29  * These routines free memory that is pruned.
30  *
31  * John H. Merritt
32  * Space Applications Corporation
33  * December 12, 1995
34  */
35
36 #include "rsl.h"
37 extern int radar_verbose_flag;
38
39 Ray *RSL_prune_ray(Ray *ray)
40 {
41   if (ray == NULL) return NULL;
42   if (ray->h.nbins > 0) return ray;
43   RSL_free_ray(ray);
44   return NULL;
45 }
46
47 Sweep *RSL_prune_sweep(Sweep *s)
48 {
49   int i, j;
50
51   if (s == NULL) return NULL;
52   if (s->h.nrays == 0) {
53         RSL_free_sweep(s);
54         return NULL;
55   }
56 /*
57  * Squash out all dataless rays.  'j' is the index for the squashed (pruned)
58  * rays.
59  */
60   for (i=0,j=0; i<s->h.nrays; i++)
61         if ((s->ray[i] = RSL_prune_ray(s->ray[i])))
62           s->ray[j++] = s->ray[i]; /* Keep this ray. */
63
64   if (j==0) {
65         RSL_free_sweep(s);
66         return NULL; /* All rays were pruned. */
67   }
68   for (i=j; i<s->h.nrays; i++) s->ray[i] = NULL;
69   s->h.nrays = j;
70   return s;
71 }
72
73 Volume *RSL_prune_volume(Volume *v)
74 {
75   int i, j;
76
77   if (v == NULL) return NULL;
78   if (v->h.nsweeps == 0) {
79         RSL_free_volume(v);
80         return NULL;
81   }
82 /*
83  * Squash out all dataless sweeps.  'j' is the index for sweep containing data.
84  */
85   for (i=0,j=0; i<v->h.nsweeps; i++)
86         if ((v->sweep[i] = RSL_prune_sweep(v->sweep[i])))
87           v->sweep[j++] = v->sweep[i]; /* Keep this sweep. */
88
89   if (j==0) {
90         RSL_free_volume(v);
91         return NULL; /* All sweeps were pruned. */
92   }
93   for (i=j; i<v->h.nsweeps; i++) v->sweep[i] = NULL;
94   v->h.nsweeps = j;
95   return v;
96 }
97
98 Radar *RSL_prune_radar(Radar *radar)
99 {
100   int i;
101   /* Volume indexes are fixed so we just prune the substructures. */
102   if (radar == NULL) return NULL;
103   for (i=0; i<radar->h.nvolumes; i++)
104         radar->v[i] = RSL_prune_volume(radar->v[i]);
105
106   return radar;
107 }