//======================================================
// Thermodynamic Package in java
// Class wetN2 Properties of water/Nitrogen mixture
// Dr. Turhan Coban
// EGE University
// Mechanical Engineering
// email : turhan.coban@mail.ege.edu.tr
// File Name   : wetN2
// This file utilise the steam and Gas1 clases
// this class sets thermophysical properties of Nitrogen-water mixture
// =====================================================

import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.Locale;
import java.text.*;

public class wetN2
{
  Gas1 a;
  steam s;
  final String u[]={"SI","EN"};
  String unit;
  final double c=18.015/28.013;
  boolean SI=true;
  public wetN2()
  {
  a=new Gas1("n2");
  s=new steam();
  unit=u[0];
  a.mole=false;
  }
  
  public void setUnit(boolean x)
  { if(x) {unit=u[0];} else {unit=u[1];}
    s.setUnit(x);a.SI=x;
  }
  
  public void setUnit(String x)
  { if(x.equals("EN")) {unit=u[1];SI=false;a.SI=false;} else {unit=u[0];SI=true;a.SI=true;}s.setUnit(x);}

  public double[] property1(String si, double v1, double v2, double P)
  {
  double aa[]=new double[14];
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  if     (si.equals("tdb_twb"))  {aa=tdb_twb(v1,v2,P);}
  else if(si.equals("tdb_rh"))   {aa=tdb_rh(v1,v2,P);}
  else if(si.equals("w_rh"))     {aa=w_rh(v1,v2,P);}
  else if(si.equals("w_h"))      {aa=w_h(v1,v2,P);}
  else if(si.equals("tdb_dos"))  {aa=tdb_dos(v1,v2,P);}
  else if(si.equals("tdb_w"))    {aa=tdb_w(v1,v2,P);}
  else if(si.equals("tdb_pv"))   {aa=tdb_pv(v1,v2,P); }
  else if(si.equals("tdb_tdew")) {aa=tdb_tdew(v1,v2,P); }
  else if(si.equals("tdb_h"))    {aa=tdb_h(v1,v2,P);}
  return aa;
  }

  public double[] property(String si, double v1, double v2, double P)
  {
  //options for string s: "tdb_twb"  dry bulb - wet bulb temperatures
  //                      "tdb_rh"   dry bulb temperature - relative humidity
  //                      "tdb_w"    dry bulb temperature - specific humidity
  //                      "tdb_tdew" dry bulb temperature - dew point temperature
  //                      "tdb_pv"   dry bulb temperature - water vapor pressure
  //                      "tdb_dos"  dry bulb temperature - degree of saturation
  //                      "tdb_h"    dry bulb temperature - enthalpy
  //                      "tdb_s"    dry bulb temperature - enthropy
  //                      "w_rh"     specific humidity    - relative humifdity
  //                      "w_h"      specific humidity    -  enthalpy
  double aa[]=new double[14];
  double bb[]=new double[15];
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  if     (si.equals("tdb_twb"))  {aa=tdb_twb(v1,v2,P);}
  else if(si.equals("tdb_rh"))   {aa=tdb_rh(v1,v2,P);}
  else if(si.equals("w_rh"))     {aa=w_rh(v1,v2,P);}
  else if(si.equals("w_h"))      {aa=w_h(v1,v2,P);}
  else if(si.equals("tdb_dos"))  {aa=tdb_dos(v1,v2,P);}
  else if(si.equals("tdb_w"))    {aa=tdb_w(v1,v2,P);}
  else if(si.equals("tdb_pv"))   {aa=tdb_pv(v1,v2,P); }
  else if(si.equals("tdb_tdew")) {aa=tdb_tdew(v1,v2,P); }
  else if(si.equals("tdb_h"))    {aa=tdb_h(v1,v2,P);}
  for(int i=0;i<aa.length;i++) bb[i]=aa[i];
  if(si.equals("tdb_twb")) bb[14]=v2;
  else bb[14]=twb(bb[1],bb[5],P);
  return bb;
  }  
    
public double[] tdb_twb(double v1,double v2,double P)
{
  //dry bulb temperature and wet bulb temperature
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];
  if(v2 >= v1) {v2=v1;aa=tdb_rh(v1,1.0,P);return aa;} 
  double sp[]=s.property("tx",v2,1.0);//saturated vapor at wet bulb temperatur
  //sp[0] p
  //sp[1] t
  //sp[2] v
  //sp[3] h
  //sp[4] u
  //sp[5] s
  double ws=c*sp[0]/(P-sp[0]);
  double hsg=sp[3];
  double sp1[]=s.property("tx",v2,0.0);//saturated liquid at wet bulb temperature
  double hsf=sp1[3];
  double hsfg=hsg-hsf;
  double sp2[]=s.property("tx",v1,1.0);//saturated vapor at dry bulb temp. first iteration
  double pvs=sp2[0];
  double t=sp2[1];
  double hg=sp2[3];
  //first iteration use hg(saturation) instead of hv(superheated)
  double ap[]=a.property((v1+tt),P);
  double ap1[]=a.property(tt,P);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double ap2[]=a.property((v2+tt),P);
  double has=ap2[3]-ap1[3];
  double w=(ws*hsfg-(ha-has))/(hg-hsf);
  double pv=w/c*P/(1.0+w/c);
  double Pa=P-pv;
  System.out.println("w="+w+"hsfg="+hsfg+"ha="+ha+"has="+has+"P="+P+"Pv="+pv+"Pa="+Pa);
  ap=a.property((v1+tt),P);
  double sp3[]=s.property("tp",v1,pv);
  double hv=sp3[3];
  double sv=sp3[5];  
  w=(ws*hsfg-(ha-has))/(hv-hsf);
  pv=w/c*P/(1.0+w/c);
  Pa=P-pv;  
  double tdb=v1;
  double sp4[]=s.property("tp",v1,pv);
  hv=sp4[3];
  sv=sp4[5];  
  //dew point
  double sp5[]=s.property("px",pv,1.0);
  double tdp=sp5[1];
  double rh=pv/pvs;
  ws=c*pvs/(P-pvs);
  double dos=w/ws;
  double h=ha+w*hv;
  double s=sa+w*sv;
  h=ha+w*hv;
  s=sa+w*sv;
  ws=c*pv/Pa;
  aa[0]=P;
  aa[1]=t;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  return aa;
  }
  
