SCALE-RM
Functions/Subroutines | Variables
scale_calendar Module Reference

module CALENDAR More...

Functions/Subroutines

subroutine, public calendar_setup
 Setup. More...
 
subroutine, public calendar_getdayofyear (DayOfYear, iyear)
 Get day of year. More...
 
subroutine, public calendar_date2daysec (absday, abssec, ymdhms, subsec, offset_year)
 Convert from gregorian date to absolute day/second. More...
 
subroutine, public calendar_daysec2date (ymdhms, subsec, absday, abssec, offset_year)
 Convert from gregorian date to absolute day/second. More...
 
subroutine, public calendar_ymd2absday (absday, gyear, gmonth, gday, oyear)
 Convert from gregorian date to absolute day, DAY 0 is AD1/1/1. More...
 
subroutine, public calendar_hms2abssec (abssec, hour, minute, second, subsec)
 Hour, minute, second, subsecond -> absolute second. More...
 
subroutine, public calendar_adjust_daysec (absday, abssec)
 Adjust day and second. More...
 
real(dp) function, public calendar_combine_daysec (absday, abssec)
 Combine day and second. More...
 
subroutine, public calendar_unit2sec (second, value, unit)
 Convert several units to second. More...
 
real(dp) function, public calendar_cfunits2sec (cftime, cfunits, offset_year, startdaysec)
 Convert time in units of the CF convention to second. More...
 
subroutine, public calendar_date2char (chardate, ymdhms, subsec)
 Convert from gregorian date to absolute day/second. More...
 

Variables

integer, parameter, public i_year = 1
 [index] year More...
 
integer, parameter, public i_month = 2
 [index] month More...
 
integer, parameter, public i_day = 3
 [index] day More...
 
integer, parameter, public i_hour = 4
 [index] hour More...
 
integer, parameter, public i_min = 5
 [index] minute More...
 
integer, parameter, public i_sec = 6
 [index] second More...
 

Detailed Description

module CALENDAR

Description
gregorian calendar module this module is available in gregorian calendar date
Author
Team SCALE
History
  • 2013-01-29 (H.Yashiro) [new]

Function/Subroutine Documentation

◆ calendar_setup()

subroutine, public scale_calendar::calendar_setup ( )

Setup.

Definition at line 82 of file scale_calendar.F90.

References scale_stdio::io_fid_log, and scale_stdio::io_l.

Referenced by mod_rm_driver::scalerm(), and mod_rm_prep::scalerm_prep().

82  implicit none
83  !---------------------------------------------------------------------------
84 
85  if( io_l ) write(io_fid_log,*)
86  if( io_l ) write(io_fid_log,*) '++++++ Module[CALENDAR] / Categ[COMMON] / Origin[SCALElib]'
87  if( io_l ) write(io_fid_log,*) '*** No namelists.'
88 
89  return
Here is the caller graph for this function:

◆ calendar_getdayofyear()

subroutine, public scale_calendar::calendar_getdayofyear ( real(dp), intent(out)  DayOfYear,
integer, intent(in)  iyear 
)

Get day of year.

Definition at line 97 of file scale_calendar.F90.

Referenced by scale_atmos_solarins::atmos_solarins_insolation_0d(), and scale_atmos_solarins::atmos_solarins_insolation_2d().

97  implicit none
98 
99  real(DP), intent(out) :: dayofyear ! # of day of year
100  integer, intent(in) :: iyear ! current year
101  !---------------------------------------------------------------------------
102 
103  dayofyear = calendar_doi
104  if( checkleap(iyear) ) dayofyear = calendar_doi + 1.0_dp
105 
106  return
Here is the caller graph for this function:

◆ calendar_date2daysec()

subroutine, public scale_calendar::calendar_date2daysec ( integer, intent(out)  absday,
real(dp), intent(out)  abssec,
integer, dimension(6), intent(in)  ymdhms,
real(dp), intent(in)  subsec,
integer, intent(in)  offset_year 
)

Convert from gregorian date to absolute day/second.

Parameters
[out]absdayabsolute day
[out]abssecabsolute second
[in]ymdhmsdate
[in]subsecsubsecond
[in]offset_yearoffset year

Definition at line 117 of file scale_calendar.F90.

References calendar_hms2abssec(), calendar_ymd2absday(), i_day, i_hour, i_min, i_month, i_sec, and i_year.

Referenced by mod_admin_time::admin_time_setup(), scale_atmos_boundary::atmos_boundary_resume(), scale_atmos_boundary::atmos_boundary_resume_file(), scale_atmos_phy_rd_profile::atmos_phy_rd_profile_read(), scale_atmos_phy_rd_profile::atmos_phy_rd_profile_setup(), calendar_cfunits2sec(), scale_external_input::extin_setup(), and scale_external_input::extin_update_3d().

