tom0395 |
12-10-2014 03:22 AM |
Unable to solve fortran95 compilation error "Unexpected array reference at (1)"
Hi guys,
I am currently using fortran95 compiler to run this code(see attached), however I am unable to solve the errors that were presented (unexpected array reference), I thought it would be because i declared my arrays wrongly somewhere, but even after a few tweaks the problem still presented itself. I would really appreciate any helpful comments, and do let me know if any more info is needed.
Warmest Regards,
Tom
Code:
Program ProgramVII
implicit none
integer, parameter :: ni=51, nj=51
double precision, parameter :: pi = 3.1415926535897932D+0
integer PL, irun, irunmax,ii,js,je,j
double precision m(ni),p(ni),mp(ni),pp(ni)
double precision mx(nj),px(nj),mpx(nj),ppx(nj)
double precision T,Mo,Po,Pe,z,R,Area,wavespeed,D,f,alpha,delx,delt,delm,k,i,time,tp,tm,Ho,vf
double precision A(3),B(3),tc
common/group1/Mo,Po,Area,wavespeed,D,f,Pe
common/group2/delx
common/group3/delt
common/group4/A,B
write(*,*)'give time tc(seconds):'
read (*,*) tc
irun=1
I=2
PL=200
irunmax=2000
js=2
je=ni-1
T=273.15
z=0.897403
R=494.94
k=1.27
alpha=1.0
Mo=80
Pe=200000
Po=400000
mx=-Mo
m=Mo
D=0.6
Area= pi*D**2/4
wavespeed= sqrt(z*R*T)
f=0.015
delx=PL/(ni-1)
delt=delx*alpha/wavespeed
time=irun*delt
A(1)=alpha*wavespeed/Area !coefficient
A(2)=0.25*f*wavespeed**2*delx/D/Area/Area !coefficient
A(3)=wavespeed*(1/alpha-alpha)/2.0/Area !coefficient
B(1) = 1/wavespeed/delt
B(2) = 1/Area/delt
B(3) = f/2/D/Area/Area
call steadystate(p)
call steadystatex(px)
pp = Po
mp = Mo
ppx=px(51)
mpx=-Mo
Ho=p(51)-px(51)
call valveI(irun,m,p,mp,pp,tc,Ho)
call valveII(irun,mx,px,ppx,tc,Ho)
do irun =1, irunmax
call pipeI(js,je,mx,px,mpx,ppx)
call valveII(irun,mx,px,mpx,ppx,tc,Ho)
call reservoirI(mx,px,mpx,ppx)
do j=1,ni
if(irun>irunmax-10)then
write(*,*)irun,j,mpx(j),ppx(j)
end if
mx(j)=mpx(j)
px(j) = ppx(j)
end do
open(unit=4,file = 'Plot53.txt')
write(4,*)(irun-1)*delt,px(50)
end do
stop
end program
subroutine steadystate(p)
implicit none
integer,parameter :: ni=51
integer i
double precision p(ni)
double precision Mo,Po,Area,wavespeed,D,f,delx
common/group1/Mo,Po,Area,wavespeed,D,f
common/group2/delx
do i=1,ni
p(i)= sqrt(Po**2-f*wavespeed**2*Mo*Mo*delx*(i-1)/D/Area/Area)
open(unit=3,file='Initial Pressure.txt')
write(3,*)i-1,p(i)
end do
return
end
subroutine steadystatex(px)
implicit none
integer,parameter :: nj=51
integer i
double precision px(nj)
double precision Mo,Pe,Area,wavespeed,D,f,delx
common/group1/Mo,Pe,Area,wavespeed,D,f
common/group2/delx
Pe=200000
do i=1,nj
px(i)=sqrt(Pe**2+f*wavespeed**2*Mo*Mo*delx*(i)/D/Area/Area)
open(unit=3,file='Initial Pressure.txt')
write(3,*)i-1,px(i)
end do
return
end
subroutine pipeI(js,je,m,p,mp,pp)
implicit none
integer,parameter :: ni=51
double precision m(ni),p(ni),mp(ni),pp(ni)
integer i,js,je
double precision c1,c2,r1,f1,f2,f1p,f1m,f2p,f2m,DP,DM
double precision r2
double precision A(3)
common/group4/A
do 1000 i=js,je
DP=1
DM=1
do while(abs(DP)>0.001.OR.abs(DM)>0.001)
c1=A(1)*(mp(i)-m(i-1))
c2=A(3)*0
r1=A(2)*abs(mp(i)+m(i-1))
r2=c1*(pp(i)+p(i-1))+pp(i)**2-p(i-1)**2+r1*(mp(i)+m(i-1))
f1= r2+ c2*(mp(i)-m(i)+mp(i-1)-m(i-1))*(pp(i)+p(i-1))
f1p=c1+2*pp(i)+c2*(mp(i)-m(i)+mp(i-1)-m(i-1))
f1m=A(1)*(pp(i)+p(i-1))+2*r1+c2*(pp(i)+p(i-1))
c1=A(1)*(mp(i)-mp(i+1))
c2=A(3)*0
r1=A(2)*abs(mp(i)+m(i+1))
r2=c1*(pp(i)+p(i+1))-pp(i)**2+p(i+1)**2+r1*(mp(i)+m(i+1))
f2= r2+c2*(mp(i)-m(i)+mp(i+1)-m(i+1))*(pp(i)+p(i+1))
f2p= c1-2*pp(i)+c2*(mp(i)-m(i)+mp(i+1)-m(i+1))
f2m= A(1)*(pp(i)+p(i+1))+2*r1+c2*(pp(i)+p(i+1))
DP=(f1/f1m-f2/f2m)/(f2p/f2m-f1p/f1m)
DM=-(f1+f1p*DP)/f1m
pp(i)=pp(i)+DP
p(i)=pp(i)
mp(i)=mp(i)+DM
m(i)=mp(i)
end do
1000 continue
return
end
subroutine valveI(irun,m,p,mp,pp,tc,Ho)
Implicit None
integer,parameter :: ni=51
Double Precision, Parameter :: Pi=3.1415926535897932D+0
Double Precision m(ni),p(ni),mp(ni),pp(ni)
double precision c1,c2,r1,f1,f2,f1p,DP,r2
Double Precision time,delm,Mo,delt,u,v,w,vf,tc,x,y,z,Ho
Double Precision A(3),B(3)
integer irun
common/group1/Mo
common/group3/delt
common/group4/A,B
delm=10.0
time=delt*irun
DP=1
Mo=80
if(time<tc)then
vf=1-time/tc !valve function
x=Ho*B(1)/vf/vf/Mo/Mo
y=B(2)
z=B(3)*m(ni-1)*abs(m(ni-1))-B(2)*m(ni-1)-B(1)*p(ni)
mp(ni)=(sqrt(y*y-4*x*z)-y)/2/x !positive mass flowrate
else
mp(ni)=0
end if
do while(abs(DP)>0.001)
!following is the Newton-Raphspn iterative method
c1=A(1)*(mp(ni)-m(ni-1))
c2=A(3)*0
r1=A(2)*abs(mp(ni)+m(ni-1))
r2=c1*(pp(ni)+p(ni-1))+pp(ni)**2-p(ni-1)**2+r1*(mp(ni)+m(ni-1))
f1= r2+ c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))*(pp(ni)+p(ni-1))
f1p=c1+2*pp(ni)+c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))
DP= -f1/f1p
pp(ni)=pp(ni)+DP
m(ni)=mp(ni)
p(ni)=pp(ni)
end do
return
end
subroutine valveII(irun,m,p,mp,pp,tc,Ho)
implicit none
integer, parameter :: ni=51
Double Precision, Parameter :: Pi=3.1415926535897932D+0
double precision m(ni),p(ni),mp(ni),pp(ni),DP,c1,c2,r1,f1,f1p,time,delm,delt,a,b,c,vf,tc,Ho,x,y,z,mx
double precision A(3),B(3)
integer irun
common/group1/Mo
common/group3/delt
common/group4/A,B
delm=10.0
time=delt*irun
DP=1
mx=-80
if(time<tc)then
vf=1-time/tc
x=-Ho*B(1)/vf/vf/mx/mx
y=B(2)
z=B(3)*m(ni-1)*abs(m(ni-1))-B(2)*m(ni-1)+B(1)*p(ni-1)
mp(ni)= (sqrt(y*y-4*x*z)-y)/2/x
else
mp(ni)=0
end if
do while(abs(DP)>0.001)
!following is the Newton-Raphspn iterative method
c1=A(1)*(mp(ni)-m(ni-1))
c2=A(3)*0
r1=A(2)*abs(mp(ni)+m(ni-1))
r2=c1*(pp(ni)+p(ni-1))+pp(ni)**2-p(ni-1)**2+r1*(mp(ni)+m(ni-1))
f1= r2+ c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))*(pp(ni)+p(ni-1))
f1p=c1+2*pp(ni)+c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))
DP= -f1/f1p
pp(ni)=pp(ni)+DP
m(ni)=mp(ni)
p(ni)=pp(ni)
end do
return
end
subroutine reservoirI(m,p,mp,pp)
implicit none
integer,parameter:: ni=51
double Precision m(ni),p(ni),mp(ni),pp(ni)
double precision A(3),DM,c1,c2,r1,f2,f2p,f2m,r2
common/group4/A
pp(1)=p(1)
DM=1
do while(abs(DM)>0.001)
!following is the Newton-Raphspn iterative method
c1=A(1)*(mp(1)-m(2))
c2=A(3)*0
r1=A(2)*abs(mp(1)+m(2))
r2=c1*(pp(1)+p(2))-pp(1)**2+p(2)**2+r1*(mp(1)+m(2))
f2= r2+c2*(mp(1)-m(1)+mp(2)-m(2))*(pp(1)+p(2))
f2m= A(1)*(pp(1)+p(2))+2*r1+c2*(pp(1)+p(2))
DM= -f2/f2m
mp(1)=mp(1)+DM
end do
return
end
|