2 * Ingest NEXRAD (wsr88d) data and output images representing
3 * all field types found.
5 * This example is the most minimum of coding that you need to do
6 * to achieve good results from using the RSL code.
8 * This is short and sweet to demonstrate the simplicity of use for
16 /* Example use for getopt; argument processing */
18 * Remember that to pass back strings you must pass the
19 * address of the pointer to the string; argument is char **.
20 * (Note: arrays of characters; the name is char **)
23 * process_args(... &file);
24 * DECLARE as: process_args(... char **file)
25 * *file = strdup(argv[optind]);
28 * process_args(... infile ...);
29 * DECLARE as: process_args(... char *infile ...)
30 * strcpy(infile, argv[optind]);
36 int usage(char **argv)
38 fprintf(stderr, "Usage: %s (v1.20) [-v] [-V] [-x n] [-y n] [-r x] infile [callid_or_firstfile]\n\n", argv[0]);
39 fprintf(stderr, "Where: -v = verbose print. Default = no printing.\n");
40 fprintf(stderr, " -V = Output entire volume. Default = output first sweep only.\n");
41 fprintf(stderr, " -x n = Image dimension, image is n x n pixels. Default = 400x400 pixels.\n");
42 fprintf(stderr, " -r x = Range of radar data. Default = 400.0 km.\n");
43 fprintf(stderr, " -b x = Make black for dbz below x. Default = 0 (no action).\n");
46 process_args(int argc, char **argv,
47 char **in_file, char **callid, int *verbose, int *wholevolume,
48 int *xdim, float *range, int *dbz_black)
52 while ((c = getopt(argc, argv, "x:r:b:vV")) != -1)
54 case 'v': *verbose = 1; break;
55 case 'V': *wholevolume = 1; break;
56 case 'x': *xdim = atoi(optarg); break;
57 case 'r': *range = atof(optarg); break;
58 case 'b': *dbz_black = atoi(optarg); break;
59 case '?': usage(argv); break;
63 /* must have 2 files listed */
64 if (argc - optind != 1 && argc - optind != 2) usage(argv);
66 /* Can use strdup, if desired */
67 /* strdup allocates memory */
68 /* in_file = strdup(argv[optind]); */
69 *in_file = strdup(argv[optind]);
70 if (argc - optind == 2) *callid = strdup(argv[optind+1]);
76 int main(int argc, char **argv)
83 char *infile, *callid;
84 char time_string[100];
96 process_args(argc, argv, &infile, &callid, &verbose, &wholevolume,
97 &xdim, &range, &dbz_black);
100 RSL_radar_verbose_on(); /* Not needed; it bides the time. */
101 RSL_select_fields("all", NULL);
102 RSL_read_these_sweeps("all", NULL);
103 radar = RSL_anyformat_to_radar(infile, callid);
105 if (radar == NULL) exit(-1);
108 RSL_write_radar(radar, "rsl.rsl");
112 sprintf(time_string,"%2.2d%2.2d%2.2d_%2.2d%2.2d",
113 radar->h.month, radar->h.day, radar->h.year-1900,
114 radar->h.hour, radar->h.minute);
116 for (i=0; i<MAX_RADAR_VOLUMES; i++) {
117 sweep = RSL_get_first_sweep_of_volume(radar->v[i]);
118 ray = RSL_get_first_ray_of_volume(radar->v[i]);
122 RSL_load_sw_color_table();
123 else if (i == VR_INDEX || i == VE_INDEX) {
124 RSL_load_vel_color_table();
125 RSL_rebin_velocity_volume(radar->v[i]);
127 RSL_load_refl_color_table();
130 char r[256], g[256], b[256];
133 RSL_get_color_table(RSL_RED_TABLE, r, &nc);
134 RSL_get_color_table(RSL_GREEN_TABLE, g, &nc);
135 RSL_get_color_table(RSL_BLUE_TABLE, b, &nc);
136 for (i=0; i<dbz_black; i++) {
141 RSL_set_color_table(RSL_RED_TABLE, r, nc);
142 RSL_set_color_table(RSL_GREEN_TABLE, g, nc);
143 RSL_set_color_table(RSL_BLUE_TABLE, b, nc);
145 memcpy(fname,radar->h.name, sizeof(radar->h.name));
146 for (j=0; j<sizeof(radar->h.name); j++)
147 if (fname[j] == '\0' || fname[j] == ' ') break;
148 if (j==sizeof(radar->h.name)) j--;
151 sprintf(&fname[j], "_%s_%s.gif", RSL_ftype[i], time_string);
152 /* printf("FNAME = <%s>\n", fname); */
153 RSL_sweep_to_gif(sweep, fname, xdim, xdim, range);
154 printf("%s\n", fname);
156 sprintf(&fname[j], "_%s_%s", RSL_ftype[i], time_string);
157 /* RSL_volume_to_gif outputs to stdout the filenames produced. */
158 RSL_volume_to_gif(radar->v[i], fname, xdim, xdim, range);