//package Lee_Kesler_Base;

//======================================================
// Thermodynamic Package in java
// Class Lee Kesler Properties of real gases
// Dr. Turhan Coban
// TUBİTAK UME(National metrology Institute of Turkey)
// email : Turhan.Coban@ume.tubitak.gov.tr
// File Name   : LeeKesler.java
// This file contains the LeeKesler class
// this class sets basic properties of real gases
// required data is read from LeeKesler.txt
// =======================================================
// Description : This file contains the LeeKesler class
//               class LeeKesler calculates thermophysical properties of
//               real fluids
// DATA FILE DEFINATION
// datas are written in the data file "RealGas.txt"
//========================================================
//  VARIABLE IDENTIFICATION
//========================================================
//  GasEquation : String type variable
//                values : "LeeKesler"
//
//
//  Formula     : Fluid chemical formula
//  Name        : Fluid name
//  atomList    : Array of atom class, structral information
//  natom       : number of atoms
//  M           : Molecular weight as calculated from atomic structure
//                through class atom and atomList
//  MolWt       : Molecular Weigth from data file RealGas
//  Tfp         : Normal freezing point (1 atm), K
//  Tb          : Normal Boiling point  (1 atm), K
//  Tc          : Critical temperature, K
//  Pc          : Critical pressure, bar
//  Vc          : Critical volume, cm^3/mole
//  Zc          : Critical compresibility factor PcVc/RTc
//  Omega       : Pitzer's accentric factor
//  Dipm        : Dipole moment, debyes
//  CPC         : constants array to calculate the isobaric heat capacity of
//                the ideal gas Cp kJ/(kmolK)
//  DELHF       : formation enthalpy, 298.2 K, 1.01325 bar, KJ/kmol
//  DELGF       : formation gibbs free energy, 298.2 K, 1.01325 bar,KJ/kmol
//  DELS0       : entropy at 298.2 K, 1.01325 bar, KJ/kmol K
//  Vpeq        : vapor pressure equation number
//  VPC         : vapor pressure equation coefficients (array)
//  Tmin        : minimum twmp. K
//  Tmax        : maximum temp. K
//  LDEN        : liquid density, g/cm^3
//  TDEN        : temperature that liquid density is given, K
//============================================================
// Reference : The Properties of Gases & Liquids,
// Robert C. Reid, John M. Prausnitz, Bruce E. Pouling
// McGraw-Hill Book Company, ISBN 0-07-051799-1
//==============================================

import java.io.*;
import java.util.*;

//==============================================
// implementation of constructors functions
// for class LeeKesler (Equation of state)

public class LeeKesler extends absfluid
{
   public String GasEquation;
   public int natom;
   public Atom atomList[];
   public  String Formula,Name;
   public double M,MolWt,Tfp,Tb,Tc,Pc,Vc,Zc,Omega,Dipm;//Tb normal bolilng point
   public double pro[]=new double[16];
   public double CPC[]=new double[4];
   public double VPC[]=new double[4];
   public double DELHF,DELGF,DELS0,DELHO;
   public int VPEq;
   public double Tmin,Tmax,LDEN,TDEN;
   public  int ierror;
   BufferedReader fin;
   public double R=8314.5; //(J/kmolK)
   double Pref=1.01325;//P reference bar for departure func 
   double Vref;
   double Tref=298.2;//K
   //Peng Robinson constants
   double a,b,u,w;  
   //
   //================================//
   // Equation of State coefficients //
   //================================//
   //Simple Fluid (omega=0) :
   //------------------------
   double b0[]=new double[4];
   double c0[]=new double[4];
   double d0[]=new double[2];
   double beta0;
   double gama0;
   double OmegaR;
   double wR;
   //Reference Fluid (n-octane):
   //------------------------
   double bR[]=new double[5];
   double cR[]=new double[5];
   double dR[]=new double[3];
   double betaR;
   double gamaR;
   public  double N;
   boolean mole=false;
   /* For better water steam property estimation  */
   steam st=new steam();
   //Better ideal gas Cp approximation for these gas
   Gas1 id_gas;
   boolean better_Cp=false;
   String[] Gas_Cp={"AIR","C","O","C9H20","C9H20G","C10H22","C11H24","C12H26","C13H28","C14H30","C15H32","C16H34","C17H36","C18H38","C19H40","C20H42","C11H16",
"C12H18","C13H20","C14H22","C15H24","C16H26","C17H28","C18H30","C19H32","C10H8","C11H10","C12H12","CH4","C2H6","C2H4","C3H8","C4H10","C5H12","CH3OH","C8H18",
"SO2","SO3","C2H2","C6H6","H2O2","NH3","H2","H2O","H2OL","ARGON","CO","CO2","H","HO","OH","N","N2","N2O","NO","NO2","O2","E-","C13H14","C14H16"};   
//===================================================================
//constructor methods for Lee Kesler

   public LeeKesler(){
   // isobutane is assumed to be initial fluid
   try{ startup("isobutane",1.0); }
   catch(IOException e){}
   }
   
   
   public LeeKesler(String s2){try{ startup(s2,1.0); }
   catch(IOException e){}
   }
   
   
   public LeeKesler(String s2,double Ne){
   try{ startup(s2,Ne); }
   catch(IOException e){}
   }
   public LeeKesler(LeeKesler lk){
   try{ startup(lk.Name,lk.N); }
   catch(IOException e){}
   }
   
   public void startup(String  s1,double Ne) throws IOException{  
   GasEquation="Lee - Kesler";   
   //setting the simple fluid coefficients :
   b0[0]=0.1181193;
   b0[1]=0.265728;
   b0[2]=0.15479;
   b0[3]=0.030323;
   c0[0]=0.0236744;
   c0[1]=0.0186984;
   c0[2]=0.0;
   c0[3]=0.042724;
   d0[0]=0.155488e-4;
   d0[1]=0.623689e-4;
   beta0=0.65392;
   gama0=0.060167;
   OmegaR=0.3978;
   //setting the reference fluid coefficients :
   bR[0]=0.2026579;
   bR[1]=0.331511;
   bR[2]=0.027655;
   bR[3]=0.203488;
   cR[0]=0.0313385;
   cR[1]=0.0503618;
   cR[2]=0.016901;
   cR[3]=0.041577;
   dR[0]=0.48736e-4;
   dR[1]=0.0740336e-4;
   betaR=1.226;
   gamaR=0.03754;
   wR=0.3978;
   int i;
   String atomName[];
   double atomN[];
   int anatom;
   ierror=1;
   String tempName="";
   String tempFormula="";
   String aFormula,aName;
   double aMolWt,aTfp,aTb,aTc,aPc,aVc,aZc,aOmega,aDipm ;
   double aCPC[]=new double[4];
   double aDELHF,aDELGF,aDELS0;
   int aVPEq;
   double aVPC[]=new double[4];
   double aTmin,aTmax,aLDEN,aTDEN ;   
   for(int j=0;j<Gas_Cp.length;j++)  {
		if(s1.toUpperCase().equals(Gas_Cp[j])){
			better_Cp=false;
			//better_Cp=true;	
			id_gas=new Gas1(s1.toLowerCase());	
		}	
	}
   try{
       //fin=new BufferedReader(new FileReader(new File("data"+File.separator+ "RealGas.txt")));
       fin=new BufferedReader(new FileReader(new File("RealGas.txt")));
       } catch(IOException e)
         {
         System.err.println("Error Opening File RealGas.dat\n"+e.toString());
         System.exit(1);
         }
   try{
      while(fin!=null)
         {
         aFormula=Text.readString(fin);
         aName=Text.readString(fin);
         //System.out.println(aFormula+" "+aName);
         anatom=Text.readInt(fin);
         atomName=new String[anatom];
         atomN=new double[anatom];
         for(i=0;i<anatom;i++)
         {
         atomName[i]=Text.readString(fin);
         atomN[i]=Text.readDouble(fin);
         }
         aMolWt=Text.readDouble(fin);         
         aTfp=Text.readDouble(fin);         
         aTb=Text.readDouble(fin);
         aTc=Text.readDouble(fin);
         aPc=Text.readDouble(fin);
         aVc=Text.readDouble(fin);
         aZc=Text.readDouble(fin);
         aOmega=Text.readDouble(fin);
         aDipm=Text.readDouble(fin);
         for(int ii=0;ii< aCPC.length;ii++)
         { aCPC[ii]=Text.readDouble(fin);
         //System.out.println(aCPC[ii]);
          }
         aDELHF=Text.readDouble(fin);
         aDELGF=Text.readDouble(fin);
         aDELS0=Text.readDouble(fin);
         aVPEq=Text.readInt(fin);
         for(int ii=0;ii< aVPC.length;ii++)
         { aVPC[ii]=Text.readDouble(fin); }
         aTmin=Text.readDouble(fin);
         aTmax=Text.readDouble(fin);
         aLDEN=Text.readDouble(fin);
         aTDEN=Text.readDouble(fin);
        
         //System.out.println(aDELHF);
         //System.out.println(aDELGF);
         //System.out.println(aDELS0);
         //System.out.println(aTc);
         //System.out.println(aPc);
         //System.out.println(aVc);
         //System.out.println(aZc);
         //System.out.println(aOmega);
         //System.out.println(aDipm); 
         //System.out.println("Name= "+aName);         
         if (aName.equals(s1) || aFormula.equals(s1) || aFormula.equals(s1.toUpperCase()) )
         {
         Name=aName;         
         Formula=aFormula;
         MolWt=aMolWt;
         Tfp=aTfp;
         Tb=aTb;
         Tc=aTc;
         Pc=aPc;
         Vc=aVc;
         Zc=aZc;
         Omega=aOmega;
         Dipm=aDipm;
         for(int ii=0;ii< CPC.length;ii++)
         { CPC[ii]=aCPC[ii]; }
         //DELHF= ((better_Cp) ? id_gas.hf : aDELHF);
         //DELGF=((better_Cp) ? (id_gas.hf-298.2*id_gas.sf) : aDELGF);
         DELHF=aDELHF;
         DELGF=aDELGF;
         DELS0=aDELS0;
         VPEq=aVPEq;
         for(int ii=0;ii< VPC.length;ii++)
         { VPC[ii]=aVPC[ii]; }
         Tmin=aTmin;
         Tmax=aTmax;
         LDEN=aLDEN;
         TDEN=aTDEN;
         natom=anatom;
         N=Ne;
         atomList=new Atom[natom];
         M=0;
         for(i=0;i<natom;i++)
         {
         atomList[i]=new Atom(atomName[i],atomN[i]);
         M+=atomList[i].mass;
         }
         ierror=0;
         break;
         }
         }
      } catch(EOFException e_eof)
        {
        System.out.println("errorii required gas "+s1+" is not found");
        System.exit(1);
        fin.close();
        return;
        }
        fin.close();
        
   }
   
      public static String[] readgasnames() throws IOException{  
   Vector<String> v1=new Vector<String>();
   BufferedReader fin;
   String[] inner_gasnames;
	      int i;
   String inner_atomName[];
   double inner_atomN[];
   int inner_anatom;
   int inner_ierror=1;
   String inner_tempName="";
   String inner_tempFormula="";
   String inner_aFormula,inner_aName;
   double inner_aMolWt,inner_aTfp,inner_aTb,inner_aTc,inner_aPc,inner_aVc,inner_aZc,inner_aOmega,inner_aDipm ;
   double inner_aCPC[]=new double[4];
   double inner_aDELHF,inner_aDELGF,inner_aDELS0;
   int inner_aVPEq;
   double inner_aVPC[]=new double[4];
   double inner_aTmin,inner_aTmax,inner_aLDEN,inner_aTDEN ;   
      try{
       //fin=new BufferedReader(new FileReader(new File("data"+File.separator+ "RealGas.txt")));
       fin=new BufferedReader(new FileReader(new File("RealGas.txt")));
      /* } catch(IOException e)
         {
         System.err.println("Error Opening File RealGas.dat\n"+e.toString());
         System.exit(1);
         }*/
   
      while(fin!=null)
      {
         inner_aFormula=Text.readString(fin);
         inner_aName=Text.readString(fin);
         v1.addElement(inner_aFormula); 
        //  System.out.println(aName);
         inner_anatom=Text.readInt(fin);
         inner_atomName=new String[inner_anatom];
         inner_atomN=new double[inner_anatom];
         for(i=0;i<inner_anatom;i++)
         {
         inner_atomName[i]=Text.readString(fin);
         inner_atomN[i]=Text.readDouble(fin);
         }
         inner_aMolWt=Text.readDouble(fin);         
         inner_aTfp=Text.readDouble(fin);         
         inner_aTb=Text.readDouble(fin);
         inner_aTc=Text.readDouble(fin);
         inner_aPc=Text.readDouble(fin);
         inner_aVc=Text.readDouble(fin);
         inner_aZc=Text.readDouble(fin);
         inner_aOmega=Text.readDouble(fin);
         inner_aDipm=Text.readDouble(fin);
         for(int ii=0;ii< inner_aCPC.length;ii++)
         { inner_aCPC[ii]=Text.readDouble(fin);
         //System.out.println(aCPC[ii]);
          }
         inner_aDELHF=Text.readDouble(fin);
         inner_aDELGF=Text.readDouble(fin);
         inner_aDELS0=Text.readDouble(fin);
         inner_aVPEq=Text.readInt(fin);
         for(int ii=0;ii< inner_aVPC.length;ii++)
         { inner_aVPC[ii]=Text.readDouble(fin); }
         inner_aTmin=Text.readDouble(fin);
         inner_aTmax=Text.readDouble(fin);
         inner_aLDEN=Text.readDouble(fin);
         inner_aTDEN=Text.readDouble(fin);         
        /* for(i=0;i<natom;i++){
         	atomList[i]=new Atom(atomName[i],atomN[i]);
         	M+=atomList[i].mass;
         } */               
       }
        fin.close();
      } catch(EOFException e_eof)
        {       
        inner_gasnames=new String[v1.size()];
        int k=0;
         for (Enumeration e = v1.elements() ; e.hasMoreElements() ;k++) {
         inner_gasnames[k]=(String)e.nextElement();
     }
        return inner_gasnames;       
        }
        int j=0;
          inner_gasnames=new String[v1.size()];
         for (Enumeration e = v1.elements() ; e.hasMoreElements() ;j++) {
         inner_gasnames[j]=(String)e.nextElement();
     }
        return inner_gasnames;
        
   }
   
   
   public String toString(){
   //return the chemical symbol of the gas
   String s="";
   for(int i=0;i<natom;i++)
      s=s+atomList[i].toString();
   return s;
   }
   
//===================================================================
//compressibility factor equations 
    //for vapor phase
   
   public double[] Z0_TP_LK_V_bracket(double x1,double x2,double T,double P){
       //returns a bracketed root 
	//if a root is not bracketed, enlarge region outwards each time
	double Tr=T/Tc;
        double Pr=P/Pc;
        int NTRY=50;
	double a[]=new double[2];
	double FACTOR=1.0001;
	int j;
	double f1,f2;
	if (x1 == x2) System.out.println("Bad initial range in ZBRAC");
	f1=Z0_TV_LK_V(T,x1)-x1*Pr/Tr;
	f2=Z0_TV_LK_V(T,x2)-x2*Pr/Tr;
        //System.out.println("Bracket da");
       // System.out.println("x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
	for (j=1;j<=NTRY;j++) {
		if (f1*f2 < 0.0) {a[0]=x1;a[1]=x2;return a;}
		if (Math.abs(f1) < Math.abs(f2)){                  
                        x1 = 0.5*x1;
                        x2 =x2-0.5*x1; 
			f1=Z0_TV_LK_V(T,x1)-x1*Pr/Tr;
               //System.out.println("|f1|<|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
		else{
                        x2 +=FACTOR*(x2-x1);                        
			f2=Z0_TV_LK_V(T,x2)-x2*Pr/Tr;
                // System.out.println("|f1|>|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
              
	}
	{a[0]=x1;a[1]=x2;return a;}
    }    
   public double[] ZR_TP_LK_V_bracket(double x1,double x2,double T,double P){
       //returns a bracketed root 
	//if a root is not bracketed, enlarge region outwards each time        
	double Tr=T/Tc;
        double Pr=P/Pc;
        int NTRY=50;
	double a[]=new double[2];
	double FACTOR=1.002;
	int j;
	double f1,f2;
	if (x1 == x2) System.out.println("Bad initial range in ZBRAC");
	f1=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;
	f2=ZR_TV_LK_V(T,x2)-x2*Pr/Tr;
       // System.out.println("Bracket da");
        //System.out.println("x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
	for (j=1;j<=NTRY;j++) {
		if (f1*f2 < 0.0) {break;}
		if (Math.abs(f1) < Math.abs(f2)){                  
                        x1 = 0.95*x1;                       
			f1=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;
             // System.out.println("|f1|<|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
		else{
                        x2 +=FACTOR*(x2-x1);                        
			f2=ZR_TV_LK_V(T,x2)-x2*Pr/Tr;
                  //System.out.println("|f1|>|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
              
	}      
        //Bisection method
        int maxit=30,iter=0;
       double es=0.0001;
       double dxp=Math.abs((x2-x1)/2);    
       double xr;      
       double fx=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;;
       double fxr;
       for(int i=0;i<maxit;i++)
       {
           xr=x1+dxp;
           if(xr>x2) break;
           fxr=ZR_TV_LK_V(T,xr)-xr*Pr/Tr;
           //System.out.println("fxr="+fxr);
           if(fx*fxr<0)
           {   x2=xr;
               if((x2-x1)<=es)  break;
           }
           else if (fx*fxr>0){ 
               x1=xr;
               if((x2-x1)<=es)  break;  
               //System.out.println("x1="+x1+" x2="+x2);
           }         
           dxp=(x2-x1)/2.0;
         }
       {a[0]=x1;a[1]=x2;return a;}
    }    
   public double Z_TP_LK_V(double T,double P){
    // root of a non-linear equation	
   //reference : Numerical Recipes in C, second edition, William H. Press, 
   //Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
   //cambridge university press	
       // System.out.println("================TP ba?lad?===================");
       double Z[]=new double [3];
        double Z0=0;
        double ZR=0;
        double Tr=T/Tc;
        double Pr=P/Pc;
        int MAXIT=40;
        double xacc=1.0e-15;
        int j;
	double fl,fh,fr,xl,xh,swap,dx,del,f;
       // System.out.println("P="+P+"  T="+T);
        double xi=Z_TP_PR_V(T,P)*Tr/Pr; 
       // System.out.println(Z_TP_PR_V(T,P));
        //System.out.println("Z0 bracket");
	double d[]=Z0_TP_LK_V_bracket(xi-0.001,xi+0.001,T,P);
	double x1=d[0];
        double x2=d[1];       
        double rtf=x1;        
        fl=Z0_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=Z0_TV_LK_V(T,x2)-x2*Pr/Tr;     
	//if (fl*fh > 0.0) //System.out.println("Root must be bracketed in RTFLSP  (Z_TP_LK_V)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;    
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z0_TV_LK_V(T,rtf)-rtf*Pr/Tr;
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}           
		dx=xh-xl;         
		if (Math.abs(del) < xacc || f == 0.0){
                    Z0=Pr*rtf/Tr;              
                    break;
                }
                Z0=Pr*rtf/Tr;
	}
        d[0]=0;
        d[1]=0;
        xacc=1e-20;
        //System.out.println("ZR bracket");
        d=ZR_TP_LK_V_bracket(xi-0.0001,xi+0.0001,T,P);
	x1=d[0];
        x2=d[1];       
        rtf=x1;        
        fl=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=ZR_TV_LK_V(T,x2)-x2*Pr/Tr;   
	//if (fl*fh > 0.0)// System.out.println("Root must be bracketed in RTFLSP(Z_TP_LK_V_2)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl; 
        int yuo=0;
	for (int k=1;k<=MAXIT;k++) {
		rtf=xl+dx*fl/(fl-fh);
		f=ZR_TV_LK_V(T,rtf)-rtf*Pr/Tr;
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}    
		dx=xh-xl;                
		if (Math.abs(del) < xacc || f == 0.0) {            
                    ZR=Pr*rtf/Tr;
                    break;
                }         
                 ZR=Pr*rtf/Tr;
	}    
        Z[0]=Z0;
        Z[1]=(ZR-Z0)/OmegaR;//ZR;
       double ZX=Z0+Omega*(ZR-Z0)/OmegaR;
        Z[2]= ZX;	
   //return Z0+w*(ZR-Z0)/wR;
        
     //   System.out.println("================TP bitti===================");
     return ZX;
       
    }
   public double[][]  Z_TP_LK_VA(double T,double P){
   // root of a non-linear equation	
   //reference : Numerical Recipes in C, second edition, William H. Press, 
   //Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
   //cambridge university press	
        double Z[][]=new double [3][2];
        double Vr0=0,VrR=0;
        double Z0=0;
        double ZR=0;
        double Tr=T/Tc;
        double Pr=P/Pc;
        int MAXIT=40;
        double xacc=1.0e-15;
        int j;
		double fl,fh,fr,xl,xh,swap,dx,del,f;
        double xi=Z_TP_PR_V(T,P)*Tr/Pr;       
		double d[]=Z0_TP_LK_V_bracket(xi-0.001,xi+0.001,T,P);
		double x1=d[0];
        double x2=d[1];       
        double rtf=x1;        
        fl=Z0_TV_LK_V(T,x1)-x1*Pr/Tr;
		fh=Z0_TV_LK_V(T,x2)-x2*Pr/Tr;
		//System.out.println("fl= "+fl+" fh="+fh);
    //	if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP  (Z_TP_LK_V)");
		if (fl < 0.0) {
			xl=x1;
			xh=x2;
		} else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
		}
		//System.out.println("baslxh= "+xh+" xl= "+xl);
		dx=xh-xl;
   	    
		for (j=1;j<=MAXIT;j++) {
			rtf=xl+dx*fl/(fl-fh);
			//System.out.println("rtf= "+rtf);
			f=Z0_TV_LK_V(T,rtf)-rtf*Pr/Tr;
			//System.out.println("f= "+f);
			if (f < 0.0) {
				del=xl-rtf;
				xl=rtf;
				fl=f;
			} else {
				del=xh-rtf;
				xh=rtf;
				fh=f;
			}	
            //System.out.println("xh= "+xh+" xl= "+xl+"  del= "+del);
			dx=xh-xl;        
		if (Math.abs(del) < xacc || f == 0.0){
                    Z0=Pr*rtf/Tr;              
                    break;
                }
                Z0=Pr*rtf/Tr;
               
	}
	 	Z[0][0]=Tr*Z0/Pr;
        Z[0][1]=Z0;   
        d[0]=0;
        d[1]=0;
        xacc=1e-20;
        d=ZR_TP_LK_V_bracket(xi-0.001,xi+0.001,T,P);
	    x1=d[0];
        x2=d[1];       
        rtf=x1;        
        fl=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=ZR_TV_LK_V(T,x2)-x2*Pr/Tr;  
	//System.out.println("x1= "+x1+" x2= "+x2+"fl= "+fl+" fh="+fh);  
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP(Z_TP_LK_V_2)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;  
        int yuo=0;
	for (int k=1;k<=MAXIT;k++) {
		rtf=xl+dx*fl/(fl-fh);
                //System.out.println("rtf="+rtf+"  Pr="+Pr+"   Tr="+Tr);
		f=ZR_TV_LK_V(T,rtf)-rtf*Pr/Tr;
                //System.out.println("rtf="+rtf+"  f="+f+" ZR= "+(rtf*Pr/Tr) );
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}           
		dx=xh-xl; 		             
		if (Math.abs(del) < xacc || f == 0.0) {                 
               ZR=Pr*rtf/Tr;              
                    break;
                } 
                ZR=Pr*rtf/Tr;
               
	}
	 	Z[1][0]=Tr*ZR/Pr;
        Z[1][1]=ZR;  
		  		    
