void RSL_free_cappi(Cappi *c) { if (c == NULL) return; RSL_free_sweep(c->sweep); free(c->loc); free(c); return; }
main (int argc, char **argv) { Radar *new_radar, *tmp_radar, *radar; Sweep *s, *new_sweep; float min_range, max_range, low_azim, hi_azim; int j, i; char type; Volume *new_volume, *v; /* RSL_radar_verbose_on(); */ if (argc < 8) { fprintf(stderr, "%s type(r|v|s) min_range max_range low_azim hi_azim ref_uf_file out_file\n", argv[0]); exit(-1); } i = 1; type = argv[i++][0]; min_range = (float) atoi(argv[i++]); max_range = (float) atoi(argv[i++]); low_azim = (float) atoi(argv[i++]); hi_azim = (float) atoi(argv[i++]); radar = RSL_uf_to_radar(argv[i++]); if (!radar) exit(-1); RSL_load_refl_color_table(); switch(type) { case 'r': case 'v': v = RSL_copy_volume(radar->v[DZ_INDEX]); if (!v) exit(-1); if ((v = RSL_clear_volume(v)) == NULL) exit(-1); printf("volume's nsweeps - %d\n", v->h.nsweeps); for (j = 0; j < v->h.nsweeps; j++) { printf("loading sweep %d\n", j); v->sweep[j] = load_sweep(v->sweep[j]); } /* test get*from radar */ if (type == 'r') { if ((tmp_radar = RSL_new_radar(radar->h.nvolumes)) == NULL) exit (-1); tmp_radar->h = radar->h; tmp_radar->v[DZ_INDEX] = v; new_radar = RSL_get_window_from_radar(tmp_radar,min_range, max_range, low_azim, hi_azim); if (new_radar == NULL) { printf("null new radar\n"); exit(-1); } RSL_volume_to_gif(new_radar->v[DZ_INDEX], argv[i], 500, 500, max_range); RSL_free_radar(tmp_radar); RSL_free_radar(new_radar); } else { new_volume = RSL_get_window_from_volume(v, min_range, max_range, low_azim, hi_azim); if (new_volume != NULL) RSL_volume_to_gif(new_volume, argv[i], 500, 500, max_range); /* RSL_bscan_volume(new_volume); */ RSL_free_volume(new_volume); } break; case 's': s = RSL_copy_sweep(radar->v[DZ_INDEX]->sweep[0]); s = RSL_clear_sweep(s); s = load_sweep(s); if (!s) { printf("null sweep\n"); exit(-1); } new_sweep = RSL_get_window_from_sweep(s, min_range, max_range, low_azim, hi_azim ); RSL_sweep_to_gif(new_sweep, argv[i], 500, 500, max_range); /* RSL_bscan_sweep(new_sweep); */ RSL_free_sweep(new_sweep); break; default: break; } RSL_free_radar(radar); printf("done\n"); exit (0); }
int wsr88d_load_sweep_into_volume(Wsr88d_sweep ws, Volume *v, int nsweep, unsigned int vmask) { int i; int iray; /*float v_data[1000]; Range c_data[1000];*/ /* Increased for super res data */ float v_data[2000]; Range c_data[2000]; int n; int mon, day, year; int hh, mm, ss; float fsec; int vol_cpat; float azm_res_spacing, minbeam_width=1.0; /* S. Chiswell added */ Ray *ray_ptr; Range (*invf)(float x); float (*f)(Range x); /* Allocate memory for MAX_RAYS_IN_SWEEP rays. */ v->sweep[nsweep] = RSL_new_sweep(MAX_RAYS_IN_SWEEP); if (v->sweep[nsweep] == NULL) { perror("wsr88d_load_sweep_into_volume: RSL_new_sweep"); return -1; } v->sweep[nsweep]->h.nrays = 0; f = (float (*)(Range x))NULL; invf = (Range (*)(float x))NULL; if (vmask & WSR88D_DZ) { invf = DZ_INVF; f = DZ_F; } if (vmask & WSR88D_VR) { invf = VR_INVF; f = VR_F; } if (vmask & WSR88D_SW) { invf = SW_INVF; f = SW_F; } v->h.invf = invf; v->h.f = f; v->sweep[nsweep]->h.invf = invf; v->sweep[nsweep]->h.f = f; for (i=0,iray=0; i<MAX_RAYS_IN_SWEEP; i++) { if (ws.ray[i] != NULL) { wsr88d_ray_to_float(ws.ray[i], vmask, v_data, &n); float_to_range(v_data, c_data, n, invf); if (n > 0) { wsr88d_get_date(ws.ray[i], &mon, &day, &year); wsr88d_get_time(ws.ray[i], &hh, &mm, &ss, &fsec); /* fprintf(stderr,"n %d, mon %d, day %d, year %d, hour %d, min %d, sec %d, fsec %f\n", n, mon, day, year, hh, mm, ss, fsec); */ /* * Load the sweep/ray headar information. */ v->sweep[nsweep]->ray[iray] = RSL_new_ray(n); /*(Range *)calloc(n, sizeof(Range)); */ ray_ptr = v->sweep[nsweep]->ray[iray]; /* Make code below readable. */ ray_ptr->h.f = f; ray_ptr->h.invf = invf; ray_ptr->h.month = mon; ray_ptr->h.day = day; ray_ptr->h.year = year + 1900; /* Yes 1900 makes this year 2000 compliant, due to wsr88d using unix time(). */ ray_ptr->h.hour = hh; ray_ptr->h.minute = mm; ray_ptr->h.sec = ss + fsec; ray_ptr->h.unam_rng = wsr88d_get_range (ws.ray[i]); ray_ptr->h.azimuth = wsr88d_get_azimuth (ws.ray[i]); /* -180 to +180 is converted to 0 to 360 */ if (ray_ptr->h.azimuth < 0) ray_ptr->h.azimuth += 360; ray_ptr->h.ray_num = wsr88d_get_ray_num( ws.ray[i] ); ray_ptr->h.elev = wsr88d_get_elevation_angle(ws.ray[i]); ray_ptr->h.elev_num = wsr88d_get_elev_num ( ws.ray[i] ); if (vmask & WSR88D_DZ) { ray_ptr->h.range_bin1 = wsr88d_get_refl_rng( ws.ray[i] ); ray_ptr->h.gate_size = wsr88d_get_refl_size( ws.ray[i] ); } else { ray_ptr->h.range_bin1 = wsr88d_get_dop_rng( ws.ray[i] ); ray_ptr->h.gate_size = wsr88d_get_dop_size( ws.ray[i] ); } /* S. Chiswell */ azm_res_spacing = wsr88d_get_azm_res( ws.ray[i] ); if ( azm_res_spacing < minbeam_width ) minbeam_width = azm_res_spacing ; ray_ptr->h.vel_res = wsr88d_get_velocity_resolution(ws.ray[i]); vol_cpat = wsr88d_get_volume_coverage(ws.ray[i]); switch (vol_cpat) { case 11: ray_ptr->h.sweep_rate = 16.0/5.0; break; case 12: ray_ptr->h.sweep_rate = 17.0/4.2; break; case 21: ray_ptr->h.sweep_rate = 11.0/6.0; break; case 31: ray_ptr->h.sweep_rate = 8.0/10.0; break; case 32: ray_ptr->h.sweep_rate = 7.0/10.0; break; case 121:ray_ptr->h.sweep_rate = 20.0/5.5; break; default: ray_ptr->h.sweep_rate = 0.0; break; } ray_ptr->h.nyq_vel = wsr88d_get_nyquist(ws.ray[i]); ray_ptr->h.azim_rate = wsr88d_get_azimuth_rate(ws.ray[i]); ray_ptr->h.fix_angle = wsr88d_get_fix_angle(ws.ray[i]); ray_ptr->h.pulse_count = wsr88d_get_pulse_count(ws.ray[i]); ray_ptr->h.pulse_width = wsr88d_get_pulse_width(ws.ray[i]); /*ray_ptr->h.beam_width = .95; was hardcoded for old data. S. Chiswell modified below*/ ray_ptr->h.beam_width = azm_res_spacing * .95; /* S. Chiswell */ ray_ptr->h.prf = wsr88d_get_prf(ws.ray[i]); ray_ptr->h.frequency = wsr88d_get_frequency(ws.ray[i]); ray_ptr->h.wavelength = 0.1071; /* Previously called * wsr88d_get_wavelength(ws.ray[i]). * See wsr88d.c for explanation. */ /* It is no coincidence that the 'vmask' and wsr88d datatype * values are the same. We expect 'vmask' to be one of * REFL_MASK, VEL_MASK, or SW_MASK. These match WSR88D_DZ, * WSR88D_VR, and WSR88D_SW in the wsr88d library. */ ray_ptr->h.nbins = n; memcpy(ray_ptr->range, c_data, n*sizeof(Range)); v->sweep[nsweep]->h.nrays = iray+1; v->sweep[nsweep]->h.elev += ray_ptr->h.elev; v->sweep[nsweep]->h.sweep_num = ray_ptr->h.elev_num; iray++; } } } /*v->sweep[nsweep]->h.beam_width = .95; S. Chiswell Modified below for super res data, not fixed beam width v->sweep[nsweep]->h.vert_half_bw = .475; v->sweep[nsweep]->h.horz_half_bw = .475; */ v->sweep[nsweep]->h.beam_width = minbeam_width * .95; v->sweep[nsweep]->h.vert_half_bw = v->sweep[nsweep]->h.beam_width / 2.0; v->sweep[nsweep]->h.horz_half_bw = v->sweep[nsweep]->h.beam_width / 2.0; /* Now calculate the mean elevation angle for this sweep. */ if (v->sweep[nsweep]->h.nrays > 0) v->sweep[nsweep]->h.elev /= v->sweep[nsweep]->h.nrays; else { RSL_free_sweep(v->sweep[nsweep]); /* free(v->sweep[nsweep]); ** No rays loaded, free this sweep. */ v->sweep[nsweep] = NULL; } return 0; }