c=========================================================================

      subroutine elevate(nz,z,p,t,wh,wo,zsurf),1

c     module:    elevate
c
c     purpose:   change surface altitude of model atmosphere if the new
c                altitude of the surface is between the two points
c                original in the original atmospheric grid, values for
c                that altitude are obtained by interpolation.  Thus the
c                grid spacing of of the lowest layer may be made
c                smaller. All points above the surface grid are
c                renumbered.
c                
c
c     input:
c       zsurf    altitude of the surface layer.  
c
c     input/output:
c       nz       input as number of vertical grid points in orginal
c                atmosphere, set to NGRID on output 
c
c       z        input:  original vertical position of grid points
c                output: regrided or renumbered vertical positions
c
c       p        pressure at height z
c       t        temperature at heigth z
c       wh       water vapor density at height z
c       wo       ozone density at height z
c
c       
c
      dimension z(*),p(*),t(*),wh(*),wo(*)             
      parameter (mxly=50)
      parameter (eps=.001)
      dimension zz(mxly),pp(mxly),tt(mxly),whh(mxly),woo(mxly)

     
      call locate(z,nz,zsurf,kz)
      dist1=zsurf-z(kz)
      dist2=z(kz+1)-zsurf
      dist=z(kz+1)-z(kz)
      if(dist1.lt.eps*dist) then
        zz(1)=z(kz)
        fz=0.
        ks=kz+1
      elseif(dist2.lt.eps*dist) then 
        zz(1)=z(kz+1)
        fz=1.
        ks=kz+2
      else
        zz(1)=zsurf
        fz=(zsurf-z(kz))/(        ks=kz+1
      endif
      pp(1)  =  p(kz)  * (      tt(1)  =  t(kz)  * (1.-fz) + t(kz+1)  * fz
      whh(1) =  wh(kz) * (1.-fz) + wh(kz+1) * fz
      woo(1) =  wo(kz) * (1.-fz) + wo(kz+1) * fz

      i=1
      do 30 j=ks,nz
        i=i+1
        zz(i)=z(j)
        pp(i)=p(j)
        tt(i)=t(j)
        whh(i)=wh(j)
        woo(i)=wo(j)
 30   continue

      nz=i

      do 40 i=1,nz
        z(i)=zz(i)
        p(i)=pp(i)
        t(i)=tt(i)
        wh(i)=whh(i)
        wo(i)=woo(i)
 40   continue


      return
      end