Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
storm_drain_capture.F90
Go to the documentation of this file.
2
3 use iso_c_binding
4
8 use datetime, only : datetime_t
9 use grid, only : grid_writearcgrid
10 use logfiles, only : logs, log_all
11 use exceptions, only : warn, assert
12 use parameters, only : params
13 use simulation_datetime, only : sim_dt
15 use fstring, only : ascharacter
16 implicit none
17
18 private
19
22
24 real (c_float), allocatable :: storm_drain_capture_fraction(:)
25 real (c_float), allocatable :: storm_drain_capture_fraction_table(:)
27
28contains
29
30 subroutine storm_drain_capture_initialize( is_cell_active, landuse_index )
31
32 logical (c_bool), intent(in) :: is_cell_active(:,:)
33 integer (c_int), intent(in) :: landuse_index(:)
34
35 ! [ LOCALS ]
36 integer (c_int) :: number_of_landuse_codes
37 integer (c_int), allocatable :: lu_codes(:)
38 integer (c_int) :: indx
39 integer (c_int) :: num_records
40 logical :: are_lengths_unequal
41 type (fstring_list_t) :: string_list
42 integer (c_int) :: status
43 character (len=256) :: sbuf
44
45 call string_list%append("LU_Code")
46 call string_list%append("Landuse_Code")
47 call string_list%append("Landuse_Lookup_Code")
48
49 !> Determine how many UNIQUE landuse codes are present
50 call params%get_parameters( slkeys=string_list, ivalues=lu_codes )
51 number_of_landuse_codes = count( lu_codes >= 0 )
52
53 call string_list%clear()
54 call string_list%append("Storm_drain_capture")
55 call string_list%append("Storm_drain_capture_fraction")
56
57 allocate( storm_drain_capture_fraction( count( is_cell_active ) ), stat=status )
58 call assert( status==0, "Problem allocating STORM_DRAIN_CAPTURE_FRACTION", &
59 __file__, __line__ )
60
61 ! set default value for STORM_DRAIN_CAPTURE_FRACTION
63
64 !> Determine how many storm_drain_capture codes are present
65 call params%get_parameters( slkeys=string_list, fvalues=storm_drain_capture_fraction_table )
66
67 call string_list%clear()
68
69 ! attempt to locate storm drain capture information in gridded format
70 pstorm_drain_capture_fraction => dat%find( "STORM_DRAIN_CAPTURE_FRACTION" )
71
72 if ( associated( pstorm_drain_capture_fraction ) ) then
73
74 ! nothing to do...
75
77
78 !> check: number of STORM_DRAIN_CAPTURE_FRACTION_TABLE values == number of landuse codes?
79 num_records = ubound(storm_drain_capture_fraction_table, 1)
80 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
81
82 if ( are_lengths_unequal ) then
83
84 sbuf = "The number of values specifying storm drain capture" &
85 //" fraction (" &
86 //ascharacter( num_records )//") does not match the number of landuse values (" &
87 //ascharacter( number_of_landuse_codes )//"). Setting default storm drain" &
88 //" capture to 0.0 (ZERO)."
89
90 call warn( smessage=trim(sbuf), &
91 smodule=__file__, &
92 iline=__line__, &
93 lfatal=.false._c_bool, &
94 iloglevel=log_all )
95
97
98 else
99
100 do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
102 enddo
103
104 endif
105
106 deallocate( storm_drain_capture_fraction_table, stat=status )
107 call assert( status==0, "Problem allocating STORM_DRAIN_CAPTURE_FRACTION_TABLE", &
108 __file__, __line__ )
109
110 endif
111
112 end subroutine storm_drain_capture_initialize
113
114!--------------------------------------------------------------------------------------------------
115
116 subroutine storm_drain_capture_calculate( capture_fraction, indx, is_cell_active )
117
118 real (c_float), intent(inout) :: capture_fraction
119 integer (c_int), intent(in) :: indx
120 logical (c_bool), intent(in) :: is_cell_active(:,:)
121
122 ! attempt to update values from gridded source, if active
123 if ( .not. date_of_last_retrieval == sim_dt%curr ) then
124
125 associate( dt => sim_dt%curr )
126
127 if ( associated( pstorm_drain_capture_fraction ) ) then
128 call pstorm_drain_capture_fraction%getvalues( dt )
129 if ( pstorm_drain_capture_fraction%lGridHasChanged ) then
130 storm_drain_capture_fraction = pack( pstorm_drain_capture_fraction%pGrdBase%rData, is_cell_active )
131 call grid_writearcgrid("Storm_drain_capture_fraction__as_read_into_SWB.asc", &
133 endif
134 endif
135
137
138 end associate
139
140 endif
141
142 if ( allocated( storm_drain_capture_fraction ) ) &
143 capture_fraction = storm_drain_capture_fraction( indx )
144
145 end subroutine storm_drain_capture_calculate
146
147end module storm_drain_capture
This module contains physical constants and convenience functions aimed at performing unit conversion...
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
subroutine, public grid_writearcgrid(sfilename, pgrd)
Definition grid.F90:1056
type(logfile_t), public logs
Definition logfiles.F90:62
type(parameters_t), public params
type(date_range_t), public sim_dt
subroutine, public storm_drain_capture_initialize(is_cell_active, landuse_index)
type(datetime_t) date_of_last_retrieval
type(data_catalog_entry_t), pointer pstorm_drain_capture_fraction
real(c_float), dimension(:), allocatable storm_drain_capture_fraction_table
real(c_float), dimension(:), allocatable, public storm_drain_capture_fraction
subroutine, public storm_drain_capture_calculate(capture_fraction, indx, is_cell_active)