#============
# Contents
#============
* CMEM NetCDF I/O
* NetCDF
* Input
  - Input
  - Contain required forcing for CMEM
  - Main (soil moisuture, soil temperature)
  - Soil Condition
  - Vegetation
  - 2m air temperature
  - Vegetation LAI
  - Atmospheric optical thickness and TB
  - Snow (single-layer)
  - Snow (multi-layer) 
  - Incident Angle
* Output
  - Output
  - Output: Level-1
  - Output: Level-2
  - Output: Level-3
  - Output: Level-4


#===================
# CMEM NetCDF I/O
#===================
input config : input # configuration of namelists
input files  : [elem].nc
output files : out*.nc


put option CFINOUT='netcdf' in file 'input'.


#==========
# NetCDF
#==========
* To use NetCDF, you need to install NetCDF

  https://www.unidata.ucar.edu/software/netcdf


#=========
# Input
#=========
* Prepare the forcing file according to your run config. Here NetCDF input required
* forcing files must be consistent in terms of grid size (checked in rdcmemnetcdfinfo.F90)
* file dimension differs depending on input file (Take care of it)


#=================================================
# Input: Main (soil moisuture, soil temperature)
#=================================================
* required for any option
* defalt: number of soil layer (NLAY_SOIL_LS) = 3
* Dimension N = lat x lon x time x lev

  STL1.nc     # Soil temperature level 1 (K)
  STL2.nc     # Soil temperature level 2 (K)
  STL3.nc     # Soil temperature level 3 (K)
  TSKIN.nc    # Skin temperature (K)
  SWVL1.nc    # Volumetric soil moisture level1 (m3/m3)
  SWVL2.nc    # Volumetric soil moisture level2 (m3/m3)
  SWVL3.nc    # Volumetric soil moisture level3 (m3/m3)


#=========================
# Input: Soil condition
#=========================
* required for any option
* Dimension N = lat x lon

  Z.nc        # Geopotential at surface (km)
              # (Take care that is is in km for netcdf input, while m2/s2 when grib or ascii are used)
  sand.nc     # Fraction of sandy textured soil (%) range 0-100
  clay.nc     # Fraction of clay  textured soil (%) range 0-100


#=====================
# Input: Vegetation
#=====================
* required file depends on options CIVEG:
* Dimension N = lat x lon

  #--------------------------
  # if CIVEG = 'Ecoclimap'
  #--------------------------
  ECOCVL.nc    # fraction of low veg (-)
  ECOCVH.nc    # fraction of high veg (-)
               # These fractions are such as their sum is the complement to one of the bare soil fraction:
               # bare soil frac = 1- cvh+cvl
  ECOTVL.nc    # low veg type
  ECOTVH.nc    # high veg type
  ECOWAT.nc    # water fraction (-)

  #------------------------------------
  # if CIVEG = 'Tessel' or 'HTessel'
  #------------------------------------
  CVL.nc       # fraction of low veg (-)
  CVH.nc       # fraction of high veg (-)
               # Appart for desert areas these fractions are such as their sum is 1
               # Accordingly a weigting function is applied to these fractions to compute bare soil
  TVL.nc       # low veg type
  TVH.nc       # high veg type
  LSM.nc       # land fraction (water fraction is set = 1-LSM) (-)

  #-----------------------
  # Useful information:
  #-----------------------
  ECOCLIMAP types are:
  No vegetation:   0
  High vegetation: 1 Decidious forests; 2 Coniferous forests; 3 Rain forests
  Low vegetation:  4 C3 Grasslands;     5 C4 Grasslands;      6 C3 Crops;
                   7 C4 Crops

  TESSEL types are:
  High vegetation: 3 Evergreen Needleleaf Trees; 4 Deciduous Needleleaf Trees; 5 eciduous Broadleaf Trees;
                   6 Evergreen Broadleaf Trees; 18 Mixed Forest/woodland;     19 Interrupted Forest
  Low vegetation:  1 Crops, Mixed Farming;       2 Short Grass;                7 Tall Grass;
                   9 Tundra;                    10 Irrigated Crops;           11 Semidesert;
                  13 Bogs and Marshes;          16 Evergreen Shrubs;          17 Deciduous Shrubs;
                  20 Water and Land Mixtures

  Vegetation tables are provided in vegtable.F90


#=============================
# Input: 2m air temperature
#=============================
* required if
       (CITVEG = 'Tair'     or 'Da_dual_all' or 'Ds_dual_onlysnow')
    or (CIATM  = 'Pellarin' or 'Ulaby'       or 'Input')