       Z[2][0]=Z[0][0]+Omega*(Z[1][0]-Z[0][0])/OmegaR;
       Z[2][1]=Z[0][1]+Omega*(Z[1][1]-Z[0][1])/OmegaR;
       //Z[2][1]=(Z[1][1]-Z[0][1])/OmegaR; //=Z1
       //[x][0] Vr0 [x][1] Z0
         return Z;
    }    
   public double Z0_TV_LK_V(double T,double Vr0){
       double B0,C0,D0;
       double Z0;
       double Tr=T/Tc;     
       B0=b0[0]-b0[1]/Tr-b0[2]/(Tr*Tr)-b0[3]/(Tr*Tr*Tr);
       C0=c0[0]-c0[1]/Tr+c0[2]/(Tr*Tr*Tr);
       D0=d0[0]+d0[1]/Tr;
       return 1+B0/Vr0+C0/(Vr0*Vr0)+D0/(Vr0*Vr0*Vr0*Vr0*Vr0)
            + c0[3]/(Tr*Tr*Tr*Vr0*Vr0)*(beta0+gama0/(Vr0*Vr0))*Math.exp(-gama0/(Vr0*Vr0));
    }    
   public double ZR_TV_LK_V(double T,double VrR){
       double BR,CR,DR;      
       double Tr=T/Tc;      
       BR=bR[0]-bR[1]/Tr-bR[2]/(Tr*Tr)-bR[3]/(Tr*Tr*Tr);
       CR=cR[0]-cR[1]/Tr+cR[2]/(Tr*Tr*Tr);
       DR=dR[0]+dR[1]/Tr;
       return 1+BR/VrR+CR/(VrR*VrR)+DR/(VrR*VrR*VrR*VrR*VrR)
            + cR[3]/(Tr*Tr*Tr*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR));
    }  
   public double[]  Vr_TV_LK_V_bracket(double x1,double x2,double Tr,double Vr){
       //returns a bracketed root 
	//if a root is not bracketed, enlarge region outwards each time	     
        int NTRY=50;
	double a[]=new double[2];
	double FACTOR=1.002;
	int j;
	double f1,f2;
	if (x1 == x2) System.out.println("Bad initial range in ZBRAC");
	f1=dPr_TV_LK_V(Tr,Vr,x1);
	f2=dPr_TV_LK_V(Tr,Vr,x2);
        //System.out.println("----Bracket------");
        //System.out.println("x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
	for (j=1;j<=NTRY;j++) {
		if (f1*f2 < 0.0) {a[0]=x1;a[1]=x2;return a;}
		if (Math.abs(f1) < Math.abs(f2)){                  
                        x1 +=FACTOR*(x1-x2);                        
			f1=dPr_TV_LK_V(Tr,Vr,x1);
              //  System.out.println("|f1|<|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
		else{
                        x2 +=FACTOR*(x2-x1);                        
			f2=dPr_TV_LK_V(Tr,Vr,x2);
                 // System.out.println("|f1|>|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }             
	}
	{a[0]=x1;a[1]=x2;return a;}
    }   
   public double[]  Z_TV_LK_V_bracket(double x1,double x2,double T,double V){
        //returns a bracketed root 
	//if a root is not bracketed, enlarge region outwards each time	     
       double Tr=T/Tc;
       double Vr=Pc*V*1e5/(R*Tc);
       int NTRY=50;
	double a[]=new double[2];
	double FACTOR=1.002;
	int j;
	double f1,f2;
	if (x1 == x2) System.out.println("Bad initial range in ZBRAC");
	f1=Z_TP_LK_V(T,x1)-x1*Vr/Pc/Tr;
	f2=Z_TP_LK_V(T,x2)-x2*Vr/Pc/Tr;
        //System.out.println("----Bracket------");
        //System.out.println("Z_TP_LK_V(T,x1)="+Z_TP_LK_V(T,x1)+" x1*Vr/Pc/Tr="+(x1*Vr/Pc/Tr));
        //System.out.println("x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
	for (j=1;j<=NTRY;j++) {
		if (f1*f2 < 0.0) {break;}
		if (Math.abs(f1) < Math.abs(f2)){                  
                        x1 +=FACTOR*(x1-x2);                        
			f1=Z_TP_LK_V(T,x1)-x1*Vr/Pc/Tr;
               // System.out.println("|f1|<|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
		else{
                        x2 +=FACTOR*(x2-x1);                        
			f2=Z_TP_LK_V(T,x2)-x2*Vr/Pc/Tr;
                  //System.out.println("|f1|>|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }   
                
	}       
           //Bisection method
        int maxit=20,iter=0;
       double es=0.0001;
       double dxp=Math.abs((x2-x1)/2);    
       double xr;      
       double fx=Z_TP_LK_V(T,x1)-x1*Vr/Pc/Tr;
       double fxr;
       for(int i=0;i<maxit;i++)
       {
           xr=x1+dxp;
           if(xr>x2) break;
           fxr=Z_TP_LK_V(T,xr)-xr*Vr/Pc/Tr;
           //System.out.println("fxr="+fxr);
           if(fx*fxr<0)
           {   x2=xr;
               if((x2-x1)<=es)  break;
           }
           else if (fx*fxr>0){ 
               x1=xr;
               if((x2-x1)<=es)  break;  
               //System.out.println("x1="+x1+" x2="+x2);
           }          
           dxp=(x2-x1)/2.0;
         }
	a[0]=x1;a[1]=x2;return a;
   }   
   public double Z_TV_LK_V(double T,double V){    
        double Tr=T/Tc;
        double Vr=Pc*V*1e5/(R*Tc);       
        double x[][]=new double[3][2];
        double d[]=new double[2];
        double Px=P_TV_PR_V(T,V);//R*T*1e-5/V;//P_TV_PR_V(T,V); ZX*R*T*1e-5/V       
       // System.out.println("Px="+Px +"  Prx="+(Px/Pc));
        d=Z_TV_LK_V_bracket(Px-0.5,Px+0.5,T,V);        
        double  x1=d[0];
        double x2=d[1];        
        int MAXIT=100;
        double xacc=1.0e-17;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_V(T,x1)-x1*Vr/Pc/Tr;
	fh=Z_TP_LK_V(T,x2)-x2*Vr/Pc/Tr;
       // System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_V(T,rtf)-rtf*Vr/Pc/Tr;
               // System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){   
                    return Z_TP_LK_V(T,rtf);
                    //return  Z_TP_LK_VA(T,rtf);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");     
        return  Z_TP_LK_V(T,rtf);
        //return  Z_TP_LK_VA(T,rtf);
   
    }     
   public double[][] Z_TV_LK_VA(double T,double V){    
        double Tr=T/Tc;
        double Vr=Pc*V*1e5/(R*Tc);       
        double x[][]=new double[3][2];
        double d[]=new double[2];
        double Px=P_TV_PR_V(T,V);//R*T*1e-5/V;//P_TV_PR_V(T,V); ZX*R*T*1e-5/V       
        //System.out.println("Px="+Px +"  Prx="+(Px/Pc));
        d=Z_TV_LK_V_bracket(Px-0.5,Px+0.5,T,V);        
        double  x1=d[0];
        double x2=d[1];        
        int MAXIT=100;
        double xacc=1.0e-17;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_V(T,x1)-x1*Vr/Pc/Tr;
	fh=Z_TP_LK_V(T,x2)-x2*Vr/Pc/Tr;
        //System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_V(T,rtf)-rtf*Vr/Pc/Tr;
               // System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
               // System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){                       
                    return  Z_TP_LK_VA(T,rtf);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");     
        return  Z_TP_LK_VA(T,rtf);
   
    } 
   public  double Z_VP_LK_V_derivative(double x,double V,double P){
// df/dx
// This method calculates derivatives of a simple function f(x)
// accuracy of method can be adjusted by changing
// variables h0 and n
// function input should be in the form given in abstract class
// f_x
double Vr=Pc*V*1e5/(R*Tc);        
double Pr=P/Pc;      
double h0=0.0256;
int i,m;
int n=7;
//derivative of a simple function
double T[][];
T=new double[n][n];
double h[];
h=new double[n];
//vector<double> h(n,0);
for(i=0;i<n;i++)
{
  h[i]=0;
  for(int j=0;j<n;j++)
    T[i][j]=0;
}
h[0]=h0;
double r=0.5;
for( i=1;i<n;i++)
{
h[i]=h0*Math.pow(r,i);
}

for(i=0;i<n;i++)
{
T[i][0]=(Z_TP_LK_V((x + h[i]),P)-Pr*Vr*Tc/(x + h[i]) - Z_TP_LK_V(( x - h[i]),P)-Pr*Vr*Tc/( x - h[i]))/(2.0*h[i]);
}
for(m=1;m<n;m++)
{
  for(i=0;i<n-m;i++)
  {
  T[i][m]=(h[i]*h[i]*T[i+1][m-1] - h[i+m]*h[i+m]*T[i][m-1])/
          (h[i]*h[i]- h[i+m]*h[i+m]);
  }
}
double xx=T[0][n-1];
return xx;
}
   public double[][]  Z_VP_LK_V_reversebracket(double x1,double x2,double V,double P){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value
       double Vr=Pc*V*1e5/(R*Tc);        
       double Pr=P/Pc;      
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=Z_TP_LK_V(x,P)-Pr*Vr*Tc/x;
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=Z_TP_LK_V(x,P)-Pr*Vr*Tc/x;
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb) return xb;
	}
        if( nb == 0)	
  System.out.println("arama tamamlandi kök olan bölge bulunamad?");
else if(nb<nbb)
  System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
return xb;     
      
   }
   public double[][] Z_VP_LK_VA(double V,double P){     
        double Vr=Pc*V*1e5/(R*Tc);        
        double Pr=P/Pc;  
        double xb[][]=new double[2][1];        
       // double d[]=new double[2];
       double x;    
        x= P==Pc ? 0.29*Tc: (P<Pc ? 0.25*T_P_LK_SV(P) : Tc*0.29);
        //System.out.println("x="+x);
        xb=Z_VP_LK_V_reversebracket(x,Tc*6,V,P);
        //System.out.println("xl="+xb[0][0]+"   xl="+xb[1][0]);        
        double x1=xb[0][0];
        double x2=xb[1][0];        
        int MAXIT=100;
        double xacc=1.0e-17;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_V(x1,P)-Pr*Vr*Tc/x1;
	fh=Z_TP_LK_V(x2,P)-Pr*Vr*Tc/x2;
        //System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_V(rtf,P)-Pr*Vr*Tc/rtf;
                //System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){                    
                   //System.out.println("--------------------------------------------------------------------------");
                    return Z_TP_LK_VA(rtf,P);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");   
        //System.out.println("--------------------------------------------------------------------------");
    return Z_TP_LK_VA(rtf,P);           
   }       
   public double Z_VP_LK_V(double V,double P){     
        double Vr=Pc*V*1e5/(R*Tc);        
        double Pr=P/Pc;  
        double xb[][]=new double[2][1];        
       // double d[]=new double[2];
       double x;    
        x= P==Pc ? 0.29*Tc: (P<Pc ? 0.25*T_P_LK_SV(P) : Tc*0.29);
        //System.out.println("x="+x);
        xb=Z_VP_LK_V_reversebracket(x,Tc*6,V,P);
        //System.out.println("xl="+xb[0][0]+"   xl="+xb[1][0]);        
        double x1=xb[0][0];
        double x2=xb[1][0];        
        int MAXIT=100;
        double xacc=1.0e-17;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_V(x1,P)-Pr*Vr*Tc/x1;
	fh=Z_TP_LK_V(x2,P)-Pr*Vr*Tc/x2;
        //System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_V(rtf,P)-Pr*Vr*Tc/rtf;
                //System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){                    
                   //System.out.println("--------------------------------------------------------------------------");
                    return Z_TP_LK_V(rtf,P);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");   
        //System.out.println("--------------------------------------------------------------------------");
    return Z_TP_LK_V(rtf,P);           
   }     
   public double  Z_TV_LK_V1(double T,double V){
        int MAXIT=100;
        double xacc=1.0e-5;
        double fl,fh,fr,xl,xh,swap,dx,del,f,rtf;
        double B0,C0,D0;
        double BR,CR,DR;
        double Vr0,VrR;
        double Z0,ZR,ZX;
        double d[]=new double[2];
        double Tr=T/Tc;        
        double Vr=Pc*V*1e5/(R*Tc);
       // double Px=(R*T*1e-5)/(V*Pc)<3 ?  (P_TV_PR_V(T,V)+(R*T*1e-5)/V)/2 :(R*T*1e-5)/V; //(R*T*1e-5)/V;//P_TV_PR_V(T,V);
       double Px=P_TV_PR_V(T,V);
        B0=b0[0]-b0[1]/Tr-b0[2]/(Tr*Tr)-b0[3]/(Tr*Tr*Tr);
        C0=c0[0]-c0[1]/Tr+c0[2]/(Tr*Tr*Tr);
        D0=d0[0]+d0[1]/Tr;
        Z0=1+B0/Vr+C0/(Vr*Vr)+D0/(Vr*Vr*Vr*Vr*Vr)
        + c0[3]/(Tr*Tr*Tr*Vr*Vr)*(beta0+gama0/(Vr*Vr))*Math.exp(-gama0/(Vr*Vr));       
        BR=bR[0]-bR[1]/Tr-bR[2]/(Tr*Tr)-bR[3]/(Tr*Tr*Tr);
        CR=cR[0]-cR[1]/Tr+cR[2]/(Tr*Tr*Tr);
        DR=dR[0]+dR[1]/Tr;
        ZR=1+BR/Vr+CR/(Vr*Vr)+DR/(Vr*Vr*Vr*Vr*Vr)
        + cR[3]/(Tr*Tr*Tr*Vr*Vr)*(betaR+gamaR/(Vr*Vr))*Math.exp(-gamaR/(Vr*Vr));
        ZX=Z0+Omega/OmegaR*(ZR-Z0);
        //Px=ZX*R*T/(V*1e5);
        //Px=(R*T*1e-5)/(V*Pc)<3 ?  (ZX*R*T/(V*1e5)+(R*T*1e-5)/V)/2 :(R*T*1e-5)/V;
        //System.out.println("Px="+Px+"  Prx="+(Px/Pc));
        double iZX[]=new double[3];
       // iZX=Z_TP_LK_VA(T,Px);
       
        //double Vrx=iZX[0]*Tr*Pc/Px;        
       // double Vr2=Vr*OmegaR/(Omega-OmegaR);
      //  System.out.println("---------------------------------TV basladi----------------------------------");
       // System.out.println("Vr="+Vr+"  Vrx="+Vrx+"   Tr="+Tr+"  Px="+Px);     
        double x1=0,x2=0;      
        d=Vr_TV_LK_V_bracket(Vr-0.001,Vr+0.001,Tr,Vr);
        x1=d[0];//Vr0 ?n alt tahmin de?eri
        x2=d[1];////Vr0 ?n üst tahmin de?eri       
        rtf=x1;        
        fl=dPr_TV_LK_V(Tr,Vr,x1);
	fh=dPr_TV_LK_V(Tr,Vr,x2);
       // System.out.println("------------------------- TV Ridder ------------------------");
      //  System.out.println("x1="+x1+"  fl="+fl+"  x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP  --- (Z_TV_LK_V)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
        //System.out.println("dx="+dx);
	for (int j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=dPr_TV_LK_V(Tr,Vr,rtf);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
               // System.out.println("rtf="+rtf+"  f="+f);
		dx=xh-xl;
              // System.out.println("dx="+dx+"  (fl-fh)="+(fl-fh)+"  f="+f);              
		if (Math.abs(f) < xacc) {                   
                    break;
                }              
	}
        Vr0=rtf;
        //System.out.println("rtf="+rtf);
        VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
       // System.out.println("VrR="+VrR);
       // Vr0=Vr;
       // VrR=Vr;
        B0=b0[0]-b0[1]/Tr-b0[2]/(Tr*Tr)-b0[3]/(Tr*Tr*Tr);
        C0=c0[0]-c0[1]/Tr+c0[2]/(Tr*Tr*Tr);
        D0=d0[0]+d0[1]/Tr;
        Z0=1+B0/Vr0+C0/(Vr0*Vr0)+D0/(Vr0*Vr0*Vr0*Vr0*Vr0)
        + c0[3]/(Tr*Tr*Tr*Vr0*Vr0)*(beta0+gama0/(Vr0*Vr0))*Math.exp(-gama0/(Vr0*Vr0));       
        BR=bR[0]-bR[1]/Tr-bR[2]/(Tr*Tr)-bR[3]/(Tr*Tr*Tr);
        CR=cR[0]-cR[1]/Tr+cR[2]/(Tr*Tr*Tr);
        DR=dR[0]+dR[1]/Tr;
        ZR=1+BR/VrR+CR/(VrR*VrR)+DR/(VrR*VrR*VrR*VrR*VrR)
        + cR[3]/(Tr*Tr*Tr*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR));
        double Pr0=Z0*Tr/Vr0;
        double PrR=ZR*Tr/VrR;
       // System.out.println("Z0=  "+Z0+"   ZR="+ZR);
       // System.out.println("Tr="+Tr+ " Pr0="+Pr0+"  PrR="+PrR);
        ZX=Z0+Omega/OmegaR*(ZR-Z0);
       // System.out.println("ZX="+ZX);
       //System.out.println("------------------------------TV bitti-------------------------------------------------");       
       return ZX ; 
      // return rtf;
    }    
   public double dPr_TV_LK_V(double T,double V,double V0){      
        double Vr=Pc*V*1e5/(R*Tc);
        double Vr0=Pc*V0*1e5/(R*Tc);
        double Tr=T/Tc;
        double VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
        double B0,C0,D0;
        double B01,C01,D01,dB01,dC01,dD01;
        double BR,CR,DR;
        double P0,PR;
       // System.out.println("Vr="+Vr+" Vr0="+Vr0+" VrR="+VrR);
       
        B0=b0[0]-b0[1]/Tr-b0[2]/(Tr*Tr)-b0[3]/(Tr*Tr*Tr);
        C0=c0[0]-c0[1]/Tr+c0[2]/(Tr*Tr*Tr);
        D0=d0[0]+d0[1]/Tr;
        
        P0=1+B0/Vr0+C0/(Vr0*Vr0)+D0/(Vr0*Vr0*Vr0*Vr0*Vr0)
        + c0[3]/(Tr*Tr*Tr*Vr0*Vr0)*(beta0+gama0/(Vr0*Vr0))*Math.exp(-gama0/(Vr0*Vr0));
        P0=Tr*P0/Vr0;
       //System.out.println(" D0=  "+D0+" C0=  "+C0+" B0=  "+B0+" Z0=  "+Z0); 
        
       
        BR=bR[0]-bR[1]/Tr-bR[2]/(Tr*Tr)-bR[3]/(Tr*Tr*Tr);
        CR=cR[0]-cR[1]/Tr+cR[2]/(Tr*Tr*Tr);
        DR=dR[0]+dR[1]/Tr;
       
        PR=1+BR/VrR+CR/(VrR*VrR)+DR/(VrR*VrR*VrR*VrR*VrR)
        + cR[3]/(Tr*Tr*Tr*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR));      
        PR=Tr*PR/VrR;
        
       /* System.out.println(" DR=  "+DR+" CR=  "+CR+" BR=  "+BR+" PR=  "+PR);  */
     //   System.out.println("cR[3]/(Tr*Tr*Tr*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR))="+(cR[3]/(Tr*Tr*Tr*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR))));
     //   System.out.println("(betaR+gamaR/(VrR*VrR))="+(betaR+gamaR/(VrR*VrR)));
      //  System.out.println("Math.exp(-gamaR/(VrR*VrR))="+Math.exp(-gamaR/(VrR*VrR)));
       // return PR-P0;  
       // return Vr0+w/wR*(VrR-Vr0);
       // System.out.println("PR-P0="+(PR-P0));
       // return PR-P0;
        return P0;
    }
   public double dPdTr_TV_LK_V(double T,double V,double V0){
        double Vr=Pc*V*1e5/(R*Tc);
        double Vr0=Pc*V0*1e5/(R*Tc);
        double Tr=T/Tc;
        double VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
        double B0,C0,D0;
        double dB0,dC0,dD0;
        double BR,CR,DR;
        double dBR,dCR,dDR;      
         
        B0=b0[0]*Tr-b0[1]-b0[2]/Tr-b0[3]/(Tr*Tr);
        C0=c0[0]*Tr-c0[1]+c0[2]/(Tr*Tr);
        D0=d0[0]*Tr+d0[1];
        
        dB0=b0[0]+b0[2]/(Tr*Tr)+2*b0[3]/(Tr*Tr*Tr);
        dC0=c0[0]-2*c0[2]/(Tr*Tr*Tr);
        dD0=d0[0];
        
        double dP0dTr=1/Vr0+dB0/(Vr0*Vr0)+dC0/(Vr0*Vr0*Vr0)+dD0/(Vr0*Vr0*Vr0*Vr0*Vr0*Vr0)
        - 2*c0[3]/(Tr*Tr*Tr*Vr0*Vr0*Vr0)*(beta0+gama0/(Vr0*Vr0))*Math.exp(-gama0/(Vr0*Vr0));
        
        BR=bR[0]*Tr-bR[1]-bR[2]/Tr-bR[3]/(Tr*Tr);
        CR=cR[0]*Tr-cR[1]+cR[2]/(Tr*Tr);
        DR=dR[0]*Tr+dR[1];
        
        dBR=bR[0]+bR[2]/(Tr*Tr)+2*bR[3]/(Tr*Tr*Tr);
        dCR=cR[0]-2*cR[2]/(Tr*Tr*Tr);
        dDR=dR[0];
        
        double dPRdTr=1/VrR+dBR/(VrR*VrR)+dCR/(VrR*VrR*VrR)+dDR/(VrR*VrR*VrR*VrR*VrR*VrR)
        - 2*cR[3]/(Tr*Tr*Tr*VrR*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR));
        
        //return dP0dTr-dPRdTr;
        return dP0dTr;
    }    
   public double dPdVr0_TV_LK_V(double T,double V,double V0){
        double Vr=Pc*V*1e5/(R*Tc);
        double Vr0=Pc*V0*1e5/(R*Tc);
        double Tr=T/Tc;
        double VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
        double B0,C0,D0; 
        double BR,CR,DR;
        
        B0=b0[0]*Tr-b0[1]-b0[2]/Tr-b0[3]/(Tr*Tr);
        C0=c0[0]*Tr-c0[1]+c0[2]/(Tr*Tr);
        D0=d0[0]*Tr+d0[1];
        
        double dP0dVr0=-Tr/(Vr0*Vr0)-2*B0/(Vr0*Vr0*Vr0)-3*C0/(Vr0*Vr0*Vr0*Vr0)-6*D0/(Vr0*Vr0*Vr0*Vr0*Vr0*Vr0*Vr0)
        +c0[3]/(Tr*Tr*Vr0*Vr0*Vr0*Vr0)*Math.exp(-gama0/(Vr0*Vr0))*
   (-3*beta0-5*gama0/(Vr0*Vr0)+2*gama0*beta0/(Vr0*Vr0)+2*gama0*gama0/(Vr0*Vr0*Vr0*Vr0));   
        
        BR=bR[0]*Tr-bR[1]-bR[2]/Tr-bR[3]/(Tr*Tr);
        CR=cR[0]*Tr-cR[1]+cR[2]/(Tr*Tr);
        DR=dR[0]*Tr+dR[1];
        
        double dPRdVrR=-Tr/(VrR*VrR)-2*BR/(VrR*VrR*VrR)-3*CR/(VrR*VrR*VrR*VrR)-6*DR/(VrR*VrR*VrR*VrR*VrR*VrR*VrR)
        +cR[3]/(Tr*Tr*VrR*VrR*VrR*VrR)*Math.exp(-gamaR/(VrR*VrR))*
   (-3*betaR-5*gamaR/(VrR*VrR)+2*gamaR*betaR/(VrR*VrR)+2*gamaR*gamaR/(VrR*VrR*VrR*VrR));   
       
        double dVrRdVr0=-OmegaR/Omega+1;
       
        return dP0dVr0-dPRdVrR*dVrRdVr0;
        //return dP0dVr0;
     }      
   public double dVr0dT_TV_LK_V(double T,double V,double V0){
        double Vr=Pc*V*1e5/(R*Tc);
        double Vr0=Pc*V0*1e5/(R*Tc);
        double Tr=T/Tc;
        double VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
        double dB0,dC0,dD0;
        double dBR,dCR,dDR; 
        double B0,C0,D0;
        double f[]=new double[4];
        
        B0=b0[0]*Tr-b0[1]-b0[2]/Tr-b0[3]/(Tr*Tr);
        C0=c0[0]*Tr-c0[1]+c0[2]/(Tr*Tr);
        D0=d0[0]*Tr+d0[1];
        
        dB0=b0[0]+b0[2]/(Tr*Tr)+2*b0[3]/(Tr*Tr*Tr);
        dC0=c0[0]-2*c0[2]/(Tr*Tr*Tr);
        dD0=d0[0];
        
        double dZ0dTr=1/Vr0+dB0/(Vr0*Vr0)+dC0/(Vr0*Vr0*Vr0)+dD0/(Vr0*Vr0*Vr0*Vr0*Vr0*Vr0)
        - 2*c0[3]/(Tr*Tr*Tr*Vr0*Vr0*Vr0)*(beta0+gama0/(Vr0*Vr0))*Math.exp(-gama0/(Vr0*Vr0));
        double dZ0dVr0=-Tr/(Vr0*Vr0)-2*B0/(Vr0*Vr0*Vr0)-3*C0/(Vr0*Vr0*Vr0*Vr0)-6*D0/(Vr0*Vr0*Vr0*Vr0*Vr0*Vr0*Vr0)
        +c0[3]/(Tr*Tr*Vr0*Vr0*Vr0*Vr0)*Math.exp(-gama0/(Vr0*Vr0))*
   (-3*beta0-5*gama0/(Vr0*Vr0)+2*gama0*beta0/(Vr0*Vr0)+2*gama0*gama0/(Vr0*Vr0*Vr0*Vr0));       
        
      f[0]=Tr/Vr0;//+B0*Tr/(Vr0*Vr0);
      f[1]=1/Vr0;//+dB0/(Vr0*Vr0);
      f[2]=-Tr/Vr0/Vr0;//-2*B0*Tr/(Vr0*Vr0*Vr0);
      f[3]=-f[1] /f[2]; 
      return -dZ0dTr/dZ0dVr0;
        //return f;
    }        
   public double d2PrdT2_TV_LK_V(double T,double V,double V0){
        double Vr=Pc*V*1e5/(R*Tc);
        double Vr0=Pc*V0*1e5/(R*Tc);
        double Tr=T/Tc;
        double VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
        double dB0,dC0,dD0;
        double dBR,dCR,dDR;  
        
        dB0=-2*b0[1]/(Tr*Tr*Tr)-6*b0[2]/(Tr*Tr*Tr*Tr)-12*b0[3]/(Tr*Tr*Tr*Tr*Tr);
        dC0=-2*c0[1]/(Tr*Tr*Tr)+12*c0[2]/(Tr*Tr*Tr*Tr*Tr);
        dD0=2*d0[1]/(Tr*Tr*Tr);
        double d2Z0=dB0/Vr0+dC0/(Vr0*Vr0)+dD0/(Vr0*Vr0*Vr0*Vr0*Vr0)
        +12*c0[3]/(Tr*Tr*Tr*Tr*Tr*Vr0*Vr0)*(beta0+gama0/(Vr0*Vr0))*Math.exp(-gama0/(Vr0*Vr0));
        
        dBR=-2*bR[1]/(Tr*Tr*Tr)-6*bR[2]/(Tr*Tr*Tr*Tr)-12*bR[3]/(Tr*Tr*Tr*Tr*Tr);
        dCR=-2*cR[1]/(Tr*Tr*Tr)+12*cR[2]/(Tr*Tr*Tr*Tr*Tr);
        dDR=2*dR[1]/(Tr*Tr*Tr);
        double d2ZR=dBR/VrR+dCR/(VrR*VrR)+dDR/(VrR*VrR*VrR*VrR*VrR)
        +12*cR[3]/(Tr*Tr*Tr*Tr*Tr*VrR*VrR)*(betaR+gamaR/(VrR*VrR))*Math.exp(-gamaR/(VrR*VrR));
        
        return d2Z0;
    }   
   public double  dPrdV_TV_LK_V(double T,double V,double V0 ){
        double Vr=Pc*V*1e5/(R*Tc);
        double Vr0=Pc*V0*1e5/(R*Tc);
        double Tr=T/Tc;
        double VrR=(Vr-Vr0)*OmegaR/Omega+Vr0;
        double B0,C0,D0;
        double BR,CR,DR;        
        B0=b0[0]-b0[1]/Tr-b0[2]/(Tr*Tr)-b0[3]/(Tr*Tr*Tr);
        C0=c0[0]-c0[1]/Tr+c0[2]/(Tr*Tr*Tr);
        D0=d0[0]+d0[1]/Tr;
        double dZ0=-B0/(Vr0*Vr0)-2*C0/(Vr0*Vr0*Vr0)-5*D0/(Vr0*Vr0*Vr0*Vr0*Vr0*Vr0)+
   2.0*c0[3]/(Tr*Tr*Tr*Vr0*Vr0*Vr0)*Math.exp(-gama0/(Vr0*Vr0))*
   (-beta0-2*gama0/(Vr0*Vr0)+gama0*beta0/(Vr0*Vr0)+gama0*gama0/(Vr0*Vr0*Vr0*Vr0));  
        
        BR=bR[0]-bR[1]/Tr-bR[2]/(Tr*Tr)-bR[3]/(Tr*Tr*Tr);
        CR=cR[0]-cR[1]/Tr+cR[2]/(Tr*Tr*Tr);
        DR=dR[0]+dR[1]/Tr;
        double dZR=-BR/(VrR*VrR)-2*CR/(VrR*VrR*VrR)-5*DR/(VrR*VrR*VrR*VrR*VrR*VrR)+
   2.0*cR[3]/(Tr*Tr*Tr*VrR*VrR*VrR)*Math.exp(-gamaR/(VrR*VrR))*
   (-betaR-2*gamaR/(VrR*VrR)+gamaR*betaR/(VrR*VrR)+gamaR*gamaR/(VrR*VrR*VrR*VrR));    
    return dZ0-dZR;
    }
   
   //for liquid phase  
  
   public double[][]  Z_VP_LK_L_reversebracket(double x1,double x2,double V,double P){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value
       double Vr=Pc*V*1e5/(R*Tc);        
       double Pr=P/Pc;      
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=Z_TP_LK_L(x,P)-Pr*Vr*Tc/x;
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=Z_TP_LK_L(x,P)-Pr*Vr*Tc/x;
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb) return xb;
	}
        if( nb == 0)	
  System.out.println("arama tamamlandi kök olan bölge bulunamad?");
