      subroutine eigen_2x2(amat,eval,evct) ! bernd berg aug 7 1999.
c real eigenvalues eval and eigenvectors evct of the amat 2x2 matrix.
c evct returns the eigenvectors stored column-wise. 
c amat is unchanged on exit.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension amat(2,2),eval(2),evct(2,2)
      phalf=-half*(amat(1,1)+amat(2,2))
      q=amat(1,1)*amat(2,2)-amat(1,2)*amat(2,1)
      arg=phalf**2-q
      if(arg.lt.0) then
        print*,"eigen_2x2 cannot be used. eigenvalues are complex!" 
        stop   "eigen_2x2 cannot be used. eigenvalues are complex!" 
      end if
      eval(1)=-phalf+sqrt(arg) ! lambda_1/2=-p/2 +/- sqrt((p/2)**2-q).
      eval(2)=-phalf-sqrt(arg)
c eigenvectors:
      eps=em10
      do i=1,2
        deno1=eval(i)-amat(1,1)
        abs1=abs(deno1)
        deno2=eval(i)-amat(2,2)
        abs2=abs(deno2)
        if(abs1.gt.abs2) then
          if(abs1.eq.eps) then
            go to 1
          else
            factor=amat(1,2)/deno1
            evct(2,i)=one/sqrt(one+factor**2) 
            evct(1,i)=factor*evct(2,i)
          end if
        else
          if(abs2.eq.eps) then
            go to 1
          else
            factor=amat(2,1)/deno2
            evct(1,i)=one/sqrt(one+factor**2) 
            evct(2,i)=factor*evct(1,i)
          end if
        end if
      end do
      return
1     continue 
        evct(1,1)=one
        evct(2,1)=zero 
        evct(1,2)=zero
        evct(2,1)=one
      return
      end
