]> Pileus Git - ~andy/rsl/blob - examples/wsr_hist_uf_test.c
615b5726ea6fff99947d90c1bf877b25e82fdec8
[~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
24 #include "rsl.h"
25
26
27 usage()
28 {
29   fprintf(stderr,"Usage: wsr_hist_uf_test infile\n");
30   exit(-1);
31 }
32
33 process_args(int argc, char **argv, char **in_file)
34 {
35   if (argc == 2) *in_file = strdup(argv[1]);
36   else usage();
37 }
38
39
40 main(int argc, char **argv)
41 {
42   char *infile;
43
44   Radar *radar;
45   Histogram *histogram = NULL;
46
47   process_args(argc, argv, &infile);
48   RSL_radar_verbose_on();
49
50   if ((radar = RSL_anyformat_to_radar(infile, "KMLB")) == NULL) {
51         /* RSL_wsr88d_to_radar writes an error message to stdout. */
52         exit(-1);
53   }
54
55 /***********************************************************************/
56 /*                                                                     */
57 /*            You now have a pointer to Radar.                         */
58 /*            Now use *radar all you like.                             */
59 /*                                                                     */
60 /***********************************************************************/
61
62 /* Use radar->v[DZ_INDEX] for REFELECTIVITY
63  *     radar->v[VR_INDEX] for VELOCITY
64  *     radar->v[SW_INDEX] for SPECTRUM_WIDTH
65  */
66   printf("Radar date: %2.2d/%2.2d/%2.2d\n", radar->h.month, radar->h.day, radar->h.year);
67   printf("Radar time: %2.2d:%2.2d:%f\n", radar->h.hour, radar->h.minute, radar->h.sec);
68
69
70   RSL_radar_to_uf(radar, "uf_file.uf");
71   histogram = RSL_get_histogram_from_volume(radar->v[DZ_INDEX],
72                                                                                  histogram, -30, 70, 0, 200);
73   RSL_print_histogram(histogram, 0, 200, "hist_wsr88d_to_radar.dat");
74   RSL_free_radar(radar);
75
76   RSL_radar_verbose_on();
77   printf("RSL_uf_to_radar\n");
78   radar = RSL_uf_to_radar("uf_file.uf");
79   histogram = NULL;  /* There should be a free here. */
80   histogram = RSL_get_histogram_from_volume(radar->v[DZ_INDEX],
81                                                                                  histogram, -30, 70, 0, 200);
82   RSL_print_histogram(histogram, 0, 200, "hist_uf_to_radar.dat");
83
84   exit(0);
85
86 }