public double f_twb(double Tdb,double w0,double P,double Twb)
{
  //basic wet bulb definition function
  double aa[]=new double[14];
  aa=tdb_w(Tdb,w0,P);
  double h1=aa[8];
  double w1=aa[5];
  aa=tdb_rh(Twb,1.0,P);
  double h2=aa[8];
  double w2=aa[5];
  double sp1[]=s.property("tx",Twb,0.0);//saturated water
  double hsf=sp1[3]; // saturated water at wet bub temperature
  return h1+(w2-w1)*hsf-h2;
  }
  
public double twb(double tdb,double w0,double P)
{
// x in f(x)=0 bracket xl and xu is given
// false position method
// function should be supplied
// defination of variables :
// xl : lower guess
// xu : upper guess
// xr : root estimate
// ea :approximate error
// maxit : maximum iterations
// iter  : number of iteration
double aa[]=new double[14];
aa=tdb_w(tdb,w0,P);
//this bracket always satisfied
double xl=aa[7];
double xu=tdb;
double test;
double xr=0;
double es,ea;
double fxl,fxr,fxu;
int iter=0;
int maxit=10;
int sign1,sign2;
es=0.0001;
ea=1.1*es;
fxu= f_twb(tdb,w0,P,xu);
fxl= f_twb(tdb,w0,P,xl);
fxr=1.0;
//false position method iteration
while((fxr>es)&&(iter<maxit))
{
iter++;
if((xl+xu)!=0)
xr=xu-fxu*(xl-xu)/(fxl-fxu);
fxr= f_twb(tdb,w0,P,xr);
sign1=(int)(fxl/Math.abs(fxl));
sign2=(int)(fxr/Math.abs(fxr));
//System.out.println("*****iter="+iter+" xl="+xl+" fxl="+fxl+" xu="+xu+" fxu="+fxu+" xr="+xr+" fxr="+fxr);
if(sign1==sign2) {xl=xr;fxl=fxr;}
else             {xu=xr;fxu=fxr;}
//System.out.println("iter="+iter+" xl="+xl+" fxl="+fxl+" xu="+xu+" fxu="+fxu+" xr="+xr+" fxr="+fxr+" sign1="+sign1+" sign2="+sign2);
test= fxl*fxr;
//System.out.println("xl="+xl+"xr="+xr+"xu="+xu+"fxl="+fxl+"fxr="+fxr);
if(test==0.0)       ea=0;
else if(test<0.0)  xu=xr;
else               xl=xr;
} //end of while
return xr;
}
  
