FORTRAN 77 Language Reference

### Editing REAL Data (D, E, F, G)

The D, E, F, and G specifiers are for decimal real data items.

#### D Editing

The D specifier is for the exponential form of decimal double-precision items. The general form is

```D [ w [ .d
] ]
```

:

The D w and D w.d edit specifiers indicate that the field to be edited occupies w positions. d indicates that the fractional part of the number (the part to the right of the decimal point) has d digits. However, if the input datum contains a decimal point, that decimal point overrides the d value.

On input, the specified list item becomes defined with a real datum. On output, the specified list item must be defined as a real datum.

In an output statement, the D edit descriptor does the same thing as the E edit descriptor, except that a D is used in place of an E. The output field for the D w.d edit specifier has the width w. The value is right-justified in that field. The field consists of zero or more leading blanks followed by either a minus if the value is negative, or an optional plus, followed by the magnitude of the value of the list item rounded to d decimal digits.

w must allow for a minus sign, at least one digit to the left of the decimal point, the decimal point, and d digits to the right of the decimal point. Therefore, it must be the case that w d+3.

Example: Real input with D editing in the program, Dinp.f:

```	CHARACTER LINE*24 / '12345678 23.5678 .345678' /
READ( LINE, '( D8.3, D8.3, D8.3 )') R, S, T
PRINT '( D10.3, D11.4, D13.6 )', R, S, T
END ```

The above program displays:

`0.123D+05 0.2357D+02 0.345678D+00 `

In the above example, the first input data item has no decimal point, so D8.3 determines the decimal point. The other input data items have decimal points, so those decimal points override the D edit descriptor as far as decimal points are concerned.

Example: Real output with D editing in the program Dout.f:

```	R = 1234.678
PRINT 1, R, R, R
1	FORMAT( D9.3 / D8.4 / D13.4 )
END```

The above program displays:

```0.123D+04
********
¤¤¤0.1235D+04 ```

In the above example, the second printed line is asterisks because the D8.4 does not allow for the sign; in the third printed line the D13.4 results in three leading blanks.

#### E Editing

The E specifier is for the exponential form of decimal real data items. The general form is:

```  E [ w
[ .d ] [
Ee ] ]
```

w indicates that the field to be edited occupies w positions.

d indicates that the fractional part of the number (the part to the right of the decimal point) has d digits. However, if the input datum contains a decimal point, that decimal point overrides the d value.

e indicates the number of digits in the exponent field. The default is 2.

The specified input/output list item must be of type real. On input, the specified list item becomes defined with a real datum. On output, the specified list item must be defined as a real datum.

The output field for the E w.d edit specifier has the width w. The value is right-justified in that field. The field consists of zero or more leading blanks followed by either a minus if the value is negative, or an optional plus, followed by a zero, a decimal point, the magnitude of the value of the list item rounded to d decimal digits, and an exponent.

For the form Ew.d:

• If | exponent | .le. 99, it has the form Enn or 0nn.

• If 99 .le. | exponent | .le. 999, it has the form nnn.

For the form Ew.dEe, if | exponent | .le. ( 10e ) - 1, then the exponent has the form nnn.

For the form Dw.d:

• If | exponent | .le. 99, it has the form Dnn or Enn or 0nn.

• If 99 £ | exponent | .le. 999, it has the form nnn.

n is any digit.

w need not allow for a minus sign, but must allow for a zero, the decimal point, and d digits to the right of the decimal point, and an exponent. Therefore, for nonnegative numbers, w .le. d+6; if e is present, then w .le. d+e+4. For negative numbers, w .le. d+7; if e is present, then w .le. d+e+5.

Example: Real input with E editing in the program, Einp.f:

```	CHARACTER L*40/'1234567E2 1234.67E-3 12.4567 '/
READ( L, '( E9.3, E12.3, E12.6 )') R, S, T
PRINT '( E15.6, E15.6, E15.7 )', R, S, T
END ```

The above program displays:

`¤¤¤0.123457E+06¤¤¤0.123467E+01¤¤0.1245670E+02 `

