]> Pileus Git - ~andy/rsl/blob - examples/print_hash_table.c
RSL v1.41
[~andy/rsl] / examples / print_hash_table.c
1 /*
2  * Ingest NEXRAD (wsr88d) data and print the azimuth hash table created.
3  *
4  * This example is the most minimum of coding that you need to do
5  * to achieve good results from using the RSL code.
6  *
7  * This is short and sweet to demonstrate the simplicity of use for
8  * the RSL.
9  *
10  */
11
12 #include <stdlib.h>
13 #include "rsl.h"
14
15 void print_link_list(Azimuth_hash *list)
16 {
17   if (list == NULL) {
18         printf("\n");
19         return;
20   }
21   printf("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);
22   print_link_list(list->next);
23 }
24   
25
26 /*
27  * Cannot compile if the hash table is static in volume.c.  For
28  * testing we make it globally known.
29  */
30
31 typedef struct {
32   Sweep *s_addr;
33   Hash_table *hash;
34 } Sweep_list;
35
36 extern int RSL_max_sweeps; /* Initial allocation for sweep_list.
37                                                         * RSL_new_sweep will allocate the space first
38                                                         * time around.
39                                                         */
40 extern int RSL_nsweep_addr; /* A count of sweeps in the table. */
41 extern Sweep_list *RSL_sweep_list;
42 extern int RSL_nextents;
43
44 void print_hash_table (Sweep *s)
45 {
46   int i;
47   int sweep_index;
48   Azimuth_hash *index;
49   float azim;
50   float res;
51
52   if (s == NULL) return;
53   sweep_index = SWEEP_INDEX(s);
54   res = 360.0/RSL_sweep_list[sweep_index].hash->nindexes;
55   printf("Azimuth resolution = %f for %d bins.\n", res, RSL_sweep_list[sweep_index].hash->nindexes);
56   for (i=0; i<RSL_sweep_list[sweep_index].hash->nindexes; i++) {
57         index = RSL_sweep_list[sweep_index].hash->indexes[i];
58         azim = i/res;
59         printf("RSL_sweep_list[%d].hash->indexes[%d] = ", sweep_index, i);
60         
61         if (index == NULL) 
62           printf("IS NULL\n");
63         else 
64           print_link_list(index);
65   }
66 }
67
68 void poke_about_sweep(Sweep *s)
69 {
70   /* This routine demonstrates that the azimuth we want is the azimuth
71    * we get.
72    */
73   float azim, res;
74   Ray *ray;
75
76   ray = RSL_get_first_ray_of_sweep(s);
77   res = 360.0/s->h.nrays;
78   for (azim=0; azim<360; azim+=res) {
79         ray = RSL_get_ray_from_sweep(s, azim);
80         if (ray)
81           printf("Azimuth %f matched in ray # %d, h.azimuth= %f, diff=%f\n",
82                          azim, ray->h.ray_num, ray->h.azimuth,
83                          ray->h.azimuth-azim);
84         else
85           printf("Azimuth %f NOT FOUND within 1/2 beamwidth; 1/2beam=%f\n",
86                          azim, s->h.horz_half_bw);
87   }
88 }
89
90
91 int main(int argc, char **argv)
92 {
93   Radar *radar;
94   Sweep *sweep;
95
96   if (argc != 3) {fprintf(stderr, "Usage: %s infile callid_or_firstfile\n", argv[0]); exit(-1);}
97   RSL_radar_verbose_on();
98   radar = RSL_wsr88d_to_radar(argv[1], argv[2]);
99   if (radar == NULL) exit(-1);
100 /***********************************************************************/
101 /*                                                                     */
102 /*            You now have a pointer to Radar.                         */
103 /*            Now use *radar all you like.                             */
104 /*                                                                     */
105 /***********************************************************************/
106
107 /* Use radar->v[DZ_INDEX] for REFELECTIVITY
108  *     radar->v[VR_INDEX] for VELOCITY
109  *     radar->v[SW_INDEX] for SPECTRUM_WIDTH
110  */
111
112   sweep = RSL_get_first_sweep_of_volume(radar->v[DZ_INDEX]);
113   print_hash_table(sweep);
114
115   poke_about_sweep(sweep);
116
117   exit(0);
118
119 }
120
121
122