CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

How to keep syntax (decimal places) when writing from array to .txt-file?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By sfn

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 29, 2017, 02:53
Default How to keep syntax (decimal places) when writing from array to .txt-file?
  #1
New Member
 
Sarah
Join Date: May 2017
Posts: 8
Rep Power: 9
Sarah_Fluent is on a distinguished road
Hello everybody,

I wrote a UDF where I want to write the temperature values from an Array into a .txt-file:

DEFINE_ON_DEMAND(export__temp)
{
cell_t c;
Domain *d = Get_Domain(1);
FILE *temp__piece;
real temp1;

Thread *c_thread= Lookup_Thread(d,3);
temp__piece=fopen("temp__piece.txt","w");

begin_c_loop(c, c_thread)
{
temp1 = C_T(c,c_thread);
fprintf(temp__piece,"%g \n",temp1);
}
end_c_loop(c, c_thread)
fclose(temp__piece);
}


The UDF works - but the temperatures do have between 0-3 decimal places. The textfile will be exported and used for Ansys Classic further.
The problem is now: If a temperature has 0 decimal places, Ansys Classic calculates wrong (Temperature that is used then is just 1/100 as high as in the .txt-file). Therefore, I would like Fluent always to use the same number of decimal places (3).

Is that possible and can someone explain me, how this might work?


Kind regards,
Sarah
Sarah_Fluent is offline   Reply With Quote

Old   May 29, 2017, 05:01
Default
  #2
sfn
New Member
 
Alexander
Join Date: Dec 2016
Posts: 24
Rep Power: 9
sfn is on a distinguished road
use printf format identiffiers
%.3f
KaLium likes this.
sfn is offline   Reply With Quote

Old   May 29, 2017, 08:48
Default
  #3
New Member
 
Sarah
Join Date: May 2017
Posts: 8
Rep Power: 9
Sarah_Fluent is on a distinguished road
It worked out!

Thank you so much
Sarah_Fluent 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
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 04:30
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 22:53
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51
error while compiling the USER Sub routine CFD user CFX 3 November 25, 2002 16:16


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