else if(nb<nbb)
  System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
return xb;     
      
   }
   public double[][] Z_VP_LK_LA(double V,double P){     
        double Vr=Pc*V*1e5/(R*Tc);        
        double Pr=P/Pc;  
        double xb[][]=new double[2][1];
       // double d[]=new double[2];
       double x;    
        x= P==Pc ? 0.29*Tc: (P<Pc ? 0.25*T_P_LK_SV(P) : -1 );
        if(P>Pc) {
            System.out.println("Hata:  olu?tu");
          
        }
        if(V>=V_P_RE_SL(P)){
             System.out.println("Hata:  olu?tu");
        }
        //System.out.println("x="+x);
        xb=Z_VP_LK_L_reversebracket(x,Tc*6,V,P);
       // System.out.println("xl="+xb[0][0]+"   xl="+xb[1][0]);        
        double x1=xb[0][0];
        double x2=xb[1][0];        
        int MAXIT=100;
        double xacc=1.0e-17;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_L(x1,P)-Pr*Vr*Tc/x1;
	fh=Z_TP_LK_L(x2,P)-Pr*Vr*Tc/x2;
        //System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_L(rtf,P)-Pr*Vr*Tc/rtf;
                //System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){                    
                   //System.out.println("--------------------------------------------------------------------------");
                    return Z_TP_LK_LA(rtf,P);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");   
       // System.out.println("--------------------------------------------------------------------------");
    return Z_TP_LK_LA(rtf,P);           
   }
   public double Z_VP_LK_L(double V,double P){     
        double Vr=Pc*V*1e5/(R*Tc);        
        double Pr=P/Pc;  
        double xb[][]=new double[2][1];
       // double d[]=new double[2];
       double x;    
        x= P==Pc ? 0.29*Tc: (P<Pc ? 0.25*T_P_LK_SV(P) : -1 );
        if(P>Pc) {
            System.out.println("Hata:  olu?tu");
          
        }
        if(V>=V_P_RE_SL(P)){
             System.out.println("Hata:  olu?tu");
        }
        //System.out.println("x="+x);
        xb=Z_VP_LK_L_reversebracket(x,Tc*6,V,P);
        //System.out.println("xl="+xb[0][0]+"   xl="+xb[1][0]);        
        double x1=xb[0][0];
        double x2=xb[1][0];        
        int MAXIT=100;
        double xacc=1.0e-17;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_L(x1,P)-Pr*Vr*Tc/x1;
	fh=Z_TP_LK_L(x2,P)-Pr*Vr*Tc/x2;
        //System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_L(rtf,P)-Pr*Vr*Tc/rtf;
               // System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
              //  System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){                    
                  // System.out.println("--------------------------------------------------------------------------");
                    return Z_TP_LK_L(rtf,P);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");   
        //System.out.println("--------------------------------------------------------------------------");
    return Z_TP_LK_L(rtf,P);           
   } 
   public double[][] Z_TP_LK_LA(double T,double P){         
    // root of a non-linear equation	
   //reference : Numerical Recipes in C, second edition, William H. Press, 
   //Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
   //cambridge university press	
        double Z0=0;
        double ZR=0;
        double Z[][]=new double[3][2];
        double Tr=T/Tc;
        double Pr=P/Pc;
        int MAXIT=30;
        double xacc=1.0e-5;
        int j;
	double fl,fh,fr,xl,xh,swap,dx,del,f;
        //System.out.println("Ridder de");
      //  System.out.println("Tr="+Tr+" Pr="+Pr);
       //System.out.println("=====================================================================================");
        double x=Z_TP_PR_L(T,P)*Tr/Pr;       
	double d[]=Z0_TP_LK_V_bracket(x-0.001,x+0.001,T,P);
	double x1=d[0];
        double x2=d[1];       
        double rtf=x1;        
        fl=Z0_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=Z0_TV_LK_V(T,x2)-x2*Pr/Tr;
        //System.out.println("-------------------------------------------------------------------------------");
       //System.out.println("x1="+x1+"  fl="+fl+"  x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP  (Z_TP_LK_V)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
        //System.out.println("dx="+dx);
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z0_TV_LK_V(T,rtf)-rtf*Pr/Tr;
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
                //System.out.println("rtf="+(Pr*rtf/Tr));
		dx=xh-xl;
                //System.out.println("dx="+dx+"  (fl-fh)="+(fl-fh));
		if (Math.abs(del) < xacc || f == 0.0){
                  Z[0][0]=rtf;  
                  Z[0][1]=rtf*Pr/Tr;
                    break;
                }
                 Z[0][0]=rtf;  
                 Z[0][1]=rtf*Pr/Tr;
	}
       // System.out.println("ZR Ba?lad?------\n x="+x);
        d[0]=0;
        d[1]=0;
        d=ZR_TP_LK_V_bracket(x-0.001,x+0.001,T,P);
	x1=d[0];
        x2=d[1];       
        rtf=x1;        
        fl=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=ZR_TV_LK_V(T,x2)-x2*Pr/Tr;
        //System.out.println("-------------------------------------------------------------------------------");
        //System.out.println("x1="+x1+"  fl="+fl+"  x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP(Z_TP_LK_V_2)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
        //System.out.println("dx="+dx);
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=ZR_TV_LK_V(T,rtf)-rtf*Pr/Tr;
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
               // System.out.println("rtf="+(Pr*rtf/Tr));
		dx=xh-xl;
               // System.out.println("dx="+dx+"  (fl-fh)="+(fl-fh));
		if (Math.abs(del) < xacc || f == 0.0) {
                    Z[1][0]=rtf;  
                    Z[1][1]=rtf*Pr/Tr;
                    break;
                }       
        }
	Z[2][0]=Z[0][0]+Omega*(Z[1][0]-Z[0][0])/OmegaR; 
        Z[2][1]=Z[0][1]+Omega*(Z[1][1]-Z[0][1])/OmegaR; 
     
	//System.out.println("Maximum number of iterations exceeded in RTFLSP");
       //System.out.println("////////////Z_TP_LK_V de Z0="+Z0+"  ZR="+ZR);
      //  System.out.println("-------------------------------------------------------------------------------");       
      return Z;
       //return (ZR-Z0)/OmegaR;
   
    }
   public double Z_TP_LK_L(double T,double P){         
    // root of a non-linear equation	
   //reference : Numerical Recipes in C, second edition, William H. Press, 
   //Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
   //cambridge university press	
        double Z0=0;
        double ZR=0;
        double Z[][]=new double[3][2];
        double Tr=T/Tc;
        double Pr=P/Pc;
        int MAXIT=30;
        double xacc=1.0e-5;
        int j;
	double fl,fh,fr,xl,xh,swap,dx,del,f;
        //System.out.println("Ridder de");
      //  System.out.println("Tr="+Tr+" Pr="+Pr);
       //System.out.println("=====================================================================================");
        double x=Z_TP_PR_L(T,P)*Tr/Pr;       
	double d[]=Z0_TP_LK_V_bracket(x-0.001,x+0.001,T,P);
	double x1=d[0];
        double x2=d[1];       
        double rtf=x1;        
        fl=Z0_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=Z0_TV_LK_V(T,x2)-x2*Pr/Tr;
        ///System.out.println("-------------------------------------------------------------------------------");
      // System.out.println("x1="+x1+"  fl="+fl+"  x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP  (Z_TP_LK_V)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
        //System.out.println("dx="+dx);
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z0_TV_LK_V(T,rtf)-rtf*Pr/Tr;
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
                //System.out.println("rtf="+(Pr*rtf/Tr));
		dx=xh-xl;
                //System.out.println("dx="+dx+"  (fl-fh)="+(fl-fh));
		if (Math.abs(del) < xacc || f == 0.0){
                   Z0=Pr*rtf/Tr;              
                    break;                 
                }
                   Z0=Pr*rtf/Tr;           
                
	}
       // System.out.println("ZR Ba?lad?------\n x="+x);
        d[0]=0;
        d[1]=0;
        d=ZR_TP_LK_V_bracket(x-0.001,x+0.001,T,P);
	x1=d[0];
        x2=d[1];       
        rtf=x1;        
        fl=ZR_TV_LK_V(T,x1)-x1*Pr/Tr;
	fh=ZR_TV_LK_V(T,x2)-x2*Pr/Tr;
        //System.out.println("-------------------------------------------------------------------------------");
        //System.out.println("x1="+x1+"  fl="+fl+"  x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP(Z_TP_LK_V_2)");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
        //System.out.println("dx="+dx);
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=ZR_TV_LK_V(T,rtf)-rtf*Pr/Tr;
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
               // System.out.println("rtf="+(Pr*rtf/Tr));
		dx=xh-xl;
               // System.out.println("dx="+dx+"  (fl-fh)="+(fl-fh));
		if (Math.abs(del) < xacc || f == 0.0) {
                ZR=Pr*rtf/Tr;
                    break;
              
                }    
                  ZR=Pr*rtf/Tr;            
        }	
         double ZX=Z0+Omega*(ZR-Z0)/OmegaR;
	//System.out.println("Maximum number of iterations exceeded in RTFLSP");
       //System.out.println("////////////Z_TP_LK_V de Z0="+Z0+"  ZR="+ZR);
      //  System.out.println("-------------------------------------------------------------------------------");       
      return ZX;
       //return (ZR-Z0)/OmegaR;
   
    } 
   public double Z_TV_LK_L(double T,double V){    
        double Tr=T/Tc;
        double Vr=Pc*V*1e5/(R*Tc);  
       //System.out.println("T="+T);
        double Px=P_T_LK_SV(T);        
        //System.out.println("Px= "+Px);
        
        double Z[][]=new double[3][2];
        double d[]=new double[2];
       // double Px=P_TV_PR_V(T,V);//R*T*1e-5/V;//P_TV_PR_V(T,V); ZX*R*T*1e-5/V       
       //System.out.println("Px="+Px +"  Prx="+(Px/Pc));
       //Px= (Px/Pc)<0.01 ? Px*20: Px; 
        d=Z_TV_LK_L_bracket(Px,Pc,T,V); 
        //System.out.println("qqqq");
        double  x1=d[0];
        double  x2=d[1];        
        int MAXIT=200;
        double xacc=1.0e-9;
        int j;
        double fl,fh,xl,xh,swap,dx,del,f;
	double rtf=x1;
	fl=Z_TP_LK_L(T,x1)-x1*Vr/Pc/Tr;
	fh=Z_TP_LK_L(T,x2)-x2*Vr/Pc/Tr;
       //System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
	//if (fl*fh > 0.0) System.out.println("Root must be bracketed in RTFLSP");
	if (fl < 0.0) {
		xl=x1;
		xh=x2;
	} else {
		xl=x2;
		xh=x1;
		swap=fl;
		fl=fh;
		fh=swap;
	}
	dx=xh-xl;
	for (j=1;j<=MAXIT;j++) {
		rtf=xl+dx*fl/(fl-fh);
		f=Z_TP_LK_L(T,rtf)-rtf*Vr/Pc/Tr;
               //System.out.println("rtf="+rtf+"  Pr="+(rtf/Pc)+"  f="+f);
		if (f < 0.0) {
			del=xl-rtf;
			xl=rtf;
			fl=f;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=f;
		}
		dx=xh-xl;
		//System.out.println("x1="+x1+"  fl="+fl+"    x2="+x2+"  fh="+fh);
        //System.out.println("del="+del);
		if (Math.abs(del) < xacc || f == 0.0){   
                    //System.out.println("ilk retrun");
                    return  Z_TP_LK_L(T,rtf);
                }
	}
	System.out.println("Maximum number of iterations exceeded in RTFLSP");
       
        //x= Z_TP_LK_VA(T,rtf);
       // return Z_TP_LK_V(T,rtf);
                           // System.out.println("ikinci retrun");
        return  Z_TP_LK_L(T,rtf);
   
    }
   public double[]  Z_TV_LK_L_bracket(double x1,double x2,double T,double V){
       /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	   
       // koklerin yer aldığı alt bölgeleri saptar
			// n : verilen bölgeyi böldüğümüz alt bölge sayısı
			// x1,x2 : sınır değerleri
			// nbb = aranan bölgedeki köksayısı	
			
			double Tr=T/Tc;
       double Vr=Pc*V*1e5/(R*Tc);
        /* System.out.println("Z_TP_LK_L(T,9.606443007861747)="+Z_TP_LK_L(T,9.606443007861747)+" 9.606443007861747*Vr/Pc/Tr="+
        (9.606443007861747*Vr/Pc/Tr)+"  "+(Z_TP_LK_L(T,9.606443007861747)-9.606443007861747*Vr/Pc/Tr));*/
			int n=10;
			int nbb=1; 
			int nb;			
			int i;
			double x,fp,fc,dx;
			double xb[]=new double[2];
			nb=0;
			dx=(x2-x1)/n;
			x=x1;
			fp=Z_TP_LK_L(T,x1)-x1*Vr/Pc/Tr;
			//System.out.println("x1= "+x1+" fp= "+fp);
			for (i=1;i<=n;i++) 
			{
				x+=dx;
				fc=Z_TP_LK_L(T,x)-x*Vr/Pc/Tr;
				//System.out.println("x= "+x+" fc= "+fc);
				// eğer kök olan bölge bulunduysa.....
				if (fc*fp < 0.0 || fp==0) {
					xb[0]=x-dx;
					xb[1]=x;
					nb++;
				}
				fp=fc;
				if (nbb == nb) return xb;
			}	
		if( nb == 0){
		System.out.println("Errror : arama tamamlandı kök olan bölge bulunamadı 1888 @LeeKesler.java");	
		System.exit(1);
	}
		//System.out.println("x0= "+xb[0]+"  x1= "+xb[1]);
		return xb;
       
       
       /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	    //returns a bracketed root 
	//if a root is not bracketed, enlarge region outwards each time	     
       /*double Tr=T/Tc;
       double Vr=Pc*V*1e5/(R*Tc);
       int NTRY=50;
	double a[]=new double[2];
	double FACTOR=1.002;
	int j;
	double f1,f2;
	if (x1 == x2) System.out.println("Bad initial range in ZBRAC");
	f1=Z_TP_LK_L(T,x1)-x1*Vr/Pc/Tr;
	f2=Z_TP_LK_L(T,x2)-x2*Vr/Pc/Tr;
        System.out.println("----Bracket------");
        System.out.println("Z_TP_LK_L(T,9.606443007861747)="+Z_TP_LK_L(T,9.606443007861747)+" 9.606443007861747*Vr/Pc/Tr="+
        (9.606443007861747*Vr/Pc/Tr)+"  "+(Z_TP_LK_L(T,9.606443007861747)-9.606443007861747*Vr/Pc/Tr));
        System.out.println("x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
	for (j=1;j<=NTRY;j++) {
		if (f1*f2 < 0.0) {break;}
	if (Math.abs(f1) < Math.abs(f2)){                  
                        x1 +=0.5*(-x1);                        
			f1=Z_TP_LK_L(T,x1)-x1*Vr/Pc/Tr;
              System.out.println("|f1|<|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }
		else{
                        x2 +=FACTOR*(x2-x1);                        
			f2=Z_TP_LK_L(T,x2)-x2*Vr/Pc/Tr;
                  System.out.println("|f1|>|f2|"+"  x1="+x1+"  f1="+f1+"  x2="+x2+"  f2="+f2);
                }                   
                
	}       
           //Bisection method
        int maxit=20,iter=0;
       double es=0.0001;
       double dxp=Math.abs((x2-x1)/2);    
       double xr;      
       double fx=Z_TP_LK_L(T,x1)-x1*Vr/Pc/Tr;
       double fxr;
       for(int i=0;i<maxit;i++)
       {
           xr=x1+dxp;
           if(xr>x2) break;
           fxr=Z_TP_LK_L(T,xr)-xr*Vr/Pc/Tr;
           //System.out.println("fxr="+fxr);
           if(fx*fxr<0)
           {   x2=xr;
               if((x2-x1)<=es)  break;
           }
           else if (fx*fxr>0){ 
               x1=xr;
               if((x2-x1)<=es)  break;  
             //  System.out.println("x1="+x1+" x2="+x2);
           }
           else System.out.println("Kök aral??? hatal?!....");
           dxp=(x2-x1)/2.0;
         }
       System.out.println("x1="+x1+" x2="+x2); 
	a[0]=x1;a[1]=x2;return a;*/
   }
   
    
//------------------------------------------------------------------------------------------------------------------------------
  
   public void setconstants(double T,String s){
     if(s.equals("VW"))//van der Waals
     {
     u=0;
     w=0;
     b=8314.5*Tc/(32*Pc*1e5);
     a=27.0/64.0*(R*R*Tc*Tc)/(Pc*1e5);
     }
     else if(s.equals("RK"))//Redlich Kwong
     {
     u=1;
     w=0;
     b=0.08664*R*Tc/(Pc*1e5);
     a=0.42748*R*R*Math.pow(Tc,2.5)/(Pc*1e5*Math.sqrt(T));
     }
     else if(s.equals("S"))//Soave
     {
     u=1;
     w=0;
     double fw=0.48+1.57*Omega-0.176*Omega*Omega;
     double Tr=T/Tc;
     b=0.08664*R*Tc/(Pc*1e5);
     double xy=1.0+fw*(1.0-Math.sqrt(Tr));
     a=0.42748*R*R*Tc*Tc/(Pc*1e5)*xy*xy;
     }
     else if(s.equals("PR"))//Peng Robinson
     {
     u=2;
     w=-1;
     double fw=0.37464+1.54226*Omega-0.26992*Omega*Omega;
     double Tr=T/Tc;
     b=0.07780*R*Tc/(Pc*1e5);
     double xy=1.0+fw*(1.0-Math.sqrt(Tr));
     a=0.45724*R*R*Tc*Tc/(Pc*1e5)*xy*xy;
     }
    }
   public double P_TV_PR_V(double T,double V){
      setconstants(T,"PR");
      double v=V;
      return (R*T/(v-b)-a/(v*v+u*b*v+w*b*b))*1e-5;     
   }     
   public double Z_TP_PR_V(double T, double P){
     //This value is calculated by using Peng-Robinson Equation of state
     //vapor phase compresibility factor
     //System.out.println("PR ba?lad?------------------------");
     setconstants(T,"PR");
     double AY=a*(P*1e5)/(R*R*T*T);
     //System.out.println("a "+a+" (P*1e5) "+(P*1e5)+" R*R*T*T "+R*R*T*T);
     double BY=b*(P*1e5)/(R*T);
    // System.out.println("P "+P);
     //System.out.println("AY "+AY+" BY "+BY);
     double A=-(1+BY-u*BY);
     double B=AY+w*BY*BY-u*BY-u*BY*BY;
     double C=-AY*BY-w*BY*BY-w*BY*BY*BY;
     double cof[]=new double[4];
     cof[0]=1;
     cof[1]=A;
     cof[2]=B;
     cof[3]=C;
     //System.out.println("A "+A+" B "+B+" C "+C);
     complex zc[]=Matrix.poly_rootsC(cof);
     //complex zc[]=Matrix.cubic_rootsC(cof);
     //System.out.println("PR Zc mztrisi=\n"+Matrix.toString(zc));
     double Z=max(zc);
     //System.out.println("Z="+Z);
     double q=Z*Z*Z+A*Z*Z+B*Z+C;
     //System.out.println("q="+q);
    // System.out.println("PR bitti------------------------");
     return Z;
   }
   public double Z_TP_PR_L(double T, double P){
     // This value is calculated by using Peng-Robinson Equation of state
     // liquid phase compressibility factor
     // if state is above critical liquid compressibility factor will be same as
     // vapor compressibility factor.
   //  System.out.println("==================================PR başladi==============================");
        setconstants(T,"PR");
        double AY=a*(P*1e5)/(R*R*T*T);
        //System.out.println("P="+P+" a="+a+" R="+R+" AY="+AY);
        double BY=b*(P*1e5)/(R*T);
        double A=-(1+BY-u*BY);
        double B=AY+w*BY*BY-u*BY-u*BY*BY;
        double C=-AY*BY-w*BY*BY-w*BY*BY*BY;
        //System.out.println("A "+A+" B "+B+" C "+C);
        double cof[]=new double[4];
        cof[0]=1;
        cof[1]=A;
        cof[2]=B;
        cof[3]=C;
        
       complex zc[]=Matrix.poly_rootsC(cof);
       //complex zc[]=Matrix.cubic_rootsC(cof);
       //System.out.println(Matrix.toString(zc));
       double zz=min(zc);
      // System.out.println("=================================PR bitti====================================");
       return zz;
   }
   double max(complex x[]){
     //maximum of complex compressibility factor solution (Peng Robinson E.S.)
     // this solution also check if solution is real or complex
     // and ignore complex solution points
     double nmax=-1e99;
     for(int i=0;i<x.length;i++)
     {
     if( (x[i].nimag>=0.0 && x[i].nimag<1e-4))
       {
       if(x[i].nreal>nmax) nmax=x[i].nreal;
       }
     }
   return nmax;
   }
   double min(complex x[]){
   //minimum of complex compressibility factor solution (Peng Robinson E.S.)
   //this solution also chack if solution is real or complex
   //and ignore complex solution points
     double nmin=1e99;
     for(int i=0;i<x.length;i++)
     {
     if((x[i].nimag>=0.0 && x[i].nimag<1e-4))
       {
       if(x[i].nreal<nmin) nmin=x[i].nreal;
       }
     }
   return nmin;
   }
   public double P_TV_VW_V(double T,double V){
     double Tr=T/Tc;        
     double Vr=Pc*V*1e5/(R*Tc);
     double Pr=Tr/(Vr-1/8)-27/(64*Vr*Vr);
      return Pr*Pc;
  }  
   public double T_VP_VW_V(double V,double P){
       setconstants(0,"VW");    
       return (P*1e5+a/(V*V))*(V-b)/R;
     
   }   
   double dZ_TP_LK_VL(double T,double P){
	   //System.out.println("  c"+" P cdeki"+P );
	   //System.out.println(" burda "+Z_TP_LK_L(T,P));
	   return Z_TP_LK_V(T,P)-Z_TP_LK_L(T,P);
   }
   
