subroutine tridag(a,b,c,d,n,ierr) implicit double precision (a-h,o-z) dimension a(1),b(1),c(1),d(1),g(1000) ierr = 0 if(b(1) .eq. 0.d0) then ierr = 1 return end if bet = b(1) d(1) = d(1)/bet do j = 2, n g(j) = c(j-1)/bet bet = b(j)-a(j)*g(j) if(bet .eq. 0.d0) then ierr = 1 return end if d(j) = (d(j)-a(j)*d(j-1))/bet end do do j = n-1, 1, -1 d(j) = d(j)-g(j+1)*d(j+1) end do return end