!
!   File.f90
!   Trial
!
!   Created by Seyhan Emre Gorucu on 8/2/13.
!   Copyright 2013 Seyhan Emre Gorucu. All rights reserved.
!
program threephaseflash
implicit none
real*8  T,P,TolSS,TolNR,TolRR,TolRRNR,TolSSSA,TolNRSA,TolXz
real*8  pmol(3),L,V,GPl,GPv,t1,t2,Plast,tmp,sumxx,gtmp,nco2,sumz
real*8, allocatable, dimension(:) :: Tc,Pc,omega,h,g,z,zold,&
KK,p1com,p2com,p3com,KK1,KK2,lnKK1,lnKK2,PCMPSA,TRIALV,&
SAz,SAnz,conb,d,sqAi,Bi,half,KK1pstab,KKwilson,KKLF,y,&
x,KK2pflash,KK2pstab
real*8, allocatable, dimension(:,:) :: BIP,KKest,cona,qalf,PVTdata
character(len=20)  filename
integer Nc,i,j,itSSSAmax,itNRSAmax,itSSmax,itNRmax,&
itKflamax,itNRSA,iVL,itrial,it,m,itSS,itNR,twophaseidentity
integer status,st1,icase,COT,convxset,initialguess
integer withline,itmmax,irline,igenin,time,threephasestability
integer identity,iteration,total,k,iteration2,&
itssstab,itnrstab,itsstwo,itnrtwo,itssthree,itnrthree,&
it3phasestabilitynr,it3phasestabilityss,twophaseflashtrial,&
threephaseflashtrial,onephaseflashtrial,itsstwophase,itnrtwophase&
,onephasestabilitytrial
real*8  Tolline,bisec,sigma,beta,TLL,SStime,diff
real*8  percent,ztotal(1000,3),time1,time2,difnr,&
threephase(201,701),threephasess(201,701),threephasenr(201,701)&
,threephasemol1(201,701),threephasemol2(201,701),&
threephaseid(201,701) ,onephasestabilityss(201,701),&
onephasestabilitynr(201,701),onephasestabilityidentity(201,701),&
twophasess(201,701),twophasenr(201,701),twophaseL(201,701),&
twophasetll(201,701),threephaseguess(201,701),&
threephasestabilityss(201,701),threephasestabilitynr(201,701),&
threephasetrial(201,701),threephaseflashss(201,701),&
threephaseflashnr(201,701), &
!!     C       Constants
one_minus_sq2,sq2_plus_1,sq2,sq2in,twosq2 &
!!C     Additional for reduced LJ
,Bmz,hl(6),hv(6),teta_z(4),h1(6),h2(6),h3(6),Tin



common one_minus_sq2,sq2_plus_1,sq2,sq2in,twosq2

!!    C     Common Multiplications
one_minus_sq2 = -0.41421356237309514547d0
sq2_plus_1 = 2.41421356237309514547d0
sq2 = 1.41421356237309514547d0
sq2in = 0.707106781186547461715d0
twosq2= 2.828427124746190d0

!!    filename='PVTinput.dat'
!!    write(*,990) filename
!!
!!990  format(' ','The input file name is: ',A)
!!    open(unit=2, file=filename, status='old',action='read',&
!!         iostat=status)
!!
!!    allocate(PVTdata(1000,2), stat=st1)
!!    if (st1.ne.0) then
!!    write(*,*) 'allocating PVT data failed'
!!    stop
!!    end if
!!
!!    !!C  Input PVTdata
!!    do
!!    read(2,*,iostat=st1) PVTdata(1,1)
!!    if(st1.eq.0) exit
!!    end do
!!    backspace(2)
!!    read(2,*,iostat=st1) ((PVTdata(i,j),j=1,2),i=1,1000)
!!    write(*,*) ((PVTdata(i,j),j=1,2),i=1,1000)

T=5
filename='input.dat'
write(*,1000) filename

1000 format(' ','The input file name is: ',A)
open(unit=3, file=filename, status='old', action='read',&
iostat=status)


if(status.eq.0) then
else
!! C  Stability AnalysisCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
!!C  Input TolSS
!it=0
do
!it=it+1
read(3,'(F25.16)',iostat=st1) TolSSSA
!write(*,*)it
if (st1.eq.0) exit
end do
write(*,1001) TolSSSA
1001   format(' ','TolSSSA: ',ES12.2)
end if
write(*,*) T

end program threephaseflash