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

查看:456
本文介绍了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 + descriptors

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天全站免登陆