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 401 real(DP),
intent(in) :: cftime
402 character(len=*),
intent(in) :: cfunits
403 integer,
intent(in) :: offset_year
404 real(DP),
intent(in),
optional :: startdaysec
407 character(len=H_MID) :: tunit
408 character(len=H_MID) :: buf
419 l = index( cfunits,
" since " )
421 tunit = cfunits(1:l-1)
426 write(*,*)
'xxx units for time is invalid (year)' 427 write(*,*)
'xxx ', trim(cfunits)
428 write(*,*)
'xxx ', trim(buf)
431 read(buf(1:4),*) date(1)
436 write(*,*)
'xxx units for time is invalid (month)' 437 write(*,*)
'xxx ', trim(cfunits)
438 write(*,*)
'xxx ', trim(buf)
441 read(buf(1:2),*) date(2)
446 write(*,*)
'xxx units for time is invalid (day)' 447 write(*,*)
'xxx ', trim(cfunits)
448 write(*,*)
'xxx ', trim(buf)
451 read(buf(1:2),*) date(3)
456 write(*,*)
'xxx units for time is invalid (hour)' 457 write(*,*)
'xxx ', trim(cfunits)
458 write(*,*)
'xxx ', trim(buf)
461 read(buf(1:2),*) date(4)
466 write(*,*)
'xxx units for time is invalid (min)' 467 write(*,*)
'xxx ', trim(cfunits)
468 write(*,*)
'xxx ', trim(buf)
471 read(buf(1:2),*) date(5)
474 if ( len_trim(buf) /= 2 )
then 475 write(*,*)
'xxx units for time is invalid (sec)' 476 write(*,*)
'xxx ', trim(cfunits)
477 write(*,*)
'xxx ', trim(buf)
478 write(*,*)
'xxx ', len_trim(buf)
481 read(buf(1:2),*) date(6)
492 if (
present(startdaysec) )
then 514 character(len=27),
intent(out) :: chardate
515 integer,
intent(in) :: ymdhms(6)
516 real(DP),
intent(in) :: subsec
519 write(chardate,
'(I4.4,A1,I2.2,A1,I2.2,A1,I2.2,A1,I2.2,A1,I2.2,A2,F6.3)') &
520 ymdhms(1),
'/',ymdhms(2),
'/',ymdhms(3),
' ', &
521 ymdhms(4),
':',ymdhms(5),
':',ymdhms(6),
' +', &
530 function checkleap( iyear )
533 integer,
intent(in) :: iyear
536 integer :: check4, check100, check400
539 check4 = mod(iyear,4 )
540 check100 = mod(iyear,100)
541 check400 = mod(iyear,400)
544 if( check4 == 0 ) checkleap = .true.
545 if( check100 == 0 ) checkleap = .false.
546 if( check400 == 0 ) checkleap = .true.
548 end function checkleap
552 subroutine calendar_ymdhms2nd( &
558 real(DP),
intent(out) :: nd
559 integer,
intent(in) :: ymdhms(6)
560 integer,
intent(in) :: oyear
562 integer :: absday, absday_jan1
577 nd = absday - absday_jan1 + 1.0_dp
580 end subroutine calendar_ymdhms2nd
584 subroutine calendar_ymdhms2mjd( &
590 real(DP),
intent(out) :: mjd
591 integer,
intent(in) :: ymdhms(6)
592 integer,
intent(in) :: oyear
594 integer :: y, m, mjd_day
598 .OR. ymdhms(
i_month) == 2 )
then 606 mjd_day = int( 365.25_dp * y ) &
607 + int( y/400.0_dp ) - int( y/100.0_dp ) &
608 + int( 30.59_dp * m-2 ) &
612 mjd =
real(mjd_day,kind=DP) &
613 + ymdhms(
i_hour) / 24.0_dp &
614 + ymdhms(
i_min) / 1440.0_dp &
615 + ymdhms(
i_sec) / 86400.0_dp
618 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 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.
integer, parameter, public dp
subroutine, public calendar_date2daysec(absday, abssec, ymdhms, subsec, offset_year)
Convert from gregorian date to absolute day/second.