In the above example, the first input data item has no decimal point, so E9.3 determines the decimal point. The other input data items have decimal points, so those decimal points override the D edit descriptor as far as decimal points are concerned.

Example: Real output with E editing in the program Eout.f:

```	R = 1234.678
PRINT 1, R, R, R
1	FORMAT( E9.3 / E8.4 / E13.4 )
END ```

The above program displays:

```0.123E+04
********
¤¤¤0.1235E+04 ```

In the above example, E8.4 does not allow for the sign, so we get asterisks. Also, the extra wide field of the E13.4 results in three leading blanks.

Example: Real output with Ew.dEe editing in the program EwdEe.f:

```	REAL  X / 0.000789 /
WRITE(*,'( E13.3)') X
WRITE(*,'( E13.3E4)') X
WRITE(*,'( E13.3E5)') X
END```

The above program displays:

```¤¤¤¤0.789E-03
¤¤0.789E-0003
¤0.789E-00003```

#### F Editing

The F specifier is for decimal real data items. The general form is

```   F [ w [
.d ] ]
```

:

The Fw and Fw.d edit specifiers indicate that the field to be edited occupies w positions.

d indicates that the fractional part of the number (the part to the right of the decimal point) has d digits. However, if the input datum contains a decimal point, that decimal point overrides the d value.

The specified input/output list item must be of type real. On input, the specified list item becomes defined with a real datum. On output, the specified list item must be defined as a real datum.

The output field for the F w.d edit specifier has the width w. The value is right-justified in that field. The field consists of zero or more leading blanks followed by either a minus if the value is negative, or an optional plus, followed by the magnitude of the value of the list item rounded to d decimal digits.

w must allow for a minus sign, at least one digit to the left of the decimal point, the decimal point, and d digits to the right of the decimal point. Therefore, it must be the case that w.le.d+3.

Example: Real input with F editing in the program Finp.f:

```	CHARACTER LINE*24 / '12345678 23.5678 .345678' /
READ( LINE, '( F8.3, F8.3, F8.3 )') R, S, T
PRINT '( F9.3, F9.4, F9.6 )', R, S, T
END ```

The program displays:

`12345.678DD23.5678D0.345678`

In the above example, the first input data item has no decimal point, so F8.3 determines the decimal point. The other input data items have decimal points, so those decimal points override the F edit descriptor as far as decimal points are concerned.

Example: Real output with F editing in the program Fout.f:

```	R = 1234.678
PRINT 1, R, R, R
1	FORMAT( F9.3 / F8.4 / F13.4 )
END```

The above program displays:

```¤1234.678
********
¤¤¤¤1234.6780```

In the above example, F8.4 does not allow for the sign; F13.4 results in four leading blanks and one trailing zero.

#### G Editing

The G specifier is for decimal real data items. The general form is

G [ w [ .d ] ]

or:

G w.d E e

:

The D, E, F, and G edit specifiers interpret data in the same way.

The representation for output by the G edit descriptor depends on the magnitude of the internal datum. In the following table, N is the magnitude of the internal datum.

Range

Form

0.1 <= N < 1.0

1.0 <= N < 10.0

...

10(d-2) <= N <= 10(d-1)

10(d-1) <= N < 10d

F(w-4).d, n(¤)

F(w-4).(d-1), n(¤)

...

F(w-4).1, n(¤)

F(w-4).0, n(¤)

#### Commas in Formatted Input

If you are entering numeric data that is controlled by a fixed-column format, then you can use commas to override any exacting column restrictions.

Example: Format:

`	(I10, F20.10, I4) `

Using the above format reads the following record correctly:

`-345,.05e-3,12 `

The I/O system is just being more lenient than described in the FORTRAN Standard. In general, when doing a formatted read of noncharacter variables, commas override field lengths. More precisely, for the Iw, Fw.d, Ew.d[Ee], and Gw.d input fields, the field ends when w characters have been scanned, or a comma has been scanned, whichever occurs first. If it is a comma, the field consists of the characters up to, but not including, the comma; the next field begins with the character following the comma.