45 integer,
public,
parameter ::
i_year = 1
47 integer,
public,
parameter ::
i_day = 3
48 integer,
public,
parameter ::
i_hour = 4
49 integer,
public,
parameter ::
i_min = 5
50 integer,
public,
parameter ::
i_sec = 6
56 private :: calendar_absday2ymd
57 private :: calendar_abssec2hms
58 private :: calendar_ymdhms2nd
59 private :: calendar_ymdhms2mjd
66 real(DP),
private :: calendar_doi = 365.0_dp
67 real(DP),
private :: calendar_hour = 24.0_dp
68 real(DP),
private :: calendar_min = 60.0_dp
69 real(DP),
private :: calendar_sec = 60.0_dp
71 integer,
private,
parameter :: i_nonleapyear = 1
72 integer,
private,
parameter :: i_leapyear = 2
73 integer,
private :: dayofmonth(12,2)
74 data dayofmonth / 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, &
75 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /
86 if(
io_l )
write(
io_fid_log,*)
'++++++ Module[CALENDAR] / Categ[COMMON] / Origin[SCALElib]' 99 real(DP),
intent(out) :: DayOfYear
100 integer,
intent(in) :: iyear
103 dayofyear = calendar_doi
104 if( checkleap(iyear) ) dayofyear = calendar_doi + 1.0_dp
119 integer,
intent(out) :: absday
120 real(DP),
intent(out) :: abssec
121 integer,
intent(in) :: ymdhms(6)
122 real(DP),
intent(in) :: subsec
123 integer,
intent(in) :: offset_year
151 integer,
intent(out) :: ymdhms(6)
152 real(DP),
intent(out) :: subsec
153 integer,
intent(in) :: absday
154 real(DP),
intent(in) :: abssec
155 integer,
intent(in) :: offset_year
158 call calendar_absday2ymd( ymdhms(
i_year), &
164 call calendar_abssec2hms( ymdhms(
i_hour), &
183 integer,
intent(out) :: absday
184 integer,
intent(in) :: gyear
185 integer,
intent(in) :: gmonth
186 integer,
intent(in) :: gday
187 integer,
intent(in) :: oyear
189 integer :: gyear_mod, gmonth_mod
190 integer :: yearday, monthday
194 gmonth_mod = mod( gmonth-1, 12 ) + 1
195 gyear_mod = gyear + ( gmonth-gmonth_mod ) / 12
197 yearday = int( calendar_doi * ( gyear_mod - oyear ) ) &
198 + int(
real(gyear_mod-1,kind=DP) / 4.0_DP ) &
199 - int(
real(gyear_mod-1,kind=DP) / 100.0_dp ) &
200 + int(
real(gyear_mod-1,kind=DP) / 400.0_dp ) &
201 - int(
real(oyear -1,kind=DP) / 4.0_dp ) &
202 + int(
real(oyear -1,kind=DP) / 100.0_dp ) &
203 - int(
real(oyear -1,kind=DP) / 400.0_dp )
205 ileap = i_nonleapyear
206 if( checkleap(gyear_mod) ) ileap = i_leapyear
209 do m = 1, gmonth_mod-1
210 monthday = monthday + dayofmonth(m,ileap)
213 absday = yearday + monthday + gday - 1
220 subroutine calendar_absday2ymd( &
228 integer,
intent(out) :: gyear
229 integer,
intent(out) :: gmonth
230 integer,
intent(out) :: gday
231 integer,
intent(in) :: absday
232 integer,
intent(in) :: oyear
238 gyear = int(
real(absday,kind=DP) / 366.0_DP ) + oyear
241 if( absday < checkday )
exit 245 ileap = i_nonleapyear
246 if( checkleap(gyear) ) ileap = i_leapyear
251 if( absday <= checkday )
exit 256 gday = absday - checkday + 1
259 end subroutine calendar_absday2ymd
271 real(DP),
intent(out) :: abssec
272 integer,
intent(in) :: hour
273 integer,
intent(in) :: minute
274 integer,
intent(in) :: second
275 real(DP),
intent(in) :: subsec
278 abssec =
real(hour, kind=DP) * CALENDAR_MIN * CALENDAR_SEC &
279 +
real(minute,kind=DP) * CALENDAR_SEC &
280 +
real(second,kind=DP) &
288 subroutine calendar_abssec2hms( &
296 integer,
intent(out) :: hour
297 integer,
intent(out) :: minute
298 integer,
intent(out) :: second
299 real(DP),
intent(out) :: subsec
300 real(DP),
intent(in) :: abssec
302 real(DP) :: nsec, nmin, nhour, temp
305 nsec =
real(int(abssec),kind=
dp)
306 subsec = abssec - nsec
308 temp = mod( nsec, calendar_sec )
310 nmin = ( nsec-temp ) / calendar_sec
312 temp = mod( nmin, calendar_min )
314 nhour = ( nmin-temp ) / calendar_min
316 temp = mod( nhour, calendar_hour )
320 end subroutine calendar_abssec2hms
329 integer,
intent(inout) :: absday
330 real(DP),
intent(inout) :: abssec
335 addday = int( abssec / ( calendar_hour * calendar_min * calendar_sec ) )
337 absday = absday + addday
339 abssec = abssec -
real(addday,kind=DP) * CALENDAR_HOUR * CALENDAR_MIN * CALENDAR_SEC
349 integer,
intent(in) :: absday
350 real(DP),
intent(in) :: abssec
354 daysec =
real(absday,kind=DP) * CALENDAR_SEC * CALENDAR_MIN * CALENDAR_HOUR &
370 real(DP),
intent(out) :: second
371 real(DP),
intent(in) ::
value 372 character(len=*),
intent(in) :: unit
377 second =
value * 1.e-3_dp
378 case(
'SEC',
'seconds')
381 second =
value * calendar_sec
383 second =
value * calendar_sec * calendar_min
385 second =
value * calendar_sec * calendar_min * calendar_hour
387 write(*,*)
' xxx Unsupported UNIT: ', trim(unit),
', ',
value 400 real(DP),
intent(in) :: cftime
401 character(len=*),
intent(in) :: cfunits
402 integer,
intent(in) :: offset_year
403 real(DP),
intent(in),
optional :: startdaysec
406 character(len=H_MID) :: tunit
407 character(len=H_MID) :: buf
417 l = index(cfunits,
" since ")
419 tunit = cfunits(1:l-1)
424 write(*,*)
'xxx units for time is invalid (year): ', trim(cfunits),
' ', trim(buf)
427 read( buf(1:4), *) date(1)
432 write(*,*)
'xxx units for time is invalid (month): ', trim(cfunits),
' ', trim(buf)
435 read( buf(1:2), *) date(2)
440 write(*,*)
'xxx units for time is invalid (day): ', trim(cfunits),
' ', trim(buf)
443 read( buf(1:2), *) date(3)
448 write(*,*)
'xxx units for time is invalid (hour): ', trim(cfunits),
' ', trim(buf)
451 read( buf(1:2), *) date(4)
456 write(*,*)
'xxx units for time is invalid (min): ', trim(cfunits),
' ', trim(buf)
459 read( buf(1:2), *) date(5)
462 if ( len_trim(buf) /= 2 )
then 463 write(*,*)
'xxx units for time is invalid (sec): ', trim(cfunits),
' ', trim(buf), len_trim(buf)
466 read( buf(1:2), *) date(6)
477 if (
present(startdaysec) )
then 499 character(len=27),
intent(out) :: chardate
500 integer,
intent(in) :: ymdhms(6)
501 real(DP),
intent(in) :: subsec
504 write(chardate,
'(I4.4,A1,I2.2,A1,I2.2,A1,I2.2,A1,I2.2,A1,I2.2,A2,F6.3)') &
505 ymdhms(1),
'/',ymdhms(2),
'/',ymdhms(3),
' ', &
506 ymdhms(4),
':',ymdhms(5),
':',ymdhms(6),
' +', &
515 function checkleap( iyear )
518 integer,
intent(in) :: iyear
521 integer :: check4, check100, check400
524 check4 = mod(iyear,4 )
525 check100 = mod(iyear,100)
526 check400 = mod(iyear,400)
529 if( check4 == 0 ) checkleap = .true.
530 if( check100 == 0 ) checkleap = .false.
531 if( check400 == 0 ) checkleap = .true.
533 end function checkleap
537 subroutine calendar_ymdhms2nd( &
543 real(DP),
intent(out) :: nd
544 integer,
intent(in) :: ymdhms(6)
545 integer,
intent(in) :: oyear
547 integer :: absday, absday_jan1
562 nd = absday - absday_jan1 + 1.0_dp
565 end subroutine calendar_ymdhms2nd
569 subroutine calendar_ymdhms2mjd( &
575 real(DP),
intent(out) :: mjd
576 integer,
intent(in) :: ymdhms(6)
577 integer,
intent(in) :: oyear
579 integer :: y, m, mjd_day
583 .OR. ymdhms(
i_month) == 2 )
then 591 mjd_day = int( 365.25_dp * y ) &
592 + int( y/400.0_dp ) - int( y/100.0_dp ) &
593 + int( 30.59_dp * m-2 ) &
597 mjd =
real(mjd_day,kind=DP) &
598 + ymdhms(
i_hour) / 24.0_DP &
599 + ymdhms(
i_min) / 1440.0_DP &
600 + ymdhms(
i_sec) / 86400.0_DP
603 end subroutine calendar_ymdhms2mjd
integer, parameter, public i_month
[index] month
subroutine, public calendar_unit2sec(second, value, unit)
Convert several units to second.
integer, parameter, public i_year
[index] year
subroutine, public prc_mpistop
Abort MPI.
real(dp) function, public calendar_combine_daysec(absday, abssec)
Combine day and second.
subroutine, public calendar_ymd2absday(absday, gyear, gmonth, gday, oyear)
Convert from gregorian date to absolute day, DAY 0 is AD1/1/1.
subroutine, public calendar_date2char(chardate, ymdhms, subsec)
Convert from gregorian date to absolute day/second.
logical, public io_l
output log or not? (this process)
subroutine, public calendar_adjust_daysec(absday, abssec)
Adjust day and second.
subroutine, public calendar_setup
Setup.
real(dp) function, public calendar_cfunits2sec(cftime, cfunits, offset_year, startdaysec)
Convert time in units of the CF convention to second.
integer, parameter, public i_min
[index] minute
integer, parameter, public dp
integer, parameter, public i_sec
[index] second
integer, parameter, public i_hour
[index] hour
integer, parameter, public i_day
[index] day
subroutine, public calendar_daysec2date(ymdhms, subsec, absday, abssec, offset_year)
Convert from gregorian date to absolute day/second.
subroutine, public calendar_getdayofyear(DayOfYear, iyear)
Get day of year.
subroutine, public calendar_hms2abssec(abssec, hour, minute, second, subsec)
Hour, minute, second, subsecond -> absolute second.
integer, public io_fid_log
Log file ID.
subroutine, public calendar_date2daysec(absday, abssec, ymdhms, subsec, offset_year)
Convert from gregorian date to absolute day/second.