Lecture 7 – Formatted Input/Output
The first topic for today is formatted input/output in Fortran.
Last time, we looked at
how Fortran reads and writes external files by replacing that first asterisk with a unit
The second asterisk is the formatting element, and now we’re going to learn
about the difference between unformatted and formatted output.
double precision b
write(*,*) ' '
The screen output looks like:
45318.591378 9830 character
********** *** chara
This program writes the same three variables to the screen in four different ways, first
unformatted and then formatted in three different ways.
Unformatted is quick and easy to
use, but it has some distinct disadvantages.
It truncates the real number after four
decimal places and rounds up, and it doesn’t know to insert a space at the beginning of
the character string.
When writing tabular data to an external file, you will usually want