      integer*4 cw_orb_add,cw_coul_add,cw_exch_add,cw_suppl_add,
     &          cw_sctch_add,cw_sor_add

      include 'commons8.inc'

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

      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

c     dynamic allocation of memory acccording to the current case 

      call fmalloc (cw_orb_add,  8*length1)
      call fmalloc (cw_coul_add, 8*length2)
      call fmalloc (cw_exch_add, 8*length3)
      call fmalloc (cw_suppl_add,8*length4)
      call fmalloc (cw_sctch_add,8*length5)
      call fmalloc (cw_sor_add,  4*length6)

c     zeroise arrays

      call zeroarray (%val(cw_orb_add),%val(cw_coul_add),
     &     %val(cw_exch_add),%val(cw_suppl_add),
     &     %val(cw_sctch_add),%val(cw_sor_add))

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 (%val(cw_suppl_add),%val(cw_sor_add))

c     print out data defining the case

      call printall

c     initialize orbitals, Coulomb and exchange potentials

      call inifun (%val(cw_orb_add),%val(cw_coul_add),
     &     %val(cw_exch_add),%val(cw_suppl_add),
     &     %val(cw_sctch_add))

c  perform scf

      call  scf (%val(cw_sor_add),%val(cw_orb_add),
     &     %val(cw_coul_add),%val(cw_exch_add),
     &     %val(cw_suppl_add),%val(cw_sctch_add))




