subroutine interpolate(n,v,x,m,u,logint,vnew) ! !* Interpolates vector v defined by abscissae values x onto specified ! new abscissae values u. Resulting interpolated values are in vnew ! ! INPUT: ! n..........number of values in vector v ! v..........vector of values to be interpolated ! x..........abscissae locations of values in v. Must monotomically increase ! or decrease. ! m..........number of values for interpolated vector ! u..........new abscissae values. Length of m. Must monotomically increase ! logint.....true interpolates abscissae logarithically. ! ! or decrease. Must be same direction as x. ! OUTPUT: ! vnew.......interpolated vector values corresponding to u. ! implicit none integer n,m,i,j real v(n),x(n),u(m),vnew(m),slope,dir logical logint,increase increase=.false. dir=x(2)-x(1) if(abs(dir) .eq. dir) increase=.true. do i=2,n-1 dir=x(i+1)-x(i) if(increase) then if(abs(dir) .ne. dir) then write(*,*) 'X not monotomic' stop endif else if(abs(dir) .eq. dir) then write(*,*) 'X not monotomic' stop endif endif enddo increase=.false. dir=u(2)-u(1) if(abs(dir) .eq. dir) increase=.true. do i=2,m-1 dir=u(i+1)-u(i) if(increase) then if(abs(dir) .ne. dir) then write(*,*) 'U not monotomic' stop endif else if(abs(dir) .eq. dir) then write(*,*) 'U not monotomic' stop endif endif enddo if(u(1) .lt. u(2) .and. x(1) .gt. x(2)) then write(*,*) 'X and U must increase or decrease together' write(*,*) 'U increases and X decreases' stop else if(u(1) .gt. u(2) .and. x(1) .lt. x(2)) then write(*,*) 'X and U must increase or decrease together' write(*,*) 'X increases and U decreases' stop endif if(u(1) .lt. u(2)) increase=.true. do j=1,m if((increase .and. (u(j) .lt. x(1) .or. u(j) .gt. x(n))) .or. & (.not. increase .and. & (u(j) .gt. x(1) .or. u(j) .lt. x(n)))) then write(*,*) 'Can not interpolate outside abscissa range' stop endif enddo do i=1,n-1 do j=1,m if((increase .and. (u(j).ge.x(i) .and. u(j).le.x(i+1))) .or. & (.not. increase .and. & (u(j).le.x(i) .and. u(j).ge.x(i+1)))) then if(logint) then slope=log(u(j)/x(i))/log(x(i+1)/x(i)) else slope=(u(j)-x(i))/(x(i+1)-x(i)) endif vnew(j)=v(i)+slope*(v(i+1)-v(i)) endif enddo enddo return end