KR403: Output from a UDF using Message() only prints to the GUI. If the output is desired to go to a file, the fprintf function is commonly used. How can one easily switch between the two without having a lot of duplicate lines in the FLUENT UDF code? (Solution ID: 1175)


A single function is given to combine the two. This function, generically is called gf_print(FILE*, char* format, ...).

The first argument, if NULL, will direct the output to the GUI. If not NULL, the output is printed to the file as specified using the fopen statement. I've included the source code and a sample UDF that demos this capability.

Parallel versions: gf_print0, and gf_print_cn are provided. The "0" function prints only from serial or the host node (in parallel). The "_cn" version only prints from compute node "cn" (the argument list is slightly different. If "cn < 0", the print is called for each compute node.
gf_print is a variable argument function, so it's calling list is of arbitrary length.





Show Form
No comments yet. Be the first to add a comment!