Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
maximum_net_infiltration.F90
Go to the documentation of this file.
1!> @file
2!! Contains the module \ref maximum_net_infiltration__gridded_data.
3
4!>
5!! Module \ref maximum_net_infiltration__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
18 use grid
19 use logfiles
21 use parameters, only : params
23 use fstring
24 use fstring_list
25
26 implicit none
27
28 private
29
31
33 real (c_float), allocatable :: fmaximum_net_infiltration(:)
34 real (c_float), allocatable :: fmaximum_net_infiltration_array(:,:)
35 real (c_float), allocatable :: fmaximum_net_infiltration_table(:,:)
36
37contains
38
39 !> Initialize the routine to establish maximum potential recharge rates.
40 !!
41 !! Open gridded data file.
42 !! Open a NetCDF output file to hold variable output.
43 !!
44 !! @param[in] lActive 2D array of active cells within the model domain.
45 !! @param[in] iLanduseIndex 1D vector of indices corresponding to rows of the
46 !! landuse lookup table(s).
47
48 subroutine maximum_net_infiltration_initialize( is_cell_active, landuse_index )
49
50 logical (c_bool), intent(in) :: is_cell_active(:,:)
51 integer (c_int), intent(in) :: landuse_index(:)
52
53 ! [ LOCALS ]
54 integer (c_int) :: istat
55 type (fstring_list_t) :: parameter_list
56 type (fstring_list_t) :: max_net_infiltration_list
57 integer (c_int), allocatable :: landuse_codes(:)
58 integer (c_int) :: soils_indx
59 integer (c_int) :: landuse_indx
60 integer (c_int) :: number_of_landuses
61 integer (c_int) :: number_of_soils
62 real (c_float) :: value
63
64
65 type (data_catalog_entry_t), pointer :: phsg
66 type (data_catalog_entry_t), pointer :: plulc
67
68 plulc => dat%find("LAND_USE")
69 phsg => dat%find("HYDROLOGIC_SOILS_GROUP")
70
71 call assert( associated( plulc), "Possible INTERNAL PROGRAMMING ERROR -- Null pointer" &
72 //" detected for pLULC", __file__, __line__ )
73
74 call assert( associated( plulc%pGrdBase ), &
75 "Possible INTERNAL PROGRAMMING ERROR -- Null pointer detected for pLULC%pGrdBase", &
76 __file__, __line__ )
77
78 call assert( allocated( plulc%pGrdBase%iData ), &
79 "Possible INTERNAL PROGRAMMING ERROR -- Unallocated array detected for pLULC%pGrdBase%iData", &
80 __file__, __line__ )
81
82 call assert( associated( phsg), "Possible INTERNAL PROGRAMMING ERROR -- Null pointer" &
83 //" detected for pHSG", __file__, __line__ )
84
85 call assert( associated( phsg%pGrdBase ), &
86 "Possible INTERNAL PROGRAMMING ERROR -- Null pointer detected for pHSG%pGrdBase", &
87 __file__, __line__ )
88
89 call assert( allocated( phsg%pGrdBase%iData ), &
90 "Possible INTERNAL PROGRAMMING ERROR -- Unallocated array detected for pHSG%pGrdBase%iData", &
91 __file__, __line__ )
92
93
94 ! attempt to find a source of GRIDDED MAXIMUM_NET_INFILTRATION data
95 pmaximum_net_infiltration => dat%find( "MAXIMUM_NET_INFILTRATION" )
96
97 ! retrieve a string list of all keys associated with Max_recharge (i.e. Max_recharge_1, Max_recharge_2, etc.)
98 max_net_infiltration_list = params%grep_name("max_net_infil", lfatal=true )
99
100 ! look for data in the form of a grid
101 if ( associated( pmaximum_net_infiltration ) ) then
102
103 allocate( fmaximum_net_infiltration( count( is_cell_active ) ), stat=istat )
104 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
105
106 associate( dt => sim_dt%curr )
107
108 if ( associated( pmaximum_net_infiltration ) ) then
109 ! NB: maximum potential recharge
110 call pmaximum_net_infiltration%getvalues( )
111 if ( pmaximum_net_infiltration%lGridHasChanged ) &
112 fmaximum_net_infiltration = pack( pmaximum_net_infiltration%pGrdBase%rData, is_cell_active )
113 endif
114
115 end associate
116
117 elseif ( max_net_infiltration_list%get(1) /= "<NA>" ) then ! no gridded data; read from TABLE values
118
119 call parameter_list%append("LU_Code")
120 call parameter_list%append("Landuse_Code")
121 call parameter_list%append("Landuse_Lookup_Code")
122
123 !> Determine how many landuse codes are present
124 call params%get_parameters( slkeys=parameter_list, ivalues=landuse_codes )
125 number_of_landuses = count( landuse_codes >= 0 )
126
127 call params%get_parameters( fvalues=fmaximum_net_infiltration_table, &
128 sprefix="max_net_infil", &
129 inumrows=number_of_landuses, &
130 lfatal=true )
131
132 number_of_soils = ubound( fmaximum_net_infiltration_table, 2 )
133
134 call logs%WRITE( "| Landuse Code | Soils Code | Number of Matches | Maximum net infiltration (in) |", &
135 iloglevel = log_debug, lecho = false )
136 call logs%WRITE( "|-------------|--------------|-------------------|--------------------------------| ", &
137 iloglevel = log_debug, lecho = false )
138
139 allocate( fmaximum_net_infiltration_array( ubound(is_cell_active,1),ubound(is_cell_active,2) ), stat=istat )
140 call assert( istat == 0, "Failed to allocate memory for maximum potential recharge table", &
141 __file__, __line__)
142
143 do soils_indx = 1, number_of_soils
144 do landuse_indx = 1, number_of_landuses
145
146 call logs%WRITE( "| "//ascharacter(landuse_codes( landuse_indx) )//" | "//ascharacter(soils_indx)//" | "// &
147 ascharacter(count( plulc%pGrdBase%iData == landuse_codes( landuse_indx) &
148 .and. phsg%pGrdBase%iData == soils_indx ) )//" | " &
149 //ascharacter( fmaximum_net_infiltration_table( landuse_indx, soils_indx))//" |", &
150 iloglevel = log_debug, lecho = false )
151
152 value = fmaximum_net_infiltration_table( landuse_indx, soils_indx )
153
154 where ( plulc%pGrdBase%iData == landuse_codes( landuse_indx) .and. phsg%pGrdBase%iData == soils_indx )
155
157
158 endwhere
159
160 enddo
161
162 enddo
163
165
168
169 call parameter_list%clear()
170
171 else ! neither TABLE nor GRIDDED Maximum Potential Recharge values were given;
172 ! default to ridiculously high maximum potential recharge
173
174 allocate( fmaximum_net_infiltration( count( is_cell_active ) ), stat=istat )
175 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
176
178
179 call warn( "Did not find any valid maximum net infiltration rate parameters.", &
180 lfatal = true )
181
182 endif
183
185
186!--------------------------------------------------------------------------------------------------
187
188 elemental subroutine maximum_net_infiltration_calculate( net_infiltration, &
189 rejected_net_infiltration, &
190 indx )
191
192 real ( c_float), intent(inout) :: net_infiltration
193 real (c_float), intent(inout) :: rejected_net_infiltration
194 integer (c_int), intent(in) :: indx
195
196 if ( net_infiltration > fmaximum_net_infiltration( indx ) ) then
197
198 rejected_net_infiltration = net_infiltration - fmaximum_net_infiltration( indx )
199 net_infiltration = fmaximum_net_infiltration( indx )
200
201 else
202
203 rejected_net_infiltration = 0.0_c_float
204
205 endif
206
208
209
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public true
logical(c_bool), parameter, public false
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
subroutine, public warn(smessage, smodule, iline, shints, lfatal, iloglevel, lecho)
Provides support for input and output of gridded ASCII data, as well as for creation and destruction ...
Definition grid.F90:8
type(logfile_t), public logs
Definition logfiles.F90:62
Module maximum_net_infiltration__gridded_data provides support for adding miscellaneous source and si...
real(c_float), dimension(:,:), allocatable fmaximum_net_infiltration_table
subroutine, public maximum_net_infiltration_initialize(is_cell_active, landuse_index)
Initialize the routine to establish maximum potential recharge rates.
type(data_catalog_entry_t), pointer pmaximum_net_infiltration
real(c_float), dimension(:,:), allocatable fmaximum_net_infiltration_array
real(c_float), dimension(:), allocatable fmaximum_net_infiltration
elemental subroutine, public maximum_net_infiltration_calculate(net_infiltration, rejected_net_infiltration, indx)
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