# 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.
#

# Uncertainties in ensembles of regional re-analysis project (UERRA)
constant marsClass = 'ur';

alias tigge_short_name=shortName;
alias short_name=shortName;
alias parameter=paramId;
alias tigge_name=name;

alias parameter.paramId=paramId;
alias parameter.shortName=shortName;
alias parameter.units=units;
alias parameter.name=name;

# Special UERRA rule for level type 103 'Specified height level above ground (m)'
if(typeOfFirstFixedSurface == 103) {
    # only the parameters above 10m
    if (level > 10) {
        constant heightLevelName = 'hl';
        alias mars.levtype = heightLevelName;
        # levelist was unaliased in template.4.horizontal.def so we must have it back
        alias mars.levelist = level;
    }
}

if(typeOfFirstFixedSurface == 151 && typeOfSecondFixedSurface == 151) {
    alias level = bottomLevel;
    alias mars.levelist = level;
}

alias mars.expver = marsExpver;
alias mars.class  = marsClass;
alias mars.param = paramId;
alias mars.origin = centre;

# See GRIB-911 re typeOfProcessedData values in UERRA
concept marsType {

   fc = {
     typeOfProcessedData = 1;
   }
   "9" = {
     typeOfProcessedData = 1;
   }

   an = {
     typeOfProcessedData = 0;
   }
   "2" = {
     typeOfProcessedData = 0;
   }

   "default" = {
     dummyc = 0;
   }
}

# See GRIB-205 re no_copy
# Cannot use typeOfProcessedData for stream. See GRIB-911
concept marsStream {

    oper = {
      productDefinitionTemplateNumber = 8;
    }

    oper = {
      productDefinitionTemplateNumber = 0;
    }

    enda = {
      productDefinitionTemplateNumber = 11;
    }

    enda = {
      productDefinitionTemplateNumber = 1;
    }

    "default" = {
      dummyc = 0;
    }
} : no_copy;

alias mars.stream = marsStream;
alias mars.type   = marsType;
