Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
27082 Discussions

Is there a standard-compliant alternative to the Q control edit descriptor?

OP1
New Contributor I
191 Views

The Q control edit descriptor is a nifty feature... but it's not standard-compliant.

A standard-compliant workaround I can think of is to use a loop of non-advancing IO read statements with EOR to catch the end of the record... but this is rather unwieldy...

Any other suggestions?

PROGRAM P
IMPLICIT NONE
INTEGER :: I
CHARACTER(LEN=1) :: S
OPEN(FILE='Test.txt',UNIT=10,FORM='FORMATTED',STATUS='REPLACE')
WRITE(10,FMT='(A10)') 'A        1'
REWIND(10)
READ(10,'(A1,Q)') S,I
WRITE(*,'(A,I4)') S,I
CLOSE(10)
END PROGRAM P

 

0 Kudos
1 Reply
Steve_Lionel
Black Belt Retired Employee
176 Views

I am not sure what you really want to do here, but I'd lean towards this approach:

PROGRAM P
IMPLICIT NONE
INTEGER :: I
CHARACTER(LEN=1) :: S
CHARACTER(100) :: LINE
OPEN(FILE='Test.txt',UNIT=10,FORM='FORMATTED',STATUS='REPLACE')
WRITE(10,FMT='(A10)') 'A        1'
REWIND(10)
READ (10,'(A)') LINE
READ(LINE,'(A1)') S
I = LEN_TRIM(LINE)-1
WRITE(*,'(A,I4)') S,I
CLOSE(10)
END PROGRAM P
 
Reply