CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to export data into binary format? (http://www.cfd-online.com/Forums/openfoam-programming-development/108231-how-export-data-into-binary-format.html)

zxj160 October 17, 2012 13:58

how to export data into binary format?
 
Dear foamers,

I am new to the openfoam programming. In the solve, I want to add a set of code to write out the binary format data? My current code is :

.........
ofstream output_file; //(It should be ASCII format, but I want binary.
Foam::string output_file_name;
........
output_file.open (output_file_name.c_str());
forAll(mesh.C(), pointI)
{
output_file << mesh.C()[pointI].x() << " " << mesh.C()[pointI].y() << " " << mesh.C()[pointI].z() << " " << U.internalField()[pointI].x() <<
" " << U.internalField()[pointI].y() << " " << U.internalField()[pointI].z() << "\n";
}

output_file.close();


Many thanks, I just want to binary format data for post-processing.

Best regards,
Jian

wyldckat October 20, 2012 16:13

Greetings Jian,

You'll need to open the file with the binary mode option:
Code:

output_file.open (output_file_name.c_str(), ios::out | ios::binary);
For more on this subject, read this tutorial "Input/Output with files": http://www.cplusplus.com/doc/tutorial/files/

Best regards,
Bruno

zxj160 October 21, 2012 17:42

It works. Many thanks.


All times are GMT -4. The time now is 01:09.