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

what is the Best way for formating the output numbers

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2011, 16:24
Default what is the Best way for formating the output numbers
  #1
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
Good afternoon,

Is it possible to use "Info" to output the numbers in a certain format, like printf does, for example, 7.3f, something like that?

Thanks
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat is offline   Reply With Quote

Old   September 21, 2011, 05:13
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22
Bernhard is on a distinguished road
Is the writePrecision option in controlDict an option?
I think the alternative is either digging really deep in the code (maybe the precision member of IOstream can help you?) or just cheat by using printf anyhow
Bernhard is offline   Reply With Quote

Old   September 21, 2011, 11:26
Default
  #3
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
Quote:
Originally Posted by Bernhard View Post
Is the writePrecision option in controlDict an option?
No, it's not relevant.
Quote:
I think the alternative is either digging really deep in the code (maybe the precision member of IOstream can help you?)
...
Quote:
or just cheat by using printf anyhow
Is this the best way so far, anyone in the know?
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat is offline   Reply With Quote

Old   September 22, 2011, 04:16
Default
  #4
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
printf is pure C, it's C++ descendant is cout. Assuming Info is built upon cout, you can do:

Code:
Info << setw(7);
Info.precision(3);
Info <<   fixed    << a << '\t' << b << '\t' << c << endl;
Try it.
akidess is offline   Reply With Quote

Old   September 26, 2011, 09:17
Default
  #5
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,285
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by lakeat View Post
Good afternoon,

Is it possible to use "Info" to output the numbers in a certain format, like printf does, for example, 7.3f, something like that?

Thanks

i use %2.10le for my DNS code. Creates big file but never had problems with precision.

PS: Sorry if this is not what you asked.
arjun is offline   Reply With Quote

Old   November 29, 2011, 14:19
Default
  #6
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
Quote:
Originally Posted by akidess View Post
printf is pure C, it's C++ descendant is cout. Assuming Info is built upon cout, you can do:

Code:
Info << setw(7);
Info.precision(3);
Info <<   fixed    << a << '\t' << b << '\t' << c << endl;
Try it.
It doesn't work, I don't think the Info(messageStream) is built on cout, I found the printf is still the best option we have.
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat 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
lift and drag on ship superstructures vaina74 OpenFOAM Running, Solving & CFD 3 June 8, 2010 13:30
Probe output produce merged numbers olesen OpenFOAM Bugs 3 October 15, 2008 16:51
[Other] Output Format of MetaMesh t42 OpenFOAM Meshing & Mesh Conversion 0 August 3, 2007 05:28
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 03:58
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07


All times are GMT -4. The time now is 04:20.