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

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();
}

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;

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.