//===================================================================
//State of equation variations

  public double P_TV_LK_V(double T, double V){
	  if(Formula.equals("H2O"))  return st.P(T-273.15,V/MolWt);
      double Zinner[][]=new double[3][2];
      Zinner=Z_TV_LK_VA(T,V);	    
      return Zinner[2][1]*R*T/(V*1e5);
   }
  public double P_TV_LK_L(double T, double V){   	  
	   if(Formula.equals("H2O"))  return st.P(T-273.15,V/MolWt);
	   return Z_TV_LK_L(T,V)*R*T/(V*1e5);
   }
  public double V_TP_LK_V(double T, double P){
	   if(Formula.equals("H2O"))  return st.v_tp(T-273.15,P)*MolWt;
	   return Z_TP_LK_V(T,P)*R*T/(P*1e5);
   }
  public double V_TP_LK_L(double T, double P){	
	  if(Formula.equals("H2O"))  return (st.v_tp(T-273.15,P))*MolWt;  
	   return Z_TP_LK_L(T,P)*R*T/(P*1e5);
   }
  public double T_VP_LK_V(double V,double P){
	   if(Formula.equals("H2O"))  return st.t_pv(P,V/MolWt);
      double Z[][]=new double[3][2];      
      Z=Z_VP_LK_VA(V,P);       
      return (P*1e5*V)/Z[2][1]/R;
  }
  public double T_VP_LK_L(double V,double P){
	   if(Formula.equals("H2O"))  return st.t_pv(P,V/MolWt);
      double Z[][]=new double[3][2];
      Z=Z_VP_LK_LA(V,P);
      return (P*1e5*V)/Z[2][1]/R;
  }
  
//===================================================================
//saturated vapor volume estimation equations

   public double V_T_LK_SV(double T){
   if(Formula.equals("H2O"))  return st.vsg_t(T-273.15);	   
   double Pinner;
   if(T<Tc)
   { 
   Pinner=P_T_SV(T);
   return Z_TP_LK_V(T,Pinner)*R*T/(Pinner*1e5);
   }
   else
   return 0;
   }   
   public double V_P_LK_SV(double P){
   if(Formula.equals("H2O"))  return st.vsg_t(st.Ts(P));	 	   
   double Tinner;
   if(P<Pc)
   { 
   Tinner=T_P_SV(P);
   return Z_TP_LK_V(Tinner,P)*R*Tinner/(P*1e5);
   }
   else
   return 0;
   }
   
 //===================================================================
 //saturated liquid volume equations  
 
   public double V_T_LK_SL(double T){
   if(Formula.equals("H2O"))  return st.vsl_t(T-273.15);
   double Pinner; 
   //System.out.println("T= "+T);   
   if(T<Tc)
   {
   Pinner=P_T_SV(T); 
   return Z_TP_LK_L(T,Pinner)*R*T/(Pinner*1e5);
   }
   else return 0;
   }
   public double V_T_BE_SL(double T){
   //Volume of saturated liquid as a function of temperature
   //Bhirud equation
   if(T<Tc)
   {
   double Tr=T/Tc;
   double Tr2=Tr*Tr;
   double Tr3=Tr*Tr2;
   double Tr4=Tr2*Tr2;
   double Tr5=Tr3*Tr2;
   double Tr6=Tr3*Tr3;
   double lnV0=1.39644-24.076*Tr+102.615*Tr2-255.719*Tr3+
   355.805*Tr4-256.671*Tr5+75.1088*Tr6;
   double lnV1=13.4412-135.7437*Tr+533.38*Tr2-1091.453*Tr3+
   1231.43*Tr4-728.227*Tr5+176.737*Tr6;
   return (R*T/(Pc*1e5)*Math.exp(lnV0+Omega*lnV1));
   }
   else
   {
   return 0;
   }
   }
   public double V_T_RE_SL(double T){
   //Volume of saturated liquid as a function of temperature
   // Rackett equation
   if(T<Tc)
   {
   double deger=0;
   double Tr=T/Tc;
   double ZRA;
      if(0.98>Tr && Tr>=1.0 )
        {ZRA=Zc;}
      else
        {ZRA=0.29506-0.08775*Omega;}
     if(LDEN!=0)
     {
      double VSR=1.0/(LDEN*1e3/M);
      double TrR=TDEN/Tc;
      double SI=Math.pow((1-Tr),(2.0/7.0))-Math.pow((1-TrR),(2.0/7.0));
      ZRA=0.29506-0.08775*Omega;
      deger=VSR*Math.pow(ZRA,SI);
     }
     else
     {
     double SI=1+Math.pow((1-Tr),(2.0/7.0));
     deger=R*Tc/Pc*Math.pow(ZRA,SI);
     }
   return deger;
   }
   else
   return 0;
   }
   public double V_P_RE_SL(double P){
   //Volume of saturated liquid as a function of pressure
   // Rackett equation
   if(P<Pc)
   {
   return V_T_RE_SL(T_P_SV(P));
   }
   else
   return 0;
   }
   public double V_P_BE_SL(double P){
   //Volume of saturated liquid as a function of pressure
   if(P<Pc)
   {
   return V_T_BE_SL(T_P_SV(P));
   }
   else
   return 0;
   }
   public double V_P_LK_SL(double P){
   double Tinner;    
   if(P<Pc)
   {
   Tinner=T_P_SV(P); 
   return Z_TP_LK_L(Tinner,P)*R*Tinner/(P*1e5);
   }
   else return 0;
   }
   
//===================================================================
//saturation pressure and temprature estimation

   public double P_T_SV(double T) {
   //boiling (saturated vapor) pressure (bar) of the substance
   // at a given temperature
   if(T<Tc)
   {
   double deger=0;
   if(VPEq==1)
      {
       double x=1-T/Tc;
       double x3=x*x*x;
       double x6=x3*x3;
       deger=Pc*Math.exp((VPC[0]*x+VPC[1]*Math.pow(x,1.5)+VPC[2]*x3+VPC[3]*x6)/(1-x));
      }
   else if(VPEq==2)
      {
      //first guess is done by using Gomez-Thodos method
      double VP=P_T_GT_SV(T);
      double fx,dfx;
      int nmax=100;
      double tolerance=1.0e-10;
      int i=0;
      while(i++<nmax)
      {
        fx = -Math.log(VP)+(VPC[0]-VPC[1]/T+VPC[2]*Math.log(T)+VPC[3]/(T*T)*VP);
        dfx=VPC[3]/(T*T)-1.0/VP;
        VP-=fx/dfx;
        if(Math.abs(fx)<tolerance)
          {deger=VP;break;}
      }
      deger=VP;
      }
   else if(VPEq==3)
      {
      deger=Math.exp(VPC[0]-VPC[1]/(T+VPC[2]));
      }
   else if(VPEq==4 || VPEq==0)
      {
      //assume Lee - Kesler estimation
      deger=P_T_LK_SV(T);
      }
   return deger;
   }
   else
   return 0;
   }//end of PVp
   public double T_P_SV(double P){
   //boiling Temperature (K) of the substance
   // at a given pressure
   {
   double deger=0;
   int nmax=150;
   double tolerance=1.0e-10;
   double Pr=P/Pc;
   //Lee Kesler equation is used as first estimation
   double T=T_P_LK_SV(P);
   if(VPEq==1)
      {
       double x=1-T/Tc;
       double fx,dfx;
      int i=0;
      while(i++<nmax)
      {
      double x3=x*x*x;
      double x6=x3*x3;
      double fx1 = (VPC[0]*x+VPC[1]*Math.pow(x,1.5)+VPC[2]*x3+VPC[3]*x6)/(1-x);
        fx=fx1-Math.log(Pr);
        dfx=(VPC[0]+1.5*VPC[1]*Math.pow(x,0.5)+3*x*x*VPC[2]+6*VPC[3]*x6)/x +
        (VPC[0]*x+VPC[1]*Math.pow(x,1.5)+VPC[2]*x3+VPC[3]*x6)/(x*x);
        x-=fx/dfx;
        T=(1-x)*Tc;
        if(Math.abs(fx)<tolerance)
          {break;}
      }
      deger=T;
      }
   else if(VPEq==2)
      {
      double x=1-T/Tc;
      double fx,dfx;
      int i=0;
      while(i++<nmax)
      {
        fx = VPC[0]-VPC[1]/T+VPC[2]*Math.log(T)+VPC[3]*P/(T*T)-Math.log(P);
        dfx= VPC[1]/(T*T)+VPC[2]/T-2.0*VPC[3]*P/(T*T*T);
        T-=fx/dfx;
         if(Math.abs(fx)<tolerance)
          {break;}
      }
      deger=T;
      }
   else if(VPEq==3)
      {
      deger=VPC[1]/(VPC[0]-Math.log(Pr))-VPC[2];
      }
   else if(VPEq==4 && VPEq==0)
      {
       deger=T_P_LK_SV(P);
      }
   return deger;
   }
   }//end of
   public double P_T_LK_SV(double T){
   //Lee-Kesler saturated vapor pressure estimation
   double Tr=T/Tc;
   //System.out.println("Tr= "+Tr);
   double Tr6=Tr*Tr*Tr*Tr*Tr*Tr;
   double f1=5.92714-6.09648/Tr-1.28862*Math.log(Tr)+0.169347*Tr6;
   double f2=15.2518-15.6875/Tr-13.4721*Math.log(Tr)+0.43577*Tr6;
   double teta=Tb/Tc;
   double teta6=teta*teta*teta*teta*teta*teta;
   double alfa=-Math.log(Pc)-5.92714+6.09648/teta+1.28862*Math.log(teta)-
   0.169347*teta6;
   double beta=15.2518-15.6875/teta-13.4721*Math.log(teta)+0.43577*teta6;
   double ww=alfa/beta;
   //System.out.println("ww  "+ww+" f1= "+f1+" f2= "+f2);
   //3.println(" PPP "+Pc*Math.exp(f1+ww*f2));
   return Pc*Math.exp(f1+ww*f2);
   }
   public double T_P_LK_SV(double P){
   //Lee-Kesler vapor temperature estimation
   //boiling Temperature (K) of the substance
   // at a given pressure
   double teta=Tb/Tc;
   double teta6=teta*teta*teta*teta*teta*teta;
   double alfa=-Math.log(Pc)-5.92714+6.09648/teta+1.28862*Math.log(teta)-
   0.169347*teta6;
   double beta=15.2518-15.6875/teta-13.4721*Math.log(teta)+0.43577*teta6;
   double ww=alfa/beta;
      //first guess is carried out by using gomez - thodos equation
      double T=T_P_GT_SV(P);      
      double Tr=T/Tc;
      double Tr6=Tr*Tr*Tr*Tr*Tr*Tr;
      double Pr=P/Pc;
      double fx,dfx;
      int nmax=500;
      double tolerance=1.0e-15;
      int i=0;
      while(i++<nmax)
      {
      double f1=5.92714-6.09648/Tr-1.28862*Math.log(Tr)+0.169347*Tr6;
      double f2=15.2518-15.6875/Tr-13.4721*Math.log(Tr)+0.43577*Tr6;
      double df1=6.09648/(Tr*Tr)-1.28862/Tr-1.1016082*Tr6/Tr;
      double df2=15.6875/(Tr*Tr)-13.4721/Tr+2.61462*Tr6/Tr;
        fx = f1+ww*f2-Math.log(Pr);
        dfx=df1+ww*df2;
        Tr-=fx/dfx;
        if(Math.abs(fx)<tolerance)
          {break;}
      }
      T=Tr*Tc;
     return T;
   }
   public double P_T_WE_SV(double T){
   // Lee Kesler - Wagner equation for vapor pressure estimation
     if(T<Tc)
     {
     double A[][]=
    {{369.85, 42.4535, 0.153, -6.72219, 1.33236, -2.13868, -1.38551},
     {562.16, 48.9794, 0.212, -6.98273, 1.33213, -2.62863, -3.33399},
     {568.81, 24.8617, 0.398, -7.91211, 1.38007, -3.80435, -4.50132},
     {566.52, 31.2481, 0.415, -8.05688, 1.46673, -3.82439, -2.78724}};
     double deger=0;
     double Tr=T/Tc;
     double x=1-Tr;
     double x3=x*x*x;
     double x6=x3*x3;
     for(int i=0;i<3;i++)
     {
      if(Omega>A[i][2]&&Omega<A[i+1][2])
      {
       double lnPvpR1=(A[i][3]*x+A[i][4]*Math.pow(x,1.5)+A[i][5]*x3+A[i][6]*x6)/(1-x);
       double lnPvpR2=(A[i+1][3]*x+A[i+1][4]*Math.pow(x,1.5)+A[i+1][5]*x3+A[i+1][6]*x6)/(1-x);
       double y1=(Omega-A[i][2])/(A[i+1][2]-A[i][2]);
       double y=lnPvpR1+(lnPvpR2-lnPvpR1)*y1;
       deger=Pc*Math.exp(y);
       break;
      }
     }
     return deger;
     }
     return 0;
   }
   public double T_P_WE_SV(double P){
   if(P<Pc)
   {
   //Lee Kesler - Wagner equation for vapor temperature estimation
   //boiling Temperature (K) of the substance at a given pressure
     double A[][]=
    {{369.85, 42.4535, 0.153, -6.72219, 1.33236, -2.13868, -1.38551},
     {562.16, 48.9794, 0.212, -6.98273, 1.33213, -2.62863, -3.33399},
     {568.81, 24.8617, 0.398, -7.91211, 1.38007, -3.80435, -4.50132},
     {566.52, 31.2481, 0.415, -8.05688, 1.46673, -3.82439, -2.78724}};
      //first guess
      double T=T_P_SV(P);
      double Tr=T/Tc;
      double x=1.0-Tr;
      double Pr=P/Pc;
      int nmax=200;
      double tolerance=1.0e-20;
      int j=0;
      for(int i=0;i<3;i++)
      {
      if(Omega>A[i][2]&&Omega<A[i+1][2])
      {
      while(j++<nmax)
      {
       double fx,dfx;
       double x2=x*x;
       double x3=x*x*x;
       double x5=x3*x2;
       double x6=x3*x3;
       double lnPvpR1=(A[i][3]*x+A[i][4]*Math.pow(x,1.5)+A[i][5]*x3+A[i][6]*x6)/(1-x);
       double lnPvpR2=(A[i+1][3]*x+A[i+1][4]*Math.pow(x,1.5)+A[i+1][5]*x3+A[i+1][6]*x6)/(1-x);
       double d_lnPvpR1=(A[i][3]+1.5*A[i][4]*Math.pow(x,0.5)+3*A[i][5]*x2+
       6*A[i][6]*x5)/(1-x)+lnPvpR1/(1-x);
       double d_lnPvpR2=(A[i+1][3]+1.5*A[i+1][4]*Math.pow(x,0.5)+3*A[i+1][5]*x2+
       6*A[i+1][6]*x5)/(1-x)+lnPvpR2/(1-x);
       double y1=(Omega-A[i][2])/(A[i+1][2]-A[i][2]);
       fx=lnPvpR1+(lnPvpR2-lnPvpR1)*y1-Math.log(Pr);
       dfx=d_lnPvpR1+(d_lnPvpR2-d_lnPvpR1)*y1;
       //fx=Pc*Math.exp(y);
       x-=fx/dfx;
        if(Math.abs(fx)<tolerance)
          {break;}
      } //end of while
      } //end of if
      }//end of for

      T=Tc*(1-x);
      return T;
      }
      else
        return 0;
   } 
   public double P_T_GT_SV(double T){
   if(T<Tc)
   {
   //Gomez-Thodos vapor pressure estimation
   double Tbr=Tb/Tc;
   double Tr=T/Tc;
   double h=Tbr*Math.log(Pc)/(1-Tbr);
   double delta=0;
   double m,gama,beta,aa,bb;
   double Tbr7=Tbr*Tbr*Tbr*Tbr*Tbr*Tbr*Tbr;
   if(Formula=="H2O" &&  Name=="Water")
     {
      delta=0.19904;
     }
   if(Formula=="H2" && Name=="Hydrogen")
     {
     delta=0.41815;
     }
   if(Formula=="Ne")
     {
     delta=0.02319;
     }
   m=0.78425*Math.exp(0.089315*h)-8.5217/Math.exp(0.74826*h);
   beta=-4.267-221.79/(Math.pow(h,2.5)*Math.exp(0.0384*Math.pow(h,2.5)))+
   3.8126/Math.exp(2272.44/(h*h*h))+delta;
   aa=(1.0-1.0/Tbr)/(Tbr7-1);
   bb=(1.0-1/Math.pow(Tbr,m))/(Tbr7-1);
   gama=aa*h+bb*beta;
   if(Formula=="H2" && Name=="Hydrogen")
     {
     m=0.0052*Math.pow(M,0.29)*Math.pow(Tc,0.72);
     gama=2.464/M*Math.exp(9.8e-6*M*Tc);
     beta=gama/bb-aa*h/bb;
     }
   double sonuc=Pc*Math.exp(beta*(1.0/Math.pow(Tr,m)-1)+
   gama*(Tr*Tr*Tr*Tr*Tr*Tr*Tr-1.0));
   return sonuc;
   }
   else
    return 0;
   }
   public double T_P_GT_SV(double P){
   if(P>Pc)
      return 0;
   else
   {
   //Gomez-Thodos vapor Temperature estimation
   //boiling Temperature (K) of the substance
   // at a given pressure
   double Tbr=Tb/Tc;
   double h=Tbr*Math.log(Pc)/(1-Tbr);
   double delta=0;
   double m,gama,beta,aa,bb;
   double Tbr7=Tbr*Tbr*Tbr*Tbr*Tbr*Tbr*Tbr;
   if(Formula=="H2O" &&  Name=="Water")
     {
      delta=0.19904;
     }
   if(Formula=="H2" && Name=="Hydrogen")
     {
     delta=0.41815;
     }
   if(Formula=="Ne")
     {
     delta=0.02319;
     }
   m=0.78425*Math.exp(0.089315*h)-8.5217/Math.exp(0.74826*h);
   beta=-4.267-221.79/(Math.pow(h,2.5)*Math.exp(0.0384*Math.pow(h,2.5)))+
   3.8126/Math.exp(2272.44/(h*h*h))+delta;
   aa=(1.0-1.0/Tbr)/(Tbr7-1);
   bb=(1.0-1/Math.pow(Tbr,m))/(Tbr7-1);
   gama=aa*h+bb*beta;
   if(Formula=="H2" && Name=="Hydrogen")
     {
     m=0.0052*Math.pow(M,0.29)*Math.pow(Tc,0.72);
     gama=2.464/M*Math.exp(9.8e-6*M*Tc);
     beta=gama/bb-aa*h/bb;
     }
      //first guess is carried out by using clapeyron equation
      double T=T_P_CE_SV(P);
      double Tr=T/Tc;
      double Pr=P/Pc;
      double fx,dfx;
      int nmax=500;
      double tolerance=1.0e-15;
      int i=0;
      while(i++<nmax)
      {
        fx = -Math.log(Pr)+beta*(1.0/Math.pow(Tr,m)-1)+
        gama*(Tr*Tr*Tr*Tr*Tr*Tr*Tr-1.0);
        dfx=beta*(-m/Math.pow(Tr,(m+1))-1)+
        7.0*gama*Tr*Tr*Tr*Tr*Tr*Tr;
        Tr-=fx/dfx;
        if(Math.abs(fx)<tolerance)
          {break;}
      }
      T=Tr*Tc;
     return T;
   }
   }
   public double P_T_CE_SV(double T){
   //Clapeyron equation vapor pressure
   //boiling Temperature (K) of the substance
   // at a given pressure
   if(T>Tc) return 0;
   else
   {
   double Tbr=Tb/Tc;
   double h=Tbr*Math.log(Pc)/(1-Tbr);
   double Tr=T/Tc;
   return Pc*Math.exp(h*(1-1/Tr));
   }
   }
   public double T_P_CE_SV(double P){
   //Clapeyron equation vapor temperature
   if(P>Pc) return 0;
   else
   {
   double Tbr=Tb/Tc;
   double h=Tbr*Math.log(Pc)/(1-Tbr);
   double Pr=P/Pc;
   return Tc/(1-1/h*Math.log(Pr));
   }
   }

