CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF Getting data from file (https://www.cfd-online.com/Forums/fluent/66278-udf-getting-data-file.html)

jreig July 10, 2009 08:07

UDF Getting data from file
 
Hi everybody!!


I am trying to get some data from an input file to use it as an Energy source.

When interpreting the udf appears this message:

Error:
FLUENT received fatal signal (ACCESS_VIOLATION)

The error comes when trying to close the file, or to scan the file to get the data. If I comment the lines "fscanf" and "fclose" no error message appears.

Maybe the error is caused by a wrong oppening of the file.

Here is the code:


**************************

#include "udf.h"


DEFINE_SOURCE(source,c,t)
{
real xc[ND_ND];
real q;
FILE *fp;
float data[108];
int i;
i=0;
fp = fopen("out.txt","r");

while (i<108){
fscanf(fp,"%f",&data[i]);
i++;
}

fclose(fp);

C_CENTROID(xc,c,t);
if (xc[0]>0.5)
q=10000;
else
q=0;
return q;
}

**************************


Can anyone help me please??


All times are GMT -4. The time now is 07:53.