Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(in) | :: | y | |||
integer, | intent(in) | :: | n | |||
real(kind=r64), | intent(in), | DIMENSION(:) | :: | ytab |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
INTEGER FUNCTION SearchAscTable(y,n,ytab)
! FUNCTION INFORMATION:
! AUTHOR Joe Klems
! DATE WRITTEN Feb 2011
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS FUNCTION:
! Given an ascending monotonic table with n entries, find an index i
! such that ytab(i-1) < y <= ytab(i)
! METHODOLOGY EMPLOYED:
! binary search
! REFERENCES:
! na
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! FUNCTION ARGUMENT DEFINITIONS:
REAL(r64), INTENT (IN) :: y ! Value to be found in the table
INTEGER, INTENT (IN) :: n ! Number of values in the table
REAL(r64), DIMENSION(:), INTENT (IN) :: ytab ! Table of values, monotonic, ascending order
! FUNCTION PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! FUNCTION LOCAL VARIABLE DECLARATIONS:
INTEGER :: Ih ! Intex for upper end of interval
INTEGER :: Il ! Index for lower end of interval
INTEGER :: Im ! Index for midpoint of interval
REAL(r64) :: Yh ! Table value for upper end of interval
REAL(r64) :: Yl ! Table value for lower end of interval
REAL(r64) :: Ym ! Table value for midpoint of interval
Yh = ytab(n)
Yl = ytab(1)
Ih = n
Il = 1
IF (y < Yl) THEN
SearchAscTable = 1
RETURN
ELSE IF (y > Yh) THEN
SearchAscTable = n
RETURN
ENDIF
DO
IF(Ih-Il <= 1) EXIT
Im = (Ih + Il)/2
Ym = ytab(Im)
IF(y <= Ym) THEN
Yh = Ym
Ih = Im
ELSE
Yl = Ym
Il = Im
ENDIF
END DO
SearchAscTable = Ih
RETURN
END FUNCTION SearchAscTable