C+ C NAME: C ArrR8Interpolate C PURPOSE: C Interpolate on 1-dim double precision array. C CALLING SEQUENCE: double precision function ArrR8Interpolate(N,A,X) C INPUTS: C N integer # points in array C A(N) double precision Array of function values C X double precision Function value where interpolated position is needed C OUTPUTS: C ArrR8Interpolate C double precision interpolated index in [1,N] C A BadR4 value is returned if X lies outside the C range of input array A. C CALLS: C BadR8 C RESTRICTIONS: C A must be a monotonically increasing array. C PROCEDURE: C For given X the pair of indices I-1 and I are located C where A(I-1) < X <= A(I). Then a linear interpolation between these C two points gives the return floating point index. C MODIFICATION HISTORY: C OCT-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- integer N double precision A(*) double precision X double precision BadR8 if (A(1) .le. X .and. X .le. A(N)) then I = 1 do while (I .le. N .and. X .gt. A(I)) I = I+1 end do ArrR8Interpolate = dble(I) if (I .ne. 1) ArrR8Interpolate = ArrR8Interpolate-(X-A(I))/(A(I-1)-A(I)) else ArrR8Interpolate = BadR8() end if return end