SUEWS API Site
Documentation of SUEWS source code
Functions/Subroutines
suews_util_time.f95 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine day2month (b, mb, md, seas, year, latitude)
 
subroutine month2day (mon, ne, k, b)
 
subroutine leapyearcalc (year_int, nroDays)
 
elemental integer function days_of_year (year_int)
 
subroutine day_of_week (DATE, MONTH, YEAR, DOW)
 
subroutine dectime_to_timevec (dectime, HOURS, MINS, SECS)
 
subroutine daylen (DOY, XLAT, DAYL, DEC, SNDN, SNUP)
 
subroutine suews_cal_dectime (id, it, imin, isec, dectime)
 
subroutine suews_cal_tstep (tstep, nsh, nsh_real, tstep_real)
 
subroutine suews_cal_weekday (iy, id, lat, dayofWeek_id)
 
subroutine suews_cal_dls (id, startDLS, endDLS, DLS)
 

Function/Subroutine Documentation

◆ day2month()

subroutine day2month ( integer, intent(in)  b,
integer, intent(out)  mb,
integer, intent(out)  md,
integer, intent(out)  seas,
integer, intent(in)  year,
real(kind(1d0))  latitude 
)

Definition at line 24 of file suews_util_time.f95.

Referenced by initialstate(), narp_module::narp_cal_sunposition(), and suews_cal_weekday().

24  IMPLICIT NONE
25  INTEGER, INTENT(in) ::b !b=doy --IN
26  INTEGER, INTENT(out) ::mb !month=mb --OUT
27  INTEGER, INTENT(out) ::md !date=md --OUT
28  INTEGER, INTENT(out) ::seas
29  INTEGER, INTENT(in) ::year
30  INTEGER::t1, t2, t3
31  INTEGER::k ! k- accounts for leap year
32 
33  REAL(KIND(1d0))::latitude
34 
35  ! initialisation
36  mb = 1
37 
38  !Corrected and calculation of date added LJ (Jun 2010)
39 
40  t1 = 4
41  t2 = 100
42  t3 = 400
43 
44  IF ((modulo(year, t1) == 0) .AND. (modulo(year, t2) /= 0) .OR. (modulo(year, t3) == 0)) THEN
45  k = 1
46  ELSE
47  k = 0
48  ENDIF
49 
50  IF (b <= 31) THEN !January
51  mb = 1
52  md = b
53  ELSEIF (b > 31 .AND. b <= 59 + k) THEN
54  mb = 2
55  md = b - 31
56  ELSEIF (b > 59 + k .AND. b <= 90 + k) THEN
57  mb = 3
58  md = b - (59 + k)
59  ELSEIF (b > 90 + k .AND. b <= 120 + k) THEN
60  mb = 4
61  md = b - (90 + k)
62  ELSEIF (b > 120 + k .AND. b <= 151 + k) THEN
63  mb = 5
64  md = b - (120 + k)
65  ELSEIF (b > 151 + k .AND. b <= 181 + k) THEN
66  mb = 6
67  md = b - (151 + k)
68  ELSEIF (b > 181 + k .AND. b <= 212 + k) THEN
69  mb = 7
70  md = b - (181 + k)
71  ELSEIF (b > 212 + k .AND. b <= 243 + k) THEN
72  mb = 8
73  md = b - (212 + k)
74  ELSEIF (b > 243 + k .AND. b <= 273 + k) THEN
75  mb = 9
76  md = b - (243 + k)
77  ELSEIF (b > 273 + k .AND. b <= 304 + k) THEN
78  mb = 10
79  md = b - (273 + k)
80  ELSEIF (b > 304 + k .AND. b <= 334 + k) THEN
81  mb = 11
82  md = b - (304 + k)
83  ELSEIF (b > 334 + k) THEN
84  mb = 12
85  md = b - (334 + k)
86  ENDIF
87 
88  !
89  IF (latitude > 0) THEN ! Northern Hemisphere
90  IF (mb > 3 .AND. mb < 10) THEN !Summer is from Apr to Sep
91  seas = 1
92  ELSE
93  seas = 2 !Winter rest of the months
94  ENDIF
95  ELSE ! southern hemisphere
96  IF (mb < 4 .OR. mb > 9) THEN !Summer is from Oct to Mar
97  seas = 1
98  ELSE
99  seas = 2 !Winter rest of the months
100  ENDIF
101  ENDIF
102  RETURN
real(kind(1d0)) year
Here is the caller graph for this function:

◆ day_of_week()

subroutine day_of_week ( integer  DATE,
integer  MONTH,
integer  YEAR,
integer  DOW 
)

Definition at line 174 of file suews_util_time.f95.

Referenced by initialstate(), and suews_cal_weekday().

