5.13.2-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_mrm_write_fluxes_states.f90
Go to the documentation of this file.
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
20
22 use mo_kind, only : i4, dp
24 use mo_netcdf, only : ncdataset, ncvariable
30 use mo_string_utils, only : num2str
31
32 implicit none
33
34contains
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 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 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 )
70 dims = data_dims()
71 ncells = level11(idomain)%nCells
72
73 ii = 0
74
75 if (outputflxstate_mrm(1)) then
76 ii = ii + 1
77 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 if (outputflxstate_mrm(2) .AND. riv_temp_pcs%active) then
82 ii = ii + 1
83 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 allocate(out%vars(ii))
88 out%vars = tmpvars(1:ii)
89
90 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 subroutine mrm_updatedataset(nc_mrm, L11_Qmod, L11_riv_temp)
114
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 type(outputvariable), pointer, dimension(:) :: vars
124
125 integer(i4) :: ii
126
127 ii = 0
128 vars => nc_mrm%vars
129
130 if (outputflxstate_mrm(1)) then
131 ii = ii + 1
132 call vars(ii)%updateVariable(l11_qmod)
133 end if
134
135 if (outputflxstate_mrm(2) .AND. riv_temp_pcs%active .AND. present(l11_riv_temp)) then
136 ii = ii + 1
137 call vars(ii)%updateVariable(l11_riv_temp)
138 end if
139
140 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 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 )
169 dtype = data_dtype(output_double_precision_mrm)
170 dims = data_dims()
171 ncells = level0(idomain)%nCells
172
173 allocate(out%vars(1))
174 out%vars(1) = outputvariable(out%nc, "riverhead", dtype, dims, ncells, mask, output_deflate_level_mrm, .true.)
175 call set_attributes(out%vars(1)%nc, "simulated riverhead at each node at level 0", "m", output_double_precision_mrm)
176
177 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 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 type(outputvariable), pointer, dimension(:) :: vars
194
195 vars => nc_gw%vars
196 call vars(1)%updateVariable(l0_river_head)
197
198 end subroutine gw_updatedataset
199
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
Provides structures needed by mHM, mRM and/or mpr.
Provides structures needed by mHM, mRM and/or mpr.
integer(i4), public iflag_cordinate_sys
type(grid), dimension(:), allocatable, target, public level0
Provides file names and units for mRM.
character(len=*), parameter file_mrm_output
file containing mrm output
Global variables for mRM only.
logical output_double_precision_mrm
float precision in output nc files
type(riv_temp_type), public riv_temp_pcs
This is a container for the river temperature routing process (pcs)
integer(i4) output_time_reference_mrm
time reference point location in output nc files
logical, dimension(noutflxstate) outputflxstate_mrm
Define model outputs see "mhm_outputs.nml".
type(grid), dimension(:), allocatable, target, public level11
integer(i4) timestep_model_outputs_mrm
timestep for writing model outputs
integer(i4) output_deflate_level_mrm
compression of output nc files
Creates NetCDF output for different fluxes and state variables of mHM.
subroutine mrm_updatedataset(nc_mrm, l11_qmod, l11_riv_temp)
Update all variables.
type(outputdataset) function gw_outputdataset(idomain, mask)
Initialize groundwater coupling OutputDataset.
subroutine gw_updatedataset(nc_gw, l0_river_head)
Update riverhead.
type(outputdataset) function mrm_outputdataset(idomain, mask)
Initialize mRM OutputDataset.
Creates NetCDF output for different fluxes and state variables of mHM.
character(16) function, dimension(3), public data_dims()
Output variable dimension names.
character(3) function, public data_dtype(double_precision)
Output variable dtype for single or double precision.
subroutine, public set_attributes(var, long_name, unit, double_precision, add_coords, standard_name, axis, bounds)
Write output variable attributes.