#include <matfileIO.hh>
Public Member Functions | |
MatfileIO (const std::string filename) | |
template<class T > | |
void | add (const T &u, const std::string varName, enum matio_compression compress=MAT_COMPRESSION_NONE) |
template<class T > | |
void | get (T &u, const std::string varName) |
void | reopen () |
void | close () |
void | clear () |
bool | isOpen () const |
bool | isEmpty () const |
bool | remove (const std::string varName) |
std::string | filename () const |
void | overWrite (bool toOverWrite) |
bool | exists (const std::string &varName) const |
bool | isReal (const std::string &varName) const |
bool | isCmplx (const std::string &varName) const |
bool | isScalar (const std::string &varName) const |
bool | isDense (const std::string &varName) const |
bool | isSparse (const std::string &varName) const |
bool | isInt (const std::string &varName) const |
bool | isUint (const std::string &varName) const |
uint | lengthVector (const std::string &varName) const |
void | assertCmplx (const std::string &varName) const |
void | assertExistence (const std::string &varName) const |
void | assertVector (const std::string &varName) const |
void | assertQuadratic (const std::string &varName) const |
Protected Member Functions | |
virtual std::ostream & | info (std::ostream &os) const |
Concepts *.mat-file tool. The class works as an interface between the Concepts and (some parts of) the library MatIO by Christopher C. Hulbert. It allows to write and read *.mat-files that are compressed with the z library or without compression within Concepts. If you do not have the z library installed, by default all compression is neglected. The heart of this class are the add/get routines. At the moment you are able to add/get concepts::ElementMatrix<T>
, concepts::SparseMatrix<T>
, concepts::DiagonalMatrix
, concepts::Array<T>
, concepts::Vector<T>
, std::vector<T>
(i.e. concepts::Sequence<T>
), concepts::Mapping<T,dim>
, Point<T,dim>
and Scalars(concepts::Real
, concepts::Cmplx
). Furthermore you are able get std::vector<Vector<T>
> objects out of a *.mat-file. There are lot of routines in this class that check if the requested object to get/add fits to the *.mat-file variabel on works with. For more details check the docu on the add/ get routines. For some control possibilities in own programm when using MatfileIO there are various control routines with that you can check for existence, sparse/dense structure, field, etc. The above mentioned classes (without SparseMatrix, DiagonalMatrix) are all called dense objects and need a dense structur representation in the matfile, when you want to get them with getter routines. A SparseMatrix needs a sparse representation in the *.mat-file. A DiagonalMatrix is a exception. It is added as sparse Matrix into a *.mat-file, but you can get it from diagonal dense/sparse matrices or dense vectorial structures.
When you add a variable you cannot get it before closing the current MatfileIO. Use The close()
, reopen()
routines for that issue. The class works with rank 2 objects only at the moment. In Matlab 1D-vectors/arrays and matrices are rank 2 objects. Matlabs multi-arrays with rank > 2 are not supported at the moment. This class works with Matlab level-5 file and Version 4 file *.mat-files, but not supports Matlab version 7.3 files atm. When using *.mat files produced with octave use the matlab binary options (-mat-binary , -mat4-binary, -mat7-binary) to save them.
Definition at line 112 of file matfileIO.hh.
concepts::MatfileIO::MatfileIO | ( | const std::string | filename | ) |
Constructor to open/create a *.mat with given name. The constructor trys to open a binary *.mat file with the given name filename
. If no such *.mat file already exists, a new *.mat file with the given filename
will be created. If the Input string does not end with the typical '.mat' label, it will be automatically added.
filename | Name of the *.mat-file. |
|
inlinevirtual |
Definition at line 130 of file matfileIO.hh.
|
inline |
Method to add various objects to a current open MatfileIO. Objects that can be added are:
ElementMatrix<T>
(i.e. DenseMatrix<T>)Array<Point<T, dim>>
DiagonalMatrix<T>
SparseMatrix<T>
Array<T>
,std::vector<T>
(i.e. Sequence<T>)Vector<T>
,Point<T, dim>
,Mapping<T, dim>
,Scalars
(Real, Cmplx)This add routine controls the Input quantities and throws an exception, if the MatfileIO instance is not open; the Input class type T
is not supported (yet); a variable with the same name varName
is added in the current MatfileIO instance, before closing it; a variable with the same name varName
already exists in the *.mat-file and is set not to be rewritable. If no error occurs the desired object is added.
u | The object you want to add to the current open *.mat-file |
varName | Name of the variable. |
compress | MAT_COMPRESSION_NONE / MAT_COMPRESSION_ZLIB |
Definition at line 160 of file matfileIO.hh.
void concepts::MatfileIO::assertCmplx | ( | const std::string & | varName | ) | const |
Throws an exception if the variable is not (at least) a complex
void concepts::MatfileIO::assertExistence | ( | const std::string & | varName | ) | const |
Throws an exception if the variable does not exist
void concepts::MatfileIO::assertQuadratic | ( | const std::string & | varName | ) | const |
Throws an exception if the variable is not a quadratic rank 2 object.
void concepts::MatfileIO::assertVector | ( | const std::string & | varName | ) | const |
Throws an exception if the variable has no vector struct, that is at most one dimension is larger than one.
void concepts::MatfileIO::clear | ( | ) |
Method to remove all variable in the current *.mat-file.
void concepts::MatfileIO::close | ( | ) |
Method to close the current *.mat-file. This method has the effect to finish the writing to the *.mat-file. It may be used in combination with reopen(). If you don't close the current MatfileIO-object the deconstructor will do it anyway.
bool concepts::MatfileIO::exists | ( | const std::string & | varName | ) | const |
Returns true if the variable /c varName exists, false otherwise. It throws an exception if no file is opened currently.
|
inline |
Returns the name of the current open *.mat-file.
Definition at line 306 of file matfileIO.hh.
Method to get various objects out of the current open MatfileIO. Objects that can be gained:
ElementMatrix<T>
(i.e. DenseMatrix<T>)DiagonalMatrix<T>
SparseMatrix<T>
Array<T>
,std::vector<T>
(i.e.Sequence<T>
)std::vector<Vector<T>
> (i.e. Sequence<Vector< T >
>)Vector<T>
,Point<T, dim>
,Mapping<T, dim>
,Scalars
(Real, Cmplx)This get routine controlls the Input quantities and throws an exception, if no variable named varName
exists in the current open *.mat-file; if the field of the requested variable in the *.mat-file and the field of u
differs, that is concepts::Real or concepts::Cmplx; if the class of u
is not supported (yet). Matlab's multidimensional arrays with rank > 2 are not supported to be read out of a *.mat-file (yet). If no error occurs the desired object gets filled. The object u
does not need to be preallocated, it gets resized due to the *.mat-file informations.
u | The object you want to get out of the current open *.mat-file |
varName | Name of the requested variable. |
Definition at line 234 of file matfileIO.hh.
|
protectedvirtual |
Gives an overview about the variables that are in a current open *.mat-file.
Reimplemented from concepts::OutputOperator.
bool concepts::MatfileIO::isCmplx | ( | const std::string & | varName | ) | const |
Return true if the variable /c varName is of type double complex
bool concepts::MatfileIO::isDense | ( | const std::string & | varName | ) | const |
Returns true if the variable /c varName is dense, else 0
|
inline |
Routine to check if a *.mat-file is empty, i.e. does not contain any variables.
Definition at line 290 of file matfileIO.hh.
bool concepts::MatfileIO::isInt | ( | const std::string & | varName | ) | const |
Returns true if the variable /c varname is int, else 0.
|
inline |
Routine to check if a *.mat-file is currently open. Might be use with reopen() and close() routines.
Definition at line 283 of file matfileIO.hh.
bool concepts::MatfileIO::isReal | ( | const std::string & | varName | ) | const |
Return true if the variable /c varName is of type double
bool concepts::MatfileIO::isScalar | ( | const std::string & | varName | ) | const |
Return true if the variable /c varName is a scalar
bool concepts::MatfileIO::isSparse | ( | const std::string & | varName | ) | const |
Returns true if the variable /c varName is sparse, else 0.
bool concepts::MatfileIO::isUint | ( | const std::string & | varName | ) | const |
Returns true if the variable /c varname is uint, else 0.
uint concepts::MatfileIO::lengthVector | ( | const std::string & | varName | ) | const |
Return its length if /c varName is a vector, 0 otherwise
Method with that u can secure already existing variables in a current open *.mat-file. By default variables get overwritten. If you disable overwriting and try to overwrite a secured variable, it will be asserted.
toOverWrite | Parameter to secure (false) or to unsecure (true) variables from overwriting. |
Definition at line 316 of file matfileIO.hh.
bool concepts::MatfileIO::remove | ( | const std::string | varName | ) |
Removes the requested variable named 'str' if it exist in the current matfile. Therefore, first the MatfileIO gets closed to finish writing and then a attempt to delete is performed. If the removal was successful it returns 1, else (i.e. the requested var does not exist in the *.mat-file) it returns 0.
void concepts::MatfileIO::reopen | ( | ) |
Method to reopen the *.mat-file that was once opened with the constructor. This could be used in combination with the close()-routine. It may has an application when using the same name for different variables in iterations, where they will be overwritten at each iteration.