gpt4 book ai didi

fortran - vms fortran 读/写单元指定

转载 作者:行者123 更新时间:2023-12-02 17:20:13 25 4
gpt4 key购买 nike

我的任务是将一些旧的(大约 1986 年)VAX VMS FORTRAN 代码移植到 C++,但遇到了一些障碍。以下两行代码是计算转到的一部分。

WRITE(2'N) (Y (I), I = 1, 5)
READ(2'N, ERR = 48) (Y (I), I = 1, 5)

我的问题是单位指示符 "2'N",如果它确实是这样的话。 “N”是传递给子例程的整数变量。我已经对这个模式进行了大量的谷歌搜索,并阅读了我能找到的 VMS 文档,但无法找到与带有撇号的该模式有关的任何信息。我理解写入和读取语句后面隐含的 do 循环,但我不明白这是在“哪里”写入和读取。浏览 FORTRAN 代码的其余部分并没有显示可能与此调用关联的 unit=2 open 语句,因此它看起来可能不是磁盘文件,但我不确定。我希望这里有人能够恢复他们的内存并帮助我。

最佳答案

如果我读了VMS VAX FORTRAN manual正确地,'N 指定单元 2 中的第 N 条记录。来自 Cl。 7.1.1.6“记录说明符”:

The record specifier identifies the number of the record you wish to access in a file with relative organization. It takes either one of the following forms:

REC = r
'r

r
Is a numeric expression with a value that represents the position in a direct access file of the record to be accessed. [...]

请注意,这不符合标准的 Fortran!大多数编译器不会接受这种语法。相反,请使用REC=...:

WRITE(2, REC=N) (Y (I), I = 1, 5)
READ(2, REC=N, ERR = 48) (Y (I), I = 1, 5)
<小时/>

单元2处的文件不需要显式打开。这在同一文件 Cl 中有所规定。 7.1.1.2“逻辑单元说明符”:

A logical unit number is assigned to a file or device in one of the two ways:

  • Explicitly trough an OPEN statement [...]
  • Implicitly by the system [...]

在后一种情况下,使用的文件名在 Cl. 4.2.2.1 "FORTRAN Logical Names" of the VAX Fortran user manual 中定义。 :

VAX FORTRAN provides predefined logical names in the following form:

FOR0nn[.DAT]

[...]

For example:

   WRITE (17,200)

If you enter the preceding statement without including an explicit file specification, the data is written to a file named FOR017.DAT on your default disk under your default directory.

在这种情况下,大多数现代编译器都会创建一个文件 fort.nn

关于fortran - vms fortran 读/写单元指定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37397173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com