Functions and Variables for plain-text input and output (Maxima Manual)

Next: Functions and Variables for binary input and output, Previous: Introduction to numericalio, Up: numericalio [Contents][Index]

### 63.2 Functions and Variables for plain-text input and output

Function: read_matrix (S)
Function: read_matrix (S, M)
Function: read_matrix (S, separator_flag)
Function: read_matrix (S, M, separator_flag)

  `read_matrix(S)` reads the source S and returns its entire content as a matrix. The size of the matrix is inferred from the input data; each line of the file becomes one row of the matrix. If some lines have different lengths, `read_matrix` complains.

  `read_matrix(S, M)` read the source S into the matrix M, until M is full or the source is exhausted. Input data are read into the matrix in row-major order; the input need not have the same number of rows and columns as M.

  The source S may be a file name or a stream.

  The recognized values of separator_flag are `comma`, `pipe`, `semicolon`, and `space`. If separator_flag is not specified, the file is assumed space-delimited.

Function: read_array (S, A)
Function: read_array (S, A, separator_flag)

  Reads the source S into the array A, until A is full or the source is exhausted. Input data are read into the array in row-major order; the input need not conform to the dimensions of A.

  The source S may be a file name or a stream.

  The recognized values of separator_flag are `comma`, `pipe`, `semicolon`, and `space`. If separator_flag is not specified, the file is assumed space-delimited.

Function: read_hashed_array (S, A)
Function: read_hashed_array (S, A, separator_flag)

  Reads the source S and returns its entire content as a hashed array. The source S may be a file name or a stream.

  `read_hashed_array` treats the first item on each line as a hash key, and associates the remainder of the line (as a list) with the key. For example, the line `567 12 17 32 55` is equivalent to `A[567]: [12, 17, 32, 55]$`. Lines need not have the same numbers of elements.

  The recognized values of separator_flag are `comma`, `pipe`, `semicolon`, and `space`. If separator_flag is not specified, the file is assumed space-delimited.

Function: read_nested_list (S)
Function: read_nested_list (S, separator_flag)

  Reads the source S and returns its entire content as a nested list. The source S may be a file name or a stream.

  `read_nested_list` returns a list which has a sublist for each line of input. Lines need not have the same numbers of elements. Empty lines are not ignored: an empty line yields an empty sublist.

  The recognized values of separator_flag are `comma`, `pipe`, `semicolon`, and `space`. If separator_flag is not specified, the file is assumed space-delimited.

Function: read_list (S)
Function: read_list (S, L)
Function: read_list (S, separator_flag)
Function: read_list (S, L, separator_flag)

  `read_list(S)` reads the source S and returns its entire content as a flat list.

  `read_list(S, L)` reads the source S into the list L, until L is full or the source is exhausted.

  The source S may be a file name or a stream.

  The recognized values of separator_flag are `comma`, `pipe`, `semicolon`, and `space`. If separator_flag is not specified, the file is assumed space-delimited.

Function: write_data (X, D)
Function: write_data (X, D, separator_flag)

  Writes the object X to the destination D.

  `write_data` writes a matrix in row-major order, with one line per row.

  `write_data` writes an array created by `array` or `make_array` in row-major order, with a new line at the end of every slab. Higher-dimensional slabs are separated by additional new lines.

  `write_data` writes a hashed array with each key followed by its associated list on one line.

  `write_data` writes a nested list with each sublist on one line.

  `write_data` writes a flat list all on one line.

  The destination D may be a file name or a stream. When the destination is a file name, the global variable `file_output_append` governs whether the output file is appended or truncated. When the destination is a stream, no special action is taken by `write_data` after all the data are written; in particular, the stream remains open.

  The recognized values of separator_flag are `comma`, `pipe`, `semicolon`, `space`, and `tab`. If separator_flag is not specified, the file is assumed space-delimited.

Next: Functions and Variables for binary input and output, Previous: Introduction to numericalio, Up: numericalio [Contents][Index]