Fortran READ(*,*), WRITE(*,*) 参数 [英] Fortran READ(*,*), WRITE(*,*) arguments

查看:30
本文介绍了Fortran READ(*,*), WRITE(*,*) 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在之前的 SO 问题中有所涉及.然而,之前的讨论似乎有些不完整.

This question has been covered somewhat in previous SO questions. However, previous discussions seem somewhat incomplete.

Fortran 有多个 I/O 语句.有 READ(*,*)WRITE(*,*) 等.第一个星号 (*) 是标准星号,表示键盘的输入或输出到/从屏幕.我的问题是关于第二个星号:

Fortran has several I/O statements. There is READ(*,*) and WRITE(*,*), etc. The first asterisk (*) is the standard asterisk designating an input or output from the keyboard to/from the screen. My question is about the second asterisk:

第二个星号表示 I/O 元素的格式,即正在使用的数据类型.如果这个星号保持不变,fortran 编译器将使用默认格式(无论是什么格式,取决于编译器).用户必须使用许多格式描述符来指定数据类型、精度等.

The second asterisk designates the format of the I/O elements, the data TYPE which is being used. If this asterisk is left unchanged, the fortran complier uses the default format (whatever that may be, based on the compiler). Users must use a number of format descriptors to designate the data type, precision, and so forth.

(1) 这些格式描述符是否适用于所有 Fortran 编译器和所有 Fortran 版本?

(1) Are these format descriptors universal for all Fortran compilers and for all versions of Fortran?

(2) 在哪里可以找到这些格式描述符的标准列表?例如,F8.3 表示应使用定点表示法打印数字,字段宽度为 8 位,小数点后 3 位.

(2) Where can I find the standard list of these format descriptors? For example, F8.3 means that the number should be printed using fixed point notation with field width 8 and 3 decimal places.

可在此处找到编辑描述符的参考:http://fortranwiki.org/fortran/show/Edit+描述符

A reference for edit descriptors can be found here: http://fortranwiki.org/fortran/show/Edit+descriptors

推荐答案

首先,作为澄清,READ/WRITE 语句中的第一个星号与您所说的含义略有不同.对于写入,表示写入默认文件单元(在linux世界中通常标准输出),对于读取表示从默认文件单元读取(在linux世界中通常标准输入),其中任何一个都不一定连接到终端屏幕或键盘.

First, as a clarification, the 1st asterisk in the READ/WRITE statement has a slightly different meaning than you state. For write, it means write to the default file unit (in linux world generally standard out), for read it means read from the default file unit (in linux world generally standard in), either of which may not necessarily be connected to a terminal screen or a keyboard.

第二个星号表示使用列表定向 IO.对于读取语句,这通常很有用,因为您的输入不需要指定格式.它将行分解为由空格或逗号分隔的字段(可能是其他几个不常用的字段),并将每个字段依次读取到参数列表中与该字段关联的变量中,忽略未读字段,并继续如果没有读入足够的字段,则下一行(除非明确包含行终止字符 ).

The 2nd asterisk means use list directed IO. For read statements this is generally useful because you don't need a specified format for your input. It breaks up the line into fields separated by space or comma (maybe a couple others that aren't commonly used), and reads each field in turn into the variable associated with that field in the argument list, ignoring unread fields, and continuing onto the next line if not enough fields were read in (unless a line termination character is explicitly included).

对于写入,这意味着允许编译器确定写入变量的格式(我相信没有分隔符).我相信允许在运行时执行此操作,因此您几乎可以保证它尝试写入的值将适合使用的格式说明符,因此您可以放心,您不会得到 ******* 写出来.不利的一面是您必须在参数列表中手动包含分隔符,否则您的所有数字将一起运行.

For writes, it means the compiler is allowed to determine what format to write the variables out (I believe with no separator). I believe it is allowed to do this at run time, so that you are all but guaranteed that the value it is trying to write will fit into the format specifier used, so you can be assured that you won't get ******* written out. The down side is you have to manually include a separator character in your argument list, or all your numbers will run together.

一般来说,使用列表定向读取对用户来说更方便,因此他们不必将输入放入严格定义的字段中,而列表定向写入对程序员来说是一种方便,以防万一他们不确定输出会是什么样子.

In general, using list directed read is more of a convenience to the user, so they don't have to fit their inputs into rigidly defined fields, and list directed writes are a convenience to the programmer, in case they're not sure what the output will look like.

这篇关于Fortran READ(*,*), WRITE(*,*) 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