      real*8,    dimension(:),allocatable :: cw_orb
      real*8,    dimension(:),allocatable :
      real*8,    dimension(:),allocatable :: cw_exch
      real*8,    dimension(:),allocatable :: cw_suppl
      real*8,    dimension(:),allocatable :: cw_sctch
      integer*4, dimension(:),allocatable :: cw_sor
      include 'commons8.inc'
c
c     no and nons denote the number of all the orbitals and number 
c     of non sigma type orbitals, respectively. ni and mu correspond to
c     the number of grid points in ni and mu variables.

c     read input data and echo input parameters
c     open input/output files
c
      call rinputd(iform,ni,mu,no,nons)

      ni8=ni+8
      mu8=mu+8
      ngrid=ni*mu
      ngrid8    = ni8*mu8

      length1   = no*ngrid
      length2   = no*ngrid

      if     (iform.eq.1.or.iform.eq.3) then
         length3=( no*(no+1)/2+nons*(nons+1)/2 )*ngrid
      elseif (iform.eq.0.or.iform.eq.2) then
         length3 = (no+nons)*ngrid	 
      endif

c     if HFS or OED method of calculation is chosen set length3 to

      if (imethod.eq.2.or.imethod.eq.3) then
         length3 = ngrid	 
      endif

      length4   = 14*ngrid
      length5   = 10*ngrid8
      length6   = 2*ngrid8+4*ni*(mu+16)+2*maxgrids*(ni+mu)
      lexchrecl = ni*mu*8

      allocate (cw_orb(length1))
      allocate (cw_coul(length2))
      allocate (cw_exch(length3))
      allocate (cw_suppl(length4))
      allocate (cw_sctch(length5))
      allocate (cw_sor(length6))

c     zeroise arrays

      call zeroarray (cw_orb,cw_coul,cw_exch,cw_suppl,
     &     cw_sctch,cw_sor)

c     initialize arrays within common blocks, 
c     initialize arrays of variable length and check input data
c     prepare an environment for poisson's equation solving routines
c     prepare arrays determining ordering of mesh points

      call inisuppl (cw_suppl,cw_sor)

c     print out data defining the case

      call printall

c     initialize orbitals, Coulomb and exchange potentials

      call inifun (cw_orb,cw_coul,cw_exch,cw_suppl,cw_sctch)

c     perform scf

      call scf (cw_sor,cw_orb,cw_coul,cw_exch,cw_suppl,cw_sctch)


