]> Pileus Git - ~andy/rsl/blob - examples/killer_sweep.c
139b231efbd790fae3150a546c58b6f134f89775
[~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
46   if (s == NULL) return;
47   sweep_index = SWEEP_INDEX(s);
48   res = 360.0/RSL_sweep_list[sweep_index].hash->nindexes;
49   printf("Azimuth resolution = %f for %d bins.\n", res, RSL_sweep_list[sweep_index].hash->nindexes);
50   for (i=0; i<RSL_sweep_list[sweep_index].hash->nindexes; i++) {
51         index = RSL_sweep_list[sweep_index].hash->indexes[i];
52         azim = i/res;
53         printf("RSL_sweep_list[%d].hash->indexes[%d] = ", sweep_index, i);
54         
55         if (index == NULL) 
56           printf("IS NULL\n");
57         else 
58           print_link_list(index);
59   }
60 }
61
62 void poke_about_sweep(Sweep *s)
63 {
64   /* This routine demonstrates that the azimuth we want is the azimuth
65    * we get.
66    */
67   float azim, res;
68   Ray *ray;
69
70   ray = RSL_get_first_ray_of_sweep(s);
71   res = 360.0/s->h.nrays;
72   for (azim=0; azim<360; azim+=res) {
73         ray = RSL_get_ray_from_sweep(s, azim);
74         if (ray)
75           printf("Azimuth %f matched in ray # %d, h.azimuth= %f, diff=%f\n",
76                          azim, ray->h.ray_num, ray->h.azimuth,
77                          ray->h.azimuth-azim);
78         else
79           printf("Azimuth %f NOT FOUND within 1/2 beamwidth; 1/2beam=%f\n",
80                          azim, s->h.horz_half_bw);
81   }
82 }
83
84 float random_azim(void)
85 {
86   double drand;
87   drand = drand48()*1;
88   return (float)drand;
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 void 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