湿蒸汽性质程序及源代码

此算法和NOAA(美国国家海洋和大气管理局)是一致的,欢迎大家直接拿去用。

function decideConvert(temp, rh, pressure)
{

temp = parseFloat(document.Convert.Temp.value);
pressure = parseFloat(document.Convert.StnPress.value);

if(document.Convert.pressureunit[0].checked)
{
if(document.Convert.StnPress.value == “”)
{
alert (‘You must enter your station pressure and choose your units for the pressure’);
}
else
{
MBpressure = parseFloat(convertinHGtomb(pressure));
}
}

if(document.Convert.pressureunit[1].checked)
{
if(document.Convert.StnPress.value == “”)
{
alert (‘You must enter your station pressure and choose your units for the pressure’);
}
else
{
MBpressure = parseFloat(convertmmHGtomb(pressure));
}
}

if(document.Convert.pressureunit[2].checked)
{
if(document.Convert.StnPress.value == “”)
{
alert (‘You must enter your station pressure and choose your units for the pressure’);
}
else
{
MBpressure = pressure;
}
}

if (document.Convert.tempunit[0].checked)
{
if (document.Convert.Temp.value == “”)
{
alert (‘You must enter your temperature and choose your units for the temperature’);
}
else
{
Ctemp = parseFloat(convertFtoC(temp));

}
}

if (document.Convert.tempunit[1].checked)
{
if (document.Convert.Temp.value == “”)
{
alert (‘You must enter your temperature and choose your units for the temperature’);

}
else
{
Ctemp = temp;

}
}

if (document.Convert.tempunit[2].checked)
{
if (document.Convert.Temp.value == “”)
{
alert (‘You must enter your temperature and choose your units for the temperature’);
}
else
{
Ctemp = parseFloat(convertKtoC(temp));

}
}

if (document.Convert.RH.value == “”)
{
alert (‘You must enter your relative humidity’);
}
else
{
if (rh > 100 )
{
alert(‘Your RH is greater than 100%. RHs greater than 100% do not normally occur in the atmosphere. This supersaturated script will now evaporate’);
}
else
{
rh = parseFloat(document.Convert.RH.value);
}

}

var Es, E, dewpoint;

Es = parseFloat(esubs(Ctemp));
E = parseFloat(invertedRH(Es,rh));
dewpoint = (Dewpoint(E));

document.Convert.DewpointF.value = parseFloat(roundOff(convertCtoF(dewpoint)));
document.Convert.DewpointC.value = roundOff(dewpoint);
document.Convert.DewpointK.value = parseFloat(roundOff(convertCtoK(dewpoint)));

E2 = parseFloat(invertedRH(Es,rh));
Twguess = 0;
incr = 10;
previoussign = 1;
Edifference = 1;

wetbulb = calcwetbulb(Edifference,Twguess,Ctemp,MBpressure,E2,previoussign,incr);
document.Convert.WetbulbF.value = parseFloat(roundOff(convertCtoF(wetbulb)));
document.Convert.WetbulbC.value = roundOff(wetbulb);
document.Convert.WetbulbK.value = parseFloat(roundOff(convertCtoK(wetbulb)));

}

function convertFtoC(Fahr)
{
var Cels;
Cels = .55556 * (Fahr – 32);
return Cels;
}

function convertKtoC(Kel)
{
var Cels;
Cels = Kel – 273.15;
return Cels;
}

function convertCtoF(Cels)
{
var Fahr;
Fahr = 1.8 * Cels + 32;
return Fahr;
}

function convertCtoK(Cels)
{
var Kelvin;
Kelvin = Cels + 273.15;
return Kelvin;
}

function convertinHGtomb(inHG)
{
var mb;
mb = 33.8639*inHG;
return mb;
}

function convertmmHGtomb(mmHG)
{
var mb;
mb = 1.333224*mmHG;
return mb;
}

function esubs(Ctemp)
{
var Es;
Es = 6.112 * Math.exp(17.67 * Ctemp / (Ctemp + 243.5));
return Es;
}

function invertedRH(Es,rh)
{
var E;
E = Es * (rh/100);
return E;
}

function Dewpoint(E)
{
var Dewpoint;
Dewpoint = (243.5 * Math.log(E/6.112))/(17.67 – Math.log(E/6.112));
return Dewpoint;
}

function calcwetbulb(Edifference,Twguess,Ctemp,MBpressure,E2,previoussign,incr)
{
outerloop:
while (Math.abs(Edifference) > 0.005)
{
Ewguess = 6.112 * Math.exp((17.67 * Twguess) / (Twguess + 243.5));
Eguess = Ewguess – MBpressure * (Ctemp – Twguess) * 0.00066 * (1 + (0.00115 * Twguess));
Edifference = E2 – Eguess;

if (Edifference == 0)
{
break outerloop;
} else {
if (Edifference < 0)
{
cursign = -1;
if (cursign != previoussign)
{
previoussign = cursign;
incr = incr/10;
} else {
incr = incr;
}
} else {
cursign = 1;
if (cursign != previoussign)
{
previoussign = cursign;
incr = incr/10;
} else {
incr = incr;
}
}
}

Twguess = Twguess + incr * previoussign;

}
wetbulb = Twguess;
return wetbulb;
}

function roundOff(value)
{
value = Math.round(100*value)/100;
return value;
}

function roundOff(value)
{
value = Math.round(100*value)/100;
return value;
}

function setToNull()
{

document.Convert.DewpointF.value=””;
document.Convert.DewpointC.value=””;
document.Convert.DewpointK.value=””;
document.Convert.WetbulbF.value=””;
document.Convert.WetbulbC.value=””;
document.Convert.WetbulbK.value=””;
document.Convert.RH.value=””;
document.Convert.StnPress.value=””;
document.Convert.Temp.value=””;
}

Author: admin on 2016年4月15日
Category: 计算软件