Printer Control
Traditionally Fortran provides a unique way for controlling printers.
Except that your output are always sent to files, you need to know how
Fortran controls printers.
As discussed in edit descriptors, the values of variables and expressions
of a WRITE statement are evaluated in the given order and
based on the the width of field (i.e., the value of w)
an output line is composed. In the good old days, printers have 133 positions
per line and the content in the first position
is for printer control. Nowadays, the length of a line is no
more an issue; but, the content in the first position of an output line
is still for printer control. Therefore, when you want to print your
result with a printer, any printer, you should remember the following
figure:
The way Fortran prints your information is line-oriented.
More precisely, the information of each edit
descriptor are not printed directly to a printer.
Instead, they are "printed" to a buffer line.
Once the construction of that buffer
line completes (e.g., all values are processed), this buffer line
is sent to printer and based on the content in the first position the
printer advances to next line, advances two lines, jumps to the first line
of the next page, or stays on the same line. Then, the contents from
position 2 to the end of that line are printed. As a result, the content
of the first position is
printed!
As mentioned above, there are four printer controls, each of which is
presented by a character:
Printer Control Character |
Effect |
space |
Advance to the next line
printing |
0 |
Advance two lines
printing |
1 |
Advance to the first line of the next page
printing |
+ |
No advancing, print on the current line
(overprinting)
|
Let us discuss all four printer control characters in some detail:
- If the first position is a space, then the printer will
advance to the next line and print. In the following example,
constant 123 is printed using edit descriptor I4. Its
output consists of four positions containing a space, 1, 2 and 3.
Therefore, the printer control character is a space and the
printer advances to the next line and prints 1, 2 and 3 in the
first, second and third positions. After printing this line,
the printer stops there.
In the figure, prev indicates the previous line.
- If the first character is a 0, then the printer will
advance two lines before printing as shown below:
The above example uses I4.4 to print 123. The output
consists of four characters 0, 1, 2 and 3. Therefore, the
printer control character is 0. The printer advances two
lines and prints 1, 2 and 3 in the first, second and third
positions. Since the printer advances two lines before printing,
there is a blank line between the previously printed line and the
line containing 1, 2 and 3.
- If the first character is a 1, then the printer will
skip to the first line of the next page and print from there.
The above uses uses I3 to print 123. The output consists
of three characters 1, 2 and 3 in the first positions.
Since the first position has a character 1, the printer skips to
the top of the next page and prints 2 and 3 in the first two
positions of the first line.
WARNING:
Avoid using the first position by putting a space there.
In this way, the printer always advances to the next line.
Otherwise, some unpleasant situations may occur
(e.g., printing too many pages).
|
- If the first character is a +, then the printer will
not advance and print the
information on the same line.
Therefore, the information on this line will print over the
information on the previously printed line.
The above figure shows the situation before the
WRITE statement prints any information. The previously
printed line contains three Os.
Now the WRITE statement prints +*/. Since the first
character is a +, the printer will not advance and the
remaining two characters * and / will be printed on
the the previously printed line.
PLEASE ALWAYS KEEP IN MIND:
Not all compilers/systems are created equal and the
Fortran standard does not mandate it. When you
print to screen using formats, some systems print every
characters, including the first one (i.e., the printer
control character), while other systems may consider the
screen output as identical to the printer output and,
consequently, printer control characters will be used to
advance lines or clear the screen (skipping to the next page).
So, you should check your local system.
|