1 /**
2 * Copyright 1981-2016 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence
5 * Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 *
7 * In applying this licence, ECMWF does not waive the privileges and immunities
8 * granted to it by virtue of its status as an intergovernmental organisation
9 * nor does it submit to any jurisdiction.
10 */
11 #ifndef GDECODESTRUCT_H
12 #define GDECODESTRUCT_H
13 
14 typedef struct gribSection0 {
15 unsigned char GRIB[4];
16 unsigned char totalGRIBlength[3];
17 unsigned char editionNumber[1];
18 } gribSection0;
19 
20 typedef struct ECMWFdefinition1 {
21 unsigned char number[1];
22 unsigned char total[1];
23 unsigned char spare[1];
24 } ECMWFdefinition1;
25 
26 typedef struct ECMWFdefinition2 {
27 unsigned char number[1];
28 unsigned char total[1];
29 unsigned char spare[1];
30 unsigned char method[1];
31 unsigned char startTimestep[2];
32 unsigned char endTimestep[2];
33 unsigned char domainNorthLatitude[3];
34 unsigned char domainWestLongitude[3];
35 unsigned char domainSouthLatitude[3];
36 unsigned char domainEastLongitude[3];
37 unsigned char operationalForecastCluster[1];
38 unsigned char controlForecastCluster[1];
39 unsigned char numberInCluster[1];
40 unsigned char forecastNumberList[256];
41 } ECMWFdefinition2;
42 
43 typedef struct ECMWFdefinition3 {
44 unsigned char band[1];
45 unsigned char functionCode[1];
46 unsigned char spare[1];
47 } ECMWFdefinition3;
48 
49 typedef struct ECMWFdefinition5 {
50 unsigned char number[1];
51 unsigned char total[1];
52 unsigned char unitsDecimalScaleFactor[1];
53 unsigned char thresholdIndicator[1];
54 unsigned char lowerThreshold[2];
55 unsigned char upperThreshold[2];
56 unsigned char spare[1];
57 } ECMWFdefinition5;
58 
59 typedef struct ICEField {
60 unsigned char date[3];
61 unsigned char satelliteNumber[1];
62 } ICEField;
63 
64 typedef struct ECMWFdefinition6 {
65 unsigned char zero[2];
66 unsigned char SSTFieldDate[3];
67 unsigned char typeOfSSTField[1];
68 unsigned char countOfICEFields[1];
69 unsigned char lowerThreshold[2];
70 unsigned char upperThreshold[2];
71 ICEField ICEFieldList[20];
72 } ECMWFdefinition6;
73 
74 typedef struct ECMWFdefinition7 {
75 unsigned char number[1];
76 unsigned char totalNumberOfDiagnostics[1];
77 unsigned char domain[1];
78 unsigned char diagnosticNumber[1];
79 unsigned char spare[1];
80 } ECMWFdefinition7;
81 
82 typedef struct ECMWFdefinition8 {
83 unsigned char interval[1];
84 unsigned char unsignedIntegers[12];
85 } ECMWFdefinition8;
86 
87 typedef struct ECMWFdefinition9 {
88 unsigned char number[2];
89 unsigned char numberOfIterations[2];
90 unsigned char numberOfSingularVectorsComputed[2];
91 unsigned char initialNorm[1];
92 unsigned char finalNorm[1];
93 unsigned char multiplicationFactor[4];
94 unsigned char northWestLatitude[4];
95 unsigned char northWestLongitude[4];
96 unsigned char southEastLatitude[4];
97 unsigned char southEastLongitude[4];
98 unsigned char accuracy[4];
99 unsigned char numberOfSingularVectorsEvolved[2];
100 unsigned char ritzNumber1[4];
101 unsigned char ritzNumber2[4];
102 unsigned char spare[1];
103 } ECMWFdefinition9;
104 
105 typedef struct ECMWFdefinition10 {
106 unsigned char number[1];
107 unsigned char total[1];
108 unsigned char centralClusterDefinition[1];
109 unsigned char parameter[1];
110 unsigned char levelType[1];
111 unsigned char domainNorth[3];
112 unsigned char domainWest[3];
113 unsigned char domainSouth[3];
114 unsigned char domainEast[3];
115 unsigned char operationalForcastTubeNumber[1];
116 unsigned char controlForcastTubeNumber[1];
117 unsigned char level[2];
118 unsigned char referenceStep[2];
119 unsigned char radiusOfCentralCluster[2];
120 unsigned char ensembleStandardDeviation[2];
121 unsigned char distanceOfExtremeToMean[2];
122 unsigned char numberOfForecastsInTube[1];
123 unsigned char ensembleForecastList[255];
124 } ECMWFdefinition10;
125 
126 typedef struct ECMWFdefinition11 {
127 unsigned char analysisClass[1];
128 unsigned char analysisType[1];
129 unsigned char analysisStream[2];
130 unsigned char analysisExpver[4];
131 unsigned char analysisYear[1];
132 unsigned char analysisMonth[1];
133 unsigned char analysisDay[1];
134 unsigned char analysisHour[1];
135 unsigned char analysisMinute[1];
136 unsigned char analysisCentury[1];
137 unsigned char analysisOriginatingCentre[1];
138 unsigned char analysisSubCentre[1];
139 unsigned char spare[7];
140 } ECMWFdefinition11;
141 
142 typedef struct ECMWFdefinition20 {
143 unsigned char iteration[1];
144 unsigned char total[1];
145 unsigned char spare[1];
146 } ECMWFdefinition20;
147 
148 typedef union localContent {
149 ECMWFdefinition1  def1;
150 ECMWFdefinition2  def2;
151 ECMWFdefinition3  def3;
152 ECMWFdefinition5  def5;
153 ECMWFdefinition6  def6;
154 ECMWFdefinition7  def7;
155 ECMWFdefinition8  def8;
156 ECMWFdefinition9  def9;
157 ECMWFdefinition10 def10;
158 ECMWFdefinition11 def11;
159 ECMWFdefinition20 def20;
160 } localContent;
161 
162 typedef struct marsHeader {
163 unsigned char definition[1];
164 unsigned char ecmwfClass[1];
165 unsigned char type[1];
166 unsigned char stream[2];
167 unsigned char experimentVersionNumber[4];
168 } marsHeader;
169 
170 typedef struct localDefinition {
171 marsHeader mars;
172 localContent contents;
173 } localDefinition;
174 
175 typedef struct gribSection1 {
176 unsigned char sectionLength[3];
177 unsigned char tableVersionNumber[1];
178 unsigned char originatingCentre[1];
179 unsigned char generatingProcessId[1];
180 unsigned char gridDefinition[1];
181 unsigned char section2and3PresentFlag[1];
182 unsigned char parameter[1];
183 unsigned char typeOfLevel[1];
184 unsigned char level1[1];
185 unsigned char level2[1];
186 unsigned char year[1];
187 unsigned char month[1];
188 unsigned char day[1];
189 unsigned char hour[1];
190 unsigned char minute[1];
191 unsigned char unitOfTimeRange[1];
192 unsigned char P1[1];
193 unsigned char P2[1];
194 unsigned char timeRangeIndicator[1];
195 unsigned char numberInAverage[2];
196 unsigned char numberMissing[1];
197 unsigned char century[1];
198 unsigned char subCentreId[1];
199 unsigned char unitsDecimalScaleFactor[2];
200 unsigned char reserved[12];
201 localDefinition local;
202 } gribSection1;
203 
204 typedef struct latitudeLongitudeGrid {
205 unsigned char numberOfPointsAlongParallel[2];
206 unsigned char numberOfPointsAlongMeridian[2];
207 unsigned char latitudeOfFirstPoint[3];
208 unsigned char longitudeOfFirstPoint[3];
209 unsigned char resolutionAndComponentsFlag[1];
210 unsigned char latitudeOfLastPoint[3];
211 unsigned char longitudeOfLastPoint[3];
212 unsigned char iDirectionIncrement[2];
213 unsigned char jDirectionIncrement[2];
214 unsigned char scanningMode[1];
215 unsigned char setToZero[4];
216 unsigned char latitudeOfSouthPole[3];
217 unsigned char longitudeOfSouthPole[3];
218 unsigned char angleOfRotationOrStretchingFactor[4];
219 unsigned char latitudeOfPoleOfStretching[3];
220 unsigned char longitudeOfPoleOfStretching[3];
221 unsigned char stretchingFactor[4];
222 } latitudeLongitudeGrid;
223 
224 typedef struct gaussianGrid {
225 unsigned char numberOfPointsAlongParallel[2];
226 unsigned char numberOfPointsAlongMeridian[2];
227 unsigned char latitudeOfFirstPoint[3];
228 unsigned char longitudeOfFirstPoint[3];
229 unsigned char resolutionAndComponentsFlag[1];
230 unsigned char latitudeOfLastPoint[3];
231 unsigned char longitudeOfLastPoint[3];
232 unsigned char iDirectionIncrement[2];
233 unsigned char numberOfParallelsBetweenPoleAndEquator[2];
234 unsigned char scanningMode[1];
235 unsigned char setToZero[4];
236 unsigned char latitudeOfSouthPole[3];
237 unsigned char longitudeOfSouthPole[3];
238 unsigned char angleOfRotationOrStretchingFactor[4];
239 unsigned char latitudeOfPoleOfStretching[3];
240 unsigned char longitudeOfPoleOfStretching[3];
241 unsigned char stretchingFactor[4];
242 } gaussianGrid;
243 
244 
245 typedef struct sphericalHarmonicCoefficients {
246 unsigned char J[2];
247 unsigned char K[2];
248 unsigned char M[2];
249 unsigned char representationType[1];
250 unsigned char representationMode[1];
251 unsigned char setToZero[18];
252 unsigned char latitudeOfSouthPole[3];
253 unsigned char longitudeOfSouthPole[3];
254 unsigned char angleOfRotationOrStretchingFactor[4];
255 unsigned char latitudeOfPoleOfStretching[3];
256 unsigned char longitudeOfPoleOfStretching[3];
257 unsigned char stretchingFactor[4];
258 } sphericalHarmonicCoefficients;
259 
260 typedef union gridDefinition {
261 latitudeLongitudeGrid latlon;
262 gaussianGrid gaussian;
263 sphericalHarmonicCoefficients spectral;
264 } gridDefinition;
265 
266 typedef struct gribSection2 {
267 unsigned char sectionLength[3];
268 unsigned char NV[1];
269 unsigned char PV_PL[1];
270 unsigned char dataRepresentationType[1];
271 gridDefinition grid;
272 } gribSection2;
273 
274 typedef struct gribSection3 {
275 unsigned char sectionLength[3];
276 unsigned char numberOfUnusedBits[1];
277 unsigned char tableReference[2];
278 unsigned char bitmap;
279 } gribSection3;
280 
281 typedef struct simplePackingGridPoint {
282 unsigned char dataBits;
283 } simplePackingGridPoint;
284 
285 typedef struct secondOrderPackingGridPoint {
286 unsigned char n1[2];
287 unsigned char extendedFlags[1];
288 unsigned char n2[2];
289 unsigned char p1[2];
290 unsigned char p2[2];
291 unsigned char reserved[1];
292 unsigned char dataBits;
293 } secondOrderPackingGridPoint;
294 
295 typedef struct simplePackingSpectral {
296 unsigned char realPartOf0_0Coefficient[4];
297 unsigned char dataBits;
298 } simplePackingSpectral;
299 
300 typedef struct complexPackingSpectral {
301 unsigned char N[2];
302 unsigned char IP[2];
303 unsigned char J[1];
304 unsigned char K[1];
305 unsigned char M[1];
306 unsigned char dataBits;
307 } complexPackingSpectral;
308 
309 typedef union binaryData {
310 simplePackingGridPoint simpleGrid;
311 secondOrderPackingGridPoint complexGrid;
312 simplePackingSpectral simpleSpectral;
313 complexPackingSpectral complexSpectral;
314 } binaryData;
315 
316 typedef struct gribSection4 {
317 unsigned char sectionLength[3];
318 unsigned char flag[1];
319 unsigned char scaleFactor[2];
320 unsigned char referenceValue[4];
321 unsigned char numberOfBitsPerValue[1];
322 binaryData data;
323 } gribSection4;
324 
325 typedef struct gribSection5 {
326 unsigned char end7777[4];
327 } gribSection5;
328 
329 typedef struct latLongValueVector {
330 fortdouble * latitude;
331 fortdouble * longitudeIncrement;
332 fortdouble * gridPointValue;
333 } latLongValueVector;
334 
335 typedef struct gribProduct {
336 gribSection0 * g0;
337 gribSection1 * g1;
338 gribSection2 * g2;
339 gribSection3 * g3;
340 gribSection4 * g4;
341 gribSection5 * g5;
342 fortint currentPointIndex;
343 fortint numberOfValues;
344 unsigned char * value;
345 unsigned char * bitStart;
346 fortint bitsPerValue;
347 fortint bitmapped;
348 fortint nextValueFirstBit;
349 fortint nextBit;
350 fortint northSet;
351 fortint southSet;
352 fortint westSet;
353 fortint eastSet;
354 fortint northSouthIncrementSet;
355 fortint westEastIncrementSet;
356 fortint northSouthNumberOfPointsSet;
357 fortint westEastNumberOfPointsSet;
358 fortdouble scale;
359 fortdouble minimum;
360 fortdouble missingValue;
361 fortint * latitudeOffsets;
362 fortdouble * expandedValues;
363 latLongValueVector currentPoint;
364 } gribProduct;
365 
366 #endif /* End of GDECODESTRUCT_H */
367