FIXME : Add documentation
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real, | intent(in) | :: | t | |||
real, | intent(in), | dimension(n) | :: | x | ||
integer, | intent(in) | :: | n |
integer function fitp_intrvl (t,x,n)
implicit none
integer, intent(in) :: n
real, intent(in) :: t
real, dimension(n), intent(in) :: x
!
! coded by alan kaylor cline
! from fitpack -- january 26, 1987
! a curve and surface fitting package
! a product of pleasant valley software
! 8603 altus cove, austin, texas 78759, usa
!
! this function determines the index of the interval
! (determined by a given increasing sequence) in which
! a given value lies.
!
! on input--
!
! t is the given value.
!
! x is a vector of strictly increasing values.
!
! and
!
! n is the length of x (n .ge. 2).
!
! on output--
!
! intrvl returns an integer i such that
!
! i = 1 if e t .lt. x(2) ,
! i = n-1 if x(n-1) .le. t ,
! otherwise x(i) .le. t .le. x(i+1),
!
! none of the input parameters are altered.
!
!-----------------------------------------------------------
integer :: il, ih, i
real :: tt
save i
data i /1/
tt = t
!
! check for illegal i
!
if (i .ge. n) i = n/2
!
! check old interval and extremes
!
if (tt .lt. x(i)) then
if (tt .le. x(2)) then
i = 1
fitp_intrvl = 1
return
else
il = 2
ih = i
end if
else if (tt .le. x(i+1)) then
fitp_intrvl = i
return
else if (tt .ge. x(n-1)) then
i = n-1
fitp_intrvl = n-1
return
else
il = i+1
ih = n-1
end if
!
! binary search loop
!
1 i = (il+ih)/2
if (tt .lt. x(i)) then
ih = i
else if (tt .gt. x(i+1)) then
il = i+1
else
fitp_intrvl = i
return
end if
go to 1
end function fitp_intrvl