1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
/*
NASA/TRMM, Code 910.1.
This is the TRMM Office Radar Software Library.
Copyright (C) 1996, 1997
John H. Merritt
Space Applications Corporation
Vienna, Virginia
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*-----------------------------------------------------------------*/
/* */
/* ray_sort_compare */
/* RSL_sort_rays_in_sweep */
/* RSL_sort_rays_in_volume */
/* */
/* By: John Merritt */
/* Space Applications Corporation */
/* August 26, 1994 */
/*
* Update and Revisions:
*
* New Routines:
* int ray_sort_compare_by_time(Ray **r1,Ray **r2);
* int sweep_sort_compare(Sweep **s1, Sweep **s2)
* Sweep *RSL_sort_rays_by_time(Sweep *s);
* Volume *RSL_sort_sweeps_in_volume(Volume *v)
* Volume *RSL_sort_volume(Volume *v)
* Radar *RSL_sort_radar(Radar *r)
*
* Modifications:
* Routines that sort data structures now set the
* number of structures in the parent data structure.
*
* Routines set the enum sorted variable in the
* appropriate data structure.
*
* Dennis Flanigan,Jr.
* 3/23/95
*/
/*-----------------------------------------------------------------*/
#include <stdlib.h>
#include "rsl.h"
static int ray_sort_compare(Ray **r1, Ray **r2)
{
/* Compare azim values. Return -1, 0, 1 for <, =, > comparison. */
if (*r1 == NULL) return 1;
if (*r2 == NULL) return -1;
if ((*r1)->h.azimuth < (*r2)->h.azimuth) return -1;
if ((*r1)->h.azimuth > (*r2)->h.azimuth) return 1;
return 0;
}
static int ray_sort_compare_by_time(Ray **r1, Ray **r2)
{
/* Compare time values. Return -1, 0, 1 for <, =, > comparison. */
if (*r1 == NULL) return 1;
if (*r2 == NULL) return -1;
/* Compare year value */
if ((*r1)->h.year < (*r2)->h.year) return -1;
if ((*r1)->h.year > (*r2)->h.year) return 1;
/* Compare month value */
if ((*r1)->h.month < (*r2)->h.month) return -1;
if ((*r1)->h.month > (*r2)->h.month) return 1;
/* Compare day value */
if ((*r1)->h.day < (*r2)->h.day) return -1;
if ((*r1)->h.day > (*r2)->h.day) return 1;
/* Compare hour value */
if ((*r1)->h.hour < (*r2)->h.hour) return -1;
if ((*r1)->h.hour > (*r2)->h.hour) return 1;
/* Compare minute value */
if ((*r1)->h.minute < (*r2)->h.minute) return -1;
if ((*r1)->h.minute > (*r2)->h.minute) return 1;
/* Compare second value */
if ((*r1)->h.sec < (*r2)->h.sec) return -1;
if ((*r1)->h.sec > (*r2)->h.sec) return 1;
return 0;
}
static int sweep_sort_compare(Sweep **s1, Sweep **s2)
{
/* Compare elevation values. Return -1, 0, 1 for <, =, > comparison. */
if (*s1 == NULL) return 1;
if (*s2 == NULL) return -1;
if ((*s1)->h.elev < (*s2)->h.elev) return -1;
if ((*s1)->h.elev > (*s2)->h.elev) return 1;
return 0;
}
Sweep *RSL_sort_rays_in_sweep(Sweep *s)
{
/* Sort rays by azimuth in passed sweep */
int a;
if (s == NULL) return NULL;
qsort((void *)s->ray, s->h.nrays, sizeof(Ray *),
(int (*)(const void *, const void *))ray_sort_compare);
/* Set nrays values to number of non-NULL indexes.
* After sorting this is highest useable index.
*/
for(a=s->h.nrays-1; a>=0 ;a--) {
if(s->ray[a] != NULL) {
s->h.nrays = a+1;
break;
}
}
return s;
}
Sweep *RSL_sort_rays_by_time(Sweep *s)
{
/* Set rays in passed sweep by time */
int a;
if (s == NULL) return NULL;
qsort((void *)s->ray, s->h.nrays, sizeof(Ray *),
(int (*)(const void *, const void *))ray_sort_compare_by_time);
/* Set nrays values to number of non-NULL indexes.
* After sorting this is highest useable index.
*/
for(a=s->h.nrays-1; a>=0 ;a--) {
if(s->ray[a] != NULL) {
s->h.nrays = a+1;
break;
}
}
return s;
}
Volume *RSL_sort_rays_in_volume(Volume *v)
{
/* Sort rays in the sweeps pointed to by the volume .
* (Does not sort the sweeps pointers)
*/
int i;
if (v == NULL) return NULL;
for (i=0; i<v->h.nsweeps; i++)
v->sweep[i] = RSL_sort_rays_in_sweep(v->sweep[i]);
return v;
}
Volume *RSL_sort_sweeps_in_volume(Volume *v)
{
/* Sort sweeps pointers in passed volume data structure.
* (Does not sort rays in sweeps.)
*/
int a;
if (v == NULL) return NULL;
qsort((void *)v->sweep,v->h.nsweeps,sizeof(Sweep *),
(int (*)(const void *, const void *))sweep_sort_compare);
/* Set nsweeps value to number of non-NULL indexes.
* After sorting, this is the highest usable index.
*/
for(a=0;a<v->h.nsweeps;a++)
{
if(v->sweep[a] == NULL)
{
v->h.nsweeps = a;
break;
}
}
return v;
}
Volume *RSL_sort_volume(Volume *v)
{
/* Sort sweeps and rays by angle in the Volume data structure
* passed.
*/
if(v == NULL) return NULL;
v = RSL_sort_sweeps_in_volume(v);
v = RSL_sort_rays_in_volume(v);
return v;
}
Radar *RSL_sort_radar(Radar *r)
{
/* Sort sweeps and rays in all Volumes of the passed Radar data
* structure.
*/
int a;
if(r == NULL) return NULL;
for(a=0; a<r->h.nvolumes;a++)
{
r->v[a] = RSL_sort_volume(r->v[a]);
}
return r;
}
|