FORTRAN 95 Problem - junk error

  • Context: Fortran 
  • Thread starter Thread starter Diracster
  • Start date Start date
  • Tags Tags
    Error Fortran
Click For Summary
SUMMARY

The forum discussion addresses a coding issue in a 3D Ising model simulation using FORTRAN 95. The user initially encounters a "junk error" due to incorrect syntax in the ELSE IF statement, specifically using "=" instead of "==". After resolving this, the user faces a logical error where the program writes coordinates to a file even when it should not. The final code correctly checks if all values in a column are -1 before writing the coordinates to 'holes.dat'.

PREREQUISITES
  • FORTRAN 95 programming language
  • Understanding of 3D array manipulation
  • Basic file I/O operations in FORTRAN
  • Logical operators and control structures in programming
NEXT STEPS
  • Review FORTRAN 95 syntax for conditional statements
  • Explore array indexing and manipulation techniques in FORTRAN
  • Learn about debugging strategies for FORTRAN programs
  • Investigate alternative methods for writing data to files in FORTRAN
USEFUL FOR

This discussion is beneficial for FORTRAN developers, computational physicists working on simulations, and anyone troubleshooting logical errors in their FORTRAN code.

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
 
Technology 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)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K