user3170933
user3170933

Reputation: 1

Fortran runtime error: Bad integer for item 0 in list input

I just wanted to test whether Fortran would read a new line from a list for every new READ statement.

The input list is a .rtf file with the following inputs;

2 4
6 8

The specific error when compiling is this:

At line 9 of file reading.f90 (unit = 10, file = 'data.rtf')
Fortran runtime error: Bad integer for item 0 in list input

This is my code:

PROGRAM reading

 IMPLICIT NONE

 INTEGER :: a, b, c, d

 OPEN (UNIT = 10, FILE = "data.rtf")

 READ (10,*) a, b
 READ (10,*) c, d

 CLOSE (10)

 WRITE (*,*) "a = ", a, "b = ", b, "c = ", c, "d = ", d

END PROGRAM reading

Thanks for the help!

Upvotes: 0

Views: 2721

Answers (2)

user1008139
user1008139

Reputation: 301

I guess you use an .rtf file because you are on a mac using TextEdit. This format contains hidden format characters. It is better if you had a plain .txt TextEdit doesn't save new documents as .txt but it can edit them with no problem. So your best bet if you don't want to use a better text editor (for example gedit) is to open the terminal and touch file.txt to create an empty file in the current directory. This you can edit latter on. You could even edit it on the terminal with VI if you want.

Upvotes: 1

Do not use .rtf files, they use a special encoding you cannot read so easily. Save the file as pure text file (ASCII)! You can use Notepad or any other editor, even that one you write the program source code in, but pay attention to the format you save it in.

Upvotes: 1

Related Questions