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.

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.

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.

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.

 -- 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.

 -- 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.

 -- 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.

 -- 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.

 -- 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.

 -- 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.