以自由格式在Fortran中不进行读取 [英] Non-advancing read in Fortran with free format

查看:455
本文介绍了以自由格式在Fortran中不进行读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个文件中读取一行,其中包括三个实数,而不用前进指针。所以我写道:(TXT是代表我的文件的值为80的变量)

  read(TXT,*,ADVANCE ='NO')(数字(i),i = 1,3)

然而,我得到了一条错误消息说:

错误#6568:ADVANCE,SIZE或EOR说明符的这种用法是无效的。



所以我应该怎么写才能使它正确?



谢谢。

解决方案

您只能以明确的格式使用advance ='no'。原因如下:advance ='no'只是避免进入下一条记录(注意文件指针始终前进,就在最后一个读取值之后);但使用定向列表(格式*),人们不知道您的读取语句涉及多少条记录(例如,三个数字可能会写入四行)。


I want to read a line in a file, which includes three real numbers, without advancing the pointer. So I wrote: (TXT is the variable representing my file which has a value of 80)

read(TXT, *, ADVANCE='NO') (numbers(i),i=1,3)

However, I got an error message saying:

"error #6568: This use of the ADVANCE, SIZE, or EOR specifier is invalid."

So how should I write it to make it correct?

Thanks.

解决方案

You can use advance='no' only with an explicit format. The reason is the following : advance='no' just avoids to go to the next record (notice that the file pointer advances anyway, just after the last read value); but with a directed list (format *), one doesn't know how many record are involved by your read statement (the three numbers may be written on four lines for instance).

这篇关于以自由格式在Fortran中不进行读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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