Automatic integer width descriptor in fortran 90

I wanted to use the automatic handle width integer in fortran 90. I referred to format the output: too many gaps in gfortran This question says that I can use I0, and F0,0for the "automatic" width. Here is my sample code (corresponds to the 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

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

Am I misunderstanding the auto-width handle? Which option to use?

+4
source share
2 answers

Use I0to indicate the minimum field width is allowed for output. For input is I0not allowed.

Fortran 2008, 10.7.2.1 (6) ( ):

, I, B, O, Z, F G, w . , . w .

I0, p - (read(*,*)) . , , . .

+4

@francescalus @agentp, , , . 100 FORMAT (I0) .

format read, . 8 , READ(*,'(I8)') i.

, , :

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
0

All Articles