//===================================================================
//equations for enthalpy and entropy of vaporization

    public double dH_T_TS_SVL(double T){
   //Torquato and Stell equation
   // as a function of temperature
   // Torquato S.and G. R. Stell; Ind. Eng. Chem. Fundam., 21:202(1982)
    //Reference fluids benzene and carbazole
   if(T>Tc) return 0;
   else
   {
   double To=1-T/Tc;
   double dHR1=6.537*Math.pow(To,(1.0/3.0))-2.467*Math.pow(To,(5.0/6.0))-
   77.521*Math.pow(To,1.208)+59.634*To+36.009*To*To-14.606*To*To*To;
   double dHR21=-0.133*Math.pow(To,(1.0/3.0))-28.215*Math.pow(To,(5.0/6.0))-
   82.958*Math.pow(To,1.208)+99.0*To+19.105*To*To-2.796*To*To*To;
   double dH=dHR1+4*(Omega-0.21)*dHR21;
   double dH1=dH*R*Tc*1e-3;
   //unit of result KJ/kmol
   return dH1;
   }
   }
    public double dH_P_TS_SVL(double P){
    //Torquato and Stell equation
    // as a function of Pressure
    // Torquato S.and G. R. Stell; Ind. Eng. Chem. Fundam., 21:202(1982)
    //Reference fluids benzene and carbazole
    if(P<Pc)
      return dH_T_TS_SVL(T_P_GT_SV(P));
    else
      return 0;
    }
    public double dH_P_VE_SVL(double P){
	//Vetere method similar to Chen
    if(P<Pc)
      return dH_T_VE_SVL(T_P_GT_SV(P));
    else
      return 0;
    }
    public double dH_P_LK_SVL(double P){
    if(P<Pc)
      return dH_T_LK_SVL(T_P_GT_SV(P));
    else
      return 0;
    }
    public double dH_P_WE_SVL(double P){//Lee-Kesler Wagner 
    if(P<Pc)
      return dH_T_WE_SVL(T_P_GT_SV(P));
    else
      return 0;
    }
    public double dH_T_LK_SVL(double T) {
    //Lee-kesler equation for enthalpy of evaporation
    //System.out.println("  b");
    if(Name.equals("water")) return dH_T_VE_SVL(T); 
    if(T>Tc) return 0;       
    else
    {
    double Tr=T/Tc;
    
    double deger=6.09648-1.28862*Tr+1.016*Tr*Tr*Tr*Tr*Tr*Tr*Tr+
    Omega*(15.6875-13.4721*Tr+2.615*Tr*Tr*Tr*Tr*Tr*Tr*Tr);
    //System.out.println("deger "+deger);
    deger*=R*Tc*dZ_TP_LK_VL(T,P_T_SV(T))*1e-3;
    //System.out.println(deger+"  "+dZ_TP_LK_VL(T,P_T_SV(T)));
    return deger;
    }
   }
    public double dH_T_GT_SVL(double T) {
    //Ghomez-thodos equation for enthalpy of evaporation
   if(T>Tc) return 0;
   else
   {
   double Tbr=Tb/Tc;
   double Tr=T/Tc;
   double h=Tbr*Math.log(Pc)/(1-Tbr);
   double delta=0;
   double m,gama,beta,aa,bb;
   double Tbr7=Tbr*Tbr*Tbr*Tbr*Tbr*Tbr*Tbr;
   if(Formula=="H2O" &&  Name=="Water")
     {
      delta=0.19904;
     }
   if(Formula=="H2" && Name=="Hydrogen")
     {
     delta=0.41815;
     }
   if(Formula=="Ne")
     {
     delta=0.02319;
     }
   m=0.78425*Math.exp(0.089315*h)-8.5217/Math.exp(0.74826*h);
   beta=-4.267-221.79/(Math.pow(h,2.5)*Math.exp(0.0384*Math.pow(h,2.5)))+
   3.8126/Math.exp(2272.44/(h*h*h))+delta;
   aa=(1.0-1.0/Tbr)/(Tbr7-1);
   bb=(1.0-1/Math.pow(Tbr,m))/(Tbr7-1);
   gama=aa*h+bb*beta;
   if(Formula=="H2" && Name=="Hydrogen")
     {
     m=0.0052*Math.pow(M,0.29)*Math.pow(Tc,0.72);
     gama=2.464/M*Math.exp(9.8e-6*M*Tc);
     beta=gama/bb-aa*h/bb;
     }
   double sonuc=7.0*gama*Tr*Tr*Tr*Tr*Tr*Tr-beta*m/Math.pow(Tr,(m-1));
   sonuc*=R*Tc*dZ_TP_LK_VL(T,P_T_SV(T))*1e-3;
   return sonuc;
   }
   }
    public double dH_P_GT_SVL(double P){
    if(P<Pc)
      return dH_T_GT_SVL(T_P_GT_SV(P));
    else
      return 0;
    }
    public double dH_T_WE_SVL(double T) {
   // Lee Kesler - Wagner equation for enthapy of vaporisation   
   //System.out.println("we de-----------");  
   double A[][]=
    {{369.85, 42.4535, 0.153, -6.72219, 1.33236, -2.13868, -1.38551},
     {562.16, 48.9794, 0.212, -6.98273, 1.33213, -2.62863, -3.33399},
     {568.81, 24.8617, 0.398, -7.91211, 1.38007, -3.80435, -4.50132},
     {566.52, 31.2481, 0.415, -8.05688, 1.46673, -3.82439, -2.78724}};
     double deger=0;
     double Tr=T/Tc;
     double x=1-Tr;
     double x2=x*x;
     double x5=x2*x2*x;
     for(int i=0;i<3;i++)
     {     
      if(Omega>A[i][2]&&Omega<A[i+1][2])
      {
      double f1=-A[i][3]+A[i][4]*Math.pow(x,0.5)*(0.5*x-1.5)+
       A[i][5]*x2*(2.0*x-3.0)+A[i][6]*x5*(5.0*x-6.0);
       //System.out.println("f1= "+f1);       
       double f2=-A[i+1][3]+A[i+1][4]*Math.pow(x,0.5)*(0.5*x-1.5)+
       A[i+1][5]*x2*(2.0*x-3.0)+A[i+1][6]*x5*(5.0*x-6.0);
       //System.out.println("f2=  "+f2);
       double y1=(Omega-A[i][2])/(A[i+1][2]-A[i][2]);       
       //System.out.println("y1= "+y1);
       double y=f1+(f2-f1)*y1;
       deger=y*R*Tc*dZ_TP_LK_VL(T,P_T_SV(T))*1e-3;
       break;
      }
     
     }
     //if(deger==0)System.out.println("WE denklemi 0 verdi ");
     return deger;
   }
    public double dHb_T_VE_SVL(){
     double Tbr=Tb/Tc;
     double dH=R*1e-3*Tc*Tbr*(0.4343*Math.log(Pc)-0.69431+0.89584*Tbr)/
     (0.37691-0.37306*Tbr+0.15075/Pc/(Tbr*Tbr));
     return dH;
   }
    public double dH_T_VE_SVL(double T){
     if(T>Tc) return 0;
     else
     {
     double Tr=T/Tc;
     double n=(0.00264*dHb_T_VE_SVL()/(R*Tb)+0.8794);
     n=n*n*n*n*n*n*n*n*n*n;
     double dH=dHb_T_VE_SVL()*Math.pow((1-Tr)/(1-Tb/Tc),n);
     return dH;
     }
   } 
   public double dH_T_S_SVL(double T){		
	   if(T>Tc) return 0;
		double t=1-T/Tc;
		double dhR1=6.537*Math.pow(t,1.0/3.0)-2.467*Math.pow(t,5.0/6.0)-77.521*Math.pow(t,1.208)
		+59.634*t+36.009*t*t-14.606*t*t*t;	
		//System.out.println("dhR1= "+dhR1);	   
		double dhR21=-0.133*Math.pow(t,1.0/3.0)-28.215*Math.pow(t,5.0/6.0)-82.958*Math.pow(t,1.208)
		+99.0*t+19.105*t*t-2.769*t*t*t;
		//System.out.println("dhR21= "+dhR21);
		double OmegaR1=0.21;
		double OmegaR2=0.46;
		return (dhR1+(Omega-OmegaR1)/(OmegaR2-OmegaR1)*dhR21)*8.314*Tc;
		
   }  
   public double dS_T_K_SVL(double T){
       double Hinner=(dH_T_WE_SVL(T)==0)?(dH_T_LK_SVL(T)):(dH_T_WE_SVL(T));
      // System.out.println("dH_T_LK_SVL(T)="+dH_T_LK_SVL(T)+"  dH_T_WE_SVL(T)="+dH_T_WE_SVL(T));
      // System.out.println("Hinner="+Hinner);
      // System.out.println("Hinner/T="+(Hinner/T));
       return Hinner/T;	   
   }
    public double dS_P_K_SVL(double P){          
	   double Tinner=T_P_WE_SV(P);
           double Hinner=(dH_T_WE_SVL(Tinner)==0)?(dH_T_LK_SVL(Tinner)):(dH_T_WE_SVL(Tinner));
	   return Hinner/Tinner;
   }
    
//===================================================================
// Ideal gas equations

    public double Cp_T_IG_V(double T){  
// Specific heat under constant pressure, Cp of ideal gas J.mol/K
	double Cpi=0;  
  	Cpi=CPC[CPC.length-1];
  	for(int i=CPC.length-2;i>=0;i--)
   	{ Cpi=Cpi*T+CPC[i]; }
	
  	return Cpi;
   }
    public double h_T_IG_V(double T){
    //enthalpy of ideal gas
    //System.out.println("t= "+T);
    double h=0;
    double T2=0,T02=0;
    double T3=0,T03=0;
    double T4=0,T04=0;
    if(better_Cp){
				h=id_gas.h(T);
				//System.out.println("better  "+Name+" "+id_gas.gasName+"  "+h);				
		        }	
	else{
		 
         T2=T*T;
         T02=Tref*Tref;
         T3=T2*T;
         T03=Tref*T02;
         T4=T2*T2;
         T04=T02*T02;
         h=CPC[0]*(T-Tref)+CPC[1]*(T2-T02)/2.0+CPC[2]*(T3-T03)/3.0+CPC[3]*(T4-T04)/4.0;
         //System.out.println("worse  "+Name+h);
          
        }    
    return h;//kJ/kmol
}
    public double hf_T_IG_V(double T){
    return DELHF+h_T_IG_V(T);
}
    public double s_TP_IG_V(double T,double P){
	     double s=0;
	     if(better_Cp){
				s=id_gas.s(T,P);
				//System.out.println("better  "+Name+" "+id_gas.gasName+"  "+s);				
		              }	
	else{
        s=DELS0+CPC[0]*Math.log(T/Tref)+CPC[1]*(T-Tref)+CPC[2]/2.0*(T*T-Tref*Tref)+
                CPC[3]/3.0*(T*T*T-Tref*Tref*Tref);
        }
        return s;
}
//===================================================================
//departure functions of the real fluids

//===================================================================
//specific heat functions

    public double dCp_T_BR_L(double T){
  //liquid specific heat difference compare to IG vapor specific heat
        if(T<Tc)
        {
            double Tr=T/Tc;
            double x=1-Tr;
            double sonuc=1.45+0.45/x+0.25*Omega*(17.11+25.2*Math.pow(x,(1.0/3.0))/Tr+1.742/x );
            sonuc*=R*1e-3;
            return sonuc;
        }
        else
            return 0;
}
    public double dCs_T_BR_L(double T){
// saturated liquid specific heat difference compare to IG vapor specific heat
        if(T<Tc)
        {
            double Tr=T/Tc;
            double x=1-Tr;
            double sonuc=dCp_T_BR_L(T)-Math.exp(20.1*Tr-17.9)*R*1e-3;
            return sonuc;
        }
        else
            return 0;
}
    public double Cp_T_BR_L(double T){
//liquid specific heats
        return dCp_T_BR_L(T)+Cp_T_IG_V(T);
}
    public double Cp_T_BR_SL(double T){
//saturated liquid specific heats
        return dCs_T_BR_L(T)+Cp_T_IG_V(T);
}
    public double Cp_TP_BR_L(double T,double P){
        double dT=0.01;	
// liquid enthalpy
        return (h_TP_BR_L((T+dT),P)-h_TP_BR_L(T,P))/dT;
}
    
    //Helhmotz energy departure functions
    
    public double dhz_TP_LK_V(double T,double P){        
        double B0,C0,D0;
        double BR,CR,DR;
        double Tr=T/Tc;   
        double Pr=P/Pc;   
        double Vref=R*T;
        double Zinner[][]=new double[3][2];   
        Zinner=Z_TP_LK_VA(T,P);   
        double Vr0=Zinner[0][0];   
        double VrR=Zinner[1][0];   
        B0=b0[0]*Tr+b0[1]-b0[2]/Tr+2.0*b0[3]/(Tr*Tr);
        C0=c0[0]*Tr-c0[1]+c0[2]/(Tr*Tr);   
        D0=d0[0]*Tr+d0[1];         
        double E0=c0[3]/(2.0*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));       
        BR=bR[0]*Tr+bR[1]-bR[2]/Tr+2.0*bR[3]/(Tr*Tr);
        CR=cR[0]*Tr-cR[1]+cR[2]/(Tr*Tr);   
        DR=dR[0]*Tr+dR[1];         
        double ER=cR[3]/(2.0*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR));          
        double dhz0=-B0/Vr0-C0/(2.0*Vr0*Vr0)-D0/(5.0*Vr0*Vr0*Vr0*Vr0*Vr0)-2.0*E0;//-Math.log(Zinner[0][1])+    
        double dhzR=-BR/VrR-CR/(2.0*VrR*VrR)-DR/(5.0*VrR*VrR*VrR*VrR*VrR)-2.0*ER;       
        double dHZ=(Tr*Math.log(Zinner[2][0]/Vref)+dhz0+Omega/OmegaR*(dhzR-dhz0))*Tc*R*1e-3;       
        return dHZ;       
    }
    public double dhz_TV_LK_V(double T,double V){
        double P=P_TV_LK_V(T,V);
        return dhz_TP_LK_V(T,P);
    }
    public double dhz_VP_LK_V(double V,double P){
        double T=T_VP_LK_V(V,P);
        return dhz_TP_LK_V(V,P);
    } 
    
    //Enthalpy departure functions   
 
    public double dh_T_BR_L(double T){
        double x=1-T/Tc;
        double x0=1-298.15/Tc;
        double sonuc1=-R*Tc*1e-3*(1.45*x+0.45*Math.log(x)+0.25*Omega*(17.11*x+
                25.2*(Math.pow(x,(-2/3))/3.0*(1-x)+Math.pow(x,(1/3)))/((1-x)*(1-x))+1.74*Math.log(x)));
        double sonuc2=-R*Tc*1e-3*(1.45*x0+0.45*Math.log(x0)+0.25*Omega*(17.11*x0+
                25.2*(Math.pow(x0,(-2/3))/3.0*(1-x0)+Math.pow(x0,(1/3)))/((1-x0)*(1-x0))+1.74*Math.log(x0)));
        return (sonuc1-sonuc2);
}      
    public double[] dh_TP_LK_V_A(double T,double P){
       //This method calculate difference between ideal gas enthalpy
      //and real gas enthalpy
   double dH0,dHR;
   double Tr=T/Tc;
   double Pr=P/Pc;  
   double Zinner[][]=new double[3][2];
   double dh[]=new double[3];//dh 0 ,R and Gas 
   //System.out.println("T= "+T+" P= "+P);
   Zinner=Z_TP_LK_VA(T,P);
   double Vr0=Zinner[0][0];
   double VrR=Zinner[1][0];
//   System.out.println("Zinner[0][0]i= "+Zinner[0][0]+" Zinner[1][0]i= "+Zinner[1][0]);
   double E0=c0[3]/(2.0*Tr*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));
  //  System.out.println("c0[3]/(2.0*Tr*Tr*Tr*gama0)="+c0[3]/(2.0*Tr*Tr*Tr*gama0)+" beta0+1-(beta0+1+gama0/Vr0/Vr0)= "+(beta0+1-(beta0+1+gama0/Vr0/Vr0))+" Math.exp(-gama0/Vr0/Vr0)= "+Math.exp(-gama0/Vr0/Vr0));
   double dh0=-Tr*(Zinner[0][1]-1-(b0[1]+2.0*b0[2]/Tr+3.0*b0[3]/(Tr*Tr))/(Tr*Vr0)
    -(c0[1]-3.0*c0[2]/Tr/Tr)/(2.0*Tr*Vr0*Vr0)
    +d0[1]/(5*Tr*Vr0*Vr0*Vr0*Vr0*Vr0)
    +3.0*E0); 
    dh[0]=dh0; 
    double ER=cR[3]/(2*Tr*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR));
    double dhR=-Tr*(Zinner[1][1]-1-(bR[1]+2*bR[2]/Tr+3*bR[3]/(Tr*Tr))/(Tr*VrR)
    -(cR[1]-3*cR[2]/Tr/Tr)/(2*Tr*VrR*VrR)
    +dR[1]/(5*Tr*VrR*VrR*VrR*VrR*VrR)
    +3*ER);
    dh[1]=dhR;
    //dh[1]=(dhR-dh0)/OmegaR;
    //System.out.println("E0= "+E0+" dh0="+dh0+" ER= "+ER +" dhR= "+dhR);
    //System.out.println("dhR= "+dhR);    
    double dH=dh0+Omega/OmegaR*(dhR-dh0);
    //double dH=(dhR-dh0)/OmegaR;
    //System.out.println("dh= "+dH);
    dH*=R*Tc*1e-3;
    dh[2]=dH;
    return dh;       
}
 public double dh_TP_LK_V(double T,double P){
       //This method calculate difference between ideal gas enthalpy
      //and real gas enthalpy  
   	double dh[]=new double[3];//dh 0 ,R and Real Gas  Enthalpy
   	dh=dh_TP_LK_V_A(T,P);
    return dh[2];       
}
    public double dh_TV_LK_V(double T, double V){
//This method calculate difference between ideal gas enthalpy
//and real gas enthalpy 
        double P=P_TV_LK_V(T,V);
        return dh_TP_LK_V(T,P);
    }  
    public double dh_VP_LK_V(double V,double P){
        return dh_TV_LK_V(T_VP_LK_V(V,P),V);
}
    public double dh_TP_LK_L1(double T,double P){	        
 //This method calculate difference between ideal gas enthalpy
//and real gas enthalpy
   double dH0,dHR;
   double Tr=T/Tc;
   double Pr=P/Pc;
   double Zinner[][]=new double[3][2];
   Zinner=Z_TP_LK_LA(T,P);
   //System.out.println(" Zinner= "+ Zinner[0][0]+"  "+Zinner[1][0]);
   double Vr0=Zinner[0][0];
   double VrR=Zinner[1][0];
   //System.out.println("zx hatali= "+ZX);
   double E0=c0[3]/(2.0*Tr*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));
   double dh0=-Tr*(Zinner[0][1]-1-(b0[1]+2.0*b0[2]/Tr+3.0*b0[3]/(Tr*Tr))/(Tr*Vr0)
    -(c0[1]-3.0*c0[2]/Tr/Tr)/(2.0*Tr*Vr0*Vr0)
    +d0[1]/(5*Tr*Vr0*Vr0*Vr0*Vr0*Vr0)
    +3.0*E0);
    ///System.out.println("E0= "+E0+"dh0= "+dh0);  
    double ER=cR[3]/(2*Tr*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR));
    double dhR=-Tr*(Zinner[1][1]-1-(bR[1]+2*bR[2]/Tr+3*bR[3]/(Tr*Tr))/(Tr*VrR)
    -(cR[1]-3*cR[2]/Tr/Tr)/(2*Tr*VrR*VrR)
    +dR[1]/(5*Tr*VrR*VrR*VrR*VrR*VrR)
    +3*ER);
    //System.out.println("E0= "+E0+"dh0= "+dh0+" ER= "+ER);
    //System.out.println("dhR= "+dhR);    
    double dH=dh0+Omega/OmegaR*(dhR-dh0);
    //System.out.println("dh= "+dH);
    dH*=R*Tc*1e-3;
    //System.out.println("dh= "+dH);
    return dH;    
  
	
}
    public double dh_TP_LK_L(double T,double P){	        
 //This method calculate difference between ideal gas enthalpy
//and real gas enthalpy
    double Ps=P_T_SV(T);
/*    System.out.println("--------------------------------------------------");
    System.out.println("Ps= "+Ps);
    System.out.println("dh_TP_LK_L1(T,P)= "+dh_TP_LK_L1(T,P));
    System.out.println("dh_TP_LK_L1(T,Ps)= "+dh_TP_LK_L1(T,Ps));
    System.out.println("dH_T_LK_SVL(T)= "+dH_T_LK_SVL(T));
    System.out.println("dh_TP_LK_V(T,Ps)= "+dh_TP_LK_V(T,Ps));
     System.out.println("--------------------------------------------------");*/
    return dh_TP_LK_L1(T,P)-dh_TP_LK_L1(T,Ps)+dH_T_LK_SVL(T)+dh_TP_LK_V(T,Ps);
    }
    public double dh_TV_LK_L(double T,double V){	        
 //This method calculate difference between ideal gas enthalpy
//and real gas enthalpy
    double P=P_TV_LK_L(T,V);
    double Ps=P_T_LK_SV(T);
    return dh_TP_LK_L1(T,P)-dh_TP_LK_L1(T,Ps)+dH_T_LK_SVL(T)+dh_TP_LK_V(T,Ps);
	
}
    public double dh_VP_LK_L(double V,double P){	        
 //This method calculate difference between ideal gas enthalpy
//and real gas enthalpy
    double T=T_VP_LK_L(V,P);
    double Ps=P_T_LK_SV(T);
    return dh_TP_LK_L1(T,P)-dh_TP_LK_L1(T,Ps)+dH_T_LK_SVL(T)+dh_TP_LK_V(T,Ps);
       }
    
    //Entropy departure functions  

    public  double  ds_TP_LK_V(double T, double P){
// difference between ideal gas entropy and real gas entropy
   double dS0,dSR;
   double V0,VR,Vr0,VrR,P0,PR;
   double Tr=T/Tc;
   double Pr=P/Pc;
   double Zinner[][]=new double[3][2];
   Zinner=Z_TP_LK_VA(T,P);
   Vr0=Zinner[0][0];
   VrR=Zinner[1][0];
   double B0,C0,D0;
   double BR,CR,DR;
   
    B0=b0[0]+b0[2]/(Tr*Tr)+2.0*b0[3]/(Tr*Tr*Tr);
    C0=c0[0]-2.0*c0[2]/(Tr*Tr*Tr);
    D0=d0[0];
    
    double E0=c0[3]/(2.0*Tr*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));  
    
    BR=bR[0]+bR[2]/(Tr*Tr)+2.0*bR[3]/(Tr*Tr*Tr);
    CR=cR[0]-2.0*cR[2]/(Tr*Tr*Tr);
    DR=dR[0];  
    double ER=cR[3]/(2*Tr*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR)); 
  
    double ds0=-Math.log(Zinner[0][1])+B0/Vr0+C0/(2.0*Vr0*Vr0)+D0/(5.0*Vr0*Vr0*Vr0*Vr0*Vr0)-2.0*E0;//-Math.log(Zinner[0][1])+
    
    double dsR=-Math.log(Zinner[1][1])+BR/VrR+CR/(2.0*VrR*VrR)+DR/(5.0*VrR*VrR*VrR*VrR*VrR)-2.0*ER;    
    double dS=(-Math.log(1/P)+ds0+Omega/OmegaR*(dsR-ds0))*R*1e-3;//-Math.log(1/P)+
    return dS;//(dsR-ds0)/OmegaR;
}
    public  double  ds_TV_LK_V(double T,double V){
    double P=P_TV_LK_V(T,V);
    return ds_TP_LK_V(T,P);    
}
    public  double  ds_VP_LK_V(double V,double P){
    double T=T_VP_LK_V(V,P);
    return ds_TP_LK_V(T,P);    
}
    public  double  ds_TP_LK_L1(double T, double P){
// difference between ideal gas entropy and real gas entropy
   double dS0,dSR;
   double V0,VR,Vr0,VrR,P0,PR;
   double Tr=T/Tc;
   double Pr=P/Pc;
   double Zinner[][]=new double[3][2];
   Zinner=Z_TP_LK_LA(T,P);
   Vr0=Zinner[0][0];
   VrR=Zinner[1][0];
   double B0,C0,D0;
   double BR,CR,DR;
   
    B0=b0[0]+b0[2]/(Tr*Tr)+2.0*b0[3]/(Tr*Tr*Tr);
    C0=c0[0]-2.0*c0[2]/(Tr*Tr*Tr);
    D0=d0[0];
    
    double E0=c0[3]/(2.0*Tr*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));  
    
    BR=bR[0]+bR[2]/(Tr*Tr)+2.0*bR[3]/(Tr*Tr*Tr);
    CR=cR[0]-2.0*cR[2]/(Tr*Tr*Tr);
    DR=dR[0];  
    double ER=cR[3]/(2*Tr*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR)); 
  
    double ds0=-Math.log(Zinner[0][1])+B0/Vr0+C0/(2.0*Vr0*Vr0)+D0/(5.0*Vr0*Vr0*Vr0*Vr0*Vr0)-2.0*E0;//-Math.log(Zinner[0][1])+
    
    double dsR=-Math.log(Zinner[1][1])+BR/VrR+CR/(2.0*VrR*VrR)+DR/(5.0*VrR*VrR*VrR*VrR*VrR)-2.0*ER;    
    double dS=(-Math.log(1/P)+ds0+Omega/OmegaR*(dsR-ds0))*R*1e-3;
    return dS;//(dsR-ds0)/OmegaR;
}
    public  double  ds_TP_LK_L(double T,double P){
        double Ps=P_T_SV(T);
        return ds_TP_LK_L1(T,P)-ds_TP_LK_L1(T,Ps)+dS_T_K_SVL(T)+ds_TP_LK_V(T,Ps);
    } 
    public  double  ds_TV_LK_L(double T,double V){
        double P=P_TV_LK_L(T,V);
        double Ps=P_T_SV(T);
        return ds_TP_LK_L1(T,P)-ds_TP_LK_L1(T,Ps)+dS_T_K_SVL(T)+ds_TP_LK_V(T,Ps);
    } 
    public  double  ds_VP_LK_L(double V,double P){
        double T=T_VP_LK_L(V,P);
        double Ps=P_T_SV(T);
        return ds_TP_LK_L1(T,P)-ds_TP_LK_L1(T,Ps)+dS_T_K_SVL(T)+ds_TP_LK_V(T,Ps);
    } 
    
    //Internal energy departure functions
    
    public double du_TP_LK_V(double T,double P){
       //This method calculate difference between ideal gas enthalpy
      //and real gas enthalpy
   double dU0,dUR;
   double Tr=T/Tc;
   double Pr=P/Pc;  
   double Zinner[][]=new double[3][2];
   Zinner=Z_TP_LK_VA(T,P);
   double Vr0=Zinner[0][0];
   double VrR=Zinner[1][0];
   //System.out.println("zx hatali= "+ZX);
   double E0=c0[3]/(2.0*Tr*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));
   double du0=-Tr*(-(b0[1]+2.0*b0[2]/Tr+3.0*b0[3]/(Tr*Tr))/(Tr*Vr0)
    -(c0[1]-3.0*c0[2]/Tr/Tr)/(2.0*Tr*Vr0*Vr0)
    +d0[1]/(5*Tr*Vr0*Vr0*Vr0*Vr0*Vr0)
    +3.0*E0);  
    double ER=cR[3]/(2*Tr*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR));
    double duR=-Tr*(-(bR[1]+2*bR[2]/Tr+3*bR[3]/(Tr*Tr))/(Tr*VrR)
    -(cR[1]-3*cR[2]/Tr/Tr)/(2*Tr*VrR*VrR)
    +dR[1]/(5*Tr*VrR*VrR*VrR*VrR*VrR)
    +3*ER);
//    System.out.println("dhR= "+dhR);    
    double dU=du0+Omega/OmegaR*(duR-du0);
//    System.out.println("dh= "+dH);
    dU*=R*Tc*1e-3;
    return dU;       
    }
    public double du_TV_LK_V(double T,double V){
        double P=P_TV_LK_V(T,V);
        return du_TP_LK_V(T,P);
    }
    public double du_VP_LK_V(double V,double P){
        double T=T_VP_LK_V(V,P);
        return du_TP_LK_V(T,P);
    }
    public double du_TP_LK_L1(double T,double P){
       //This method calculate difference between ideal gas enthalpy
      //and real gas enthalpy
   double dU0,dUR;
   double Tr=T/Tc;
   double Pr=P/Pc;  
   double Zinner[][]=new double[3][2];
   Zinner=Z_TP_LK_LA(T,P);
   double Vr0=Zinner[0][0];
   double VrR=Zinner[1][0];
   //System.out.println("zx hatali= "+ZX);
   double E0=c0[3]/(2.0*Tr*Tr*Tr*gama0)*
    (beta0+1-(beta0+1+gama0/Vr0/Vr0)*Math.exp(-gama0/Vr0/Vr0));
   double du0=-Tr*(-(b0[1]+2.0*b0[2]/Tr+3.0*b0[3]/(Tr*Tr))/(Tr*Vr0)
    -(c0[1]-3.0*c0[2]/Tr/Tr)/(2.0*Tr*Vr0*Vr0)
    +d0[1]/(5*Tr*Vr0*Vr0*Vr0*Vr0*Vr0)
    +3.0*E0);  
    double ER=cR[3]/(2*Tr*Tr*Tr*gamaR)*
    (betaR+1-(betaR+1+gamaR/VrR/VrR)*Math.exp(-gamaR/VrR/VrR));
    double duR=-Tr*(-(bR[1]+2*bR[2]/Tr+3*bR[3]/(Tr*Tr))/(Tr*VrR)
    -(cR[1]-3*cR[2]/Tr/Tr)/(2*Tr*VrR*VrR)
    +dR[1]/(5*Tr*VrR*VrR*VrR*VrR*VrR)
    +3*ER);
//    System.out.println("dhR= "+dhR);    
    double dU=du0+Omega/OmegaR*(duR-du0);
//    System.out.println("dh= "+dH);
    dU*=R*Tc*1e-3;
    return dU;       
    }   

