Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
weather_data_tabular.F90
Go to the documentation of this file.
2
3 use iso_c_binding, only : c_short, c_int, c_float, c_double, c_bool
6 use fstring, only : ascharacter, squote, operator(.contains.)
7 use parameters, only : params
9 use datetime, only : datetime_t, operator(<), operator(>)
10 use logfiles, only : logs, log_all
11 use exceptions, only : assert, warn, die
12
13 implicit none
14
15 real (c_float), allocatable :: tmin(:)
16 real (c_float), allocatable :: tmax(:)
17 real (c_float), allocatable :: precip(:)
18 type (datetime_t), allocatable :: weather_date(:)
19
20 integer (c_int), save :: date_indx = 1
21
22 private date_indx
23
24contains
25
27
28 type (FSTRING_LIST_T) :: slList
29 integer (kind=c_int) :: indx
30 integer (kind=c_int) :: iStat
31 character (len=:), allocatable :: date_str
32 type (DATETIME_T) :: tempdate
33 type (DATETIME_T) :: firstdate
34 type (DATETIME_T) :: lastdate
35 integer (c_int) :: error_count
36 integer (c_int) :: first_indx
37
38
39 call params%get_parameters(skey="PRCP", fvalues=precip)
40 call params%get_parameters(skey="TMIN", fvalues=tmin)
41 call params%get_parameters(skey="TMAX", fvalues=tmax)
42
43 !> read in dates as a string list
44 call params%get_parameters( skey="Date", slvalues=sllist)
45
46 allocate(weather_date(sllist%count), stat=istat)
47 call assert( istat==0, "Failed to allocate memory for WEATHER_DATE array", &
48 __file__, __line__ )
49
50 call logs%write(" Date | PRCP | TMIN | TMAX")
51 call logs%write("-------------|---------------|--------------|--------------")
52
53 call weather_date(1)%setDateFormat(sdateformat="YYYY-MM-DD")
54
55 print *, "Scanning weather data file for anomalies... There are "//ascharacter(sllist%count)//" entries."
56
57
58 error_count = 0
59
60 do indx=1, sllist%count
61
62 date_str = sllist%get(indx)
63 call weather_date(indx)%parsedate( date_str, __file__, __line__ )
64
65 if (indx == 1) tempdate = weather_date(1)
66
67 do
68 if ( ( tempdate < sim_dt%start ) .or. ( tempdate > sim_dt%end ) ) then
69
70 error_count = 0
71 ! NOP
72 exit
73
74 elseif ( (weather_date(indx) == tempdate) .and. (error_count == 0)) then
75
76 if (precip(indx) <= na_float) call warn("Missing PRCP value for "//weather_date(indx)%prettydate(), lfatal=true)
77 if (tmax(indx) <= na_float) call warn("Missing TMAX value for "//weather_date(indx)%prettydate(), lfatal=true)
78 if (tmin(indx) <= na_float) call warn("Missing TMIN value for "//weather_date(indx)%prettydate(), lfatal=true)
79
80 call logs%write(weather_date(indx)%prettydate()//" | "//ascharacter(precip(indx))//" | " &
81 //ascharacter(tmin(indx))//" | " &
82 //ascharacter(tmax(indx)))
83
84 exit
85
86 elseif ((weather_date(indx) == tempdate) .and. (error_count > 0)) then
87
88 call warn("Missing or out of order date sequence "//ascharacter(error_count)//" value(s) in" &
89 //" single-station weather data file. Problem date(s) span "//firstdate%prettydate()//" to " &
90 //lastdate%prettydate()//".", lfatal=true)
91 error_count = 0
92 exit
93 elseif (error_count == 0) then
94
95 firstdate = tempdate
96 error_count = error_count + 1
97 lastdate = weather_date(indx) - 1
98 call tempdate%addDay()
99 cycle
100 else
101
102 error_count = error_count + 1
103 call tempdate%addDay()
104 cycle
105
106 endif
107
108 enddo
109
110 call tempdate%addDay()
111
112 enddo
113
114 ! can we really have set up the code to use a GLOBAL value for the default
115 ! date format?? That needs to change.
116 call weather_date(1)%setDateFormat(sdateformat="MM-DD-YYYY")
117
119
120!-----------------------------------------------------------------------------------
121
123
124 type (DATETIME_T), intent(in) :: dt
125
126 integer (c_int) :: indx
127 logical (c_bool) :: date_found
128
129 date_found = false
130
131 do indx=date_indx, size(weather_date%iJulianDay,1)
132
133 if (weather_date(indx) == dt) then
134 date_found = true
135 date_indx = indx
136 exit
137 endif
138
139 enddo
140
141 call assert(date_found, "Failed to find a matching date value in the daily weather data table.", &
142 __file__, __line__)
143
144 end subroutine weather_data_find_date_indx
145
146!-----------------------------------------------------------------------------------
147
148 subroutine weather_data_tabular_get_precip( dt, precip_value )
149
150 type (DATETIME_T), intent(in) :: dt
151 real (kind=c_float), intent(out) :: precip_value
152
154
155 precip_value = precip(date_indx)
156
158
159!-----------------------------------------------------------------------------------
160
161 subroutine weather_data_tabular_get_tmax( dt, tmax_value )
162
163 type (DATETIME_T), intent(in) :: dt
164 real (kind=c_float), intent(out) :: tmax_value
165
167 tmax_value = tmax(date_indx)
168
169 end subroutine weather_data_tabular_get_tmax
170
171!-----------------------------------------------------------------------------------
172
173 subroutine weather_data_tabular_get_tmin( dt, tmin_value )
174
175 type (DATETIME_T), intent(in) :: dt
176 real (kind=c_float), intent(out) :: tmin_value
177
179 tmin_value = tmin(date_indx)
180
181 end subroutine weather_data_tabular_get_tmin
182
183
184end module weather_data_tabular
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
real(c_double), parameter, public m_per_foot
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)
subroutine, public die(smessage, smodule, iline, shints, scalledby, icalledbyline)
real(c_float), parameter, public na_float
real(c_float), parameter, private na_float
Definition fstring.F90:182
type(logfile_t), public logs
Definition logfiles.F90:62
type(parameters_t), public params
type(date_range_t), public sim_dt
subroutine weather_data_tabular_initialize()
subroutine weather_data_tabular_get_tmin(dt, tmin_value)
subroutine weather_data_find_date_indx(dt)
real(c_float), dimension(:), allocatable tmax
real(c_float), dimension(:), allocatable precip
real(c_float), dimension(:), allocatable tmin
subroutine weather_data_tabular_get_precip(dt, precip_value)
integer(c_int), save, private date_indx
subroutine weather_data_tabular_get_tmax(dt, tmax_value)
type(datetime_t), dimension(:), allocatable weather_date