subroutine Agen(n,Ag, job)

real(8) Ag(n,n)
character(20) job
real(8) alpha/1D-10/
real(8), allocatable :: c(:,:), b(:,:), d(:,:)

character(100) fname_2


Job_If: &
IF(job =='0') THEN
ag(1,1) =1
ag(1,2) =-sqrt(2.)/2
ag(1,3)=0

ag(2,1) =ag(1,2)
ag(2,2) =1.5
ag(2,3) =-2/sqrt(5.)

ag(3,1) =0
ag(3,2) =ag(2,3)
ag(3,3) =2.4

ELSEIF(job =='wilk12')	THEN	! Wilkinson (Ex.: n=12):
ag =0D0
!
do i = 1, n
	do j = 1, n

	if ( j <= i+1 ) then
	ag(j,i) = n+1 -max (i,j)
	endif

   enddo
enddo


ELSEIF(job(1:6) =='wilk20') THEN

ag =0D0

do i =1,n
ag(i,i) =dfloat(i)

if(i <=n-1) ag(i,i+1) =dfloat(n)
enddo

!*  
if(job(7:7) =='a') then
ag(n,1) = alpha
endif


ELSEIF(job =='parlett') THEN		! PARLETT:
ag =0D0

do i = 1, n
	do j = 1, n
	if ( i < j ) then
		if ( i == 1 .and. j == 2 ) then
        ag(i,j) = 40.D0 / 102.D0
        else if ( i == 1 .and. j == 100 ) then
        ag(i,j) = 40.D0
        else
        ag(i,j) = 0.D0
        end if

	else if ( i == j ) then
        ag(i,j) = 101.D0 - dfloat(i)

    else if ( i > j ) then
        ag(i,j) = ( - 1.D0 )**(i+j+1) * 40.D0 / dfloat ( i + j - 2 )
    end if

    end do
end do

!a=transpose(a)
ELSEIF(job =='lotkin') THEN
ag =0D0

ag(1, 1:n) =1

do i=2,n
	do j=1,n
	ag(i,j) =1D0/dfloat(i+j-1)
	enddo
enddo

ELSEIF(job =='ebe16') THEN
allocate(c(4,4), b(8,8))
c(1,1) =-2; c(1,2:4) =2;
c(2,1) =-3; c(2,2) =3; c(2,3:4) =2;
c(3,1) =-2; c(3,2) =0; c(3,3) =4; c(3,4) =2;
c(4,1) =-1; c(4,2:3) =0; c(4,4) =5

b(1:4,1:4) =5*c; b(1:4,5:8) =-c;
b(5:8,1:4) =5*c; b(5:8,5:8) =c;

ag(1:8,1:8) =b; ag(1:8,9:16) =2*b;
ag(9:16,1:8) =4*b; ag(9:16,9:16) =3*b;

ELSEIF(job =='ebe40') THEN
allocate(d(5,5), c(10,10), b(20,20))
d =0.
d(1:5,1) =-1; d(1,2) =1.; d(2,3) =1.; d(3,4) =1.; d(4,5) =1.;

c(1:5,1:5) =4*d; c(1:5,6:10) =3*d;
c(6:10,1:5) =-2*d; c(6:10,6:10) =-d;

b(1:10,1:10) =c; b(1:10,11:20) =2*c;
b(11:20,1:20) =4*c; b(11:20,11:20) =3*c;

ag(1:20,1:20) =8*b; ag(1:20, 21:40) =4*b;
ag(21:40,1:20) =-5*b; ag(21:40, 21:40) =-b;

ELSEIF(job(1:3) =='tol') THEN
ag =0D0

fname_2 ='tols90.txt'
open(2, file =fname_2, status ='old', form ='formatted')
read(2,*) title_2
40 read(2,*, err =50, end =50) i, j, ag(i,j)
goto 40
close(2)

50 continue

ELSEIF(job(1:4) =='fida') THEN
ag =0D0

fname_2 ='fida5.txt'
open(2, file =fname_2, status ='old', form ='formatted')
read(2,*) title_2
41 read(2,*, err =51, end =51) i, j, ag(i,j)
goto 41
close(2)

51 continue

ELSEIF(job(1:7) =='Clement' .or. job(1:7) =='clement') THEN
ag =0D0

  do i = 1, n
    do j = 1, n
      if ( j == i+1 ) then
        ag(i,j) = real ( i )
      else if ( j == i-1 ) then
        ag(i,j) = real ( n - j )
      else
        ag(i,j) = 0.0E+00
      end if
    end do
  end do

ELSE

ENDIF Job_If


END

