FortranPirate
Programmer
I keep getting this error when i try to excute the program.
Linking...
ex.obj : error LNK2001: unresolved external symbol _P@8
ex.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
ex.exe - 2 error(s), 0 warning(s)
I have no clue why, except that its due to the subroutine.
the subroutine code was given to me by the professor, i believe its written in fortran 77. but my code is in 90.
Please help,
the code I am trying to run is..
PROGRAM Project2
IMPLICIT NONE
REAL F, G, Q, Po, Uo, Vo, Qo, U, V, P, Re, dx, dy, dt, t, f1,f2,f3,f4,g1,g2,g3,g4,nts, erroru, errorv, nstop, time
INTEGER imax, jmax, i, j
PARAMETER (imax=100,jmax=100)
DIMENSION F(imax,jmax), G(imax,jmax), Q(imax,jmax), Uo(imax,jmax), Vo(imax,jmax), Po(imax,jmax), Qo(imax,jmax), U(imax,jmax), V(imax,jmax)
OPEN (unit=2, file='testoutput', status = 'new')
Re = 1000.0
dx = 1.0/float(imax-2)
dy = dx
dt=0.25*Re*dx*dx*0.1
nts = 0.0
erroru = 0.0
errorv = 0.0
nstop = 1
!initial conditions
DO i=1, imax
Do j=1, jmax
Uo(i,j) = 0.0
Vo(i,j) = 0.0
Po(i,j) = 0.0
END DO
END DO
DO i=1, imax
DO j=1, jmax
!boundary conditions
nts = nts +1
time = time + dt
Vo(i,1) = 0
Vo(i,2) = 0
Vo(i,jmax+1) = 0
Vo(i,jmax-1) = 0
Uo(1,j) = 0
Uo(2,j) = 0
Uo(imax-1,j) = 0
Uo(imax+1,j) = 0
Uo(i+1,1) = -2 - Uo(i+1,2)
Uo(i-1,1) = -2 - Uo(i-1,2)
Uo(i+1,jmax) = 2 - Uo(i+1,jmax - 1)
Uo(i-1,jmax) = 2 - Uo(i-1,jmax - 1)
Vo(1,j+1) = -Vo(2,j+1)
Vo(1,j-1) = -Vo(2,j-1)
Vo(imax,j+1) = -Vo(imax-1,j+1)
Vo(imax,j-1) = -Vo(imax-1,j-1)
!Fn calculation
f1 = (Uo(i+2,j) - 2*Uo(i,j) + Uo(i-1,j))/(Re*dx**2)
f2 = (Uo(i,j-1) - 2*Uo(i,j) + Uo(i,j+1))/(Re*dy**2)
f3 = (((Uo(i+1,j) + Uo(i,j))/2)**2 - ((Uo(i,j) + Uo(i-1,j))/2)**2)/(dx)
f4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i,j)+Uo(i,j-1))*(Vo(i+1,j-1)+Vo(i,j-1)))/(dy)))
F(i,j) = Uo(i,j) + dt*(f1 + f2 - f3 - f4)
!Gn calculation
g1 = (Vo(i+1,j) - 2*Vo(i,j+1) + Vo(i-1,j+1))/(Re*(dx)**2)
g2 = (Vo(i,j+1) - 2*Vo(i,j) + Vo(i,j-1))/(Re*(dy)**2)
g3 = (((Vo(i,j+1) + Vo(i,j))/2)**2 - ((Vo(i,j) + Vo(i,j-1))/2)**2)/(dy)
g4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i-1,j)+Uo(i-1,j+1))*(Vo(i-1,j)+Vo(i,j)))/(dy)))
G(i,j) = Vo(i,j+1) + dt*(g1 + g2 - g3 - g4)
!Qn calculation
Q(i,j) = (1/dt)*((F(i+1,j) - F(i-1,j))/dx + (G(i,j+1) - G(i,j-1))/dy)
END DO !j
END DO !i
CALL poisson
!calculation of Un+1 and Vn+1
Do i=2,imax-1
Do j=2,jmax-1
U(i,j) = F(i,j) - dt/dx*((P(i,j)+P(i+1,j))/2 - (P(i,j)+P(i-1,j))/2)
V(i,j) = G(i,j) - dt/dy*((P(i,j)+P(i,j+1))/2 - (P(i,j)+P(i,j-1))/2)
Uo(i,j) = U(i,j)
Vo(i,j) = V(i,j)
Po(i,j) = P(i,j)
Qo(i,j) = Q(i,j)
erroru = (U(i,j) - Uo(i,j))
errorv = (V(i,j) - Vo(i,j))
IF (erroru.lt.0.01 .and. errorv.lt.0.01) then
print*, erroru, errorv
END IF
END DO !j
END DO !i
END DO !dt
!!!!!!!!!!!!!!!!!!!!!!!!!!!!! writing u,v,p to file
i=x
j=y
DO i=1, imax
DO j=1, jmax
UU(i,j) = (U(i,j) + U(i+1,j))/2
VV(i,j) = (V(i,j) + V(i+1,j))/2
END DO !j
END DO !i
WRITE (2,70) 'x','y','U','V'
70 FORMAT (1x,A8,T12,A8,T22,A8,T32,A9/1x, 40("="))
WRITE (2,80) x,y,UU,VV
80 FORMAT (1x, I6, 2I10, 2x, F10.4)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END PROGRAM
!Poisson calculation
subroutine poisson
implicit real*8(a-h,o-z)
parameter (imax=42,jmax=42)
dimension u(imax,jmax),v(imax,jmax),p(imax,jmax),q(imax,jmax)
common /Po/U,V,P,Q,Re,time,nts,dx
rf=1.6
eps=0.01
itmax=5000
iter=0
10 iter=iter+1
change=0.0
do 20 i=2,i-1
do 20 j=2,j-1
pold=p(i,j)
p(i,j)=0.25*(p(i-1,j)+p(i,j-1)+p(i+1,j)+p(i,j+1)-q(i,j)*dx**2)
p(i,j)=pold+rf*(p(i,j)-pold)
if (pold .ne. 0.0) ch=dabs((p(i,j)-pold)/pold)
if (ch .gt. change) then
change=ch
im=i
jm=j
Po=pold
endif
20 continue
do 40 k=1,imax
p(k,1)=p(k,2)-2.*v(k,2)/Re/dx
p(k,j)=p(k,j-1)+2.*v(k,j-2)/Re/dx
p(1,k)=p(2,k)-2.*u(2,k)/Re/dx
40 p(i,k)=p(i-1,k)+2.*u(i-2,k)/Re/dx
if (iter .ge. itmax) then
write(2,*) '**** NO CONVERGENCE FOR "P" at Time= ',time
goto 50
endif
if (change .gt. eps) goto 10
50 continue
return
end subroutine
Linking...
ex.obj : error LNK2001: unresolved external symbol _P@8
ex.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
ex.exe - 2 error(s), 0 warning(s)
I have no clue why, except that its due to the subroutine.
the subroutine code was given to me by the professor, i believe its written in fortran 77. but my code is in 90.
Please help,
the code I am trying to run is..
PROGRAM Project2
IMPLICIT NONE
REAL F, G, Q, Po, Uo, Vo, Qo, U, V, P, Re, dx, dy, dt, t, f1,f2,f3,f4,g1,g2,g3,g4,nts, erroru, errorv, nstop, time
INTEGER imax, jmax, i, j
PARAMETER (imax=100,jmax=100)
DIMENSION F(imax,jmax), G(imax,jmax), Q(imax,jmax), Uo(imax,jmax), Vo(imax,jmax), Po(imax,jmax), Qo(imax,jmax), U(imax,jmax), V(imax,jmax)
OPEN (unit=2, file='testoutput', status = 'new')
Re = 1000.0
dx = 1.0/float(imax-2)
dy = dx
dt=0.25*Re*dx*dx*0.1
nts = 0.0
erroru = 0.0
errorv = 0.0
nstop = 1
!initial conditions
DO i=1, imax
Do j=1, jmax
Uo(i,j) = 0.0
Vo(i,j) = 0.0
Po(i,j) = 0.0
END DO
END DO
DO i=1, imax
DO j=1, jmax
!boundary conditions
nts = nts +1
time = time + dt
Vo(i,1) = 0
Vo(i,2) = 0
Vo(i,jmax+1) = 0
Vo(i,jmax-1) = 0
Uo(1,j) = 0
Uo(2,j) = 0
Uo(imax-1,j) = 0
Uo(imax+1,j) = 0
Uo(i+1,1) = -2 - Uo(i+1,2)
Uo(i-1,1) = -2 - Uo(i-1,2)
Uo(i+1,jmax) = 2 - Uo(i+1,jmax - 1)
Uo(i-1,jmax) = 2 - Uo(i-1,jmax - 1)
Vo(1,j+1) = -Vo(2,j+1)
Vo(1,j-1) = -Vo(2,j-1)
Vo(imax,j+1) = -Vo(imax-1,j+1)
Vo(imax,j-1) = -Vo(imax-1,j-1)
!Fn calculation
f1 = (Uo(i+2,j) - 2*Uo(i,j) + Uo(i-1,j))/(Re*dx**2)
f2 = (Uo(i,j-1) - 2*Uo(i,j) + Uo(i,j+1))/(Re*dy**2)
f3 = (((Uo(i+1,j) + Uo(i,j))/2)**2 - ((Uo(i,j) + Uo(i-1,j))/2)**2)/(dx)
f4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i,j)+Uo(i,j-1))*(Vo(i+1,j-1)+Vo(i,j-1)))/(dy)))
F(i,j) = Uo(i,j) + dt*(f1 + f2 - f3 - f4)
!Gn calculation
g1 = (Vo(i+1,j) - 2*Vo(i,j+1) + Vo(i-1,j+1))/(Re*(dx)**2)
g2 = (Vo(i,j+1) - 2*Vo(i,j) + Vo(i,j-1))/(Re*(dy)**2)
g3 = (((Vo(i,j+1) + Vo(i,j))/2)**2 - ((Vo(i,j) + Vo(i,j-1))/2)**2)/(dy)
g4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i-1,j)+Uo(i-1,j+1))*(Vo(i-1,j)+Vo(i,j)))/(dy)))
G(i,j) = Vo(i,j+1) + dt*(g1 + g2 - g3 - g4)
!Qn calculation
Q(i,j) = (1/dt)*((F(i+1,j) - F(i-1,j))/dx + (G(i,j+1) - G(i,j-1))/dy)
END DO !j
END DO !i
CALL poisson
!calculation of Un+1 and Vn+1
Do i=2,imax-1
Do j=2,jmax-1
U(i,j) = F(i,j) - dt/dx*((P(i,j)+P(i+1,j))/2 - (P(i,j)+P(i-1,j))/2)
V(i,j) = G(i,j) - dt/dy*((P(i,j)+P(i,j+1))/2 - (P(i,j)+P(i,j-1))/2)
Uo(i,j) = U(i,j)
Vo(i,j) = V(i,j)
Po(i,j) = P(i,j)
Qo(i,j) = Q(i,j)
erroru = (U(i,j) - Uo(i,j))
errorv = (V(i,j) - Vo(i,j))
IF (erroru.lt.0.01 .and. errorv.lt.0.01) then
print*, erroru, errorv
END IF
END DO !j
END DO !i
END DO !dt
!!!!!!!!!!!!!!!!!!!!!!!!!!!!! writing u,v,p to file
i=x
j=y
DO i=1, imax
DO j=1, jmax
UU(i,j) = (U(i,j) + U(i+1,j))/2
VV(i,j) = (V(i,j) + V(i+1,j))/2
END DO !j
END DO !i
WRITE (2,70) 'x','y','U','V'
70 FORMAT (1x,A8,T12,A8,T22,A8,T32,A9/1x, 40("="))
WRITE (2,80) x,y,UU,VV
80 FORMAT (1x, I6, 2I10, 2x, F10.4)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END PROGRAM
!Poisson calculation
subroutine poisson
implicit real*8(a-h,o-z)
parameter (imax=42,jmax=42)
dimension u(imax,jmax),v(imax,jmax),p(imax,jmax),q(imax,jmax)
common /Po/U,V,P,Q,Re,time,nts,dx
rf=1.6
eps=0.01
itmax=5000
iter=0
10 iter=iter+1
change=0.0
do 20 i=2,i-1
do 20 j=2,j-1
pold=p(i,j)
p(i,j)=0.25*(p(i-1,j)+p(i,j-1)+p(i+1,j)+p(i,j+1)-q(i,j)*dx**2)
p(i,j)=pold+rf*(p(i,j)-pold)
if (pold .ne. 0.0) ch=dabs((p(i,j)-pold)/pold)
if (ch .gt. change) then
change=ch
im=i
jm=j
Po=pold
endif
20 continue
do 40 k=1,imax
p(k,1)=p(k,2)-2.*v(k,2)/Re/dx
p(k,j)=p(k,j-1)+2.*v(k,j-2)/Re/dx
p(1,k)=p(2,k)-2.*u(2,k)/Re/dx
40 p(i,k)=p(i-1,k)+2.*u(i-2,k)/Re/dx
if (iter .ge. itmax) then
write(2,*) '**** NO CONVERGENCE FOR "P" at Time= ',time
goto 50
endif
if (change .gt. eps) goto 10
50 continue
return
end subroutine