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 wet_N2
{
  Gas1 a=new Gas1("n2");
  steam s=new steam();
  final double c=18.015/28.013;
  public wet_N2()
  {a.mole=false;}
  //Steam 0 p bar
  //      1 T deg C
  //      2 v m3/kg
  //      3 h kJ/kg
  //      4 u kJ/kg
  //      5 s kJ/kgK
  //      6 x kg vapor/kg total
  //      7 ro kg/m^3
  //      8 phase
  // Nitrogen 
  // 0 pressure bar
  // 1 T deg K
  // 2 v m^3/kg
  // 3 h kJ/jg
  // 4 u kJ/kg
  // 5 s kJ/kgK
  
 public double[] tdb_w(double v1,double v2,double P)
 {
 double tdb=v1;
 double tt=273.15;
 double w=v2;
 double pv=w/c*P/(1-w/c);
 double pa=P-pv;
 double ap[]=a.property((tdb+tt),pa);
 double va=ap[2];
 double apr[]=a.property(tt,pa);
 double ha=ap[3]-apr[3];
 double sa=ap[5]-apr[5];
 double sp[]=s.property("tp",tdb,pv);
 double hv=sp[3];
 double sv=sp[5];
 double h=ha+w*hv;
 double ss=sa+w*sv;
 double sps[]=s.property("tx",tdb,1.0);
 double sp1[]=s.property("px",pv,1.0);
 double tdp=sp1[1];
 double pvs=sps[0];
 double rh=pv/pvs;
 double aa[]=new double[14];
  aa[0]=P;
  aa[1]=tdb;
  aa[2]=va;
  aa[3]=pv;
  aa[4]=pa;
  aa[5]=w;
  aa[6]=rh;
  aa[7]=rh;//degree of saturation
  aa[8]=h;
  aa[9]=ss;
  aa[10]=tdp;
  aa[11]=ha;
  aa[12]=hv;
  aa[13]=w*hv;
  // System.out.println("w="+"pv="+pv+"pvs="+pvs+"rh="+rh);
 return aa;
 }
 public double[] property(String s,double v1,double v2,double P)
 {  
	 //if(s.equals("tdb_w")) 
	 return tdb_w(v1,v2,P); 
 }
 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______";
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____________________";
   double pp[]=property(si,v1,v2,P);
   for(int i=0;i<14;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;
 } 
 public String toString(String s[][])
 {String s1="";
 for(int i=0;i<s.length;i++)
 {for(int j=0;j<s[0].length;j++)
  {s1+=s[i][j];}
  s1+="\n"; 
 }
 return s1;
 }
 
 public static void main(String arg[])
 {wet_N2 q=new wet_N2();
 String x[][]=q.toString1("tdb_w",200.0,0.01,1.01325);
 System.out.println(q.toString(x));
 }
}