!
!=============================
! POISSON matrix:
!  Formula:
!
!    If ( I = J )
!      A(I,J) = 4.0E+00
!    Else If ( I = J+1 or I = J-1 or I = J+NROW or I = J-NROW )
!      A(I,J) = -1.0E+00
!    Else
!      A(I,J) = 0.0E+00
!
!  Example:
!
!    NROW = NCOL = 3
!
!     4 -1  0 | -1  0  0 |  0  0  0
!    -1  4 -1 |  0 -1  0 |  0  0  0
!     0 -1  4 |  0  0 -1 |  0  0  0
!     ----------------------------
!    -1  0  0 |  4 -1  0 | -1  0  0
!     0 -1  0 | -1  4 -1 |  0 -1  0
!     0  0 -1 |  0 -1  4 |  0  0 -1
!     ----------------------------
!     0  0  0 | -1  0  0 |  4 -1  0
!     0  0  0 |  0 -1  0 | -1  4 -1
!     0  0  0 |  0  0 -1 |  0 -1  4
!
!    A has eigenvalues
!
!      LAMBDA(I,J) = 4 - 2 * COS(I*PI/(N+1))
!                      - 2 * COS(J*PI/(M+1)), I = 1 to N, J = 1 to M.

! n =9:
!=======================================================
!! WILK20 returns the 20 by 20 Wilkinson example.
!
!
!  Formula:
!
!    if ( I = J )
!      A(I,J) = I
!    else if ( I = J-1 )
!      A(I,J) = 20
!    else if ( I = N, J = 1 ) then
!      A(I,J) = ALPHA
!    else
!      A(I,J) = 0
!
!  Example:
!
!    1 20  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
!    .  2 20  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
!    .  .  3 20  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
!    .  .  .  4 20  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
!    .  .  .  .  5 20  .  .  .  .  .  .  .  .  .  .  .  .  .  .
!    .  .  .  .  .  6 20  .  .  .  .  .  .  .  .  .  .  .  .  .
!    .  .  .  .  .  .  7 20  .  .  .  .  .  .  .  .  .  .  .  .
!    .  .  .  .  .  .  .  8 20  .  .  .  .  .  .  .  .  .  .  .
!    .  .  .  .  .  .  .  .  9 20  .  .  .  .  .  .  .  .  .  .
!    .  .  .  .  .  .  .  .  . 10 20  .  .  .  .  .  .  .  .  .
!    .  .  .  .  .  .  .  .  .  . 11 20  .  .  .  .  .  .  .  .
!    .  .  .  .  .  .  .  .  .  .  . 12 20  .  .  .  .  .  .  .
!    .  .  .  .  .  .  .  .  .  .  .  . 13 20  .  .  .  .  .  .
!    .  .  .  .  .  .  .  .  .  .  .  .  . 14 20  .  .  .  .  .
!    .  .  .  .  .  .  .  .  .  .  .  .  .  . 15 20  .  .  .  .
!    .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 16 20  .  .  .
!    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 17 20  .  .
!    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 18 20  .
!    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 19 20
!  ALPHA.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 20
!
!  Properties:
!
!    A is generally not symmetric: A' /= A.
!
!    If ALPHA = 0, then
!
!      LAMBDA(I) = i
!
!    and the characteristic equation is
!
!      product ( 1 <= I <= 20 ) ( I - LAMBDA ) = 0
!
!    and the condition number of eigenvalue I is
!
!      COND(LAMBDA(I)) = (20-I)! * (I-1)! / 20**19.
!
!    If ALPHA is nonzero, the characteristic equation is
!
!      product ( 1 <= I <= 20 ) ( I - LAMBDA ) = 20**19 * ALPHA.
!
!    If ALPHA = 1.0E-10, there are 6 real eigenvalues, and 14 complex
!    eigenvalues with considerable imaginary parts.
!
!  Reference:
!
!    Robert Gregory and David Karney,
!    Example 5.23,
!    A Collection of Matrices for Testing Computational Algorithms,
!    Wiley, New York, 1969, page 104, QA263 G862.
!
!    Joan Westlake,
!    Test Matrix A40,
!    A Handbook of Numerical Matrix Inversion and Solution of Linear Equations,
!    John Wiley, 1968.
!
!    J H Wilkinson,
!    Rounding Errors in Algebraic Processes,
!    Prentice Hall, 1963,
!    page 138.
!
!  Modified:
!
!    15 April 1999
!
!  Author:
!
!    John Burkardt
!
!  Parameters:
!
!    Input, real ALPHA, the perturbation.
!
!    Output, real A(20,20), the matrix.
!