CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   int to char in UDF (

Paolo Lampitella December 9, 2008 16:12

int to char in UDF

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.


max December 10, 2008 09:53

Re: int to char in UDF
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

Paolo Lampitella December 10, 2008 13:51

Re: int to char in UDF
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.

max December 11, 2008 05:01

Re: int to char in UDF
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.


All times are GMT -4. The time now is 17:39.