
      subroutine htint(gcmin,gcmht,loght,hts,nhts,kmx,gcmout,
     +  spval,ier)
c
      dimension gcmin(kmx),gcmht(kmx),hts(nhts),gcmout(nhts)
c
c Find min,max of gcm heights:
      htmin = 1.e36
      htmax = -1.e36
      do k=1,kmx
        if (gcmht(k).lt.htmin) htmin = gcmht(k)        
        if (gcmht(k).gt.htmax) htmax = gcmht(k)        
      enddo
c
c Height loop:
      do ih=1,nhts
        if (hts(ih).gt.htmax.or.hts(ih).lt.htmin) then
          gcmout(ih) = spval
          goto 100
        endif
c
c Bracket desired height:
c     subroutine bracket(x,xx,nx,inc,n1,n2,ier)
c
        call bracket(hts(ih),gcmht,kmx,1,iht0,iht1,ier)
        if (ier.ne.0) then
          write(6,"('>>> htscale error ',i3,' from bracket for ht=',
     +      f9.3)") hts(ih)
          stop 'hts'
        endif
c
c Log interpolation:
        if (loght.eq.1) then
          exparg = (alog(gcmin(iht1) / gcmin(iht0)) /
     +             (gcmht(iht1)-gcmht(iht0))) * (hts(ih)-gcmht(iht0))
          gcmout(ih) = gcmin(iht0)*exp(exparg)
        else
          f1 = (hts(ih)-gcmht(iht0)) /
     +         (gcmht(iht1)-gcmht(iht0))
          gcmout(ih) = f1*gcmin(iht1)+(1.-f1)*gcmin(iht0)
        endif
 100    continue
      enddo

      return
      end