public double[] tdb_rh(double v1,double v2,double P)
{
  //dry bulb temperature and relative humidity
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];
  double sp[]=s.property("tx",v1,1.0);
  double pvs=sp[0];
  double pv=pvs*v2;
  double sp4[]=s.property("px",pv,1.0);
  double tdp=sp4[1];
  double ws=c*pvs/(P-pvs);
  double w=c*pv/(P-pv);
  double sp1[];
  if(v2>0.9999) sp1=sp;
  else
    sp1=s.property("tp",v1,pv);
  double hg=sp1[3];
  double Pa=P-pv;
  double ap[]=a.property((v1+tt),Pa);
  double ap1[]=a.property(tt,Pa);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double rh=v2;
  double dos=w/ws;
  double hv=sp1[3];
  double sv=sp1[5];
  double h=ha+w*hv;
  double s=sa+w*sv;
  aa[0]=P;
  aa[1]=v1;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  
  return aa;
}

public double[] w_rh(double v1,double v2,double P)
{
  //dry bulb temperature and relative humidity
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];	
  double w=v1;
  double rh=v2;
  double pv=w/c*P/(1.0+w/c);
  double pvs=pv/rh;
  double sp[]=s.property("px",pvs,1.0);
  double t=sp[1];
  double sp1[]=s.property("tp",t,pv);
  double hv=sp1[3];
  double sv=sp1[5];
  double sp4[]=s.property("px",pv,1.0);
  double tdp=sp4[1];
  double ws=c*pvs/(P-pvs);
  double Pa=P-pv;
  double ap[]=a.property((t+tt),Pa);
  double ap1[]=a.property(tt,Pa);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double dos=w/ws;
  double h=ha+w*hv;
  double s=sa+w*sv;
  aa[0]=P;
  aa[1]=t;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
 
  return aa;
}

public double[] w_h(double v1,double v2,double P)
{
  //dry bulb temperature and wet bulb temperature
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];
  double w=v1;
  double h=v2;
  if(w==0)
      {
      double pv=0;
      double Pa=P;
      double t0=h/1.005;
      double t1=t0+0.1;
      double ap[]=a.property((t0+tt),Pa);
      double ap1[]=a.property(tt,Pa);
      Cpa=ap[9];
  //first guess for t;
     Cp=Cpa;
     double t=h/Cp;
     double ha=ap[3]-ap1[3];
     double hv=0;
     double sa=ap[5]-ap1[5];
     double tdp=t;
     double rh=0;
     double ws=0;
     double dos=0;
     double s=sa;
     aa[0]=P;
     aa[1]=t;
     aa[2]=ap[2];
     aa[3]=pv;
     aa[4]=Pa;
     aa[5]=w;
     aa[6]=rh;
     aa[7]=dos;
     aa[8]=h;
     aa[9]=s;
     aa[10]=tdp;
     aa[11]=ha;
     aa[12]=0;
     aa[13]=w*hv;
    
  }
  else
  {
  double pv=w/c*P/(1.0+w/c);
  double Pa=P-pv;
  double sp[]=s.property("px",pv,1.0);
  double t0=sp[1];
  System.out.println("to = "+t0);
  double t1=t0+0.1;
  hg0=sp[3];
  double ap[]=a.property((t0+tt),Pa);
  double ap1[]=a.property(tt,Pa);
  Cpa=ap[9];
  sp=s.property("tx",t1,1.0);
  double hg1=sp[3];
  Cpw=(hg1-hg0)/0.1;
  //first guess for t;
  Cp=Cpa+w*Cpw;
  double t=(h-w*hg0+Cpw*t0*w)/Cp;
  ap=a.property((t+tt),Pa);
  Cpa=ap[9];
  sp=s.property("tx",t,1.0);
  t0=t;
  hg0=sp[3];
  System.out.println("t0=t"+t0);
  t1=t0+0.1;
  sp=s.property("tx",t1,1.0);
  hg1=sp[3];
  Cpw=(hg1-hg0)/0.1;
  Cp=Cpa+w*Cpw;
  t=t=(h-w*hg0+Cpw*t0*w)/Cp;
  System.out.println("t last correction ="+t);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  sp=s.property("tp",t,pv);
  double hv=sp[3];
  double sv=sp[5];
  double sp4[]=s.property("px",pv,1.0);
  double tdp=sp4[1];
  double sp1[]=s.property("tx",t,1.0);
  double pvs=sp1[0];
  double rh=pv/pvs;
  double ws=c*pvs/(P-pvs);
  double dos=w/ws;
  double s=sa+w*sv;
  aa[0]=P;
  aa[1]=t;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
 
  }
return aa;
}

