FMS  2024.03
Flexible Modeling System
time_interp_mod

Computes a weight and dates/indices for linearly interpolating between two dates. More...

Data Types

interface  time_interp
 Returns a weight and dates or indices for interpolating between two dates. The interface fraction_of_year is provided for backward compatibility with the previous version.
. More...
 

Functions/Subroutines

subroutine bisect (Timelist, Time, index1, index2)
 Given an array of times in ascending order and a specific time returns values of index1 and index2 such that the Timelist(index1)<=Time and Time<=Timelist(index2), and index2=index1+1 index1=0, index2=1 or index=n, index2=n+1 are returned to indicate that the time is out of range.
 
subroutine error_handler (string)
 
real(r8_kind) function, public fraction_of_year (Time)
 Wrapper function to return the fractional time into the current year Always returns an r8_kind, conversion to r4 will be done implicitly if needed. More...
 
type(time_type) function month_midpt (yr, mo)
 
type(time_type) function set_modtime (Tin, modtime)
 
subroutine time_interp_day_ (Time, weight, year1, year2, month1, month2, day1, day2)
 Calculates fractional time between mid points of consecutive days.
 
subroutine time_interp_frac_ (Time, weight)
 Calculates the fractional time into the current year. More...
 
subroutine, public time_interp_init ()
 
subroutine time_interp_list_ (Time, Timelist, weight, index1, index2, modtime, err_msg)
 
subroutine time_interp_modulo_ (Time, Time_beg, Time_end, Timelist, weight, index1, index2, correct_leap_year_inconsistency, err_msg)
 Part of the time_interp interface, calculates for cyclical data Time_beg and Time_end mark a repeating period. More...
 
subroutine time_interp_month_ (Time, weight, year1, year2, month1, month2)
 Calculates fractional time between mid points of consecutive months.
 
subroutine time_interp_year_ (Time, weight, year1, year2)
 Calculates fractional time between mid points of consecutive years. More...
 
type(time_type) function year_midpt (yr)
 

Variables

integer, parameter, public day =3
 
integer dymod
 
integer, parameter halfday = secday/2
 
integer, parameter hourday = 24
 
integer, parameter minhour = 60
 
logical mod_leapyear
 
logical module_is_initialized =.FALSE.
 
integer momod
 
integer, parameter, public month =2
 
integer, parameter monyear = 12
 
integer, parameter, public none =0
 
logical perthlike_behavior =.FALSE.
 
integer, parameter secday = secmin*minhour*hourday
 
integer, parameter sechour = secmin*minhour
 
integer, parameter secmin = 60
 
integer, parameter, public year =1
 
integer yrmod
 

Detailed Description

Computes a weight and dates/indices for linearly interpolating between two dates.

Author
Bruce Wyman

A time type is converted into two consecutive dates plus a fraction representing the distance between the dates. This information can be used to interpolate between the dates. The dates may be expressed as years, months, or days or as indices in an array.


Data Type Documentation

◆ time_interp_mod::time_interp

interface time_interp_mod::time_interp

Returns a weight and dates or indices for interpolating between two dates. The interface fraction_of_year is provided for backward compatibility with the previous version.
.

Returns weight by interpolating Time between Time1 and Time2. i.e. weight = (Time-Time1)/(Time2-Time1) Time1 and Time2 may be specified by any of several different ways, which is the reason for multiple interfaces.

  • If Time1 and Time2 are the begining and end of the year in which Time falls, use first interface.
  • If Time1 and Time2 fall on year boundaries, use second interface.
  • If Time1 and Time2 fall on month boundaries, use third.
  • If Time1 and Time2 fall on day boundaries, use fourth.
  • If Time1 and Time2 are consecutive elements of an assending list, use fifth. The fifth also returns the indices of Timelist between which Time falls.
  • The sixth interface is for cyclical data. Time_beg and Time_end specify the begining and end of a repeating period. In this case:
    weight = (Time_adjusted - Time1) / (Time2 - Time1)
    Where:
    time1 = timelist(index1)
    time2 = timelist(index2)
    time_adjusted = time - n*period
    period = time_end-time_beg
    N is between (Time-Time_end)/Period and (Time-Time_beg)/Period That is, N is the integer that results in Time_adjusted that is between Time_beg and Time_end.


Example usages:

call time_interp( time, weight )
call time_interp( time, weight, year1, year2 )
call time_interp( time, weight, year1, year2, month1, month2 )
call time_interp( time, weight, year1, year2, month1, month2, day1, day2 )
call time_interp( time, timelist, weight, index1, index2 [, modtime] )
call time_interp( time, time_beg, time_end, timelist, weight, index1, index2
[,correct_leap_year_inconsistency])

