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_regist(), 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_regist(), 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_regist(), 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_regist(), 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_regist().

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

512  implicit none
513 
514  character(len=27), intent(out) :: chardate
515  integer, intent(in) :: ymdhms(6)
516  real(DP), intent(in) :: subsec
517  !---------------------------------------------------------------------------
518 
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),' +', &
522  subsec
523 
524  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

◆ 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

◆ 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