c++ - What's the most basic way to format a 2D matrix of doubles in binary for reading into IDL? -
so have j matrix of doubles in c++ want read idl program.
lets matrix called data, size rows cols, , name string saved filename. , write values out in stream binary file.
ofstream myfile (filename, ios::binary); if(myfile.isopen()) { (int = 0; < rows; i++){ (int j=0; j < cols; j++){ myfile<<data.at(i,j); } myfile.close();
i want read idl i'm new working binary in idl , following documentation has gotten me here it's not working.
function read_binmatrix, filename, rows, cols, thetype mat = read_binary(filename,data_type=thetype,data_dims=[rows-1,cols-1]) return, mat end ... ... matrix = read_binmatrix(file2,num_rows,num_cols,5)
...but error output.
% read_binary: readu: end of file encountered. unit: 100, file: ... % execution halted at: read_binmatrix 21 ...
myfile<<data.at(i,j);
writes text file, not binary data. write numbers in binary format use std::ofstream::write()
:
myfile.write(reinterpret_cast<char*>(&data.at(i,j),sizeof(decltype(data.at(i,j))));
Comments
Post a Comment