Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
simulation_datetime.F90
Go to the documentation of this file.
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
24 generic :: initialize => initialize_datetimes_sub
25
27 generic :: days_from_origin => days_from_origin_fn
28
30 generic :: addday => increment_by_one_day_sub
31
33 generic :: advance_to_last_doy => advance_curr_to_last_day_of_year_sub
34
36 generic :: advance_to_last_day_of_month => advance_curr_to_last_day_of_month_sub
37
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
47contains
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 = this%days_from_origin( new_current_date )
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 = this%curr - this%start + 1
78
80
81!------------------------------------------------------------------------------
82
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 = this%curr - this%start + 1
99
101
102!------------------------------------------------------------------------------
103
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 = this%curr - this%start + 1
117
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
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 = this%curr - this%start + 1
156
157 end subroutine increment_by_one_day_sub
158
159end module simulation_datetime
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition datetime.F90:9
integer(c_int) function, public day_of_year(ijd)
subroutine advance_curr_to_last_day_of_month_sub(this)
real(c_float) function percent_complete_fn(this)
type(date_range_t), public sim_dt
subroutine increment_by_one_day_sub(this)
subroutine advance_curr_to_last_day_of_year_sub(this)
subroutine set_curr_to_arbitrary_date_sub(this, new_current_date)
subroutine initialize_datetimes_sub(this, start_date, end_date)
real(c_double) function days_from_origin_fn(this, datetime)