home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / hp48 / 4010 < prev    next >
Encoding:
Text File  |  1992-07-24  |  5.3 KB  |  157 lines

  1. Newsgroups: comp.sys.hp48
  2. Path: sparky!uunet!caen!sdd.hp.com!hp-col!dfk
  3. From: dfk@col.hp.com (David F. Kurth)
  4. Subject: Relative Humidity program
  5. Sender: news@col.hp.com (Usenet News)
  6. Message-ID: <1992Jul24.170551.1138@col.hp.com>
  7. Date: Fri, 24 Jul 1992 17:05:51 GMT
  8. Organization: HP Colorado Springs Division
  9. Lines: 146
  10.  
  11. BEGIN_DOC rh.doc
  12.  
  13. Here is a basic algorithm I found on a bulletin board posted by Jim
  14. Little that calculates relative humidity given temperature and dew point
  15. (in degrees F).  I have re-written the function for the HP48 and that 
  16. follows below.  I've included the original here just as a point of reference.
  17. The few tests I've done on the HP48 have given correct answers, but I'll 
  18. leave the "original" here just in case I made a mistake.
  19.  
  20. For a checkpoint, at a temperature of 68 F and a dewpoint of 50 F,
  21. my table says the RH is 53%.  My calculator says 52.5077...
  22.  
  23. If somebody has any insight why this function works, I'd be interested
  24. in hearing your comments.  It surely looks like a Taylor series expansion, 
  25. but of what?  And why the eight power?  Enjoy 
  26.  
  27. Dave Kurth
  28. dfk@col.hp.com
  29. Colorado Springs, CO
  30.  
  31.  
  32. DECLARE FUNCTION RH! (Temp!, DewPoint!)
  33.  
  34. '$page
  35. '***************************************************************************
  36. '
  37. '       This relative humidity algorithm is an adaptation of a
  38. '       FORTRAN routine used by the National Weather Service.
  39. '       I'm sure there are other quick and dirty methods of
  40. '       calculating Relative Humidity but this one works and is
  41. '       *very* accurate.
  42. '
  43. '       Questions or comments contact:      
  44. '
  45. '                               Jim Little
  46. '                               Compuserve 72765,1431
  47. '                               c/o KATU-TV
  48. '                               Portland, Oregon 97232
  49. '
  50. '    
  51. '***************************************************************************
  52. FUNCTION RH (Temp, DewPoint) STATIC
  53.  
  54.       IF DewPoint > Temp THEN                 'Return -1 as error code
  55.             RH = -1                         '   if dewpoint greater
  56.             GOTO RelHumidEnd                '   than temperature
  57.       END IF
  58.  
  59.       T = (Temp - 32) * 5 / 9                 'Convert to celsius
  60.       D = (DewPoint - 32) * 5 / 9
  61.       
  62.       C1# = .9999968299999999#                'set constants
  63.       C2# = -.0090826951#
  64.       C3# = .000078736169#
  65.       C4# = -.00000061117958#
  66.       C5# = .0000000043884187#
  67.       C6# = -2.9883885D-11
  68.       C7# = 2.1874425D-13
  69.       C8# = -1.7892321D-15
  70.       C9# = 1.1112018D-17
  71.       C10# = -3.0994571D-20
  72.       
  73.       X1# = C10#
  74.       X1# = C9# + T * (X1#)
  75.       X1# = C8# + T * (X1#)
  76.       X1# = C7# + T * (X1#)
  77.       X1# = C6# + T * (X1#)
  78.       X1# = C5# + T * (X1#)
  79.       X1# = C4# + T * (X1#)
  80.       X1# = C3# + T * (X1#)
  81.       X1# = C2# + T * (X1#)
  82.       X1# = C1# + T * (X1#)
  83.       X1# = X1# ^ 8
  84.  
  85.       X2# = C10#
  86.       X2# = C9# + D * (X2#)
  87.       X2# = C8# + D * (X2#)
  88.       X2# = C7# + D * (X2#)
  89.       X2# = C6# + D * (X2#)
  90.       X2# = C5# + D * (X2#)
  91.       X2# = C4# + D * (X2#)
  92.       X2# = C3# + D * (X2#)
  93.       X2# = C2# + D * (X2#)
  94.       X2# = C1# + D * (X2#)
  95.       X2# = X2# ^ 8
  96.  
  97.  
  98.  
  99.       RH = 100 * X1# / X2#                    'express results as percent
  100.  
  101. RelHumidEnd:
  102.  
  103. END FUNCTION
  104. END_DOC
  105.  
  106. Directory rh.rpl
  107. Checksum  # D635h
  108. Bytes       325.5
  109.  
  110. BEGIN_RPL rh.rpl
  111. %%HP: T(3)A(R)F(.);
  112. DIR
  113.   RH
  114.     @ Convert Temperature and Dewpoint (on stack) to Relative Humidity @
  115.     @ This relative humidity algorithm is an adaptation of a           @
  116.     @ FORTRAN routine used by the National Weather Service.            @
  117.     @ I'm sure there are other quick and dirty methods of              @
  118.     @ calculating Relative Humidity but this one works and is          @
  119.     @ *very* accurate.                                                 @
  120.     @                                                                  @
  121.     @ Questions or comments contact:                                   @
  122.     @                                                                  @
  123.     @ Jim Little                                                       @
  124.     @ Compuserve 72765,1431                                            @
  125.     @ c/o KATU-TV                                                      @
  126.     @ Portland, Oregon 97232                                           @
  127.     \<< 32 - 5 * 9 /                        @ Convert DewPoint to celsius
  128.       SWAP 32 - 5 * 9 /                     @ Convert Temp     to celsius
  129.       {-3.0994571E-20                       @ set Ci constants
  130.       1.1112018E-17                         @ In original algorithm,
  131.       -1.7892321E-15                        @ these were defined as 
  132.       2.1874425E-13                         @ double precision.  I'm
  133.       -2.9883885E-11                        @ just using the normal
  134.       .0000000043884187                     @ precision of the HP48
  135.       -.00000061117958
  136.       .000078736169
  137.       -.0090826951
  138.       .9999968299999999} \-> D T C          @ DewPoint, Temp, Constants
  139.       \<<
  140.         0                                   @ X1 = C1*T^9 + C2*T^8 + ...
  141.         1 10 
  142.         FOR i
  143.           T * C i GET +                     @ X1 = T * X1 + Ci
  144.         NEXT
  145.  
  146.         0                                   @ X2 = C1*D^9 + C2*D^8 + ...
  147.         1 10 
  148.         FOR i
  149.           D * C i GET +                     @ X2 = D * X2 + Ci
  150.         NEXT
  151.  
  152.         / 8 ^ 100 *                         @ RH =(X1 / X2)^8 as percent
  153.       \>>
  154.     \>>
  155. END
  156. END_RPL
  157.