// ==============================================================
// File Name    : Gmix.java
// Author       : Dr. Turhan Coban
// TUBITAK Ulusal Metroloji Enstitüs
// email        : Turhan.Coban@ume.tubitak.gov.tr
// Description  : This file contains class gmix which  calculates
// thermophysical properties of mixture of perfect gases.
//               following properties can be calculated
//               T()     : Temperature degree K
//               h(T)    : enthalpy  KJ/kmol
//               hf      : formation enthalpy KJ/kg
//               ht(T)   : total enthalpy KJ/kg (h+hf)
//               M       : molar mass kg/kmol
//               HT(T)   : total enthalpy KJ : M*ht(T)
//               P()     : presure bar
//               s(T,P)  : entropy KJ/kmol K
//               Cp(T)   : specific heat at constant pressure KJ/kmol K
//               Cv(T)   : specific heat at constant volume KJ/kg K
//               gamma(T): adiabatic constant Cp/Cv
//               c(T)    : speed of sound m/s
//               u(T)    : Internal energy KJ/kmol
//               vis(T)  : viscosity
//               k(T)    : thermal conductivity KW/kg K
// DATA FILE DEFINATION
// gas mixture definations are given the data file "Gmix.txt"
// if gas mixture data is not given in the Gmix.txt user can be add
// his own data to the file which has the following format
//------------------
// gmixName
// ngas
// gname_0 N_0
// .........
// gname_ngas-1 N_ngas-1
//-------------------
// and defination : gmix a(gmixName); will defined this gas mixture
// the same mixture can be defined directly in the main program as :
// -------------------
// Gas a_0=new Gas("a_0");
//.......
// Gas a_ngas=new Gas("a_ngas);
// Gmix a=new Gmix;
// a=N_0*a_0+...+N_ngas*a_ngas;
// -------------------
//============================================================
//  VARIABLE IDENTIFICATION
// all the variables that type is not defined is a double variable
// PUBLIC  VARIABLES :
// gasName  : String class variable of gas mixture name
// ngas     : int variable, number of simple gasses
// N   : total molar mass of the gas mixture
// gasList  :gas class vector variables
// All the other variables defined for class gas is also valid for gmix
import java.io.*;
import java.util.*;

