Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(in) | :: | Value | |||
real(kind=r64), | intent(in), | DIMENSION(:) | :: | Array | ||
integer, | intent(in), | optional | :: | LowBound | ||
integer, | intent(in), | optional | :: | UpperBound |
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 FindArrayIndex(Value,Array,LowBound,UpperBound)
! FUNCTION INFORMATION:
! AUTHOR Rick Strand
! DATE WRITTEN May 2000
! MODIFIED Simon Rees (May 2002)
! RE-ENGINEERED na
! PURPOSE OF THIS FUNCTION:
! This generic function simply finds the points in an array between
! which a single value is found. The returned value is the index of
! the low point.
! METHODOLOGY EMPLOYED:
! Straight interval halving. It is assumed that the values in the array
! appear in ascending order. If the value is below that in the supplied
! data array a zero index is returned. If the value is above that in the
! supplied data array, the max index is returned. This allows some error
! checking in the calling routine.
! REFERENCES:
! na
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! FUNCTION ARGUMENT DEFINITIONS:
REAL(r64), INTENT(IN) :: Value ! Value to be placed/found within the array of values
REAL(r64), INTENT(IN), DIMENSION(:) :: Array ! Array of values in ascending order
INTEGER, INTENT(IN), OPTIONAL :: LowBound ! Valid values lower bound (set by calling program)
INTEGER, INTENT(IN), OPTIONAL :: UpperBound ! Valid values upper bound (set by calling program)
! FUNCTION PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! FUNCTION LOCAL VARIABLE DECLARATIONS:
INTEGER :: start ! sets low index value
INTEGER :: finish ! sets high index value
INTEGER :: middle ! difference of finish & start
! FLOW:
IF (PRESENT(LowBound) .and. PRESENT(UpperBound)) THEN
start = LowBound
finish = UpperBound
ELSEIF (PRESENT(LowBound)) THEN
start = LowBound
finish = SIZE(Array)
ELSEIF (PRESENT(UpperBound)) THEN
start = 1
finish = UpperBound
ELSE
start = 1
finish = SIZE(Array)
ENDIF
! check bounds of data and set limiting values of the index
IF(Value < Array(start)) THEN
FindArrayIndex = 0
ELSE IF(Value >Array(finish)) THEN
FindArrayIndex = finish
ELSE ! start searching by bisection method
DO WHILE ((finish - start) > 1)
middle = (finish + start) / 2
IF (Value > Array(middle)) THEN
start = middle
ELSE
finish = middle
END IF
END DO
FindArrayIndex = start
END IF
RETURN
END FUNCTION FindArrayIndex