Q (Character Count) Editing (IBM extension)

Purpose

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.

Syntax

Rules

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.

The character count Q edit descriptor can read records of the following file types and access modes:
  • Formatted sequential external files. A record of this file type is terminated by a new-line character. Records in the same file have different lengths.
  • Formatted sequential internal nonarray files. The record length is the length of the scalar character variable.
  • Formatted sequential internal array files. The record length is the length of an element in the character array.
  • Formatted direct external files. The record length is the length specified by the RECL= specifier in the OPEN statement.
  • Formatted stream external files. A record of this file type is terminated by a new-line character. Records in the same file have different lengths.

In an output operation, the character count Q edit descriptor is ignored. The corresponding output item is skipped.

Examples

@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