gpt4 book ai didi

fortran - Fortran 输入的自动宽度整数描述符

转载 作者:行者123 更新时间:2023-12-02 16:37:34 26 4
gpt4 key购买 nike

我想在 Fortran 中使用自动整数宽度描述符。我提到了Output formatting: too much whitespace in gfortran

这个问题说我可以使用 I0F0.0 作为“自动”宽度。这是我的示例代码(符合 GNU Fortran 编译器):

PROGRAM MAIN
IMPLICIT NONE

INTEGER :: i
REAL :: j

WRITE (*,*) 'Enter integer'
READ (*,100) i
100 FORMAT (I0)

WRITE (*,*) 'Enter real'
READ (*,110) j
110 FORMAT (F0.0)

WRITE (*,100) 'Integer = ',i
WRITE (*,110) 'Real = ',j

END PROGRAM

存在运行时错误

(unit = 5, file = 'stdin')
Fortran runtime error: Positive width required in format

我是否误解了自动宽度描述符?我应该使用什么选项?

最佳答案

使用I0指定允许输出的最小字段宽度。对于输入,不允许 I0

来自 Fortran 2008,10.7.2.1 (6)(我的重点):

On output, with I, B, O, Z, F, and G editing, the specified value of the field width w may be zero. In such cases, the processor selects the smallest positive actual field width that does not result in a field filled with asterisks. The specified value of w shall not be zero on input.

对于输入,没有明确的替代 I0 的方法,但作为 agentp 注释,列表定向输入 (read(*,*)) 很简单,很可能是适合您的需求。如果不是,那么您可以研究作为字符变量读入的行的更一般的解析。您可以find后者的例子。

关于fortran - Fortran 输入的自动宽度整数描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29572830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com