
import java.io.*;
public class gibbsSpecies
{
	/*
	*
	*
	*/
	int indicator=-1;
	LeeKesler LK;
	Gas1 g1;
	double P0=1;//bar
	double T=298.2;
	double P=1;
	double mu0=0;
	Atom[] atomList;
	String Formula;
	public gibbsSpecies(String SpeciesName,String SpeciesPhase){		
		if(SpeciesPhase.equals("gas") || SpeciesPhase.equals("(g)") || SpeciesPhase.equals("g") ){					
			try{				
				String[] a=LeeKesler.readgasnames();		
				for(int i=0;i<a.length;i++){
					//System.out.println(a[i]+""+SpeciesName);
					if(SpeciesName.equals(a[i])){ 						
						indicator=1;	
						LK=new LeeKesler(SpeciesName);
						atomList=LK.atomList;						
						Formula=LK.Formula;
						break;
					}
				}						
				Gas1 g=new Gas1();		
				//System.out.println("\n\n\n");		
				String[] b=g.readAllGasNames();		
				for(int i=0;i<b.length;i++){
					if(SpeciesName.equals(b[i])){						
						indicator=2;	
						g1=new Gas1(SpeciesName);
						atomList=g1.atomList;
						Formula=g1.gasName.toUpperCase();
					}
				}
			}catch(IOException ioe){System.out.println(ioe.getMessage());}
		}
		else if(SpeciesPhase.equals("liquid") || SpeciesPhase.equals("(l)") || SpeciesPhase.equals("l") ){
			System.out.println("For the moment Liquid phase properties are not in use");
		}
		else if(SpeciesPhase.equals("solid") || SpeciesPhase.equals("(s)") || SpeciesPhase.equals("s") ){
			System.out.println("For the moment Solid phase properties are not in use");
		}
		else if(SpeciesPhase.equals("aqueous") || SpeciesPhase.equals("(aq)") || SpeciesPhase.equals("aq") ){
			System.out.println("For the moment Aqueous phase properties are not in use");
		}
		else System.out.println("bitti");
		
	}
	public void setP0(double iP){
		P0=iP;
	}
	
	public double mu(double iT,double iP,double n,double nt){
		double mu=0;
		if(indicator==1 || indicator==2){			
			double value=0;						
			//System.out.println("T= "+T);
			//System.out.println("P= "+P);		
			//System.out.println("n=\n "+Matrix.toString(in));		
			double lnP=Math.log(iP/P0);
			//for(int i=0;i<n.length;i++) nt+=in[i][0];		
			//System.out.println(""+LK[i].better_Cp);
			value=Math.abs(n)<1e-15? 0 :Math.log(n/nt);
				//mu[i][0]=(LK[i].m0_T_LK_V(T)+8.3145*T*Math.log(in[i][0]/getnt(in))+8.3145*T*lnP);
			mu=(mu0+8.3145*iT*value+8.3145*iT*lnP);		
			//System.out.println(LK[i].Formula+"  g(t)= "+LK[i].m0_T_LK_V(T)+"  RTlnxi= "+
			//(8.3145*T*value)+"  RTlnP= "+(8.3145*T*lnP)+"  "+mu[i][0]);				
		}
		return mu;
			
	}
	public void getmu0(double iT,double iP){
		if(indicator==1) mu0=LK.m0_T_LK_V(iT);
		else if (indicator==2) mu0=g1.gt(iT);
		else System.out.println("False Indicator at getmu0(double,double) gibbsSpecies.java ");		
	}
	public double ht(double iT){
		if(indicator==1) return LK.ht_T_LK_V(iT);
		else if(indicator==2) return g1.ht(iT);	
		else {
			System.out.println("False Indicator at  ht(double) gibbsSpecies.java ");
			return 0;	
			
		}
	}
        public String[] LKreadGas()throws java.io.IOException {
            return LeeKesler.readgasnames();
            
        }
	
	

}