FORTRAN 95 Problem - junk error

In summary, the conversation discusses a problem with a 3D Ising model simulation code. The goal is to write the i and j coordinates of a column to a file if all the values in that column are -1. The code provided includes a loop to check each column and a conditional statement to write the coordinates if the condition is met. However, the code is giving an error and not functioning as expected. The speaker asks for help in understanding the error and improving the code.
  • #1
Diracster
3
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
  • #2
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)
 

Related to FORTRAN 95 Problem - junk error

What is a FORTRAN 95 junk error?

A FORTRAN 95 junk error is an error that occurs when the compiler encounters an unexpected character or symbol in the source code. This could be caused by a typo, missing quotation marks, or an incorrect variable declaration.

How do I fix a FORTRAN 95 junk error?

To fix a FORTRAN 95 junk error, you will need to carefully review your source code and look for any typos, missing punctuation, or incorrect variable declarations. If you are unable to find the error, you may need to consult with a more experienced FORTRAN programmer or use a debugger to track down the issue.

Why am I getting a junk error when my code previously compiled without errors?

This could be caused by a recent change in your source code, such as a new line of code that contains a typo or a missing punctuation mark. It could also be caused by using a different compiler or compiler settings that are more strict in detecting errors.

Can a FORTRAN 95 junk error be caused by a hardware or operating system issue?

In rare cases, a FORTRAN 95 junk error could be caused by a hardware or operating system issue. This could occur if there is a problem with your computer's memory or if there is a compatibility issue with the FORTRAN compiler and your operating system. However, it is more likely that the error is caused by an issue in your source code.

Is there a way to prevent FORTRAN 95 junk errors?

While it is impossible to completely prevent all errors in programming, there are steps you can take to reduce the likelihood of encountering a FORTRAN 95 junk error. These include carefully reviewing your code for typos and using a debugger to identify and fix any errors. Additionally, it is helpful to have a good understanding of the FORTRAN language rules and syntax to avoid common mistakes.

Similar threads

  • Programming and Computer Science
Replies
4
Views
747
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
17
Views
5K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
2
Replies
55
Views
4K
Back
Top