]> Pileus Git - ~andy/rsl/blob - examples/wsr_hist_uf_test.c
Changes from Bart (2011-02-01)
[~andy/rsl] / examples / wsr_hist_uf_test.c
1 /*
2  * Test reading and writing of UF files by using the histogram function.
3  *
4  * 1. Read WSR88D file.
5  * 2. Print histogram of DZ volume.
6  * 3. Output Radar to UF.
7  * 3. Free Radar structure.
8  * 4. Read UF into Radar.
9  * 5. Print histogram of DZ volume.
10  *
11  * The two outputted histograms should be identical.
12  *
13  */
14
15
16
17 #include <stdio.h>
18 #ifdef sgi
19 #include <getopt.h>
20 #endif
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24
25 #include "rsl.h"
26
27
28 usage()
29 {
30   fprintf(stderr,"Usage: wsr_hist_uf_test infile [-s site_id]\n");
31   exit(-1);
32 }
33
34 process_args(int argc, char **argv, char **in_file, char **site)
35 {
36   int c;
37   
38   while ((c = getopt(argc, argv, "s:")) != -1)
39         switch (c) {
40         case 's': *site = strdup(optarg); break;
41         case '?': usage(argv); break;
42         default:  break;
43         }
44   if (argc - optind == 1) *in_file = strdup(argv[optind]);
45   else usage();
46 }
47
48
49 main(int argc, char **argv)
50 {
51   char *infile;
52   char *site = NULL;
53
54   Radar *radar;
55   Histogram *histogram = NULL;
56
57   process_args(argc, argv, &infile, &site);
58   RSL_radar_verbose_on();
59
60   if ((radar = RSL_anyformat_to_radar(infile, site)) == NULL) {
61         /* RSL_wsr88d_to_radar writes an error message to stdout. */
62         exit(-1);
63   }
64
65 /***********************************************************************/
66 /*                                                                     */
67 /*            You now have a pointer to Radar.                         */
68 /*            Now use *radar all you like.                             */
69 /*                                                                     */
70 /***********************************************************************/
71
72 /* Use radar->v[DZ_INDEX] for REFELECTIVITY
73  *     radar->v[VR_INDEX] for VELOCITY
74  *     radar->v[SW_INDEX] for SPECTRUM_WIDTH
75  */
76   printf("Radar date: %2.2d/%2.2d/%2.2d\n", radar->h.month, radar->h.day, radar->h.year);
77   printf("Radar time: %2.2d:%2.2d:%f\n", radar->h.hour, radar->h.minute, radar->h.sec);
78
79
80   RSL_radar_to_uf(radar, "uf_file.uf");
81   histogram = RSL_get_histogram_from_volume(radar->v[DZ_INDEX],
82                                                                                  histogram, -30, 70, 0, 200);
83   RSL_print_histogram(histogram, 0, 200, "hist_wsr88d_to_radar.dat");
84   RSL_free_radar(radar);
85
86   RSL_radar_verbose_on();
87   printf("RSL_uf_to_radar\n");
88   radar = RSL_uf_to_radar("uf_file.uf");
89   histogram = NULL;  /* There should be a free here. */
90   histogram = RSL_get_histogram_from_volume(radar->v[DZ_INDEX],
91                                                                                  histogram, -30, 70, 0, 200);
92   RSL_print_histogram(histogram, 0, 200, "hist_uf_to_radar.dat");
93
94   exit(0);
95
96 }