CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > FLUENT

FSCANF Problem

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

Like Tree3Likes
  • 1 Post By DK
  • 2 Post By D.Martelli

Reply
 
LinkBack Thread Tools Display Modes
Old   August 10, 2007, 10:07
Default 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 likes this.
  Reply With Quote

Old   September 15, 2011, 08:57
Default fscanf problem
  #2
New Member
 
Daniele
Join Date: Dec 2009
Location: Pisa
Posts: 11
Rep Power: 7
D.Martelli is on a distinguished road
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.
D.Martelli is offline   Reply With Quote

Old   March 11, 2013, 07:18
Default
  #3
Member
 
Ali Mohamadi
Join Date: Aug 2012
Posts: 32
Rep Power: 4
Alimohamadi_nasr is on a distinguished road
Quote:
Originally Posted by D.Martelli View Post
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.
Alimohamadi_nasr is offline   Reply With Quote

Old   June 4, 2014, 07:17
Default
  #4
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
I got crazy with this fscanf....thanks Martelli, declaring the variable as float works!

Daniele
ghost82 is offline   Reply With Quote

Old   June 24, 2014, 11:58
Default
  #5
New Member
 
Select One...
Join Date: Apr 2012
Posts: 21
Rep Power: 5
eneja is on a distinguished road
Where do you use this code? I thought UDF needs DEFINE macro...
eneja is offline   Reply With Quote

Old   June 24, 2014, 18:01
Default
  #6
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
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
ghost82 is offline   Reply With Quote

Old   June 26, 2014, 03:53
Default
  #7
New Member
 
Select One...
Join Date: Apr 2012
Posts: 21
Rep Power: 5
eneja is on a distinguished road
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
eneja is offline   Reply With Quote

Old   July 7, 2014, 12:19
Default
  #8
New Member
 
Join Date: Jun 2011
Posts: 22
Rep Power: 6
sescobar is on a distinguished road
I was having the same problem. Changing variable from real or double to float worked perfectly.

Thanks
sescobar is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 21:30.