Soil Water Balance (SWB2)
Toggle main menu visibility
Loading...
Searching...
No Matches
simulation_datetime.F90
Go to the documentation of this file.
1
module
simulation_datetime
2
3
use
iso_c_binding
4
use
datetime
5
implicit none
6
7
private
8
9
type
,
public
::
date_range_t
10
type
(
datetime_t
) :: start
11
type
(
datetime_t
) :: end
12
type
(
datetime_t
) :: curr
13
integer (c_int)
:: idoy
14
integer (c_int)
:: idaysinmonth
15
integer (c_int)
:: idaysinyear
16
integer (c_int)
:: iyearofsimulation = 1
17
logical (c_bool)
:: lisleapyear
18
integer (c_int)
:: inumdaysfromorigin = 0
19
integer (c_int)
:: idayofsimulation = 0
20
21
contains
22
23
procedure
::
initialize_datetimes_sub
24
generic :: initialize =>
initialize_datetimes_sub
25
26
procedure
::
days_from_origin_fn
27
generic :: days_from_origin =>
days_from_origin_fn
28
29
procedure
::
increment_by_one_day_sub
30
generic :: addday =>
increment_by_one_day_sub
31
32
procedure
::
advance_curr_to_last_day_of_year_sub
33
generic :: advance_to_last_doy =>
advance_curr_to_last_day_of_year_sub
34
35
procedure
::
advance_curr_to_last_day_of_month_sub
36
generic :: advance_to_last_day_of_month =>
advance_curr_to_last_day_of_month_sub
37
38
procedure
::
set_curr_to_arbitrary_date_sub
39
generic :: set_current_date =>
set_curr_to_arbitrary_date_sub
40
41
procedure
:: percent_complete =>
percent_complete_fn
42
43
end type
date_range_t
44
45
type
(
date_range_t
),
public
::
sim_dt
46
47
contains
48
49
subroutine
initialize_datetimes_sub
( this, start_date, end_date )
50
51
class(
date_range_t
),
intent(inout)
:: this
52
type
(DATETIME_T),
intent(inout)
:: start_date
53
type
(DATETIME_T),
intent(inout)
:: end_date
54
55
this%start = start_date
56
this%end = end_date
57
this%curr = start_date
58
59
end subroutine
initialize_datetimes_sub
60
61
!------------------------------------------------------------------------------
62
63
subroutine
set_curr_to_arbitrary_date_sub
(this, new_current_date)
64
65
class(
date_range_t
),
intent(inout)
:: this
66
type
(DATETIME_T),
intent(in)
:: new_current_date
67
68
if
(( new_current_date > this%end ) .or. ( new_current_date < this%start )) &
69
stop(
"Attempted to set current date to one outside of start and end date."
)
70
71
this%curr = new_current_date
72
this%iNumDaysFromOrigin = int(this%days_from_origin( new_current_date ), c_int)
73
this%iDaysInMonth = this%curr%dayspermonth()
74
this%iDaysInYear = this%curr%daysperyear()
75
this%lIsLeapYear = this%curr%isLeapYear()
76
this%iDOY =
day_of_year
( this%curr%getJulianDay() )
77
this%iDayOfSimulation = int(this%curr - this%start + 1, c_int)
78
79
end subroutine
set_curr_to_arbitrary_date_sub
80
81
!------------------------------------------------------------------------------
82
83
subroutine
advance_curr_to_last_day_of_year_sub
(this)
84
85
class(
date_range_t
),
intent(inout)
:: this
86
87
this%curr%iMonth = 12
88
this%curr%iDay = 31
89
90
call
this%curr%calcJulianDay()
91
92
this%iDaysInMonth = this%curr%dayspermonth()
93
this%iDaysInYear = this%curr%daysperyear()
94
this%lIsLeapYear = this%curr%isLeapYear()
95
this%iDOY =
day_of_year
( this%curr%getJulianDay() )
96
this%iYearOfSimulation = this%curr%iYear - this%start%iYear + 1
97
this%iNumDaysFromOrigin = this%iNumDaysFromOrigin + 1
98
this%iDayOfSimulation = int(this%curr - this%start + 1, c_int)
99
100
end subroutine
advance_curr_to_last_day_of_year_sub
101
102
!------------------------------------------------------------------------------
103
104
subroutine
advance_curr_to_last_day_of_month_sub
(this)
105
106
class(
date_range_t
),
intent(inout)
:: this
107
108
call
this%curr%advanceLastDayOfMonth()
109
110
! this%iDaysInMonth = this%curr%dayspermonth()
111
! this%iDaysInYear = this%curr%daysperyear()
112
! this%lIsLeapYear = this%curr%isLeapYear()
113
this%iDOY =
day_of_year
( this%curr%getJulianDay() )
114
this%iYearOfSimulation = this%curr%iYear - this%start%iYear + 1
115
this%iNumDaysFromOrigin = this%iNumDaysFromOrigin + 1
116
this%iDayOfSimulation = int(this%curr - this%start + 1, c_int)
117
118
end subroutine
advance_curr_to_last_day_of_month_sub
119
120
!------------------------------------------------------------------------------
121
122
function
days_from_origin_fn
(this, datetime )
result
( num_days_from_origin )
123
124
class(
date_range_t
),
intent(inout)
:: this
125
type
(
datetime_t
),
intent(in)
::
datetime
126
real
(c_double) :: num_days_from_origin
127
128
num_days_from_origin = real(
datetime
- this%start, c_double)
129
130
end function
days_from_origin_fn
131
132
function
percent_complete_fn
( this )
result
( percent_complete )
133
134
class(
date_range_t
),
intent(inout)
:: this
135
real
(c_float) :: percent_complete
136
137
percent_complete = real(this%curr - this%start) / real( this%end - this%start ) * 100.
138
139
end function
percent_complete_fn
140
141
!------------------------------------------------------------------------------
142
143
subroutine
increment_by_one_day_sub
(this)
144
145
class(
date_range_t
),
intent(inout)
:: this
146
147
call
this%curr%addDay()
148
149
this%iDaysInMonth = this%curr%dayspermonth()
150
this%iDaysInYear = this%curr%daysperyear()
151
this%lIsLeapYear = this%curr%isLeapYear()
152
this%iDOY =
day_of_year
( this%curr%getJulianDay() )
153
this%iYearOfSimulation = this%curr%iYear - this%start%iYear + 1
154
this%iNumDaysFromOrigin = this%iNumDaysFromOrigin + 1
155
this%iDayOfSimulation = int(this%curr - this%start + 1, c_int)
156
157
end subroutine
increment_by_one_day_sub
158
159
end module
simulation_datetime
datetime
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition
datetime.F90:9
datetime::day_of_year
integer(c_int) function, public day_of_year(ijd)
Definition
datetime.F90:1458
simulation_datetime
Definition
simulation_datetime.F90:1
simulation_datetime::advance_curr_to_last_day_of_month_sub
subroutine advance_curr_to_last_day_of_month_sub(this)
Definition
simulation_datetime.F90:105
simulation_datetime::percent_complete_fn
real(c_float) function percent_complete_fn(this)
Definition
simulation_datetime.F90:133
simulation_datetime::sim_dt
type(date_range_t), public sim_dt
Definition
simulation_datetime.F90:45
simulation_datetime::increment_by_one_day_sub
subroutine increment_by_one_day_sub(this)
Definition
simulation_datetime.F90:144
simulation_datetime::advance_curr_to_last_day_of_year_sub
subroutine advance_curr_to_last_day_of_year_sub(this)
Definition
simulation_datetime.F90:84
simulation_datetime::set_curr_to_arbitrary_date_sub
subroutine set_curr_to_arbitrary_date_sub(this, new_current_date)
Definition
simulation_datetime.F90:64
simulation_datetime::initialize_datetimes_sub
subroutine initialize_datetimes_sub(this, start_date, end_date)
Definition
simulation_datetime.F90:50
simulation_datetime::days_from_origin_fn
real(c_double) function days_from_origin_fn(this, datetime)
Definition
simulation_datetime.F90:123
datetime::datetime_t
Definition
datetime.F90:38
simulation_datetime::date_range_t
Definition
simulation_datetime.F90:9
src
simulation_datetime.F90
Generated on
for Soil Water Balance (SWB2) by
1.17.0