|
[Sponsors] |
November 4, 2008, 16:39 |
using UDF to read file
|
#1 |
Guest
Posts: n/a
|
Hi,
I've been trying to read a table to Fluent using UDF. I started simple: read a file which contains only one number. It can be interpreted, but when I run it, Fluent gave me an error message saying sth like "fatal error", asking me to exit and restart. Then I skipped the reading part (fscanf), and only open a file with "ifp = fopen("myfile.txt", "r"), but there's still the same error message. I tried to write to a file using fopen and fprintf, and it worked ok. Can anyone please give an idea why I can write but cannot read using UDF? or, please tell me where I did wrong. Thank you in advance, Ellen |
|
November 4, 2008, 23:23 |
Re: using UDF to read file
|
#2 |
Guest
Posts: n/a
|
did you set Fluents working directory to where myfile.txt is?
|
|
November 5, 2008, 10:19 |
Re: using UDF to read file
|
#3 |
Guest
Posts: n/a
|
Yes, the file myfile.txt is in the same directory as the case file that I'm running. Yesterday I tried some more with the udf code, and after I put the definition "FILE *ifp, *ofp" outside the DEFINE_PROPERTY() function, the case was able to run without any error. But it run very slowly and it didn't read from the file. (there's only one number is this file, and I checked whether the number was read or not by writing this number to another file using fprintf).
Do you have any suggestions? Thanks a lot. Ellen |
|
November 5, 2008, 16:53 |
Re: using UDF to read file
|
#4 |
Guest
Posts: n/a
|
type ls in the fluent console and hit enter to see if the working directory is correct.
Can you post the code? You can add code like the following example to detect the file reading errors if ((fp = fopen(filename, "w"))==NULL) Message("\n Warning: Unable to open %s for writing\n",filename); else Message("\nWriting Pressure to %s...",filename); |
|
November 5, 2008, 18:38 |
Re: using UDF to read file
|
#5 |
Guest
Posts: n/a
|
Thanks a lot for the reply, CDE. I'll try what you suggested.
I found the reason of the incorrect file reading. It's because a mismatch of the data type and the format specifier I used in fscanf. Now I'm able to read the data file correctly into an array, however, the running speed is very slow (it takes about 10 seconds to perform one iteration). I've posted another message in this board about this problem. Do you have any idea what might be the reason? Ellen |
|
November 25, 2008, 18:38 |
Re: using UDF to read file
|
#6 |
Guest
Posts: n/a
|
Hi Ellen, I have the same problem when try reading from the file.Could you advise please Ehsan
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
read file in UDF | Echo | FLUENT | 4 | July 4, 2017 13:37 |
How to read a file from a macro | StarCD | Siemens | 2 | July 8, 2004 22:31 |
Why I can't read one external file? | Lee | Siemens | 7 | April 2, 2004 13:25 |
Read file | RBM | FLUENT | 0 | July 14, 2002 14:48 |
Read data file | R.B.M | FLUENT | 0 | July 11, 2002 00:16 |