!******************** START FILE FLIN1_Z.FOR ; GROUP SIGS2 ********************
!==============================================================================
!
!  FLIN1_Z
!   INTERPOLATE ON A 1D ARRAY
!
SUBROUTINE FLIN1_Z(X,F,N,VTR,XMIN,XMAX,XLR,NX,IWARN)
!
! Interpolates the table VTR(NX) to find the value at x.
! If XLR>0, then the X grid is equally spaced on a logarithmic scale:
!
!   X(i) = XMIN * (exp(XLR)) ** ( (i-1)/(NX-1) )
!
!   So X(i) ranges from XMIN to XMIN*exp(XLR), and XLR=log(xmax/xmin).
!
! For XLR<=0, the X grid is equally spaced on a linear scale from
! XMIN to XMAX.
!
! Modified 7/26/00 (PCR) - vectorized.
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER n,nx,it,iwarn,ix,ixp1
!============
! idecl:  explicitize implicit REAL declarations:
  real(fp) xmin,xmax,xlr,zx,zy,zzx,zlogx
!============
  real(fp) VTR(NX)
  real(fp), DIMENSION(n) :: X,F
!
!  INTERPOLATE TO X  LOGARITHMIC SPACING IN X
!     LINEAR IF XLR .LE. 0.0
!
!
  iwarn=0
!
  do it=1,n
!
     ZX=X(it)
!
     if(zx .lt. xmin) then
        zzx=0.0_fp
     else
        IF(XLR.GT.0.0_fp) THEN
           ZLOGX=log(ZX/XMIN)
           ZZX=1.0_fp+ZLOGX/XLR * (NX-1)
        ELSE
           ZZX=1.0_fp+(ZX-XMIN)/(XMAX-XMIN) * (NX-1)
        ENDIF
     endif
!
     IX=ZZX
!
!  CHECK FOR POINT OUT OF BOUNDS OF ARRAY
     IF(IX.GE.1) GO TO 10
!
     IF(ZX.LT.(XMIN - 5.0e-7_fp)) THEN
        IWARN=1
     ENDIF
     IX=1
     ZZX=1.0_fp
!
10   CONTINUE
!
     IF(IX.LT.NX) GO TO 30
!
     IF(ZX.GT.(XMAX + 5.0e-7_fp)) THEN
        IWARN=1
     ENDIF
     IX=NX-1
     ZZX=NX
!
!---------------------------
!  OK
!
30   CONTINUE
!
     IXP1=IX+1
     ZZX=ZZX-IX
!
!  INTERPOLATE
!
     F(it)=(1.0_fp-ZZX)*VTR(IX)+ZZX*VTR(IXP1)
!
  enddo
!
!
END SUBROUTINE FLIN1_Z
!
!******************** END FILE FLIN1.FOR ; GROUP SIGS2 ************************
! 26Jul2000 fgtok -s r8_precision.sub "r8con.csh conversion"
