From: dfk@col.hp.com (David F. Kurth)
Subject: Relative Humidity program
Date: Fri, 24 Jul 1992 17:05:51 GMT
Organization: HP Colorado Springs Division

BEGIN_DOC rh.doc

Here is a basic algorithm I found on a bulletin board posted by Jim
Little that calculates relative humidity given temperature and dew point
(in degrees F).  I have re-written the function for the HP48 and that 
follows below.  I've included the original here just as a point of reference.
The few tests I've done on the HP48 have given correct answers, but I'll 
leave the "original" here just in case I made a mistake.

For a checkpoint, at a temperature of 68 F and a dewpoint of 50 F,
my table says the RH is 53%.  My calculator says 52.5077...

If somebody has any insight why this function works, I'd be interested
in hearing your comments.  It surely looks like a Taylor series expansion, 
but of what?  And why the eight power?  Enjoy 

Dave Kurth
dfk@col.hp.com
Colorado Springs, CO


DECLARE FUNCTION RH! (Temp!, DewPoint!)

'$page
'***************************************************************************
'
'       This relative humidity algorithm is an adaptation of a
'       FORTRAN routine used by the National Weather Service.
'       I'm sure there are other quick and dirty methods of
'       calculating Relative Humidity but this one works and is
'       *very* accurate.
'
'       Questions or comments contact:      
'
'                               Jim Little
'                               Compuserve 72765,1431
'                               c/o KATU-TV
'                               Portland, Oregon 97232
'
'    
'***************************************************************************
FUNCTION RH (Temp, DewPoint) STATIC

      IF DewPoint > Temp THEN                 'Return -1 as error code
            RH = -1                         '   if dewpoint greater
            GOTO RelHumidEnd                '   than temperature
      END IF

      T = (Temp - 32) * 5 / 9                 'Convert to celsius
      D = (DewPoint - 32) * 5 / 9
      
      C1# = .9999968299999999#                'set constants
      C2# = -.0090826951#
      C3# = .000078736169#
      C4# = -.00000061117958#
      C5# = .0000000043884187#
      C6# = -2.9883885D-11
      C7# = 2.1874425D-13
      C8# = -1.7892321D-15
      C9# = 1.1112018D-17
      C10# = -3.0994571D-20
      
      X1# = C10#
      X1# = C9# + T * (X1#)
      X1# = C8# + T * (X1#)
      X1# = C7# + T * (X1#)
      X1# = C6# + T * (X1#)
      X1# = C5# + T * (X1#)
      X1# = C4# + T * (X1#)
      X1# = C3# + T * (X1#)
      X1# = C2# + T * (X1#)
      X1# = C1# + T * (X1#)
      X1# = X1# ^ 8

      X2# = C10#
      X2# = C9# + D * (X2#)
      X2# = C8# + D * (X2#)
      X2# = C7# + D * (X2#)
      X2# = C6# + D * (X2#)
      X2# = C5# + D * (X2#)
      X2# = C4# + D * (X2#)
      X2# = C3# + D * (X2#)
      X2# = C2# + D * (X2#)
      X2# = C1# + D * (X2#)
      X2# = X2# ^ 8



      RH = 100 * X1# / X2#                    'express results as percent

RelHumidEnd:

END FUNCTION
END_DOC

Directory rh.rpl
Checksum  # D635h
Bytes       325.5

BEGIN_RPL rh.rpl
%%HP: T(3)A(R)F(.);
DIR
  RH
    @ Convert Temperature and Dewpoint (on stack) to Relative Humidity @
    @ This relative humidity algorithm is an adaptation of a           @
    @ FORTRAN routine used by the National Weather Service.            @
    @ I'm sure there are other quick and dirty methods of              @
    @ calculating Relative Humidity but this one works and is          @
    @ *very* accurate.                                                 @
    @                                                                  @
    @ Questions or comments contact:                                   @
    @                                                                  @
    @ Jim Little                                                       @
    @ Compuserve 72765,1431                                            @
    @ c/o KATU-TV                                                      @
    @ Portland, Oregon 97232                                           @
    \<< 32 - 5 * 9 /                        @ Convert DewPoint to celsius
      SWAP 32 - 5 * 9 /                     @ Convert Temp     to celsius
      {-3.0994571E-20                       @ set Ci constants
      1.1112018E-17                         @ In original algorithm,
      -1.7892321E-15                        @ these were defined as 
      2.1874425E-13                         @ double precision.  I'm
      -2.9883885E-11                        @ just using the normal
      .0000000043884187                     @ precision of the HP48
      -.00000061117958
      .000078736169
      -.0090826951
      .9999968299999999} \-> D T C          @ DewPoint, Temp, Constants
      \<<
        0                                   @ X1 = C1*T^9 + C2*T^8 + ...
        1 10 
        FOR i
          T * C i GET +                     @ X1 = T * X1 + Ci
        NEXT

        0                                   @ X2 = C1*D^9 + C2*D^8 + ...
        1 10 
        FOR i
          D * C i GET +                     @ X2 = D * X2 + Ci
        NEXT

        / 8 ^ 100 *                         @ RH =(X1 / X2)^8 as percent
      \>>
    \>>
END
END_RPL
From: akcs.mmorgan@hpcvbbs.cv.hp.com (Mike Morgan)
Date: Sun, 26 Jul 1992 18:40:03 GMT
Subject: Re: OFF TOPIC?
Message-ID: <2a72f151.1483.1comp.sys.hp48.1@hpcvbbs.cv.hp.com>