* Dimension N = lat x lon x time x lev

  2T.nc # 2m air temperature (K)


#=========================
# Input: Vegetation LAI
#=========================
* required if CIDVEG = 'HTessel' or 'Ecoclimap'
* required file depends on options CIVEG:
* Dimension N = lat x lon x time x lev

  #--------------------------
  # if CIVEG = 'Ecoclimap'
  #--------------------------
  ECOLAIL.nc     # LAI of low veg for each pixel

  #------------------------
  # if CIVEG = 'HTessel'
  #------------------------
  LAIL.nc        # LAI of low veg for each pixel


#===============================================
# Input: Atmospheric optical thickness and TB
#===============================================
* required if CIATM = 'Input'
* Dimension N = lat x lon x time x lev

  TAU_ATM.nc    # optical thickness of atmosphere (zenith opacity / cos(angle))
  TB_AU.nc      # upward   atmospheric radiation (TB) (K)
  TB_AD.nc      # downward atmospheric radiation (TB) (K)


#==============================
# Input: Snow (single-layer)
#==============================
* required if CISNOWSET = 'Single'
* Dimension N = lat x lon x time x lev

  #-------------------------------------------------
  # Snow depth in water equivalent (single-layer)
  #-------------------------------------------------
  * required if CISNOWSET = 'Single'

  SD.nc # snow depth in water equivalent (m)

  #-------------------------------
  # Snow density (single-layer)
  #-------------------------------
  * required if CISNOWSET = 'Single'

  RSN.nc # snow density (kg/m3)

  #-----------------------------------
  # Snow temperature (single-layer)
  #-----------------------------------
  * required if CISNOWSET = 'Single' and CISNOWTEMP = 'Snowtemp'

  TSNOW.nc # snow temperature (K)

  #--------------------------------------------
  # Snow liquid water content (single-layer)
  #--------------------------------------------
  * required if CISNOWSET = 'Single' and CISNOWMV = 'Input'

  SLW.nc # snow liquid water content (kg/m2)


#===========================
# Input: Multi-layer Snow
#===========================

* required if CISNOWSET = 'Multi'
* NLAY_SNOW: number of snow layers
* Dimension N = lat x lon x time x lev

  #-------------------
  # Layer structure
  #-------------------

  AIR

  ----------------------------------
  snow layer 1 (top layer)
  ----------------------------------
  snow layer 2
  ----------------------------------
  ...
  ----------------------------------
  snow layer NLAY_SNOW (bottom)
  ==================================
  SOIL

  (Note: see 'Ignored data' and 'Ignored layer')

  #--------------------------------------------------------------
  # Snow depth (WEQ) (multi-layer)
  #   Take care that this is in [kg/m2] for multi-layer input,
  #   while [m] are used for single-layer input SD.nc
  #--------------------------------------------------------------
  * required if CISNOWSET = 'Multi'

  SDWEQ_1.nc            # snow water equivalent (kg/m2) : layer 1 (top)
  SDWEQ_2.nc            # snow water equivalent (kg/m2) : layer 2
  ...                   # snow water equivalent (kg/m2) : layer ...
  SDWEQ_$NLAY_SNOW.nc   # snow water equivalent (kg/m2) : layer NLAY_SNOW (bottom)

  #------------------------------------------
  # Snow liquid water content: multi-layer
  #------------------------------------------
  SLW_1.nc              # snow liquid water content (kg/m2) : layer 1 (top)
  SLW_2.nc              # snow liquid water content (kg/m2) : layer 2
  ...                   # snow liquid water content (kg/m2) : layer ...
  SLW_$NLAY_SNOW.nc     # snow liquid water content (kg/m2) : layer NLAY_SNOW (bottom)

  #-----------------------------
  # Snow density: multi-layer
  #-----------------------------
  RSN_1.nc              # snow density (kg/m3) : layer 1 (top)
  RSN_2.nc              # snow density (kg/m3) : layer 2
  ...                   # snow density (kg/m3) : layer ...
  RSN_$NLAY_SNOW.nc     # snow density (kg/m3) : layer NLAY_SNOW (bottom)

  #---------------------------------
  # Snow temperature: multi-layer
  #---------------------------------
  TSNOW_1.nc            # snow temperature (K) : layer 1 (top)
  TSNOW_2.nc            # snow temperature (K) : layer 2
  ...                   # snow temperature (K) : layer ...
  TSNOW_$NLAY_SNOW.nc   # snow temperature (K) : layer NLAY_SNOW (bottom)

  #----------------------
  # NOTE: Ignored data
  #----------------------
  * if total snow water equivalent < 0.01 (m), the point is treated as without snow.

  #-----------------------
  # NOTE: Ignored layer
  #-----------------------
  * if snow depth (WEQ)          >= 9999 or <= 0, the layer (about snow-weq, snow-lwc, snow-dense, snow-t) is ignored at the point.
  * if snow liquid water content >= 9999 or <= 0, the layer (about snow-weq, snow-lwc, snow-dense, snow-t) is ignored at the point.


