MODULE Time_Procedures

Module Time_Procedures exports constants, subroutines and functions for manipulating dates and time.

Here is the list of the public constants exported by module Time_Procedures:

!
! MONTHS OF THE YEAR.
!
character(len=9), parameter :: months(12) = (/   'January  ', 'February ',  &
                                                 'March    ', 'April    ',  &
                                                 'May      ', 'June     ',  &
                                                 'July     ', 'August   ',  &
                                                 'September', 'October  ',  &
                                                 'November ', 'December '/)
!
! DAYS OF THE WEEK.
!
character(len=9), parameter :: days(1:7)  = (/   'Monday   ',               &
                                                 'Tuesday  ', 'Wednesday',  &
                                                 'Thursday ', 'Friday   ',  &
                                                 'Saturday ', 'Sunday   ' /)

In order to use one of these constants or one of the routines listed below, you must include an appropriate use Time_Procedures or use Statpack statement in your Fortran program, like:

use Time_Procedures, only: months

or :

use Statpack, only: months

Here is the list of the public routines exported by Time_Procedures:

leapyr()

Purpose:

leapyr() checks for a leap year. LEAPYR is returned as true if IYR is a leap year, and false otherwise.

This function uses the Gregorian calendar adopted the Oct. 15, 1582.

Leap years are years that are evenly divisible by 4, except years that are evenly divisible by 100 must be divisible by 400.

Synopsis:

is_leap_year = leapyr( iyr )

Examples:

ex1_leapyr.F90

daynum()

Purpose:

daynum() computes a day number.

One of the more useful applications for this routine is to compute the number of days between two dates.

This function uses the Gregorian calendar adopted the Oct. 15, 1582.

In other words, Oct. 15, 1582 will return a day number of unity and hence this algorithm will not work properly for dates early than 10-15-1582.

Synopsis:

jdaynum = daynum( iyr , imon , iday )
day_of_week()

Purpose:

day_of_week() returns the day of the week (e.g., Mon, Tue, …) as an index (e.g. Mon = 1 to Sun=7) for a given year, month, and day.

This routine assumes a valid day, month and year are input.

Synopsis:

wdaynum = day_of_week( iyr , imon , iday )

Examples:

ex1_day_of_week.F90

daynum_to_ymd()

Purpose:

daynum_to_ymd() converts a Julian Day Number (JDAYNUM) to Gregorian year (IYR), month (IMON) and day (IDAY) in the Gregorian calendar promulgated by Gregory XIII, starting with jdaynum = 1 on Friday, 15 October 1582.

This subroutine is adapted from a MATLAB M-file written by W. Kahan available on the WEB.

Synopsis:

call daynum_to_ymd( jdaynum , iyr , imon , iday )

Examples:

ex1_daynum_to_ymd.F90

ymd_to_daynum()

Purpose:

ymd_to_daynum() is just the opposite of daynum_to_ymd(). It converts Gregorian year (IYR), month (IMON) and day (IDAY) to Julian day Number.

ymd_to_daynum() is useful to compute the number of days between two dates, which is the difference between their Julian day.

This subroutine is adapted from a MATLAB M-file written by W. Kahan available on the WEB.

Synopsis:

jdaynum = ymd_to_daynum( iyr , imon , iday )

Examples:

ex1_ymd_to_daynum.F90

ymd_to_dayweek()

Purpose:

ymd_to_dayweek() computes the day of the week from Gregorian year (IYR), month (IMON) and day (IDAY), as an integer index (e.g. Mon=1 to Sun=7) for the given year, month, and day in the Gregorian calendar promulgated by Gregory XIII on Friday, 15 October 1582.

This subroutine is adapted from a MATLAB M-file written by W. Kahan available on the WEB.

Synopsis:

wdaynum = ymd_to_dayweek( iyr , imon , iday )

Examples:

ex1_ymd_to_dayweek.F90

daynum_to_dayweek()

Purpose:

