]> Pileus Git - ~andy/rsl/blob - examples/sector.c
Merge branch 'master' into aweather
[~andy/rsl] / examples / sector.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "rsl.h"
4
5 /*
6  * Cannot compile if the hash table is static in volume.c.  For
7  * testing we make it globally known.
8  */
9
10 typedef struct {
11   Sweep *s_addr;
12   Hash_table *hash;
13 } Sweep_list;
14
15 extern int RSL_max_sweeps; /* Initial allocation for sweep_list.
16                                                         * RSL_new_sweep will allocate the space first
17                                                         * time around.
18                                                         */
19 extern int RSL_nsweep_addr; /* A count of sweeps in the table. */
20 extern Sweep_list *RSL_sweep_list;
21 extern int RSL_nextents;
22
23
24 void print_link_list(Azimuth_hash *list)
25 {
26   if (list == NULL) {
27         printf("\n");
28         return;
29   }
30   printf("ray# %d azim %f |", list->ray->h.ray_num, list->ray->h.azimuth);
31   print_link_list(list->next);
32 }
33   
34
35 void print_hash_table (Sweep *s)
36 {
37   int i;
38   int sweep_index;
39   Azimuth_hash *index;
40   float azim;
41   float res;
42   int SWEEP_INDEX(Sweep *s); // From Volume.c
43
44   if (s == NULL) return;
45   sweep_index = SWEEP_INDEX(s);
46   res = 360.0/RSL_sweep_list[sweep_index].hash->nindexes;
47   printf("Azimuth resolution = %f for %d bins.\n", res, RSL_sweep_list[sweep_index].hash->nindexes);
48   for (i=0; i<RSL_sweep_list[sweep_index].hash->nindexes; i++) {
49         index = RSL_sweep_list[sweep_index].hash->indexes[i];
50         azim = i/res;
51         printf("RSL_sweep_list[%d].hash->indexes[%d] = ", sweep_index, i);
52         
53         if (index == NULL) 
54           printf("IS NULL\n");
55         else 
56           print_link_list(index);
57   }
58 }
59
60 Sweep * get_sector(Sweep *s, float lo_azimuth, float hi_azimuth)
61 {
62   int   i, j;
63   Sweep *new_sweep;
64
65   if (s == NULL) return NULL;
66
67   if ((new_sweep = RSL_new_sweep(s->h.nrays)) == NULL)
68         return NULL;
69   new_sweep->h = s->h;
70
71   for (i = 0,j = 0; i < s->h.nrays; i++) {
72         if (s->ray[i] == NULL) continue;
73         if (s->ray[i]->h.azimuth >= lo_azimuth && 
74                 s->ray[i]->h.azimuth < hi_azimuth) {
75
76
77           new_sweep->ray[j] =RSL_copy_ray(s->ray[i]);
78
79           j++;
80         }
81   }
82
83   return new_sweep;
84
85 }
86
87
88 int main(int argc, char **argv)
89 {
90   Radar *radar;
91   Sweep *sector;
92
93   if (argc != 3) {fprintf(stderr, "Usage: %s infile callid_or_firstfile\n", argv[0]); exit(-1);}
94   RSL_radar_verbose_on();
95   radar = RSL_wsr88d_to_radar(argv[1], argv[2]);
96   if (radar == NULL) exit(-1);
97
98   RSL_load_refl_color_table();
99
100   sector = get_sector(radar->v[DZ_INDEX]->sweep[0], 0.0, 90.0);
101
102 /*  sector = RSL_copy_sweep(radar->v[DZ_INDEX]->sweep[0]);
103 */
104   
105   print_hash_table(sector);
106
107   RSL_sweep_to_gif(sector, "dz_sector.gif", 400, 400, 200.0);
108
109   exit(0);
110
111 }