********************************************************************************
*                                                                              * 
*  2DHF version 1-2003                                                         *
*  Copyright (C) 1996  Jacek Kobus, Leif Laaksonen, Dage Sundholm              *
*                                                                              *
*  This software may be used and distributed according to the terms            *
*  of the GNU General Public License, see README and COPYING.                  *
*                                                                              *
********************************************************************************
c ### tail ####
c
      subroutine tail (psi)
      implicit integer*4 (i-n)
      implicit real*8 (a-h,o-z)
c
      include 'commons8.inc'
      dimension psi(*)

c     examine the tails of all orbitals and determine location of the last
c     maximum (in mi variable), i.e.

c     f(max)=max{vmax(1),vmax(2),...,vmax(nni)}

c     and the maximum value of psi at the last mi=nmi grid line

      do iorb=1,norb
         ibeg=i1b(iorb)-1
         vpmax=-1.d30
         imaxg =0
         
         vpmax=-1.d30
         do ini=1,nni
            ijk=(mxnmu-1)*nni+ini
	    vp=abs(psi(ibeg+ijk))
	    if (vp.gt.vpmax) then
               vpmax=vp
               inimax=ini
            endif
         enddo 
         write(*,5110) 'tail: ',iorb,inimax,vpmax
      enddo

 5000 continue
      
 5100 format('   orbital     ni    max{psi(ni,mxnmui)}    ')
 5110 format(1x,a10,2i5,2x,d12.2)
      return
      end
