       subroutine cvals1(nx,tabx,tabc,xi,ci,cxi,cxxi)
       
c***********************************************************************
c      CVALS1.FOR
c      (1D) Interpolation of sound speed and its derivatives.
c      Faro, 22/12/2009 at 15:30
c      Written by Orlando Camargo Rodriguez
c****&******************************************************************

c      Define local variables:

       integer*4 i, nx

       real*8 tabx(nx),tabc(nx)
       real*8 xc(4),fc(4)
       real*8 xp(3),fp(3)
       real*8 xl(2),fl(2)
       real*8 xi,ci,cxi,cxxi
       
c-----------------------------------------------------------------------

       if (xi.lt.tabx(2)) then
       
       xl(1) = tabx(1)
       xl(2) = tabx(2)
       
       fl(1) = tabc(1)
       fl(2) = tabc(2)
       
       call lini1d(xl,fl,xi,ci,cxi)

       cxxi = 0.0 
       
       elseif (xi.ge.tabx(nx-1)) then
       
       xl(1) = tabx(nx-1)
       xl(2) = tabx( nx )
       
       fl(1) = tabc(nx-1)
       fl(2) = tabc( nx )
       
       call lini1d(xl,fl,xi,ci,cxi)
       
       cxxi = 0.0
       
       elseif ((xi.ge.tabx(2)).and.(xi.lt.tabx(3))) then
       
       xp(1) = tabx(1)
       xp(2) = tabx(2)
       xp(3) = tabx(3)
       
       fp(1) = tabc(1)
       fp(2) = tabc(2)
       fp(3) = tabc(3)
       
       call bpai1d(xp,fp,xi,ci,cxi,cxxi)
       
       else if ((xi.ge.tabx(nx-2)).and.(xi.lt.tabx(nx-1))) then
       
       xp(1) = tabx(nx-2)
       xp(2) = tabx(nx-1)
       xp(3) = tabx( nx )
       
       fp(1) = tabc(nx-2)
       fp(2) = tabc(nx-1)
       fp(3) = tabc( nx )
       
       call bpai1d(xp,fp,xi,ci,cxi,cxxi)

       else 
       
       call brcket(nx,tabx,xi,i)

       xc(1) = tabx(i-1)
       xc(2) = tabx( i )
       xc(3) = tabx(i+1)
       xc(4) = tabx(i+2)
       
       fc(1) = tabc(i-1)
       fc(2) = tabc( i )
       fc(3) = tabc(i+1)
       fc(4) = tabc(i+2)
       
       call bcui1d(xc,fc,xi,ci,cxi,cxxi)

       end if

c-----------------------------------------------------------------------

c***********************************************************************
c     Back to main:
c***********************************************************************

       return

       end