#=========================
# Input: Incident Angle
#=========================
* required if LTHETA_CONST = .False.
* Dimension N = lat x lon x time x lev

  ANGLE.nc             # Incident angle (degrees)



#==========
# Output
#==========
* option JPHISTLEV in file 'input' defines levels of outputs
* variables in output filename

    $CNAMEID : Summarize of options    # e.g. WaWiFrWiWiPeTsHTTeWaNoNoHsSiTsCoEf 
    $FREQ    : frequency      [0.1GHz] # e.g. 0014 (1.4[GHz])
    $ANGLE   : Incident angle [degree] # e.g. 040  (40[degree])

* details of $CNAMEID

    Option CNAMEIDTYPE in file 'input' defines the length of $CNAMEID

    if CNAMEIDTYPE = 'CI-0'

      $CNAMEID = ''

    if CNAMEIDTYPE = 'CI-8' # as CMEM.v5.1

      $CNAMEID =  CIDIEL(1:2)     # first and second characters about option CIDIEL (e.g. 'Wa' if CIDIEL='Wang')
                + CITEFF(1:2)     # same as above
                + CISMR (1:2)     # same as above
                + CIRGHR(1:2)     # same as above
                + CIVEG (1:2)     # same as above
                + CIATM (1:2)     # same as above
                + CITVEG(1:2)     # same as above
                + CIDVEG(1:2)     # same as above

    if CNAMEIDTYPE = 'CI-ALL'

      $CNAMEID =  CIDIEL    (1:2) # same as above
                + CITEFF    (1:2)
                + CISMR     (1:2)
                + CIRGHR    (1:2)
                + CIVEG     (1:2)
                + CIATM     (1:2)
                + CITVEG    (1:2)
                + CIDVEG    (1:2)
                + CITDIEL   (1:2)
                + CIVEGDW   (1:2)
                + CIVEGDI   (1:2)
                + CIDESERT  (1:2)
                + CISNOW    (1:2)
                + CISNOWSET (1:2)
                + CISNOWTEMP(1:2)
                + CISNOWMV  (1:2)
                + CIOTEFF   (1:2)


#====================================
# Output: Level-1 (JPHISTLEV >= 1)
#====================================

  out_level1_$OPTID_$FREQ_$ANGLE.nc

  * dimension N = lat x lon x time x lev
  * variables

    LONGITUDE      (LONGITUDE)                   # longtitude
    LATITUDE       (LATITUDE)                    # latitude
    LEV            (LEV)                         # level
    TIME           (TIME)                        # time
    TBH            (TIME,LEV,LATITUDE,LONGITUDE) # simulated brightness temperature (H-pol) [K]
    TBV            (TIME,LEV,LATITUDE,LONGITUDE) # simulated brightness temperature (V-pol) [K]
    EFFECTIVE_TEMP (TIME,LEV,LATITUDE,LONGITUDE) # effective temperature (H-pol) [K]


#====================================
# Output: Level-2 (JPHISTLEV >= 2)
#====================================

  out_level2_$OPTID_$FREQ_$ANGLE.nc

  * dimension N = lat x lon x time x lev
  * variables

  LONGITUDE         (LONGITUDE)                   # longitude
  LATITUDE          (LATITUDE)                    # latitude
  LEV               (LEV)                         # level
  TIME              (TIME)                        # time
  TAU_VEG_H         (TIME,LEV,LATITUDE,LONGITUDE) # effective vegetation opacity (H-pol) [-]
  TAU_VEG_V         (TIME,LEV,LATITUDE,LONGITUDE) # effective vegetation opacity (V-pol) [-]
  BARE_FRACT        (TIME,LEV,LATITUDE,LONGITUDE) # total bare soil fraction [-]
  VEG_WATER_CONTENT (TIME,LEV,LATITUDE,LONGITUDE) # total vegetation water content [kg/m2]
  TAU_ATM           (TIME,LEV,LATITUDE,LONGITUDE) # atmospheric optical depth
  TB_ATM_UP         (TIME,LEV,LATITUDE,LONGITUDE) # atmospheric TB (upward) [K]
  TB_ATM_DW         (TIME,LEV,LATITUDE,LONGITUDE) # atmospheric TB (downward) [K]


