Fortran Syntax error in OPEN statement

和自甴很熟 提交于 2019-12-24 02:35:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!