gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dc_date_generic Module Reference

Interface declarations for procedures provided from dc_date. More...

Data Types

interface  dcdatetimecreate
interface  dcdifftimecreate
interface  dcdatetimeputline
interface  dcdifftimeputline
interface  setcaltype
interface  setsecofday
interface  validcaltype
interface  validzone
interface  zonetodiff
interface  parsetimeunits
interface  setzone
interface  eval
interface  evalday
interface  evalhour
interface  evalmin
interface  evalsec
interface  evalnondim
interface  evalsclsec
interface  evalbyunit
interface  tochar
interface  tocharcal
interface  operator(+)
interface  operator(-)
interface  operator(*)
interface  operator(/)
interface  mod
interface  operator(==)
interface  operator(>)
interface  operator(<)
interface  operator(>=)
interface  operator(<=)
interface  max
interface  min
interface  create
interface  putline

Detailed Description

Interface declarations for procedures provided from dc_date.

Author
Yasuhiro MORIKAWA, Eizi TOYODA

This module provides interface declarations for procedures in dc_date. See dc_date for module overview.

Procedures List

The following procedures operate on DC_DATETIME or DC_DIFFTIME derived types (which store date/time information).

Procedure Description
DCDateTimeCreate Initialize DC_DATETIME type variable
DCDiffTimeCreate Initialize DC_DIFFTIME type variable
assignment(=) Initialize DC_DATETIME/DC_DIFFTIME variables
Eval Get individual date/time components
toChar Convert date/time to character string
EvalDay Get as number of days (real type)
EvalHour Get as number of hours (real type)
EvalMin Get as number of minutes (real type)
EvalSec Get as number of seconds (real type)
EvalNondim Get as nondimensional time (real type)
EvalByUnit Get in specified unit (day/hour/min/sec)
operator(+) Addition (DC_DATETIME and DC_DIFFTIME types)
operator(-) Subtraction (DC_DATETIME and DC_DIFFTIME types)
operator(*) Multiplication (DC_DIFFTIME and numeric types)
operator(/) Division (DC_DIFFTIME and numeric types)
mod Remainder (between DC_DIFFTIME types)
operator(==) Comparison (between DC_DATETIME types)
operator(>) Comparison (between DC_DATETIME types)
operator(>=) Comparison (between DC_DATETIME types)
operator(<) Comparison (between DC_DATETIME types)
operator(<=) Comparison (between DC_DATETIME types)
max Return larger value
min Return smaller value
SetZone Change timezone
DCDateTimePutLine Print DC_DATETIME variable information
DCDiffTimePutLine Print DC_DIFFTIME variable information

The following procedures modify internal variables in dc_date_types:

Procedure Description
SetCaltype Change default calendar type
SetSecOfDay Change default seconds per day

Other procedures:

Procedure Description
ValidCaltype Check if calendar type is valid
ValidZone Check if timezone is valid
ZoneToDiff Convert timezone to DC_DIFFTIME variable
ParseTimeUnits Parse time unit and return unit symbol

Usage

Display Current Time

When DCDateTimeCreate subroutine is used on a DC_DATETIME type variable, the time is set. If year/month/day are not specified, current time is set. The set time can be converted to character type with toChar. See dc_string::Printf for Printf subroutine details.

program dc_date_sample1
use dc_string, only: printf
use dc_date, only: dc_datetime, dcdatetimecreate, tochar
implicit none
type(DC_DATETIME) :: time
call dcdatetimecreate( time = time ) ! (out)
call printf( fmt = 'current date and time is %c', c1 = trim( tochar(time) ) )
end program dc_date_sample1
Date and time manipulation module.
Definition dc_date.f90:57
Handling character types.
Definition dc_string.f90:83

Adding Date/Time Information

DC_DIFFTIME type variables express time differences. In the example below, variable diff is prepared and set to 25 days + 12 hours + 50 minutes using Create subroutine. By adding DC_DATETIME variable time_before and diff with operator(+), we get time_after which is 25 days + 12 hours + 50 minutes ahead of time_before.

program dc_date_sample2
use dc_types, only: dp
use dc_string, only: printf
use dc_date, only: dc_datetime, dc_difftime, &
& dcdatetimecreate, dcdifftimecreate, tochar, operator(+)
implicit none
type(DC_DATETIME) :: time_before, time_after
type(DC_DIFFTIME) :: diff
call dcdatetimecreate( time = time_before, & ! (out)
& year = 2006, mon = 6, day = 10, & ! (in)
& hour = 14, min = 15, sec = 0.0_dp ) ! (in)
call dcdifftimecreate( diff = diff, & ! (out)
& day = 25, hour = 12, min = 50) ! (in)
time_after = time_before + diff
call printf( fmt = '%c + %c = %c', &
& c1 = trim( tochar(time_before) ), c2 = trim( tochar(diff) ), &
& c3 = trim( tochar(time_after) ) )
end program dc_date_sample2
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92

Application to Time Integration Loop

Below is an example program solving dA/dt = -αA (initial value 1, α=0.0001) up to t = 12 (hours) using forward difference. By using DC_DIFFTIME for Δt, data output interval, and calculation time, loop termination and time comparison for data output become easy.

program dc_date_sample3
use dc_types, only: dp
use dc_date, only: dc_difftime, &
& dcdifftimecreate, evalsec, evalbyunit, mod, &
& operator(*), operator(==), operator(>)
implicit none
real(DP) :: func_a = 1.0d0 ! Initial value of function A
real(DP), parameter :: alph = 0.0001d0 ! Coefficient α
character(*), parameter :: out_unit = 'hour' ! Unit for output time
type(DC_DIFFTIME):: DelTimef, intervalf, calctimef
integer :: i
continue
call dcdifftimecreate( & ! Δt = 5.0 (sec)
& diff = deltimef, & ! (out)
& value = 5.0_dp, unit = 'sec') ! (in)
call dcdifftimecreate( & ! Data output interval = 1.0 (min)
& diff = intervalf, & ! (out)
& value = 1.0_dp, unit = 'min') ! (in)
call dcdifftimecreate( & ! Calculation time = 12.0 (hour)
& diff = calctimef, & ! (out)
& value = 12.0_dp, unit = 'hour') ! (in)
open( 10, file='dc_date_sample.dat' )
write(10,'(A,A,A)') '# ', out_unit, ' value'
i = 1
do
if (deltimef * i > calctimef) exit ! Exit when past calculation time
! A_(n+1) = (1 - αΔt) * A_(n)
func_a = (1.0 - alph * evalsec(deltimef)) * func_a
! Output data every intervalf (1 min)
if (mod(deltimef * i, intervalf) == 0) then
write(10,*) ' ', evalbyunit( deltimef * i, out_unit ), func_a
end if
i = i + 1
end do
end program dc_date_sample3