174  ! Calculate weekday from year, month and day information.
175  ! DOW: Sunday=1,...Saturday=7
176  ! YEAR fixed to integer, LJ March 2015
177 
178  IMPLICIT NONE
179 
180  INTEGER date, month, day, yr, mn, n1, n2, dow, year
181 
182  yr = year
183  mn = month
184 
185  !C
186  !C IF JANUARY OR FEBRUARY, ADJUST MONTH AND YEAR
187  !C
188  IF (mn > 2) GO TO 10
189  mn = mn + 12
190  yr = yr - 1
191 10 n1 = (26*(mn + 1))/10
192  n2 = (125*yr)/100
193  day = (date + n1 + n2 - (yr/100) + (yr/400) - 1)
194  dow = mod(day, 7) + 1
195 
196  RETURN
real(kind(1d0)) year
Here is the caller graph for this function:

◆ daylen()

subroutine daylen ( integer  DOY,
real(kind(1d0)), intent(in)  XLAT,
real(kind(1d0)), intent(out)  DAYL,
real(kind(1d0)), intent(out)  DEC,
real(kind(1d0)), intent(out)  SNDN,
real(kind(1d0)), intent(out)  SNUP 
)

Definition at line 227 of file suews_util_time.f95.

Referenced by solweig_module::solweig_cal_main().

227  !=======================================================================
228  ! DAYLEN, Real Function, N.B. Pickering, 09/23/1993
229  ! Computes solar day length (Spitters, 1986).
230  !=======================================================================
231  !-----------------------------------------------------------------------
232  IMPLICIT NONE
233  INTEGER :: doy
234  REAL(KIND(1d0)), INTENT(IN) :: xlat
235  REAL(KIND(1d0)), INTENT(OUT) :: dec, dayl, sndn, snup
236  REAL(KIND(1d0)):: soc
237  REAL(KIND(1d0)), PARAMETER :: pi = 3.14159, rad = pi/180.0
238 
239  !-----------------------------------------------------------------------
240  ! Calculation of declination of sun (Eqn. 16). Amplitude= +/-23.45
241  ! deg. Minimum = DOY 355 (DEC 21), maximum = DOY 172.5 (JUN 21/22).
242  dec = -23.45*cos(2.0*pi*(doy + 10.0)/365.0)
243 
244  ! Sun angles. SOC limited for latitudes above polar circles.
245  soc = tan(rad*dec)*tan(rad*xlat)
246  soc = min(max(soc, -1.0), 1.0)
247 
248  ! Calculate daylength, sunrise and sunset (Eqn. 17)
249  dayl = 12.0 + 24.0*asin(soc)/pi
250  snup = 12.0 - dayl/2.0
251  sndn = 12.0 + dayl/2.0
252 
Here is the caller graph for this function:

◆ days_of_year()

elemental integer function days_of_year ( integer, intent(in)  year_int)

Definition at line 157 of file suews_util_time.f95.

157  IMPLICIT NONE
158  INTEGER, INTENT(in) :: year_int
159  INTEGER :: ndays
160 
161  IF (mod(year_int, 100) /= 0 .AND. mod(year_int, 4) == 0) THEN
162  ndays = 366
163  ELSEIF (mod(year_int, 400) == 0) THEN
164  ndays = 366
165  ELSE
166  ndays = 365
167  ENDIF
168 
integer, parameter ndays

◆ dectime_to_timevec()

subroutine dectime_to_timevec ( real(kind(1d0))  dectime,
integer  HOURS,
integer  MINS,
real(kind(1d0))  SECS 
)

Definition at line 203 of file suews_util_time.f95.

Referenced by narp_module::narp_cal_sunposition().

203  !This subroutine converts dectime to individual
204  !hours, minutes and seconds
205  INTEGER :: hours, mins, doy
206  REAL(KIND(1d0)) :: dectime, secs, dh, dm, ds
207  !INTEGER :: year
208 
209  doy = floor(dectime)
210 
211  dh = dectime - doy !Decimal hours
212  hours = int(24*dh)
213 
214  dm = 24*dh - hours !Decimal minutes
215  mins = int(60*dm)
216 
217  ds = 60*dm - mins
218  secs = int(60*ds)
219 
real(kind(1d0)) dectime
Here is the caller graph for this function:

◆ leapyearcalc()

subroutine leapyearcalc ( integer  year_int,
integer  nroDays 
)

Definition at line 139 of file suews_util_time.f95.

Referenced by initialstate(), and suews_program().

139 
140  IMPLICIT NONE
141 
142  INTEGER :: nrodays, year_int
143 
144  IF (mod(year_int, 100) /= 0 .AND. mod(year_int, 4) == 0) THEN
145  nrodays = 366
146  ELSEIF (mod(year_int, 400) == 0) THEN
147  nrodays = 366
148  ELSE
149  nrodays = 365
150  ENDIF
Here is the caller graph for this function:

◆ month2day()

subroutine month2day ( integer  mon,
integer  ne,
integer  k,
integer  b 
)

Definition at line 106 of file suews_util_time.f95.

