      integer*4 cw_sor(1)
      integer
      real*8 cw_orb(1),cw_coul(1),cw_exch(1),cw_suppl(1),cw_sctch(1)
      include 'commons8.inc'

      external malloc

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
c     DEC OSF/1: get ready to allocate memory dynamically 

      pointer (p_orb,cw_orb)
      pointer (p_coul,cw_coul)
      pointer (p_exch,cw_exch)
      pointer (p_suppl,cw_suppl)
      pointer (p_sctch,cw_sctch)
      pointer (p_sor,cw_sor)

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     DEC OSF/1: dynamic allocation of memory acccording 
c     to the current case 
      
      p_orb   = malloc (8*length1)
      p_coul  = malloc (8*length2)
      p_exch  = malloc (8*length3)
      p_suppl = malloc (8*length4)
      p_sctch = malloc (8*length5)
      p_sor   = malloc (4*length6)

c     zeroise array
      
      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)




