2.15 The IO_matrix_file class

Read and write functions are provided by the class IO_matrix_file. It is possible to read or write data at every iteration of the simulation using an instance of this class.

Constructor

Syntax
IO_matrix_file(const string & filename);

Description

IO_matrix_file object constructor.

Return Value

None

write

Syntax
short write(const vector<Matrix> & data);  
short write(const vector<Matrix> & data, const vector<string> & data_title);

Description

This member function appends data to a file (specified by the constructor, and opened by write() when first called). data_title is used to write a header description at the beginning of the file. If it is not specified, a default description datai,i = 1,2,⋅⋅⋅,n will be added. The header contains the number of iterations, the number of vectors and the data parameters, as follows:

nb_iterations 1269

nb_vector 2

nb_rows 1 nb_cols 1 time (s)

nb_rows 6 nb_cols 1 q(i) (rad)

———————————

Return Value

A short integer return the status:

  1. 0 successful,
  2. IO_COULD_NOT_OPEN_FILE
  3. IO_DATA_EMPTY

read

Syntax
short read(const vector<Matrix> & data);  
short read(const vector<Matrix> & data, const vector<string> & data_title);  
short read_all(vector<Matrix> & data, vector<string> & data_title);

Description

These member functions read data from a file (specified by the constructor, and opened when first called). read() reads the values corresponding to only one iteration, while read_all() reads the entire file at once.

These member functions are meant to read a file that was written using write().

Return Value

Status, as a short int.

  1. 0 successful
  2. IO_DATA_EMPTY
  3. IO_COULD_NOT_OPEN_FILE