]> Pileus Git - aweather/blob - opt/level2.h
got levels working, plus faster
[aweather] / opt / level2.h
1 #ifndef LEVEL2_H
2 #define LEVEL2_H
3
4 /* http://www.ncdc.noaa.gov/oa/radar/leveliidoc.html */
5 typedef struct {
6         /* 24 bytes */
7         char version[4];
8         char unknown0[16];
9         char station[4];
10 } __attribute__ ((packed)) level2_header_t;
11
12 typedef struct {
13         /**
14          * Channel Terminal Manager:
15          *
16          * Archive II (the data tape) is a copy of messages or data packets
17          * prepared for transmission from the RDA to the RPG.  CTM information
18          * is attached to a message or data packet for checking data integrity
19          * during the transmission process and is of no importance to the base
20          * data (omit or read past these bytes).
21          */
22         short ctm[6]; // ignore
23
24         /**
25          * Message Header:
26          *
27          * This information is used to identify either base data or one of
28          * thirteen types of messages that may follow in bytes 28 - 2431.  This
29          * header includes the information indicated below:
30          */
31         // Message size in halfwords measure from this halfword to the end of
32         // record.
33         unsigned short size;
34
35         // Channel ID:
36         //   0 = Non-Redundant Site
37         //   1 = Redundant Site Channel 1
38         //   2 = Redundant Site Channel 2
39         unsigned char id;
40
41         // Message type, where:
42         //   1  = DIGITAL RADAR DATA (This message  may contain a combination of
43         //        either reflectivity, aliased velocity, or spectrum width)
44         //   2  = RDA STATUS DATA.
45         //   3  = PERFORMANCE/MAINTENANCE DATA.
46         //   4  = CONSOLE MESSAGE - RDA TO RPG.
47         //   5  = MAINTENANCE LOG DATA.
48         //   6  = RDA CONTROL COMMANDS.
49         //   7  = VOLUME COVERAGE PATTERN.
50         //   8  = CLUTTER CENSOR ZONES.
51         //   9  = REQUEST FOR DATA.
52         //   10 = CONSOLE MESSAGE - RPG TO RDA.
53         //   11 = LOOP BACK TEST  - RDA TO RPG.
54         //   12 = LOOP BACK TEST  - RPG TO RDA.
55         //   13 = CLUTTER FILTER BYPASS MAP - RDA to RPG.
56         //   14 = EDITED CLUTTER FILTER BYPASS MAP - RPG to RDA.
57         unsigned char type;
58
59         // I.D. Sequence = 0 to 7FFF, then roll over back to 0.
60         unsigned short seq;
61
62         // Modified Julian date starting from 1/1/70
63         unsigned short gen_date;
64
65         // Generation time of messages in milliseconds of day past midnight
66         // (UTC). This time may be different than time listed in halfwords
67         // 15-16 defined below.
68         unsigned int   gen_time;
69
70         // Number of message segments.  Messages larger than message size
71         // (halfword 7 defined above) are segmented and recorded in separate
72         // data packets.
73         unsigned short num_seg;
74
75         // Message segment number.
76         unsigned short seg;
77
78         /**
79          * Digital Radar Data Header:
80          * 
81          * This information describes the date, time, azimuth, elevation, and
82          * type of base data included in the radial. This header includes the
83          * following information:
84          */
85         // Collection time for this radial in milliseconds of the day from
86         // midnight (UTC).
87         unsigned int   coll_time;
88
89         // Modified Julian date referenced from 1/1/70.
90         unsigned short coll_date;
91
92         // Unambiguous range (scaled: Value/10. = KM).
93         unsigned short range;
94         
95         // Azimuth angle (coded: [Value/8.]*[180./4096.] = DEG). An azimuth of
96         // "0 degrees" points to true north while "90 degrees" points east.
97         // Rotation is always clockwise as viewed from above the radar.
98         unsigned short angle;
99
100         // Radial number within the elevation scan.
101         unsigned short radial;
102
103         // Radial status where:
104         //   0 = START OF NEW ELEVATION.
105         //   1 = INTERMEDIATE RADIAL.
106         //   2 = END OF ELEVATION.
107         //   3 = BEGINNING OF VOLUME SCAN.
108         //   4 = END OF VOLUME SCAN.
109         unsigned short rad_status;
110
111         // Elevation angle (coded:[Value/8.]*[180./4096.] = DEG). An elevation
112         // of "0 degree" is parallel to the pedestal base while "90 degrees" is
113         // perpendicular to the pedestal base.
114         unsigned short elev_angle;
115
116         // RDA elevation number within the volume scan.
117         unsigned short elev_num;
118
119         // Range to first gate of reflectivity data (METERS). Range may be
120         // negative to account for system delays in transmitter and/or receiver
121         // components. 
122         short          first_refl;
123
124         // Range to first gate of Doppler data.  Doppler data - velocity and
125         // spectrum width (METERS).  Range may be negative to account for
126         // system delays in transmitter and/or receiver components.
127         short          first_dopp;
128
129         // Reflectivity data gate size (METERS).
130         unsigned short refl_size;
131
132         // Doppler data gate size (METERS).
133         unsigned short dopp_size;
134
135         // Number of reflectivity gates.
136         unsigned short num_refl_gate;
137
138         // Number of velocity and/or spectrum width data gates.
139         unsigned short num_dopp_gate;
140
141         // Sector number within cut.
142         unsigned short sector;
143
144         // System gain calibration constant (dB biased).
145         float          gain;
146
147         // Reflectivity data pointer (byte # from the start of  digital radar
148         // data message header). This pointer locates the beginning of
149         // reflectivity data.
150         unsigned short refl_ptr;
151
152         // Velocity data pointer (byte # from the start of digital radar data
153         // message header). This pointer locates beginning of velocity data.
154         unsigned short vel_ptr;
155
156         // Spectrum-width pointer (byte # from the start of  digital radar data
157         // message header). This pointer locates beginning of spectrum-width
158         // data.
159         unsigned short spec_ptr;
160
161         // Doppler velocity resolution.
162         //   Value of: 2 = 0.5 m/s
163         //             4 = 1.0 
164         unsigned short dopp_res;
165
166         // Volume coverage pattern.
167         //   Value of: 11 = 16 elev. scans/ 5 mins.
168         //             21 = 11 elev. scans/ 6 mins.
169         //             31 = 8 elev. scans/ 10 mins.
170         //             32 = 7 elev. scans/ 10 mins.
171         unsigned short pattern;
172
173         // Unused.  Reserved for V&V Simulator.
174         short          vv_sim[4];
175
176         // Reflectivity data pointer for Archive II playback. Archive II
177         // playback pointer used exclusively by RDA.
178         unsigned short refl_ptr_rda;
179         
180         // Velocity data pointer for Archive II playback. Archive II playback
181         // pointer used exclusively by RDA.
182         unsigned short vel_ptr_rda;
183
184         // Spectrum-width data pointer for Archive II playback. Archive II
185         // playback pointer used exclusively by RDA.
186         unsigned short spec_ptr_rda;
187
188         // Nyquist velocity (scaled: Value/100. = M/S).
189         unsigned short nyquist;
190
191         // Atmospheric attenuation factor (scaled: [Value/1000. = dB/KM]).
192         unsigned short atten;
193
194         // Threshold parameter for minimum difference in echo power between two
195         // resolution volumes for them not to be labeled range ambiguous
196         // (i.e.,overlaid) [Value/10. = Watts].
197         short          thresh;
198
199         // Unused.
200         short          unused0[17];
201
202         /**
203          * Base Data:
204          *
205          * This information includes the three base data moments; reflectivity,
206          * velocity and spectrum width.  Depending on the collection method, up
207          * to three base data moments may exist in this section of the packet.
208          * (For this example, only reflectivity is present.) Base data is coded
209          * and placed in a single byte and is archived in the following format:
210          */
211         // A bit confsued by these docs.
212         // Note: Need to check size field to get correct size.
213         unsigned char data[2300];
214
215         // Reflectivity data (0 - 460 gates) (coded: [((Value-2)/2.)-32. =
216         // dBZ], for Value of 0 or 1 see note below).
217         //unsigned char refl[460];
218
219         // Doppler velocity data (coded: for doppler velocity resolution of 0.5
220         // M/S, [((Value-2)/2.)-63.5 = M/S]; for doppler resolution of 1.0 M/S,
221         // [(Value-2)-127.] = M/S], for Value of 0 or 1 see note below), (0 -
222         // 92 gates). Starting data location depends on length of the
223         // reflectivity field, stop location depends on length of the velocity
224         // field. Velocity data is range unambiguous out to 230 KM.
225         //unsigned char vel[920];
226         
227         // Doppler spectrum width (coded: [((Value - 2)/2.)-63.5 = M/S], for
228         // Value of 0 or 1 see note below), (0 - 920 gates). Starting data
229         // location depends on length of the reflectivity and velocity fields,
230         // stop location depends on length of the spectrum width field.
231         // Spectrum width is range unambiguous out to 230 KM.
232         //unsigned char spec[920];
233
234         // Four bytes of trailer characters referred to the Frame Check
235         // Sequence (FCS) follow the data. In cases where the three moments are
236         // not all present or the number of gates for each moment have been
237         // reduced, the record is padded out to a constant size of 1216
238         // halfwords (2432 bytes) following the trailer characters.
239         unsigned int fcs;
240 } __attribute__ ((packed)) level2_packet_t;
241
242 #endif