//===================================================================
//termodynamic properties of real fluids   
 
    public double h_T_BR_SL(double T){
//enthalpy of the saturated liquid
        return Cp_T_BR_SL(T)*T;
}
    public double h_P_BR_SL(double P){
//enthapy of the saturated liquid
        double T=T_P_LK_SV(P);
        return Cp_T_BR_SL(T)*T;
}
    public double h_TP_BR_L(double T,double P){
// liquid enthalpy
return h_T_BR_SL(T)+V_T_BE_SL(T)*(P-P_T_LK_SV(T));
}
    public double h_TP_LK_V(double T, double P){	    		
    //enthalpy of the real fluid
    //as a function of T and P
    /*if(Formula.equals("H2O")){
	    //System.out.println(""+(st.h(T-273.15,st.v_tp(T-273.15,P))*MolWt)+" "+T);
	    //System.out.println(""+(st.h(Tref-273.15,st.vsg_t(Tref-273.15))*MolWt)+" "+Tref);
	      return st.h(T-273.15,st.v_tp(T-273.15,P))*MolWt-st.h(Tref-273.15,st.vsg_t(Tref-273.15))*MolWt;
	 }  */
     //int z=zone(Tref,Pref);
     //System.out.println("dh_TP_LK_L(Tref,Pref) "+dh_TP_LK_L(Tref,Pref));      
    double value= (Tref>Tc) ? dh_TP_LK_V(Tref,Pc)  : dh_TP_LK_V(Tref,P_T_LK_SV(Tref));
      
    //System.out.println("value= "+value);
    //System.out.println("dh_TP_LK_V(T,P)= "+dh_TP_LK_V(T,P));
    //System.out.println("h_T_IG_V(T)= "+h_T_IG_V(T));
    //return (T/Tc)>7 ? h_T_IG_V(T):(value+h_T_IG_V(T)-dh_TP_LK_V(T,P));
    return h_T_IG_V(T)-dh_TP_LK_V(T,P)+value;
    //return h_T_IG_V(T)-dh_TP_LK_V(T,P);
}
    public double h_TV_LK_V(double T, double V){
    if(Formula.equals("H2O"))  return st.h(T-273.15,V/MolWt)*MolWt-st.h(Tref,st.vsg_t(Tref));
     //enthalpy of the real fluid
     // as a function of T and V
     //FT)-h_T_IG_V(273.15)+dh_TV_LK_V(T,V)+50839.212       
        double P=P_TV_LK_V(T,V);        
        return h_TP_LK_V(T,P);   
}
    public double h_VP_LK_V(double V,double P){
	    if(Formula.equals("H2O"))  return st.h(st.t_pv(P,V/MolWt),P)*MolWt-st.h(Tref,st.vsg_t(Tref));
        double T=T_VP_LK_V(V,P);
        return h_TP_LK_V(T,P);
    }
    public double h_T_LK_SV(double T){
        if(Formula.equals("H2O"))  return st.h(T-273.15,st.vsg_t(T-273.15))*MolWt-st.h(Tref,st.vsg_t(Tref));
        return h_TP_LK_V(T,P_T_LK_SV(T));
}
    public double h_P_LK_SV(double P){	
	    if(Formula.equals("H2O"))  return st.h(st.Ts(P),st.vsg_t(st.Ts(P)))*MolWt-st.h(Tref,st.vsg_t(Tref));    
        double T=T_P_LK_SV(P);      
        return h_TP_LK_V(T,P_T_LK_SV(T));
}
    public double h_T_LK_SL(double T){ 
	    if(Formula.equals("H2O"))  return st.h(T-273.15,st.vsl_t(T-273.15))*MolWt-st.h(Tref,st.vsg_t(Tref)); 
        if(T>=Tc)System.out.println("Hata T de?eri Tc de?erinin üzerinde");               
        return h_TP_LK_V(T,P_T_LK_SV(T))-dH_T_LK_SVL(T);  
}
    public double h_P_LK_SL(double P){ 
	    if(Formula.equals("H2O"))  return st.h(st.Ts(P),st.vsl_t(st.Ts(P)))*MolWt-st.h(Tref,st.vsg_t(Tref));
        double T=T_P_LK_SV(P);
        return h_TP_LK_V(T,P_T_LK_SV(T))-dH_T_LK_SVL(T);  
}
   /*
      public double h_TP_LK_L(double T,double P){
        // liquid enthalpy h_T_LK_SL(T)+V_T_BE_SL(T)*(P*1e5-P_T_LK_SV(T)*1e5);
        int z=zone(Tref,Pref);
        double value= (z==5) ? dh_TP_LK_L(Tref,Pref)  :  dh_TP_LK_V(Tref,Pref); 
        return  value+ h_T_IG_V(T)-dh_TP_LK_L(T,P);
}
   */
 	public double h_TP_LK_L(double T,double P){
	 	if(Formula.equals("H2O"))  return st.h(T-273.15,st.v_tp(T-273.15,P))*MolWt-st.h(Tref,st.vsg_t(Tref));	
        // liquid enthalpy h_T_LK_SL(T)+V_T_BE_SL(T)*(P*1e5-P_T_LK_SV(T)*1e5);
        int z=zone(Tref,Pref);
        double value= (z==5) ? dh_TP_LK_L(Tref,Pref)  :  dh_TP_LK_V(Tref,Pref);       
        return   h_T_IG_V(T)-dh_TP_LK_L(T,P)+value;
        //return   h_T_IG_V(T)-dh_TP_LK_L(T,P)+value;
}
    public double h_TV_LK_L(double T,double V){	
	 if(Formula.equals("H2O"))  return st.h(T-273.15,V/MolWt)*MolWt-st.h(Tref,st.vsg_t(Tref));
 	double P=P_TV_LK_L(T,V);       
        return h_TP_LK_L(T,P);
}
    public double h_VP_LK_L(double V,double P){
	    if(Formula.equals("H2O"))  return st.h(st.t_pv(P,V/MolWt),P)*MolWt-st.h(Tref,st.vsg_t(Tref));	
 		double T=T_VP_LK_L(V,P);       
        return h_TP_LK_L(T,P);
}     
    public double s_TP_LK_V(double T, double P){ 	     
//entropy of the real fluid
// as a function of T and P  
 		//if(Formula.equals("H2O"))  return st.s(T-273.15,st.v_tp(T-273.15,P))*MolWt;      
        //int z=zone(Tref,Pref);
		//double value= (z==5) ? ds_TP_LK_L(Tref,Pref)  :  ds_TP_LK_V(Tref,Pref); 
        //System.out.println("TP="+T+" "+P+"  s_TP_IG_V(T,P)="+(s_TP_IG_V(T,P)/MolWt)+"   ds_TP_LK_V(T,P)="+(ds_TP_LK_V(T,P)/MolWt));
        //return (T/Tc)>7 ? s_TP_IG_V(T,P):(value+s_TP_IG_V(T,P)-ds_TP_LK_V(T,P));
        //return  s_TP_IG_V(T,P)-ds_TP_LK_V(T,P)+value;
        return  s_TP_IG_V(T,P)-ds_TP_LK_V(T,P);
}
    public double s_TV_LK_V(double T, double V){
      //entropy of the real fluid
      // as a function of T and V
      //if(Formula.equals("H2O"))  return st.s(T-273.15,V/MolWt)*MolWt;
        double P=P_TV_LK_V(T,V);
        return s_TP_LK_V(T,P);
}
    public double s_VP_LK_V(double V, double P){
      //entropy of the real fluid
      // as a function of T and V
      //if(Formula.equals("H2O"))  return st.s(st.t_pv(P,V/MolWt),P)*MolWt;
        double T=T_VP_LK_V(V,P);
        return s_TP_LK_V(T,P);
}   
    public double s_TP_LK_L(double T,double P){	
	    //if(Formula.equals("H2O"))  return st.s(T-273.15,st.v_tp(T-273.15,P))*MolWt;
	    //int z=zone(Tref,Pref);
		//double value= (z==5) ? ds_TP_LK_L(Tref,Pref)  :  ds_TP_LK_V(Tref,Pref);         
        //return s_TP_IG_V(T,P)-ds_TP_LK_L(T,P)+value;
        return s_TP_IG_V(T,P)-ds_TP_LK_L(T,P);
}
    public double s_TV_LK_L(double T,double V){	
	    //if(Formula.equals("H2O"))  return st.s(T-273.15,V/MolWt)*MolWt;
          double P=P_TV_LK_L(T,V);
          return s_TP_LK_L(T,P);
}
    public double s_VP_LK_L(double V,double P){	
	   // if(Formula.equals("H2O"))  return st.s(st.t_pv(P,V/MolWt),P)*MolWt;
          double T=T_VP_LK_L(V,P);
          return s_TP_LK_L(T,P);
}
    public double s_T_K_SV(double T){    	
         return s_TP_LK_V(T,P_T_LK_SV(T));
}   
    public double s_T_K_SL(double T){     
        return s_T_K_SV(T)-dS_T_K_SVL(T);
}
    public double s_P_K_SV(double P){    	
         return s_TP_LK_V(T_P_LK_SV(P),P);
}   
    public double s_P_K_SL(double P){   
        double Tinner=T_P_LK_SV(P);
        return s_T_K_SV(Tinner)-dS_T_K_SVL(Tinner);
}

	public double ht_T_LK_V(double T){
		return DELHF+h_TP_LK_V(T,Pref)-h_TP_LK_V(298.2,Pref);	
		
	}
	public double m0_T_LK_V(double T){
		/*
		*Method returns chemical gibbs energy of gas at T DELGF is formation gibbs energy
		*
		*/
        double P0=1.1013;     
       	double value= DELGF+h_TP_LK_V(T,Pref)-h_TP_LK_V(298.2,Pref)-(T*s_TP_LK_V(T,Pref)-298.2*DELS0);
       	//System.out.println("gt= "+value);
        return value;    
    }
    public double u_TP_LK_V(double T,double P){
	 	return h_TP_LK_V(T,P)-P*V_TP_LK_V(T,P)*100;   
    }
      public double u_TP_LK_L(double T,double P){
	 	return h_TP_LK_L(T,P)-P*V_TP_LK_L(T,P)*100;   
    }
    public double cp_TP_LK_V(double T,double P){ 
	    double h=1.0e-3;
  		double hh=1.0/h;   	
  		double fp2h,fph,fm2h,fmh;          		 
  		fp2h=h_TP_LK_V(T+2.0*h,P);
  		fph=h_TP_LK_V(T+h,P);
  		fm2h=h_TP_LK_V(T-2.0*h,P);
  		fmh=h_TP_LK_V(T-h,P);
  		return (-fp2h+8.0*fph-8.0*fmh+fm2h)/12.0*hh;
	}
	 public double cp_TP_LK_L(double T,double P){ 
	    double h=1.0e-3;
  		double hh=1.0/h;   	
  		double fp2h,fph,fm2h,fmh;          		 
  		fp2h=h_TP_LK_L(T+2.0*h,P);
  		fph=h_TP_LK_L(T+h,P);
  		fm2h=h_TP_LK_L(T-2.0*h,P);
  		fmh=h_TP_LK_L(T-h,P);
  		return (-fp2h+8.0*fph-8.0*fmh+fm2h)/12.0*hh;
	}
	public double cp_T_LK_SL(double T){ 
	   return cp_TP_LK_L(T,P_T_LK_SV(T));
	}
	public double cp_T_LK_SV(double T){ 
	   return cp_TP_LK_V(T,P_T_LK_SV(T));
	}
	public double cv_TP_LK_V(double T,double P){
		double h=1.0e-3;
  		double hh=1.0/h;   	
  		double fp2h,fph,fm2h,fmh;          		 
  		fp2h=u_TP_LK_V(T+2.0*h,P);
  		fph=u_TP_LK_V(T+h,P);
  		fm2h=u_TP_LK_V(T-2.0*h,P);
  		fmh=u_TP_LK_V(T-h,P);
  		return (-fp2h+8.0*fph-8.0*fmh+fm2h)/12.0*hh;
	}
	public double cv_TP_LK_L(double T,double P){
		double h=1.0e-3;
  		double hh=1.0/h;   	
  		double fp2h,fph,fm2h,fmh;          		 
  		fp2h=u_TP_LK_L(T+2.0*h,P);
  		fph=u_TP_LK_L(T+h,P);
  		fm2h=u_TP_LK_L(T-2.0*h,P);
  		fmh=u_TP_LK_L(T-h,P);
  		return (-fp2h+8.0*fph-8.0*fmh+fm2h)/12.0*hh;
	}
	public double kv_TP_LK_V(double T,double P){
		if(this.Formula.equals("H2O")) return st.cond_stv(T-273.15)*1e-3;
		double alfa=cv_TP_LK_V(T,P)/8.314-3.0/2.0;
		double beta=0.7862-0.7109*Omega+1.3168*Omega*Omega;
		double Z=2.0+10.5*(T/Tc)*(T/Tc);
		double nu=1+alfa*((0.215+0.28288*alfa-1.061*beta+0.26665*Z)/(0.6366+beta*Z+1.061*alfa*beta));	
		return 3.75*nu*1e-7*lpgasvis_T(T)*8.314/MolWt*1000;//  W/(m.K)
	}
	public double kl_T_LK_L(double T){
		//return (1.11/Math.pow(MolWt,0.5));
		if(this.Formula.equals("H2O")) return st.cond_stl(T-273.15)*1e-3;
		if(T>=Tc) return (double)Double.NaN;
		return Tb<273.15  ? (double)Double.NaN :(1.11/Math.pow(MolWt,0.5))*(3+20*Math.pow(1-T/Tc,2.0/3.0))/
		(3+20*Math.pow(1-Tb/Tc,2.0/3.0));//  W/(m.K)
		
	}
	public double lpgasvis_T(double T){
		//low pressure gas dynamic viscosity
		double mur=131.3*Dipm/Math.pow(Vc*Tc,0.5);
		double Fc=1-0.2756*Omega+0.059035*mur*mur*mur*mur;
		double Tu=1.2593*T/Tc;
		double omegav=1.16145*Math.pow(Tu,-0.14874)+0.52487*Math.exp(-0.7732*Tu)+2.16178*Math.exp(-2.43787*Tu);
		return 40.785*Fc*Math.pow(M*T,0.5)/(Math.pow(Vc,2.0/3.0)*omegav);	
	}
	public double vis_T_L_LPV(double T){
		if(this.Formula.equals("H2O")) return st.vis_stv(T-273.15)*1e-6;
		double Tr=T/Tc;
		double ksi=0.176*Math.pow(Tc/MolWt/MolWt/MolWt/Pc/Pc/Pc/Pc,1.0/6.0);	
		double mur=52.46*Dipm*Dipm*Pc/Tc/Tc;	
		//System.out.println("Dipm= "+Dipm+" Pc= "+Pc+" Tc= "+Tc );
		double Fp=1;		
		if(mur>=0 && mur<0.022) Fp=1;
		else if(mur>=0.022 && mur<0.075) Fp=1+30.55*Math.pow((0.292-Zc),1.72);
		else if(mur>=0.075)              Fp=1+30.55*Math.pow((0.292-Zc),1.72)*Math.abs(0.96+0.1*(T/Tc-0.7));		
		double Fq=1;
		if(Formula.equals("He") ) 
		Fq=1.22*Math.pow(1.38,0.15)*(1+0.00385*Math.pow((T/Tc-12)*(T/Tc-12),1/MolWt)*Math.signum(T/Tc-12));
		else if(Formula.equals("H2"))
		Fq=1.22*Math.pow(0.76,0.15)*(1+0.00385*Math.pow((T/Tc-12)*(T/Tc-12),1/MolWt)*Math.signum(T/Tc-12));
		else if(Formula.equals("D2"))
		Fq=1.22*Math.pow(0.52,0.15)*(1+0.00385*Math.pow((T/Tc-12)*(T/Tc-12),1/MolWt)*Math.signum(T/Tc-12));			
		return (0.807*Math.pow(Tr,0.618)-0.357*Math.exp(-0.449*Tr)+0.34*Math.exp(-4.058*Tr)+0.018)*Fp*Fq/ksi/10/1000000;// Pa.s		
	}
	/*
	*Low Temperature liquid viscosity Przezdziecki and Sridhar
	*/
	public double vis_T_PS_LTL(double T){
		if(this.Formula.equals("H2O")) return st.vis_stl(T-273.15)*1e-6;
		double Tr=T/Tc;		
		double TrR=0.2;//TR/Tc;
		double TR=TrR*Tc;
		double VR=V_TP_LK_L(TR,1.01325)*1000;
		//System.out.println("VR= "+VR+" ro= "+(1/V_TP_LK_L(TR,1.01325)));	
		double H1R=0.33593-0.33953*TrR+1.51941*TrR*TrR-2.02512*TrR*TrR*TrR+1.11422*TrR*TrR*TrR*TrR;
		//System.out.println("H1R= "+H1R);
		double H2R=0.29607-0.09045*TrR-0.04842*TrR*TrR;
		//System.out.println("H2R= "+H2R);
		double H1=0.33593-0.33953*Tr+1.51941*Tr*Tr-2.02512*Tr*Tr*Tr+1.11422*Tr*Tr*Tr*Tr;
		//System.out.println("H1= "+H1);
		double H2=0.29607-0.09045*Tr-0.04842*Tr*Tr;
		//System.out.println("H2= "+H2);
		//double V=H1*(1-Omega*H2)/(H1R*(1-Omega*H2R))*VR;
		double V=V_TP_LK_L(T,1.01325)*1000;
		//System.out.println("V= "+V);
		double Vm=V_TP_LK_L(Tfp,1.01325)*1000;				
		//System.out.println("Vm= "+Vm);
		double V0=0.0085*Omega*Tc-2.02+Vm/(0.342*Tfp/Tc+0.894);
		//System.out.println("V0= "+V0);
		double E=-1.12+Vc/(12.94+0.1*MolWt-0.23*Pc+0.0424*Tfp-11.58*Tfp/Tc);
		//System.out.println("E= "+E);
		return V0/(E*(V-V0))*1e-3;		
	}	
    
    /*
    *Phase related equations
    */
    public double x_tv(double T,double V){
	double x=0;
	double vl,vv;
	//System.out.println("1a");
	//System.out.println("T 3307=" +T);
	double z=zonev(T,V);
	//System.out.println("2a");
	vl=V_T_BE_SL(T);
	//System.out.println("vliquid= "+vl);
	vv=V_T_LK_SV(T);
	//System.out.println("vvapour= "+vv);
	if(z==4)x=(V-vl)/(vv-vl);
	else if(z== 1)x=1;
	else if(z==2)x=1;
	else if (z==3)x=1;
	else if(z==5)x=0;
	else if(z==6)x=1;
	else if(z==7)x=0;
	//System.out.println("x= "+x);
	return x;	
}
    public int zone(double T,double P){
/*
1 : supercritical fluid
2 : critical point
3 : superheated vapour
4 : saturated mixture
5 : liquid
6 : saturated vapour
7 : saturated liquid
*/
int z=0;
double Tvapour= P<=Pc ? T_P_LK_SV(P) : Tc;
//System.out.println("Tvapour=  "+Tvapour);
if(P>=Pc || T>Tc) z=1;
else if(T==Tc) z=2;
else if(Tc>T && T> Tvapour) z=3;
else if (T==Tvapour && V_TP_LK_V(T,P)==V_T_LK_SV(Tvapour)) z=6;
else if (T==Tvapour && V_TP_LK_L(T,P)==V_T_LK_SL(Tvapour)) z=7;
else if(T==Tvapour) z=4;
else if(T < Tvapour) z=5;
return z;
}
    public int zonev(double T,double V){
/*
1 : supercritical fluid
2 : critical point
3 : superheated vapour
4 : saturated mixture
5 : liquid
6 : saturated vapour
7 : saturated liquid
*///System.out.println("T 3354= "+T);
int z=0;
double vl,vv;
vl=V_T_LK_SL(T);
vv=V_T_LK_SV(T);
//System.out.println("vl= "+vl+"  vv= "+vv+"  V= "+V);
if(T>=Tc) z=1;
else if(T==Tc) z=2;
else if(Tc>T && V>vv) z=3;
else if (V==vv) z=6;
else if (V==vl) z=7;
else if(V>vl && V<vv) z=4;
else if(V<vl) z=5;
return z;
}    
    public int zonep(double V,double P){
/*
1 : supercritical fluid
2 : critical point
3 : superheated vapour
4 : saturated mixture
5 : liquid
6 : saturated vapour
7 : saturated liquid
*/
int z=0;
double vl,vv;
vl=V_P_LK_SL(P);
vv=V_P_LK_SV(P);
if(P>=Pc) z=1;
else if(P==Pc) z=2;
else if(Pc>P && V>vv) z=3;
else if (V==vv) z=6;
else if (V==vl) z=7;
else if(V>vl && V<vv) z=4;
else if(V<vl) z=5;
return z;

}
    String zoneName(double T,double V){
    String s="";
    int z=zone(T,V);	
	if(z==1) s="supercritical fluid";
	else if(z==2) s="critical point";
	else if(z==3) s="superheated vapour";
	else if (z==6) s="saturated vapour";
	else if (z==7) s="saturated liquid";
	else if(z==4) s="saturated mixture";
	else if(z==5) s="saturated mixture";
	return s;
}
 String zoneName(int z){
    String s="";    
	if(z==1) s="supercritical fluid";
	else if(z==2) s="critical point";
	else if(z==3) s="superheated vapour";
	else if (z==6) s="saturated vapour";
	else if (z==7) s="saturated liquid";
	else if(z==4) s="saturated mixture";
	else if(z==5) s="liquid";
	return s;
}
    String toString(double T,double P){
String s1="";
double Tvapour=T_P_SV(P);
if(T>=Tc) s1="supercritical fluid";
else if(T==Tc) s1="critical point";
else if(Tc>T && T> Tvapour) s1="superheated vapour";
else if (T==Tvapour && V_TP_LK_V(T,P)==V_T_LK_SV(Tvapour)) s1="saturated vapour";
else if (T==Tvapour && V_TP_LK_L(T,P)==V_T_LK_SL(Tvapour)) s1="saturated liquid";
else if(T==Tvapour) s1="saturated mixture";
else if(T < Tvapour) s1="liquid";
return s1;
}
    String properties(){  String s="isim   = "+GasEquation+"\n";
   s+="isim   = "+Name+"\n";
   s+="formul = "+Formula+"\n";
   s+="formul(atom sinifi) = "+toString()+"\n";
   s+="N = "+N+" M = "+M+"\n";
   s+="MolWt  = "+MolWt+"\n";
   s+="M      = "+M+"\n";
   s+="Tfp    = "+Tfp+"\n";
   s+="Tb     = "+Tb+"\n";
   s+="Tc     = "+Tc+"\n";
   s+="Pc     = "+Pc+"\n";
   s+="Vc     = "+Vc+"\n";
   s+="Zc     = "+Zc+"\n";
   s+="Omega  = "+Omega+"\n";
   s+="Dipm   = "+Dipm+"\n";
   s+="CPVAPA = "+CPC[0]+"\n";
   s+="CPVAPB = "+CPC[1]+"\n";
   s+="CPVAPC = "+CPC[2]+"\n";
   s+="CPVAPD = "+CPC[3]+"\n";
   s+="DELHF  = "+DELHF+"\n";
   s+="DELGF  = "+DELGF+"\n";
   s+="DELS0  = "+DELS0+"\n";
   s+="VPEq   = "+VPEq+"\n";
   s+="VPA    = "+VPC[0]+"\n";
   s+="VPB    = "+VPC[1]+"\n";
   s+="VPC    = "+VPC[2]+"\n";
   s+="VPD    = "+VPC[3]+"\n";
   s+="Tmin   = "+Tmin+"\n";
   s+="Tmax   = "+Tmax+"\n";
   s+="LDEN   = "+LDEN+"\n";
   s+="TDEN   = "+TDEN+"\n";
   return s;
}
    
    //Properties calculations
    
    /**
     * 
     * @param knownpro=tp,tv,,th,tx,ts,vp,ph,ps (t temperature @K , p pressure @bar , v specific volume @m^3/kmol , 
     *  h enthalpy @kJ/kmol , s entropy @kJ/kmolK )
     * @param iv1 =first value of  knownpro pair
     * @param iv2 =second value of  knownpro pair
     * @return  pro[10]= all properties calculated from known properties
     * (pro[0]=P @bar pressure
     *pro[1]=T @K  temparature
     *pro[2]=v @m^3/kmol  specific volume
     *pro[3]=h @kJ/kmol    specific enthalpy
     *pro[4]=u @kJ/kmol    specific internal energy
     *pro[5]=s @kJ/kmolK   specific entropy
     *pro[6]=x @-      quality
     *pro[7]=z @-      state zone
     *pro[8]=Z @-      compressibility factor
     *pro[9]=g @kJ/kmol gibbs free energy 
     */
    public double[] property_SI(String knownpro ,double iv1,double iv2) {		
         //double dh[]=new double[3];                 
        double protemp1,protemp2;
		//T,P are known properties               
        if(knownpro.equals("tp")){                   
            pro[1]=iv1+273.15;                     
            pro[0]=iv2;
            // System.out.println("hsl="+h_T_LK_SL(pro[1])+"   hsv="+h_T_LK_SV(pro[1]));		
            double v1=0,v2=0;		
            int z=zone(pro[1],pro[0]);
	    	//int z=4;		
            //System.out.println("z=  "+z);		       
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor		       
                pro[8]=Z_TP_LK_V(pro[1],pro[0]);		       
               // System.out.println("pro_SI dan=  "+pro[8]);		       
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);		      
                pro[6]=x_tv(pro[1],pro[2]);		       
                pro[7]=zonev(pro[1],pro[2]);		       
                pro[3]=h_TP_LK_V(pro[1],pro[0]);		       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_TP_LK_V(pro[1],pro[0]);		       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);	
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt;
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);                	       
            }		       
            else if(z==7){
                //saturated liquid		       
                //System.out.println("T= "+pro[1]+" P= "+pro[0]);		       
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);		       
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);  
                pro[6]=0;		       
                pro[7]=7;                       
                pro[3]=h_T_LK_SL(pro[1]);		       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_T_K_SL(pro[1]);		       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt;	
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);	       
            }
		       
            else if(z==5){
                //liquid		       
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);		      
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);	       
                pro[6]=-1;		       
                pro[7]=5;		       
                pro[3]=h_TP_LK_L(pro[1],pro[0]);		       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_TP_LK_L(pro[1],pro[0]);		       
                pro[9]=pro[3]-pro[1]*pro[5];	
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt;  
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);   
            }		      
            else if(z==4){
                //vapor-liquid mixture		       
                //System.out.println("P="+pro[0]);		       
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);	       
                //System.out.println("Zilk="+pro[8]);		       
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);
                //System.out.println("Z="+pro[8]);  
                pro[6]=x_tv(pro[1],pro[2]);		      
                pro[7]=4;		      
                pro[3]=h_T_LK_SL(pro[1])-h_T_LK_SL(298)+pro[6]*dH_T_WE_SVL(pro[1]);	       	       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_TP_LK_L(pro[1],pro[0]);		       
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt;
                if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1])); 
            }  
        }		
		
        //T,V are known properties   
        if(knownpro.equals("tv")){   		    
            pro[1]=iv1+273.15;		    
            pro[2]=iv2;		   
            int z=zonev(pro[1],pro[2]);                    
            //int z=5;		    
            //System.out.println("z=  "+z);	    
            if(z==1 ||z==3 || z==6 || z==2){
                //vapor , supercritical fluid , superheated vapor 	    
                pro[8]=Z_TV_LK_V(pro[1],pro[2]);   		    
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		    
                pro[6]=x_tv(pro[1],pro[2]);		    
                pro[7]=zonev(pro[1],pro[2]);		    
                pro[3]=h_TP_LK_V(pro[1],pro[0]);		    
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		    
                pro[5]=s_TP_LK_V(pro[1],pro[0]);		    
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt;	
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);		    
            }		
            else if(z==7){
                //saturated liquid
                pro[8]=Z_TV_LK_L(pro[1],pro[2]);			 
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		 
                pro[6]=0;			 
                pro[7]=7;			 
                pro[3]=h_T_LK_SL(pro[1]);  	 
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;			 
                pro[5]=s_T_K_SL(pro[1]);  
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt;	 
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);  
            }		
            else if(z==5){
                //liquid           		
                pro[8]=Z_TV_LK_L(pro[1],pro[2]);              		
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);	                                  
                pro[6]=-1;                      
                pro[7]=5;	                      
                pro[3]=h_TP_LK_L(pro[1],pro[0]);                       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	                       
                pro[5]=s_TP_LK_L(pro[1],pro[0]);                       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);	
            }			
            else if(z==4){
                //vapor-liquid mixture		     
                pro[0]=P_T_LK_SV(pro[1]);                     
                pro[8]=pro[0]*pro[2]*1e5/R/pro[1];	     
                pro[6]=x_tv(pro[1],pro[2]);   	     
                pro[7]=4;		     
                pro[3]=h_T_LK_SL(pro[1])+pro[6]*dH_T_LK_SVL(pro[1]);	     
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	     
                pro[5]=s_T_K_SL(pro[1])+pro[6]*dS_T_K_SVL(pro[1]);   
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1])); 
            }			 
        }
        
       // T,h are known properties                 
        if(knownpro.equals("th_l")){		
            pro[1]=iv1+273.15;		
            pro[3]=iv2;                  
            double hcheck;	
            double hsl=h_T_LK_SL(pro[1]);          	
            double hsv=h_T_LK_SV(pro[1]);                                                                                                 	       
            pro[0]=P_hT_LK_L(pro[3],pro[1]);	           			      
            pro[8]=Z_TP_LK_L(pro[1],pro[0]);  	      
            pro[2]=R*pro[8]*pro[1]/(pro[0]*1e5);   
            pro[6]=-1;		       
            pro[7]=5;	    
            pro[4]=pro[3]-pro[0]*pro[2]*1e2;		      
            pro[5]=s_TP_LK_L(pro[1],pro[0]);		       
            pro[9]=pro[3]-pro[1]*pro[5]; 
            pro[10]=STension(pro[1]);
            pro[11]=cp_TP_LK_L(pro[1],pro[0]);
            pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            pro[13]=MolWt; 
            pro[14]=kl_T_LK_L(pro[1]);
            pro[15]=vis_T_PS_LTL(pro[1]);
                           
        }              
		
        if(knownpro.equals("th")){		
            pro[1]=iv1+273.15;		
            pro[3]=iv2;                 
            double hcheck;		
            double hsl=h_T_LK_SL(pro[1]);     		
            double hsv=h_T_LK_SV(pro[1]);               
            protemp1=0;               
            protemp2=0;		
            //System.out.println("hsv= "+hsv+"  hsl= "+hsl+" h="+pro[3]);		       
            if(pro[3]>=hsv || pro[1]>Tc){
                //vapor , supercritical fluid , superheated vapor,saturated vapour		       
                //System.out.println("vapor");		       
                pro[2]=V_hT_LK_V(pro[3],pro[1]);    
                pro[8]=Z_TV_LK_V(pro[1],pro[2]); 	       
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		       
                pro[6]=x_tv(pro[1],pro[2]);		       
                pro[7]=zonev(pro[1],pro[2]);	       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_TV_LK_V(pro[1],pro[2]);		       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt; 	
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);	       
            }		       
            else if(pro[3]==hsl){
                //saturated liquid	  
                //System.out.println("saturated liquid");		       
                pro[2]=V_T_LK_SL(pro[1]);		       
                pro[8]=Z_TV_LK_L(pro[1],pro[2]);		       
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		      
                pro[6]=0;		      
                pro[7]=7;    
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		     
                pro[5]=s_T_K_SL(pro[1]);		      
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt; 
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);	      
            }		      
            else if(pro[3]<hsl){
                //liquid		      
                //System.out.println("liquid");     
                pro[0]=P_hT_LK_L(pro[3],pro[1]);               		       
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);   	       
                pro[2]=R*pro[8]*pro[1]/(pro[0]*1e5);	       
                pro[6]=-1;	       
                pro[7]=5;   
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		      
                pro[5]=s_TP_LK_L(pro[1],pro[0]);	      
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt; 	 
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);     
            }              
            else if(pro[3]<hsv || pro[3]>hsl){
                //vapor-liquid mixture		      
                //System.out.println("mixture");                       
                pro[0]=P_T_LK_SV(pro[1]);                       
                hcheck=(dH_T_WE_SVL(pro[1])==0)?(dH_T_LK_SVL(pro[1])):(dH_T_WE_SVL(pro[1]));                        
                pro[6]=(pro[3]-h_T_LK_SL(pro[1]))/hcheck;                       
                protemp1=V_TP_LK_L(pro[1],pro[0]);                       
                protemp2=V_TP_LK_V(pro[1],pro[0]);                    
                pro[2]=protemp1+pro[6]*(protemp2-protemp1);	         
                pro[8]=pro[2]*pro[0]*1e5/(pro[1]*R);	  
                pro[7]=3;	    	      
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;          
                pro[5]=s_T_K_SL(pro[1])+pro[6]*dS_T_K_SVL(pro[1]);	       
                pro[9]=pro[3]-pro[1]*pro[5];	
                pro[10]=STension(pro[1]);
               if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1]));    
            }		
        }
        
        if(knownpro.equals("tx")){                    
            pro[1]=iv1+273.15;                   
            pro[6]=iv2;                    
            protemp1=0;                    
            protemp2=0;                    
            if(pro[6]<0){                        
                System.out.println("x degeri 0 dan küçük olamaz");                    
            }                    
            if(pro[6]>1){                       
                System.out.println("x degeri 0 dan büyük olamaz");                    
            }                     
            else{                        
                pro[0]=P_T_SV(pro[1]);                        
                protemp1=Z_TP_LK_L(pro[1],pro[0]);                        
                protemp2=Z_TP_LK_V(pro[1],pro[0]);                        
                pro[2]=protemp1+pro[6]*(protemp2-protemp1);                        
                pro[8]=pro[0]*pro[2]*1e5/R/pro[1];                        
                pro[7]=3;                        
                pro[3]=h_T_LK_SL(pro[1])+pro[6]*dH_T_LK_SVL(pro[1]);                        
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		        
                pro[5]=s_T_K_SL(pro[1])+pro[6]*dS_T_K_SVL(pro[1]);		        
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]); 
               if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1]));                
            }                
        }
        
         if(knownpro.equals("px")){                    
            pro[0]=iv1;                   
            pro[6]=iv2;                    
            protemp1=0;                    
            protemp2=0;                    
            if(pro[6]<0){                        
                System.out.println("x degeri 0 dan küçük olamaz");                    
            }                    
            if(pro[6]>1){                       
                System.out.println("x degeri 0 dan büyük olamaz");                    
            }                     
            else{                        
                pro[1]=T_P_SV(pro[0]);
                System.out.println("T= "+pro[1]);                        
                protemp1=Z_TP_LK_L(pro[1],pro[0]);                        
                protemp2=Z_TP_LK_V(pro[1],pro[0]);                        
                pro[2]=protemp1+pro[6]*(protemp2-protemp1);                        
                pro[8]=pro[0]*pro[2]*1e5/R/pro[1];                        
                pro[7]=3;                        
                pro[3]=h_T_LK_SL(pro[1])+pro[6]*dH_T_LK_SVL(pro[1]);                        
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		        
                pro[5]=s_T_K_SL(pro[1])+pro[6]*dS_T_K_SVL(pro[1]);		        
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]); 
                if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1]));            
            }                
        }
        
        
                 
        if(knownpro.equals("ts")){                     
            pro[1]=iv1+273.15;                    
            pro[5]=iv2;                     
            protemp1=0;                     
            protemp2=0;                  
            double ssv=s_T_K_SV(pro[1]);                    
            double ssl=s_T_K_SL(pro[1]);                     
            //System.out.println("ssl="+ssl+" ssv="+ssv+"  s="+pro[5]);                    
            if(pro[5]>ssv){        
	            //System.out.println("1  "+pro[1]+""+pro[5] );                
                pro[0]=P_sT_LK_V(pro[5],pro[1]);            
                //System.out.println("2  "+pro[1]+""+pro[0] );  
                pro[8]=Z_TV_LK_V(pro[1],pro[2]);                           
                //System.out.println("1  "+pro[1]+""+pro[8] );
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);                         
                pro[3]=h_TP_LK_V(pro[1],pro[0]);                         
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;                         
                pro[6]=2;                         
                pro[7]=zonev(pro[1],pro[2]);                        
                pro[9]=pro[3]-pro[1]*pro[5]; 
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt; 	
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);                    
            }                    
            else if(pro[5]<ssv && pro[5]>ssl){                         
                pro[6]=(pro[5]-s_T_K_SL(pro[1]))/dS_T_K_SVL(pro[1]);                        
                pro[0]=P_T_LK_SV(pro[1]);                        
                protemp1=V_T_LK_SL(pro[1]);                         
                protemp2=V_T_LK_SV(pro[1]);                        
                pro[2]=protemp1+pro[6]*(protemp2-protemp1);                         
                pro[8]=pro[0]*pro[2]*1e5/R/pro[1];                         
                pro[7]=3;                         
                pro[3]=h_T_LK_SL(pro[1])+pro[6]*dH_T_LK_SVL(pro[1]);                         
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	      
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]);
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]); 
                                    
            }                     
            else if(pro[5]==ssl){                      
                //System.out.println("saturated liquid");		       
                pro[2]=V_T_LK_SL(pro[1]);		      
                pro[8]=Z_TV_LK_L(pro[1],pro[2]);                      
                pro[3]=h_T_LK_SL(pro[1]);		       
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		       
                pro[6]=0;		       
                pro[7]=7;	    
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	       
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]);  
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt; 
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);              
            }                    
            else if(pro[5]==ssv){                       
                //System.out.println("saturated liquid");		       
                pro[2]=V_T_LK_SV(pro[1]);		       
                pro[8]=Z_TV_LK_V(pro[1],pro[2]);                       
                pro[3]=h_T_LK_SV(pro[1]);		       
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		       
                pro[6]=2;		       
                pro[7]=6;	 
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		      
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt; 	              
            }                    
            else if(pro[5]<ssl){                         
                //System.out.println("liquid");                         
                pro[0]=P_sT_LK_L(pro[5],pro[1]);        
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);                      
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);                      
                pro[3]=h_TP_LK_L(pro[1],pro[0]);                        
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;     
                pro[6]=-1;                        
                pro[7]=5;                        
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt; 	
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);                      
            }                
        }
                     
        if(knownpro.equals("vp")){	   
            pro[2]=iv1;		    
            pro[0]=iv2;	
            //System.out.println("v="+pro[2]+"  P= "+pro[0]);	    
            int z=zonep(pro[2],pro[0]);
            //System.out.println("z=  "+z);	
            if(z==1 ||z==3 || z==6 || z==2){
                //vapor , supercritical fluid , superheated vapor   
                pro[8]=Z_VP_LK_V(pro[2],pro[0]);   	    
                pro[1]=pro[0]*1e5*pro[2]/(R*pro[8]);	    
                pro[6]=2;	    
                pro[7]=z;		    
                pro[3]=h_TP_LK_V(pro[1],pro[0]);		    
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		    
                pro[5]=s_TP_LK_V(pro[1],pro[0]);		    
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);	
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt; 
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);		   
            }		
            else if(z==7){
                //saturated liquid                        
                pro[8]=Z_VP_LK_L(pro[2],pro[0]);                  
                pro[1]=pro[0]*1e5*pro[2]/(R*pro[8]);                       
                pro[6]=x_tv(pro[1],pro[2]);	                        
                pro[7]=7;		                        
                pro[3]=h_T_LK_SL(pro[1]); 	                       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	                        
                pro[5]=s_T_K_SL(pro[1]);  	                        
                pro[9]=pro[3]-pro[1]*pro[5]; 
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt; 	
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);       
            }	
            else if(z==5){
                //liquid	     
                // System.out.println("pro[1]="+pro[1]+" pro[2]  ="+pro[2]);			 
                pro[8]=Z_VP_LK_L(pro[2],pro[0]);                	
                pro[1]=pro[0]*1e5*pro[2]/(R*pro[8]);	 
                pro[6]=x_tv(pro[1],pro[2]);                
                //System.out.println("1");					 
                pro[7]=5;			 
                pro[3]=h_TP_LK_L(pro[1],pro[0]);			 
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;			 
                pro[5]=s_TP_LK_L(pro[1],pro[0]);			 
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt; 
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);		           
            }			
            else if(z==4){
                //vapor-liquid mixture		    
                pro[1]=T_P_LK_SV(pro[0]);                    
                pro[8]=pro[0]*pro[2]*1e5/R/pro[1];	     
                pro[6]=x_tv(pro[1],pro[2]);    		     
                pro[7]=4;	    
                pro[3]=h_T_LK_SL(pro[1])+pro[6]*dH_T_LK_SVL(pro[1]);			     
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		    
                pro[5]=s_T_K_SL(pro[1])+pro[6]*dS_T_K_SVL(pro[1]);   
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);	
                if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1])); 
            }			  
        }          
        
        if(knownpro.equals("ph")){		
            pro[0]=iv1;		
            pro[3]=iv2;                 
            double hcheck;	
            double hsl=h_P_LK_SL(pro[0]);     	
            double hsv=h_P_LK_SV(pro[0]);              
            protemp1=0;              
            protemp2=0;	            
            if(pro[3]>=hsv || pro[0]>Pc){
                //vapor , supercritical fluid , superheated vapor,saturated vapour		      
                //System.out.println("vapor");	                 
                pro[1]=T_hP_LK_V(pro[3],pro[0]);   
                pro[8]=Z_TP_LK_V(pro[1],pro[0]);        
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);		       
                pro[6]=x_tv(pro[1],pro[2]);		       
                pro[7]=zonev(pro[1],pro[2]);	   
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_TP_LK_V(pro[1],pro[0]);		       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt;	
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);		      
            }           
            else if(pro[3]==hsl){
                //saturated liquid	       
                //System.out.println("saturated liquid");		       
                pro[2]=V_T_LK_SL(pro[1]);		       
                pro[8]=Z_TV_LK_L(pro[1],pro[2]);		      
                pro[0]=pro[8]*R*pro[1]/(pro[2]*1e5);		       
                pro[6]=0;		       
                pro[7]=7;			       
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_T_K_SL(pro[1]);		       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);			       
            }
		      
            else if(pro[3]<hsl){
                //liquid		                      
                //System.out.println("liquid");        
                pro[1]=T_hP_LK_L(pro[3],pro[0]);		       
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);    
                pro[2]=R*pro[8]*pro[1]/(pro[0]*1e5);		  
                pro[6]=-1;		       
                pro[7]=5;	 
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;		       
                pro[5]=s_TP_LK_L(pro[1],pro[0]);		      
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);	
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);
                pro[13]=MolWt;	
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);    
            }
		      
            else if(pro[3]<hsv || pro[3]>hsl){
                //vapor-liquid mixture		      
                //System.out.println("mixture");                       
                pro[1]=T_P_LK_SV(pro[0]);                   
                hcheck=(dH_T_WE_SVL(pro[1])==0)?(dH_T_LK_SVL(pro[1])):(dH_T_WE_SVL(pro[1]));                    
                pro[6]=(pro[3]-h_T_LK_SL(pro[1]))/hcheck;                      
                protemp1=V_TP_LK_L(pro[1],pro[0]);                      
                protemp2=V_TP_LK_V(pro[1],pro[0]);                  
                pro[2]=protemp1+pro[6]*(protemp2-protemp1);   
                pro[8]=pro[2]*pro[0]*1e5/(pro[1]*R);	 
                pro[7]=3;	 
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;   
                pro[5]=s_T_K_SL(pro[1])+pro[6]*dS_T_K_SVL(pro[1]);		       
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);	
                  if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }     
                pro[13]=MolWt; 
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1])); 
            }                    
        }
                
        if(knownpro.equals("ps")){                    
            pro[0]=iv1;                    
            pro[5]=iv2;                    
            protemp1=0;                     
            protemp2=0;                    
            double ssv=s_P_K_SV(pro[0]);                     
            double ssl=s_P_K_SL(pro[0]);                     
            //System.out.println("ssl="+ssl+" ssv="+ssv+"  s="+pro[5]);                
            if(pro[5]>ssv){                       
                //System.out.println("vapour");                        
                pro[1]=T_sP_LK_V(pro[5],pro[0]);  
                pro[8]=Z_TP_LK_V(pro[1],pro[0]);                          
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);                         
                pro[3]=h_TP_LK_V(pro[1],pro[0]);                         
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;                         
                pro[6]=x_tv(pro[1],pro[2]);                         
                pro[7]=zonev(pro[1],pro[2]);                        
                pro[9]=pro[3]-pro[1]*pro[5]; 
                pro[10]=STension(pro[1]);
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                pro[13]=MolWt;
                pro[14]=kv_TP_LK_V(pro[1],pro[0]);
                pro[15]=vis_T_L_LPV(pro[1]);                    
            }                     
            else if(pro[5]<ssv && pro[5]>ssl){                         
                //System.out.println("mixture");                         
                pro[1]=T_P_LK_SV(pro[0]);                       
                pro[6]=(pro[5]-s_T_K_SL(pro[1]))/dS_T_K_SVL(pro[1]);                     
                protemp1=V_T_LK_SL(pro[1]);                       
                protemp2=V_T_LK_SV(pro[1]);                        
                pro[2]=protemp1+pro[6]*(protemp2-protemp1);                         
                pro[8]=pro[0]*pro[2]*1e5/R/pro[1];                         
                pro[7]=3;                       
                pro[3]=h_T_LK_SL(pro[1])+pro[6]*dH_T_LK_SVL(pro[1]);                      
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]);  
              if(pro[6]==0){
                	pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_L(pro[1],pro[0]);
            	}
                else if(pro[6]==1){
	                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                	pro[12]=cv_TP_LK_V(pro[1],pro[0]);
                }
                else{
	             	pro[11]=0;
                	pro[12]=0;   
                }          
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1])+pro[6]*(kv_TP_LK_V(pro[1],pro[0])-kl_T_LK_L(pro[1]));
                pro[15]=vis_T_PS_LTL(pro[1])+pro[6]*(vis_T_L_LPV(pro[1])-vis_T_PS_LTL(pro[1]));       
            }                    
            else if(pro[5]==ssl){                       
                //System.out.println("saturated liquid");		      
                pro[2]=V_P_LK_SL(pro[0]);                      
                pro[1]=T_P_SV(pro[0]);		       
                pro[8]=pro[0]*pro[2]*1e5/pro[1]/R;                       
                pro[3]=h_T_LK_SL(pro[1]);	
                pro[6]=0;		       
                pro[7]=7;	  
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;	
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);  
                pro[13]=MolWt; 
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);          
            }                     
            else if(pro[5]==ssv){                      
                //System.out.println("saturated vapour");		       
                pro[2]=V_P_LK_SV(pro[0]);                       
                pro[1]=T_P_SV(pro[0]);                       
                pro[8]=pro[0]*pro[2]*1e5/pro[1]/R;                       
                pro[3]=h_T_LK_SV(pro[1]); 
                pro[6]=1;		       
                pro[7]=6;	
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;
                pro[9]=pro[3]-pro[1]*pro[5];
                pro[10]=STension(pro[1]); 
                pro[13]=MolWt;
                pro[11]=cp_TP_LK_V(pro[1],pro[0]);
                pro[12]=cv_TP_LK_V(pro[1],pro[0]);                        
            }        
            else if(pro[5]<ssl){                        
                //System.out.println("liquid");                     
                pro[0]=T_sP_LK_L(pro[5],pro[0]);      
                pro[8]=Z_TP_LK_L(pro[1],pro[0]);                    
                pro[2]=pro[8]*R*pro[1]/(pro[0]*1e5);                         
                pro[3]=h_TP_LK_L(pro[1],pro[0]);                        
                pro[4]=pro[3]-pro[0]*pro[2]*1e2;                         
                pro[6]=-1;                        
                pro[7]=5;                         
                pro[9]=pro[3]-pro[1]*pro[5];  
                pro[10]=STension(pro[1]); 
                pro[11]=cp_TP_LK_L(pro[1],pro[0]);
                pro[12]=cv_TP_LK_L(pro[1],pro[0]);  
                pro[13]=MolWt;
                pro[14]=kl_T_LK_L(pro[1]);
                pro[15]=vis_T_PS_LTL(pro[1]);                     
            }                 
        }                 
        return pro;                 
    }	
	
        //new methods             
          
    public double[][]  T_sP_LK_L_reversebracket(double x1,double x2,double P,double s){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
            // System.out.println("-----------------------baracket----------------------");
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=s_TP_LK_L(x1,P)-s;
      //  System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=s_TP_LK_L(x,P)-s;
                //System.out.println("x="+x+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb){
                     // System.out.println("-----------------------baracket bitti----------------------");
                    return xb;
                }
	}
        if( nb == 0)	
        {  System.out.println("arama tamamlandi kök olan bölge bulunamad? ----sonuç hatal?----");
        System.exit(1);}