public double[] tdb_dos(double v1,double v2,double P)
{
  //dry bulb temperature and degree of saturation
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];	
  double sp[]=s.property("tx",v1,1.0);
  double pvs=sp[0];
  double ws=c*pvs/(P-pvs);
  double w=v2*ws;
  double pv=w/c*P/(1+w/c);
  double sp4[]=s.property("px",pv,1.0);
  double tdp=sp4[1];
  double sp1[];
    if(v2>0.9999) sp1=sp;
  else
    sp1=s.property("tp",v1,pv);
  double hg=sp1[3];
  double ap[]=a.property((v1+tt),P);
  double ap1[]=a.property(tt,P);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double rh=pv/pvs;
  double dos=w/ws;
  double hv=sp1[3];
  double sv=sp1[5];
  double h=ha+w*hv;
  double s=sa+w*sv;
  double Pa=P-pv;
  ap=a.property((v1+tt),Pa);
  aa[0]=P;
  aa[1]=v1;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  
  return aa;
}

public double[] tdb_w(double v1,double v2,double P)
{  //v1 tdb  v2 w
   double tdb=v1;
  //dry bulb temperature and degree of saturation
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];
  //w check : w can not be bigger than saturated Nitrogen
  aa=tdb_rh(v1,1.0,P);
  if(v2>aa[5]) v2=aa[5]; //w can not be bigger than saturated Nitrogen	

  
 
  double w=v2;
  double pv=w/c*P/(1-w/c);
  double sp[]=s.property("tp",v1,pv);
  double pa=P-pv;
  double sp4[]=s.property("tx",tdb,1.0);
  double pg=sp4[0];
  double rh=pv/pg;
  System.out.println("pv="+pv+"pg="+pg+"rh="+rh+"pa="+pa);
  double tdp=sp4[1];
  double ws=w;
  double sp1[]=s.property("tp",v1,pv);
  double hg=sp1[3];
  double ap[]=a.property((v1+tt),P);
  double ap1[]=a.property(tt,P);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double dos=w/ws;
  double hv=sp1[3];
  double sv=sp1[5];
  double h=ha+w*hv;
  double s=sa+w*sv;
  double Pa=P-pv;
  ap=a.property((v1+tt),Pa);
  aa[0]=P;
  aa[1]=v1;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  
  return aa;
}

public double[] tdb_pv(double v1,double v2,double P)
{
  //dry bulb temperature and vapor pressure
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];	
  double sp[]=s.property("tx",v1,1.0);
  double pvs=sp[0];
  double pv=v2;
  double w=c*pv/(P-pv);
  double rh=pv/pvs;
  double sp4[]=s.property("px",pv,1.0);
  double tdp=sp4[1];
  double ws=c*pvs/(P-pvs);
  double sp1[]=s.property("tp",v1,pv);
  double hg=sp1[3];
  double ap[]=a.property((v1+tt),P);
  double ap1[]=a.property(tt,P);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double dos=w/ws;
  double hv=sp1[3];
  double sv=sp1[5];
  double h=ha+w*hv;
  double s=sa+w*sv;
  double Pa=P-pv;
  ap=a.property((v1+tt),Pa);
  aa[0]=P;
  aa[1]=v1;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  
  return aa;
}

public double[] tdb_tdew(double v1,double v2,double P)
{
  //dry bulb temperature and vapor pressure
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];		
  double sp[]=s.property("tx",v1,1.0);
  double pvs=sp[0];
  double sp1[]=s.property("tx",v2,1.0);
  double pv=sp1[0];
  double tdp=v2;
  double w=c*pv/(P-pv);
  double rh=pv/pvs;
  double ws=c*pvs/(P-pvs);
  double sp2[]=s.property("tp",v1,pv);
  double hg=sp2[3];
  double ap[]=a.property((v1+tt),P);
  double ap1[]=a.property(tt,P);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double dos=w/ws;
  double hv=sp1[3];
  double sv=sp1[5];
  double h=ha+w*hv;
  double s=sa+w*sv;
  double Pa=P-pv;
  ap=a.property((v1+tt),Pa);
  aa[0]=P;
  aa[1]=v1;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  
  return aa;
}

