File
Constructor
L = fopen(file-name,mode=’string’,xdr=boolean,swap=boolean)
|
Parameters
Description
The File data type is used for file I/O operations.
Operations on File objects
methods
- F.close[]: close the file stream.
- F.putstr[str]: outputs a string.
- F.put[M,type=’string’] outputs the contents of real matrix M using the type
parameter as a conversion specifier. The type argument can be chosen among
"l", \verb”i”+, "s", "ul", "ui", "us", "d", "f", "c","uc" for writing respectively a
long, an int, a short, an unsigned long, an unsigned int, an unsigned short, a double,
a float, a char and an unsigned char. The bytes which are read are automatically
swapped if necessary (by checking little-endian status). This default swapping mode
can be suppressed by adding a flag in the mopen function. It is also possible to read in
little-endian or big-endian mode by adding a ’l’ or ’b’ character at the end of a type
specification. For example ’db’ can be used to read a double in big-endian mode.
- F.get[n=val,type=’string’]: reads n values of type given by type (see the above put
method for type specification). and returns the values in a vector of size n.
- F.getstr[n=val]: reads n bytes and returns the a string.
- F.eof[]: returns %t if an end-of-file was encountered.
- F.seek[value,str]: sets the file position indicator. The new position, measured in
bytes, is obtained by adding offset bytes to the position specified by ˙verb+str+. If str is
set to ’set’, cur, ’end’ the offset is relative to the start of the file, the current position
indicator, or end of file, respectively. Successful call clears the end of file indicator.
- F.tell[]: returns the current value of the file position indicator.
- F.clearerr[]: clears any previously raised error.
- F.error[]: returns %t if an error was encountered during previous read/write operations
- [M,S]F.get_matrix[format=’string’]: read a scalar matrix from file current
position. First lines can be non-numeric and are then returned in S. The read stops
when current line read is not compatible with previous ones. An optional format to be
used for reading each matrix entry can be given.
- S=F.get_lines[n]: acquires n lines from the file stream F and returns the result in a
string matrix. If n is omitted or negative it is assumed to be equal to one.
- S=F.get_smatrix[]: read the whole file contents from current position and return a
column string vector. Each line read giving a row of the column vector.
- F.put_matrix[M,format=’string’,sep=’string’,title=S]: output matrix contents
in a file using the given format for each element and the string given by sep as separator.
If title is given its contents is outputed in the file before the matrix. Default value for
format is the defualt format used in nsp interactive output and defaut separator is a
white space.
- F.put_smatrix[S]: output the contents of a string matrix in file F the string matrix is
explored columnwise (i.e equivalent to S(:)).
- F.print[Obj,as_read=boolean,depth=integer,
indent=integer,latex=boolean,name=string,table=boolean]: see the print
function for a description of optional arguments.
- F.printf[format,arg1,...,argn]: Similar to the C fprintf function.
functions
- fopen open a file for I/O operations returning a File object.
- is_little_endian checks the little-endian machine specification.
- getfile(fname): gets the contents of ascii file given by fname in a string column vector.
- putfile(fname,S): put the contents of a string matrix in file named fname. If the file
already existed its contents is replaced if not it is created.
Examples
See also unique (??) setdiff (??)
Authors jpc