else if(nb<nbb)
  System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
          // System.out.println("-----------------------baracket bitti----------------------");
return xb;     
          
   }                
    public double T_sP_LK_L(double s,double P){
                int MAXIT=40;
		double xacc=1.0e-6;		
		double x2=Tc;
		double x1=x2*0.1;	
                double[][] x=new double[2][1];
                x=T_sP_LK_L_reversebracket(x1,x2,P,s);
		x1=x[0][0];
                x2=x[1][0];
                int i=2;			
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=s_TP_LK_L(x1,P)-s;
		fh=s_TP_LK_L(x2,P)-s;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir  P_sT_LK_V" );
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);		  
		    ff=s_TP_LK_L(rtf,P)-s;
		   // System.out.println("rtf= "+rtf+"  ff= "+ff);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		////System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
            
        }             
    public double[][]  T_sP_LK_V_reversebracket(double x1,double x2,double P,double s){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
            // System.out.println("-----------------------baracket----------------------");
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=s_TP_LK_V(x1,P)-s;
      //  System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=s_TP_LK_V(x,P)-s;
                //System.out.println("x="+x+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb){
                     // System.out.println("-----------------------baracket bitti----------------------");
                    return xb;
                }
	}
        if( nb == 0)	
        {  System.out.println("arama tamamlandı kök olan bölge bulunamad? ----sonuç hatal?----");
        System.exit(1);}