public double[] tdb_h(double v1,double v2,double P)
{
  //dry bulb temperature and vapor pressure
  double tt,Cpa,Cpw,hg0,Cp;
  if(a.SI){tt=273.15;} else {tt=459.67;};
  double aa[]=new double[14];
  double sp[]=s.property("tx",v1,1.0);
  double hg=sp[3];
  double pvs=sp[0];
  double ap[]=a.property((v1+tt),P);
  double ap1[]=a.property(tt,P);
  double ha=ap[3]-ap1[3];
  double sa=ap[5]-ap1[5];
  double h=v2;
  double w=(h-ha)/hg;
  double pv=w/c*P/(1.0+w/c);
  double rh=pv/pvs;
  double sp4[]=s.property("px",pv,1.0);
  double tdp=sp4[1];
  double ws=c*pvs/(P-pvs);
  double sp1[]=s.property("tp",v1,pv);
  double dos=w/ws;
  double hv=sp1[3];
  double sv=sp1[5];
  double s=sa+w*sv;
  double Pa=P-pv;
  ap=a.property((v1+tt),Pa);
  aa[0]=P;
  aa[1]=v1;
  aa[2]=ap[2];
  aa[3]=pv;
  aa[4]=Pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=dos;
  aa[8]=h;
  aa[9]=s;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  
  return aa;
} 



public String toString(String si, double v1, double v2, double P)
{
   String s1[][]=toString1(si,v1,v2,P);
   String ss="";
   for(int i=0;i<15;i++)
   {ss+=s1[i][0]+s1[i][1]+s1[i][2]+"\n";}
   return ss;
}

public String[][] toString1(String si, double v1, double v2, double P)
{
String s1[][]=new String[15][3];
s1[0][0]="P,_pressure_______________";
s1[1][0]="T,_dry_bulb_temperature______";
s1[2][0]="v,_dry_Nitrogen_specific_vol_____";
s1[3][0]="Pv_water_vapor_pressure_____";
s1[4][0]="Pa_Nitrogen_partial_pressure_____";
s1[5][0]="w,_humidity_ratio___________";
s1[6][0]="rh,relative_humidity________";
s1[7][0]="dos,degree_of_saturat______";
s1[8][0]="h_enthalpy_________________";
s1[9][0]="s,_enthropy________________";
s1[10][0]="tdew,dew_point_temperat.___";
s1[11][0]="ha,_par_Nitrogen_vap_enthalpy___";
s1[12][0]="hv,_par_water_vap_enthalpy____";
s1[13][0]="hv*w,_latent_enthalpy_____";
s1[14][0]="T_wet_bulb_temperature______";
   if(SI)
   {
s1[0][2]="_bar______________________";
s1[1][2]="_deg_C____________________";
s1[2][2]="_m^3/kg___________________";
s1[3][2]="_bar______________________";
s1[4][2]="_bar______________________";
s1[5][2]="_kg_vapor/kg_dry_Nitrogen______";
s1[6][2]="__________________________";
s1[7][2]="__________________________";
s1[8][2]="_KJ/kg_dry_Nitrogen____________";
s1[9][2]="_KJ/kg_dry_Nitrogen_K__________";
s1[10][2]="_deg_C____________________";
s1[11][2]="_KJ/kg_dry_Nitrogen____________";
s1[12][2]="_KJ/kg_dry_Nitrogen____________";
s1[13][2]="_KJ/kg_dry_Nitrogen____________";
s1[14][2]="_deg_C____________________";
}
   else
   {
   s1[0][2]=" lbf/in^2, psia      ";
   s1[1][2]=" deg F               ";
   s1[2][2]=" ft^3/lbmass dry Nitrogen ";
   s1[3][2]=" lbf/in^2, psia      ";
   s1[4][2]=" lbf/in^2, psia      ";
   s1[5][2]=" lbm vapor/lbm dry Nitrogen ";
   s1[6][2]="   ";
   s1[7][2]="   ";
   s1[8][2]=" BTU/lbmole dry Nitrogen   ";
   s1[9][2]=" BTU/lbmole dry Nitrogen R ";
   s1[10][2]="deg F";
   s1[11][2]=" BTU/lbmole dry Nitrogen   ";
   s1[12][2]=" BTU/lbmole dry Nitrogen   ";
   s1[13][2]=" BTU/lbmole dry Nitrogen   ";
   s1[14][2]=" deg F               ";
   }
   double pp[]=property(si,v1,v2,P);
   for(int i=0;i<15;i++)
   {s1[i][1]=toString(pp[i],23,14);}
   return s1;
} 
  public static String toString(double left, int w, int d)
  // converts a double to a string with given width and decimals.
  {
	NumberFormat df=NumberFormat.getInstance(Locale.US);
	df.setMaximumFractionDigits(d);
    df.setMinimumFractionDigits(d);
    df.setGroupingUsed(false);
    String s = df.format(left);
    while (s.length() < w)
      s = " " + s;
    if (s.length() > w)
    {
        s = "";
        for (int i=0; i<w; i++)
          s = s + "-";
    }
    return s;
 }

}

