OPEN语句中的Fortran语法错误 [英] Fortran Syntax error in OPEN statement
问题描述
我无法弄清楚以下Fortran OPEN语句有什么问题:
filename ='state_save.txt'
OPEN(FILE = TRIM(dir)// TRIM(文件名),UNIT = ffunit,STATUS ='old',FORM ='格式化',
IOSTAT = ios,只读)
[为清晰起见添加了CR]
(dir)// TRIM(filename),UNIT = ffunit,STATUS ='old',FORM ='formatted',IOSTAT = ios,rea
1
错误:在(1)$ OP $语句中的语法错误
代码可以用 ifort
编译OK(但我没有ifort)。
有人可以解释出了什么问题,以及如何以符合标准的方式编写报表?
OPEN()
的 READONLY
关键字不是Fortran标准的一部分。尽管几乎所有的商业编译器都支持它,但似乎并没有得到gfortran的支持。但是现在,您可以使用 action ='read'
来获得相同的结果,这得到了语言标准的支持(并且似乎也适用于我)。 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?
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).
这篇关于OPEN语句中的Fortran语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!