CFD Online Logo CFD Online URL
Home > Forums > FLUENT

int to char in UDF

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

LinkBack Thread Tools Display Modes
Old   December 9, 2008, 16:12
Default int to char in UDF
Paolo Lampitella
Posts: n/a

i wrote the following UDF to write some simple data on an external file:

/*****UDF for output*****/

#include "udf.h"



Domain *d;

real x[ND_ND];

real x0, y0, z0, u, v, w;

real p, mut;

int time;

char *filename;

FILE *fp;

Thread *t;

cell_t c;

d = Get_Domain(1);

time = N_TIME;

filename = "data.txt";

fp = fopen(filename,"w");






ND_SET(x0, y0, z0, x[0], x[1], x[2]);

ND_SET(u, v, w, C_U(c, t), C_V(c, t), C_W(c, t));

p = C_P(c,t);

mut = C_MU_T(c,t);

fprintf(fp, "%14.12f %14.12f %14.12f ", x0, y0, z0);

fprintf(fp, "%18.16f %18.16f %18.16f %18.16f %18.16f\n", u, v, w, p, mut);






Now, i'd like to modify filename to handle the the current number of time steps, i.e.



and so on, but i'm not able to do so. Actually i think that the only line which has to be modified is

filename = "data.txt";

but i don't know how because all i know about c is coming from the fluent udf manual. Any help is really appreciated.

  Reply With Quote

Old   December 10, 2008, 09:53
Default Re: int to char in UDF
Posts: n/a
hello paolo

sprintf() will do the job, e.g.:

const char base[] = "data-"; char filename [10]; int number = RP_Get_Integer("time-step"); sprintf(filename, "%s%d", base, number);

you may check this with: printf("filename = \"%s\"\n", filename);

cheers max

  Reply With Quote

Old   December 10, 2008, 13:51
Default Re: int to char in UDF
Paolo Lampitella
Posts: n/a
Thanks max for your help but i'm not able to let it work.

Moreover sprintf seems not be recognized...maybe it is because i'm interpreting the udf

Somewhere i also find the itoa command but i really don't know how to use it. Anyway, thanks again for your help.
  Reply With Quote

Old   December 11, 2008, 05:01
Default Re: int to char in UDF
Posts: n/a
All i can say is that sprintf works nicely in compiled udf mode. Give it a try and let me know if the problem persists.

  Reply With Quote


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
Problems in combustion of char Cleiton CFX 2 December 12, 2008 12:35
Char Reactions A A S FLUENT 0 May 25, 2007 14:44
char reactivity Jurgen Jacoby Main CFD Forum 0 September 14, 2006 06:23
Please help! Char-o2, Char-CO2, Char-H2O reactions Dai FLUENT 4 May 28, 2003 14:40
Char Oxidation Monir Hossain CFX 4 February 19, 2001 13:25

All times are GMT -4. The time now is 10:54.