CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

how to export data into binary format?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 17, 2012, 14:58
Default how to export data into binary format?
  #1
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14
zxj160 is on a distinguished road
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
zxj160 is offline   Reply With Quote

Old   October 20, 2012, 17:13
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
__________________
wyldckat is offline   Reply With Quote

Old   October 21, 2012, 18:42
Default
  #3
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14
zxj160 is on a distinguished road
It works. Many thanks.
zxj160 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic Data Export (ascii format) A Kourm FLUENT 4 March 7, 2021 15:08
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Meshing & Mesh Conversion 12 May 2, 2013 11:52
Format data in Fluent phinix FLUENT 1 February 11, 2013 09:17
Generating a binary data file without using tecio tom10 Tecplot 0 June 18, 2012 20:16
export data at nodes Meenu FLUENT 1 December 30, 2011 02:24


All times are GMT -4. The time now is 05:31.