writeOptions

Sets or retrieves an option for printing a matrix.

Synopsis

writeOptions (option, optionValue)

Required Arguments

int option (Input)
Option giving the type of the printing attribute to set or retrieve.
option for Setting option for Retrieving Attribute Description
SET_DEFAULTS   Use the default settings for all parameters
SET_CENTERING GET_CENTERING Horizontal centering
SET_ROW_WRAP GET_ROW_WRAP Row wrapping
SET_PAGING GET_PAGING Paging
SET_NAN_CHAR GET_NAN_CHAR Method for printing NaN (not a number)
SET_TITLE_PAGE GET_TITLE_PAGE Whether or not titles appear on each page
SET_FORMAT GET_FORMAT Default format for real and complex numbers
int optionValue (Input, if option is to be set; Output, otherwise)
The value of the option attribute selected by option. The values to be used when setting attributes are described in a table in the description section.

Description

The function writeOptions allows the user to set or retrieve an option for printing a matrix. Options controlled by writeOptions are horizontal centering, method for printing large matrices, paging, method for printing in NaN (not a number), method for printing titles, and the default format for real and complex numbers. (NaN can be retrieved by function machine.)

The values that may be used for the attributes are as follows:

Option Value Meaning
CENTERING 0 Matrix is left justified.
1 Matrix is centered.
ROW_WRAP 0 A complete row is printed before the next row is printed. Wrapping is used if necessary.
m

Here m is a positive integer. Let \(n_1\) be the maximum number of columns that fit across the page, as determined by the widths in the conversion specifications starting with column 1. First, columns 1 through \(n_1\) are printed for rows 1 through m. Let \(n_2\) be the maximum number of columns that fit across the page, starting with column

\(n_1+1\). Second, columns \(n_1+1\) through \(n_1+n_2\) are printed for rows 1 through m. This continues until the last columns are printed for rows 1 through m. Printing continues in this fashion for the next m rows, etc.

PAGING -2 No paging occurs.
-1 Paging is on. Every invocation of a writeMatrix function begins on a new page, and paging occurs within each invocation as is needed.
0 Paging is on. The first invocation of a writeMatrix function begins on a new page, and subsequent paging occurs as is needed. Paging occurs in the second and all subsequent calls to a writeMatrix function only as needed.
k Turn paging on and set the number of lines printed on the current page to k lines. If k is greater than or equal to the page length, then the first invocation of a writeMatrix function begins on a new page. In any case, subsequent paging occurs as is needed.
NAN_CHAR 0 … … … . is printed for NaN.
1 A blank field is printed for NaN.
TITLE_PAGE 0 Title appears only on first page.
1 Title appears on the first page and all continuation pages.
FORMAT 0 Format is “%10.4x”.
1 Format is “%12.6w”.
2 Format is “%22.5e”.

The w conversion character used by the FORMAT option is a special conversion character that can be used to automatically select a pretty C conversion specification ending in either e, f, or d. The conversion specification ending with w is specified as “%n.dw”. Here, n is the field width, and d is the number of significant digits generally printed.

The function writeOptions can be invoked repeatedly before using a writeMatrix function to print a matrix. The matrix printing functions retrieve the values set by writeOptions to determine the printing options. It is not necessary to call writeOptions if a default value of a printing option is desired. The defaults are as follows:

Option Default Value Description
CENTERING 0 Left justified
ROW_WRAP 1000 Lines before wrapping
PAGING -2 No paging
NAN_CHAR 0 … … … … . .
TITLE_PAGE 0 Title appears only on the first page
FORMAT 0 %10.4w

Example

The following example illustrates the effect of writeOptions when printing a 3 × 4 real matrix A with PyIMSL function writeMatrix, where \(a_{ij}=i+j/10\). The first call to writeOptions sets horizontal centering so that the matrix is printed centered horizontally on the page. In the next invocation of writeMatrix, the left-justification option has been set via function writeOptions, so the matrix is left justified when printed.

from numpy import *
from pyimsl.math.writeMatrix import writeMatrix
from pyimsl.math.writeOptions import writeOptions, SET_CENTERING

nra = 4
nca = 3
a = zeros((nra, nca), dtype='double')
for i in range(0, nra):
    for j in range(0, nca):
        a[i, j] = (i + 1) + (j + 1) / 10.0

writeOptions(SET_CENTERING, 1)
writeMatrix("a", a)

writeOptions(SET_CENTERING, 0)
writeMatrix("a", a)

Output

 
                                       a
                                1            2            3
                   1          1.1          1.2          1.3
                   2          2.1          2.2          2.3
                   3          3.1          3.2          3.3
                   4          4.1          4.2          4.3
 
                    a
             1            2            3
1          1.1          1.2          1.3
2          2.1          2.2          2.3
3          3.1          3.2          3.3
4          4.1          4.2          4.3