# (C) Copyright 2005- ECMWF.

codetable[1] typeOfWavelengthInterval ('4.91.table',masterDir,localDir) : dump;
alias typeOfIntervalForFirstAndSecondWavelength=typeOfWavelengthInterval;

# Wavelengths in metres
signed[1] scaleFactorOfFirstWavelength : dump;
signed[4] scaledValueOfFirstWavelength : dump;
signed[1] scaleFactorOfSecondWavelength = missing(): can_be_missing,dump;
signed[4] scaledValueOfSecondWavelength = missing(): can_be_missing,dump;

meta firstWavelength  from_scale_factor_scaled_value(scaleFactorOfFirstWavelength, scaledValueOfFirstWavelength);
meta secondWavelength from_scale_factor_scaled_value(scaleFactorOfSecondWavelength, scaledValueOfSecondWavelength);
alias firstWavelengthInMetres = firstWavelength;
alias secondWavelengthInMetres = secondWavelength;

constant billion = 1000000000 : hidden;
meta firstWavelengthInNanometres  multdouble(firstWavelength, billion) : read_only;
meta secondWavelengthInNanometres multdouble(secondWavelength, billion) : read_only;

# All post-MTG2 data (MTG2Switch != 0) will have the wavelength key
if (MTG2Switch != 0) {
 # typeOfWavelengthInterval (table 4.91 specifies if first / second / first+second limit(s) are to be defined)
 if ( typeOfWavelengthInterval == 0 || typeOfWavelengthInterval == 3 || typeOfWavelengthInterval == 5 || typeOfWavelengthInterval == 8 || typeOfWavelengthInterval == 11 ){
  alias mars.wavelength = firstWavelengthInNanometres ;
 }
 if ( typeOfWavelengthInterval == 1 || typeOfWavelengthInterval == 4 || typeOfWavelengthInterval == 6 || typeOfWavelengthInterval == 9 ){
  alias mars.wavelength = secondWavelengthInNanometres ;
 }
 if ( typeOfWavelengthInterval == 2 || typeOfWavelengthInterval == 7 || typeOfWavelengthInterval == 10 ){
  meta wavelengthRange sprintf("%s-%s",firstWavelengthInNanometres,secondWavelengthInNanometres) ;
  alias mars.wavelength = wavelengthRange ;
 }
}
