Automatic width integer descriptor in fortran 90

◇◆丶佛笑我妖孽 提交于 2019-12-05 18:09:08
francescalus

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.

In addition to @francescalus 's and @agentp 's answers, be aware that format labels, e.g. 100 FORMAT (I0) should be avoided.

Instead, simply include the format within the read, e.g. if you wanted to read an integer that is up to 8 characters wide, READ(*,'(I8)') i.

If you have a very lengthy format or a format that you re-use in several lines of code, save it in a character string:

character :: form*64
real      :: r1, r2

form = '(es13.6)'  ! e.g. 9.123456e+001

.
.
.

WRITE (*,*) 'Enter a number'
READ (*, form) r1
WRITE (*,*) 'Enter another number'
READ (*, form) r2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!