简体   繁体   English

如何在Fortran中回车和冲洗?

[英]How to carriage return and flush in Fortran?

I've always wondered about whether or not you can carriage return and flush a write statement in Fortran. 我一直想知道您是否可以在Fortran中回车并刷新一条写语句。 In Python/C++ you can '/r' then flush the stream. 在Python / C ++中,您可以'/r'然后刷新流。

How can I do this in Fortran? 如何在Fortran中做到这一点?

A carriage-return is inserted by default at the end of a write statement, or explicitly using the ADVANCE specifier: 默认情况下,在写语句的末尾插入回车符,或者使用ADVANCE说明符显式插入回车符:

write(unit , '(A)') 'Hello World'
write(unit , '(A)' , ADVANCE = 'YES') 'Hello World'
write(unit , '(A)' , ADVANCE = 'YES') '-'

The result of the preceding three statements is: 前三个语句的结果是:

Hello World
Hello World
-

Alternatively, the carriage-return may be suppressed by specifying ADVANCE='NO': 或者,可以通过指定ADVANCE ='NO'来抑制回车:

write(unit , '(A)' , ADVANCE = 'NO') 'Hello World'
write(unit , '(A)' , ADVANCE = 'NO') 'Hello World'
write(unit , '(A)' , ADVANCE = 'NO') '-'

Which yields: 产生:

Hello WorldHello World-

To flush in Fortran90, close the file and reopen. 要在Fortran90中刷新,请关闭文件并重新打开。 Specific compilers and/or newer versions of the Fortran standard offer FLUSH as an intrinsic, but closing the file will always have the effect of flushing regardless of your Fortran version. 特定的编译器和/或更高版本的Fortran标准提供了FLUSH作为内在函数,但是无论您使用的是哪个Fortran版本,关闭文件都将始终具有刷新的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM