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.
Keyword for Setting Keyword for Retrieving Attribute Description
SET_DEFAULTS   uses 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
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)
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

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 NaN, method for printing titles, and the default format for real and complex numbers. (NaN can be retrieved by functions machine and machine (Chapter 15, Utilities).

The following values can be used for the attributes:

Keyword Value Meaning
CENTERING

0

1

Matrix is left justified.

Matrix is centered.

ROW_WRAP

0

m

Complete row is printed before the next row is printed. Wrapping is used if necessary.

Here, m is a positive integer. Let n1 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 n1 are printed for rows 1 through m. Let n2 be the maximum number of columns that fit across the page, starting with column n1+1. Second, columns n1+1 through n1+n2 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

-1

0

k

No paging occurs.

Paging is on. Every invocation of an function writeMatrix begins on a new page, and paging occurs within each invocation as is needed.

Paging is on. The first invocation of an write_f_matrix function begins on a new page, and subsequent paging occurs as is needed. Paging occurs in the second and all subsequent calls to an writeMatrix function only as needed.

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 an writeMatrix function begins on a new page. In any case, subsequent paging occurs as is needed.

NAN_CHAR

0

1

… … … . is printed for NaN.

A blank field is printed for NaN.

TITLE_PAGE

0

1

Title appears only on first page.

Title appears on the first page and all continuation pages.

FORMAT

0

1

2

Format is "%10.4x".

Format is "%12.6w".

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.

Function writeOptions can be invoked repeatedly before using a function writeMatrix 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:

Keyword Default Value Meaning
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 function writeMatrix, where aij=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 by function writeOptions so the matrix is left justified when printed.

from numpy import *
from pyimsl.stat.page import page, SET_PAGE_WIDTH, GET_PAGE_WIDTH, SET_PAGE_LENGTH, GET_PAGE_LENGTH
from pyimsl.stat.writeOptions import writeOptions, SET_CENTERING, GET_CENTERING
from pyimsl.stat.writeMatrix import writeMatrix

nra = 4
nca = 3
a = zeros((nra, nca))
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