117  implicit none
118 
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
124  !---------------------------------------------------------------------------
125 
126  call calendar_ymd2absday( absday, & ! [OUT]
127  ymdhms(i_year), & ! [IN]
128  ymdhms(i_month), & ! [IN]
129  ymdhms(i_day), & ! [IN]
130  offset_year ) ! [IN]
131 
132  call calendar_hms2abssec( abssec, & ! [OUT]
133  ymdhms(i_hour), & ! [IN]
134  ymdhms(i_min), & ! [IN]
135  ymdhms(i_sec), & ! [IN]
136  subsec ) ! [IN]
137 
138  return
integer, parameter, public i_month
[index] month
integer, parameter, public i_year
[index] year
subroutine, public calendar_ymd2absday(absday, gyear, gmonth, gday, oyear)
Convert from gregorian date to absolute day, DAY 0 is AD1/1/1.
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_hms2abssec(abssec, hour, minute, second, subsec)
Hour, minute, second, subsecond -> absolute second.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calendar_daysec2date()

subroutine, public scale_calendar::calendar_daysec2date ( integer, dimension(6), intent(out)  ymdhms,
real(dp), intent(out)  subsec,
integer, intent(in)  absday,
real(dp), intent(in)  abssec,
integer, intent(in)  offset_year 
)

Convert from gregorian date to absolute day/second.

Parameters
[out]ymdhmsdate
[out]subsecsubsecond
[in]absdayabsolute day
[in]abssecabsolute second
[in]offset_yearoffset year

Definition at line 149 of file scale_calendar.F90.

References i_day, i_hour, i_min, i_month, i_sec, and i_year.

Referenced by mod_admin_time::admin_time_advance(), mod_admin_time::admin_time_setup(), scale_external_input::extin_setup(), and scale_external_input::extin_update_3d().

149  implicit none
150 
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
156  !---------------------------------------------------------------------------
157 
158  call calendar_absday2ymd( ymdhms(i_year), & ! [OUT]
159  ymdhms(i_month), & ! [OUT]
160  ymdhms(i_day), & ! [OUT]
161  absday, & ! [IN]
162  offset_year ) ! [IN]
163 
164  call calendar_abssec2hms( ymdhms(i_hour), & ! [OUT]
165  ymdhms(i_min), & ! [OUT]
166  ymdhms(i_sec), & ! [OUT]
167  subsec, & ! [OUT]
168  abssec ) ! [IN]
169 
170  return
integer, parameter, public i_month
[index] month
integer, parameter, public i_year
[index] year
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
Here is the caller graph for this function:

◆ calendar_ymd2absday()

subroutine, public scale_calendar::calendar_ymd2absday ( integer, intent(out)  absday,
integer, intent(in)  gyear,
integer, intent(in)  gmonth,
integer, intent(in)  gday,
integer, intent(in)  oyear 
)

Convert from gregorian date to absolute day, DAY 0 is AD1/1/1.

Parameters
[out]absdayabsolute day
[in]gyearyear
[in]gmonthmonth
[in]gdayday
[in]oyearoffset year

Definition at line 181 of file scale_calendar.F90.

Referenced by scale_atmos_solarins::atmos_solarins_insolation_0d(), scale_atmos_solarins::atmos_solarins_insolation_2d(), calendar_date2char(), and calendar_date2daysec().

181  implicit none
182 
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
188 
189  integer :: gyear_mod, gmonth_mod
190  integer :: yearday, monthday
191  integer :: m, ileap
192  !---------------------------------------------------------------------------
193 
194  gmonth_mod = mod( gmonth-1, 12 ) + 1
195  gyear_mod = gyear + ( gmonth-gmonth_mod ) / 12
196 
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 )
204 
205  ileap = i_nonleapyear
206  if( checkleap(gyear_mod) ) ileap = i_leapyear
207 
208  monthday = 0
209  do m = 1, gmonth_mod-1
210  monthday = monthday + dayofmonth(m,ileap)
211  enddo
212 
213  absday = yearday + monthday + gday - 1
214 
215  return
Here is the caller graph for this function:

◆ calendar_hms2abssec()

subroutine, public scale_calendar::calendar_hms2abssec ( real(dp), intent(out)  abssec,
integer, intent(in)  hour,
integer, intent(in)  minute,
integer, intent(in)  second,
real(dp), intent(in)  subsec 
)

Hour, minute, second, subsecond -> absolute second.

Parameters
[out]abssecabsolute second
[in]subsecsubsecond

Definition at line 269 of file scale_calendar.F90.

Referenced by scale_atmos_solarins::atmos_solarins_insolation_0d(), scale_atmos_solarins::atmos_solarins_insolation_2d(), and calendar_date2daysec().