106  IMPLICIT NONE
107  INTEGER:: mon, ne, k, b
108 
109  IF (mon == 1) THEN
110  ne = 32 - b
111  ELSE IF (mon == 2) THEN
112  ne = 60 + k - b
113  ELSE IF (mon == 3) THEN
114  ne = 91 + k - b
115  ELSE IF (mon == 4) THEN
116  ne = 121 + k - b
117  ELSE IF (mon == 5) THEN
118  ne = 152 + k - b
119  ELSE IF (mon == 6) THEN
120  ne = 182 + k - b
121  ELSE IF (mon == 7) THEN
122  ne = 213 + k - b
123  ELSE IF (mon == 8) THEN
124  ne = 244 + k - b
125  !**********PAGE 151 STARTS HERE**************
126  ELSE IF (mon == 9) THEN
127  ne = 274 + k - b
128  ELSE IF (mon == 10) THEN
129  ne = 305 + k - b
130  ELSE IF (mon == 11) THEN
131  ne = 335 + k - b
132  ELSE IF (mon == 12) THEN
133  ne = 366 + k - b
134  END IF

◆ suews_cal_dectime()

subroutine suews_cal_dectime ( integer, intent(in)  id,
integer, intent(in)  it,
integer, intent(in)  imin,
integer, intent(in)  isec,
real(kind(1d0)), intent(out)  dectime 
)

Definition at line 273 of file suews_util_time.f95.

Referenced by suews_driver::suews_cal_main().

273  IMPLICIT NONE
274  INTEGER, INTENT(in)::id, it, imin, isec
275 
276  REAL(KIND(1D0)), INTENT(out)::dectime ! nsh in type real
277 
278  dectime = REAL(id - 1, KIND(1d0)) &
279  + REAL(it, kind(1d0))/24 &
280  + REAL(imin, kind(1d0))/(60*24) &
281  + REAL(isec, kind(1d0))/(60*60*24)
282 
integer isec
integer id
integer imin
integer it
real(kind(1d0)) dectime
Here is the caller graph for this function:

◆ suews_cal_dls()

subroutine suews_cal_dls ( integer, intent(in)  id,
integer, intent(in)  startDLS,
integer, intent(in)  endDLS,
integer, intent(out)  DLS 
)

Definition at line 329 of file suews_util_time.f95.

Referenced by suews_driver::suews_cal_main().

329  IMPLICIT NONE
330 
331  INTEGER, INTENT(in) :: id, startdls, enddls
332  INTEGER, INTENT(out) :: dls
333 
334  dls = 0
335  IF (id > startdls .AND. id < enddls) dls = 1
336 
integer dls
integer startdls
integer id
Here is the caller graph for this function:

◆ suews_cal_tstep()

subroutine suews_cal_tstep ( integer, intent(in)  tstep,
integer, intent(out)  nsh,
real(kind(1d0)), intent(out)  nsh_real,
real(kind(1d0)), intent(out)  tstep_real 
)

Definition at line 289 of file suews_util_time.f95.

Referenced by suews_driver::suews_cal_main().

289  IMPLICIT NONE
290  INTEGER, INTENT(in)::tstep ! number of timesteps per hour
291  ! values that are derived from tstep
292  INTEGER, INTENT(out)::nsh ! number of timesteps per hour
293  REAL(KIND(1D0)), INTENT(out)::nsh_real ! nsh in type real
294  REAL(KIND(1D0)), INTENT(out)::tstep_real ! tstep in type real
295  nsh = 3600/tstep
296  nsh_real = nsh*1.0
297  tstep_real = tstep*1.0
298 
real(kind(1d0)) tstep_real
real(kind(1d0)) nsh_real
Here is the caller graph for this function:

◆ suews_cal_weekday()

subroutine suews_cal_weekday ( integer, intent(in)  iy,
integer, intent(in)  id,
real(kind(1d0)), intent(in)  lat,
integer, dimension(3), intent(out)  dayofWeek_id 
)

Definition at line 304 of file suews_util_time.f95.

References day2month(), and day_of_week().

Referenced by initialstate(), and suews_driver::suews_cal_main().

304  IMPLICIT NONE
305 
306  INTEGER, INTENT(in) :: iy ! year
307  INTEGER, INTENT(in) :: id ! day of year
308  REAL(KIND(1d0)), INTENT(in):: lat
309 
310  INTEGER, DIMENSION(3), INTENT(OUT) ::dayofweek_id
311 
312  INTEGER::wd
313  INTEGER::mb
314  INTEGER::date
315  INTEGER::seas
316 
317  CALL day2month(id, mb, date, seas, iy, lat) !Calculate real date from doy
318  CALL day_of_week(date, mb, iy, wd) !Calculate weekday (1=Sun, ..., 7=Sat)
319 
320  dayofweek_id(1) = wd !Day of week
321  dayofweek_id(2) = mb !Month
322  dayofweek_id(3) = seas !Season
323 
subroutine day2month(b, mb, md, seas, year, latitude)
integer id
real(kind(1d0)) lat
integer iy
subroutine day_of_week(DATE, MONTH, YEAR, DOW)
Here is the call graph for this function:
Here is the caller graph for this function: