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(:,:)
37
38contains
39
40 !> Initialize the routine to establish maximum potential recharge rates.
41 !!
42 !! Open gridded data file.
43 !! Open a NetCDF output file to hold variable output.
44 !!
45 !! @param[in] lActive 2D array of active cells within the model domain.
46 !! @param[in] iLanduseIndex 1D vector of indices corresponding to rows of the
47 !! landuse lookup table(s).
48
49 subroutine maximum_net_infiltration_initialize( is_cell_active, landuse_index )
50
51 logical (c_bool), intent(in) :: is_cell_active(:,:)
52 integer (c_int), intent(in) :: landuse_index(:)
53
54 ! [ LOCALS ]
55 integer (c_int) :: istat
56 type (fstring_list_t) :: parameter_list
57 type (fstring_list_t) :: max_net_infiltration_list
58 real (c_float), allocatable :: max_net_infiltration_vector(:)
59 integer (c_int), allocatable :: sequence_nums(:)
60 integer (c_int), allocatable :: landuse_codes(:)
61 logical (c_bool) :: larelengthsequal
62 integer (c_int) :: soils_indx
63 integer (c_int) :: landuse_indx
64 integer (c_int) :: number_of_landuses
65 integer (c_int) :: number_of_soils
66 real (c_float) :: value
67 integer (c_int) :: month, day,year, julian_day
68 character( len=:), allocatable :: text_str
69
70
71 type (data_catalog_entry_t), pointer :: phsg
72 type (data_catalog_entry_t), pointer :: plulc
73
74 plulc => dat%find("LAND_USE")
75 phsg => dat%find("HYDROLOGIC_SOILS_GROUP")
76
77 call assert( associated( plulc), "Possible INTERNAL PROGRAMMING ERROR -- Null pointer" &
78 //" detected for pLULC", __file__, __line__ )
79
80 call assert( associated( plulc%pGrdBase ), &
81 "Possible INTERNAL PROGRAMMING ERROR -- Null pointer detected for pLULC%pGrdBase", &
82 __file__, __line__ )
83
84 call assert( allocated( plulc%pGrdBase%iData ), &
85 "Possible INTERNAL PROGRAMMING ERROR -- Unallocated array detected for pLULC%pGrdBase%iData", &
86 __file__, __line__ )
87
88 call assert( associated( phsg), "Possible INTERNAL PROGRAMMING ERROR -- Null pointer" &
89 //" detected for pHSG", __file__, __line__ )
90
91 call assert( associated( phsg%pGrdBase ), &
92 "Possible INTERNAL PROGRAMMING ERROR -- Null pointer detected for pHSG%pGrdBase", &
93 __file__, __line__ )
94
95 call assert( allocated( phsg%pGrdBase%iData ), &
96 "Possible INTERNAL PROGRAMMING ERROR -- Unallocated array detected for pHSG%pGrdBase%iData", &
97 __file__, __line__ )
98
99
100 ! attempt to find a source of GRIDDED MAXIMUM_NET_INFILTRATION data
101 pmaximum_net_infiltration => dat%find( "MAXIMUM_NET_INFILTRATION" )
102
103 ! retrieve a string list of all keys associated with Max_recharge (i.e. Max_recharge_1, Max_recharge_2, etc.)
104 max_net_infiltration_list = params%grep_name("max_net_infil", lfatal=true )
105
106 ! look for data in the form of a grid
107 if ( associated( pmaximum_net_infiltration ) ) then
108
109 allocate( fmaximum_net_infiltration( count( is_cell_active ) ), stat=istat )
110 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
111
112 associate( dt => sim_dt%curr )
113
114 if ( associated( pmaximum_net_infiltration ) ) then
115 ! NB: maximum potential recharge
116 call pmaximum_net_infiltration%getvalues( )
117 if ( pmaximum_net_infiltration%lGridHasChanged ) &
118 fmaximum_net_infiltration = pack( pmaximum_net_infiltration%pGrdBase%rData, is_cell_active )
119 endif
120
121 end associate
122
123 elseif ( max_net_infiltration_list%get(1) /= "<NA>" ) then ! no gridded data; read from TABLE values
124
125 call parameter_list%append("LU_Code")
126 call parameter_list%append("Landuse_Code")
127 call parameter_list%append("Landuse_Lookup_Code")
128
129 !> Determine how many landuse codes are present
130 call params%get_parameters( slkeys=parameter_list, ivalues=landuse_codes )
131 number_of_landuses = count( landuse_codes >= 0 )
132
133 call params%get_parameters( fvalues=fmaximum_net_infiltration_table, &
134 sprefix="max_net_infil", &
135 inumrows=number_of_landuses, &
136 lfatal=true )
137
138 number_of_soils = ubound( fmaximum_net_infiltration_table, 2 )
139
140 call logs%WRITE( "| Landuse Code | Soils Code | Number of Matches | Maximum net infiltration (in) |", &
141 iloglevel = log_debug, lecho = false )
142 call logs%WRITE( "|-------------|--------------|-------------------|--------------------------------| ", &
143 iloglevel = log_debug, lecho = false )
144
145 allocate( fmaximum_net_infiltration_array( ubound(is_cell_active,1),ubound(is_cell_active,2) ), stat=istat )
146 call assert( istat == 0, "Failed to allocate memory for maximum potential recharge table", &
147 __file__, __line__)
148
149 do soils_indx = 1, number_of_soils
150 do landuse_indx = 1, number_of_landuses
151
152 call logs%WRITE( "| "//ascharacter(landuse_codes( landuse_indx) )//" | "//ascharacter(soils_indx)//" | "// &
153 ascharacter(count( plulc%pGrdBase%iData == landuse_codes( landuse_indx) &
154 .and. phsg%pGrdBase%iData == soils_indx ) )//" | " &
155 //ascharacter( fmaximum_net_infiltration_table( landuse_indx, soils_indx))//" |", &
156 iloglevel = log_debug, lecho = false )
157
158 value = fmaximum_net_infiltration_table( landuse_indx, soils_indx )
159
160 where ( plulc%pGrdBase%iData == landuse_codes( landuse_indx) .and. phsg%pGrdBase%iData == soils_indx )
161
163
164 endwhere
165
166 enddo
167
168 enddo
169
171
174
175 call parameter_list%clear()
176
177 else ! neither TABLE nor GRIDDED Maximum Potential Recharge values were given;
178 ! default to ridiculously high maximum potential recharge
179
180 allocate( fmaximum_net_infiltration( count( is_cell_active ) ), stat=istat )
181 call assert( istat==0, "Problem allocating memory", __file__, __line__ )
182
184
185 call warn( "Did not find any valid maximum net infiltration rate parameters.", &
186 lfatal = true )
187
188 endif
189
191
192!--------------------------------------------------------------------------------------------------
193
194 elemental subroutine maximum_net_infiltration_calculate( net_infiltration, &
195 rejected_net_infiltration, &
196 indx )
197
198 real ( c_float), intent(inout) :: net_infiltration
199 real (c_float), intent(inout) :: rejected_net_infiltration
200 integer (c_int), intent(in) :: indx
201
202 if ( net_infiltration > fmaximum_net_infiltration( indx ) ) then
203
204 rejected_net_infiltration = net_infiltration - fmaximum_net_infiltration( indx )
205 net_infiltration = fmaximum_net_infiltration( indx )
206
207 else
208
209 rejected_net_infiltration = 0.0_c_float
210
211 endif
212
214
215
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
integer(c_int) function, public julian_day(iyear, imonth, iday, iorigin, sinputitemname)
Definition datetime.F90:642
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