0

for (i=0, i<imax, i++)
{
// ...

Array< complex<float>, 3 > matrix(x,y,z);

// x,y,z are large and vary in each loop
// ...
// matrix <=== values for each element assigned
// ...
// now want to write "matrix" in a single binary file.
// later, this matrix can be read directly from the file.
// HOW??
}

Thanks for your help.

Apple

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by chiwawa10
0

Here is a relevant example of serialization, meaning writing the data binary.

class Matrix
{
public:
    Matrix()
    {
        x1 = x2 = x3 = y1 = y2 = y3 = z1 = z2 = z3 = 0.f;
    }

    float x1, x2, x3, y1, y2, y3, z1, z2, z3;
};

int main()
{
    Matrix myMatrix;
    fstream stream("file.bin", std::ios::write | std::ios::binary);
    stream.write((const char*) &myMatrix, sizeof(Matrix));
    stream.close();
}
0

for Array< complex<float>, 3 >, sizeof( Array< complex<float>, 3 > ) returns 64.
We need to find the size of matrix for Array< complex<float>, 3 > matrix(x,y,z) where x/y/z >> 1;

0

Do note that this will only write one Matrix into the file.

stream.write((const char*) &myMatrix, sizeof(Matrix));

Just replace the pointer of myMatrix to the location of your matrix array and the size to the total number of matrix multiply by sizeof(Matrix)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.