]> Pileus Git - ~andy/rsl/blob - examples/killer_sweep.c
Change RSL variables from static to extern
[~andy/rsl] / examples / killer_sweep.c
1 /*
2  * This app tests what happens when a sweep has just one azimuth bin for
3  * all the rays.  I will first read real data then permute the sweeps.
4  * Then, I'll check how the hash table were built.  Based on print_hash_table.
5  */
6
7 #include "rsl.h"
8 #include <stdlib.h>
9 #include <limits.h>
10 void print_link_list(Azimuth_hash *list)
11 {
12   if (list == NULL) {
13         printf("\n");
14         return;
15   }
16   printf("\n            ray# %d azim %f, hi# %d lo# %d", list->ray->h.ray_num, list->ray->h.azimuth, list->ray_high->ray->h.ray_num, list->ray_low->ray->h.ray_num);
17   print_link_list(list->next);
18 }
19   
20
21 /*
22  * Cannot compile if the hash table is static in volume.c.  For
23  * testing we make it globally known.
24  */
25
26 typedef struct {
27   Sweep *s_addr;
28   Hash_table *hash;
29 } Sweep_list;
30
31 extern int RSL_max_sweeps; /* Initial allocation for sweep_list.
32                                                         * RSL_new_sweep will allocate the space first
33                                                         * time around.
34                                                         */
35 extern int RSL_nsweep_addr; /* A count of sweeps in the table. */
36 extern Sweep_list *RSL_sweep_list;
37 extern int RSL_nextents;
38
39 void print_hash_table (Sweep *s)
40 {
41   int i;
42   int sweep_index;
43   Azimuth_hash *index;
44   float azim;
45   float res;
46   int SWEEP_INDEX(Sweep *s); // From Volume.c
47
48   if (s == NULL) return;
49   sweep_index = SWEEP_INDEX(s);
50   res = 360.0/RSL_sweep_list[sweep_index].hash->nindexes;
51   printf("Azimuth resolution = %f for %d bins.\n", res, RSL_sweep_list[sweep_index].hash->nindexes);
52   for (i=0; i<RSL_sweep_list[sweep_index].hash->nindexes; i++) {
53         index = RSL_sweep_list[sweep_index].hash->indexes[i];
54         azim = i/res;
55         printf("RSL_sweep_list[%d].hash->indexes[%d] = ", sweep_index, i);
56         
57         if (index == NULL) 
58           printf("IS NULL\n");
59         else 
60           print_link_list(index);
61   }
62 }
63
64 void poke_about_sweep(Sweep *s)
65 {
66   /* This routine demonstrates that the azimuth we want is the azimuth
67    * we get.
68    */
69   float azim, res;
70   Ray *ray;
71
72   ray = RSL_get_first_ray_of_sweep(s);
73   res = 360.0/s->h.nrays;
74   for (azim=0; azim<360; azim+=res) {
75         ray = RSL_get_ray_from_sweep(s, azim);
76         if (ray)
77           printf("Azimuth %f matched in ray # %d, h.azimuth= %f, diff=%f\n",
78                          azim, ray->h.ray_num, ray->h.azimuth,
79                          ray->h.azimuth-azim);
80         else
81           printf("Azimuth %f NOT FOUND within 1/2 beamwidth; 1/2beam=%f\n",
82                          azim, s->h.horz_half_bw);
83   }
84 }
85
86 float random_azim(void)
87 {
88   return (float)rand() / INT_MAX;
89 }
90
91 Sweep *permute_sweep(Sweep *sweep)
92 {
93   int i;
94   Ray *ray;
95   if (sweep == NULL) return NULL;
96   for (i=0; i<sweep->h.nrays; i++) {
97         ray = sweep->ray[i];
98         if (ray == NULL) continue;
99         ray->h.azimuth = random_azim();
100   }
101   return sweep;
102 }
103 Volume *permute_volume(Volume *volume)
104 {
105   int i;
106   if (volume == NULL) return NULL;
107   for (i=0; i<volume->h.nsweeps; i++)
108         volume->sweep[i] = permute_sweep(volume->sweep[i]);
109   return volume;
110 }
111 Radar *permute_radar(Radar *radar)
112 {
113   int i;
114   if (radar == NULL) return NULL;
115   for (i=0; i<radar->h.nvolumes; i++)
116         radar->v[i] = permute_volume(radar->v[i]);
117   printf("Radar permuted.  Now, redo the ray_indexes.\n");
118   return radar;
119 }
120
121 void chase_hi_links(Sweep *sweep)
122 {
123   int i;
124   Azimuth_hash *table;
125   Hash_table *hash_table;
126   float last_azimuth;
127   float azimuth;
128
129   if (sweep == NULL) return;
130   hash_table = hash_table_for_sweep(sweep);
131   table = hash_table->indexes[0];
132
133   printf("Printing HI links.  This has better be a sorted output.\n");
134   printf("ELEVATION angle = %f\n", sweep->h.elev);
135   for (i=0, last_azimuth=-1;i<sweep->h.nrays; i++) {
136         if (table == NULL) continue;
137         printf("   ray# %3d azim %8.6f hi# %3d lo# %3d\n",
138                    table->ray->h.ray_num,
139                    table->ray->h.azimuth,
140                    table->ray_high->ray->h.ray_num,
141                    table->ray_low->ray->h.ray_num);
142         azimuth = table->ray->h.azimuth;
143         if (azimuth < last_azimuth) printf("AZIMUTH OUT OF ORDER\n");
144         last_azimuth = azimuth;
145         table = table->ray_high;
146   }
147 }
148
149 int main(int argc, char **argv)
150 {
151   Radar *radar;
152   Sweep *sweep;
153   int i;
154
155   if (argc < 2 || argc > 3) {fprintf(stderr, "Usage: %s infile [callid_or_firstfile]\n", argv[0]); exit(-1);}
156   RSL_radar_verbose_on();
157   radar = RSL_anyformat_to_radar(argv[1], argv[2]);
158   if (radar == NULL) {
159         printf("RADAR IS NULL.\n");
160         exit(-1);
161   }
162
163   printf("permute_radar\n");
164   radar = permute_radar(radar);
165
166   for (i=0; i<radar->v[DZ_INDEX]->h.nsweeps; i++) {
167         sweep = radar->v[DZ_INDEX]->sweep[i];
168         chase_hi_links(sweep);
169   }
170 /*
171   print_hash_table(sweep);
172
173   poke_about_sweep(sweep);
174 */
175   exit(0);
176
177 }
178
179
180