LCOV - code coverage report
Current view: top level - mHM - mo_mhm_read_config.f90 (source / functions) Hit Total Coverage
Test: mHM coverage Lines: 104 131 79.4 %
Date: 2024-04-15 17:48:09 Functions: 1 1 100.0 %

          Line data    Source code
       1             : !> \file mo_mhm_read_config.f90
       2             : !> \brief   \copybrief mo_mhm_read_config
       3             : !> \details \copydetails mo_mhm_read_config
       4             : 
       5             : !> \brief Reading of main model configurations.
       6             : !> \details This routine reads the configurations of mHM including, input and
       7             : !!       output directories, module usage specification, simulation time periods,
       8             : !!       global parameters, ...
       9             : !> \authors Matthias Zink
      10             : !> \date Dec 2012
      11             : !> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
      12             : !! mHM is released under the LGPLv3+ license \license_note
      13             : !> \ingroup f_mhm
      14             : MODULE mo_mhm_read_config
      15             : 
      16             :   USE mo_kind, ONLY : i4, dp
      17             :   use mo_message, only: message, error_message
      18             : 
      19             :   IMPLICIT NONE
      20             : 
      21             :   PRIVATE
      22             : 
      23             :   PUBLIC :: mhm_read_config ! read main directories
      24             : 
      25             :   ! ------------------------------------------------------------------
      26             : 
      27             : CONTAINS
      28             : 
      29             :   ! ------------------------------------------------------------------
      30             : 
      31             :   !    NAME
      32             :   !        mhm_read_config
      33             : 
      34             :   !    PURPOSE
      35             :   !>       \brief Read main configurations for mHM
      36             : 
      37             :   !>       \details The main configurations in mHM are read from three files:
      38             :   !>       <ol>
      39             :   !>       <li> mhm.nml
      40             :   !>       <li> mhm_parameters.nml
      41             :   !>       <li> mhm_outputs.nml
      42             :   !>       </ol>
      43             :   !>       For details please refer to the above mentioned namelist files.
      44             : 
      45             :   !    INTENT(IN)
      46             :   !>       \param[in] "character(*) :: file_namelist"
      47             :   !>       \param[in] "integer :: unamelist"
      48             : 
      49             :   !    HISTORY
      50             :   !>       \authors Matthias Zink
      51             : 
      52             :   !>       \date Dec 2012
      53             : 
      54             :   ! Modifications:
      55             :   ! Luis Samaniego               Jan 2013 - messages Rohini Kumar
      56             :   ! Matthias Cuntz               Jan  2013 - namelist consolidation and positioning
      57             :   ! Matthias Zink                Jan  2013 - bug fix, added gaugeinfo reading
      58             :   ! Rohini Kumar                 Jun  2013 - added restart flags
      59             :   ! R. Kumar & S. Thober         Aug  2013 - code change to incorporate output timestep during
      60             :   !                                          writing of the netcdf file
      61             :   ! Rohini Kumar                 Aug  2013 - name changed from "inputFormat" to inputFormat_meteo_forcings
      62             :   ! Rohini Kumar                 Aug  2013 - added dirSoil_LUT and dirGeology_LUT, and changed
      63             :   !                                          in namelist made accordingly
      64             :   ! Rohini Kumar                 Aug  2013 - added new namelist for LAI related datasets, and changed in within
      65             :   !                                          the code made accordingly
      66             :   ! Matthias Zink                Aug  2013 - changed read in for land cover period
      67             :   ! Juliane Mai                  Oct  2013 - adding global_parameters_name
      68             :   ! Matthias Zink                Nov  2013 - edited documentation and included DEFAULT cases for ptocess Matrix
      69             :   ! Stephan Thober               Nov  2013 - added read of directories where latitude longitude fields are located
      70             :   ! Matthias Zink                Feb  2014 - added multiple options for PET process
      71             :   ! Matthias Zink                Mar  2014 - added inflow from upstream areas and gauge information as namelist
      72             :   ! Rohini Kumar                 May  2014 - added options for the model run coordinate system
      73             :   ! Stephan Thober               May  2014 - added switch for chunk read in
      74             :   ! Stephan Thober               Jun  2014 - added option for switching off mpr
      75             :   ! Matthias Cuntz & Juliane Mai Nov  2014 - LAI input from daily, monthly or yearly files
      76             :   ! Matthias Zink                Dec  2014 - adopted inflow gauges to ignore headwater cells
      77             :   ! Matthias Zink                Mar  2015 - added optional soil moisture read in for calibration
      78             :   ! Matthias Cuntz               Jul  2015 - removed adjustl from trim(adjustl()) of Geoparams for PGI compatibilty
      79             :   ! Stephan Thober               Aug  2015 - added read_config_routing and read_routing_params from mRM
      80             :   ! Oldrich Rakovec              Oct  2015 - added reading of the domain average TWS data
      81             :   ! Rohini Kumar                 Mar  2016 - options to handle different soil databases
      82             :   ! Stephan Thober               Nov  2016 - moved nProcesses and processMatrix to common variables
      83             :   ! Rohini Kumar                 Dec  2016 - option to handle monthly mean gridded fields of LAI
      84             :   ! M.Zink & M. Cuneyd Demirel   Mar  2017 - Added Jarvis soil water stress function at SM process(3)
      85             :   ! M.C. Demirel & Simon Stisen  Apr  2017 - Added FC dependency on root fraction coefficient (ET) at SM process(3)
      86             :   ! Robert Schweppe              Dec  2017 - switched from fractional julian day to integer
      87             :   ! Robert Schweppe              Jun  2018 - refactoring and reformatting
      88             : 
      89          14 :   subroutine mhm_read_config(file_namelist, unamelist)
      90             : 
      91             :     use mo_common_constants, only : maxNoDomains, nodata_i4
      92             :     use mo_common_mHM_mRM_read_config, only : common_check_resolution
      93             :     use mo_common_mhm_mrm_variables, only : opti_function, optimize
      94             :     use mo_common_variables, only : domainMeta, processMatrix
      95             :     use mo_file, only : file_defOutput, udefOutput
      96             :     use mo_global_variables, only : &
      97             :       L1_twsaObs, L1_etObs, L1_smObs, L1_neutronsObs, &
      98             :       evap_coeff, &
      99             :       nSoilHorizons_sm_input, outputFlxState, &
     100             :       timeStep_model_outputs, &
     101             :       output_deflate_level, output_double_precision, output_time_reference, &
     102             :       BFI_calc, BFI_obs
     103             :     use mo_mpr_constants, only : maxNoSoilHorizons
     104             :     use mo_mpr_global_variables, only : nSoilHorizons_mHM
     105             :     use mo_nml, only : close_nml, open_nml, position_nml
     106             :     use mo_string_utils, only : num2str
     107             : 
     108             :     implicit none
     109             : 
     110             :     character(*), intent(in) :: file_namelist
     111             : 
     112             :     integer, intent(in) :: unamelist
     113             : 
     114             :     integer(i4) :: iDomain, domainID
     115             : 
     116             :     ! soil moisture input
     117             :     character(256), dimension(maxNoDomains) :: dir_soil_moisture
     118             : 
     119             :     ! ground albedo neutron input
     120             :     character(256), dimension(maxNoDomains) :: dir_neutrons
     121             : 
     122             :     ! evapotranspiration input
     123             :     character(256), dimension(maxNoDomains) :: dir_evapotranspiration
     124             : 
     125             :     ! tws input
     126             :     character(256), dimension(maxNoDomains) :: dir_TWS
     127             : 
     128             :     integer(i4) :: timeStep_tws_input         ! time step of optional data: tws
     129             :     integer(i4) :: timeStep_et_input          ! time step of optional data: et
     130             :     integer(i4) :: timeStep_sm_input          ! time step of optional data: sm
     131             :     integer(i4) :: timeStep_neutrons_input    ! time step of optional data: neutrons
     132             : 
     133             : 
     134             :     ! define namelists
     135             :     ! optional data used for optimization
     136             :     namelist /optional_data/ &
     137             :             dir_soil_moisture, &
     138             :             nSoilHorizons_sm_input, &
     139             :             dir_neutrons, &
     140             :             dir_evapotranspiration, &
     141             :             dir_TWS, &
     142             :             timeStep_sm_input, &
     143             :             timeStep_neutrons_input, &
     144             :             timeStep_et_input, &
     145             :             timeStep_tws_input
     146             :     ! namelist for pan evaporation
     147             :     namelist /panEvapo/evap_coeff
     148             : 
     149             :     ! name list regarding output
     150             :     namelist /NLoutputResults/ &
     151             :             output_deflate_level, &
     152             :             output_double_precision, &
     153             :             output_time_reference, &
     154             :             timeStep_model_outputs, &
     155             :             outputFlxState
     156             :     ! namelist for baseflow index optimzation
     157             :     namelist /baseflow_config/ BFI_calc, BFI_obs
     158             : 
     159             :     !===============================================================
     160             :     !  Read namelist main directories
     161             :     !===============================================================
     162          14 :     call open_nml(file_namelist, unamelist, quiet = .true.)
     163             : 
     164          68 :     allocate(L1_twsaObs(domainMeta%nDomains))
     165          68 :     allocate(L1_etObs(domainMeta%nDomains))
     166          68 :     allocate(L1_smObs(domainMeta%nDomains))
     167          68 :     allocate(L1_neutronsObs(domainMeta%nDomains))
     168             :     ! observed baseflow indizes
     169          42 :     allocate(BFI_obs(domainMeta%nDomains))
     170          54 :     BFI_obs = -1.0_dp  ! negative value to flag missing values
     171          14 :     BFI_calc = .false.
     172             : 
     173             :     !===============================================================
     174             :     !  Read namelist of optional input data
     175             :     !===============================================================
     176             :     ! read optional optional data if necessary
     177          14 :     if (optimize) then
     178           1 :       select case (opti_function)
     179             :         case(10 : 13, 28)
     180             :           ! soil moisture
     181           1 :           call position_nml('optional_data', unamelist)
     182           1 :           read(unamelist, nml = optional_data)
     183           2 :           do iDomain = 1, domainMeta%nDomains
     184           1 :             domainID = domainMeta%indices(iDomain)
     185           1 :             L1_smObs(iDomain)%dir = dir_Soil_moisture(domainID)
     186           1 :             L1_smObs(iDomain)%timeStepInput = timeStep_sm_input
     187           2 :             L1_smObs(iDomain)%varname = 'sm'
     188             :           end do
     189           1 :           if (nSoilHorizons_sm_input .GT. nSoilHorizons_mHM) then
     190           0 :             call error_message('***ERROR: Number of soil horizons representative for input soil moisture exceeded', raise=.false.)
     191           0 :             call error_message('          defined number of soil horizions: ', adjustl(trim(num2str(maxNoSoilHorizons))), '!')
     192             :           end if
     193             :         case(17)
     194             :           ! neutrons
     195           1 :           call position_nml('optional_data', unamelist)
     196           1 :           read(unamelist, nml = optional_data)
     197           2 :           do iDomain = 1, domainMeta%nDomains
     198           1 :             domainID = domainMeta%indices(iDomain)
     199           1 :             L1_neutronsObs(iDomain)%dir = dir_neutrons(domainID)
     200           1 :             L1_neutronsObs(iDomain)%timeStepInput = timeStep_neutrons_input
     201           1 :             L1_neutronsObs(iDomain)%timeStepInput = -1 ! TODO: daily, hard-coded, to be flexibilized
     202           2 :             L1_neutronsObs(iDomain)%varname = 'neutrons'
     203             :           end do
     204             :         case(27, 29, 30)
     205             :           ! evapotranspiration
     206           0 :           call position_nml('optional_data', unamelist)
     207           0 :           read(unamelist, nml = optional_data)
     208           0 :           do iDomain = 1, domainMeta%nDomains
     209           0 :             domainID = domainMeta%indices(iDomain)
     210           0 :             L1_etObs(iDomain)%dir = dir_evapotranspiration(domainID)
     211           0 :             L1_etObs(iDomain)%timeStepInput = timeStep_et_input
     212           0 :             L1_etObs(iDomain)%varname = 'et'
     213             :           end do
     214             :         case(15)
     215             :           ! domain average TWS data
     216           1 :           call position_nml('optional_data', unamelist)
     217           1 :           read(unamelist, nml = optional_data)
     218           2 :           do iDomain = 1, domainMeta%nDomains
     219           1 :             domainID = domainMeta%indices(iDomain)
     220           1 :             L1_twsaObs(iDomain)%dir = dir_TWS(domainID)
     221           1 :             L1_twsaObs(iDomain)%timeStepInput = timeStep_tws_input
     222           2 :             L1_twsaObs(iDomain)%varname = 'twsa'
     223             :           end do
     224             :         case(33)
     225             :           ! evapotranspiration
     226           1 :           call position_nml('optional_data', unamelist)
     227           1 :           read(unamelist, nml = optional_data)
     228           7 :           do iDomain = 1, domainMeta%nDomains
     229           6 :             domainID = domainMeta%indices(iDomain)
     230           6 :             L1_etObs(iDomain)%dir = dir_evapotranspiration(domainID)
     231           6 :             L1_etObs(iDomain)%timeStepInput = timeStep_et_input
     232           7 :             L1_etObs(iDomain)%varname = 'et'
     233             :           end do
     234             : 
     235             :           ! domain average TWS data
     236           1 :           call position_nml('optional_data', unamelist)
     237           1 :           read(unamelist, nml = optional_data)
     238           7 :           do iDomain = 1, domainMeta%nDomains
     239           6 :             domainID = domainMeta%indices(iDomain)
     240           6 :             L1_twsaObs(iDomain)%dir = dir_TWS(domainID)
     241           6 :             L1_twsaObs(iDomain)%timeStepInput = timeStep_tws_input
     242           7 :             L1_twsaObs(iDomain)%varname = 'twsa'
     243             :           end do
     244             : 
     245             :         case(34)
     246             :           !baseflow index optimization
     247           0 :           call position_nml('baseflow_config', unamelist)
     248           5 :           read(unamelist, nml = baseflow_config)
     249             : 
     250             :       end select
     251             :     end if
     252             : 
     253             :     !===============================================================
     254             :     ! Read pan evaporation
     255             :     !===============================================================
     256             :     ! Evap. coef. for free-water surfaces
     257          14 :     call position_nml('panEvapo', unamelist)
     258          14 :     read(unamelist, nml = panEvapo)
     259             : 
     260          14 :     call common_check_resolution(.true., .false.)
     261             : 
     262          14 :     call close_nml(unamelist)
     263             : 
     264             :     !===============================================================
     265             :     ! Read output specifications for mHM
     266             :     !===============================================================
     267          14 :     call open_nml(file_defOutput, udefOutput, quiet = .true.)
     268          14 :     output_deflate_level = 6
     269          14 :     output_time_reference = 0
     270          14 :     output_double_precision = .true.
     271          14 :     outputFlxState = .FALSE.
     272          14 :     call position_nml('NLoutputResults', udefOutput)
     273          14 :     read(udefOutput, nml = NLoutputResults)
     274          14 :     call close_nml(udefOutput)
     275             : 
     276          14 :     call message('')
     277          14 :     call message('Following output will be written:')
     278          14 :     call message('  NetCDF deflate level: ', adjustl(trim(num2str(output_deflate_level))))
     279          14 :     if ( output_double_precision ) then
     280          14 :       call message('  NetCDF output precision: double')
     281             :     else
     282           0 :       call message('  NetCDF output precision: single')
     283             :     end if
     284          14 :     select case(output_time_reference)
     285             :       case(0)
     286          14 :         call message('    NetCDF output time reference point: start of time interval')
     287             :       case(1)
     288           0 :         call message('    NetCDF output time reference point: center of time interval')
     289             :       case(2)
     290          14 :         call message('    NetCDF output time reference point: end of time interval')
     291             :     end select
     292          14 :     call message('  STATES:')
     293          14 :     if (outputFlxState(1)) then
     294           0 :       call message('    interceptional storage                          (L1_inter) [mm]')
     295             :     end if
     296          14 :     if (outputFlxState(2)) then
     297           0 :       call message('    height of snowpack                           (L1_snowpack) [mm]')
     298             :     end if
     299          14 :     if (outputFlxState(3)) then
     300          13 :       call message('    soil water content in the single layers     (L1_soilMoist) [mm]')
     301             :     end if
     302          14 :     if (outputFlxState(4)) then
     303           0 :       call message('    volumetric soil moisture in the single layers              [mm/mm]')
     304             :     end if
     305          14 :     if (outputFlxState(5)) then
     306           0 :       call message('    mean volum. soil moisture averaged over all soil layers    [mm/mm]')
     307             :     end if
     308          14 :     if (outputFlxState(6)) then
     309           0 :       call message('    waterdepth in reservoir of sealed areas       (L1_sealSTW) [mm]')
     310             :     end if
     311          14 :     if (outputFlxState(7)) then
     312           0 :       call message('    waterdepth in reservoir of unsat. soil zone  (L1_unsatSTW) [mm]')
     313             :     end if
     314          14 :     if (outputFlxState(8)) then
     315           0 :       call message('    waterdepth in reservoir of sat. soil zone      (L1_satSTW) [mm]')
     316             :     end if
     317          14 :     if (processMatrix(10, 1) .eq. 0) outputFlxState(18) = .false. ! suppress output if process is off
     318          14 :     if (outputFlxState(18)) then
     319           1 :       call message('    ground albedo neutrons                       (L1_neutrons) [cph]')
     320             :     end if
     321             : 
     322          14 :     call message('  FLUXES:')
     323          14 :     if (outputFlxState(9)) then
     324           2 :       call message('    potential evapotranspiration PET                  (L1_pet) [mm/T]')
     325             :     end if
     326          14 :     if (outputFlxState(10)) then
     327           3 :       call message('    actual evapotranspiration aET               (L1_aETCanopy) [mm/T]')
     328             :     end if
     329          14 :     if (outputFlxState(11)) then
     330          13 :       call message('    total discharge generated per cell       (L1_total_runoff) [mm/T]')
     331             :     end if
     332          14 :     if (outputFlxState(12)) then
     333           0 :       call message('    direct runoff generated per cell           (L1_runoffSeal) [mm/T]')
     334             :     end if
     335          14 :     if (outputFlxState(13)) then
     336           0 :       call message('    fast interflow generated per cell          (L1_fastRunoff) [mm/T]')
     337             :     end if
     338          14 :     if (outputFlxState(14)) then
     339           0 :       call message('    slow interflow generated per cell          (L1_slowRunoff) [mm/T]')
     340             :     end if
     341          14 :     if (outputFlxState(15)) then
     342           0 :       call message('    baseflow generated per cell                  (L1_baseflow) [mm/T]')
     343             :     end if
     344          14 :     if (outputFlxState(16)) then
     345           2 :       call message('    groundwater recharge                           (L1_percol) [mm/T]')
     346             :     end if
     347          14 :     if (outputFlxState(17)) then
     348           0 :       call message('    infiltration                                (L1_infilSoil) [mm/T]')
     349             :     end if
     350          14 :     if (outputFlxState(19)) then
     351           0 :       call message('    actual evapotranspiration from soil layers    (L1_aETSoil) [mm/T]')
     352             :     end if
     353          14 :     if (outputFlxState(20)) then
     354           0 :       call message('    effective precipitation                     (L1_preEffect) [mm/T]')
     355             :     end if
     356          14 :     if (outputFlxState(21)) then
     357           0 :       call message('    snow melt                                        (L1_melt) [mm/T]')
     358             :     end if
     359          14 :     call message('')
     360          14 :     call message('FINISHED reading config')
     361             : 
     362             :     ! warning message
     363          61 :     if (any(outputFlxState) .and. optimize) then
     364           5 :       call message('WARNING: FLUXES and STATES netCDF will be not written since optimization flag is TRUE ')
     365             :     end if
     366             : 
     367          14 :   end subroutine mhm_read_config
     368             : 
     369             : END MODULE mo_mhm_read_config

Generated by: LCOV version 1.16