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

  function f = trib(a,b,c,f,nl,nu)

%$$$c         forward elimination sweep
  
    x(nl)=c(nl)/b(nl);
    f(nl)=f(nl)/b(nl);
    nlp1 = nl +1;
    for j=nlp1:nu
      z=1./(b(j)-a(j)*x(j-1));
      x(j)=c(j)*z;
      f(j)=(f(j)-a(j)*f(j-1))*z;
    end

%$$$ c         backward elimination pass

    nupnl=nu+nl;
    for j1=nlp1:nu
      j=nupnl-j1;
      f(j)=f(j)-x(j)*f(j+1);
    end
    
  end