1# Copyright 2005-2018 ECMWF.
2#
3# This software is licensed under the terms of the Apache Licence Version 2.0
4# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5#
6# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
7# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
8#
9
10meta groupWidths unsigned_bits(widthOfWidths,numberOfGroups) : read_only;
11meta groupLengths unsigned_bits(widthOfLengths,numberOfGroups) : read_only;
12meta firstOrderValues unsigned_bits(widthOfFirstOrderValues,numberOfGroups) : read_only;
13meta countOfGroupLengths sum(groupLengths);
14transient halfByte=0;
15
16position offsetBeforeData;
17
18if(bitmapPresent)   {
19   meta codedValues data_g1second_order_general_extended_packing(
20	#simple_packing args
21     section7Length,
22     offsetBeforeData,
23     offsetSection7,
24     unitsFactor,
25     unitsBias,
26     changingPrecision,
27     numberOfCodedValues,
28     bitsPerValue,
29     referenceValue,
30     binaryScaleFactor,
31     decimalScaleFactor,
32	#g1second_order_row_by_row args
33	 halfByte,
34	 packingType,
35	 grid_ieee,
36	 precision,
37	 widthOfFirstOrderValues,
38	 firstOrderValues,
39	 N1,
40	 N2,
41	 numberOfGroups,
42	 numberOfGroups,
43	 numberOfSecondOrderPackedValues,
44	 keyNotPresent,
45	 groupWidths,
46	 widthOfWidths,
47	 groupLengths,
48	 widthOfLengths,
49	 NL,
50	 SPD,
51	 widthOfSPD,
52	 orderOfSPD,
53	 numberOfPoints
54
55   ): read_only;
56   alias data.packedValues = codedValues;
57
58   if (boustrophedonicOrdering) {
59       meta preBitmapValues data_apply_bitmap(codedValues,bitmap,missingValue,binaryScaleFactor) : read_only;
60       meta values data_apply_boustrophedonic(preBitmapValues,numberOfRows,numberOfColumns,numberOfPoints,pl) : dump;
61   } else {
62       meta values data_apply_bitmap(codedValues,bitmap,missingValue,binaryScaleFactor) : dump;
63   }
64
65} else {
66	if (boustrophedonicOrdering) {
67	   meta codedValues data_g1second_order_general_extended_packing(
68		#simple_packing args
69		 section7Length,
70		 offsetBeforeData,
71		 offsetSection7,
72		 unitsFactor,
73		 unitsBias,
74		 changingPrecision,
75		 numberOfCodedValues,
76		 bitsPerValue,
77		 referenceValue,
78		 binaryScaleFactor,
79		 decimalScaleFactor,
80		#g1second_order_row_by_row args
81		 halfByte,
82		 packingType,
83		 grid_ieee,
84		 precision,
85		 widthOfFirstOrderValues,
86		 firstOrderValues,
87		 N1,
88		 N2,
89		 numberOfGroups,
90		 numberOfGroups,
91		 numberOfSecondOrderPackedValues,
92		 keyNotPresent,
93		 groupWidths,
94		 widthOfWidths,
95		 groupLengths,
96		 widthOfLengths,
97		 NL,
98		 SPD,
99		 widthOfSPD,
100		 orderOfSPD,
101		 numberOfPoints
102
103		 ) : dump;
104
105		meta values data_apply_boustrophedonic(codedValues,numberOfRows,numberOfColumns,numberOfPoints,pl) : dump;
106
107	} else {
108	   meta values data_g1second_order_general_extended_packing(
109		#simple_packing args
110		 section7Length,
111		 offsetBeforeData,
112		 offsetSection7,
113		 unitsFactor,
114		 unitsBias,
115		 changingPrecision,
116		 numberOfCodedValues,
117		 bitsPerValue,
118		 referenceValue,
119		 binaryScaleFactor,
120		 decimalScaleFactor,
121		#g1second_order_row_by_row args
122		 halfByte,
123		 packingType,
124		 grid_ieee,
125		 precision,
126		 widthOfFirstOrderValues,
127		 firstOrderValues,
128		 N1,
129		 N2,
130		 numberOfGroups,
131		 numberOfGroups,
132		 numberOfSecondOrderPackedValues,
133		 keyNotPresent,
134		 groupWidths,
135		 widthOfWidths,
136		 groupLengths,
137		 widthOfLengths,
138		 NL,
139		 SPD,
140		 widthOfSPD,
141		 orderOfSPD,
142		 numberOfPoints
143
144		 ) : dump;
145		 alias codedValues=values;
146	}
147    alias data.packedValues = values;
148}
149
150meta packingError simple_packing_error(bitsPerValue,binaryScaleFactor,decimalScaleFactor,referenceValue,ieee) : no_copy;
151
152template statistics "common/statistics_grid.def";
153