[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

64. numericalio


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

64.1 Introduction to numericalio

numericalio is a collection of functions to read and write data files and streams.

It is assumed that each item to read or write is an atom: an integer, float, bigfloat, string, or symbol, and not a rational or complex number or any other kind of nonatomic expression. The numericalio functions may attempt to do something sensible faced with nonatomic expressions, but the results are not specified here and subject to change.

Atoms in both input and output files have the same format as in Maxima batch files or the interactive console. In particular, strings are enclosed in double quotes, backslash \ prevents any special interpretation of the next character, and the question mark ? is recognized at the beginning of a symbol to mean a Lisp symbol (as opposed to a Maxima symbol). No continuation character (to join broken lines) is recognized.

separator_flag tells which character separates elements. It is an optional argument for all read and write functions.

Categories:  File input · File output · Share packages · Package numericalio


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

64.1.1 Separator flag values for input

For input, these values of separator_flag are recognized: comma for comma separated values, pipe for values separated by the vertical bar character |, semicolon for values separated by semicolon ;, and space for values separated by space or tab characters. If the file name ends in .csv and separator_flag is not specified, comma is assumed. If the file name ends in something other than .csv and separator_flag is not specified, space is assumed.

In input, multiple successive space and tab characters count as a single separator. However, multiple comma, pipe, or semicolon characters are significant. Successive comma, pipe, or semicolon characters (with or without intervening spaces or tabs) are considered to have false between the separators. For example, 1234,,Foo is treated the same as 1234,false,Foo.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

64.1.2 Separator flag values for output

For output, tab, for values separated by the tab character, is recognized as a value of separator_flag, as well as comma, pipe, semicolon, and space.

In output, false atoms are written as such; a list [1234, false, Foo] is written 1234,false,Foo, and there is no attempt to collapse the output to 1234,,Foo.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

64.2 Functions and Variables for numericalio

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

Reads the file file_name or file stream S and returns its entire content as a matrix. If separator_flag is not specified, the file is assumed space-delimited.

read_matrix infers the size of the matrix from the input data. Each line of the file becomes one row of the matrix. If some lines have different lengths, read_matrix complains.

Categories:  Package numericalio · File input

Function: read_lisp_array (file_name, A)
Function: read_lisp_array (file_name, A, separator_flag)
Function: read_lisp_array (S, A)
Function: read_lisp_array (S, A, separator_flag)

Reads the file file_name or file stream S and returns its entire content as a Lisp array. If separator_flag is not specified, the file is assumed space-delimited.

read_lisp_array requires that the array be declared by make_array before calling the read function. (This obviates the need to infer the array dimensions, which could be a problem for arrays with multiple dimensions.)

read_lisp_array does not check to see that the input file conforms in some way to the array dimensions; the input is read as a flat list, then the array is filled using fillarray.

Categories:  Package numericalio · File input

Function: read_maxima_array (file_name, A)
Function: read_maxima_array (file_name, A, separator_flag)
Function: read_maxima_array (S, A)
Function: read_maxima_array (S, A, separator_flag)

Reads the file file_name or file stream S and returns its entire content as a Maxima array. If separator_flag is not specified, the file is assumed space-delimited.

read_maxima_array requires that the array be declared by array before calling the read function. (This obviates the need to infer the array dimensions, which could be a hassle for arrays with multiple dimensions.)

read_maxima_array does not check to see that the input file conforms in some way to the array dimensions; the input is read as a flat list, then the array is filled using fillarray.

Categories:  Package numericalio · File input

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

Reads the file file_name or file stream S and returns its entire content as a hashed array. If separator_flag is not specified, the file is assumed space-delimited.

read_hashed_array treats the first item on a 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.

Categories:  Package numericalio · File input

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

Reads the file file_name or file stream S and returns its entire content as a nested list. If separator_flag is not specified, the file is assumed space-delimited.

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.

Categories:  Package numericalio · File input

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

Reads the file file_name or file stream S and returns its entire content as a flat list. If separator_flag is not specified, the file is assumed space-delimited.

Categories:  Package numericalio · File input

Function: write_data (X, file_name)
Function: write_data (object, file_name, separator_flag)
Function: write_data (X, S)
Function: write_data (object, S, separator_flag)

write_data writes the object X to the file file_name or file stream S.

write_data writes matrices in row-major form, with one line per row.

write_data writes Lisp and Maxima declared arrays in row-major form, with a new line at the end of every slab. Higher-dimensional slabs are separated by additional new lines.

write_data writes hashed arrays with a key followed by the associated list on each line.

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

write_data writes a flat list all on one line.

When write_data writes to a file, the global variable file_output_append governs whether the output file is appended or truncated.

No special action concerning appending or truncating is taken when write_data writes to a file stream. The file stream is not closed by write_data.

Categories:  Package numericalio · File output


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Robert Dodier on December, 22 2007 using texi2html 1.76.