hplnoz= new Array(60.,115.,230.,460.,920.);
var numhpl=24;

lplnoz= new Array(50.,100.,200.,400.);
var numlpl=16;

function roundoff(value, precision)
{
var result;

        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

function flowrate(flowind,noz)
{
var i,flow,flowpt;
var na=noz.length;

flow=0.0;
flowpt=flowind;
for (i=0;i<na;i++){
   if (flowpt&1) flow+=noz[i];
   flowpt>>=1;
   }
return flow;
}   

var rhof;  //make this a global

function densityratio(press,temp)
{
var rhob;

   rhof=NX19RHOF(temp,press,0.57,0.5,1.0);
   rhob=NX19RHOB(temp,press,0.57,0.5,1.0);
   return rhof/rhob;
}

function flowtable(press,temp,dia,loop)
{
var i,nn,drat,area;
var vel,macfh,massf,mmscfd;
var noz;

     drat=densityratio(press,temp);
     area=Math.PI*dia*dia/576.;
     document.writeln("<HTML><body>");
     document.writeln("<!-- style='font-family: Arial, Verdana; font-size: small'-->");
     document.writeln("<P>");
     document.writeln("<BIG>MRF "+loop+" Flow Rates </BIG><BR>");
     document.writeln("For a meter with ID=",roundoff(dia,3)," inches at P=",roundoff(press,1));
     document.writeln(" psig, T=",roundoff(temp,1)," F<BR>");
     document.writeln("</P>");
     document.writeln("<table border='1' width='100%'>");
     document.writeln("<tr>");
     document.writeln("<td width='20%' align='center'>Point</td>");
     document.writeln("<td width='20%' align='center'>Velocity(ft/s)</td>");
     document.writeln("<td width='20%' align='center'>MACF/H</td>");
     document.writeln("<td width='20%' align='center'>MassFlow(lb/min)</td>");
     document.writeln("<td width='20%' align='center'>MMSCF/D</td>");
     document.writeln("</tr>");
     if (loop=="HPL") {
	nn=numhpl;
        noz=hplnoz;
	}
     else {
       if (loop=="LPL") {
	nn=numlpl;
        noz=lplnoz;
	}       
	}
     for (i=1;i<nn;i++) {
	acfm=flowrate(i,noz);
	vel=acfm/(60.*area);
	macfh=acfm*60./1000.;
	massf=acfm*rhof;
	mmscfd=macfh*24.*drat/1000.;
        document.writeln("<tr>");
        document.writeln("<td width='20%' align='center'>",i,"</td>");
        document.writeln("<td width='20%' align='center'>",roundoff(vel,2),"</td>");
        document.writeln("<td width='20%' align='center'>",roundoff(macfh,1),"</td>");
        document.writeln("<td width='20%' align='center'>",roundoff(massf,1),"</td>");
        document.writeln("<td width='20%' align='center'>",roundoff(mmscfd,1),"</td>");
        document.writeln("</tr>");
	}
     document.writeln("</table>");
     document.writeln("<P>The above values are for estimating purposes only.<BR>");
     document.writeln("Southwest Research Institute</P>");
}
