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
40
41contains
42
43 !> Initialize the routine to enable input/output of arbitrary sources/sink terms
44 !! to be added directly to SOIL MOISTURE.
45 !!
46 !! Open gridded data file.
47 !! Open a NetCDF output file to hold variable output.
48 !!
49 !! @param[in] lActive 2D array of active cells within the model domain.
50 !! @param[in] iLanduseIndex 1D vector of indices corresponding to rows of the
51 !! landuse lookup table(s).
52 !! @param[in] dX 1D vector of X coordinates associated with the model domain.
53 !! @param[in] dY 1D vector of Y coordinates.
54 !! @param[in] dX_lon 2D array of longitude values.
55 !! @param[in] dY_lat 2D array of latitude values.
56
57 subroutine direct_soil_moisture_initialize( is_cell_active, landuse_index )
58
59 logical (c_bool), intent(in) :: is_cell_active(:,:)
60 integer (c_int), intent(in) :: landuse_index(:)
61
62 ! [ LOCALS ]
63 integer (c_int) :: istat
64 type (fstring_list_t) :: parameter_list
65 integer (c_int) :: iindex
66 integer (c_int), allocatable :: ilandusecodes(:)
67 integer (c_int) :: inumberoflanduses
68 logical (c_bool) :: larelengthsequal
69
70
71 !> Determine how many landuse codes are present
72 call parameter_list%append( "LU_Code" )
73 call parameter_list%append( "Landuse_Code" )
74
75 call params%get_parameters( slkeys=parameter_list, ivalues=ilandusecodes )
76 inumberoflanduses = count( ilandusecodes > 0 )
77
78 call parameter_list%clear()
79 call parameter_list%append( "Septic_system_discharge" )
80 call parameter_list%append( "SEPTIC_DISCHARGE" )
81 call parameter_list%append( "Daily_septic_discharge" )
82
83 call params%get_parameters( slkeys=parameter_list , fvalues=fseptic_discharge_table )
84
85 ! attempt to find a source of GRIDDED SEPTIC DISCHARGE data
86 pseptic_discharge => dat%find( "SEPTIC_DISCHARGE" )
87
88 ! look for data in the form of a grid
89 if ( associated( pseptic_discharge ) ) then
90
91 allocate( fseptic_discharge( count( is_cell_active ) ), stat=istat )
92 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
93
94 ! no grid? then look for a table version; values > TINYVAL indicate that
95 ! something is present
96 elseif ( fseptic_discharge_table(1) > ftinyval ) then
97
98 larelengthsequal = ( ( ubound(fseptic_discharge_table,1) == ubound(ilandusecodes,1) ) )
99
100 if ( .not. larelengthsequal ) &
101 call warn( smessage="The number of landuses does not match the number of annual direct" &
102 //" recharge rate values.", smodule=__file__, iline=__line__, lfatal=.true._c_bool )
103
104 allocate( fseptic_discharge( count( is_cell_active ) ), stat=istat )
105 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
106
107 ! now populate the vector of cell values
108 do iindex=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
109 fseptic_discharge( iindex ) = fseptic_discharge_table( landuse_index( iindex ) )
110 enddo
111
112 endif
113
114 call parameter_list%clear()
115 call parameter_list%append( "ANNUAL_septic_system_discharge" )
116 call parameter_list%append( "ANNUAL_SEPTIC_DISCHARGE" )
117 call parameter_list%append( "ANNUAL_septic_discharge" )
118
119 call params%get_parameters( slkeys=parameter_list , fvalues=fannual_septic_discharge_table )
120
121 ! attempt to find a source of GRIDDED ANNUAL SEPTIC DISCHARGE data
122 pannual_septic_discharge => dat%find( "ANNUAL_SEPTIC_DISCHARGE" )
123
124 ! look for data in the form of a grid
125 if ( associated( pannual_septic_discharge ) ) then
126
127 allocate( fannual_septic_discharge( count( is_cell_active ) ), stat=istat )
128 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
129
130 ! no grid? then look for a table version; values > TINYVAL indicate that
131 ! something is present
132 elseif ( fannual_septic_discharge_table(1) > ftinyval ) then
133
134 larelengthsequal = ( ( ubound(fannual_septic_discharge_table,1) == ubound(ilandusecodes,1) ) )
135
136 if ( .not. larelengthsequal ) &
137 call warn( smessage="The number of landuses does not match the number of annual direct" &
138 //" recharge rate values.", smodule=__file__, iline=__line__, lfatal=.true._c_bool )
139
140 allocate( fannual_septic_discharge( count( is_cell_active ) ), stat=istat )
141 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
142
143 ! now populate the vector of cell values
144 do iindex=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
145 fannual_septic_discharge( iindex ) = fannual_septic_discharge_table( landuse_index( iindex ) )
146 enddo
147
148 endif
149
150 ! initialize last retrieval date to something implausibly low to trigger initial read
151 ! in the calculate procedure
152 call date_of_last_retrieval%parseDate("01/01/1000")
153
155
156!--------------------------------------------------------------------------------------------------
157
158 subroutine direct_soil_moisture_calculate( direct_soil_moisture, is_cell_active, indx )
159
160 real (c_float), intent(inout) :: direct_soil_moisture
161 logical (c_bool), intent(in) :: is_cell_active(:,:)
162 integer (c_int), intent(in) :: indx
163
164 ! [ LOCALS ]
165
166 if ( .not. date_of_last_retrieval == sim_dt%curr ) then
167
168 associate( dt => sim_dt%curr )
169
170 if ( associated( pseptic_discharge ) ) then
171 call pseptic_discharge%getvalues( dt )
172 if ( pseptic_discharge%lGridHasChanged ) fseptic_discharge = &
173 pack( pseptic_discharge%pGrdBase%rData, is_cell_active )
174 endif
175
176 if ( associated( pannual_septic_discharge ) ) then
177 call pannual_septic_discharge%getvalues( dt )
178 if ( pannual_septic_discharge%lGridHasChanged ) fannual_septic_discharge = &
179 pack( pannual_septic_discharge%pGrdBase%rData, is_cell_active )
180 endif
181
182 end associate
183
185
186 endif
187
188 direct_soil_moisture = 0.0_c_float
189
190 if ( allocated( fseptic_discharge) ) direct_soil_moisture = direct_soil_moisture &
191 + fseptic_discharge( indx )
192 if ( allocated( fannual_septic_discharge) ) direct_soil_moisture = direct_soil_moisture &
193 + fannual_septic_discharge( indx ) / 365.25
194
195
196 end subroutine direct_soil_moisture_calculate
197
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