|
[Sponsors] |
December 9, 2008, 16:12 |
int to char in UDF
|
#1 |
Guest
Posts: n/a
|
Hi,
i wrote the following UDF to write some simple data on an external file: /*****UDF for output*****/ #include "udf.h" DEFINE_ON_DEMAND(output) { 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"); thread_loop_c(t,d) { begin_c_loop(c,t) { C_CENTROID(x,c,t); 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); } end_c_loop(c,t) } fclose(fp); } Now, i'd like to modify filename to handle the the current number of time steps, i.e. data-2000.txt data-3000.txt 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. Thanks |
|
December 10, 2008, 09:53 |
Re: int to char in UDF
|
#2 |
Guest
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 |
|
December 10, 2008, 13:51 |
Re: int to char in UDF
|
#3 |
Guest
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. |
|
December 11, 2008, 05:01 |
Re: int to char in UDF
|
#4 |
Guest
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.
max |
|
|
|
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 15:44 |
char reactivity | Jurgen Jacoby | Main CFD Forum | 0 | September 14, 2006 07:23 |
Please help! Char-o2, Char-CO2, Char-H2O reactions | Dai | FLUENT | 4 | May 28, 2003 15:40 |
Char Oxidation | Monir Hossain | CFX | 4 | February 19, 2001 13:25 |