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


      subroutine satcloud(nz,ncldz,lcld,t,rhcld,wh,lunc) 1,1
      parameter (tzero=273.15)
      dimension t(*),wh(*),lcld(*)
c
c purpose: modify the watervapor density inside clouds to have a
c          relative humidity of RHCLD.
c
c INPUT:
c   nz        number of atmospheric levels
c   ncldz     size cloud layer arrays
c   lcld      cloud layer array
c   t         temperature at altitude z
c   rhcld     relative humidity of cloud layer, used to specify
c             water vapor density.
c
c
c h2osat is the mass density (g/m3) of water vapor at 100% saturation
c (source: handbook of chemistry and physics, h2o vapor pressure
c table d-112, assuming density related to pressure by ideal gas law)
c
            satden(a)=a*exp(18.916758-a*(14.845878+a*2.4918766))

      if(lunc.gt.0) write(lunc,'(a/1p(10e11.3))') 'wh_in  ',
     &           (wh(i)/satden(tzero/t(i)),i=1,nz)
c
c  adjust cloud layer, don't adjust clear layers
c
      do 20 i=1,ncldz
        call levrng(ncldz,lcld,i,lbot,ltop)
        if(lbot.ne.0) then
          do 10 j=ltop,lbot
            jj=nz-j+1
            wh(jj)=rhcld*satden(tzero/t(jj))
 10       continue
        endif
 20   continue

      if(lunc.gt.0) then

        write(lunc,'(a/1p(10e11.3))') 'rh_out  ',
     &           (wh(i)/satden(tzero/t(i)),i=1,nz)
        write(lunc,'(a/1p(10e11.3))') 'wh_out  ',
     &           (wh(i),i=1,nz)
      endif

      return
      end