FORTRAN 95 Problem - junk error

  • Context: Fortran 
  • Thread starter Thread starter Diracster
  • Start date Start date
  • Tags Tags
    Error Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 9K views
Diracster
Messages
3
Reaction score
0
I have a 3D ising model simulation, what i am trying to do is look up each column in the array and if all the values of that column are -1 then i wish to write the i and j coordinates of that column to a file. the section of code I am having problems with is:

OPEN (10, FILE='holes.dat')
DO i=1,x
DO j=1,y
DO k=1,z
IF (s(i,j,k)>0) THEN
EXIT
ELSE IF (k=10) THEN
WRITE (10,*) i, j
END IF
END DO
END DO
END DO
CLOSE (10)

My compiler is giving me the error:

isingmodel8.f95:163.19:

ELSE IF (k=10) THEN
1
Error: Unexpected junk after ELSE statement at (1)

Basically i would like to know why i am getting this error and also if you think that my code will do what i want it to or if there is a better way of doing it. Any help is much appreciated!

Thanks
 
Physics news on Phys.org
ok so i have fixed the junk error and modified the code slightly, but now i am having the problem that it is writing out every coordinate when i know it shouldn't be. I have a layer of up spins (=1) in the middle of two layers of down spins (=-1) so at the start i would expect the code not to write out any i,j coordinates yet it still rights out all but (4,5). The new code is as follows:

OPEN (10, FILE='holes.dat')
DO i=1,x
DO j=1,y
DO k=1,z
IF (s(i,j,k).GT.0) EXIT
IF (k==z) THEN
WRITE (10,*) i, j
END IF
end do
END DO
END DO
CLOSE (10)