2

I couldn't figure out what's wrong with the following Fortran OPEN statement:

filename = 'state_save.txt'                
OPEN(FILE=TRIM(dir)//TRIM(filename),UNIT=ffunit,STATUS='old',FORM='formatted',
IOSTAT=ios, readonly)

[I added CR for clarity]

Compiled under gfortran (from gcc-4.8.1), the above gives the following error:

(dir)//TRIM(filename),UNIT=ffunit,STATUS='old',FORM='formatted',IOSTAT=ios, rea
                                                                           1
Error: Syntax error in OPEN statement at (1)

The code might compile OK with ifort (but I don't have ifort).

Can someone please explain what went wrong and how to write the statement in a standard compliant way?

1 Answer 1

5

The READONLY keyword for OPEN() is not part of the Fortran standard. Although nearly all commerical compilers support it, it does not appear to be supported by gfortran. But nowadays, you can use action='read' to get the same result, which is supported by the language standard (and also seems to work for me).

Sign up to request clarification or add additional context in comments.

1 Comment

In theory, gFortran is supposed to be able to support such extension via the "-fdec" etc switches, but there are "issues", some of which are discussed here (stackoverflow.com/questions/33245989/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.