c 
c     Second Edition
c     Numerical Analysis:
c     The Mathematics of Scientific Computing
c     D.R. Kincaid & E.W. Cheney
c     Brooks/Cole Publ., 1996
c     ISBN 0-534-33892-5
c     COPYRIGHT (c) 1996
c
c     Section 4.2
c
c     Example of Forward Substitution for a permuted system
c
c
c     file: pforsub.f
c
      parameter (n=3)
      dimension a(n,n),x(n),b(n)
      integer p(n)
      data (a(1,j),j=1,n) /3.0,2.0,0.0/
      data (a(2,j),j=1,n) /4.0,2.0,1.0/
      data (a(3,j),j=1,n) /6.0,0.0,0.0/
      data (b(i),i=1,n) /5.0,7.0,6.0/
      data (p(i),i=1,n) /3,1,2/
c
      print *
      print *,' Forward Substitution for a permuted system'
      print *,' Section 4.2, Kincaid-Cheney'
      print *
c
      do 3 i=1,n
         sum = b(p(i))
         do 2 j=1,i-1
            sum = sum - a(p(i),j)*x(j)
 2       continue
         x(i) = sum/a(p(i),i)
 3     continue 
c
       do 4 i=1,n
          print 5,i,x(i)
 4     continue
c
 5     format (1x,'x(',i2,') =',2x,e13.6)
       stop
       end 
