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