Fortran 中 READ 的含义
READ()
在 Fortran 中做什么?
例如:
READ(1,82)
What does READ()
do in Fortran?
For example:
READ(1,82)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
READ()
在 Fortran 中做什么?
例如:
READ(1,82)
What does READ()
do in Fortran?
For example:
READ(1,82)
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
1 是文件句柄,您必须使用正确的 open 调用来打开它。
82 是引用格式的标签,表示您将如何以可视格式报告数据。
在此示例中,程序从标准输入(未指定其单元号,因此我输入了 *)接受一个整数和一个浮点值。 格式表示整数占据前四列,然后我有一个浮点数,它保留在 8 列中,小数点后有 3 位数字
如果我现在运行程序,并且不完全遵循此格式,则程序将抱怨并崩溃,因为前 4 列预计表示一个整数(由于 I4 格式)和“5 3”。 不是有效的整数
但是,正确的规范(请注意数字 5 之前的三个空格)将执行正确的操作(有一点容差,并不严格)
1 is the file handle, which you have to open with the proper open call.
82 is a label that references a format, meaning how you will report the data in terms of visual formatting.
In this example, the program accepts from the standard input (whose unit number is not specified, and so I put a *) an integer and a floating point value. the format says that the integer occupies the first four columns, then I have a float which stays in 8 columns, with 3 digits after the decimal point
If I run the program now, and I don't follow exactly this format, the program will complain and crash, because the first 4 columns are expected to represent an integer (due to the I4 format), and "5 3." is not a valid integer
However, a correct specification (please note the three spaces before the number 5) will perform the correct operation (with a little tolerance, it's not that strict)
根据标签 82 处的 FORMAT 语句,它从 1 号“单元”(打开的文件)读取。但是,由于该语句没有列出任何变量,因此它没有地方放置它正在读取的数据,这不太可能有帮助;
READ(1,82) FOOBAR
将更有用地将其正在读取的数据放入变量 FOOBAR 中。It reads from "unit" (opened file) number 1, according to the FORMAT statement at label 82. However since the statement doesn't list any variables it has no place to put the data it's reading, which is unlikely to help;
READ(1,82) FOOBAR
would more usefully put the data it's reading in variable FOOBAR.您可以使用 fortran“read”语句执行更多操作。
考虑:
read (unit #, format, options) ... generic
其中,“7”是读取的单元号,“*”是格式(本例中默认),“10”是程序控制的行号跳转到读取设备/文件到达 eof 时。 “选项”槽可以填充诸如“err ='要转到的行号'”或iostat,advance =“no”之类的内容。 您可以查看 更多内容
格式部分位于何处您可以更精确地指定您期望的数据格式。 例如,如果您有如下格式说明符:
这里,“2X”表示 2 个空格,“2I5”表示 2 个 5 位整数,“F7.3”表示具有以下性质的十进制值:总长度为7,小数点后三位。 “A”指的是一个字符。 您可以查看更多这些
干杯!
You can do a few more things with the fortran "read" statement.
consider:
read (unit #, format, options) ... generic
Where, "7" is the unit number read from, "*" is the format (default in this case), and "10" is the line number that the program control jumps to when the read device / file reaches the eof. The "options" slot can be filled with such things as "err='line number to go to'", or iostat, advance="no". You can check out some more of these
The format part is where you can specify more precisely the format of the data that you expect. For instance, if you have a format specifier like:
Here, the "2X", refers to 2 spaces, the "2I5", refers to 2 integers that are 5 digits, "F7.3", refers to a decimal value which has a total length of 7, with three digits after the decimal. The "A" refers to a character. You can check out some more of these
CHEERS!
“1”是用于在 Fortran 中打开文件的单位,“82”指定读取命令的格式。
上面的代码打开一个名为“fname”的文件,读取命令从文件 fname 中读取,因为它是用单位“1”打开的,并且读取命令以格式 82 指定的格式读取。有关 Fortran 格式的详细信息如下:
"1" the unit that you used to open a file in fortran and "82" specifies the format for the read command.
The code above opens a file called "fname" the read command reads from the file fname as it was opened with a unit "1" and the read command reads in the format as specified by format 82. Details on formatting in fortran is given below:
它使用编号 82 的语句指定的格式从单元 1 读取。
It reads from unit 1 using the format specified by the statement numbered 82.
当 Fortran 读取文件时,它要求 READ 语句唯一标识该文件。 使用 Fortran 单元标识符来完成识别。
单元标识符可以是以下之一:
1) 值大于或等于 0 的整型变量或表达式。
2) 仅在 READ 和 WRITE 语句中允许使用星号 (*)。 在 READ 语句中,星号表示单元 100(标准输入)。
单元编号最好使用 newunit 提供
在使用任何单元编号之前,使用 INQUIRE 语句检查其有效性(存在性),如下例所示:
然后我们有 FORMAT 语句,这是一个带标签的语句,可以出现在格式可见的程序。
它的形式为
FORMAT 语句
一个稍有不同的 FORMAT 语句是,
它再次生成三个宽度为 10 的右对齐 INTEGER,但这次需要至少打印 8 位数字。
When Fortran reads from a file, it required that the READ statements uniquely identify the file. The identification is done using the Fortran unit identifier.
A unit identifier can be one of the following:
1) An integer variable or expression whose value is greater than or equal to 0.
2) An asterisk (*) is allowed only on READ and WRITE statements. On READ statements, an asterisk refers to unit 100 (standard input).
Unit numbers are best supplied using newunit
Use the INQUIRE statement to check the validity (existence) of any unit number prior to using it, as in the following example:
Then we have the FORMAT statement, a labelled statement which can appear in any portion of the program in which the format is visible.
It is of the form
The FORMAT statement
A slightly different FORMAT statement is
which again yields three right-justified INTEGERs of width 10 but this time requires a minimum of 8 digits to be printed.