The print command looks like this:

The easiest way to do print is to put * in place of a detailed format specification. In this case, the formatting is done automatically. Example:

A specific format can be added. A format specification is a string and the actual format is enclosed in parentheses. This example contains a11 as the format for the string literal 'My name is ' and a8 for the variable name:

The format specification is a string, so it starts and ends with quotes: '(...)'. The actual format is the part enclosed in parentheses, i.e. the ... part. In the example

'(a11,a8)' is the format specification
a11,a8 is the format

Different edit descriptors are used for different types of variables. The edit descriptor may be followed by a number that indicates the length of the output field. A short list of output descriptors is given here:

Short list of output descriptors.
Variable Type Edit Descriptor Example Comment
string a a11 A string is printed into an 11 character wide output field
string a a The length of the output field is the length of the string
integer i i4 An integer is printed into a 4 character wide output field
integer i i INVALID! The length has to be specified
real f f12.5 A real is printed into a 12 character wide output field. The 5 after the decimal point means that 5 decimal digits of the floating point number are to be printed. No exponent is used with this edit descriptor
real e e12.5 A real is printed with an exponent
real es es12.5 Same as e, but number does not start with a zero
logical l l2 T (true) or F (false) is printed into a 2 character wide output field
whitespace x x Add a blank character
whitespace x 4x Four whitespace characters are added

Note that if a printed item is shorter than the length of its output field, it will be right justified within the field; if the printed item is longer, it will be truncated, or the field will be filled with stars (*). Similarly, the decimal parts of reals will be zero-padded or rounded to conform to the specified number of decimal places.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement