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

int to char in UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 9, 2008, 15:12
Default int to char in UDF
  #1
Paolo Lampitella
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
  Reply With Quote

Old   December 10, 2008, 08:53
Default Re: int to char in UDF
  #2
max
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

  Reply With Quote

Old   December 10, 2008, 12:51
Default Re: int to char in UDF
  #3
Paolo Lampitella
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.
  Reply With Quote

Old   December 11, 2008, 04:01
Default Re: int to char in UDF
  #4
max
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
  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
Problems in combustion of char Cleiton CFX 2 December 12, 2008 11: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 12:25


All times are GMT -4. The time now is 06:12.