FMS  2024.03
Flexible Modeling System
time_manager_mod

A software package that provides a set of simple interfaces for modelers to perform computations related to time and dates. More...

Data Types

interface  assignment(=)
 Operator override interface for use with time_type. More...
 
interface  operator(*)
 Operator override interface for use with time_type. More...
 
interface  operator(+)
 Operator override interface for use with time_type. More...
 
interface  operator(-)
 Operator override interface for use with time_type. More...
 
interface  operator(/)
 Operator override interface for use with time_type. More...
 
interface  operator(//)
 Operator override interface for use with time_type. More...
 
interface  operator(/=)
 Operator override interface for use with time_type. More...
 
interface  operator(<)
 Operator override interface for use with time_type. More...
 
interface  operator(<=)
 Operator override interface for use with time_type. More...
 
interface  operator(==)
 Operator override interface for use with time_type. More...
 
interface  operator(>)
 Operator override interface for use with time_type. More...
 
interface  operator(>=)
 Operator override interface for use with time_type. More...
 
interface  set_date
 Given an input date in year, month, days, etc., creates a time_type that represents this time interval from the internally defined base date. More...
 
interface  set_time
 Given some number of seconds and days, returns the corresponding time_type. More...
 
type  time_type
 Type to represent amounts of time. Implemented as seconds and days to allow for larger intervals. More...
 

Functions/Subroutines

character(len=19) function convert_integer_date_to_char (year, month, day, hour, minute, second)
 
character(len=256) function cut0 (string)
 
character(len=15) function, public date_to_string (time, err_msg)
 Get the a character string that represents the time. The format will be yyyymmdd.hhmmss.
 
integer function, public day_of_year (time)
 Returns number of day in year for given time. Jan 1st is day 1, not zero!
 
integer function, public days_in_month (Time, err_msg)
 Given a time, computes the corresponding date given the selected date time mapping algorithm. More...
 
integer function days_in_month_gregorian (Time)
 Returns the number of days in a gregorian month.
 
integer function days_in_month_julian (Time)
 Returns the number of days in a julian month.
 
integer function days_in_month_no_leap (Time)
 Returns the number of days in a 365 day year month.
 
integer function days_in_month_thirty (Time)
 Returns the number of days in a thirty day month (needed for transparent changes to calendar type).
 
integer function, public days_in_year (Time)
 Returns the number of days in the calendar year corresponding to the date represented by time for the default calendar. More...
 
integer function days_in_year_gregorian (Time)
 
integer function days_in_year_julian (Time)
 
integer function days_in_year_no_leap (Time)
 
integer function days_in_year_thirty (Time)
 
type(time_type) function, public decrement_date (Time, years, months, days, hours, minutes, seconds, ticks, err_msg, allow_neg_inc)
 Given a time and some date decrement, computes a new time. Depending on the mapping algorithm from date to time, it may be possible to specify undefined decrements (i.e. if one decrements by 68 days and 3 months in a Julian calendar, it matters which order these operations are done and we don't want to deal with stuff like that, make it an error). More...
 
type(time_type) function, public decrement_time (Time, seconds, days, ticks, err_msg, allow_neg_inc)
 Decrements a time by seconds and days. More...
 
logical function error_handler (routine, err_msg_local, err_msg)
 The purpose of this routine is to prevent the addition of an excessive amount of code in order to implement the error handling scheme involving an optional error flag of type character. It allows one line of code to accomplish what would otherwise require 6 lines. A value of .true. for this function is a flag to the caller that it should immediately return to it's caller.
 
integer function, public get_calendar_type ()
 Returns default calendar type for mapping from time to date.
 
subroutine, public get_date (time, year, month, day, hour, minute, second, tick, err_msg)
 Gets the date for different calendar types. Given a time_interval, returns the corresponding date under the selected calendar. When err_msg present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this:
More...
 
subroutine get_date_gregorian (time, year, month, day, hour, minute, second, tick)
 Gets the date on a Gregorian calendar. Computes the year, month, day on the fly from the quantity timedays.
 
subroutine, public get_date_julian (time, year, month, day, hour, minute, second)
 
subroutine get_date_julian_private (time, year, month, day, hour, minute, second, tick)
 Base date for Julian calendar is year 1 with all multiples of 4 years being leap years.
 
subroutine, public get_date_no_leap (time, year, month, day, hour, minute, second)
 
subroutine get_date_no_leap_private (time, year, month, day, hour, minute, second, tick)
 
subroutine get_date_thirty (time, year, month, day, hour, minute, second, tick)
 Computes date corresponding to time interval for 30 day months, 12 month years.
 
logical function get_tick_from_string (string, err_msg, allow_rounding, tick)
 
integer function, public get_ticks_per_second ()
 Returns the number of ticks per second.
 
subroutine, public get_time (Time, seconds, days, ticks, err_msg)
 Returns days and seconds ( < 86400 ) corresponding to a time. err_msg should be checked for any errors. More...
 
type(time_type) function, public increment_date (Time, years, months, days, hours, minutes, seconds, ticks, err_msg, allow_neg_inc)
 
logical function increment_date_private (Time, years, months, days, hours, minutes, seconds, ticks, Time_out, err_msg)
 Given a time and some date increment, computes a new time. Depending on the mapping algorithm from date to time, it may be possible to specify undefined increments (i.e. if one increments by 68 days and 3 months in a Julian calendar, it matters which order these operations are done and we don't want to deal with stuff like that, make it an error). More...
 
type(time_type) function, public increment_time (Time, seconds, days, ticks, err_msg, allow_neg_inc)
 Increments a time by seconds and days. More...
 
logical function increment_time_private (Time_in, seconds, days, ticks, Time_out, err_msg)
 Increments a time by seconds, days and ticks.
 
logical function, public interval_alarm (time, time_interval, alarm, alarm_interval)
 Supports a commonly used type of test on times for models. Given the current time, and a time for an alarm, determines if this is the closest time to the alarm time given a time step of time_interval. If this is the closest time (alarm - time <= time_interval/2), the function returns true and the alarm is incremented by the alarm_interval. Watch for problems if the new alarm time is less than time + time_interval. More...
 
logical function, public leap_year (Time, err_msg)
 Returns true if the year corresponding to the input time is a leap year (for default calendar). Always returns false for THIRTY_DAY_MONTHS and NOLEAP. More...
 
logical function leap_year_gregorian (Time)
 
logical function leap_year_gregorian_int (year)
 
logical function leap_year_julian (Time)
 Returns the number of days in a julian month.
 
logical function leap_year_no_leap (Time)
 Another tough one; no leap year returns false for leap year inquiry.
 
logical function leap_year_thirty (Time)
 No leap years in thirty day months, included for transparency.
 
type(time_type) function, public length_of_year ()
 Returns the mean length of the year in the default calendar setting. More...
 
type(time_type) function length_of_year_gregorian ()
 
type(time_type) function length_of_year_julian ()
 
type(time_type) function length_of_year_no_leap ()
 
type(time_type) function length_of_year_thirty ()
 
character(len=9) function, public month_name (n)
 Returns a character string containing the name of the month corresponding to month number n. More...
 
subroutine, public print_date (Time, str, unit)
 Prints the time to standard output (or optional unit) as a date. More...
 
subroutine, public print_time (Time, str, unit)
 Prints the given time_type argument as a time (using days, seconds and ticks) More...
 
type(time_type) function real4_to_time_type (x, err_msg)
 
type(time_type) function real8_to_time_type (x, err_msg)
 Convert a real number of seconds into a time_type variable. More...
 
logical function, public repeat_alarm (time, alarm_frequency, alarm_length)
 Repeat_alarm supports an alarm that goes off with alarm_frequency and lasts for alarm_length. If the nearest occurence of an alarm time is less than half an alarm_length from the input time, repeat_alarm is true. For instance, if the alarm_frequency is 1 day, and the alarm_length is 2 hours, then repeat_alarm is true from time 2300 on day n to time 0100 on day n + 1 for all n. More...
 
integer function safe_rtoi (rval, mode)
 Convert a floating point value to an integer value. More...
 
type(time_type) function scalar_time_mult (n, time)
 Returns time multipled by integer factor n. More...
 
subroutine, public set_calendar_type (type, err_msg)
 Sets calendar_type for mapping an interval to a date. For the Gregorian calendar, negative years and the proleptic calendar are not used; and the discontinuity of days in October 1582 (when the Gregorian calendar was adopted by select groups in Europe) is also not taken into account. More...
 
type(time_type) function set_date_c (string, zero_year_warning, err_msg, allow_rounding)
 Calls set_date_private for different calendar types when given a string input. Examples of acceptable forms of string: More...
 
logical function set_date_gregorian (year, month, day, hour, minute, second, tick, Time_out, err_msg)
 Sets Time_outdays on a Gregorian calendar Computes the total number of days between 1/1/0001 to the current month/day/year.
 
type(time_type) function set_date_i (year, month, day, hour, minute, second, tick, err_msg)
 Calls set_date_private to set days for different calendar types.
 
type(time_type) function, public set_date_julian (year, month, day, hour, minute, second)
 
logical function set_date_julian_private (year, month, day, hour, minute, second, tick, Time_out, err_msg)
 
type(time_type) function, public set_date_no_leap (year, month, day, hour, minute, second)
 
logical function set_date_no_leap_private (year, month, day, hour, minute, second, tick, Time_out, err_msg)
 
logical function set_date_private (year, month, day, hour, minute, second, tick, Time_out, err_msg)
 Sets days for different calendar types. Given an input date in year, month, days, etc., creates a time_type that represents this time interval from the internally defined base date. More...
 
logical function set_date_thirty (year, month, day, hour, minute, second, tick, Time_out, err_msg)
 
subroutine, public set_ticks_per_second (tps)
 Sets the number of ticks per second.
 
type(time_type) function set_time_c (string, err_msg, allow_rounding)
 Returns a time_type set to the given amount of time via a string. More...
 
type(time_type) function set_time_i (seconds, days, ticks, err_msg)
 Returns a time_type set to the given amount of time via integer amounts. More...
 
logical function set_time_private (seconds, days, ticks, Time_out, err_msg)
 Returns a time interval corresponding to this number of days, seconds, and ticks. days, seconds and ticks may be negative, but resulting time must be positive.
 
subroutine time_assignment (time1, time2)
 Assigns all components of the time_type variable on RHS to same components of time_type variable on LHS.
 
integer function time_divide (time1, time2)
 Returns the largest integer, n, for which time1 >= time2 * n. More...
 
logical function time_eq (time1, time2)
 Returns true if time1 == time2. More...
 
logical function time_ge (time1, time2)
 Returns true if time1 >= time2. More...
 
logical function time_gt (time1, time2)
 Returns true if time1 > time2. More...
 
logical function time_le (time1, time2)
 Returns true if time1 <= time2. More...
 
subroutine, public time_list_error (T, Terr)
 This routine converts the integer tdays to a string. More...
 
logical function time_lt (time1, time2)
 Returns true if time1 < time2. More...
 
subroutine, public time_manager_init ()
 Initialization routine. Writes the version information to the log file.
 
type(time_type) function time_minus (time1, time2)
 Returns difference of two time_types. WARNING: a time type is positive so by definition time1 - time2 is the same as time2 - time1. More...
 
logical function time_ne (time1, time2)
 Returns true if time1 /= time2. More...
 
type(time_type) function time_plus (time1, time2)
 Returns sum of two time_types. More...
 
real(r8_kind) function time_real_divide (time1, time2)
 Returns the double precision quotient of two times. More...
 
type(time_type) function time_scalar_divide (time, n)
 Returns the largest time, t, for which n * t <= time. More...
 
type(time_type) function time_scalar_mult (time, n)
 Returns time multiplied by integer factor n. More...
 
real(kind=r8_kind) function, public time_type_to_real (time)
 Converts time to seconds and returns it as a real number.
 
character(len=24) function, public valid_calendar_types (ncal, err_msg)
 Returns a character string that describes the calendar type corresponding to the input integer. More...
 
logical function valid_increments (year, month, day, hour, minute, second, tick, err_msg)
 

Variables

integer, private calendar_type = NO_CALENDAR
 
integer, parameter days_in_400_year_period = 146097
 Used only for gregorian.
 
integer, dimension(12), private days_per_month = (/31,28,31,30,31,30,31,31,30,31,30,31/)
 
integer, parameter do_floor = 0
 
integer, parameter do_nearest = 1
 
integer, parameter, public gregorian = 3
 
integer, parameter, public invalid_calendar =-1
 
integer, parameter, public julian = 2
 
integer, parameter max_type = 4
 
logical module_is_initialized = .false.
 
integer, parameter, public no_calendar = 0
 
integer, parameter, public noleap = 4
 
integer, parameter seconds_per_day = rseconds_per_day
 
integer ticks_per_second = 1
 

Detailed Description

A software package that provides a set of simple interfaces for modelers to perform computations related to time and dates.

Optional error flag can be used in calling arguments of public routines. This allows the using routine to terminate the program. It is likely that more diagnostic information is available from the user than from time_manager alone. If the error flag is present then it is the responsibility of the using routine to test it and add additional information to the error message.

Calendar specific routines are private. They are not used, and should not be used, by any using code.

The module defines a type that can be used to represent discrete times (accurate to one second) and to map these times into dates using a variety of calendars. A time is mapped to a date by representing the time with respect to an arbitrary base date (refer to NOTES section for the base date setting).

The time_manager provides a single defined type, time_type, which is used to store time and date quantities. A time_type is a positive definite quantity that represents an interval of time. It can be most easily thought of as representing the number of seconds in some time interval. A time interval can be mapped to a date under a given calendar definition by using it to represent the time that has passed since some base date. A number of interfaces are provided to operate on time_type variables and their associated calendars. Time intervals can be as large as n days where n is the largest number represented by the default integer type on a compiler. This is typically considerably greater than 10 million years (assuming 32 bit integer representation) which is likely to be adequate for most applications. The description of the interfaces is separated into two sections. The first deals with operations on time intervals while the second deals with operations that convert time intervals to dates for a given calendar.

The smallest increment of time is referred to as a tick. A tick cannot be larger than 1 second, which also is the default. The number of ticks per second is set via pubic subroutine set_ticks_per_second. For example, ticks_per_second = 1000 will set the tick to one millisecond.


Data Type Documentation

◆ time_manager_mod::assignment(=)

interface time_manager_mod::assignment(=)

Operator override interface for use with time_type.

Definition at line 185 of file time_manager.F90.

Private Member Functions

subroutine time_assignment (time1, time2)
 Assigns all components of the time_type variable on RHS to same components of time_type variable on LHS.
 

◆ time_manager_mod::operator(*)

interface time_manager_mod::operator(*)

Operator override interface for use with time_type.

Definition at line 156 of file time_manager.F90.

Private Member Functions

type(time_type) function scalar_time_mult (n, time)
 Returns time multipled by integer factor n. More...
 
type(time_type) function time_scalar_mult (time, n)
 Returns time multiplied by integer factor n. More...
 

Member Function/Subroutine Documentation

◆ scalar_time_mult()

type(time_type) function scalar_time_mult ( integer, intent(in)  n,
type(time_type), intent(in)  time 
)
private

Returns time multipled by integer factor n.

Parameters
[in]timea time interval
[in]nfactor to mulitply by

Definition at line 800 of file time_manager.F90.

◆ time_scalar_mult()

type(time_type) function time_scalar_mult ( type(time_type), intent(in)  time,
integer, intent(in)  n 
)
private

Returns time multiplied by integer factor n.

Parameters
[in]timetime interval to multply
[in]nfactor to multiply by

Definition at line 761 of file time_manager.F90.

◆ time_manager_mod::operator(+)

interface time_manager_mod::operator(+)

Operator override interface for use with time_type.

Definition at line 150 of file time_manager.F90.

Private Member Functions

type(time_type) function time_plus (time1, time2)
 Returns sum of two time_types. More...
 

Member Function/Subroutine Documentation

◆ time_plus()

type(time_type) function time_plus ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns sum of two time_types.

Parameters
[in]time1time interval to add
[in]time2time interval to add

Definition at line 728 of file time_manager.F90.

◆ time_manager_mod::operator(-)

interface time_manager_mod::operator(-)

Operator override interface for use with time_type.

Definition at line 153 of file time_manager.F90.

Private Member Functions

type(time_type) function time_minus (time1, time2)
 Returns difference of two time_types. WARNING: a time type is positive so by definition time1 - time2 is the same as time2 - time1. More...
 

Member Function/Subroutine Documentation

◆ time_minus()

type(time_type) function time_minus ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns difference of two time_types. WARNING: a time type is positive so by definition time1 - time2 is the same as time2 - time1.

Parameters
[in]time1time interval to subtract
[in]time2time interval to subtract

Definition at line 743 of file time_manager.F90.

◆ time_manager_mod::operator(/)

interface time_manager_mod::operator(/)

Operator override interface for use with time_type.

Definition at line 160 of file time_manager.F90.

Private Member Functions

integer function time_divide (time1, time2)
 Returns the largest integer, n, for which time1 >= time2 * n. More...
 
type(time_type) function time_scalar_divide (time, n)
 Returns the largest time, t, for which n * t <= time. More...
 

Member Function/Subroutine Documentation

◆ time_divide()

integer function time_divide ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns the largest integer, n, for which time1 >= time2 * n.

Parameters
[in]time1a time interval (dividend)
[in]time2a time interval (divisor)

Definition at line 813 of file time_manager.F90.

◆ time_scalar_divide()

type(time_type) function time_scalar_divide ( type(time_type), intent(in)  time,
integer, intent(in)  n 
)
private

Returns the largest time, t, for which n * t <= time.

Parameters
[in]timetime interval to divide
[in]ndivisor

Definition at line 944 of file time_manager.F90.

◆ time_manager_mod::operator(//)

interface time_manager_mod::operator(//)

Operator override interface for use with time_type.

Definition at line 182 of file time_manager.F90.

Private Member Functions

real(r8_kind) function time_real_divide (time1, time2)
 Returns the double precision quotient of two times. More...
 

Member Function/Subroutine Documentation

◆ time_real_divide()

real(r8_kind) function time_real_divide ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns the double precision quotient of two times.

Parameters
[in]time1a time interval (dividend)
[in]time2a time interval (divisor)

Definition at line 838 of file time_manager.F90.

◆ time_manager_mod::operator(/=)

interface time_manager_mod::operator(/=)

Operator override interface for use with time_type.

Definition at line 179 of file time_manager.F90.

Private Member Functions

logical function time_ne (time1, time2)
 Returns true if time1 /= time2. More...
 

Member Function/Subroutine Documentation

◆ time_ne()

logical function time_ne ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 /= time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 716 of file time_manager.F90.

◆ time_manager_mod::operator(<)

interface time_manager_mod::operator(<)

Operator override interface for use with time_type.

Definition at line 170 of file time_manager.F90.

Private Member Functions

logical function time_lt (time1, time2)
 Returns true if time1 < time2. More...
 

Member Function/Subroutine Documentation

◆ time_lt()

logical function time_lt ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 < time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 671 of file time_manager.F90.

◆ time_manager_mod::operator(<=)

interface time_manager_mod::operator(<=)

Operator override interface for use with time_type.

Definition at line 173 of file time_manager.F90.

Private Member Functions

logical function time_le (time1, time2)
 Returns true if time1 <= time2. More...
 

Member Function/Subroutine Documentation

◆ time_le()

logical function time_le ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 <= time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 689 of file time_manager.F90.

◆ time_manager_mod::operator(==)

interface time_manager_mod::operator(==)

Operator override interface for use with time_type.

Definition at line 176 of file time_manager.F90.

Private Member Functions

logical function time_eq (time1, time2)
 Returns true if time1 == time2. More...
 

Member Function/Subroutine Documentation

◆ time_eq()

logical function time_eq ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 == time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 701 of file time_manager.F90.

◆ time_manager_mod::operator(>)

interface time_manager_mod::operator(>)

Operator override interface for use with time_type.

Definition at line 164 of file time_manager.F90.

Private Member Functions

logical function time_gt (time1, time2)
 Returns true if time1 > time2. More...
 

Member Function/Subroutine Documentation

◆ time_gt()

logical function time_gt ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 > time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 639 of file time_manager.F90.

◆ time_manager_mod::operator(>=)

interface time_manager_mod::operator(>=)

Operator override interface for use with time_type.

Definition at line 167 of file time_manager.F90.

Private Member Functions

logical function time_ge (time1, time2)
 Returns true if time1 >= time2. More...
 

Member Function/Subroutine Documentation

◆ time_ge()

logical function time_ge ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 >= time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 659 of file time_manager.F90.

◆ time_manager_mod::set_date

interface time_manager_mod::set_date

Given an input date in year, month, days, etc., creates a time_type that represents this time interval from the internally defined base date.

Given a date, computes the corresponding time given the selected date time mapping algorithm. Note that it is possible to specify any number of illegal dates; these should be checked for and generate errors as appropriate.


Example usage:
Integer input

time = set_date(year, month, day, hours, minute, second, tick, err_msg)


String input

time = set_date(time_string, zero_year_warning, err_msg, allow_rounding)
Parameters
time_stringA character string containing a date formatted according to CF conventions. e.g. '1980-12-31 23:59:59.9'
zero_year_warningIf the year number is zero, it will be silently changed to one, unless zero_year_warning=.true., in which case a WARNING message will also be issued.
allow_roundingWhen .true., any fractions of a second will be rounded off to the nearest tick. When .false., it is a fatal error if the second fraction cannot be exactly represented by a number of ticks.
err_msgWhen present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this:
if(err_msg /= '') call error_mesg('my_routine','additional info: '//trim(err_msg) ,fatal)

Definition at line 247 of file time_manager.F90.

Private Member Functions

type(time_type) function set_date_c (string, zero_year_warning, err_msg, allow_rounding)
 Calls set_date_private for different calendar types when given a string input. Examples of acceptable forms of string: More...
 
type(time_type) function set_date_i (year, month, day, hour, minute, second, tick, err_msg)
 Calls set_date_private to set days for different calendar types.
 

Member Function/Subroutine Documentation

◆ set_date_c()

type(time_type) function set_date_c ( character(len=*), intent(in)  string,
logical, intent(in), optional  zero_year_warning,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_rounding 
)
private

Calls set_date_private for different calendar types when given a string input. Examples of acceptable forms of string:

1980-01-01 00:00:00 1980-01-01 00:00:00.50 1980-1-1 0:0:0 1980-1-1

year number must occupy 4 spaces. months, days, hours, minutes, seconds may occupy 1 or 2 spaces year, month and day must be separated by a '-' hour, minute, second must be separated by a ':' hour, minute, second are optional. If not present then zero is assumed. second may be a real number.

zero_year_warning: If the year number is zero, it will be silently changed to one, unless zero_year_warning=.true., in which case a WARNING message will also be issued

Definition at line 1508 of file time_manager.F90.

◆ time_manager_mod::set_time

interface time_manager_mod::set_time

Given some number of seconds and days, returns the corresponding time_type.

Given some number of seconds and days, returns the corresponding time_type. set_time has two forms; one accepts integer input, the other a character string with the day and second counts. For the first form, there are no restrictions on the range of the inputs, except that the result must be positive time. e.g. days=-1, seconds=86401 is acceptable. For the second form, days and seconds must both be positive.


Example usage:

type(time_type) :: time1, time2
time1 = set_time(seconds, days, ticks, err_msg)
time2 = set_time("100 43200", err_msg, allow_rounding)

Definition at line 207 of file time_manager.F90.

Private Member Functions

type(time_type) function set_time_c (string, err_msg, allow_rounding)
 Returns a time_type set to the given amount of time via a string. More...
 
type(time_type) function set_time_i (seconds, days, ticks, err_msg)
 Returns a time_type set to the given amount of time via integer amounts. More...
 

Member Function/Subroutine Documentation

◆ set_time_c()

type(time_type) function set_time_c ( character(len=*), intent(in)  string,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_rounding 
)
private

Returns a time_type set to the given amount of time via a string.

Parameters
[in]stringContains days and seconds separated by a single blank. days must be integer, seconds may be integer or real. Examples: '100 43200' '100 43200.50'
[out]err_msgWhen present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this: if(err_msg /= '') call error_mesg('my_routine','additional info: '//trim(err_msg),FATAL)
[in]allow_roundingWhen .true., any fractions of a second will be rounded off to the nearest tick. When .false., it is a fatal error if the second fraction cannot be exactly represented by a number of ticks.

Definition at line 360 of file time_manager.F90.

◆ set_time_i()

type(time_type) function set_time_i ( integer, intent(in)  seconds,
integer, intent(in), optional  days,
integer, intent(in), optional  ticks,
character(len=*), intent(out), optional  err_msg 
)
private

Returns a time_type set to the given amount of time via integer amounts.

Parameters
[in]secondsA number of seconds
[in]daysA number of days
[in]ticksA number of ticks
[out]err_msgWhen present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this: if(err_msg /= '') call error_mesg('my_routine','additional info: '//trim(err_msg),FATAL)

Definition at line 332 of file time_manager.F90.

◆ time_manager_mod::time_type

type time_manager_mod::time_type

Type to represent amounts of time. Implemented as seconds and days to allow for larger intervals.

Definition at line 141 of file time_manager.F90.

Collaboration diagram for time_type:
[legend]

Private Attributes

integer days
 
integer seconds
 
integer ticks
 

Function/Subroutine Documentation

◆ days_in_month()

integer function, public time_manager_mod::days_in_month ( type(time_type), intent(in)  Time,
character(len=*), intent(out), optional  err_msg 
)

Given a time, computes the corresponding date given the selected date time mapping algorithm.

Returns
number of days in month given the current selected calendar type
Parameters
[in]timea time interval

Definition at line 2136 of file time_manager.F90.

◆ days_in_year()

integer function, public time_manager_mod::days_in_year ( type(time_type), intent(in)  Time)

Returns the number of days in the calendar year corresponding to the date represented by time for the default calendar.

Returns
The number of days in this year for the default calendar type.
Parameters
[in]timeA time interval

Definition at line 2383 of file time_manager.F90.

◆ decrement_date()

type(time_type) function, public time_manager_mod::decrement_date ( type(time_type), intent(in)  Time,
integer, intent(in), optional  years,
integer, intent(in), optional  months,
integer, intent(in), optional  days,
integer, intent(in), optional  hours,
integer, intent(in), optional  minutes,
integer, intent(in), optional  seconds,
integer, intent(in), optional  ticks,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_neg_inc 
)

Given a time and some date decrement, computes a new time. Depending on the mapping algorithm from date to time, it may be possible to specify undefined decrements (i.e. if one decrements by 68 days and 3 months in a Julian calendar, it matters which order these operations are done and we don't want to deal with stuff like that, make it an error).

Note
For all but the thirty_day_months calendar, decrements to months and years must be made separately from other units because of the non-associative nature of addition. If the result is a negative time (i.e. date before the base date) it is considered a fatal error.
Returns
Time after the given decrement is applied
Parameters
[in]timetime interval to decrement
[in]ticksamount of time to decrement by units should not exceed next largest unit (ie. 61 seconds should be 1 min 1 sec )

Definition at line 2089 of file time_manager.F90.

◆ decrement_time()

type(time_type) function, public time_manager_mod::decrement_time ( type(time_type), intent(in)  Time,
integer, intent(in)  seconds,
integer, intent(in), optional  days,
integer, intent(in), optional  ticks,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_neg_inc 
)

Decrements a time by seconds and days.

Given a time and a decrement of days and seconds, returns a time that subtracts this decrement from an input time.

Returns
A time that suvtracts this decrement from an input time. A negative result is a fatal error.
Parameters
[in]timeA time interval
[in]secondsDecrement of seconds
[in]ticksDecrement of days and ticks
[out]err_msgPresent and non-blank when a fatal error has occured, holds the error message.
[in]allow_neg_incThrows fatal warning when set to false if negative values are used to decrement. Default is true.

Definition at line 600 of file time_manager.F90.

◆ get_date()

subroutine, public time_manager_mod::get_date ( type(time_type), intent(in)  time,
integer, intent(out)  year,
integer, intent(out)  month,
integer, intent(out)  day,
integer, intent(out)  hour,
integer, intent(out)  minute,
integer, intent(out)  second,
integer, intent(out), optional  tick,
character(len=*), intent(out), optional  err_msg 
)

Gets the date for different calendar types. Given a time_interval, returns the corresponding date under the selected calendar. When err_msg present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this:

    if(err_msg /= '') call error_mesg('my_routine','additional info: '//trim(err_msg),FATAL)

Definition at line 1145 of file time_manager.F90.

◆ get_time()

subroutine, public time_manager_mod::get_time ( type(time_type), intent(in)  Time,
integer, intent(out)  seconds,
integer, intent(out), optional  days,
integer, intent(out), optional  ticks,
character(len=*), intent(out), optional  err_msg 
)

Returns days and seconds ( < 86400 ) corresponding to a time. err_msg should be checked for any errors.

Parameters
timeA time_type interval to get days and seconds from
[out]secondsThe number of seconds
[out]daysThe number of seconds
[out]ticksThe number of ticks
[out]err_msgContains an error message on failure
Example usage:
get_time(time, seconds, days, ticks, err_msg)

Definition at line 491 of file time_manager.F90.

◆ increment_date_private()

logical function time_manager_mod::increment_date_private ( type(time_type), intent(in)  Time,
integer, intent(in)  years,
integer, intent(in)  months,
integer, intent(in)  days,
integer, intent(in)  hours,
integer, intent(in)  minutes,
integer, intent(in)  seconds,
integer, intent(in)  ticks,
type(time_type), intent(out)  Time_out,
character(len=*), intent(out)  err_msg 
)
private

Given a time and some date increment, computes a new time. Depending on the mapping algorithm from date to time, it may be possible to specify undefined increments (i.e. if one increments by 68 days and 3 months in a Julian calendar, it matters which order these operations are done and we don't want to deal with stuff like that, make it an error).

This routine operates in one of two modes.

  1. days, hours, minutes, seconds, ticks are incremented, years and months must be zero or absent arguments.
  2. years and/or months are incremented, other time increments must be zero or absent arguments.

Negative increments are always allowed in the private version of this routine.

Definition at line 1993 of file time_manager.F90.

◆ increment_time()

type(time_type) function, public time_manager_mod::increment_time ( type(time_type), intent(in)  Time,
integer, intent(in)  seconds,
integer, intent(in), optional  days,
integer, intent(in), optional  ticks,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_neg_inc 
)

Increments a time by seconds and days.

Given a time and an increment of days and seconds, returns a new time_type that represents the given time after the given increment.

Returns
incremented time_type
Parameters
[in]timeA time interval
[in]secondsIncrement of seconds
[in]ticksIncrement of days and ticks
[out]err_msgWhen present and non-blank, a fatal error condition has been detected, with the string itself as the error message.
[in]allow_neg_incWhen false, negative increments give fatal errors Defaults to true.

Definition at line 532 of file time_manager.F90.

◆ interval_alarm()

logical function, public time_manager_mod::interval_alarm ( type(time_type), intent(in)  time,
type(time_type), intent(in)  time_interval,
type(time_type), intent(inout)  alarm,
type(time_type), intent(in)  alarm_interval 
)

Supports a commonly used type of test on times for models. Given the current time, and a time for an alarm, determines if this is the closest time to the alarm time given a time step of time_interval. If this is the closest time (alarm - time <= time_interval/2), the function returns true and the alarm is incremented by the alarm_interval. Watch for problems if the new alarm time is less than time + time_interval.

This is a specialized operation that is frequently performed in models. Given a time, and a time interval, this function is true if this is the closest time step to the alarm time. The actual computation is:

if((alarm_time - time) &#60;&#61; (time_interval / 2))

If the function is true, the alarm time is incremented by the alarm_interval; WARNING, this is a featured side effect. Otherwise, the function is false and there are no other effects. CAUTION: if the alarm_interval is smaller than the time_interval, the alarm may fail to return true ever again. Watch for problems if the new alarm time is less than time + time_interval

Parameters
[in]timecurrent time
[in]time_intervala time interval
[in]alarm_intervala time interval
[in,out]alarmAn alarm time, which is incremented by the alarm_interval if the function is true.

Definition at line 1000 of file time_manager.F90.

◆ leap_year()

logical function, public time_manager_mod::leap_year ( type(time_type), intent(in)  Time,
character(len=*), intent(out), optional  err_msg 
)

Returns true if the year corresponding to the input time is a leap year (for default calendar). Always returns false for THIRTY_DAY_MONTHS and NOLEAP.

Parameters
[in]timea time interval to check if leap year

Definition at line 2216 of file time_manager.F90.

◆ length_of_year()

type(time_type) function, public time_manager_mod::length_of_year

Returns the mean length of the year in the default calendar setting.

There are no arguments in this function. It returns the mean length of the year for the default calendar.

Definition at line 2304 of file time_manager.F90.

◆ month_name()

character (len=9) function, public time_manager_mod::month_name ( integer, intent(in)  n)

Returns a character string containing the name of the month corresponding to month number n.

Definition is the same for all calendar types.

Returns
The character string associated with a month. All calendars have 12 months and return full month names, not abreviations.
Parameters
[in]nMonth number

Definition at line 2465 of file time_manager.F90.

◆ print_date()

subroutine, public time_manager_mod::print_date ( type(time_type), intent(in)  Time,
character (len=*), intent(in), optional  str,
integer, intent(in), optional  unit 
)

Prints the time to standard output (or optional unit) as a date.

Prints the given time_type argument as a date (using year, month, day, hour, minutes, seconds and ticks). NOTE: there is no check for PE number.

Parameters
[in]timeTime that will be printed
[in]strCharacter string that precedes the printed time
[in]unitUnit number for printed output, defaults to stdout

Definition at line 2559 of file time_manager.F90.

◆ print_time()

subroutine, public time_manager_mod::print_time ( type(time_type), intent(in)  Time,
character (len=*), intent(in), optional  str,
integer, intent(in), optional  unit 
)

Prints the given time_type argument as a time (using days, seconds and ticks)

Note
There is no check for PE number.
Parameters
[in]timeTime that will be printed
[in]strCharacter string that precedes the printed time
[in]unitUnit number for printed output, defaults to stdout

Definition at line 2524 of file time_manager.F90.

◆ real4_to_time_type()

type(time_type) function time_manager_mod::real4_to_time_type ( real(r4_kind), intent(in)  x,
character(len=*), intent(out), optional  err_msg 
)
private
Parameters
[in]xnumber of seconds
[out]err_msgError message.

Definition at line 910 of file time_manager.F90.

◆ real8_to_time_type()

type(time_type) function time_manager_mod::real8_to_time_type ( real(r8_kind), intent(in)  x,
character(len=*), intent(out), optional  err_msg 
)
private

Convert a real number of seconds into a time_type variable.

Returns
A filled time type variable, and an error message if an error occurs.
Parameters
[in]xNumber of seconds.
[out]err_msgError message.

Definition at line 885 of file time_manager.F90.

◆ repeat_alarm()

logical function, public time_manager_mod::repeat_alarm ( type(time_type), intent(in)  time,
type(time_type), intent(in)  alarm_frequency,
type(time_type), intent(in)  alarm_length 
)

Repeat_alarm supports an alarm that goes off with alarm_frequency and lasts for alarm_length. If the nearest occurence of an alarm time is less than half an alarm_length from the input time, repeat_alarm is true. For instance, if the alarm_frequency is 1 day, and the alarm_length is 2 hours, then repeat_alarm is true from time 2300 on day n to time 0100 on day n + 1 for all n.

Parameters
[in]timecurrent time
[in]alarm_frequencya time interval for time in between alarm activations
[in]alarm_lengtha time interval for amount of time alarm is active for

Definition at line 1025 of file time_manager.F90.

◆ safe_rtoi()

integer function time_manager_mod::safe_rtoi ( real(r8_kind), intent(in)  rval,
integer, intent(in)  mode 
)
private

Convert a floating point value to an integer value.

Returns
The integer value, using the input rounding mode.
Parameters
[in]rvalA floating point value.
[in]modeA rouding mode (either "do_floor" or "do_nearest")

Definition at line 919 of file time_manager.F90.

◆ scalar_time_mult()

type(time_type) function time_manager_mod::scalar_time_mult ( integer, intent(in)  n,
type(time_type), intent(in)  time 
)
private

Returns time multipled by integer factor n.

Parameters
[in]timea time interval
[in]nfactor to mulitply by

Definition at line 800 of file time_manager.F90.

◆ set_calendar_type()

subroutine, public time_manager_mod::set_calendar_type ( integer, intent(in)  type,
character(len=*), intent(out), optional  err_msg 
)

Sets calendar_type for mapping an interval to a date. For the Gregorian calendar, negative years and the proleptic calendar are not used; and the discontinuity of days in October 1582 (when the Gregorian calendar was adopted by select groups in Europe) is also not taken into account.

Parameters
[in]typeconstant parameter value (ie. one NO_CALENDAR, )

Definition at line 1074 of file time_manager.F90.

◆ set_date_c()

type(time_type) function time_manager_mod::set_date_c ( character(len=*), intent(in)  string,
logical, intent(in), optional  zero_year_warning,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_rounding 
)
private

Calls set_date_private for different calendar types when given a string input. Examples of acceptable forms of string:

1980-01-01 00:00:00 1980-01-01 00:00:00.50 1980-1-1 0:0:0 1980-1-1

year number must occupy 4 spaces. months, days, hours, minutes, seconds may occupy 1 or 2 spaces year, month and day must be separated by a '-' hour, minute, second must be separated by a ':' hour, minute, second are optional. If not present then zero is assumed. second may be a real number.

zero_year_warning: If the year number is zero, it will be silently changed to one, unless zero_year_warning=.true., in which case a WARNING message will also be issued

Definition at line 1508 of file time_manager.F90.

◆ set_date_private()

logical function time_manager_mod::set_date_private ( integer, intent(in)  year,
integer, intent(in)  month,
integer, intent(in)  day,
integer, intent(in)  hour,
integer, intent(in)  minute,
integer, intent(in)  second,
integer, intent(in)  tick,
type(time_type Time_out,
character(len=*), intent(out)  err_msg 
)
private

Sets days for different calendar types. Given an input date in year, month, days, etc., creates a time_type that represents this time interval from the internally defined base date.

Note
that it is possible to specify any number of illegal dates; these are checked for and generate errors as appropriate.
Parameters
[out]err_msgerror message, if non-empty an error has occured

Definition at line 1430 of file time_manager.F90.

◆ set_time_c()

type(time_type) function time_manager_mod::set_time_c ( character(len=*), intent(in)  string,
character(len=*), intent(out), optional  err_msg,
logical, intent(in), optional  allow_rounding 
)
private

Returns a time_type set to the given amount of time via a string.

Parameters
[in]stringContains days and seconds separated by a single blank. days must be integer, seconds may be integer or real. Examples: '100 43200' '100 43200.50'
[out]err_msgWhen present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this: if(err_msg /= '') call error_mesg('my_routine','additional info: '//trim(err_msg),FATAL)
[in]allow_roundingWhen .true., any fractions of a second will be rounded off to the nearest tick. When .false., it is a fatal error if the second fraction cannot be exactly represented by a number of ticks.

Definition at line 360 of file time_manager.F90.

◆ set_time_i()

type(time_type) function time_manager_mod::set_time_i ( integer, intent(in)  seconds,
integer, intent(in), optional  days,
integer, intent(in), optional  ticks,
character(len=*), intent(out), optional  err_msg 
)
private

Returns a time_type set to the given amount of time via integer amounts.

Parameters
[in]secondsA number of seconds
[in]daysA number of days
[in]ticksA number of ticks
[out]err_msgWhen present, and when non-blank, a fatal error condition as been detected. The string itself is an error message. It is recommended that, when err_msg is present in the call to this routine, the next line of code should be something similar to this: if(err_msg /= '') call error_mesg('my_routine','additional info: '//trim(err_msg),FATAL)

Definition at line 332 of file time_manager.F90.

◆ time_divide()

integer function time_manager_mod::time_divide ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns the largest integer, n, for which time1 >= time2 * n.

Parameters
[in]time1a time interval (dividend)
[in]time2a time interval (divisor)

Definition at line 813 of file time_manager.F90.

◆ time_eq()

logical function time_manager_mod::time_eq ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 == time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 701 of file time_manager.F90.

◆ time_ge()

logical function time_manager_mod::time_ge ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 >= time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 659 of file time_manager.F90.

◆ time_gt()

logical function time_manager_mod::time_gt ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 > time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 639 of file time_manager.F90.

◆ time_le()

logical function time_manager_mod::time_le ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 <= time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 689 of file time_manager.F90.

◆ time_list_error()

subroutine, public time_manager_mod::time_list_error ( type(time_type), intent(in)  T,
character(len=:), allocatable  Terr 
)

This routine converts the integer tdays to a string.

Author
Tom Robinson thoma.nosp@m.s.ro.nosp@m.binso.nosp@m.n@no.nosp@m.aa.go.nosp@m.v
Parameters
[in]ttime_type input
terrString holding the tdays

Allocate the string

Write the integer to the string

Definition at line 2639 of file time_manager.F90.

◆ time_lt()

logical function time_manager_mod::time_lt ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 < time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 671 of file time_manager.F90.

◆ time_minus()

type(time_type) function time_manager_mod::time_minus ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns difference of two time_types. WARNING: a time type is positive so by definition time1 - time2 is the same as time2 - time1.

Parameters
[in]time1time interval to subtract
[in]time2time interval to subtract

Definition at line 743 of file time_manager.F90.

◆ time_ne()

logical function time_manager_mod::time_ne ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns true if time1 /= time2.

Parameters
[in]time1time interval to compare
[in]time2time interval to compare

Definition at line 716 of file time_manager.F90.

◆ time_plus()

type(time_type) function time_manager_mod::time_plus ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns sum of two time_types.

Parameters
[in]time1time interval to add
[in]time2time interval to add

Definition at line 728 of file time_manager.F90.

◆ time_real_divide()

real(r8_kind) function time_manager_mod::time_real_divide ( type(time_type), intent(in)  time1,
type(time_type), intent(in)  time2 
)
private

Returns the double precision quotient of two times.

Parameters
[in]time1a time interval (dividend)
[in]time2a time interval (divisor)

Definition at line 838 of file time_manager.F90.

◆ time_scalar_divide()

type(time_type) function time_manager_mod::time_scalar_divide ( type(time_type), intent(in)  time,
integer, intent(in)  n 
)
private

Returns the largest time, t, for which n * t <= time.

Parameters
[in]timetime interval to divide
[in]ndivisor

Definition at line 944 of file time_manager.F90.

◆ time_scalar_mult()

type(time_type) function time_manager_mod::time_scalar_mult ( type(time_type), intent(in)  time,
integer, intent(in)  n 
)
private

Returns time multiplied by integer factor n.

Parameters
[in]timetime interval to multply
[in]nfactor to multiply by

Definition at line 761 of file time_manager.F90.

◆ valid_calendar_types()

character(len=24) function, public time_manager_mod::valid_calendar_types ( integer, intent(in)  ncal,
character(len=*), intent(out), optional  err_msg 
)

Returns a character string that describes the calendar type corresponding to the input integer.

Returns
A character string describing the calendar type
Parameters
[in]ncalInteger corresponding to a valid calendar type
[out]err_msgHolds an error message when present

Definition at line 2589 of file time_manager.F90.