iconEuler Reference

Elementary File Input and Output

Content

Formatted input and output to files.

See also the Euler core functions for file input and output in Euler Core.

For files of unknown sources getmatrix() or getvector() should be used to read the numerical content. For output, writematrix() is the easiest choice.

The functions work either for files opened with open(), or for a file name provided as a parameter, or for terminal output.

For Latex, writelatex() can be used.

Reading and Writing Matrices and Vectors

function comment setdecimaldot (s)
  Set the decimal dot.
  
  Returns the current value of the decimal dot.
  
  >dd=setdecimaldot(",");
  >...
  >setdecimaldot(dd);
function decimalcomma ()
  Use a decimal comma for matrix input
  
  Returns the previous value.
function overwrite getvector (n, comma=0)
  Read at most numbers from an input file
  
  A file must be opened for this to work. The function returns a
  vector of numbers. The numbers in the file can be separated by any
  character.
  
  See: 
getvectorline (Elementary File Input and Output),
open (Euler Core),
close (Euler Core),
close (Maxima Documentation)
function overwrite getvectorline (n, comma=0)
  Read at most numbers from an input line
  
  A file must be opened for this to work. The function returns a
  vector of numbers. The numbers in the file can be separated by any
  character.
  
  See: 
getmatrix (Elementary File Input and Output),
readmatrix (Elementary File Input and Output)
function getmatrix (n:real scalar, m:real scalar,
    filename:string="", comma=0)
  Read a real nxm Matrix from the file.
  
  If the filename is "", the file must be opened before. Else the
  file will open and close for read.
  
  Matrix values must be decimal fix point numbers with a dot (or a
  comma, if set). They must be stored row after row.
  
  comma : use decimal comma
  
  See: 
getvector (Elementary File Input and Output),
open (Euler Core),
readmatrix (Elementary File Input and Output)
function readmatrix (filename:string="",
    max=1000, expand=false, comma=false)
  Read a real matrix from the file.
  
  The matrix is stored row by row in lines, with an empty line ending
  the matrix. If the filename is not empty, the function will open
  the file for reading, and close it after reading. Otherwise, it
  will use the provided file name.
  
  max : the maximimal number of columns.
  expand : incomplete lines will filled with 0.
  comma : use decimal comma instead of dot
  
  To import matrices from Excel, export to CSV (comma separated
  values). These files can be read directly. On German systems,
  enable the decimal comma with >comma.
  
  See: 
writematrix (Elementary File Input and Output),
open (Euler Core),
close (Euler Core),
close (Maxima Documentation),
getmatrix (Elementary File Input and Output)
function getmatrixlines (filename:string="", max=1000, expand=0)
  Obsolete. Use readmatrix.
  
  See: 
readmatrix (Elementary File Input and Output)
function writematrix (v:real,
    file:string=none, format:string="%0.16g",
    separator=none, comma=false)
  Write a real nxm Matrix to the file row after row.
  
  v : real matrix
  file : filename
  format : C type format, see printf
  separator : Separator string
  comma : >comma uses a decimal comma.
  
  If the filename is not "", the file will be created (beware!),
  opened, and closed after writing. If the filename is "", a file
  opened with open(filename,"w") will be used, or the terminal.
  
  For cvs output (comma separated values), set the separator to ","
  and use a filename with extension "csv". For German files, set the
  use ";" and enable >comma. These files can be opened directly in
  Excel.
  
  See: 
readmatrix (Elementary File Input and Output),
open (Euler Core),
printf (Basic Utilities),
printf (Maxima Documentation)

Formatted Output to Files

function writeform (x, format="%0.16g")
  Converts x in the specified format to a string
function writevar (x,s="",filename="",newlines=0)
  Write a variable Euler syntax.
  
  If a filename is given, or a file is open, it will be used,
  otherwise the function will write to the command line.
  
  s : the name of the variable
  filename : a file to write to
  newlines : flag for newlines to separate elements in a row
function writeformat (x,f:string="%g",sep1=", ",sep2=";",
    writereal=1,ibracket1="~",ibracket2="~",perline=100)
  Print the vector x formatted with format f.
  
  The format is applied to real and imaginary part, or lower and
  upper part of the elements of x.
  
  writereal : Complex and interval values become two real values.
  Rows are separated with sep2.
  
  If a file is open, the function will write to that file.
  
  See: 
writevar (Elementary File Input and Output)

Latex is a text system for mathematical texts. Sometimes, you may wish to output Euler matrices in Latex. Symbolic matrices can be printed using the latex command of Maxima.

function writelatex (x,f="%g",environment="pmatrix",perline=100)
  Write x for AMS latex matrix environment
  
  This function can output an Euler matrix for the AMS Latex
  environment pmatrix, or any other environment. The open file is
  used, or the terminal.
  
  perline: Maximal number of items per line
  
  See: 
writeformat (Elementary File Input and Output),
open (Euler Core),
latex (Plot Functions)

Use the dir command to get a listing of the files in the active directory. This is the directory, where the notebook is stored. It can be changed using the changedir command in Euler Core.

function overwrite dir (pattern:string=none, dirs:integer=false)
  vector of strings with matching file names or subdirectories.
  
  The pattern can be something like "*.en" or "file?.dat"
  If dirs==true, then only directories will be listed.
  Directories are listed with a "/" at the end.
  
  See: 
changedir (Euler Core),
searchfile (Euler Core)
function printfile (filename:string, lines:index=100)
  Print the first lines of a file
  
  See: 
open (Euler Core),
close (Euler Core),
close (Maxima Documentation)
function printhexfile (filename:string, n:index=1024)
  Print the first bytes of a file in hex

Documentation Homepage