    use precision
    use io
    use ferror
    implicit none
    real(D),parameter::ZERO=0.0
    real(D),allocatable::a(:,:),z(:,:),mu(:),lambda(:),work(:)
    integer,allocatable::newseed(:),iwork(:),isuppz(:)
    real(D)::abstol
    character(80)::arg
    integer,external::iargc
    integer::j,k,n,sz,info,nfound
!
    if(iargc().eq.0) call fexit('asize [seed]',2)
    call random_seed(size=sz)
    allocate(newseed(sz))
    if(iargc().eq.sz+1) then
       do j=1,sz
          call getarg(j+1,arg)
          read(arg,*) newseed(j)
       enddo
    else
       call random_seed(get=newseed)
    endif
    write(LOGFILE,100) newseed
100 format('seed: ',4i11)
!
    call getarg(1,arg)
    read(arg,*) n
    allocate(a(n,n),z(n,n),mu(n),work(70*n),lambda(n))
    allocate(iwork(10*n),isuppz(2*n))
    if(iargc().eq.2) then
       call getarg(2,arg)
       read(arg,*) newseed
    endif
!
!  Create a random symmetric matrix A
!
    call random_number(a)
    do k=1,n-1
       do j=k+1,n
          a(j,k)=a(k,j)
       enddo
    enddo
!
!  Compute eigenvalues and eigenvectors as in assim.f90
!
    abstol=2.0*tiny(a)
    call dsyevr('v','i','u',n,a,n,ZERO,ZERO,1,n, &
       abstol,nfound,mu,z,n,isuppz,work,size(work),iwork,size(iwork),info)
    if(info.lt.0) then   ! bad argument - definitely a bug in caller
       call fabort('testev: bad call to dsyevr')
    else if(info.gt.0) then  !internal error in dsyevr
       nfound=0
    else
       do j=1,nfound
          lambda(j)=mu(nfound-j+1)
          !! a(:,j)=z(:,nfound-j+1)
       enddo
    endif
    write(LOGFILE,110) info,nfound
110 format('info: ',i0,' nfound: ',i0)
    write(LOGFILE,111) lambda(1:nfound)
111 format('eigenvalues:'/(5es14.4))
    stop
    end
