1 @c -----------------------------------------------------------------------------
2 @c File : numericalio.de.texi
3 @c License : GNU General Public License (GPL)
7 @c This file is part of Maxima -- GPL CAS based on DOE-MACSYMA
8 @c -----------------------------------------------------------------------------
11 * Introduction to numericalio::
12 * Functions and Variables for plain-text input and output::
13 * Functions and Variables for binary input and output::
16 @c -----------------------------------------------------------------------------
17 @node Introduction to numericalio, Functions and Variables for plain-text input and output, numericalio, numericalio
18 @section Introduction to numericalio
20 @code{numericalio} is a collection of functions to read and write files and streams.
21 Functions for plain-text input and output
22 can read and write numbers (integer, float, or bigfloat), symbols, and strings.
23 Functions for binary input and output
24 can read and write only floating-point numbers.
26 If there already exists a list, matrix, or array object to store input data,
27 @code{numericalio} input functions can write data into that object.
28 Otherwise, @code{numericalio} can guess, to some degree, the structure of an object
29 to store the data, and return that object.
32 @c @category{File input} @category{File output} @category{Share packages} @category{Package numericalio}
35 @c -----------------------------------------------------------------------------
36 @subsection Plain-text input and output
38 In plain-text input and output,
39 it is assumed that each item to read or write is an atom:
40 an integer, float, bigfloat, string, or symbol,
41 and not a rational or complex number or any other kind of nonatomic expression.
42 The @code{numericalio} functions may attempt to do something sensible faced with nonatomic expressions,
43 but the results are not specified here and subject to change.
45 Atoms in both input and output files have the same format as
46 in Maxima batch files or the interactive console.
47 In particular, strings are enclosed in double quotes,
48 backslash @code{\} prevents any special interpretation of the next character,
49 and the question mark @code{?} is recognized at the beginning of a symbol
50 to mean a Lisp symbol (as opposed to a Maxima symbol).
51 No continuation character (to join broken lines) is recognized.
53 @c -----------------------------------------------------------------------------
54 @subsection Separator flag values for input
56 The functions for plain-text input and output take an optional argument,
57 @var{separator_flag}, that tells what character separates data.
59 For plain-text input, these values of @var{separator_flag} are recognized:
60 @code{comma} for comma separated values,
61 @code{pipe} for values separated by the vertical bar character @code{|},
62 @code{semicolon} for values separated by semicolon @code{;},
63 and @code{space} for values separated by space or tab characters.
64 If the file name ends in @code{.csv} and @var{separator_flag} is not specified,
65 @code{comma} is assumed.
66 If the file name ends in something other than @code{.csv} and @code{separator_flag} is not specified,
67 @code{space} is assumed.
69 In plain-text input, multiple successive space and tab characters count as a single separator.
70 However, multiple comma, pipe, or semicolon characters are significant.
71 Successive comma, pipe, or semicolon characters (with or without intervening spaces or tabs)
72 are considered to have @code{false} between the separators.
73 For example, @code{1234,,Foo} is treated the same as @code{1234,false,Foo}.
75 @c -----------------------------------------------------------------------------
76 @subsection Separator flag values for output
78 For plain-text output, @code{tab}, for values separated by the tab character,
79 is recognized as a value of @var{separator_flag},
80 as well as @code{comma}, @code{pipe}, @code{semicolon}, and @code{space}.
82 In plain-text output, @code{false} atoms are written as such;
83 a list @code{[1234, false, Foo]} is written @code{1234,false,Foo},
84 and there is no attempt to collapse the output to @code{1234,,Foo}.
86 @c -----------------------------------------------------------------------------
87 @subsection Binary floating-point input and output
89 @code{numericalio} functions can read and write 8-byte IEEE 754 floating-point numbers.
90 These numbers can be stored either least significant byte first or most significant byte first,
91 according to the global flag set by @code{assume_external_byte_order}.
92 If not specified, @code{numericalio} assumes the external byte order is most-significant byte first.
94 Other kinds of numbers are coerced to 8-byte floats;
95 @code{numericalio} cannot read or write binary non-numeric data.
97 Some Lisp implementations do not recognize IEEE 754 special values
98 (positive and negative infinity, not-a-number values, denormalized values).
99 The effect of reading such values with @code{numericalio} is undefined.
101 @code{numericalio} includes functions to open a stream for reading or writing a stream of bytes.
103 @c -----------------------------------------------------------------------------
104 @node Functions and Variables for plain-text input and output, Functions and Variables for binary input and output, Introduction to numericalio, numericalio
105 @section Functions and Variables for plain-text input and output
107 @c -----------------------------------------------------------------------------
108 @deffn {Function} read_matrix (@var{S})
109 @deffnx {Function} read_matrix (@var{S}, @var{M})
110 @deffnx {Function} read_matrix (@var{S}, @var{separator_flag})
111 @deffnx {Function} read_matrix (@var{S}, @var{M}, @var{separator_flag})
113 @code{read_matrix(@var{S})} reads the source @var{S} and returns its entire content as a matrix.
114 The size of the matrix is inferred from the input data;
115 each line of the file becomes one row of the matrix.
116 If some lines have different lengths, @code{read_matrix} complains.
118 @code{read_matrix(@var{S}, @var{M})} read the source @var{S} into the matrix @var{M},
119 until @var{M} is full or the source is exhausted.
120 Input data are read into the matrix in row-major order;
121 the input need not have the same number of rows and columns as @var{M}.
123 The source @var{S} may be a file name or a stream.
125 The recognized values of @var{separator_flag} are
126 @code{comma}, @code{pipe}, @code{semicolon}, and @code{space}.
127 If @var{separator_flag} is not specified, the file is assumed space-delimited.
130 @c @category{Package numericalio} @category{File input}
134 @c -----------------------------------------------------------------------------
135 @deffn {Function} read_array (@var{S}, @var{A})
136 @deffnx {Function} read_array (@var{S}, @var{A}, @var{separator_flag})
138 Reads the source @var{S} into the array @var{A},
139 until @var{A} is full or the source is exhausted.
140 Input data are read into the array in row-major order;
141 the input need not conform to the dimensions of @var{A}.
143 The source @var{S} may be a file name or a stream.
145 The recognized values of @var{separator_flag} are
146 @code{comma}, @code{pipe}, @code{semicolon}, and @code{space}.
147 If @var{separator_flag} is not specified, the file is assumed space-delimited.
150 @c @category{Package numericalio} @category{File input}
154 @c -----------------------------------------------------------------------------
155 @deffn {Function} read_hashed_array (@var{S}, @var{A})
156 @deffnx {Function} read_hashed_array (@var{S}, @var{A}, @var{separator_flag})
158 Reads the source @var{S} and returns its entire content as a hashed array.
159 The source @var{S} may be a file name or a stream.
161 @code{read_hashed_array} treats the first item on each line as a hash key,
162 and associates the remainder of the line (as a list) with the key.
164 the line @code{567 12 17 32 55} is equivalent to @code{A[567]: [12, 17, 32, 55]$}.
165 Lines need not have the same numbers of elements.
167 The recognized values of @var{separator_flag} are
168 @code{comma}, @code{pipe}, @code{semicolon}, and @code{space}.
169 If @var{separator_flag} is not specified, the file is assumed space-delimited.
172 @c @category{Package numericalio} @category{File input}
176 @c -----------------------------------------------------------------------------
177 @deffn {Function} read_nested_list (@var{S})
178 @deffnx {Function} read_nested_list (@var{S}, @var{separator_flag})
180 Reads the source @var{S} and returns its entire content as a nested list.
181 The source @var{S} may be a file name or a stream.
183 @code{read_nested_list} returns a list which has a sublist for each
184 line of input. Lines need not have the same numbers of elements.
185 Empty lines are @i{not} ignored: an empty line yields an empty sublist.
187 The recognized values of @var{separator_flag} are
188 @code{comma}, @code{pipe}, @code{semicolon}, and @code{space}.
189 If @var{separator_flag} is not specified, the file is assumed space-delimited.
192 @c @category{Package numericalio} @category{File input}
196 @c -----------------------------------------------------------------------------
197 @deffn {Function} read_list (@var{S})
198 @deffnx {Function} read_list (@var{S}, @var{L})
199 @deffnx {Function} read_list (@var{S}, @var{separator_flag})
200 @deffnx {Function} read_list (@var{S}, @var{L}, @var{separator_flag})
202 @code{read_list(@var{S})} reads the source @var{S} and returns its entire content as a flat list.
204 @code{read_list(@var{S}, @var{L})} reads the source @var{S} into the list @var{L},
205 until @var{L} is full or the source is exhausted.
207 The source @var{S} may be a file name or a stream.
209 The recognized values of @var{separator_flag} are
210 @code{comma}, @code{pipe}, @code{semicolon}, and @code{space}.
211 If @var{separator_flag} is not specified, the file is assumed space-delimited.
214 @c @category{Package numericalio} @category{File input}
218 @c -----------------------------------------------------------------------------
219 @deffn {Function} write_data (@var{X}, @var{D})
220 @deffnx {Function} write_data (@var{X}, @var{D}, @var{separator_flag})
222 Writes the object @var{X} to the destination @var{D}.
224 @code{write_data} writes a matrix in row-major order,
225 with one line per row.
227 @code{write_data} writes an array created by @code{array} or @code{make_array}
228 in row-major order, with a new line at the end of every slab.
229 Higher-dimensional slabs are separated by additional new lines.
231 @code{write_data} writes a hashed array with each key followed by
232 its associated list on one line.
234 @code{write_data} writes a nested list with each sublist on one line.
236 @code{write_data} writes a flat list all on one line.
238 The destination @var{D} may be a file name or a stream.
239 When the destination is a file name,
240 the global variable @code{file_output_append} governs
241 whether the output file is appended or truncated.
242 When the destination is a stream,
243 no special action is taken by @code{write_data} after all the data are written;
244 in particular, the stream remains open.
246 The recognized values of @var{separator_flag} are
247 @code{comma}, @code{pipe}, @code{semicolon}, @code{space}, and @code{tab}.
248 If @var{separator_flag} is not specified, the file is assumed space-delimited.
251 @c @category{Package numericalio} @category{File output}
255 @c -----------------------------------------------------------------------------
256 @node Functions and Variables for binary input and output, , Functions and Variables for plain-text input and output, numericalio
257 @section Functions and Variables for binary input and output
259 @c -----------------------------------------------------------------------------
260 @deffn {Function} assume_external_byte_order (@var{byte_order_flag})
261 Tells @code{numericalio} the byte order for reading and writing binary data.
262 Two values of @var{byte_order_flag} are recognized:
263 @code{lsb} which indicates least-significant byte first, also called little-endian byte order;
264 and @code{msb} which indicates most-significant byte first, also called big-endian byte order.
266 If not specified, @code{numericalio} assumes the external byte order is most-significant byte first.
269 @c @category{Package numericalio}
273 @c -----------------------------------------------------------------------------
274 @deffn {Function} openr_binary (@var{file_name})
275 Returns an input stream of 8-bit unsigned bytes to read the file named by @var{file_name}.
278 @c @category{Package numericalio} @category{File input}
282 @c -----------------------------------------------------------------------------
283 @deffn {Function} openw_binary (@var{file_name})
284 Returns an output stream of 8-bit unsigned bytes to write the file named by @var{file_name}.
287 @c @category{Package numericalio} @category{File output}
291 @c -----------------------------------------------------------------------------
292 @deffn {Function} opena_binary (@var{file_name})
293 Returns an output stream of 8-bit unsigned bytes to append the file named by @var{file_name}.
296 @c @category{Package numericalio} @category{File output}
300 @c -----------------------------------------------------------------------------
301 @deffn {Function} read_binary_matrix (@var{S}, @var{M})
302 Reads binary 8-byte floating point numbers from the source @var{S} into the matrix @var{M}
303 until @var{M} is full, or the source is exhausted.
304 Elements of @var{M} are read in row-major order.
306 The source @var{S} may be a file name or a stream.
308 The byte order in elements of the source is specified by @code{assume_external_byte_order}.
311 @c @category{Package numericalio} @category{File input}
315 @c -----------------------------------------------------------------------------
316 @deffn {Function} read_binary_array (@var{S}, @var{A})
317 Reads binary 8-byte floating point numbers from the source @var{S} into the array @var{A}
318 until @var{A} is full, or the source is exhausted.
319 @var{A} must be an array created by @code{array} or @code{make_array}.
320 Elements of @var{A} are read in row-major order.
322 The source @var{S} may be a file name or a stream.
324 The byte order in elements of the source is specified by @code{assume_external_byte_order}.
327 @c @category{Package numericalio} @category{File input}
331 @c -----------------------------------------------------------------------------
332 @deffn {Function} read_binary_list (@var{S})
333 @deffnx {Function} read_binary_list (@var{S}, @var{L})
334 @code{read_binary_list(@var{S})} reads the entire content of the source @var{S}
335 as a sequence of binary 8-byte floating point numbers, and returns it as a list.
336 The source @var{S} may be a file name or a stream.
338 @code{read_binary_list(@var{S}, @var{L})} reads 8-byte binary floating point numbers
339 from the source @var{S} until the list @var{L} is full, or the source is exhausted.
341 The byte order in elements of the source is specified by @code{assume_external_byte_order}.
344 @c @category{Package numericalio} @category{File input}
348 @c -----------------------------------------------------------------------------
349 @deffn {Function} write_binary_data (@var{X}, @var{D})
351 Writes the object @var{X}, comprising binary 8-byte IEEE 754 floating-point numbers,
352 to the destination @var{D}.
353 Other kinds of numbers are coerced to 8-byte floats.
354 @code{write_binary_data} cannot write non-numeric data.
356 The object @var{X} may be a list, a nested list, a matrix,
357 or an array created by @code{array} or @code{make_array};
358 @var{X} cannot be an undeclared array or any other type of object.
359 @code{write_binary_data} writes nested lists, matrices, and arrays in row-major order.
361 The destination @var{D} may be a file name or a stream.
362 When the destination is a file name,
363 the global variable @code{file_output_append} governs
364 whether the output file is appended or truncated.
365 When the destination is a stream,
366 no special action is taken by @code{write_binary_data} after all the data are written;
367 in particular, the stream remains open.
369 The byte order in elements of the destination
370 is specified by @code{assume_external_byte_order}.
373 @c @category{Package numericalio} @category{File output}
377 @c --- End of file numericalio.de.texi -----------------------------------------