#====================================
# Output: Level-3 (JPHISTLEV >= 3)
#====================================

  out_level2_$OPTID_$FREQ_$ANGLE.nc

  * dimension N = lat x lon x time x lev
  * variables

  LONGITUDE              (LONGITUDE)                   # longitude
  LATITUDE               (LATITUDE)                    # latitude
  LEV                    (LEV)                         # level
  TIME                   (TIME)                        # time
  BARE_FRACT_NOSNOW      (TIME,LEV,LATITUDE,LONGITUDE) # pure (no snow) bare soil fraction [-]
  LOW_VEG_FRACT_NOSNOW   (TIME,LEV,LATITUDE,LONGITUDE) # pure (no snow) low vegetation fraction [-]
  LOW_VEG_FRACT          (TIME,LEV,LATITUDE,LONGITUDE) # low vegetation fraction (snow + no snow) [-]
  HIGH_VEG_FRACT         (TIME,LEV,LATITUDE,LONGITUDE) # high vegetation fraction (snow + no snow) [-]
  LOW_VEG_WATER_CONTENT  (TIME,LEV,LATITUDE,LONGITUDE) # low vegetation water content [kg/m2]
  HIGH_VEG_WATER_CONTENT (TIME,LEV,LATITUDE,LONGITUDE) # high vegetation water content [kg/m2]
  LOW_VEG_B_PARAM        (TIME,LEV,LATITUDE,LONGITUDE) # low vegetation b parameter (if CIVEG=Jackson)
  HIGH_VEG_B_PARAM       (TIME,LEV,LATITUDE,LONGITUDE) # high vegetation b parameter (if CIVEG=Jackson)
  RUGO_H                 (TIME,LEV,LATITUDE,LONGITUDE) # roughness parameter
  WILTING_PT_SM          (TIME,LEV,LATITUDE,LONGITUDE) # wilting point soil moisture [cm3/cm3]
  EMIS_H                 (TIME,LEV,LATITUDE,LONGITUDE) # soil surface emissivity (H-pol) [-]
  EMIS_V                 (TIME,LEV,LATITUDE,LONGITUDE) # soil surface emissivity (V-pol) [-]
  C_PARAM_TEFF           (TIME,LEV,LATITUDE,LONGITUDE) # C parameter used for effective temperature
  EMIS_EFF_H             (TIME,LEV,LATITUDE,LONGITUDE) # effective emissivity (H-pol) [-]
  EMIS_EFF_V             (TIME,LEV,LATITUDE,LONGITUDE) # effective emissivity (V-pol) [-]
  TB_VEG_H               (TIME,LEV,LATITUDE,LONGITUDE) # vegetation TB (H-pol) [K]
  TB_VEG_V               (TIME,LEV,LATITUDE,LONGITUDE) # vegetation TB (V-pol) [K]
  TB_SOIL_H              (TIME,LEV,LATITUDE,LONGITUDE) # soil TB (H-pol) [K]
  TB_SOIL_V              (TIME,LEV,LATITUDE,LONGITUDE) # soil TB (V-pol) [K]
  FRACT_SAND             (TIME,LEV,LATITUDE,LONGITUDE) # sand fraction [%]
  FRACT_CLAY             (TIME,LEV,LATITUDE,LONGITUDE) # cray fraction [%]
  FRACT_FROST            (TIME,LEV,LATITUDE,LONGITUDE) # frozen soil fraction [-]
  FRACT_SNOW             (TIME,LEV,LATITUDE,LONGITUDE) # snow cover fraction [-]
  SNOW_MVMAX             (TIME,LEV,LATITUDE,LONGITUDE) # volume fraction of liquid water (maximum value in snowlayers at the point) [-]
  TEFF_OUT               (TIME,LEV,LATITUDE,LONGITUDE) # effective temperature used for calculating effective emissivity [K]


#====================================
# Output: Level-4 (JPHISTLEV >= 4)
#====================================
* LEVEL-4 outputs are ignored in NetCDF I/O