udf source
Hello,
I have a question and I will like if anyone can help me to write the following DEFINE_SOURCE: I inform you that the values of T_mean and Time is in a txt file named result.txt. I want to write an udf program that uses the found values of the text file. I ran the progame and I did not find any errors but the program does not give me the values of T_mean and Time. Help me please. DEFINE_SOURCE(Source_AIR, c, t, dS, eqn) { real source, Time,T_mean; FILE *pFile; pFile=fopen("c:/result.txt","r"); fscanf(pFile,"%g %g\n",&Time,&T_mean); fclose(pFile); source =32*T_mean*Time; dS[eqn] = 0.0; return source; } |
-You don't give any value to T_mean
-Also this equation is odd: TEMP=T_Mean; source =32*T_Mean*TEMP/TIM; T_mean*TEMP is the same as T_mean^2 Why do you even need the TEMP? -You have not defined the T_Moyenne inside the DEFINE_SOURCE. -You should remove the semicolon ';' from inside of fscanf(pFile,"%g ;%g\n" and fprintf(pFile,"%g ;%g\n" -fscanf( is missing the last bracket ')' |
thank you for your replay
For this Source term, I want open file text (in mu case result.txt), in this file they have a value, for exemple 30 299. (30 is 30 sec, and 299 is temperature). for DEFINE SOURCE, I want open result.txt and read 30 as time and 299 as temperture. Tahnk you. DEFINE_SOURCE(Source_AIR, c, t, dS, eqn) { real source, Time,T_mean; FILE *pFile; pFile=fopen("c:/result.txt","r"); fscanf(pFile,"%g %g\n",&Time,&T_mean); fclose(pFile); source =32*T_mean*Time; dS[eqn] = 0.0; return source; } |
still:
-fscanf( is missing the last bracket ')' -T_Moyenne -are you sure about that source-equation? |
My problem is not in the equation or in the bracket (. but how can I read a file txt and load some variables (Time and Time) in the DEFINE SOURCE
|
Your problem was also the bracket. UDF do not work, if the code is wrong.
Do you need the "\n" when using fscanf();? You could also try %f in your fscanf(); or are you using double precision? |
not necessery to put \n or double double precision, I want juste read a text file
and calculate source =32*T_mean*Time. the values of Time and T_mean finded in the file text. I want to have any solution to read these two values from a text file. |
All times are GMT -4. The time now is 20:42. |