This command displays character strings and variables in specified formats,
thus producing tables of results.
The simplest form of PRINTF is PRINTF 'string'. This prints the specified
string. Examples are:
You can print the values of expressions by specifying in the character string (1) that expression is to be evaluated and its value printed, and (2) the format for the printing of the variable. The character % in the string does the job. It tells that an expression is to be evaluated and printed where the % appears. The rest of the word following the % is used to specify the format of the string. The format specifiers are the same as they are in FORTRAN. ANY valid FORTRAN specifier appropriate for displaying numeric values may be used. You can specify multiple variables with the same format specification by putting the number of variables for which you wish to use the specifier for before the format specifier.
For example, if you want to print a single floating point variable with a field width of 9 characters with 3 after the decimal point, use %f9.3, and give one argument after the format specifier. If you have 5 variables which you want all printed in this format, you can use either '%f9.3 %f9.3 %f9.3 %f9.3 %f9.3', or '%5f9.3'.
For users familiar with C, you can also use the %d specifier for an integer (as well as %i); note, however, that the width/precision specification comes after the format specifier, not before it (e.g., arguments to be printed with the desired format.
Examples:
Suppose we have the variables A with value 1.0 and PI with value
3.14159. Then
Note that spaces between % specifiers are printed. The output of PRINTF
can be redirected.
To force a new line when printing, use the pattern \n
in the format
statement (the newline character). An example is:
See the section SUBSTITUTE (type 'HELP SUBSTITUTE' if you are on a terminal) for instructions on printing string variables.