How to INPUT and OUTPUT data in Maple
In addition to the basic commands listed in the answer "How to SAVE
and RESTORE information from Maple" there are several routines for
direct data input/output. A brief description follows; use the online
help for more information.
For input:
1. "readline" reads a single line from a file or the terminal, and
returns it as a string. You can then parse this with "sscanf" or the
"parse" function (for Maple expressions).
2. "readdata" reads a text file containing numbers separated by tabs
or spaces, and returns it as a list. You can specify which columns to
read, and whether to treat them as integers or floats.
3. "fscanf" "sscanf" and "scanf" are based on the C standard library
functions of the same names for formatting input. The Maple versions
of these functions each return a list.
4. "readbytes" reads a specified number of bytes from a file, and
returns either a list of integers or a string of characters.
For output:
1. "writeline" writes strings to a file or the terminal.
2. "writedata" is used to write numerical data to a text file.
3. "fprintf" "sprintf" and "printf" are based on the C standard library
functions of the same names; these allow you to control the format of
output. There is also an "nprintf" which returns a Maple symbol
rather than a string.
4. "writebytes" writes the bytes from a string of characters or list
of integers to a file (the file is opened with type text or binary,
respectively).
|