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

how to export data into binary format?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   October 17, 2012, 13:58
Default how to export data into binary format?
  #1
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 107
Rep Power: 5
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, 16:13
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 7,947
Blog Entries: 34
Rep Power: 79
wyldckat is a jewel in the roughwyldckat is a jewel in the roughwyldckat is a jewel in the roughwyldckat is a jewel in the rough
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, 17:42
Default
  #3
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 107
Rep Power: 5
zxj160 is on a distinguished road
It works. Many thanks.
zxj160 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Other Meshers: ICEM, Star, Ansys, Pointwise, GridPro, Ansa, ... 12 May 2, 2013 10: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 19:16
export data at nodes Meenu FLUENT 1 December 30, 2011 02:24
Automatic Data Export (ascii format) A Kourm FLUENT 3 January 21, 2009 08:36


All times are GMT -4. The time now is 02:46.