|
[Sponsors] |
August 10, 2007, 10:07 |
FSCANF Problem
|
#1 |
Guest
Posts: n/a
|
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, |
|
September 15, 2011, 08:57 |
fscanf problem
|
#2 |
New Member
Daniele
Join Date: Dec 2009
Location: Pisa
Posts: 11
Rep Power: 16 |
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 |
|
March 11, 2013, 06:18 |
|
#3 |
Member
Ali Mohamadi
Join Date: Aug 2012
Posts: 32
Rep Power: 13 |
||
June 4, 2014, 07:17 |
|
#4 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26 |
I got crazy with this fscanf....thanks Martelli, declaring the variable as float works!
Daniele |
|
June 24, 2014, 11:58 |
|
#5 |
New Member
Select One...
Join Date: Apr 2012
Posts: 21
Rep Power: 14 |
Where do you use this code? I thought UDF needs DEFINE macro...
|
|
June 24, 2014, 18:01 |
|
#6 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26 |
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 |
|
June 26, 2014, 03:53 |
|
#7 |
New Member
Select One...
Join Date: Apr 2012
Posts: 21
Rep Power: 14 |
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 |
|
July 7, 2014, 12:19 |
|
#8 |
New Member
Join Date: Jun 2011
Posts: 22
Rep Power: 14 |
I was having the same problem. Changing variable from real or double to float worked perfectly.
Thanks |
|
September 19, 2017, 03:33 |
fscanf in udf
|
#9 |
New Member
mohammad
Join Date: May 2016
Location: Tehran
Posts: 17
Rep Power: 10 |
Hi
Changing the double or real to float will work I think because we have used "%g" in fscanf function |
|
April 6, 2024, 16:30 |
|
#10 |
New Member
Join Date: May 2023
Posts: 2
Rep Power: 0 |
Thanks a lot guys. This works !!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF compiling problem | Wouter | Fluent UDF and Scheme Programming | 6 | June 6, 2012 04:43 |
Gambit - meshing over airfoil wrapping (?) problem | JFDC | FLUENT | 1 | July 11, 2011 05:59 |
natural convection problem for a CHT problem | Se-Hee | CFX | 2 | June 10, 2007 06:29 |
Adiabatic and Rotating wall (Convection problem) | ParodDav | CFX | 5 | April 29, 2007 19:13 |
Is this problem well posed? | Thomas P. Abraham | Main CFD Forum | 5 | September 8, 1999 14:52 |