问题
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:
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).
来源:https://stackoverflow.com/questions/26201876/fortran-syntax-error-in-open-statement