
          subroutine wetbulbcal(tc,pmb,tdc,twbsave,xmin)


          a0=6.107799961
          a1=4.436518521e-1
          a2=1.428945805e-2
          a3=2.650648471e-4
          a4=3.031240396e-6
          a5=2.034080948e-8
          a6=6.136820929e-11
 
          xlv0=2.501e6
          cpv=1850.
          cpd=1005.
          cw=4218.
          eps=0.622

          xlv=xlv0+(cpv-cw)*tc
          constant=cpd*pmb/(eps*xlv)

          emb=a0+tdc*(a1+tdc*(a2+tdc*(a3+
     *    tdc*(a4+tdc*(a5+tdc*a6))))) 

          esmb=a0+tc*(a1+tc*(a2+tc*(a3+
     *    tdc*(a4+tc*(a5+tc*a6))))) 
          rh=100.*emb/esmb

          xmin=10.
          twb=tc
          twbsave=999.


          do k=1,10000
          ewb=a0+twb*(a1+twb*(a2+twb*(a3+
     *    twb*(a4+twb*(a5+twb*a6))))) 

          rhside=ewb-constant*(tc-twb)
          dif=abs(emb-rhside)
          if(dif.lt.xmin)twbsave=twb
          if(dif.lt.xmin)xmin=dif
c         print*,constant,twb,rhside,emb,twbsave,dif
          twb=twb-0.01
          enddo

          return
          end

          
