Hello,
I'm using C to write a user defined macro for the Ansys Fluent software. In a part of this macro, I read data from text files and store them in arrays , Here's the code:
Code:
DEFINE_EXECUTE_ON_LOADING(data_import,libname) /*macro definition*/
{
FILE *fp ;
size_t i, j, k ; /*Array indexes*/
char *tok1, *tok2, row[1000] ;
/*First file*/
fp=fopen("RCT.csv","r");
i = 0;
while (1) /*Loop to read each line of characters*/
{
fgets(row,50,fp);
if (feof(fp)) /*Breaks the loop if ENDOFFILE=TRUE*/
{
break;
}
tok1=strtok(row,",");
j=0;
while (tok1 != NULL) /*Loop to read tokens of each line*/
{
blade_d[i][j] = strtod(tok1,NULL);
tok1 = strtok(NULL,",");
j++;
}
i++;
}
fclose(fp);
Message("\n %f\n", blade_d[0][0]) ; /*A command to display messages*/
/*Second and third file*/
fp=fopen("Data_C_l.txt","r");
for (k = 0; k < 2; k++)
{
i=0;
while (1)
{
fgets(row,1000,fp);
if (feof(fp))
{
break;
}
tok2=strtok(row," ");
j=0;
while (tok2 != NULL)
{
airfoil_d[k][i][j] = strtod(tok2,NULL);
tok2 = strtok(NULL," ");
j++;
}
i++;
}
fclose(fp);
fp = fopen("Data_C_d.txt","r");
}
fclose(fp);
Message("\n %f\n", blade_d[0][0]) ;
}
Now, the problem is that the first element of "blade_d" array changes value from 0.25 (the correct one) to 0.0 . And this happens somewhere between the two "Message" commands. Since I'm pretty new to C language, I'm quite confused about why this is happening.
Any help is much appreciated.
p.s. "blade_d" and "airfoil_d" arrays are defined as global variables above macro definition.