269  implicit none
270 
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
276  !---------------------------------------------------------------------------
277 
278  abssec = real(hour, kind=DP) * calendar_min * calendar_sec &
279  + real(minute,kind=DP) * calendar_sec &
280  + real(second,kind=DP) &
281  + subsec
282 
283  return
Here is the caller graph for this function:

◆ calendar_adjust_daysec()

subroutine, public scale_calendar::calendar_adjust_daysec ( integer, intent(inout)  absday,
real(dp), intent(inout)  abssec 
)

Adjust day and second.

Parameters
[in,out]absdayabsolute day
[in,out]abssecabsolute second

Definition at line 327 of file scale_calendar.F90.

Referenced by mod_admin_time::admin_time_advance(), mod_admin_time::admin_time_setup(), scale_external_input::extin_setup(), and scale_external_input::extin_update_3d().

327  implicit none
328 
329  integer, intent(inout) :: absday
330  real(DP), intent(inout) :: abssec
331 
332  integer :: addday
333  !---------------------------------------------------------------------------
334 
335  addday = int( abssec / ( calendar_hour * calendar_min * calendar_sec ) )
336 
337  absday = absday + addday
338 
339  abssec = abssec - real(addday,kind=DP) * calendar_hour * calendar_min * calendar_sec
340 
341  return
Here is the caller graph for this function:

◆ calendar_combine_daysec()

real(dp) function, public scale_calendar::calendar_combine_daysec ( integer, intent(in)  absday,
real(dp), intent(in)  abssec 
)

Combine day and second.

Parameters
[in]absdayabsolute day
[in]abssecabsolute second
Returns
absolute day.second

Definition at line 347 of file scale_calendar.F90.

Referenced by mod_admin_time::admin_time_advance(), mod_admin_time::admin_time_setup(), scale_atmos_boundary::atmos_boundary_resume(), scale_atmos_boundary::atmos_boundary_resume_file(), calendar_cfunits2sec(), scale_external_input::extin_setup(), and scale_external_input::extin_update_3d().

347  implicit none
348 
349  integer, intent(in) :: absday
350  real(DP), intent(in) :: abssec
351  real(DP) :: daysec
352  !---------------------------------------------------------------------------
353 
354  daysec = real(absday,kind=DP) * calendar_sec * calendar_min * calendar_hour &
355  + abssec
356 
357  return
Here is the caller graph for this function:

◆ calendar_unit2sec()

subroutine, public scale_calendar::calendar_unit2sec ( real(dp), intent(out)  second,
real(dp), intent(in)  value,
character(len=*), intent(in)  unit 
)

Convert several units to second.

Parameters
[in]unitvariable unit

Definition at line 366 of file scale_calendar.F90.

References scale_process::prc_mpistop().

Referenced by mod_admin_time::admin_time_setup(), and calendar_cfunits2sec().

366  use scale_process, only: &
368  implicit none
369 
370  real(DP), intent(out) :: second
371  real(DP), intent(in) :: value
372  character(len=*), intent(in) :: unit
373  !---------------------------------------------------------------------------
374 
375  select case(unit)
376  case('MSEC')
377  second = value * 1.e-3_dp
378  case('SEC', 'seconds')
379  second = value
380  case('MIN')
381  second = value * calendar_sec
382  case('HOUR')
383  second = value * calendar_sec * calendar_min
384  case('DAY')
385  second = value * calendar_sec * calendar_min * calendar_hour
386  case default
387  write(*,*) ' xxx Unsupported UNIT: ', trim(unit), ', ', value
388  call prc_mpistop
389  endselect
390 
391  return
subroutine, public prc_mpistop
Abort MPI.
module PROCESS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calendar_cfunits2sec()

real(dp) function, public scale_calendar::calendar_cfunits2sec ( real(dp), intent(in)  cftime,
character(len=*), intent(in)  cfunits,
integer, intent(in)  offset_year,
real(dp), intent(in), optional  startdaysec 
)

Convert time in units of the CF convention to second.

Definition at line 397 of file scale_calendar.F90.

References calendar_combine_daysec(), calendar_date2daysec(), calendar_unit2sec(), and scale_process::prc_mpistop().

Referenced by mod_admin_time::admin_time_setup(), and scale_external_input::extin_setup().