else if(nb<nbb)
  System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
          // System.out.println("-----------------------baracket bitti----------------------");
return xb;     
          
   }         
    public double T_sP_LK_V(double s,double P){
                int MAXIT=40;
		double xacc=1.0e-6;		
		double x2=Tc*6;
		double x1=x2*0.1;	
                double[][] x=new double[2][1];
                x=T_sP_LK_V_reversebracket(x1,x2,P,s);
		x1=x[0][0];
                x2=x[1][0];
                int i=2;			
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=s_TP_LK_V(x1,P)-s;
		fh=s_TP_LK_V(x2,P)-s;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir  P_sT_LK_V" );
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);		  
		    ff=s_TP_LK_V(rtf,P)-s;
		   // System.out.println("rtf= "+rtf+"  ff= "+ff);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		////System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
            
        }                   
    public double[][]  P_sT_LK_V_reversebracket(double x1,double x2,double T,double s){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
            // System.out.println("-----------------------baracket----------------------");
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=s_TP_LK_V(T,x1)-s;
      //  System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=s_TP_LK_V(T,x)-s;
                //System.out.println("x="+x+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb){
                     // System.out.println("-----------------------baracket bitti----------------------");
                    return xb;
                }
	}
        if( nb == 0)	
        {  System.out.println("arama tamamlandi kök olan bölge bulunamad? ----sonuç hatal?----");
        System.exit(1);}
else if(nb<nbb)
  System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
          // System.out.println("-----------------------baracket bitti----------------------");
return xb;     
          
   }               
    public double P_sT_LK_V(double s,double T){
                int MAXIT=40;
		double xacc=1.0e-6;		
		double x2=Pc*10;
		double x1=0.01*Pc;	
                double[][] x=new double[2][1];
                x=P_sT_LK_V_reversebracket(x1,x2,T,s);
		x1=x[0][0];
                x2=x[1][0];
                int i=2;
		double s1=s;		
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=s_TP_LK_V(T,x1)-s1;
		fh=s_TP_LK_V(T,x2)-s1;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir  P_sT_LK_V" );
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);		  
		    ff=s_TP_LK_V(T,rtf)-s1;
		   // System.out.println("rtf= "+rtf+"  ff= "+ff);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		//System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
            
        }            
    public double[][]  T_hP_LK_L_reversebracket(double x1,double x2,double P,double h){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=h_TP_LK_L(x,P)-h;
       // System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=h_TP_LK_L(x,P)-h;
              //  System.out.println("x="+x+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb) {
                    //   System.out.println("-----------------------baracket bitti----------------------");
                    return xb;                      
                }
	}
        if( nb == 0)	{
       System.out.println("arama tamamlandi kök olan bölge bulunamad?");
        System.exit(1);
        }
else if(nb<nbb)
 System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
           //System.out.println("-----------------------baracket bitti----------------------");
        
    return xb;     
      
   }         
    public double T_hP_LK_L(double h,double P){
		double[][] x=new double[2][1];             
                int MAXIT=40;
		double xacc=1.0e-8;		
		double x2=Tc;
		double x1=x2*0.1;		
		int i=2;
		double h1=h;
		//System.out.println("h1=  "+h1);
		//System.out.println("x1= "+x1+" x2= "+x2);
                x=T_hP_LK_L_reversebracket(x1,x2,P,h);	
	    x1=x[0][0];
            x2=x[1][0];
            if(x1==0 && x2==0) return 0.1;
           // System.out.println("x1= "+x1+" x2= "+x2);
	    //System.out.println("a");
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_TP_LK_L(x1,P)-h1;
		fh=h_TP_LK_L(x2,P)-h1;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);
		   // System.out.println("rtf="+rtf+" xl="+xl+" dx*fl="+(dx*fl)+"  (fl-fh)="+(fl-fh));
		    ff=h_TP_LK_L(rtf,P)-h1;
		    //System.out.println("ff= "+ff+" rtf= "+rtf);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		////System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
	}     
    public double[][]  T_hP_LK_V_reversebracket(double x1,double x2,double P,double h){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=h_TP_LK_V(x,P)-h;
        //System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=h_TP_LK_V(x,P)-h;
              // System.out.println("x="+x+"   x+dx"+(x+dx)+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb) {
                       //System.out.println("-----------------------baracket bitti----------------------");
                    return xb;                      
                }
	}
        if( nb == 0)	{
        System.out.println("arama tamamlandi kök olan bölge bulunamad?");
        System.exit(1);
        }
else if(nb<nbb)
 System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
           //System.out.println("-----------------------baracket bitti----------------------");
        
    return xb;     
      
   }      
    public double T_hP_LK_V(double h,double P){
		double[][] x=new double[2][1];             
                int MAXIT=40;
		double xacc=1.0e-7;		
		double x2=Tc*6;
		double x1=Tc*0.1;		
		int i=2;		
		//System.out.println("h1=  "+h1);
		//System.out.println("x1= "+x1+" x2= "+x2);
                x=T_hP_LK_V_reversebracket(x1,x2,P,h);	
	    x1=x[0][0];
            x2=x[1][0];
            if(x1==0 && x2==0) return 0.1;
           //System.out.println("x1= "+x1+" x2= "+x2);
	    //System.out.println("a");
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_TP_LK_V(x1,P)-h;
		fh=h_TP_LK_V(x2,P)-h;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);
		   // System.out.println("rtf="+rtf+" xl="+xl+" dx*fl="+(dx*fl)+"  (fl-fh)="+(fl-fh));
		    ff=h_TP_LK_V(rtf,P)-h;
		    //System.out.println("ff= "+ff+" rtf= "+rtf);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		////System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
	}                 
    public double[][]  P_sT_LK_L_reversebracket(double x1,double x2,double T,double s){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
            // System.out.println("-----------------------baracket----------------------");
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=s_TP_LK_L(T,x1)-s;
      //  System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=s_TP_LK_L(T,x)-s;
                //System.out.println("x="+x+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb){
                     // System.out.println("-----------------------baracket bitti----------------------");
                    return xb;
                }
	}
        if( nb == 0)	
        {  System.out.println("arama tamamlandi kök olan bölge bulunamad? ----sonuç hatal?----");
        System.exit(1);}
else if(nb<nbb)
  System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
          // System.out.println("-----------------------baracket bitti----------------------");
return xb;     
          
   }       
    public double P_sT_LK_L(double s,double T){
                int MAXIT=40;
		double xacc=1.0e-6;		
		double x2=Pc;
		double x1=0.01*x2;	
                double[][] x=new double[2][1];
                x=P_sT_LK_V_reversebracket(x1,x2,T,s);
		x1=x[0][0];
                x2=x[1][0];
                int i=2;
		double s1=s;		
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=s_TP_LK_L(T,x1)-s1;
		fh=s_TP_LK_L(T,x2)-s1;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir  P_sT_LK_V" );
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);		  
		    ff=s_TP_LK_L(T,rtf)-s1;
		   // System.out.println("rtf= "+rtf+"  ff= "+ff);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
                //System.out.println("del="+del);
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		//System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
            
        }                   
    public double[][]  P_hT_LK_L_reversebracket(double x1,double x2,double T,double h){
       // n : verilen bölgeyi böldü?ümüz alt bölge say?s?
	// x1,x2 : s?n?r de?erleri
	// nbb = aranan bölgedeki köksay?s?
	// f_x y function value    
       int nbb=1;
       int n=10;
        int nb;
	int i;
	double x,fp,fc,dx;
	double xb[][]=new double[2][1];
	nb=0;
	dx=(x2-x1)/n;
	x=x1;        
	fp=h_TP_LK_L(T,x)-h;
       // System.out.println("x="+x+"  fp="+fp);
	for (i=1;i<=n;i++) {
		x+=dx;
		fc=h_TP_LK_L(T,x)-h;
              //  System.out.println("x="+x+"  fc="+fc);
		// e?er kök olan bölge bulunduysa.....
		if (fc*fp < 0.0 || fp==0) {
			xb[0][nb]=x-dx;
			xb[1][nb]=x;
			nb++;
		}
		fp=fc;
		if (nbb == nb) {
                    //   System.out.println("-----------------------baracket bitti----------------------");
                    return xb;                      
                }
	}
        if( nb == 0)	{
       System.out.println("arama tamamlandi kök olan bölge bulunamad?");
        System.exit(1);
        }
else if(nb<nbb)
 System.out.println("arama tamamlandi sadece "+nb+"adet kök bulundu");
           //System.out.println("-----------------------baracket bitti----------------------");
        
    return xb;     
      
   }
    public double P_hT_LK_L(double h,double T){
		double[][] x=new double[2][1];             
                int MAXIT=40;
		double xacc=1.0e-6;		
		double x2=Pc;
		double x1=0.01*Pc;		
		int i=2;
		double h1=h;
		//System.out.println("h1=  "+h1);
		//System.out.println("x1= "+x1+" x2= "+x2);
                x=P_hT_LK_L_reversebracket(x1,x2,T,h);	
	    x1=x[0][0];
            x2=x[1][0];
            if(x1==0 && x2==0) return 0.1;
           // System.out.println("x1= "+x1+" x2= "+x2);
	    //System.out.println("a");
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_TP_LK_L(T,x1)-h1;
		fh=h_TP_LK_L(T,x2)-h1;
		//System.out.println("fl="+fl+" fh="+fh);
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		    //System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);
		   // System.out.println("rtf="+rtf+" xl="+xl+" dx*fl="+(dx*fl)+"  (fl-fh)="+(fl-fh));
		    ff=h_TP_LK_L(T,rtf)-h1;
		    //System.out.println("ff= "+ff+" rtf= "+rtf);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		////System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
	}
    
          //old methods          
         
    public double V_hT_LK_L(double h,double T){
		int MAXIT=30;
		double xacc=1.0e-10;		
		double x2=Vc;
		double x1=x2/2;		
		int i=2;
		double h1=h;
		//System.out.println("x1= "+x1+" x2= "+x2);				
		while((h_TV_LK_L(T,x1)-h1)*(h_TV_LK_L(T,x2)-h1)>0){
		x1=x2/Math.pow(2,i);					
		i++;
	    }
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_TV_LK_V(T,x1)-h1;
		fh=h_TV_LK_V(T,x2)-h1;
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    for (j=1;j<=MAXIT;j++){
		    rtf=xl+dx*fl/(fl-fh);
		    ff=h_TV_LK_L(T,rtf)-h1;
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		//System.out.println("iterasyon bitti");
		return rtf;
	}          
    public double V_sT_LK_V(double s,double T){
            int MAXIT=30;
		double xacc=1.0e-5;		
		double x2=Pc;
		double x1=0;		
		int i=2;
		double s1=s;
		//System.out.println("s1=  "+s1);
		//System.out.println("x1= "+x1+" x2= "+x2);		
	       int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=s_TV_LK_V(T,x1)-s1;
		fh=s_TV_LK_V(T,x2)-s1;	
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    //System.out.println("b");
	    for (j=1;j<=MAXIT;j++){	
		   // System.out.println("-------------------------"+j+". iterasyon------------------------------------");	    
		    rtf=xl+dx*fl/(fl-fh);
		    //System.out.println("rtf="+rtf+" xl="+xl+" dx*fl="+(dx*fl)+"  (fl-fh)="+(fl-fh));
		    ff=s_TV_LK_V(T,rtf)-s1;
		   // System.out.println("ff= "+ff+" rtf= "+rtf);
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0)return rtf;
		}	
		////System.out.println("iterasyon bitti"+" rtf= "+rtf);
		return rtf;
            
        }        
    public double T_h_LK_SL(double h){
		//h_T_LK_SL(x);
		int MAXIT=30;
		double xacc=1.0e-10;		
		double x2=Tc;
		double x1=x2/2;		
		int i=2;
		//System.out.println("iterasyon başlıyor");
		//System.out.println("h=  "+h);		
		while((h_T_LK_SL(x1)-h)*(h_T_LK_SL(x2)-h)>0){
		x1=x2/Math.pow(2,i);
		/*System.out.println("x1=  "+x1);
		System.out.println("(h_T_LK_SL(x1)-h)=  "+(h_T_LK_SL(x1)-h));
		System.out.println("(h_T_LK_SL(x2)-h)=  "+(h_T_LK_SL(x2)-h));	*/		
		i++;
	    }
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_T_LK_SL(x1)-h;
		fh=h_T_LK_SL(x2)-h;
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    for (j=1;j<=MAXIT;j++){
		    rtf=xl+dx*fl/(fl-fh);
		    ff=h_T_LK_SL(rtf)-h;
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		//System.out.println("iterasyon bitti");
		return rtf;
	}        
    public double P_hT_LK_V(double h,double T){		
		//h_TV_LK_V(pro[1],pro[2])-h_TV_LK_V(298,pro[2]);
		int MAXIT=30;
		double xacc=1.0e-10;		
		double x2=Vc;
		double x1=x2/2;		
		int i=2;
		double h1=h;				
		while((h_TP_LK_V(T,x1)-h1)*(h_TP_LK_V(T,x2)-h1)>0){
		x1=x2/Math.pow(2,i);					
		i++;
	    }
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_TP_LK_V(T,x1)-h1;
		fh=h_TP_LK_V(T,x2)-h1;
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    for (j=1;j<=MAXIT;j++){
		    rtf=xl+dx*fl/(fl-fh);
		    ff=h_TP_LK_V(T,rtf)-h1;
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		//System.out.println("iterasyon bitti");
		return rtf;
	}         
    public double V_hT_LK_V(double h,double T){		
		//h_TV_LK_V(pro[1],pro[2])-h_TV_LK_V(298,pro[2]);
		int MAXIT=30;
		double xacc=1.0e-10;		
		double x2=Vc;
		double x1=x2/2;		
		int i=2;
		double h1=h;				
		while((h_TV_LK_V(T,x1)-h1)*(h_TV_LK_V(T,x2)-h1)>0){
		x1=x2/Math.pow(2,i);					
		i++;
	    }
		int j;		
		double fl,fh,xl,xh,swap,dx,del,ff;
		double rtf=x1;
		fl=h_TV_LK_V(T,x1)-h1;
		fh=h_TV_LK_V(T,x2)-h1;
		if (fl*fh > 0.0)
		System.out.println("Kök sınırlarında hata oluştu sonuç hatalı olabilir");
		if (fl < 0.0){
			xl=x1;
			xh=x2;
		}
		else {
			xl=x2;
			xh=x1;
			swap=fl;
			fl=fh;
			fh=swap;
	    }
	    dx=xh-xl;
	    for (j=1;j<=MAXIT;j++){
		    rtf=xl+dx*fl/(fl-fh);
		    ff=h_TV_LK_V(T,rtf)-h1;
		if (ff < 0.0){
			del=xl-rtf;
			xl=rtf;
			fl=ff;
		} else {
			del=xh-rtf;
			xh=rtf;
			fh=ff;
		}
		dx=xh-xl;
		if (Math.abs(del) < xacc || ff == 0.0) return rtf;
		}	
		//System.out.println("iterasyon bitti");
		return rtf;
	}       
    public double[] func(double T){
		//System.out.println("Tmin=  "+Tmin+"  Tmax=  "+Tmax);
		return property_SI("tp",T,5);
	}         
    public double Pb_T(double T){
		double Pb=P_T_LK_SV(T);	
	    return Pb;
    }    
    public double Tb_P(double P){
		double Tb=T_P_LK_SV(P); 	
		//System.out.println(Tb);	 
	    return Tb;
    } 
    public double STension(double T){
		if(this.Formula.equals("H2O")) return st.sigma(T-273.15)*1e-3;
	    if(T>Tc) return 0;//(double)Double.NaN;
		double Pb=1.01325;	
		double Tr=(1-T/Tc);
		double Tbr=(Tb_P(Pb))/Tc;
		double alfac=0.9076*(1+(Tbr*Math.log(Pc/1.01325)/(1-Tbr)));
		//System.out.println("Pb= "+Pb+" Tr= "+Tr+" Tbr= "+Tbr+" alfac= "+alfac);		
		return Math.pow(Pc,2.0/3)*Math.pow(Tc,1.0/3)*(0.132*alfac-0.279)*Math.pow(Tr,11.0/9)*0.001;	
		}
		public double[] putproZero(){
   for(int i=0;i<pro.length;i++)pro[i]=0;
	   	return pro;
} 
    
    public String[][] toString1(String knownpro,double v1, double v2){ 
	    String s1[][]=new String[16][3]; 
	    
	double ipro[]=property_SI(knownpro,v1,v2);    
	for(int i=0;i<ipro.length;i++){
			s1[i][1]= i==7 ? zoneName((int)ipro[7]) : ""+ipro[i];			
			
	}
	    s1[0][0]="P, pressure                  ";  
	    s1[1][0]="T, temperature               ";  	
	    s1[2][0]="v, specific volume           ";  	
	    s1[3][0]="h, enthalpy                  ";	
	    s1[4][0]="u, internal energy           ";	
	    s1[5][0]="s, entropy                   ";
	    s1[6][0]="x,                           ";
	    s1[7][0]="zone name                    ";
	    s1[8][0]="Compressibility factor       ";
	    s1[9][0]="g, qibbs free energy         ";	
	   s1[10][0]="s, surface tension           ";
	   s1[11][0]="cp, specific heat constant v ";
	   s1[12][0]="cv, specific heat constant v ";
	   s1[13][0]="M, molecular weight          ";
	   if(ipro[7]==1 || ipro[7]==2 || ipro[7]==3 || ipro[7]==6) s1[14][0]="kv, vapour conductivity      ";
       else if(ipro[7]==7 || ipro[7]==5)                        s1[14][0]="kl, liquid conductivity      ";                            
       else                                                     s1[14][0]="klv, mixture conductivity    ";
       if(ipro[7]==1 || ipro[7]==2 || ipro[7]==3 || ipro[7]==6) s1[15][0]="muv, vapour viscosity        ";
       else if(ipro[7]==7 || ipro[7]==5)                        s1[15][0]="mul, liquid viscosity        ";                            
       else                                                     s1[15][0]="mulv, mixture viscosity      ";   
	    
	    s1[0][2]=" bars          ";   
	    s1[1][2]=" deg K         ";   
	    s1[2][2]=" m^3/kmole     ";   
	    s1[3][2]=" KJ/kmole      ";   
	    s1[4][2]=" KJ/kmole      ";   
	    s1[5][2]=" KJ/kmole K    ";   
	    s1[6][2]="               ";   
	    s1[7][2]="               ";   
	    s1[8][2]="               ";   
	    s1[9][2]=" KJ/kmole      ";  
	   s1[10][2]=" N/m           "; 
	   s1[11][2]=" KJ/kmole K    ";
	   s1[12][2]=" KJ/kmole K    ";
	   s1[13][2]=" kg/kmole      ";
	   s1[14][2]=" W/(m.K)       ";
	   s1[15][2]=" Pa.s          ";    	     	    
	    return s1; 
	 }
	 
/*
*Implemented methods from fluidInterface class
*/ 	
 	public static absfluid getInstance(String fluidName) throws java.io.IOException {	 	
	 	return new LeeKesler(fluidName);	
 	}
	public double h_TP(double T,double P) throws GException {
			int z=zone(T,P);  
			if(Formula.equals("H2O")){
				/*System.out.println("h2o "+T+"  "+P);
				System.out.println("ffdf"+(st.h(T-273.15,st.v_tp(T-273.15,P))
			*MolWt));
			System.out.println("fdff"+(st.h(Tref-273.15,st.vsg_t(Tref-273.15))*MolWt));*/
				 return st.h(T-273.15,st.v_tp(T-273.15,P))
			*MolWt-st.h(Tref-273.15,st.vsg_t(Tref-273.15))*MolWt;  	       
		}
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor		                             
                 return h_TP_LK_V(T,P);		                     
            }		       
            else if(z==7){                                
                return h_T_LK_SL(T);		                          
            }		       
            else if(z==5){
                //liquid		                    		       
                return h_TP_LK_L(T,P);		                      
            }		      
            else if(z==4){
                //vapor-liquid mixture		       
                return h_T_LK_SV(T);             
            } 
            else throw new UnDefinedStituationException();            
	}
	public double h_TV(double T,double V) throws GException {
			int z=zonev(T,V);    	       
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor		                             
                 return h_TV_LK_V(T,V);		                     
            }		       
            else if(z==7){                                
                return h_T_LK_SL(T);		                          
            }		       
            else if(z==5){
                //liquid		                    		       
                return h_TV_LK_L(T,V);		                      
            }		      
            else if(z==4){
                //vapor-liquid mixture		       
                return h_T_LK_SV(T);             
            } 
            else throw new UnDefinedStituationException();            
	}
	public double T(double h,double P) throws GException{  
		   	
        if(Formula.equals("H2O")) {
	    //System.out.println("st.t_ph(P,h/MolWt)= "+st.t_ph(P,h/MolWt)+" h= "+h);   
	    h+=st.h(Tref-273.15,st.vsg_t(Tref-273.15))*MolWt;
        return   st.t_ph(P,h/MolWt)+273.15;//  st.h(T-273.15,V/MolWt)*MolWt-st.h(Tref,st.vsg_t(Tref));
    }
		double hsl=h_P_LK_SL(P);     	
        double hsv=h_P_LK_SV(P);                
        if(h>=hsv || P>Pc){
                //vapor , supercritical fluid , superheated vapor,saturated vapour		      
                //System.out.println("vapor");	                 
            return T_hP_LK_V(pro[3],pro[0]);                     
        }           
        else if(h==hsl || (h<hsv && h>hsl)){
                //saturated liquid	       
                //System.out.println("saturated liquid");		       
        	return T_P_LK_SV(P);		       
        }		      
        else if(h<hsl){
                //liquid		                      
                //System.out.println("liquid");        
                return T_hP_LK_L(h,P);	                  
               
        }
        else throw new UnDefinedStituationException(); 
		      
          
	}
	public double x(double T,double V)throws GException{
			int z=zonev(T,V);
			 if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor		                             
                 return 2;		                     
            }		       
            else if(z==7){                                
                return 0;		                          
            }		       
            else if(z==5){
                //liquid		                    		       
                return -1;		                      
            }		      
            else if(z==4){
                //vapor-liquid mixture		       
                return x_tv(T,V);             
            } 
            else throw new UnDefinedStituationException();          
	}
	public double k(double T,double P) throws GException {
			int z=zone(T,P);	    		       
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor    
                return kv_TP_LK_V(T,P);               	       
            }		       
            else if(z==7){
                //saturated liquid	      
                return kl_T_LK_L(T);                      
            }		       
            else if(z==5){
                //liquid         
                return kl_T_LK_L(T);                
            }		      
            else if(z==4){               
                return kv_TP_LK_V(T,P);                
            }
            else throw new UnDefinedStituationException();           
	}
	public double vis(double T,double P) throws GException {
			int z=zone(T,P);	    		       
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor               
                return vis_T_L_LPV(T);
                	       
            }		       
            else if(z==7){
                //saturated liquid	                
                return vis_T_PS_LTL(T);	       
            }	       
            else if(z==5){
                //liquid                 
                return vis_T_PS_LTL(T);   
            }		      
            else if(z==4){          
                return vis_T_L_LPV(T); 
            }
            else throw new UnDefinedStituationException();            
	}
	public double ro(double T,double P)throws GException{
			int z=zone(T,P);    	       
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor		                             
                 return 1/V_TP_LK_V(T,P);		                     
            }		       
            else if(z==7){                                
                return 1/V_T_LK_SL(T);		                          
            }		       
            else if(z==5){
                //liquid		                    		       
                return 1/V_TP_LK_L(T,P);		                      
            }		      
            else if(z==4){
                //vapor-liquid mixture		       
                return 1/V_T_LK_SV(T);             
            } 
            else throw new UnDefinedStituationException();  	
			
	}
	public double cp(double T,double P) throws GException {
			int z=zone(T,P);    	       
            if(z==1 ||z==3 || z==6 || z==2) {
                //vapor , supercritical fluid , superheated vapor		                             
                 return cp_TP_LK_V(T,P);		                     
            }		       
            else if(z==7){                                
                return cp_T_LK_SL(T);		                          
            }		       
            else if(z==5){
                //liquid		                    		       
                return cp_TP_LK_L(T,P);		                      
            }		      
            else if(z==4){
                //vapor-liquid mixture		       
                return cp_T_LK_SV(T);             
            } 
            else throw new UnDefinedStituationException(); 
	}
	public double sigma(double T,double P) throws GException {
			return STension(T);
	}
}
