NAG Fortran Compiler, Release 7.2: Input/output

Navigation: Previous Up Next

## 11.4 Input/output

- [7.0] The `RECL=` specifier in an `INQUIRE` statement for an unconnected unit or file now assigns the value −1 to the variable. For a unit or file connected with `ACCESS='STREAM'`, it assigns the value −2 to the variable. Under previous Fortran standards, the variable became undefined.
- [7.1] The `SIZE=` specifier can be used in a `READ` statement without `ADVANCE='NO'`, that is, in a `READ` statement with no `ADVANCE=` specifier, or one with an explicit `ADVANCE='YES'`. For example,

          Character(65536) buf
          Integer nc
          Read(*,'(A)',Size=nc) buf
          Print *,'The number of characters on that line was',nc

  Note that `SIZE=` is not permitted with list-directed or namelist formatting; that would be pointless, as there are no edit descriptors with such formatting and thus no characters to be counted by `SIZE=`.
- [7.2] The `E0` exponent width specifier can be used on all edit descriptors that allow the exponent width to be specified (thus `E`, `EN` et al, but not `D`). This specifies formatting with the minimal width for the exponent. For example,

             Print '(7X,3ES10.2E0)', 1.23, 4.56E24, 7.89D101

  will print

                1.23E+0  4.56E+24 7.89E+101

- [7.2] The `E`, `D`, `EN` and `ES` edit descriptors may have a width of zero on output. This provides minimal width editing similarly to the `I` and other edit descriptors; that is, the processor chooses the smallest value for the width w that does not result in the field being filled with asterisks. This means that leading blanks will be suppressed, and for `E` and `D`, when the scale factor is less than or equal to zero, the optional zero before the decimal symbol is suppressed.

  For example, printing 12.3 with the formats shown below will display the results below with no leading or trailing blanks.

  | `E0.4` | `.1230E+02`
  | `E0.4E3` | `.1230E+002`
  | `1PE0.4` | `1.2300E+01`
  | `EN0.4` | `12.3000E+00`
  | `ES0.4` | `1.2300E+01`
  | `E0.4E0` | `.1230E+2`

  Note that field width has no effect on the format of the exponent; that is, to print a number in the smallest width requires use of exponent width zero as well (as shown in the last example above).

  There is no means of eliminating trailing zeroes in the mantissa part for these edit descriptors (though there is for the new `EX` edit descriptor).

- [7.2] The `G0.d` edit descriptor is permitted for types Integer, Logical, and Character; in Fortran 2008, this was an i/o error. In Fortran 2018 it has the same effect as `I0` for Integer, `L1` for Logical, and `A` for Character. For example,

             Print '(7X,"start:",3G0.17,":end")', 123, .True., 'ok'

  will print

             start:123Tok:end

- [7.2] The new edit descriptors `EXw.d` and `EXw.dEe` can be used for output of floating-point numbers with a hexadecimal significand. The format is

  [ s ] `0X` x0 `.` x1x2… exponent

  where s is an optional plus or minus sign (+ or −), each xi is a hexadecimal digit (`0`…`9` or `A`…`F`), and exponent is the binary exponent (power of two) expressed in decimal, with the format `P` s z1…zn, where if the optional `E`e appears, n is equal to e, and otherwise is the minimum number of digits needed to represent the exponent. If the exponent is equal to zero, the sign s is a plus sign.

  If the number of digits d is zero, the number of mantissa digits xi produced is the smallest number that represents the internal value exactly. Note that d must not be zero if the radix of the internal value is not a power of two.

  For input, the effect of the `EX` edit descriptor is identical to that of the `F` edit descriptor.

  Note that the value of the initial hexadecimal digit is not standardised, apart from being non-zero. Thus, depending on the compiler, writing the value 1.0 in `EX0.1` might produce `0X1.0P+0`, `0X2.0P-1`, `0X4.0P-2`, or `0X8.0P-3`. The NAG Fortran Compiler always shifts the mantissa so that the most significant bit is set, thus will output `0X8.0P-3` in this case.

- [7.2] Input of floating-point numbers with list-directed, namelist, and explicit formatting (e.g. the `F` edit descriptor) accepts input values in hexadecimal-significand form. That is, the form produced by the `EX` edit descriptor. Note that a hexadecimal-significand value always begins with an optional sign followed by the digit zero and the letter `X`; that is, `+0X`, `-0X`, or `0X`, thus there is no ambiguity.

  For example, reading ‘`-0XA.P-3`’ will produce the value `-1.25`.

  As usual for numeric input, lowercase input is treated the same as upper case; thus `-0xa.p-3` produces the same value as `-0XA.P-3`.