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 /*-----------------------------------------------------------------*/
25 /* ray_sort_compare */
26 /* RSL_sort_rays_in_sweep */
27 /* RSL_sort_rays_in_volume */
29 /* By: John Merritt */
30 /* Space Applications Corporation */
33 * Update and Revisions:
36 * int ray_sort_compare_by_time(Ray **r1,Ray **r2);
37 * int sweep_sort_compare(Sweep **s1, Sweep **s2)
38 * Sweep *RSL_sort_rays_by_time(Sweep *s);
39 * Volume *RSL_sort_sweeps_in_volume(Volume *v)
40 * Volume *RSL_sort_volume(Volume *v)
41 * Radar *RSL_sort_radar(Radar *r)
44 * Routines that sort data structures now set the
45 * number of structures in the parent data structure.
47 * Routines set the enum sorted variable in the
48 * appropriate data structure.
53 /*-----------------------------------------------------------------*/
58 static int ray_sort_compare(Ray **r1, Ray **r2)
60 /* Compare azim values. Return -1, 0, 1 for <, =, > comparison. */
61 if (*r1 == NULL) return 1;
62 if (*r2 == NULL) return -1;
64 if ((*r1)->h.azimuth < (*r2)->h.azimuth) return -1;
65 if ((*r1)->h.azimuth > (*r2)->h.azimuth) return 1;
70 static int ray_sort_compare_by_time(Ray **r1, Ray **r2)
72 /* Compare time values. Return -1, 0, 1 for <, =, > comparison. */
74 if (*r1 == NULL) return 1;
75 if (*r2 == NULL) return -1;
77 /* Compare year value */
78 if ((*r1)->h.year < (*r2)->h.year) return -1;
79 if ((*r1)->h.year > (*r2)->h.year) return 1;
81 /* Compare month value */
82 if ((*r1)->h.month < (*r2)->h.month) return -1;
83 if ((*r1)->h.month > (*r2)->h.month) return 1;
85 /* Compare day value */
86 if ((*r1)->h.day < (*r2)->h.day) return -1;
87 if ((*r1)->h.day > (*r2)->h.day) return 1;
89 /* Compare hour value */
90 if ((*r1)->h.hour < (*r2)->h.hour) return -1;
91 if ((*r1)->h.hour > (*r2)->h.hour) return 1;
93 /* Compare minute value */
94 if ((*r1)->h.minute < (*r2)->h.minute) return -1;
95 if ((*r1)->h.minute > (*r2)->h.minute) return 1;
97 /* Compare second value */
98 if ((*r1)->h.sec < (*r2)->h.sec) return -1;
99 if ((*r1)->h.sec > (*r2)->h.sec) return 1;
104 static int sweep_sort_compare(Sweep **s1, Sweep **s2)
106 /* Compare elevation values. Return -1, 0, 1 for <, =, > comparison. */
107 if (*s1 == NULL) return 1;
108 if (*s2 == NULL) return -1;
110 if ((*s1)->h.elev < (*s2)->h.elev) return -1;
111 if ((*s1)->h.elev > (*s2)->h.elev) return 1;
115 Sweep *RSL_sort_rays_in_sweep(Sweep *s)
117 /* Sort rays by azimuth in passed sweep */
120 if (s == NULL) return NULL;
122 qsort((void *)s->ray, s->h.nrays, sizeof(Ray *),
123 (int (*)(const void *, const void *))ray_sort_compare);
125 /* Set nrays values to number of non-NULL indexes.
126 * After sorting this is highest useable index.
128 for(a=s->h.nrays-1; a>=0 ;a--) {
129 if(s->ray[a] != NULL) {
138 Sweep *RSL_sort_rays_by_time(Sweep *s)
140 /* Set rays in passed sweep by time */
143 if (s == NULL) return NULL;
145 qsort((void *)s->ray, s->h.nrays, sizeof(Ray *),
146 (int (*)(const void *, const void *))ray_sort_compare_by_time);
148 /* Set nrays values to number of non-NULL indexes.
149 * After sorting this is highest useable index.
151 for(a=s->h.nrays-1; a>=0 ;a--) {
152 if(s->ray[a] != NULL) {
162 Volume *RSL_sort_rays_in_volume(Volume *v)
164 /* Sort rays in the sweeps pointed to by the volume .
165 * (Does not sort the sweeps pointers)
168 if (v == NULL) return NULL;
170 for (i=0; i<v->h.nsweeps; i++)
171 v->sweep[i] = RSL_sort_rays_in_sweep(v->sweep[i]);
176 Volume *RSL_sort_sweeps_in_volume(Volume *v)
178 /* Sort sweeps pointers in passed volume data structure.
179 * (Does not sort rays in sweeps.)
183 if (v == NULL) return NULL;
185 qsort((void *)v->sweep,v->h.nsweeps,sizeof(Sweep *),
186 (int (*)(const void *, const void *))sweep_sort_compare);
188 /* Set nsweeps value to number of non-NULL indexes.
189 * After sorting, this is the highest usable index.
191 for(a=0;a<v->h.nsweeps;a++)
193 if(v->sweep[a] == NULL)
203 Volume *RSL_sort_volume(Volume *v)
205 /* Sort sweeps and rays by angle in the Volume data structure
209 if(v == NULL) return NULL;
211 v = RSL_sort_sweeps_in_volume(v);
212 v = RSL_sort_rays_in_volume(v);
218 Radar *RSL_sort_radar(Radar *r)
220 /* Sort sweeps and rays in all Volumes of the passed Radar data
225 if(r == NULL) return NULL;
227 for(a=0; a<r->h.nvolumes;a++)
229 r->v[a] = RSL_sort_volume(r->v[a]);