The Q edit descriptor gets the length of an input record or the remaining portion of it that is unread. @ It gets the number of characters remaining to be read from the current record.
demo% cat qed1.f * qed1.f Q edit descriptor (real & string) CHARACTER CVECT(80)*1 OPEN ( UNIT=4, FILE='qed1.data' ) READ ( 4, 1 ) R, L, ( CVECT(I), I=1,L ) 1 FORMAT ( F4.2, Q, 80 A1 ) WRITE ( *, 2 ) R, L, '"', (CVECT(I),I=1,L), '"' 2 FORMAT ( 1X, F7.2, 1X, I2, 1X, 80A1 ) END demo% cat qed1.data 8.10qwerty demo% f77 qed1.f -o qed1 qed1.f: MAIN: demo% qed1 8.10 6 "qwerty" demo%
The above program reads a field into the variable R, then reads the number of characters remaining after that field into L, then reads L characters into CVECT. Q as the nth edit descriptor matches with L as the nth element in the READ list.
demo% cat qed2.f CHARACTER CVECT(80)*1 OPEN ( UNIT=4, FILE='qed2.data' ) READ ( 4, 1 ) L, ( CVECT(I), I=1,L ) 1 FORMAT ( Q, 80A1 ) WRITE ( *, 2 ) L, '"', (CVECT(I),I=1,L), '"' 2 FORMAT ( 1X, I2, 1X, 80A1 ) END demo% cat qed2.data qwerty demo% f77 qed2.f -o qed2 qed2.f: MAIN: demo% qed2 6 "qwerty" demo%
The above example gets the length of the input record. With the whole input string and its length, you can then parse it yourself.
Several restrictions on the Q edit descriptor apply:
The list element Q corresponds to must be of INTEGER or LOGICAL data type.
Q does strictly a character count. It gets the number of characters remaining in the input record, and does not get the number of integers or reals or anything else.
The Q edit descriptor cannot be applied for pipe files, as Q edit requires that the file be rereadable.
This descriptor operates on files and stdin (terminal) input.
This descriptor is ignored for output.