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
37
38 call params%get_parameters(skey="PRCP", fvalues=precip)
39 call params%get_parameters(skey="TMIN", fvalues=tmin)
40 call params%get_parameters(skey="TMAX", fvalues=tmax)
41
42 !> read in dates as a string list
43 call params%get_parameters( skey="Date", slvalues=sllist)
44
45 allocate(weather_date(sllist%count), stat=istat)
46 call assert( istat==0, "Failed to allocate memory for WEATHER_DATE array", &
47 __file__, __line__ )
48
49 call logs%write(" Date | PRCP | TMIN | TMAX")
50 call logs%write("-------------|---------------|--------------|--------------")
51
52 call weather_date(1)%setDateFormat(sdateformat="YYYY-MM-DD")
53
54 print *, "Scanning weather data file for anomalies... There are "//ascharacter(sllist%count)//" entries."
55
56
57 error_count = 0
58
59 do indx=1, sllist%count
60
61 date_str = sllist%get(indx)
62 call weather_date(indx)%parsedate( date_str, __file__, __line__ )
63
64 if (indx == 1) tempdate = weather_date(1)
65
66 do
67 if ( ( tempdate < sim_dt%start ) .or. ( tempdate > sim_dt%end ) ) then
68
69 error_count = 0
70 ! NOP
71 exit
72
73 elseif ( (weather_date(indx) == tempdate) .and. (error_count == 0)) then
74
75 if (precip(indx) <= na_float) call warn("Missing PRCP value for "//weather_date(indx)%prettydate(), lfatal=true)
76 if (tmax(indx) <= na_float) call warn("Missing TMAX value for "//weather_date(indx)%prettydate(), lfatal=true)
77 if (tmin(indx) <= na_float) call warn("Missing TMIN value for "//weather_date(indx)%prettydate(), lfatal=true)
78
79 call logs%write(weather_date(indx)%prettydate()//" | "//ascharacter(precip(indx))//" | " &
80 //ascharacter(tmin(indx))//" | " &
81 //ascharacter(tmax(indx)))
82
83 exit
84
85 elseif ((weather_date(indx) == tempdate) .and. (error_count > 0)) then
86
87 call warn("Missing or out of order date sequence "//ascharacter(error_count)//" value(s) in" &
88 //" single-station weather data file. Problem date(s) span "//firstdate%prettydate()//" to " &
89 //lastdate%prettydate()//".", lfatal=true)
90 error_count = 0
91 exit
92 elseif (error_count == 0) then
93
94 firstdate = tempdate
95 error_count = error_count + 1
96 lastdate = weather_date(indx) - 1
97 call tempdate%addDay()
98 cycle
99 else
100
101 error_count = error_count + 1
102 call tempdate%addDay()
103 cycle
104
105 endif
106
107 enddo
108
109 call tempdate%addDay()
110
111 enddo
112
113 ! can we really have set up the code to use a GLOBAL value for the default
114 ! date format?? That needs to change.
115 call weather_date(1)%setDateFormat(sdateformat="MM-DD-YYYY")
116
118
119!-----------------------------------------------------------------------------------
120
122
123 type (DATETIME_T), intent(in) :: dt
124
125 integer (c_int) :: indx
126 logical (c_bool) :: date_found
127
128 date_found = false
129
130 do indx=date_indx, size(weather_date%iJulianDay,1)
131
132 if (weather_date(indx) == dt) then
133 date_found = true
134 date_indx = indx
135 exit
136 endif
137
138 enddo
139
140 call assert(date_found, "Failed to find a matching date value in the daily weather data table.", &
141 __file__, __line__)
142
143 end subroutine weather_data_find_date_indx
144
145!-----------------------------------------------------------------------------------
146
147 subroutine weather_data_tabular_get_precip( dt, precip_value )
148
149 type (DATETIME_T), intent(in) :: dt
150 real (kind=c_float), intent(out) :: precip_value
151
153
154 precip_value = precip(date_indx)
155
157
158!-----------------------------------------------------------------------------------
159
160 subroutine weather_data_tabular_get_tmax( dt, tmax_value )
161
162 type (DATETIME_T), intent(in) :: dt
163 real (kind=c_float), intent(out) :: tmax_value
164
166 tmax_value = tmax(date_indx)
167
168 end subroutine weather_data_tabular_get_tmax
169
170!-----------------------------------------------------------------------------------
171
172 subroutine weather_data_tabular_get_tmin( dt, tmin_value )
173
174 type (DATETIME_T), intent(in) :: dt
175 real (kind=c_float), intent(out) :: tmin_value
176
178 tmin_value = tmin(date_indx)
179
180 end subroutine weather_data_tabular_get_tmin
181
182
183end 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, private na_float
Definition fstring.F90:178
real(c_float), parameter, public na_float
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