daynum_to_dayweek() computes the day of the week from Julian day number JDAYNUM, as an integer index (e.g. Mon=1 to Sun=7) starting with jdaynum = 1 on Friday, 15 October 1582.

Synopsis:

wdaynum = daynum_to_dayweek( jdaynum )

Examples:

ex1_daynum_to_dayweek.F90

rtsw()

Purpose:

rtsw() is a Real-Time Stop Watch.

This routine can be used to compute the time lapse (in seconds) between functions calls according to the system (wall) clock.

Since this routine uses the system clock, the elapsed time computed with this routine may not (probably won’t be in a multi-tasking OS) an accurate reflection of the number of cpu cycles required to perform a calculation. Therefore care should be exercised when using this to profile a code.

The result is a real of kind extd.

Synopsis:

wtime = rtsw( )

Examples:

ex1_rtsw.F90

elapsed_time()

Purpose:

elapsed_time() computes elapsed time between two invocations of the intrinsic function date_and_time(). elapsed_time( t1, t0 ) returns the time in seconds that has elapsed between the vectors T0 and T1. Each vector must have at least seven elements in the format returned by date_and_time() for the optional argument VALUES; namely

T = (/ year, month, day, x, hour, minute, second /)

This routine can be used to compute the elapsed time between date_and_time() calls according to the system (wall) clock.

Since this routine uses the system clock, the elapsed time computed with this routine may not (probably won’t be in a multi-tasking OS) an accurate reflection of the number of cpu cycles required to perform a calculation. Therefore care should be exercised when using this to profile a code.

Synopsis:

etime = elapsed_time( t1(:n) , t0(:n) )

Examples:

ex1_elapsed_time.F90

cpusecs()

Purpose:

cpusecs() obtains, from the intrinsic routine system_clock(), the current value of the system CPU usage clock. This value is then converted to seconds and returned as an extended precision real value (e.g. of kind extd).

This functions assumes that the number of CPU cycles (e.g. clock counts) between two calls is less than COUNT_MAX, the maximum possible value of clock counts as returned by the intrinsic routine system_clock().

The result is a real of kind extd.

Synopsis:

cputime = cpusecs( )

Examples:

ex1_cpusecs.F90

time_to_hmsms()

Purpose:

time_to_hmsms() converts time (in seconds) to hours, minutes, seconds, milliseconds format.

Synopsis:

call time_to_hmsms( time , hmsms(:4) )
time_to_string()

Purpose:

time_to_string() converts TIME to a string format for printing as

hours.minutes.seconds.milliseconds

The result is a string of (at least) 13 characters.

Synopsis:

ctime = time_to_string( time )

Examples:

ex1_time_to_string.F90

get_date()

Purpose:

get_date() outputs a given date given as year (IYR), month (IMON), and day (IDAY) in a nice format.

Synopsis:

call get_date( iyr , imon , iday , date )
get_date_time()

Purpose:

get_date_time() outputs system date and time in nice formats.

This routine just reformats the output from the standard date_and_time() intrinsic function.

Synopsis:

call get_date_time( date=date, time=time )
system_date_time()

Purpose:

system_date_time() retrieves the current system time and date and transfers them to the string argument CHDATE in a “pretty” format, i.e.,

chdate = "DATE: DD-MMM-YYYY  TIME: HH:MM:SS"

If the CHDATE argument is more than 33 characters in length, CHDATE is padded with blanks. If it is less than 33 in length, only the leftmost characters of the date will be returned.

Synopsis:

call system_date_time( chdate )
my_date_time()

Purpose:

my_date_time() returns in CHDATE a 41-character date of the form given in model (below).

It uses the time and date as obtained from the intrinsic routine date_and_time() and converts them to the form of the model:

chdate = "00:00 a.m., Wednesday, September 00, 1999"

Note that excess blanks in the date are eliminated. If CHDATE is more than 41 characters in length, CHDATE is padded with blanks. If it is less than 41 in length, only the leftmost characters of the date will be returned.

Synopsis:

call my_date_time( chdate )
Flag Counter