FSCANF Problem
I'm trying to load velocity data from a file using the following code:
/***********BEGIN**************/ int maxcent = 1; int a = 0; int b = 0; double tempvel; double velprof[1000][8]; /* make sure # faces <= 1000 */ double test1; FILE *fi2; fi2 = fopen("velprof4.txt", "r"); if (fi2 == NULL) printf("*\nERROR - CANNOT OPEN THE FILE\n*"); else printf("*\n File Opened. ID is %d\n", fi2); while (a <= maxcent) { b = 0; while (b <= 7) { fscanf(fi2, "%g", &tempvel); velprof[a][b] = tempvel; printf("%d %d %g\n", a, b, velprof[a][b]); ++b; } ++a; } fclose(fi2); } /***********END**************/ The input file was created in a text editor and is: 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0; 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0; The representative output from FLUENT for the velocity matrix is: File Opened. ID is 18001056; 0 0 5.26354e-315 0 1 5.30499e-315 0 2 5.32571e-315 0 3 5.34643e-315 0 4 5.3568e-315 0 5 5.36716e-315 0 6 5.37752e-315 0 7 5.38788e-315 1 0 5.39306e-315 1 1 5.39824e-315 1 2 5.40342e-315 1 3 5.4086e-315 1 4 5.41378e-315 1 5 5.41896e-315 1 6 5.41896e-315 1 7 5.41896e-315 So the velocity values in the matrix are wrong. Any ideas? Thanks, |
fscanf problem
Hi i had got the same problem and i soved it defining the variable as float and not double...try it and let me know
by daniele:confused: |
Quote:
|
I got crazy with this fscanf....thanks Martelli, declaring the variable as float works!
Daniele |
Where do you use this code? I thought UDF needs DEFINE macro...
|
Hi, in a few words,
fscanf is a C function to scan a file for its content. Macros are written in C language to communicate with fluent. Inside macros you use C language, so you can use the fscanf function. Daniele |
Thank you for your explanation, but in the code from above, there is no macro, that would communicate with fluent. I assume that part is left out, or is it possible to execute code as it is?
Thanks |
I was having the same problem. Changing variable from real or double to float worked perfectly.
Thanks |
fscanf in udf
Hi
Changing the double or real to float will work I think because we have used "%g" in fscanf function |
Thanks a lot guys. This works !!
|
All times are GMT -4. The time now is 15:34. |