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