带有 STATUS='NEW' 的 OPEN 的默认行为
Default behavior of OPEN with STATUS='NEW'
我正在使用 gfortran 编译一个程序(不是我写的)。 make文件指定f77为编译器,我没有。
我 运行 遇到与 OPEN 命令相关的错误。
Error: The STATUS specified in OPEN statement at (1) is 'NEW' and no FILE specifier is present
我查看了 Fortran 77 OPEN,根据 Oracle 语言参考,未指定 'FILE=name' 时存在默认行为。
http://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnaf/index.html
'NEW' -- 文件不存在(存在即为错误)。如果未指定 'FILE=name',则打开名为 'fort.n' 的文件,其中 n 是指定的逻辑单元。
有没有办法强制编译器使用语言指定的默认行为。或者,我可以修改代码以执行预期的默认行为吗?
您引用的文档不是语言规范,它是对特定编译器的描述。关于文件 fort.n
的行为是特定于编译器的。有关实际标准文档,请参阅 https://whosebug.com/tags/fortran/info
具体来说,Fortran 2008 说:
9.5.6.10 FILE= specifier in the OPEN statement
1 The value of the FILE= specifier is the name of the file to be connected to the
specified unit. Any trailing blanks are ignored. The file-name-expr
shall be a name that is allowed by the processor. If this specifier is
omitted and the unit is not connected to a file, the STATUS= specifier
shall be specified with a value of SCRATCH; in this case, the
connection is made to a processor-dependent file. The interpretation
of case is processor dependent.
这意味着你的程序不符合规范,因为当省略FILE=
时,STATUS=
唯一允许的值是"SCRATCH"
。
Gfortran 也会在您写入未打开的单元时创建 fort.n
文件,但当您使用 status="new"
执行 open
语句时则不会。将 file=
说明符添加到代码中应该很容易。如果您坚持使用 fort.N
名称,您甚至可以使用它们。有关如何将整数放入文件名的方法,请参阅 Convert integers to strings to create output filenames at run time。
另一种选择是下载 Oracle Solaris Studio,它包含 f77
命令并且很可能遵循您引用的编译器特定文档。它实际上是一个非常好的编译器(如果缺少一些现代 Fortran 功能),具有非常好的可视化调试和分析实用程序。但是,我建议您首先使您的代码可移植并符合标准。
我正在使用 gfortran 编译一个程序(不是我写的)。 make文件指定f77为编译器,我没有。
我 运行 遇到与 OPEN 命令相关的错误。
Error: The STATUS specified in OPEN statement at (1) is 'NEW' and no FILE specifier is present
我查看了 Fortran 77 OPEN,根据 Oracle 语言参考,未指定 'FILE=name' 时存在默认行为。
http://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnaf/index.html
'NEW' -- 文件不存在(存在即为错误)。如果未指定 'FILE=name',则打开名为 'fort.n' 的文件,其中 n 是指定的逻辑单元。
有没有办法强制编译器使用语言指定的默认行为。或者,我可以修改代码以执行预期的默认行为吗?
您引用的文档不是语言规范,它是对特定编译器的描述。关于文件 fort.n
的行为是特定于编译器的。有关实际标准文档,请参阅 https://whosebug.com/tags/fortran/info
具体来说,Fortran 2008 说:
9.5.6.10 FILE= specifier in the OPEN statement
1 The value of the FILE= specifier is the name of the file to be connected to the specified unit. Any trailing blanks are ignored. The file-name-expr shall be a name that is allowed by the processor. If this specifier is omitted and the unit is not connected to a file, the STATUS= specifier shall be specified with a value of SCRATCH; in this case, the connection is made to a processor-dependent file. The interpretation of case is processor dependent.
这意味着你的程序不符合规范,因为当省略FILE=
时,STATUS=
唯一允许的值是"SCRATCH"
。
Gfortran 也会在您写入未打开的单元时创建 fort.n
文件,但当您使用 status="new"
执行 open
语句时则不会。将 file=
说明符添加到代码中应该很容易。如果您坚持使用 fort.N
名称,您甚至可以使用它们。有关如何将整数放入文件名的方法,请参阅 Convert integers to strings to create output filenames at run time。
另一种选择是下载 Oracle Solaris Studio,它包含 f77
命令并且很可能遵循您引用的编译器特定文档。它实际上是一个非常好的编译器(如果缺少一些现代 Fortran 功能),具有非常好的可视化调试和分析实用程序。但是,我建议您首先使您的代码可移植并符合标准。