FORTRAN Tutorials – Input and Output

Home Computational Physics FORTRAN FORTRAN Tutorials – Input and Output


Input and Output
FORTRAN provides a great deal of power and flexibility in the reading of data and printing of results. And for the experienced programmer this power and flexibility is needed, for a heavy part of the total programming task revolves around input and output. For our purposes now we need only the minimum that will permit us to write complete programs. We present here accordingly a small subset of the total FORTRAN input/output capability.
READ
Used to read the data from the specific device, such as Keyboard. We also reference a FORMAT statement that describes to the program how the data values are written. The READ-FORMAT combination might be as follows:
READ

FORMAT statement, which tell the program how the data values are entered from the keyboard and whether the variables are integer or real. In “F6.2” the “F” means that the value is an real; the 6 means field contains six columns. The 2 means number of decimal places in this case it is two.

Alternative way to read the data with out FORMAT statement
READ (5,*) AKJ


WRITE
Use to write the data to the screen or printer.

WRITE
Alternative way to write without FORMAT statement.
WRITE (6,*) AKJ


FORMAT Sets the format in which data is written to or read. FORMAT statements must be labeled.
10 FORMAT (F12.6)

The table below summarizes the formatting characters.
DescriptorUse
IInteger Values
ZHexadecimal values
FReal values
EReal values with exponents
GReal values, extended range
DDouble-precision real values
LLogical values
ACharacter values