Fortran 90中的自动宽度整数描述符 [英] Automatic width integer descriptor in fortran 90

查看:414
本文介绍了Fortran 90中的自动宽度整数描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在fortran 90中使用自动整数宽度描述符。我提到输出格式:gfortran中的空白太多
这个问题说我可以使用 I0 F0, 0 代表自动宽度。
这里是我的示例代码(符合GNU Fortran编译器):

 程序主要
IMPLICIT NONE

INTEGER :: i
REAL :: j

WRITE(*,*)'输入整数'
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运行时错误:



格式需要的正宽度我是否理解了自动宽度描述符?我应该使用什么样的选项?

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



从Fortran 2008,10.7.2.1(6) :


在I,B,O,Z,F和G编辑的输出上,字段宽度w的指定值可以为零。在这种情况下,处理器选择不会导致填充星号的字段的最小正实际字段宽度。

没有明确的替代方案可以替代 I0 作为输入,但是作为agentp注释,列表控制输入( read(*,*))很简单,适合您的需求。如果不是,那么你可以看看更多的一般解析行读取作为字符变量。您可以查找后者的示例。


I wanted to use automatic integer width descriptor in fortran 90. I referred to Output formatting: too much whitespace in gfortran This question says that I can use I0 and F0,0 for "auto" width. Here is my sample code (complied with GNU Fortran Compiler):

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

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

Am I mis-understanding the auto width descriptor? What option should I use?

解决方案

Using I0 to specify a minimal field width is allowed for output. For input, I0 is not allowed.

From Fortran 2008, 10.7.2.1 (6) (my emphasis):

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.

There is no clear alternative to I0 for input, but as agentp comments, list-directed input (read(*,*)) is simple and may well be suitable for your needs. If it isn't then you can look into more general parsing of lines read in as character variables. You can find examples of this latter.

这篇关于Fortran 90中的自动宽度整数描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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