*...:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
*    
*     pstart.f
*
*     Copyright (C) 1991.
*
*     Marie Davidian and A. Ronald Gallant 
*     P.O. Box 5513, Raleigh NC 27650-5513, USA   
*
*     Permission to use, copy, modify, and distribute this
*     software and its documentation for any purpose and
*     without fee is hereby granted, provided that the
*     above copyright notice appear in all copies and that
*     both that copyright notice and this permission notice
*     appear in supporting documentation.
*
*     This software is provided "as is" without any
*     expressed or implied warranty.
*
*...:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
      subroutine pstart(vec,lvec)
      implicit real*8 (a-h,o-z)
      implicit integer*4 (i-n)
      save

      include "global.f"

      real*8 vec
      real*8 zinc
      real*8 objf,objgrd,objmin

      integer*4 i,j
      integer*4 mode
      integer*4 izz

      real*8 pscale

      integer*4 pgrid

      parameter (pscale=2.d0)
      parameter (pgrid=5)

      dimension vec(lvec)
      dimension zinc(mM)
      dimension objgrd(mM)
      dimension izz(mM)

      if (lvec.ne.M) then
        write(3,3001)
        stop
      end if

      mode=0

      do i=1,M
        zinc(i)=pscale*dsqrt(Cz(i*(i+1)/2))/dfloat(pgrid)
      end do

      do i=1,M
        izz(i)=-pgrid
      end do
      izz(1)=izz(1)-1

      do j=1,(2*pgrid+1)**M

        do i=1,M
          if (izz(i).lt.pgrid) then
            izz(i)=izz(i)+1
            go to 10
          else
            izz(i)=-pgrid
          end if
        end do
10      continue

        do i=1,M
          z(i)=Ez(i)+dfloat(izz(i))*zinc(i)
        end do

        call post(mode,M,z,objf,objgrd,1)

        if (j.eq.1) then
          objmin=objf
          do i=1,M
            vec(i)=z(i)
          end do
        end if

        if (objf.lt.objmin) then
          objmin=objf
          do i=1,M
            vec(i)=z(i)
          end do
        end if

      end do

      return
3001  format(1x,'error, pstart, lvec doesn''t equal M')
9001  format(d30.18)
      end