397  use scale_process, only: &
399  implicit none
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
404  real(DP) :: sec
405 
406  character(len=H_MID) :: tunit
407  character(len=H_MID) :: buf
408 
409  integer :: date(6)
410  integer :: day
411  real(DP) :: sec0
412 
413  integer :: l
414 
415  intrinsic index
416 
417  l = index(cfunits, " since ")
418  if ( l > 1 ) then ! untis is under the CF convension
419  tunit = cfunits(1:l-1)
420  buf = cfunits(l+7:)
421 
422  l = index(buf, "-")
423  if ( l /= 5 ) then
424  write(*,*) 'xxx units for time is invalid (year): ', trim(cfunits), ' ', trim(buf)
425  call prc_mpistop
426  end if
427  read( buf(1:4), *) date(1) ! year
428  buf = buf(6:)
429 
430  l = index(buf, "-")
431  if ( l /= 3 ) then
432  write(*,*) 'xxx units for time is invalid (month): ', trim(cfunits), ' ', trim(buf)
433  call prc_mpistop
434  end if
435  read( buf(1:2), *) date(2) ! month
436  buf = buf(4:)
437 
438  l = index(buf, " ")
439  if ( l /= 3 ) then
440  write(*,*) 'xxx units for time is invalid (day): ', trim(cfunits), ' ', trim(buf)
441  call prc_mpistop
442  end if
443  read( buf(1:2), *) date(3) ! day
444  buf = buf(4:)
445 
446  l = index(buf, ":")
447  if ( l /= 3 ) then
448  write(*,*) 'xxx units for time is invalid (hour): ', trim(cfunits), ' ', trim(buf)
449  call prc_mpistop
450  end if
451  read( buf(1:2), *) date(4) ! hour
452  buf = buf(4:)
453 
454  l = index(buf, ":")
455  if ( l /= 3 ) then
456  write(*,*) 'xxx units for time is invalid (min): ', trim(cfunits), ' ', trim(buf)
457  call prc_mpistop
458  end if
459  read( buf(1:2), *) date(5) ! min
460  buf = buf(4:)
461 
462  if ( len_trim(buf) /= 2 ) then
463  write(*,*) 'xxx units for time is invalid (sec): ', trim(cfunits), ' ', trim(buf), len_trim(buf)
464  call prc_mpistop
465  end if
466  read( buf(1:2), *) date(6) ! sec
467 
468  call calendar_date2daysec( day, & ! (out)
469  sec0, & ! (out)
470  date(:), & ! (in)
471  0.0_dp, & ! (in)
472  offset_year ) ! (in)
473 
474  sec0 = calendar_combine_daysec( day, sec0 )
475  else
476  tunit = cfunits
477  if ( present(startdaysec) ) then
478  sec0 = startdaysec
479  else
480  sec0 = 0.0_dp
481  end if
482  end if
483 
484  call calendar_unit2sec(sec, cftime, tunit)
485 
486  sec = sec0 + sec
487 
488  return
subroutine, public prc_mpistop
Abort MPI.
module PROCESS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calendar_date2char()

subroutine, public scale_calendar::calendar_date2char ( character(len=27), intent(out)  chardate,
integer, dimension(6), intent(in)  ymdhms,
real(dp), intent(in)  subsec 
)

Convert from gregorian date to absolute day/second.

Parameters
[out]chardateformatted date character
[in]ymdhmsdate
[in]subsecsubsecond

Definition at line 497 of file scale_calendar.F90.

References calendar_ymd2absday(), i_day, i_month, and i_year.

Referenced by mod_admin_time::admin_time_checkstate(), mod_admin_time::admin_time_setup(), and scale_atmos_boundary::atmos_boundary_resume().

497  implicit none
498 
499  character(len=27), intent(out) :: chardate
500  integer, intent(in) :: ymdhms(6)
501  real(DP), intent(in) :: subsec
502  !---------------------------------------------------------------------------
503 
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),' +', &
507  subsec
508 
509  return
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ i_year

integer, parameter, public scale_calendar::i_year = 1

◆ i_month

integer, parameter, public scale_calendar::i_month = 2

◆ i_day

integer, parameter, public scale_calendar::i_day = 3

◆ i_hour

integer, parameter, public scale_calendar::i_hour = 4

[index] hour

Definition at line 48 of file scale_calendar.F90.

Referenced by scale_atmos_solarins::atmos_solarins_insolation_0d(), scale_atmos_solarins::atmos_solarins_insolation_2d(), calendar_date2daysec(), and calendar_daysec2date().

48  integer, public, parameter :: i_hour = 4
integer, parameter, public i_hour
[index] hour

◆ i_min

integer, parameter, public scale_calendar::i_min = 5

[index] minute

Definition at line 49 of file scale_calendar.F90.

Referenced by scale_atmos_solarins::atmos_solarins_insolation_0d(), scale_atmos_solarins::atmos_solarins_insolation_2d(), calendar_date2daysec(), and calendar_daysec2date().

49  integer, public, parameter :: i_min = 5
integer, parameter, public i_min
[index] minute

◆ i_sec

integer, parameter, public scale_calendar::i_sec = 6

[index] second

Definition at line 50 of file scale_calendar.F90.

Referenced by scale_atmos_solarins::atmos_solarins_insolation_0d(), scale_atmos_solarins::atmos_solarins_insolation_2d(), calendar_date2daysec(), and calendar_daysec2date().

50  integer, public, parameter :: i_sec = 6
integer, parameter, public i_sec
[index] second