<script language="javascript" type="text/javascript">
<!-- Original: Ilan Kroo kroo@leland.stanford.edu
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function setEUnits() {
var str = document.inputs.hunits.value;
if ( str== "ft") {
alert("Already in English Units.");
return;
}
document.inputs.hunits.value = "ft"
document.inputs.vunits.value = "ft/sec"
document.inputs.lunits.value = "ft"
document.results.tunits.value = "deg R"
document.results.runits.value = "sl/ft^3"
document.results.punits.value = "lb/ft^2"
document.results.sunits.value = "ft/sec"
document.results.muunits.value = "lb sec/ft^2"
document.results.qunits.value = "lb/ft^2"
var h = document.inputs.alt.value;
var v =document.inputs.speed.value;
var rl = document.inputs.rlength.value;
var tempVal = document.results.temp.value
var rhoVal = document.results.rho.value
var pVal = document.results.press.value
var soundVal = document.results.ssound.value
var viscVal = document.results.visc.value
var machVal = document.results.mach.value
var qVal =document.results.q.value
var cpstarVal = document.results.cpstar.value
var cpminVal = document.results.cpmin.value
var reynolds = document.results.reno.value
var cflam = document.results.cfl.value
var cfturb = document.results.cft.value
document.inputs.alt.value = h*3.2808
document.inputs.speed.value = v*3.2808
document.inputs.rlength.value = rl*3.2808
document.results.temp.value =tempVal*1.8
document.results.rho.value = rhoVal * .068521 * .028317
document.results.press.value = pVal * .020885
document.results.ssound.value = soundVal*3.2808
document.results.visc.value = viscVal*.22481*.092903
document.results.mach.value = machVal
document.results.q.value = qVal * .020885
document.results.cpstar.value = cpstarVal
document.results.cpmin.value = cpminVal
document.results.reno.value = reynolds
document.results.cfl.value = cflam
document.results.cft.value = cfturb
roundAll();
}
function setMUnits() {
var str = document.inputs.hunits.value;
if ( str== "m") {
alert("Already in metric units.");
return;
}
Compute();
document.inputs.hunits.value = "m"
document.inputs.vunits.value = "m/sec"
document.inputs.lunits.value = "m"
document.results.tunits.value = "deg K"
document.results.runits.value = "kg/m^3"
document.results.punits.value = "N/m^2"
document.results.sunits.value = "m/sec"
document.results.muunits.value = "N sec/m^2"
document.results.qunits.value = "N/m^2"
var h = document.inputs.alt.value;
var v = document.inputs.speed.value;
var rl = document.inputs.rlength.value;
var tempVal = document.results.temp.value
var rhoVal = document.results.rho.value
var pVal = document.results.press.value
var soundVal = document.results.ssound.value
var viscVal = document.results.visc.value
var machVal = document.results.mach.value
var qVal =document.results.q.value
var cpstarVal = document.results.cpstar.value
var cpminVal = document.results.cpmin.value
var reynolds = document.results.reno.value
var cflam = document.results.cfl.value
var cfturb = document.results.cft.value
document.inputs.alt.value = h/3.2808
document.inputs.speed.value = v/3.2808
document.inputs.rlength.value = rl/3.2808
document.results.temp.value =tempVal/1.8
document.results.rho.value = rhoVal / .068521 / .028317
document.results.press.value = pVal / .020885
document.results.ssound.value = soundVal/3.2808
document.results.visc.value = viscVal/.22481/.092903
document.results.mach.value = machVal
document.results.q.value = qVal / .020885
document.results.cpstar.value = cpstarVal
document.results.cpmin.value = cpminVal
document.results.reno.value = reynolds
document.results.cfl.value = cflam
document.results.cft.value = cfturb
roundAll();
}
function ResetForm() {
document.inputs.alt.value = "0.0"
document.inputs.speed.value = "1.0"
document.inputs.rlength.value = "1.0"
}
function Compute() {
// First set to English Units
var origUnits = "english";
var str = document.inputs.hunits.value;
if ( str== "m") {
origUnits = "metric";
setEUnits();
}
var h = document.inputs.alt.value;
var v =document.inputs.speed.value;
var rl = document.inputs.rlength.value;
var TEMPSL = 518.67;
var RHOSL = 0.00237689;
var PRESSSL = 2116.22;
var saTheta = 1.0
var saSigma = 1.0
var saDelta = 1.0
if ( h<232940 ){
saTheta = 1.434843 - h/337634;
saSigma = Math.pow( 0.79899-h/606330, 11.20114 );
saDelta = Math.pow( 0.838263-h/577922, 12.20114 );
}
if ( h<167323 ){
saTheta = 0.939268;
saSigma = 0.00116533 * Math.exp( (h-154200)/-25992 );
saDelta = 0.00109456 * Math.exp( (h-154200)/-25992 );
}
if ( h<154199 ){
saTheta = 0.482561 + h/337634;
saSigma = Math.pow( 0.857003+h/190115, -13.20114 );
saDelta = Math.pow( 0.898309+h/181373, -12.20114 );
}
if ( h<104987 ){
saTheta = 0.682457 + h/945374;
saSigma = Math.pow( 0.978261+h/659515, -35.16319 );
saDelta = Math.pow( 0.988626+h/652600, -34.16319 );
}
if ( h<65617 ){
saTheta = 0.751865;
saSigma = 0.297076 * Math.exp( (36089-h)/20806 );
saDelta = 0.223361 * Math.exp( (36089-h)/20806 );
}
if ( h<36089 ){
saTheta = 1.0 - h/145442;
saSigma = Math.pow( 1.0-h/145442, 4.255876 );
saDelta = Math.pow( 1.0-h/145442, 5.255876 );
}
var tempVal = TEMPSL * saTheta;
var rhoVal = RHOSL * saSigma;
var pVal = PRESSSL * saDelta;
var viscVal = 0.0226968*Math.pow( tempVal, 1.5 ) / ((tempVal)+198.72) /
1000000.0;
var soundVal = Math.sqrt( 1.4*1716.56*(tempVal) );
var machVal = v/soundVal
var qVal = 0.7*pVal*machVal*machVal
var reynolds = v*rl*rhoVal/viscVal
var cfturb = 0.455/Math.pow((Math.log(reynolds)/Math.log(10)),2.58)
var cflam = 1.328/Math.sqrt(reynolds)
document.results.temp.value = tempVal
document.results.rho.value = rhoVal
document.results.press.value = pVal
document.results.ssound.value = soundVal
document.results.visc.value = viscVal
document.results.mach.value = machVal
document.results.q.value = qVal
document.results.cpstar.value = (Math.pow((1/1.2 +
machVal*machVal/6.0),3.5)-1)/(0.7*machVal*machVal)
document.results.cpmin.value = -1.0/(0.7*machVal*machVal)
document.results.reno.value = reynolds
document.results.cfl.value = cflam
document.results.cft.value = cfturb
if (origUnits == "metric") {
setMUnits();
}
roundAll();
}
// Rounding
function roundAll(){
document.inputs.alt.value = truncNum(document.inputs.alt.value,9)
document.inputs.speed.value = truncNum(document.inputs.speed.value,7)
document.inputs.rlength.value =
truncNum(document.inputs.rlength.value,7)
document.results.temp.value =truncNum(document.results.temp.value,7)
document.results.rho.value = truncNum(document.results.rho.value,7)
document.results.press.value = truncNum(document.results.press.value,7)
document.results.ssound.value = truncNum(document.results.ssound.value
,8)
document.results.visc.value = truncNum(document.results.visc.value,10)
document.results.mach.value = truncNum(document.results.mach.value,6)
document.results.q.value = truncNum(document.results.q.value,7)
document.results.cpstar.value =
truncNum(document.results.cpstar.value,6)
document.results.cpmin.value = truncNum(document.results.cpmin.value,6)
document.results.reno.value = truncNum(document.results.reno.value,9)
document.results.cfl.value = truncNum(document.results.cfl.value,7)
document.results.cft.value = truncNum(document.results.cft.value,7)
return;
}
function truncNum(inputVal, rsize) {
var instr = " " + inputVal
var inputlength = instr.length
if (inputlength<=rsize+1) return instr.substring(1, inputlength);
var epos = strpos(instr, "e")
if ( epos > rsize+1) {
var instr1 = instr.substring(1,rsize+1) +
instr.substring(epos,inputlength);
return instr1;
}
var rounded = instr.substring(1, rsize+1);
return rounded;
}
function strpos(str, ch) {
for (var i = 0; i < str.length; i++)
if (str.substring(i, i+1) == ch) return i;
return -1;
}
// End -->
</script>
<center>
<FORM name = "units">
Select unit system:
<INPUT TYPE="radio" VALUE="radio" NAME="unitbut" CHECKED="true"
onClick="setEUnits()">English
<INPUT TYPE="radio" VALUE="radio" NAME="unitbut"
onClick="setMUnits()">Metric
</FORM>
<p>
<HR>
<H3>Inputs</H3>
<FORM name="inputs">
<table>
<tr>
<td>Altitude</td>
<td><INPUT NAME="alt" TYPE=text VALUE="0.0" SIZE=15></td>
<td><INPUT NAME="hunits" TYPE=text SIZE=6 VALUE="ft"></td>
</tr>
<tr>
<td>Speed</td>
<td><INPUT NAME="speed" TYPE="text" VALUE="1.0" SIZE="15"></td>
<td><INPUT NAME="vunits" TYPE="text" SIZE="6" VALUE="ft/sec"></td>
</tr>
<tr>
<td>Reference Length</td>
<td><INPUT NAME="rlength" TYPE="text" VALUE="1.0" SIZE="15"></td>
<td><INPUT NAME="lunits" TYPE="text" SIZE="6" VALUE="ft"></td>
</tr>
</table>
<BR>
<BR>
<INPUT NAME="name" TYPE="button" VALUE="Compute" onClick="Compute()">
<INPUT NAME="name" TYPE="button" VALUE="Reset" onClick="ResetForm()">
</FORM>
<HR SIZE="4">
<H3>Results</H3>
<FORM name = "results">
<table>
<tr>
<td>Temperature</td>
<td><INPUT NAME="temp" TYPE="text" SIZE="15"></td>
<td><INPUT NAME="tunits" TYPE="text" SIZE="8" VALUE="?R"></td>
</tr>
<tr>
<td>Density</td>
<td><INPUT NAME="rho" TYPE="text" SIZE="15"></td>
<td><INPUT NAME="runits" TYPE="text" SIZE="8" VALUE="sl/ft^3"></td>
</tr>
<tr>
<td>Pressure</td>
<td><INPUT NAME="press" TYPE="text" SIZE="15"></td>
<td><INPUT NAME="punits" TYPE="text" SIZE="8" VALUE="lb/ft^2"></td>
</tr>
<tr><td>Speed of Sound</td>
<td><INPUT NAME="ssound" TYPE="text" SIZE="15"></td>
<td><INPUT NAME="sunits" TYPE="text" SIZE="8" VALUE="ft/sec"></td>
</tr>
<tr>
<td>Viscosity</td>
<td><INPUT NAME="visc" TYPE="text" SIZE="15"></td>
<td><INPUT NAME="muunits" TYPE="text" SIZE="11" VALUE="lb
sec/ft^2"></td>
<tr></tr>
</tr>
<tr>
<td>Mach Number</td>
<td><INPUT NAME="mach" TYPE="text" SIZE="15"></td>
</tr>
<tr>
<td>Dynamic Pressure</td>
<td><INPUT NAME="q" TYPE="text" SIZE="15"></td>
<td><INPUT NAME="qunits" TYPE="text" SIZE="8" VALUE="lb/ft^2"></td>
</tr>
<tr>
<td>Critical Cp</td>
<td><INPUT NAME="cpstar" TYPE="text" SIZE="15"></td>
</tr>
<tr>
<td>Vacuum Cp</td>
<td><INPUT NAME="cpmin" TYPE="text" SIZE="15"></td>
<tr>
</tr>
</tr>
<tr>
<td>Reynolds Number</td>
<td><INPUT NAME="reno" TYPE="text" SIZE="15"></td>
</tr>
<tr>
<td>Laminar Cf</td>
<td><INPUT NAME="cfl" TYPE="text" SIZE="15"></td>
</tr>
<tr>
<td>Turbulent Cf</td>
<td><INPUT NAME="cft" TYPE="text" SIZE="15"></td>
</tr>
</table>
</FORM>
</center>