next up previous contents index
Next: Input/Output Statements and Keywords Up: Input/Output Facilities Previous: List-directed Input

Carriage-Control and Printing


Although a format specification allows complete control over the layout of each line of text, it does not include any way of controlling pagination. The only way to do this is by using a unique and extraordinary mechanism dating back to the earliest days of Fortran. Even if you are not concerned with pagination you still need to know about the carriage-control convention since it is liable to affect every text file you produce.

Whenever formatted output is sent to a ``printer", the first character of every record is removed and used to control the vertical spacing. This carriage-control character must be one of the four listed in the the table below.

Character Vertical spacing before printing
blank Advance to next line
0 Advance two lines
1 Advance to top of next page
+ No advance, i.e. print on same line

An empty record is treated as if it started with a single blank. For example, these statements start a new page with a page number at the top and a title on the third line:

      WRITE(LP, 55) NUMBER, 'Report and Accounts' 
55    FORMAT('1PAGE', I4, /, '0', A)
This carriage-control convention is an absurd relic which causes a multitude of problems in practice. Firstly, systems differ on what they call a ``printer": it may or may not apply to visual display terminals or to text initially saved on a disc file and later printed out. Some operating systems have a special file type for Fortran formatted output which is treated differently by printers (and terminals). Others have been known to chop off the first character of all files sent to the system printer so that special utilities are needed to print ordinary text.

To be on the safe side you should always provide an explicit carriage-control character at the start of each format specification and after each slash. Special care is needed in formats which use forced reversion. Normal single spacing is obtained with a blank, conveniently produced by the 1X edit descriptor. If you forget and accidentally print a number at the start of each record with a leading digit 1 then each record will start a new page.

The effect of + as a carriage-control character would be more useful if its effects were more predictable. Some devices over-print the previous record (allowing the formation of composite characters like ), others append to it, and some (including many visual display terminals) erase what was there before. In portable software there is no alternative but to ignore the + case altogether.

Standard Fortran can only use the four carriage-control characters listed in the table but many systems use other symbols for special formatting purposes, such as setting vertical spacing, changing fonts, and so on. One extension which is widely available is the use of the currency symbol $ to suppress carriage-return at the end of the line. This can be useful when producing terminal prompts as it allows the reply to be entered on the same line. There is, unfortunately, no way of doing this in Standard Fortran.

The rules for list-directed output ensure that the lines are single-spaced by requiring at least one blank at the start of every record.

next up previous contents index
Next: Input/Output Statements and Keywords Up: Input/Output Facilities Previous: List-directed Input
Helen Rowlands