# FSCANF Problem

 Register Blogs Members List Search Today's Posts Mark Forums Read

 August 10, 2007, 10:07 FSCANF Problem #1 DK 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, czhao86 and myaghoobi2 like this.

 September 15, 2011, 08:57 fscanf problem #2 New Member   Daniele Join Date: Dec 2009 Location: Pisa Posts: 11 Rep Power: 9 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 ghost82 and Alimohamadi_nasr like this.

March 11, 2013, 07:18
#3
Member

Join Date: Aug 2012
Posts: 32
Rep Power: 7
Quote:
 Originally Posted by D.Martelli 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
dear D.Martelli many thanks, it also works for me.

 June 4, 2014, 07:17 #4 Senior Member     Daniele Join Date: Oct 2010 Location: Italy Posts: 998 Rep Power: 17 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: 7 Where do you use this code? I thought UDF needs DEFINE macro...

 June 24, 2014, 18:01 #6 Senior Member     Daniele Join Date: Oct 2010 Location: Italy Posts: 998 Rep Power: 17 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: 7 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: 8 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: 12 Rep Power: 3 Hi Changing the double or real to float will work I think because we have used "%g" in fscanf function

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 04:43 JFDC FLUENT 1 July 11, 2011 05:59 Se-Hee CFX 2 June 10, 2007 06:29 ParodDav CFX 5 April 29, 2007 19:13 Thomas P. Abraham Main CFD Forum 5 September 8, 1999 14:52

All times are GMT -4. The time now is 10:48.