LCOV - code coverage report
Current view: top level - mRM - mo_mrm_write_fluxes_states.f90 (source / functions) Hit Total Coverage
Test: mHM coverage Lines: 29 42 69.0 %
Date: 2024-04-15 17:48:09 Functions: 2 4 50.0 %

          Line data    Source code
       1             : !> \file mo_mrm_write_fluxes_states.f90
       2             : !> \brief   \copybrief mo_mrm_write_fluxes_states
       3             : !> \details \copydetails mo_mrm_write_fluxes_states
       4             : 
       5             : !> \brief Creates NetCDF output for different fluxes and state variables of mHM.
       6             : !> \details NetCDF is first initialized and later on variables are put to the NetCDF.
       7             : !> \changelog
       8             : !! - David Schaefer       Aug 2015
       9             : !!   - major rewrite
      10             : !! - Stephan Thober       Oct 2015
      11             : !!   - adapted to mRM
      12             : !! - O. Rakovec, R. Kumar Nov 2017
      13             : !!   - added project description for the netcdf outputs
      14             : !> \authors Matthias Zink
      15             : !> \date Apr 2013
      16             : !> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
      17             : !! mHM is released under the LGPLv3+ license \license_note
      18             : !> \ingroup f_mrm
      19             : module mo_mrm_write_fluxes_states
      20             : 
      21             :   use mo_nc_output, only: OutputDataset, OutputVariable, set_attributes, data_dims, data_dtype
      22             :   use mo_kind, only : i4, dp
      23             :   use mo_common_constants, only : nodata_dp
      24             :   use mo_netcdf, only : NcDataset, NcVariable
      25             :   use mo_mrm_global_variables, only : output_deflate_level_mrm, output_double_precision_mrm, &
      26             :     output_time_reference_mrm, timeStep_model_outputs_mrm, outputFlxState_mrm, riv_temp_pcs, level11
      27             :   use mo_common_mHM_mRM_variables, only: timeStep
      28             :   use mo_mrm_file, only : file_mrm_output
      29             :   use mo_common_variables, only : iFlag_cordinate_sys, level0
      30             :   use mo_String_utils, only : num2str
      31             : 
      32             :   implicit none
      33             : 
      34             : contains
      35             : 
      36             :   !> \brief Initialize mRM OutputDataset
      37             :   !> \details Create and initialize the output file. If new a new output
      38             :   !! variable needs to be written, this is the first of two
      39             :   !! procedures to change (second: updateDataset)
      40             :   !> \changelog
      41             :   !! - Robert Schweppe Jun 2018
      42             :   !!   - refactoring and reformatting
      43             :   !! - Sebastian Mueller Jul 2020
      44             :   !!   - added output for river temperature
      45             :   !> \return type(OutputDataset)
      46             :   !> \authors Matthias Zink
      47             :   !> \date Apr 2013
      48           4 :   function mRM_OutputDataset(iDomain, mask) result(out)
      49             :     implicit none
      50             : 
      51             :     integer(i4), intent(in) :: iDomain !< domain id
      52             :     logical, intent(in), pointer, dimension(:, :) :: mask !< L11 mask
      53             : 
      54             :     type(OutputDataset) :: out
      55             : 
      56             :     integer(i4) :: ii, nCells
      57             :     character(3) :: dtype
      58             :     character(16), dimension(3) :: dims
      59          32 :     type(OutputVariable), dimension(size(outputFlxState_mrm)) :: tmpvars
      60             : 
      61             :     out = OutputDataset( &
      62             :       iDomain=iDomain, &
      63             :       level=level11, &
      64             :       file_name=file_mrm_output, &
      65             :       double_precision=output_double_precision_mrm, &
      66             :       outputs_frequence=timeStep_model_outputs_mrm, &
      67             :       time_reference=output_time_reference_mrm &
      68           4 :     )
      69           4 :     dtype = data_dtype(output_double_precision_mrm)
      70           4 :     dims = data_dims()
      71           4 :     nCells = level11(iDomain)%nCells
      72             : 
      73           4 :     ii = 0
      74             : 
      75           8 :     if (outputFlxState_mrm(1)) then
      76           4 :       ii = ii + 1
      77           4 :       tmpvars(ii) = OutputVariable(out%nc, "Qrouted", dtype, dims, nCells, mask, output_deflate_level_mrm, .true.)
      78             :       call set_attributes(tmpvars(ii)%nc, "routed streamflow", "m3 s-1", output_double_precision_mrm)
      79             :     end if
      80             : 
      81           5 :     if (outputFlxState_mrm(2) .AND. riv_temp_pcs%active) then
      82           1 :       ii = ii + 1
      83           1 :       tmpvars(ii) = OutputVariable(out%nc, "RivTemp", dtype, dims, nCells, mask, output_deflate_level_mrm, .true.)
      84             :       call set_attributes(tmpvars(ii)%nc, "routed river temperature", "degC", output_double_precision_mrm)
      85             :     end if
      86             : 
      87          17 :     allocate(out%vars(ii))
      88          13 :     out%vars = tmpvars(1:ii)
      89             : 
      90           4 :   end function mRM_OutputDataset
      91             : 
      92             :   !> \brief Update all variables.
      93             :   !> \details Call the type bound procedure updateVariable for
      94             :   !! all output variables. If a new output
      95             :   !! variable needs to be written, this is the second
      96             :   !! of two procedures to change (first: newOutputDataset)
      97             :   !!
      98             :   !> \changelog
      99             :   !! - L. Samaniego et al. Dec  2013
     100             :   !!   - nullify pointer Matthias Zink,        Feb. 2014
     101             :   !!   - added aditional output: pet V. Prykhodk, J. Mai,  Nov. 2014
     102             :   !!   - adding new variable infilSoil
     103             :   !!   - case 16 David Schaefer      , Jun. 2015
     104             :   !!   - major rewrite
     105             :   !! - Stephan Thober      Oct  2015
     106             :   !!   - adapted to mRM
     107             :   !! - Robert Schweppe     Jun  2018
     108             :   !!   - refactoring and reformatting
     109             :   !! - Sebastian Mueller   Jul  2020
     110             :   !!   - add river temperature output (optional)
     111             :     !> \authors Matthias Zink
     112             :   !> \date Apr 2013
     113       70080 :   subroutine mRM_updateDataset(nc_mrm, L11_Qmod, L11_riv_temp)
     114             : 
     115           4 :     use mo_mrm_global_variables, only : outputFlxState_mrm
     116             : 
     117             :     implicit none
     118             : 
     119             :     class(OutputDataset), intent(inout), target :: nc_mrm
     120             :     real(dp), intent(in), dimension(:) :: L11_Qmod
     121             :     real(dp), intent(in), dimension(:), optional :: L11_riv_temp
     122             : 
     123       35040 :     type(OutputVariable), pointer, dimension(:) :: vars
     124             : 
     125             :     integer(i4) :: ii
     126             : 
     127       35040 :     ii = 0
     128       35040 :     vars => nc_mrm%vars
     129             : 
     130       35040 :     if (outputFlxState_mrm(1)) then
     131       35040 :       ii = ii + 1
     132       35040 :       call vars(ii)%updateVariable(L11_Qmod)
     133             :     end if
     134             : 
     135       35040 :     if (outputFlxState_mrm(2) .AND. riv_temp_pcs%active .AND. present(L11_riv_temp)) then
     136        8760 :       ii = ii + 1
     137        8760 :       call vars(ii)%updateVariable(L11_riv_temp)
     138             :     end if
     139             : 
     140       35040 :   end subroutine mRM_updateDataset
     141             : 
     142             :   !> \brief Initialize groundwater coupling OutputDataset
     143             :   !> \details Create and initialize the output file. If new a new output
     144             :   !! variable needs to be written, this is the first of two
     145             :   !! procedures to change (second: updateDataset)
     146             :   !> \return type(OutputDataset)
     147             :   !> \authors Sebastian Mueller
     148             :   !> \date Dec 2022
     149           0 :   function GW_OutputDataset(iDomain, mask) result(out)
     150             :     implicit none
     151             : 
     152             :     integer(i4), intent(in) :: iDomain !< domain id
     153             :     logical, intent(in), target, dimension(:, :) :: mask !< L11 mask
     154             : 
     155             :     type(OutputDataset) :: out
     156             : 
     157             :     integer(i4) :: nCells
     158             :     character(3) :: dtype
     159             :     character(16), dimension(3) :: dims
     160             : 
     161             :     out = OutputDataset( &
     162             :       iDomain=iDomain, &
     163             :       level=level0, &
     164             :       file_name='mRM_riverhead_' // trim(num2str(iDomain, '(i3.3)')) // '.nc', &
     165             :       double_precision=output_double_precision_mrm, &
     166             :       outputs_frequence=timeStep_model_outputs_mrm, &
     167             :       time_reference=output_time_reference_mrm &
     168           0 :     )
     169           0 :     dtype = data_dtype(output_double_precision_mrm)
     170           0 :     dims = data_dims()
     171           0 :     nCells = level0(iDomain)%nCells
     172             : 
     173           0 :     allocate(out%vars(1))
     174           0 :     out%vars(1) = OutputVariable(out%nc, "riverhead", dtype, dims, nCells, mask, output_deflate_level_mrm, .true.)
     175           0 :     call set_attributes(out%vars(1)%nc, "simulated riverhead at each node at level 0", "m", output_double_precision_mrm)
     176             : 
     177       35040 :   end function GW_OutputDataset
     178             : 
     179             :   !> \brief Update riverhead.
     180             :   !> \details Call the type bound procedure updateVariable for
     181             :   !! all output variables. If a new output
     182             :   !! variable needs to be written, this is the second
     183             :   !! of two procedures to change (first: newOutputDataset)
     184             :   !> \authors Sebastian Mueller
     185             :   !> \date Dec 2022
     186           0 :   subroutine GW_updateDataset(nc_gw, L0_river_head)
     187             : 
     188             :     implicit none
     189             : 
     190             :     class(OutputDataset), intent(inout), target :: nc_gw
     191             :     real(dp), intent(in), dimension(:) :: L0_river_head
     192             : 
     193           0 :     type(OutputVariable), pointer, dimension(:) :: vars
     194             : 
     195           0 :     vars => nc_gw%vars
     196           0 :     call vars(1)%updateVariable(L0_river_head)
     197             : 
     198           0 :   end subroutine GW_updateDataset
     199             : 
     200             : end module mo_mrm_write_fluxes_states

Generated by: LCOV version 1.16