Fortran Lecture 4
Fortran Lecture 4
Integer values are right justified in their fields. This means that integers
are printed out so that the last digit of the integer occupies the
rightmost column of the field.
The I descriptor has the general form
rIw or rIw.m
where r, w, and m have the meanings given in the above table.
Example
INTEGER :: x = 12345
PRINT’(I5)’, x !integer with field width = 5, 12345 is the output
If the integer is too large to fit into the field in which it is to be printed,
then the field is filled with asterisk.
PRINT’(I3)’, x !integer with field width = 3, **** is the output
Formatted Output 3/7
Real data can be printed in exponential form using the E descriptor. Real
values displayed by E descriptor are normalized to a range between 0.1
and 1.0. For example 4.096 x 103 will appears as 0.4096E+04 using the
E descriptor
The E descriptor has the general form
rEw.d
The width w of E descriptor must satisfied the expression
w ≥ d +6 where d has the same meaning given in the table
Example:
REAL :: res = 23456
PRINT’(E11.5)’, res !output = 0.23456E+05
PRINT’(E13.5)’, res !output = 0.23456E+05, check the position
PRINT’(E8.2)’, res !output = 0.23E+05
Formatted Output 5/7
The X Descriptor is used to add one or more blanks space between two
values on the output line.
The X Descriptor has the form of a positive integer followed by X:
nX
where n is the number of blanks to insert.
Example:
CHARACTER(LEN = 7) :: dept = ’physics’
REAL :: ans = 2345.6
PRINT’(ES8.2,A7)’, ans, dept ! output = 2.35E+03physics
PRINT’(ES8.2,2X,A7)’, ans, dept ! output = 2.35E+03 physics
where 2X create two blank spaces between ES8.2 and A7 outputs