For all routines in this module the calendar type in module time_manager must be set.

The following private parameters are set by this module:

 seconds per minute = 60
 minutes per hour   = 60
 hours   per day    = 24
 months  per year   = 12
Parameters
TimeThe time at which the the weight is computed.
Time_begFor cyclical interpolation: Time_beg specifies the begining time of a cycle.
Time_endFor cyclical interpolation: Time_end specifies the ending time of a cycle.
TimelistFor cyclical interpolation: Timelist is an array of times between Time_beg and Time_end. Must be monotonically increasing.
index1Timelist(index1) = The largest value of Timelist which is less than mod(Time,Time_end-Time_beg)
index2Timelist(index2) = The smallest value of Timelist which is greater than mod(Time,Time_end-Time_beg)
correct_leap_year_inconsistencyTurns on a kluge for an inconsistency which may occur in a special case. When the modulo time period (i.e. Time_end - Time_beg) is a whole number of years and is not a multiple of 4, and the calendar in use has leap years, then it is likely that the interpolation will involve mapping a common year onto a leap year. In this case it is often desirable, but not absolutely necessary, to use data for Feb 28 of the leap year when it is mapped onto a common year. To turn this on, set correct_leap_year_inconsistency=.true.
weightweight = (mod(Time,Time_end-Time_beg) - Timelist(index1)) / (Timelist(index2) - Timelist(index1))

Definition at line 127 of file time_interp.F90.

Private Member Functions

 time_interp_day_r4
 
 time_interp_day_r8
 
 time_interp_frac_r4
 
 time_interp_frac_r8
 
 time_interp_list_r4
 
 time_interp_list_r8
 
 time_interp_modulo_r4
 
 time_interp_modulo_r8
 
 time_interp_month_r4
 
 time_interp_month_r8
 
 time_interp_year_r4
 
 time_interp_year_r8
 

Function/Subroutine Documentation

◆ fraction_of_year()

real(r8_kind) function, public time_interp_mod::fraction_of_year ( type(time_type), intent(in)  Time)

Wrapper function to return the fractional time into the current year Always returns an r8_kind, conversion to r4 will be done implicitly if needed.

Parameters
Timetime to calculate fraction with
Returns
real(kind=8) fraction of time passed in current year

Definition at line 184 of file time_interp.F90.

◆ time_interp_frac_()

subroutine time_interp_frac_ ( type(time_type), intent(in)  Time,
real(fms_ti_kind_), intent(out)  weight 
)

Calculates the fractional time into the current year.

Parameters
[out]weightfractional time

Definition at line 24 of file time_interp.inc.

◆ time_interp_modulo_()

subroutine time_interp_modulo_ ( type(time_type), intent(in)  Time,
type(time_type), intent(in)  Time_beg,
type(time_type), intent(in)  Time_end,
type(time_type), dimension(:), intent(in)  Timelist,
real(fms_ti_kind_), intent(out)  weight,
integer, intent(out)  index1,
integer, intent(out)  index2,
logical, intent(in), optional  correct_leap_year_inconsistency,
character(len=*), intent(out), optional  err_msg 
)

Part of the time_interp interface, calculates for cyclical data Time_beg and Time_end mark a repeating period.

Finds mid points and fractional weight for a time perioid

Parameters
[in]timea specific time value
[in]time_begbegining of period to search with
[in]time_endend of period to search with
[in]timelistascending time values to search between
[out]index2indices of bounding time values within Timelist
[in]correct_leap_year_inconsistencyWhen true turns on a kluge for an inconsistency which may occur in a special case. When the modulo time period (i.e. Time_end - Time_beg) is a whole number of years and is not a multiple of 4, and the calendar in use has leap years, then it is likely that the interpolation will involve mapping a common year onto a leap year. In this case it is often desirable, but not absolutely necessary, to use data for Feb 28 of the leap year when it is mapped onto a common year.

Definition at line 181 of file time_interp.inc.

◆ time_interp_year_()

subroutine time_interp_year_ ( type(time_type), intent(in)  Time,
real(fms_ti_kind_), intent(out)  weight,
integer, intent(out)  year1,
integer, intent(out)  year2 
)

Calculates fractional time between mid points of consecutive years.

Parameters
[out]weightfractional time between midpoints of year1 and year2

Definition at line 48 of file time_interp.inc.