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
10constant ECMWF = 98 : hidden;
11constant ECMWF_s = "ecmf" : hidden;
12constant WMO= 0;
13constant conceptsMasterDir="grib1" : hidden;
14constant conceptsLocalDirECMF="grib1/localConcepts/ecmf" : hidden;
15constant conceptsLocalDirAll="grib1/localConcepts/[centre:s]" : hidden;
16
17constant tablesMasterDir="grib1" : hidden;
18constant tablesLocalDir="grib1/local/[centre:s]" : hidden;
19
20transient productionStatusOfProcessedData=0;
21position offsetSection1;
22length[3] section1Length ;
23meta section1Pointer section_pointer(offsetSection1,section1Length,1);
24constant wrongPadding=0;
25
26#  GRIB tables Version No.
27# (currently 3 for international exchange)
28unsigned[1] table2Version  : edition_specific,dump;
29alias gribTablesVersionNo=table2Version;
30
31
32#assert(section1Length > 5);
33
34#  Identification of originating/generating centre
35codetable[1] centre 'grib1/0.table' : dump,string_type;
36alias identificationOfOriginatingGeneratingCentre=centre;
37meta centreDescription codetable_title(centre);
38
39alias parameter.centre=centre;
40alias originatingCentre=centre;
41alias ls.centre = centre;
42
43#  Generating process identification number
44# (allocated by originating centre)
45unsigned[1] generatingProcessIdentifier : dump ;
46alias generatingProcessIdentificationNumber=generatingProcessIdentifier;
47alias process=generatingProcessIdentifier;
48
49unsigned[1] gridDefinition = 255 : edition_specific ;
50flags[1] section1Flags 'grib1/1.table' = 128 : hidden ; # = section 2 present
51
52alias centreForTable2=centre;
53
54codetable[1] indicatorOfParameter 'grib1/2.[centreForTable2:l].[table2Version:l].table' : edition_specific,no_copy,dump;
55meta parameterName codetable_title(indicatorOfParameter);
56meta parameterUnits codetable_units(indicatorOfParameter);
57
58# Local comes before Master to give precedence to the local, centre-specific table
59codetable[1] indicatorOfTypeOfLevel ('3.table',tablesLocalDir,tablesMasterDir) : edition_specific,no_copy,dump,string_type;
60alias levelType=indicatorOfTypeOfLevel;
61
62transient pressureUnits="hPa";
63
64concept_nofail typeOfLevelECMF      (unknown,         "typeOfLevel.def",conceptsMasterDir,conceptsLocalDirECMF);
65concept_nofail vertical.typeOfLevel (typeOfLevelECMF, "typeOfLevel.def",conceptsMasterDir,conceptsLocalDirAll);
66
67when ( typeOfLevel is "isobaricInPa" ) { set pressureUnits="Pa"; }
68else { set pressureUnits="hPa";}
69
70alias ls.typeOfLevel=typeOfLevel;
71
72if ( indicatorOfTypeOfLevel == 101 or
73     indicatorOfTypeOfLevel == 104 or
74     indicatorOfTypeOfLevel == 106 or
75     indicatorOfTypeOfLevel == 108 or
76     indicatorOfTypeOfLevel == 110 or
77     indicatorOfTypeOfLevel == 112 or
78     indicatorOfTypeOfLevel == 114 or
79     indicatorOfTypeOfLevel == 116 or
80     indicatorOfTypeOfLevel == 120 or
81     indicatorOfTypeOfLevel == 121 or
82     indicatorOfTypeOfLevel == 128 or
83     indicatorOfTypeOfLevel == 141    )
84{
85    unsigned[1] topLevel : can_be_missing,dump;
86    unsigned[1] bottomLevel : can_be_missing,dump;
87    meta levels sprintf("%d-%d",topLevel,bottomLevel) : dump;
88    alias ls.levels=levels;
89    alias vertical.level = topLevel;
90    alias vertical.topLevel = topLevel;
91    alias vertical.bottomLevel = bottomLevel;
92}
93else
94{
95  unsigned[2] level : can_be_missing,dump;
96  if (indicatorOfTypeOfLevel == 210) {
97    meta marsLevel scale(level,oneConstant,hundred) : read_only;
98	alias mars.levelist = marsLevel;
99  }
100  alias vertical.level=level;
101  alias vertical.topLevel    = level;
102  alias vertical.bottomLevel = level;
103  alias ls.level=level;
104  alias lev=level;
105}
106
107if(	indicatorOfTypeOfLevel == 109 ||
108	indicatorOfTypeOfLevel == 100 ||
109	indicatorOfTypeOfLevel == 110 ||
110	indicatorOfTypeOfLevel == 113 ||
111	indicatorOfTypeOfLevel == 117)
112{
113	  alias mars.levelist = level;
114}
115
116unsigned[1] yearOfCentury : edition_specific ;
117unsigned[1] month  ;
118unsigned[1] day ;
119unsigned[1] hour  ;
120unsigned[1] minute  ;
121transient second = 0;
122
123codetable[1] unitOfTimeRange 'grib1/4.table' = 1 : edition_specific;
124alias unitOfTime=unitOfTimeRange;
125alias indicatorOfUnitOfTimeRange=unitOfTimeRange;
126
127unsigned[1] P1 : edition_specific;
128
129unsigned[1] P2 : edition_specific;
130
131# Local comes before Master to give precedence to the local, centre-specific table
132codetable[1] timeRangeIndicator ('5.table',tablesLocalDir,tablesMasterDir) = 1 : dump,edition_specific;
133
134unsigned[2] numberIncludedInAverage;
135
136meta mybits bits(numberIncludedInAverage,0,12);
137
138unsigned[1] numberMissingFromAveragesOrAccumulations;
139unsigned[1] centuryOfReferenceTimeOfData ;
140
141codetable[1] subCentre 'grib1/0.[centre].table' : dump;
142
143if(table2Version >= 128) {
144  _if (centre != 98 && subCentre == 98) {
145    alias centreForTable2 = subCentre;
146} else {
147    alias centreForTable2 = centre;
148}
149} else {
150  alias centreForTable2 = WMO;
151}
152
153#if ( subCentre == 98 ) {
154#  alias conceptsLocalDir=conceptsLocalDirECMF;
155#} else {
156#  alias conceptsLocalDir=conceptsLocalDirAll;
157#}
158
159concept paramIdECMF (defaultParameter,"paramId.def",conceptsMasterDir,conceptsLocalDirECMF): no_copy;
160concept paramId (paramIdECMF,"paramId.def",conceptsMasterDir,conceptsLocalDirAll): long_type,dump;
161
162concept cfNameECMF(defaultName,"cfName.def",conceptsMasterDir,conceptsLocalDirECMF) : dump,no_copy,read_only;
163concept cfName(cfNameECMF,"cfName.def",conceptsMasterDir,conceptsLocalDirAll) : dump,no_copy,read_only;
164
165concept cfVarNameECMF(defaultName,"cfVarName.def",conceptsMasterDir,conceptsLocalDirECMF) : dump,no_copy,read_only;
166concept cfVarName(cfVarNameECMF,"cfVarName.def",conceptsMasterDir,conceptsLocalDirAll) : dump,no_copy,read_only;
167
168concept unitsECMF(defaultName,"units.def",conceptsMasterDir,conceptsLocalDirECMF) : no_copy,read_only;
169concept units(unitsECMF,"units.def",conceptsMasterDir,conceptsLocalDirAll) : dump,no_copy,read_only;
170
171concept nameECMF(defaultName,"name.def",conceptsMasterDir,conceptsLocalDirECMF) : dump,no_copy,read_only;
172concept name(nameECMF,"name.def",conceptsMasterDir,conceptsLocalDirAll) : dump,no_copy,read_only;
173
174signed[2] decimalScaleFactor :dump;
175transient setLocalDefinition= 0 : no_copy;
176
177meta      dataDate            g1date(centuryOfReferenceTimeOfData,yearOfCentury,month,day) : dump;
178meta      year                evaluate(dataDate / 10000) ;
179
180meta dataTime   time(hour,minute,second) : dump;
181meta julianDay  julian_day(dataDate,hour,minute,second) : edition_specific;
182
183codetable[1] stepUnits 'stepUnits.table' = 1 : transient,dump,no_copy;
184
185concept_nofail stepType (timeRangeIndicator, "stepType.def", conceptsMasterDir, conceptsLocalDirAll);
186
187#alias stepTypeInternal=stepType;
188#alias lengthOfTimeRange=numberIncludedInAverage;
189#alias indicatorOfUnitForTimeRange=unitOfTimeRange;
190#alias indicatorOfUnitForTimeIncrement=zero;
191#alias timeIncrement=zero;
192
193#if (timeRangeIndicator==113) {
194#	alias lengthOfTimeRange=numberIncludedInAverage;
195#	alias indicatorOfUnitForTimeRange=unitOfTimeRange;
196#	alias indicatorOfUnitForTimeIncrement=unitOfTimeRange;
197#	alias timeIncrement=P2;
198#	alias forecastTime=P1;
199#}
200
201#if (stepType is "accum") {
202#		transient accumulationRange=P2-P1;
203#		alias lengthOfTimeRange=accumulationRange;
204#		alias forecastTime=P1;
205#		alias indicatorOfUnitForTimeRange=unitOfTimeRange;
206#}
207
208#conversion 1->2
209_if (stepType is "instant" ) {
210  alias productDefinitionTemplateNumber=zero;
211} else {
212  alias productDefinitionTemplateNumber=eight;
213}
214
215meta stepRange g1step_range(P1,P2,timeRangeIndicator,unitOfTimeRange,stepUnits,stepType) : dump;
216meta startStep long_vector(stepRange,0) : dump,no_copy;
217meta endStep   long_vector(stepRange,1) : dump,no_copy;
218
219alias stepInHours = endStep;
220alias ls.stepRange = stepRange;
221alias ls.dataDate  = dataDate;
222
223alias mars.step    = endStep;
224alias mars.date    = dataDate;
225alias mars.levtype = indicatorOfTypeOfLevel;
226alias mars.time    = dataTime;
227#alias mars.param   = paramId;
228meta marsParam mars_param(paramId,gribTablesVersionNo,indicatorOfParameter): read_only,dump;
229alias mars.param  = marsParam;
230
231# GRIB-860: JRA55 rule for MARS.
232# subCentre of 241 means Japanese Reanalysis Project
233if (centre == 34 && subCentre == 241)
234{
235   alias mars.param = paramId;
236
237   if (indicatorOfTypeOfLevel == 101) {
238      # See ECC-467
239      constant sfc_levtype = "sfc";
240      alias mars.levtype = sfc_levtype;
241   }
242}
243
244meta time.validityDate validity_date(dataDate,dataTime,step,stepUnits);
245meta time.validityTime validity_time(dataDate,dataTime,step,stepUnits);
246
247transient deleteLocalDefinition=0;
248
249if(((section1Length > 40) or new() or setLocalDefinition> 0) and deleteLocalDefinition==0)
250{
251  constant localUsePresent = 1 : edition_specific;
252  alias grib2LocalSectionPresent=present;
253
254  if( (centre == ECMWF) or
255      (centre != ECMWF and
256        subCentre == ECMWF))
257  {
258    pad reservedNeedNotBePresent(12);
259    codetable[1] localDefinitionNumber 'grib1/localDefinitionNumber.98.table' = 1 : dump;
260    template  localDefinition  "grib1/local.98.[localDefinitionNumber:l].def";
261    if (changed(localDefinitionNumber)) {
262      if(!new() && localDefinitionNumber!=4 ) {
263         section_padding localExtensionPadding : read_only;
264      }
265    }
266
267	template_nofail marsKeywords "mars/grib1.[stream:s].[type:s].def";
268	#template marsKeywords "mars/grib1.[stream:s].[type:s].def";
269
270  }
271  else
272  {
273	if ( !new() || setLocalDefinition ) {
274		# Other centres
275		pad reservedNeedNotBePresent(12);
276		template_nofail  localDefinition  "grib1/local.[centre:l].def";
277
278		section_padding localExtensionPadding : read_only;
279	}
280  }
281}
282else
283{
284   constant localUsePresent  = 0 : edition_specific;
285   #   template defaultMarsLabeling "mars/default_labeling.def";
286}
287
288section_padding section1Padding : read_only;
289
290#if (!wrongPadding) {
291#  padtoeven evenpadding_sec1(offsetSection1,section1Length);
292#}
293
294
295concept shortNameECMF (defaultShortName,"shortName.def",conceptsMasterDir,conceptsLocalDirECMF) : no_copy;
296concept ls.shortName (shortNameECMF,"shortName.def",conceptsMasterDir,conceptsLocalDirAll) : no_copy,dump;
297meta ifsParam ifs_param(paramId,type);
298
299alias parameter.paramId=paramId;
300alias parameter.shortName=shortName;
301alias parameter.units=units;
302alias parameter.name=name;
303
304alias parameter=paramId;
305alias short_name=shortName;
306
307alias time.stepRange=stepRange;
308alias time.stepUnits=stepUnits;
309alias time.dataDate=dataDate;
310alias time.dataTime=dataTime;
311alias time.startStep=startStep;
312alias time.endStep=endStep;
313alias time.stepType=stepType;
314
315meta md5Section1 md5(offsetSection1,section1Length);
316