Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
direct_soil_moisture__gridded_data.F90
Go to the documentation of this file.
1!> @file
2!! Contains the module \ref direct_soil_moisture__gridded_data.
3
4!>
5!! Module \ref direct_soil_moisture__gridded_data
6!! provides support for adding miscellaneous source and sink terms.
7
9
10 use iso_c_binding
12 use datetime
13 use data_catalog
15 use dictionary
16 use exceptions
19 use parameters, only : params
21 use fstring
22 use fstring_list
23
24 implicit none
25
26 private
27
29
32
33 real (c_float), allocatable :: fseptic_discharge(:)
34 real (c_float), allocatable :: fannual_septic_discharge(:)
35
36 real (c_float), allocatable :: fseptic_discharge_table(:)
37 real (c_float), allocatable :: fannual_septic_discharge_table(:)
38
39 type (t_netcdf4_file), pointer :: pncfile
40
42
43contains
44
45 !> Initialize the routine to enable input/output of arbitrary sources/sink terms
46 !! to be added directly to SOIL MOISTURE.
47 !!
48 !! Open gridded data file.
49 !! Open a NetCDF output file to hold variable output.
50 !!
51 !! @param[in] lActive 2D array of active cells within the model domain.
52 !! @param[in] iLanduseIndex 1D vector of indices corresponding to rows of the
53 !! landuse lookup table(s).
54 !! @param[in] dX 1D vector of X coordinates associated with the model domain.
55 !! @param[in] dY 1D vector of Y coordinates.
56 !! @param[in] dX_lon 2D array of longitude values.
57 !! @param[in] dY_lat 2D array of latitude values.
58
59 subroutine direct_soil_moisture_initialize( is_cell_active, landuse_index )
60
61 logical (c_bool), intent(in) :: is_cell_active(:,:)
62 integer (c_int), intent(in) :: landuse_index(:)
63
64 ! [ LOCALS ]
65 integer (c_int) :: istat
66 type (fstring_list_t) :: parameter_list
67 integer (c_int) :: iindex
68 integer (c_int) :: inx
69 integer (c_int) :: iny
70 integer (c_int), allocatable :: ilandusecodes(:)
71 integer (c_int) :: inumberoflanduses
72 logical (c_bool) :: larelengthsequal
73
74
75 !> Determine how many landuse codes are present
76 call parameter_list%append( "LU_Code" )
77 call parameter_list%append( "Landuse_Code" )
78
79 call params%get_parameters( slkeys=parameter_list, ivalues=ilandusecodes )
80 inumberoflanduses = count( ilandusecodes > 0 )
81
82 call parameter_list%clear()
83 call parameter_list%append( "Septic_system_discharge" )
84 call parameter_list%append( "SEPTIC_DISCHARGE" )
85 call parameter_list%append( "Daily_septic_discharge" )
86
87 call params%get_parameters( slkeys=parameter_list , fvalues=fseptic_discharge_table )
88
89 ! attempt to find a source of GRIDDED SEPTIC DISCHARGE data
90 pseptic_discharge => dat%find( "SEPTIC_DISCHARGE" )
91
92 ! look for data in the form of a grid
93 if ( associated( pseptic_discharge ) ) then
94
95 allocate( fseptic_discharge( count( is_cell_active ) ), stat=istat )
96 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
97
98 ! no grid? then look for a table version; values > TINYVAL indicate that
99 ! something is present
100 elseif ( fseptic_discharge_table(1) > ftinyval ) then
101
102 larelengthsequal = ( ( ubound(fseptic_discharge_table,1) == ubound(ilandusecodes,1) ) )
103
104 if ( .not. larelengthsequal ) &
105 call warn( smessage="The number of landuses does not match the number of annual direct" &
106 //" recharge rate values.", smodule=__file__, iline=__line__, lfatal=.true._c_bool )
107
108 allocate( fseptic_discharge( count( is_cell_active ) ), stat=istat )
109 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
110
111 ! now populate the vector of cell values
112 do iindex=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
113 fseptic_discharge( iindex ) = fseptic_discharge_table( landuse_index( iindex ) )
114 enddo
115
116 endif
117
118 call parameter_list%clear()
119 call parameter_list%append( "ANNUAL_septic_system_discharge" )
120 call parameter_list%append( "ANNUAL_SEPTIC_DISCHARGE" )
121 call parameter_list%append( "ANNUAL_septic_discharge" )
122
123 call params%get_parameters( slkeys=parameter_list , fvalues=fannual_septic_discharge_table )
124
125 ! attempt to find a source of GRIDDED ANNUAL SEPTIC DISCHARGE data
126 pannual_septic_discharge => dat%find( "ANNUAL_SEPTIC_DISCHARGE" )
127
128 ! look for data in the form of a grid
129 if ( associated( pannual_septic_discharge ) ) then
130
131 allocate( fannual_septic_discharge( count( is_cell_active ) ), stat=istat )
132 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
133
134 ! no grid? then look for a table version; values > TINYVAL indicate that
135 ! something is present
136 elseif ( fannual_septic_discharge_table(1) > ftinyval ) then
137
138 larelengthsequal = ( ( ubound(fannual_septic_discharge_table,1) == ubound(ilandusecodes,1) ) )
139
140 if ( .not. larelengthsequal ) &
141 call warn( smessage="The number of landuses does not match the number of annual direct" &
142 //" recharge rate values.", smodule=__file__, iline=__line__, lfatal=.true._c_bool )
143
144 allocate( fannual_septic_discharge( count( is_cell_active ) ), stat=istat )
145 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
146
147 ! now populate the vector of cell values
148 do iindex=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
149 fannual_septic_discharge( iindex ) = fannual_septic_discharge_table( landuse_index( iindex ) )
150 enddo
151
152 endif
153
154 ! initialize last retrieval date to something implausibly low to trigger initial read
155 ! in the calculate procedure
156 call date_of_last_retrieval%parseDate("01/01/1000")
157
159
160!--------------------------------------------------------------------------------------------------
161
162 subroutine direct_soil_moisture_calculate( direct_soil_moisture, is_cell_active, indx )
163
164 real (c_float), intent(inout) :: direct_soil_moisture
165 logical (c_bool), intent(in) :: is_cell_active(:,:)
166 integer (c_int), intent(in) :: indx
167
168 ! [ LOCALS ]
169 integer (c_int) :: ijulianday
170 integer (c_int) :: imonth
171 integer (c_int) :: iday
172 integer (c_int) :: iyear
173 integer (c_int) :: idaysinmonth
174 integer (c_int) :: inumdaysfromorigin
175 integer (c_int) :: iindex
176 real (c_float) :: ffactor
177
178 if ( .not. date_of_last_retrieval == sim_dt%curr ) then
179
180 associate( dt => sim_dt%curr )
181
182 if ( associated( pseptic_discharge ) ) then
183 call pseptic_discharge%getvalues( dt )
184 if ( pseptic_discharge%lGridHasChanged ) fseptic_discharge = &
185 pack( pseptic_discharge%pGrdBase%rData, is_cell_active )
186 endif
187
188 if ( associated( pannual_septic_discharge ) ) then
189 call pannual_septic_discharge%getvalues( dt )
190 if ( pannual_septic_discharge%lGridHasChanged ) fannual_septic_discharge = &
191 pack( pannual_septic_discharge%pGrdBase%rData, is_cell_active )
192 endif
193
194 end associate
195
197
198 endif
199
200 direct_soil_moisture = 0.0_c_float
201
202 if ( allocated( fseptic_discharge) ) direct_soil_moisture = direct_soil_moisture &
203 + fseptic_discharge( indx )
204 if ( allocated( fannual_septic_discharge) ) direct_soil_moisture = direct_soil_moisture &
205 + fannual_septic_discharge( indx ) / 365.25
206
207
208 end subroutine direct_soil_moisture_calculate
209
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public true
Defines the DATA_CATALOG_T data type, which contains type-bound procedures to add,...
type(data_catalog_t), public dat
DAT is a global to hold data catalog entries.
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition datetime.F90:9
Module direct_soil_moisture__gridded_data provides support for adding miscellaneous source and sink t...
real(c_float), dimension(:), allocatable fannual_septic_discharge
type(data_catalog_entry_t), pointer pseptic_discharge
real(c_float), dimension(:), allocatable fannual_septic_discharge_table
type(data_catalog_entry_t), pointer pannual_septic_discharge
subroutine, public direct_soil_moisture_calculate(direct_soil_moisture, is_cell_active, indx)
subroutine, public direct_soil_moisture_initialize(is_cell_active, landuse_index)
Initialize the routine to enable input/output of arbitrary sources/sink terms to be added directly to...
real(c_float), dimension(:), allocatable fseptic_discharge
real(c_float), dimension(:), allocatable fseptic_discharge_table
subroutine, public warn(smessage, smodule, iline, shints, lfatal, iloglevel, lecho)
Provide support for use of netCDF files as input for time-varying, gridded meteorlogic data,...
type(parameters_t), public params
type(date_range_t), public sim_dt