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