# Copyright 2005-2017 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# 
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#

section_length[3] section1Length ;

unsigned[1] gribTablesVersionNo ;
codetable[1] centre 'common/c-1.table' : string_type;

alias ls.centre=centre;
alias identificationOfOriginatingGeneratingCentre=centre;

unsigned[1] generatingProcessIdentifier ;

unsigned[1] gridDefinition ;

flags[1] flag 'grib1/1.table';

codetable[1] indicatorOfParameter 'grib1/2.[centre:l].[gribTablesVersionNo:l].table';

codetable[1] indicatorOfTypeOfLevel 'grib1/3.table';
codetable[2] heightPressureEtcOfLevels 'grib1/3.table';
alias ls.levelType=indicatorOfTypeOfLevel;

#  Year of century
# NOTE 6 NOT FOUND
unsigned[1] yearOfCentury ;

#  Month
unsigned[1] month ;

#  Day
unsigned[1] day;

#  Hour
unsigned[1] hour ;

#  Minute
unsigned[1] minute ;


transient second  = 0;
meta      dataDate    budgdate(yearOfCentury,month,day);
alias ls.date=dataDate;
meta      dataTime    time(hour,minute,second);

meta julianDay julian_day(dataDate,hour,minute,second) : edition_specific;


#  Indicator of unit of time range
codetable[1] indicatorOfUnitOfTimeRange 'grib1/4.table';

#  P1 - Period of time
# (number of time units)
unsigned[1] periodOfTime ;

alias   P1 =  periodOfTime ;

#  P2 - Period of time
# (number of time units)
unsigned[1] periodOfTimeIntervals ;

alias   P2 =  periodOfTimeIntervals ;

codetable[1] timeRangeIndicator 'grib1/5.table';

codetable[1] stepUnits 'grib2/tables/1/4.4.table' = 1 : transient,dump,no_copy;

concept stepType {
  "instant" = {timeRangeIndicator=1;}
  "instant" = {timeRangeIndicator=10;}
  "instant" = {timeRangeIndicator=0;}
  "avg"     = {timeRangeIndicator=3;}
  "accum"   = {timeRangeIndicator=4;}
  "max"     = {timeRangeIndicator=2;}
  "min"     = {timeRangeIndicator=2;}
  "diff"    = {timeRangeIndicator=5;}
  "rms"     = {timeRangeIndicator=2;}
  "sd"      = {timeRangeIndicator=2;}
  "cov"     = {timeRangeIndicator=2;}
  "ratio"   = {timeRangeIndicator=2;}
}

meta ls.stepRange g1step_range(P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange,stepUnits,stepType) : dump;
meta startStep long_vector(stepRange,0) : dump;
meta endStep   long_vector(stepRange,1) : dump;

# Set stepUnits to 1 to get step range in hours
meta stepRangeInHours g1step_range(P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange,one,stepType);
meta startStepInHours long_vector(stepRangeInHours,0) : dump;
meta endStepInHours   long_vector(stepRangeInHours,1) : dump;

meta marsStep mars_step(stepRange,stepType);

alias mars.date = dataDate;
alias mars.time = dataTime;
alias mars.step = marsStep;

# This does not work? gribTablesVersionNo is 0
#meta param sprintf("%d.0",indicatorOfParameter) ;
constant paramId = 128;
alias parameter = paramId;
alias ls.parameter=parameter;
