%$$$ C***********************************************************************
%$$$ C*************** SCALAR PERIODIC TRIDIAGONAL ***************************
%$$$ C***********************************************************************
%$$$ 
%$$$ C     Thomas H. Pulliam
%$$$ C     NASA Ames Research Center
%$$$ C     Copyright 1992 

  function f = trip(jdim,a,b,c,f,q,s,nl,nu)

    ja = nl + 1;
    fn = f(nu);

%$$$c         forward elimination sweep

    q(nl) = -c(nl)/b(nl);
    f(nl) = f(nl)/b(nl);
    s(nl) = - a(nl)/b(nl);
    for j=ja:nu
      p =1./( b(j) + a(j)*q(j-1));
      q(j) = - c(j)*p;
      f(j) = ( f(j) - a(j)*f(j-1))*p;
      s(j) = - a(j)*s(j-1)*p;
    end

%$$$ c         backward pass

    jj = nl + nu;
    q(nu) = 0.;
    s(nu) = 1.;
    for i=ja:nu
      j = jj - i;
      s(j) = s(j) + q(j)*s(j+1);
      q(j) = f(j) + q(j)*q(j+1);
    end

    f(nu) = ( fn - c(nu)*q(nl) - a(nu)*q(nu-1))/(c(nu)*s(nl) + ...
	a(nu)*s(nu-1)  +b(nu));

%$$$ c         backward elimination pass

    for i=ja:nu
      j = jj -i;
      f(j) = f(nu)*s(j) + q(j);
    end

  end
  
