unit uWxUtilsUS; // This source code may be freely used, including for commercial purposes // Steve Hatchett info@softwx.com // http://www.softwx.org/weather {********************************************** This file provides US unit versions of the functions in uWxUtils. Refer to uWxUtils for documentation. All input and output paramters are in the following US units: pressure in inches of mercury temperature in Fahrenheit wind in MPH elevation in feet **********************************************} interface uses uWxUtils; type TWxUtilsUS = class(TObject) private public // basic pressure functions - all take US params (inches Mercury, Fahrenheit, ft) class function StationToSensorPressure(pressureIn: TWxReal; sensorElevationFt: TWxReal; stationElevationFt: TWxReal; currentTempF: TWxReal): TWxReal; class function StationToAltimeter(pressureIn: TWxReal; elevationFt: TWxReal; algorithm: TAltimeterAlgorithm = DefaultAltimeterAlgorithm): TWxReal; class function StationToSeaLevelPressure(pressureIn: TWxReal; elevationFt: TWxReal; currentTempF: TWxReal; meanTempF: TWxReal; humidity: TWxHumidity; algorithm: TSLPAlgorithm = DefaultSLPAlgorithm): TWxReal; class function SensorToStationPressure(pressureIn: TWxReal; sensorElevationFt: TWxReal; stationElevationFt: TWxReal; currentTempF: TWxReal): TWxReal; // class function AltimeterToStationPressure(pressureIn: TWxReal; elevationFt: TWxReal; // algorithm: TAltimeterAlgorithm = DefaultAltimeterAlgorithm): TWxReal; class function SeaLevelToStationPressure(pressureIn: TWxReal; elevationFt: TWxReal; currentTempF: TWxReal; meanTempF: TWxReal; humidity: TWxHumidity; algorithm: TSLPAlgorithm = DefaultSLPAlgorithm): TWxReal; // low level pressure related functions class function PressureReductionRatio(pressureIn: TWxReal; elevationFt: TWxReal; currentTempF: TWxReal; meanTempF: TWxReal; humidity: TWxHumidity; algorithm: TSLPAlgorithm = DefaultSLPAlgorithm): TWxReal; class function ActualVaporPressure(tempF: TWxReal; humidity: TWxHumidity; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; class function SaturationVaporPressure(tempF: TWxReal; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; class function MixingRatio(pressureIn: TWxReal; tempF: TWxReal; humidity: TWxHumidity): TWxReal; class function HumidityCorrection(tempF: TWxReal; elevationFt: TWxReal; humidity: TWxHumidity; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; // temperature related functions class function DewPoint(tempF: TWxReal; humidity: TWxHumidity; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; class function WindChill(tempF: TWxReal; windSpeedMph: TWxReal): TWxReal; class function HeatIndex(tempF: TWxReal; humidity: TWxHumidity): TWxReal; class function Humidex(tempF: TWxReal; humidity: TWxHumidity): TWxReal; // simplified algorithm for geopotential altitude from US Standard Atmosphere 1976 // assumes latitude 45.5 degrees class function GeopotentialAltitude(geometricAltitudeFt: TWxReal): TWxReal; end; implementation class function TWxUtilsUS.StationToSensorPressure(pressureIn: TWxReal; sensorElevationFt: TWxReal; stationElevationFt: TWxReal; currentTempF: TWxReal): TWxReal; begin Result := pressureIn / TWxUtils.Power10(0.00813 * (sensorElevationFt - stationElevationFt) / TWxUtils.FToR(currentTempF)); end; class function TWxUtilsUS.StationToAltimeter(pressureIn: TWxReal; elevationFt: TWxReal; algorithm: TAltimeterAlgorithm = DefaultAltimeterAlgorithm): TWxReal; begin Result := TWxUtils.HPaToIn(TWxUtils.StationToAltimeter(TWxUtils.InToHPa(pressureIn), TwxUtils.FtToM(elevationFt), algorithm)); end; class function TWxUtilsUS.StationToSeaLevelPressure(pressureIn: TWxReal; elevationFt: TWxReal; currentTempF: TWxReal; meanTempF: TWxReal; humidity: TWxHumidity; algorithm: TSLPAlgorithm = DefaultSLPAlgorithm): TWxReal; begin Result := pressureIn * PressureReductionRatio(pressureIn, elevationFt, currentTempF, meanTempF, humidity, algorithm); end; class function TWxUtilsUS.SensorToStationPressure(pressureIn: TWxReal; sensorElevationFt: TWxReal; stationElevationFt: TWxReal; currentTempF: TWxReal): TWxReal; begin Result := pressureIn * TWxUtils.Power10(0.00813 * (sensorElevationFt - stationElevationFt) / TWxUtils.FToR(currentTempF)); end; { // still to do class function TWxUtilsUS.AltimeterToStationPressure(pressureIn: TWxReal; elevationFt: TWxReal; algorithm: TAltimeterAlgorithm = DefaultAltimeterAlgorithm): TWxReal; begin Result := TWxUtils.AltimeterToStationPressure(TWxUtils.InToHPa(pressureIn), TWxUtils.FtToM(elevationFt), algorithm); end; } class function TWxUtilsUS.SeaLevelToStationPressure(pressureIn: TWxReal; elevationFt: TWxReal; currentTempF: TWxReal; meanTempF: TWxReal; humidity: TWxHumidity; algorithm: TSLPAlgorithm = DefaultSLPAlgorithm): TWxReal; begin Result := pressureIn / PressureReductionRatio(pressureIn, elevationFt, currentTempF, meanTempF, humidity, algorithm); end; class function TWxUtilsUS.PressureReductionRatio(pressureIn: TWxReal; elevationFt: TWxReal; currentTempF: TWxReal; meanTempF: TWxReal; humidity: TWxHumidity; algorithm: TSLPAlgorithm = DefaultSLPAlgorithm): TWxReal; begin Result := TWxUtils.PressureReductionRatio(TWxUtils.InToHPa(pressureIn), TWxUtils.FtToM(elevationFt), TWxUtils.FToC(currentTempF), TWxUtils.FToC(meanTempF), humidity, algorithm); end; class function TWxUtilsUS.ActualVaporPressure(tempF: TWxReal; humidity: TWxHumidity; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; begin result := (humidity * SaturationVaporPressure(tempF, algorithm)) / 100; end; class function TWxUtilsUS.SaturationVaporPressure(tempF: TWxReal; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; begin Result := TWxUtils.HPaToIn(TWxUtils.SaturationVaporPressure(TWxUtils.FToC(tempF), algorithm)); end; class function TWxUtilsUS.MixingRatio(pressureIn: TWxReal; tempF: TWxReal; humidity: TWxHumidity): TWxReal; begin Result := TWxUtils.HPaToIn(TWxUtils.MixingRatio(TWxUtils.InToHPa(pressureIn), TWxUtils.FToC(tempF), humidity)); end; class function TWxUtilsUS.HumidityCorrection(tempF: TWxReal; elevationFt: TWxReal; humidity: TWxHumidity; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; begin Result := TWxUtils.HumidityCorrection(TWxUtils.FToC(tempF), TWxUtils.FtToM(elevationFt), humidity, algorithm); end; class function TWxUtilsUS.DewPoint(tempF: TWxReal; humidity: TWxHumidity; algorithm: TVapAlgorithm = DefaultVapAlgorithm): TWxReal; begin Result := TWxUtils.CToF(TWxUtils.DewPoint(TWxUtils.FToC(tempF), humidity, algorithm)); end; class function TWxUtilsUS.WindChill(tempF: TWxReal; windSpeedMph: TWxReal): TWxReal; begin if ((tempF >= 50.0) or (windSpeedMph <= 3.0)) then begin Result := tempF; end else begin Result := TWxUtils.CToF(TWxUtils.WindChill(TWxUtils.FToC(tempF), TWxUtils.MToKm(windSpeedMph))); end; end; class function TWxUtilsUS.HeatIndex(tempF: TWxReal; humidity: TWxHumidity): TWxReal; begin Result := TWxUtils.CToF(TWxUtils.HeatIndex(TWxUtils.FToC(tempF), humidity)); end; class function TWxUtilsUS.Humidex(tempF: TWxReal; humidity: TWxHumidity): TWxReal; begin Result := TWxUtils.CToF(TWxUtils.Humidex(TWxUtils.FToC(tempF), humidity)); end; class function TWxUtilsUS.GeopotentialAltitude(geometricAltitudeFt: TWxReal): TWxReal; begin Result := TWxUtils.MToFt(TWxUtils.GeopotentialAltitude(TWxUtils.FtToM(geometricAltitudeFt))); end; end.