-
Notifications
You must be signed in to change notification settings - Fork 6
/
radtec_to_radar.c
216 lines (190 loc) · 7.7 KB
/
radtec_to_radar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
NASA/TRMM, Code 910.1.
This is the TRMM Office Radar Software Library.
Copyright (C) 1996, 1997, 1998
John H. Merritt
Space Applications Corporation
Vienna, Virginia
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include "rsl.h"
#ifdef HAVE_LIBIMPLODE
#include "radtec.h"
extern int radar_verbose_flag;
static void fill_ray_header(Ray_header *h, Radtec_header *rh, Radtec_ray_header *rrh)
{
/* Fill the limited ray header information. */
h->month = rh->month; /* Time for this ray; month (1-12). */
h->day = rh->day; /* Time for this ray; day (1-31). */
h->year = rh->year; /* Time for this ray; year (eg. 1993). */
h->hour = rrh->hour; /* Date for this ray; hour (0-23). */
h->minute = rrh->min;/* Date for this ray; minute (0-59).*/
h->sec = rrh->sec; /* Date for this ray; second + fraction of second. */
h->azimuth = rrh->azim_angle; /* Azimuth angle. (degrees). Must be positive
* 0=North, 90=east, -90/270=west.
* This angle is the mean azimuth for the whole ray.
* Eg. for NSIG the beginning and end azimuths are
* averaged.
*/
h->ray_num = rrh->ray_num; /* Ray no. within elevation scan. */
h->elev = rrh->elev_angle; /* Elevation angle. (degrees). */
h->gate_size = rh->range_bin_size * RSL_SPEED_OF_LIGHT / 1e6; /* Data gate size (meters)*/
h->lat = rh->site_latitude; /* Latitude (degrees) */
h->lon = rh->site_longitude; /* Longitude (degrees) */
h->alt = rh->site_elevation; /* Altitude (m) */
h->nbins = rh->num_range_bins; /* Number of array elements for 'Range'. */
h->beam_width = rh->azim_resolution; /* Beamwidth in degrees. */
#ifdef RADTEC_UNKNOWN
h->unam_rng = 0; /* Unambiguous range. (KM). */
h->elev_num = 0; /* Elevation no. within volume scan. */
h->range_bin1 = 0; /* Range to first gate.(meters) */
h-> vel_res = 0; /* Doppler velocity resolution */
h->sweep_rate = 0; /* Sweep rate. Full sweeps/min. */
h->prf = 0; /* Pulse repetition frequency, in Hz. */
h->azim_rate; /* degrees/sec */
h->fix_angle;
h->pitch; /* Pitch angle. */
h->roll; /* Roll angle. */
h->heading; /* Heading. */
h->pitch_rate; /* (angle/sec) */
h->roll_rate; /* (angle/sec) */
h->heading_rate; /* (angle/sec) */
h->rvc; /* Radial velocity correction (m/sec) */
h->vel_east; /* Platform velocity to the east (m/sec) */
h->vel_north; /* Platform velocity to the north (m/sec) */
h->vel_up; /* Platform velocity toward up (m/sec) */
h->pulse_count; /* Pulses used in a single dwell time. */
h->pulse_width; /* Pulse width (micro-sec). */
h->frequency; /* Carrier freq. GHz. */
h->wavelength; /* Wavelength. Meters. */
h->nyq_vel; /* Nyquist velocity. m/s */
#endif
return;
}
Radar *RSL_radtec_to_radar(char *infile)
{
Radar *radar;
Volume *volume;
Sweep *sweep;
Ray *ray;
float (*f)(Range x); /* Data conversion function. f(x). */
Range (*invf)(float x); /* Data conversion function. invf(x). */
Radtec_file *rfile;
float tmp;
int nsweeps, nrays, nbins;
int isweep, iray, ibin;
float sum_elev;
rfile = radtec_read_file(infile);
if (radar_verbose_flag) {
radtec_print_header(&rfile->h);
}
/* Have the entire radtec file; headers and data.
* Initialize the RSL radar and load it up.
*
* Handles both RHI and PPI scan types.
*/
/* Only one field type per file. */
radar = RSL_new_radar(MAX_RADAR_VOLUMES);
if (rfile->h.scan_type == 1) { /* PPI */
nrays = (int)(360.0 / rfile->h.azim_resolution + 0.5);
nsweeps = (int)(rfile->h.num_rays / nrays + 0.5);
} else { /* RHI */
nrays = 1;
nsweeps = (int)(rfile->h.num_rays / nrays + 0.5);
/* Each sweep will contain one ray for RHI scans. */
}
nbins = rfile->h.num_range_bins;
if (radar_verbose_flag) {
fprintf(stderr,"Expecting %d sweeps.\n", nsweeps);
fprintf(stderr,"Expecting %d rays.\n", nrays);
fprintf(stderr,"Expecting %d bins.\n", nbins);
}
if (rfile->h.scan_mode == 0) { /* Log video == Reflectivity. */
f = DZ_F;
invf = DZ_INVF;
volume = radar->v[DZ_INDEX] = RSL_new_volume(nsweeps);
volume->h.type_str = strdup("Reflectivity");
} else { /* Doppler */
f = VR_F;
invf = VR_INVF;
volume = radar->v[VR_INDEX] = RSL_new_volume(nsweeps);
volume->h.type_str = strdup("Velocity");
}
volume->h.f = f;
volume->h.invf = invf;
/* Load the radar header information. */
radar->h.month = rfile->h.month;
radar->h.day = rfile->h.day;
radar->h.year = rfile->h.year;
radar->h.hour = rfile->h.hour;
radar->h.minute = rfile->h.min;
radar->h.sec = rfile->h.sec; /* Second plus fractional part. */
sprintf(radar->h.radar_type,"radtec");
radar->h.number = rfile->h.version; /* arbitrary number of this radar site */
sprintf(radar->h.name,"radtec"); /* Nexrad site name */
sprintf(radar->h.radar_name,"RADTEC"); /* Radar name. */
sprintf(radar->h.city,"Unknown"); /* nearest city to radar site */
sprintf(radar->h.state,"??"); /* state of radar site */
sprintf(radar->h.country,"???");
/** Latitude deg, min, sec **/
radar->h.latd = (int)rfile->h.site_latitude;
tmp = (rfile->h.site_latitude - radar->h.latd) * 60.0;
radar->h.latm = (int)tmp;
radar->h.lats = (int)((tmp - radar->h.latm) * 60.0);
/** Longitude deg, min, sec **/
radar->h.lond = (int)rfile->h.site_longitude;
tmp = (rfile->h.site_longitude - radar->h.lond) * 60.0;
radar->h.lonm = (int)tmp;
radar->h.lons = (int)((tmp - radar->h.lonm) * 60.0);
radar->h.height = rfile->h.site_elevation; /* height of site in meters above sea level*/
radar->h.spulse = 0; /* length of short pulse (ns)*/
radar->h.lpulse = 0; /* length of long pulse (ns) */
/* Loop through the RSL number of sweeps and attach the data. */
for (isweep = 0; isweep < nsweeps; isweep++) {
sweep = volume->sweep[isweep] = RSL_new_sweep(nrays);
sweep->h.f = f;
sweep->h.invf = invf;
sum_elev = 0;
for (iray = 0; iray < nrays; iray++) {
ray = sweep->ray[iray] = RSL_new_ray(nbins);
ray->h.f = f;
ray->h.invf = invf;
fill_ray_header(&ray->h, &rfile->h, rfile->ray[iray].h);
RSL_fix_time(ray);
sum_elev += ray->h.elev;
/* Fill the data. */
for (ibin=0; ibin < nbins; ibin++) {
/* printf ("ray[%d].dbz[%d] = %f\n", iray, ibin, rfile->ray[iray].dbz[ibin]); */
ray->range[ibin] = invf(rfile->ray[iray].dbz[ibin]);
}
}
sweep->h.elev = sum_elev / nrays;
sweep->h.beam_width = rfile->h.azim_resolution; /* This is in the ray header too. */
sweep->h.vert_half_bw = sweep->h.beam_width/2; /* Vertical beam width divided by 2 */
sweep->h.horz_half_bw = sweep->h.beam_width/2; /* Horizontal beam width divided by 2 */
}
radtec_free_file(rfile);
rfile = NULL;
return radar;
}
#else
Radar *RSL_radtec_to_radar(char *infile)
{
fprintf(stderr, "RADTEC is not installed in this version of RSL.\n");
fprintf(stderr, "The library libimplode.a (or .so) was not found during\n");
fprintf(stderr, "the RSL configuration.\n");
return NULL;
}
#endif