cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 
c Gregor von Laszewski * North East Parallel Architectures Center
c                      * Center for Computational Science, Syracuse University
c                      * 111 College Place * Syracuse, NY 13244-4100
c                      * (315) 443-4883 * gregor@npac.syr.edu 
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

C
C     ReadMatrix (A,x,y)         -- reads  Matrix A[x,y]
C     ReadVector (B,y)           -- reads  Vector B[y]
C     PrintMatrix (A,x,y,Name)   -- prints Matrix A[x,y] and Name
C     PrintVector (B,y,Name)     -- prints Vector B[y] and Name
C     InitEquation (A,B,n,file)  -- Initialize A,B
C     RandomVector(B,n,vmax)     -- generate a random vector
C                                   values are smaler than vmax 
C     RandomMatrix (A,x,y,vmax)  -- generate a random matrix
C                                   values are smaler than vmax 
C     -----------------------------------------------------------
C     -----------------------------------------------------------
        subroutine ReadMatrix (A,LDA,x,y)
C
C         reads in the matrix A with the dimension x and y
C        
        real A(LDA, *)
        integer i,j,x,y,LDA

        read (*,*) x, y 
        read (*,*) (( A(i,j),  j=1,y), i=1,x) 
c        read (*,*) (( A(i,j), i=1,y), j=1,x)
        
C       end subroutine ReadMatrix
        end


C     -----------------------------------------------------------
        subroutine ReadVector (B,y)
C
C         reads in the vector B with the dimension y
C        
        real B(*)
        integer y,j

        read (*,*) y 
        read (*,*) (B(j), j=1,y) 
        
C       end subroutine ReadVector
        end

C     -----------------------------------------------------------
        subroutine PrintMatrix (A,x,y,LDA,Name, proc)
C
C         prints the matrix A with the dimension x and y and 
C                                      name Name
C        
        real A(LDA, *)
        integer LDA,x,y,proc,i,j
        character*8 Name

        write(*,*) proc,':',x,'x',y,' Matrix: ', Name        
        do i=1,x
           write (*,101) proc, i, ( A(i,j), j=1,y)
c 101       format ( I6, ':', 25 F7.3 )
 101       format ( I3, I2, ':', 25 F6.2 )
        end do

C       end subroutine PrintMatrix
        end
C     -----------------------------------------------------------
        subroutine PrintIMatrix (A,x,y,LDA,Name, proc)
C
C         prints the matrix A with the dimension x and y and 
C                                      name Name
C        
        real A(LDA, *)
        integer LDA,x,y,proc,i,j
        character*8 Name

        write(*,*) proc,':',x,'x',y,' Matrix: ', Name        
        do i=1,x
           write (*,101) proc, ( A(i,j), j=1,y)
 101       format ( I6, ':', 25 I4 )
        end do

C       end subroutine PrintMatrix
        end
C     -----------------------------------------------------------
        subroutine PrintFMatrix (A,x,y,LDA,Name, proc)
C
C         prints the matrix A with the dimension x and y and 
C                                      name Name
C        
        real A(LDA, *)
        integer LDA,x,y,proc,i,j
        character*8 Name

        write(*,*) proc,':',x,'x',y,' Matrix: ', Name        
        do i=1,x
           write (*,101) proc, ( A(i,j), j=1,y)
 101       format ( I6, ':', 25 F10.3 )
        end do

C       end subroutine PrintMatrix
        end




        subroutine PrintTIVector (B,y,Name,proc)
C
C         prints the vector B with the dimension y and 
C                                      name Name
C        
        integer B(*)
        integer y,proc,J
        character*10 Name


        write(*,*) proc,': ',y,' Vector: ', Name        
        write (*,101) proc, ( B(j), j=1,y)
 101    format ( I6, ':', 25 I3 )


        return
        end
        subroutine PrintTVector (B,y,Name,proc)
C
C         prints the vector B with the dimension y and 
C                                      name Name
C        
        real B(*)
        integer y,proc,J
        character*10 Name


        write(*,*) proc,': ',y,' Vector: ', Name        
        write (*,101) proc, ( B(j), j=1,y)
 101    format ( I6, ':', 25 F10.3 )


        return
        end

