The character count Q edit descriptor returns the number of characters remaining in an input record. The result can be used to control the rest of the input.
There also exists the extended precision Q edit descriptor. By default, XL Fortran only recognizes the extended precision Q edit descriptor described earlier. See E, D, and Q (Extended Precision) Editing for more information. To enable both Q edit descriptors, you must specify the -qqcount compiler option.
When you specify the -qqcount compiler option, the compiler will distinguish between the two Q edit descriptors by the way the Q edit descriptor is used. If only a solitary Q is found, the compiler will interpret it as the character count Q edit descriptor. If Qw. or Qw.d is encountered, XL Fortran will interpret it as the extended precision Q edit descriptor. You should use correct format specifications with the proper separators to ensure that XL Fortran correctly interprets which Q edit descriptor you specified.
The value returned as a result of the character count Q edit descriptor depends on the length of the input record and on the current character position in that record. The value is returned into a scalar integer variable on the READ statement whose position corresponds to the position of the character count Q edit descriptor in the FORMAT statement.
In an output operation, the character count Q edit descriptor is ignored. The corresponding output item is skipped.
@PROCESS QCOUNT
CHARACTER(50) BUF
INTEGER(4) NBYTES
CHARACTER(60) STRING
...
BUF = 'This string is 29 bytes long.'
READ( BUF, FMT='(Q)' ) NBYTES
WRITE( *,* ) NBYTES
! NBYTES equals 50 because the buffer BUF is 50 bytes long.
READ(*,20) NBYTES, STRING
20 FORMAT(Q,A)
! NBYTES will equal the number of characters entered by the user.
END