// ==============================================================
   class Gmix1{
// this class calculates perfect gas thermodynamic
// properties when the perfect gas constitutes of
// several single gases
        boolean mole=false;
        boolean SI=true;
        public int ngas;  // number of simple gasses inside of the gas mixture
        String gasName;
        public double M;  // molar mass of atom kg/kmol
        public double h0; // enthalpy at T=298 K
        public double hf; // enthalpy of formation
        public double sf; // entropy of formation    kJ/kmol K
        public double N;  // moles of gas kmol
        int ierror;
        int natom;          //number of unique atoms in the atom list
        Gas1  gasList[];     //list of the component gasses
        Atom atomList[];    //list of component atoms
        File gmixFile;      // File name and directory
        BufferedReader cfin;
        // construction methods :
//========definations of class gmix =============================
//constructor functions
	public Gmix1(String name) throws IOException
	{readgas(name);}
// ==============================================================
public String readGmixNames() throws IOException
{
    String temp=readgas("");
    return temp;
}

// ==============================================================

public void arrange_atoms()  
{
int i,j;
      for(i=0;i<ngas;i++)
      {  int nn=gasList[i].natom;
	     for(j=0;j<nn;j++)
	     {
             add_atom(i,j);
             }
      }
}

public int  add_atom(int i,int j)  
{
int k;
//Atom tempAtom=new Atom(gasList[i].atomList[j].symbol,gasList[i].atomList[j].N*gasList[i].N/N);
for(k=0;k<natom;k++)
{
//String s0=gasList[i].gasName;
String s1=gasList[i].atomList[j].symbol;
String s2=atomList[k].symbol;
if(s1.equals(s2))
  {
  atomList[k]=new Atom(atomList[k].symbol,atomList[k].N+gasList[i].atomList[j].N*gasList[i].N/N);
  return 1;
  }
}
Atom atomL[];
atomL=new Atom[natom+1];
for(k=0;k<natom;k++)
atomL[k]=new Atom(atomList[k]);
atomL[natom]=new Atom(gasList[i].atomList[j].symbol,gasList[i].atomList[j].N*gasList[i].N/N);
atomList=atomL;
natom+=1;
return 2;
}

//===============================================================
   public Gmix1() throws IOException
   {readgas("air");}

// ==============================================================
	public Gmix1(Gmix1 g1) throws IOException
	{
	gasName=g1.gasName;
	gasName=gasName;
	N=g1.N;
	M=g1.M;
        hf=g1.hf;
	ngas=g1.ngas;
        natom=g1.natom;
	gasList=new Gas1[ngas];
	for(int i=0;i<ngas;i++) gasList[i]=new Gas1(g1.gasList[i]);
        for(int i=0;i<natom;i++) atomList[i]=new Atom(g1.atomList[i]);
        }
// ==============================================================
    public Gmix1(Gas1 g1) throws IOException
	{
	gasName=g1.gasName;
	gasName=gasName;
	N=g1.N;
	M=g1.M;
        hf=g1.hf;
        ngas=1;
        natom=g1.natom;
	gasList=new Gas1[ngas];
        for(int i=0;i<ngas;i++) gasList[i]=new Gas1(g1);
        for(int i=0;i<natom;i++) atomList[i]=new Atom(g1.atomList[i]);
        }
        
    public Gmix1(String gn,Gas1 g1[]) throws IOException
	{
	gasName=gn;;
    for(int i=1;i<g1.length;i++)
      {add(g1[i]);} 
    }
// ==============================================================
    public void changeN(double newN) throws IOException
	{
	normalise();
	for(int i=0;i<ngas;i++)
	  { gasList[i].N*=newN; }
          N=newN;
	}

	public boolean base(String s)
    {
    if(s.equals("mole")) {mole=true;for(int i=0;i<ngas;i++){ gasList[i].mole=true; }}
    else                 {mole=false;for(int i=0;i<ngas;i++){ gasList[i].mole=false;}}
    return mole;
    }

    public boolean unit(String s)
    {
    if(s.equals("SI")) {SI=true;for(int i=0;i<ngas;i++){ gasList[i].SI=true; }}
    else               {SI=false;for(int i=0;i<ngas;i++){ gasList[i].SI=false; }}
    return SI;
    }
// ==============================================================
	public void add(Gas1 g1) throws IOException
	{
	// this function adds a single gas to the mixture
        int gasflag=1;
        // if the gas exist in the list simply change N and M values
	for(int i=0;i<ngas;i++)
	{
	if(gasList[i].gasName.equals(g1.gasName))
	   {
	   gasflag=0;
           M=M*N+g1.M*g1.N;
	   gasList[i].N+=g1.N;
           N+=g1.N;
           M=M/N;
           }
	}
	if(gasflag!=0)
          {
	  Gas1 newGas[];
	  newGas=new Gas1[ngas+1];
	  for(int i=0;i<ngas;i++)
	  {
	  newGas[i]=new Gas1(gasList[i]);
	  }
	  ngas++;
	  double MT=M*N+g1.M*g1.N;
	  N+=g1.N;
	  M=MT/N;
	  newGas[ngas-1]=new Gas1(g1);
	  gasList=newGas;
          }
        arrange_atoms();
        }
// ==============================================================
	public void remove(String name) throws IOException
	{
	// this function removes a  single gas
	// from the list
    int i,k;
	for(i=0;i<ngas;i++)
	  {
	    if(gasList[i].gasName.equals(name))
	      {
	      	Gas1 newGas[];
		    newGas=new Gas1[ngas];
                M=0;
                N=0;
		for(k=0;k<i;k++)
		{ newGas[k]=new Gas1(gasList[k]);
		  M+=newGas[k].M*newGas[k].N;
		  N+=newGas[k].N;
		}
		for( k=i;k<(ngas-1);k++)
		{
		  newGas[k]=new Gas1(gasList[k+1]);
		  M+=newGas[k].M*newGas[k].N;
          N+=newGas[k].N;
		}
		M=M/N;
	      ngas--;
	    gasList=newGas;
	    break;
	      }
	  }
        arrange_atoms();
        // correct dynamic memory size
	}
// ==============================================================
	public void add(String name,double Nnew) throws IOException
	{
	// this function adds a single gas to the mixture
        Gas1 g1=new Gas1(name,Nnew);
        int gasflag=1;
        // if the gas exist in the list simply change N and M values
	for(int i=0;i<ngas;i++)
	{
	if(gasList[i].gasName.equals(g1.gasName))
	   {
	   gasflag=0;
           M=M*N+g1.M*g1.N;
	   gasList[i].N+=g1.N;
           N+=g1.N;
           M=M/N;
           }
	}
	if(gasflag!=0)
          {
	  Gas1 newGas[];
	  newGas=new Gas1[ngas+1];
	  for(int i=0;i<ngas;i++)
	  {
	  newGas[i]=new Gas1(gasList[i]);
	  }
	  ngas++;
	  double MT=M*N+g1.M*g1.N;
	  N+=g1.N;
	  M=MT/N;
	  newGas[ngas-1]=new Gas1(g1);
	  gasList=newGas;
          }
        arrange_atoms();
        }
// ==============================================================

	public void   simplify() throws IOException
	{
	// this function combines any  single gas
	// that repeated in the list
        double ngasold=ngas;
    int i,j,k;
	for(i=0;i<ngas;i++)
	  {
	  for(j=i+1;j<ngas;j++)
	    {
	    if(gasList[i].gasName.equals(gasList[j].gasName))
	      {
	      gasList[i].N+=gasList[j].N;
	      for(k=j;k<(ngas-1);k++)
	        { gasList[k]=new Gas1(gasList[k+1]); }
	      ngas--;
	      }
	    }
	  }
        // correct dynamic memory size
	if(ngasold!=ngas)
        {
	Gas1 newGas[];
	newGas=new Gas1[ngas];
	for(i=0;i<ngas;i++)
	  {
          newGas[i]=new Gas1(gasList[i]);
	  }
	gasList=newGas;
	}
        }
// ==============================================================
public void  normalise() throws IOException
{
for(int i=0;i<ngas;i++)
  {
  gasList[i].N=gasList[i].N/N;
  }
N=1.0;
arrange_atoms();
}
// ==============================================================
public void changeMix(double Nmix[]) throws IOException
   {
   // this function changes
	// all the molar weights in the mixture
   N=0;
   M=0;
	for(int i=0;i<ngas;i++)
   {
   gasList[i].N=Nmix[i];
   N+=Nmix[i];
   M+=Nmix[i]*gasList[i].M;
   }
   M=M/N;
   arrange_atoms();
	}
// ==============================================================
  public double  vis(double T)
   {
   // dynamic viscosity of the mixture
   // note that viscosity of the mixture IS NOT the simple addition
   // of viscosity of component gasses
      double vmix=0;
   for(int i=0;i<ngas;i++)
     {
     T=T;
     double fij;
     double xj=0;
     double p1;
     double c1,c2,c3;
     for(int j=0;j<ngas;j++)
       {
       double vratio;
       double xi=gasList[i].M/gasList[j].M;
       if(gasList[j].vis(T)!=0)
         {
	     c1=gasList[i].vis(T)/gasList[j].vis(T);
	     vratio=Math.sqrt(c1);
	     }
       else
	     vratio=0;
	   c2=Math.pow(xi,0.25);
	   p1=(1+vratio/c2);
	   c3=8.0+8.0*xi;
	   fij=p1*p1 / Math.sqrt(c3);
       xj+=fij*gasList[j].N/N;
       }
     vmix+=gasList[i].N/N*gasList[i].vis(T)/xj;
     }
   return vmix;
   }
// ==============================================================
   public double  k(double T)
   {
   // thermal conductivity of the mixture
   // note that thermal conductivity  of the mixture IS NOT the
   // simple addition of the thermal conductivity  of component gasses
   double vmix=0;
   for(int i=0;i<ngas;i++)
     {
     T=T;
     double fij;
     double xj=0;
     double p1;
     double c1,c2,c3;
     for(int j=0;j<ngas;j++)
       {
       double vratio;
       double xi=gasList[i].M/gasList[j].M;
       if(gasList[j].k(T)!=0)
           {
	        c1=gasList[i].k(T)/gasList[j].k(T);
//           if(c1<0) System.out.println("negative c1 value ");
	        vratio=Math.sqrt(c1);
	       }
       else
	       vratio=0;
       c2=Math.pow(xi,0.25);
       p1=(1+vratio/c2);
       c3= 8.0+8.0*xi;
//       if(c2<0) System.out.println(" negative c2 value ");
       fij=p1*p1/Math.sqrt(c3);
       xj+=fij*gasList[j].N/N;
       }
     vmix+=gasList[i].N/N*gasList[i].k(T)/xj;
     }
   return vmix;
   }
// ==============================================================
   public double  Prandtl(double t)
   {
   // Prandtl number
   return Cp(t)*vis(t)/k(t)/M*1e3;
   }
// ==============================================================
   public double  h(double T)
   {
   //specific enthalpy of the mixture KJ/kmol
   double HH=0;
   for(int i=0;i<ngas;i++)
	{ HH+=gasList[i].h(T)*gasList[i].N; }
	return HH/N;
   }
// ==============================================================
   public double  ht(double T)
   {
   //specific  enthalpy of the mixture ht=h+hf
   // hf : formation enthalpy
   double HH=0;
   for(int i=0;i<ngas;i++)
	{ HH+=gasList[i].ht(T)*gasList[i].N; }
   return HH/N;
   }
// ==============================================================
   public double  H(double t)
   {
   //total enthalpy of the mixture KJ
   return h(t)*N;
   }
// ==============================================================
   public double  HT(double t)
   //total enthalpy of the mixture HT=N*(h+hf)  KJ
   {
   return ht(t)*N;
   }
// ==============================================================
   public double  u(double T)
   {
   // specific internal energy of the mixture  KJ/kmol
   double UU=0;
   for(int i=0;i<ngas;i++)
	{ UU+=gasList[i].u(T)*gasList[i].N; }
   return UU/N;
   }
//===================================================================
public double g(double T,double P)
{
  return h(T)-T*s(T,P);
}

public double gt(double T,double P)
{
  return h(T)+hf-T*s(T,P);
}

public double gt(double T)
{
  double Pref;
  if(!SI) {Pref=14.503684;}
  else {Pref=1.0;}
  return h(T)+hf-T*s(T,Pref);
}


public double g(double T)
{
  double Pref;
  if(!SI) {Pref=14.503684;}
  else {Pref=1.0;}
  return h(T)-T*s(T,Pref);
}

public double G(double T,double P)
{
 return g(T,P)*N;
}

public double G(double T)
{
 return g(T)*N;
}

public double GT(double T)
{
 return gt(T)*N;
}

public double GT(double T,double P)
{
 return gt(T,P)*N;
}
// ==============================================================
   public double  Cp(double T)
   {
   // Specific energy at constant pressure  KJ/kmol K
   double C=0;
	for(int i=0;i<ngas;i++)
	{ C+=gasList[i].Cp(T)*gasList[i].N; }
   return C/N;
   }
// ==============================================================
   public double  Cv(double T)
   //Specific energy at constant volume  KJ/kmol K
   {
   double C=0;
   for(int i=0;i<ngas;i++)
	{ C+=gasList[i].Cv(T)*gasList[i].N; }
   return C/N;
   }
// ==============================================================
   public double  gamma(double T)
   {
   //adiabatic constant
   return Cp(T)/Cv(T);
   }
// ==============================================================
   public double  c(double T)
   //speed of sound m/s
   {
   return Math.sqrt(8314.5/M*T*gamma(T));
   }
// ==============================================================
   public double  s(double T, double P)
   {
   //specific entropy KJ/kmol K
   double SS=0;
   for(int i=0;i<ngas;i++)
	{
	SS+=gasList[i].s(T,P)*gasList[i].N;
	}
   return SS/N;
	}

   public double  s(double T)
   {
   //specific entropy KJ/kmol K
   double P=1.0;
   double SS=0;
   for(int i=0;i<ngas;i++)
	{
	SS+=gasList[i].s(T,P)*gasList[i].N;
	}
   return SS/N;
	}
	public double pr(double T)
{
double Tref, Rref;
  if(!SI) {Tref=491.67;Rref=1.986;}
  else {Tref=273.15;Rref=8.3145;}
  if(!mole) Rref/=M;
  return Math.exp((s(T)-s(Tref))/Rref);
}

public double vr(double T)
{
  double Rref;
  if(!SI) {Rref=1.986;}
  else {Rref=8.3145;}
  return (Rref/M)*T/pr(T)*10;
}

// ==============================================================
   public double  v(double T, double P)
   {
   double VV=0;
   for(int i=0;i<ngas;i++)
	{ VV+=gasList[i].v(T,P)*gasList[i].N; }
   return VV/N;
   }
// ==============================================================
public double  T( char name,double y0,double p)
{
double t=300;
if(name=='v') {t= p*1e5*y0/8.314e3;}
else
  {
  double dt;
  int nmax=400;
  double tolerance=1.0e-8;
  for(int i=0;i<nmax;i++)
    {
    if     (name=='h') dt=-( h(t)   - y0 ) /Cp(t);
    else if(name=='u') dt=-( u(t)   - y0 ) /Cv(t);
    else if(name=='s') dt=-( s(t,p) - y0 ) /(Cp(t)/t);
	 else { System.out.println("wrong name defined please try h,u,s ot v"); break;}
    t+=dt;
    if(Math.abs(dt)<tolerance) break;
    }
  }
return t;
}
// ==============================================================
public double  P( char name,double y0,double t1)
{
if(name=='v')       return 8.314e3*t1/y0*1e-5;
else if (name=='s') return Math.exp((s(t1,1.0)-y0)/8.314);
else { System.out.println("wrong name defined please try s or v"); return 1.0;}
}
// ==============================================================
public void  multiplyassign(double Nx)
{
	for(int i=0;i<ngas;i++)
	  { gasList[i].N*=Nx; }
	N*=Nx;
}
// ==============================================================
public void addassign(Gas1 g1) throws IOException
{
	// this function adds a single gas to the mixture
        int gasflag=1;
        // if the gas exist in the list simply change N and M values
	for(int i=0;i<ngas;i++)
	{
	if(gasList[i].gasName==g1.gasName)
	   {
	   gasflag=0;
           M=M*N+g1.M*g1.N;
	   gasList[i].N+=g1.N;
           N+=g1.N;
           M=M/N;
           }
	}
	if(gasflag!=0)
          {
	  Gas1 newGas[];
	  newGas=new Gas1[ngas+1];
	  for(int i=0;i<ngas;i++)
	  {
	  newGas[i]=new Gas1(gasList[i]);
	  }
	  ngas++;
	  double MT=M*N+g1.M*g1.N;
	  N+=g1.N;
	  M=MT/N;
	  newGas[ngas-1]=new Gas1(g1);
	  gasList=newGas;
          }
}
// ==============================================================
public void addassign(Gmix1 right) throws IOException
{
 	// this function adds a gas mixture to the mixture
	for(int i=0;i<right.ngas;i++)
	{
        add(right.gasList[i]);
	}
}
// ==============================================================
public Gmix1 multiply( double Nx,Gmix1 right) throws IOException
{
Gmix1 g1=new Gmix1(right);
g1.N*=Nx;
for(int i=0;i<g1.ngas;i++)
  {
  g1.gasList[i].N*=Nx;
  }
return g1;
}
// ==============================================================
public Gmix1 add(Gas1 l,Gas1 r) throws IOException
{
 Gmix1 g1=new Gmix1(r);
 Gas1 g2=new Gas1(l);
 g1.add(g2);
 return  g1;
}
// ==============================================================
public Gmix1 add(Gmix1 l,Gas1 r) throws IOException
{
Gmix1 g1=new Gmix1(l);
Gas1 g2=new Gas1(r);
g1.add(g2);
return  g1;
}
// ==============================================================
public Gmix1  add(Gas1 l,Gmix1 r) throws IOException
{
Gmix1 g1=new Gmix1(r);
Gas1 g2=new Gas1(l);
g1.add(g2);
return g1;
}
// ==============================================================
public Gmix1 add(Gmix1 l,Gmix1 r) throws IOException
{
Gmix1 g1=new Gmix1(l);
for(int i=0;i<r.ngas;i++)
	{
	g1.add(r.gasList[i]);
	}
return g1;
}
// ==============================================================
public void  assign(Gmix1 g1) throws IOException
{
	gasName=g1.gasName;
	N=g1.N;
	M=g1.M;
	ngas=g1.ngas;
	Gas1 newGas[];
    newGas=new Gas1[ngas];
	for(int i=0;i<ngas;i++) newGas[i]=g1.gasList[i];
        gasList = newGas;
}
// ==============================================================
public void assign(Gas1  g1) throws IOException
{
// a single gas is assigned to the mixture
   gasName=g1.gasName;
   N=g1.N;
   M=g1.M;
   ngas=1;
   gasList=new Gas1[ngas];
   gasList[0]=new Gas1(g1);
}

public String toString(String ch)
{
//return the c
String s="";
int i,j;
if(ch.equals("name"))
   s=s+gasName+"\n";
else if(ch.equals("formula"))
{
  for(i=0;i<ngas;i++)
  { s=s+" "+gasList[i].toString()+" "+gasList[i].N+"\n"; }
}
else if(ch.equals("composition"))
{
for(i=0;i<natom;i++)
  s=s+atomList[i].toString()+"\n";
}
return s;
}

public String[][] toString1(double v1, double v2)
{
  String s1[][]=new String[20][3];
   s1[0][0]="P, basınç                    ";
   s1[1][0]="T, sıcaklık                  ";
   s1[2][0]="v, özgül hacim               ";
   s1[3][0]="   yoğunluk                  ";
   s1[4][0]="h, entalpi                   ";
   s1[5][0]="u, iç enerji                 ";
   s1[6][0]="s, entropi                   ";
   s1[7][0]="g, qibbs serbest enerjisi    ";
   s1[8][0]="ht,kimyasal toplam entalpi   ";
   s1[9][0]="gt,kimyasal toplam gibbs s.e.";
   s1[10][0]="Cp, sabit basınçta özgül ısı ";
   s1[11][0]="Cv, sabit hacimde özgül ısı ";
   s1[12][0]="Cp/Cv, adyabatik sabit      ";
   s1[13][0]="c, ses hızı                 ";
   s1[14][0]="vizkozite                   ";
   s1[15][0]="ısıl iletkenlik katsayısı   ";
   s1[16][0]="M, moleküler ağırlık        ";
   s1[17][0]="Prandtl sayısı              ";
   s1[18][0]="Pr, indirgenmiş basınç      ";
   s1[19][0]="vr, indirgenmiş hacim       ";

   if(SI && !mole)
   {
   s1[0][2]=" bar          ";
   s1[1][2]=" derece K         ";
   s1[2][2]=" m^3/kg        ";
   s1[3][2]=" kg/m^3        ";
   s1[4][2]=" KJ/kg         ";
   s1[5][2]=" KJ/kg         ";
   s1[6][2]=" KJ/kg K       ";
   s1[7][2]=" KJ/kg         ";
   s1[8][2]=" KJ/kg         ";
   s1[9][2]=" KJ/kg         ";
   s1[10][2]=" KJ/kg K        ";
   s1[11][2]=" KJ/kg K       ";
   s1[12][2]="               ";
   s1[13][2]=" m/s           ";
   s1[14][2]=" Ns/m^2        ";
   s1[15][2]=" W/m K         ";
   s1[16][2]=" kg/kmol       ";
   s1[17][2]="               ";
   s1[18][2]="               ";
   s1[19][2]="               ";
   }
   else if(SI && mole)
   {
   s1[0][2]=" bar           ";
   s1[1][2]=" derece K      ";
   s1[2][2]=" m^3/kmol     ";
   s1[3][2]=" kmol/m^3     ";
   s1[4][2]=" KJ/kmol      ";
   s1[5][2]=" KJ/kmol      ";
   s1[6][2]=" KJ/kmol K    ";
   s1[7][2]=" KJ/kmol      ";
   s1[8][2]=" KJ/kmol      ";
   s1[9][2]=" KJ/kmol      ";
   s1[10][2]=" KJ/kmol K    ";
   s1[11][2]=" KJ/kmol K   ";
   s1[12][2]="               ";
   s1[13][2]=" m/s           ";
   s1[14][2]=" Ns/m^2        ";
   s1[15][2]=" W/m K         ";
   s1[16][2]=" kg/kmol       ";
   s1[17][2]="               ";
   s1[18][2]="               ";
   s1[19][2]="               ";
   }
   else if(!SI && mole)
   {
   s1[0][2]=" lbf/in^2, psia  ";
   s1[1][2]=" derece R        ";
   s1[2][2]=" ft^3/lbmole     ";
   s1[3][2]=" lbmole/ft^3     ";
   s1[4][2]=" BTU/lbmole      ";
   s1[5][2]=" BTU/lbmole      ";
   s1[6][2]=" BTU/lbmole K    ";
   s1[7][2]=" BTU/lbmole      ";
   s1[8][2]=" BTU/lbmole      ";
   s1[9][2]=" BTU/lbmole      ";
   s1[10][2]=" BTU/lbmole K   ";
   s1[11][2]=" BTU/lbmole K   ";
   s1[12][2]="                ";
   s1[13][2]=" ft/s           ";
   s1[14][2]=" lbm/(ft.s)     ";
   s1[15][2]=" BTU/(hr ft R)  ";
   s1[16][2]=" lbm/lbmole     ";
   s1[17][2]="                ";
   s1[18][2]="                ";
   s1[19][2]="                ";
   }
   else if(!SI && !mole)
   {
   s1[0][2]=" lbf/in^2, psia  ";
   s1[1][2]=" deg R           ";
   s1[2][2]=" ft^3/lbm     ";
   s1[3][2]=" ft^3/lbm     ";
   s1[4][2]=" BTU/lbm      ";
   s1[5][2]=" BTU/lbm      ";
   s1[6][2]=" BTU/lbm K    ";
   s1[7][2]=" BTU/lbm      ";
   s1[8][2]=" BTU/lbm      ";
   s1[9][2]=" BTU/lbm      ";
   s1[10][2]=" BTU/lbm K    ";
   s1[11][2]=" BTU/lbm K   ";
   s1[12][2]="                ";
   s1[13][2]=" ft/s           ";
   s1[14][2]=" lbm/(ft.s)     ";
   s1[15][2]=" BTU/(hr ft R)  ";
   s1[16][2]=" lbm/lbmole     ";
   s1[17][2]="                ";
   s1[18][2]="                ";
   s1[19][2]="                ";
   }
   double pp[]=property(v1,v2);
   for(int i=0;i<20;i++)
   {s1[i][1]=""+pp[i];}
return s1;
}

public double[] property(double t, double p)
{
double pp[]=new double[20];
pp[0]=p;
pp[1]=t;
pp[2]=v(t,p);
pp[3]=1.0/pp[2];
pp[4]=h(t);
pp[5]=u(t);
pp[6]=s(t,p);
pp[7]=g(t,p);
pp[8]=ht(t);
pp[9]=gt(t,p);
pp[10]=Cp(t);
pp[11]=Cv(t);
pp[12]=gamma(t);
pp[13]=c(t);
pp[14]=vis(t);
pp[15]=k(t);
pp[16]=M;
pp[17]=Prandtl(t);
pp[18]=pr(t);
pp[19]=vr(t);
return pp;
}
public String readgasnames() {return readgas("");}

public String readgas(String gName)
{
String s="";
Vector gi=new Vector();
String s1[];
double n1[];
int nn;
	nn=1;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="air";n1[0]=1.0;
 if(gName.equals(null)||gName.equals("")) gName="hava";
{
	nn=6;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="ch4";n1[0]=0.906;
	s1[1]="c2h6";n1[1]=0.056;
	s1[2]="c3h8";n1[2]=8.0e-4;
	s1[3]="c4h10";n1[3]=2.0e-4;
	s1[4]="co2";n1[4]=0.017;
	s1[5]="n2";n1[5]=0.011;
	GmixData gasd=new GmixData("dogal_gaz",s1,n1);
	gi.addElement(gasd);
}
//else if(gName.equals("LPG") )
{
	nn=2;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="c3h8";n1[0]=0.3;
	s1[1]="c4h10";n1[1]=0.7;
	GmixData gasd=new GmixData("LPG",s1,n1);
	gi.addElement(gasd);
}
//else if(gName.equals("su buharı") )
{
	nn=1;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="h2o";n1[0]=1.0;
	GmixData gasd=new GmixData("su_buharı",s1,n1);
	gi.addElement(gasd);
}
//else if(gName.equals("hidrojen") )
{
	nn=1;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="h2";n1[0]=1.0;
	GmixData gasd=new GmixData("hidrojen",s1,n1);
	gi.addElement(gasd);
}
//else if(gName.equals("azot") )
{
	nn=1;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="n2";n1[0]=1.0;
	GmixData gasd=new GmixData("azot",s1,n1);
	gi.addElement(gasd);
}
//else if(gName.equals("hava") || gName.equals("hava"))
{
	nn=1;
	s1=new String[nn];
	n1=new double[nn];
	s1[0]="air";n1[0]=1.0;
	GmixData gasd=new GmixData("hava",s1,n1);
	gi.addElement(gasd);
}
ngas=nn;

String aName;
double aN;
ierror=1;

Enumeration ni1=gi.elements();
GmixData gasd=new GmixData("hava",s1,n1); ;
while(ni1.hasMoreElements())
{
   gasd=(GmixData)ni1.nextElement();
   s+=gasd.gmixName+" ";
   if (gasd.gmixName.equals(gName)) {ierror=0;break;}
}
        int i,j;
        N=0;
      	M=0;
        hf=0;
        natom=0;
	    gasName=gName;
        ngas=gasd.n;
        gasList=new Gas1[ngas];
        String pgasName;
        double ppercent;
        //Gas1 tempgas;
	    for(i=0;i<ngas;i++)
        {
        s+=gasd.name[i];
	        //tempgas=new Gas1(gasd.name[i],gasd.N[i]);
        gasList[i]=new Gas1(gasd.name[i],gasd.N[i]);
	    N+=gasList[i].N;
	    M+=gasList[i].N*gasList[i].M;
	    hf+=gasList[i].N*gasList[i].hf;
	    }
        M=M/N;
        hf=hf/N;
        arrange_atoms();
return s;
}      
      
}//end of class