C     -----------------------------------------------------------
        subroutine PrintVector (B,y,Name)
C
C         prints the vector B with the dimension y and 
C                                      name Name
C        
        real B(*)
        integer y,J
        character*10 Name

        write(*,*) y,' Vector: ', Name
        do j=1,y
           call WriteReal (B(j))
        end do

C       end subroutine PrintVector
        end

C     -----------------------------------------------------------
        subroutine PrintIVector (B,y,Name)
C
C         prints the vector B with the dimension y and 
C                                      name Name
C        
        integer B(*)
        integer y,j
        character*10 Name

        write(*,*) y,' Vector: ', Name 
        do j=1,y
           call WriteInt (B(j))
        end do

C       end subroutine PrintVector
        end

C     -----------------------------------------------------------
        subroutine RandomVector (B,n,vmax)
C
C         generates a random vector B with the dimension n
C        
c       does not run!!!!

        real B(*)
        integer vmax,n,h,j
        external irandom
        
        do j=1,n
c           h = irandom(vmax)	
           B(j) = h + 1.0
        end do

C       end subroutine RandomVector
        end


C     -----------------------------------------------------------
        subroutine RandomMatrix (A,x,y,LDA, vmax)
C
C         generates a random matrix A with the dimension x and y. 
C         each entry in the matrix is between 1 and max  
C	                                    0 < aij < max
C        
        real A(LDA, *)
        integer x,y,vmax,i,j,LDA
        external irandom

        do i=1,x
	  do j=1,y
c             A(i,j) = irandom(vmax)  + 1.0
          end do	
        end do

C       end subroutine RandomMatrix
        end

C     -----------------------------------------------------------
        subroutine InitEquation (A,B,n,LDA,fromfile)
C
C         initialize the matrix A and vector B
C         with data either  from file   (fromfile = 1)
C                   or      random      (fromfile = 0)
C
        real A(LDA, *)
        real B(*)
        integer n, fromfile,LDA

	if (fromfile .eq. 1) then
           call ReadMatrix (A,LDA,n,n)	
           call ReadVector (B,n)
        else
           print *, 'N: '
           read *,n
           call RandomMatrix(A,n,n,LDA,n)
           call RandomVector(B,n, n)
        end if
        
C       end subroutine InitEquation
        end

        subroutine WriteReal (x)
        real x
        
        write (*,10) x
 10     format ( F7.3 )

        end

        subroutine WriteInt (x)
        integer x
        
        write (*,20) x
 20     format (I5)

        end

        subroutine PrintTime (timearray)
        real timearray(2)

	write (*, 101) '   User    time: ', timearray(1)
	write (*, 101) ' + System  time: ', timearray(2)
	print *, '------------------------------------'
	write (*, 101) '   Elapsed time: ', timearray(1) + timearray(2)
 101    format ( A20,  F10.7 )
        end


      subroutine UnityMatrix (A, LDA, n)

      integer LDA, n      
      real a (LDA, *)

      integer i
      call ZeroMatrix (A, LDA, n)
      do i=1,n
         a(i,i) = 1.0
      end do
      
      return
      end

      subroutine ZeroMatrix (A, LDA, n)
      
      integer LDA, n
      real a (LDA, *)


      integer i,j
      do i=1,n
         do j=1,n
            a(i,j) = 0.0
         end do
      end do
      
      return
      end


      subroutine OneMatrix (A, LDA, n)
      
      integer LDA, n
      real a (LDA, *)


      integer i,j
      do i=1,n
         do j=1,n
            a(i,j) = 9.0
         end do
      end do
      
      return
      end




      subroutine CopyMatrix (A, B, n, LDA)

      integer n,LDA,i,j
      real A(LDA, *)
      real B(LDA, *)

      do i=1,n
         do j=1,n
            b(i,j) = a(i,j)
         end do
      end do

c     end subroutine CopyMatrix
      end

      subroutine CopyVector (A, B, n)

      integer n,i
      real A(*)
      real B(*)

      do i=1,n
            b(i) = a(i)
      end do

c     end subroutine CopyMatrix
      end

