applepomme 0 Newbie Poster

I used this to write the matrix into a file:

int Nx, Ny, Nz;
Array <complex<float>, 3> matrix(Nx, Ny, Nz, ColumnMajorArray<3>());
...get matrix data...
fstream outbin(outname.c_str(),ios::out|ios::binary);
outbin.write(reinterpret_cast<char *>(matrix.data()),sizeof(complex<float>)*Nx*Ny*Nz);
outbin.close();

Then, I used this to read this matrix, works fine, values and orders are correct too:

Array <complex<float>, 3> matrixb(Nx, Ny, Nz, ColumnMajorArray<3>());
fstream inbin(inname.c_str(),ios::binary|ios::in);
for (int k=0; k<Nz; k++){
  for (int j=0; j<Ny; j++){
    for (int i=0; i<Nx; i++){    
    inbin.read(reinterpret_cast<char *>(&matrixb(i,j,k)),sizeof(complex<float>));
        }
    }
}
inbin.close();

However, this read all ZEROs in matrixb:

Array <complex<float>, 3> matrixb(Nx, Ny, Nz, ColumnMajorArray<3>());
fstream inbin(inname.c_str(),ios::binary|ios::in);
outbin.read(reinterpret_cast<char *>(matrixb.data()),sizeof(complex<float>)*Nx*Ny*Nz);
inbin.close();

Thank you for pointing out the problem.

Apple