Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. public class ObsMath {
  4.  
  5.    public static final int    PAD   = -1000;
  6.  
  7.  
  8.    public static int heatStressTempCalc (int tdry, int RH, int statHeight) {
  9.       // Calculates heat stress temperature (deg. C) from
  10.       // dry temperature (deg. C) and relative humidity (%)
  11.       // Uses station height for station level pressure calculation
  12.  
  13.       int twet = wetTempCalc (tdry, RH, statHeight);
  14.       return (int) Math.round ((tdry + twet) / 2.);
  15.    }
  16.  
  17.    public static int heatStressIndexCalc (int temp) {
  18.  
  19.       // Calculates heat stress index from heat stress temperature
  20.  
  21.       int index = PAD;
  22.       if (temp > 22 && temp <= 24)
  23.      index = 1;
  24.       else if (temp > 24 && temp <= 26)
  25.      index = 2;
  26.       else if (temp > 26 && temp <= 28)
  27.      index = 3;
  28.       else if (temp > 28 && temp <= 30)
  29.      index = 4;
  30.       else if (temp > 30)
  31.      index = 5;
  32.  
  33.       return index;
  34.    }
  35.  
  36.  
  37.    private static int wetTempCalc (int tdry, int RH, int statHeight) {
  38.       // Calculates wet temperature (deg. C) from dry temperature (deg. C) and relative humidity (%)
  39.       // Uses station height for station level pressure calculation
  40.  
  41.       double twx, twn, twi=99999., EsTw, Ei, Ri=99999.;
  42.       double pst = 101.3 * Math.pow (( 293. - 0.0065 * statHeight )/293., 5.26);
  43.       double Psych = 0.000792 * pst;
  44.       double EsTd = 0.611 * Math.exp( 17.27 * tdry / (237.3 + tdry));
  45.       double R = RH / 100.;
  46.       double E = R * EsTd;
  47.       if ( Math.abs (E-0.611) < 0.0022 )
  48.          twn = 0.;
  49.       else
  50.          twn = 13.7406 / ( 1./Math.log (E/.611) - .05791 );
  51.       twx = tdry;
  52.  
  53.       while (Math.abs (R - Ri) >= 0.005) {
  54.      twi = (twn + twx)/2.;
  55.      EsTw = 0.611 * Math.exp( 17.27 * twi / (237.3 + twi) );
  56.      Ei = EsTw - Psych * (tdry - twi) * ( 1 + 0.00115*twi);
  57.      Ri = Ei / EsTd ;
  58.      if ( Ri > R )
  59.         twx = twi;
  60.      else
  61.         twn = twi;
  62.       }
  63.    
  64.       return (int) Math.round (twi);
  65.    }
  66.      
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement