CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

HOW CAN I USE "ftell" ????

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 16, 2009, 05:24
Default HOW CAN I USE "ftell" ????
  #1
Senior Member
 
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 16
enry is on a distinguished road
Hi everybody,
I wanna know the end position of a file. So I write this routine:



#include "udf.h"

DEFINE_ON_DEMAND(example)
{
FILE *fp;
long len;

fp=fopen("moment.txt","rb");
if(fp == NULL)
printf("ERROR!!!!");

len=ftell(fp); /*get position at end (length)*/
fclose(fp);
}




Fluent report:

error: ftell : undeclared variable.




WHY ?!?! CAN ANYBODY HELP ME?!
thanks.
enry is offline   Reply With Quote

Old   November 16, 2009, 10:18
Default
  #2
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
If you add
#include <stdio.h>
does this help?

cheers
coglione is offline   Reply With Quote

Old   November 16, 2009, 10:31
Default
  #3
Senior Member
 
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 16
enry is on a distinguished road
I have to read the number in a file .txt; the file is like the following:


12.3
43.2
123.4
122.3



HOW CAN I READ THE NUMBER TILL THE END?

ps. In Fluent you have to include only the file header udf.h : #include "udf.h"
pps. sei italiano?
enry is offline   Reply With Quote

Old   November 16, 2009, 11:05
Default
  #4
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
hi enrico,

as far as i know "udf.h" will include some standard IO-functions, but not the more sophisticated ones. Try to include "std.io" and see what happens.
Sorry i am not Italian, my synonym originates from an Italian girl i once knew, but something went wrong as you may perceive easily.

cheers
coglione is offline   Reply With Quote

Old   November 25, 2009, 08:27
Default
  #5
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Quote:
Originally Posted by enry View Post
I have to read the number in a file .txt; the file is like the following:


12.3
43.2
123.4
122.3



HOW CAN I READ THE NUMBER TILL THE END?

ps. In Fluent you have to include only the file header udf.h : #include "udf.h"
pps. sei italiano?
Hi Enrico,
The following code should do the trick:
Code:
#include "udf.h"

DEFINE_ON_DEMAND(example)
{
#if !PARALLEL
   FILE *fp;
   real bubu;

   fp=fopen("moment.txt","r");
   if(fp == NULL)
      Message("ERROR!!!!\n");

   while(!feof(pf))
   {
      fscanf(pf,"%g",&bubu);
   }

   fclose(fp);
#endif
}
Note: it should be run in serial.
dmoroian is offline   Reply With Quote

Old   November 26, 2009, 05:16
Default
  #6
Senior Member
 
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 16
enry is on a distinguished road
Thanks a lot for your reply.
Do you know how can I read only the last number on a .txt file?
enry is offline   Reply With Quote

Old   November 26, 2009, 05:21
Default It reads the last number
  #7
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Well, my example this is what actually does: it reads the last number from the file. It reads all of them, but only the last remains after it exits the "while" loop.
dmoroian is offline   Reply With Quote

Old   November 26, 2009, 06:01
Default
  #8
Senior Member
 
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 16
enry is on a distinguished road
Oh yes! of course!!!

I compile the following text on fluent, but it reports an error:



#include "udf.h"

DEFINE_ON_DEMAND(example)
{
#if !PARALLEL
FILE *fp;
double bubu;

fp=fopen("moment.txt","r");
if(fp == NULL)
Message("ERROR!!!!\n");

while(!feof(fp))
{
fscanf(fp,"%lf",&bubu);
}

fclose(fp);
#endif

}


Error: example.c: line 13: feof: undeclared variable

I compile it as INTERPRETED. I try also as COMPILED, but it doesn't work.
Do you know if I have to add some header files when I use FEOF ?
An other question: what's the meaning of #if !PARALLEL ?

Thank in advance.
enry is offline   Reply With Quote

Old   November 26, 2009, 06:15
Default
  #9
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Hi Enrico,
The function feof() is declared in the header stdio.h, which I think is already included by udf.h, but just in case add it:
Code:
#define "udf.h"
#define<stdio.h>
The compiler directive
Code:
#if !PARALLEL ...#endif
specifies that the code works only serial (not parallel).
dmoroian is offline   Reply With Quote

Old   November 26, 2009, 06:46
Default
  #10
Senior Member
 
Herman
Join Date: Nov 2009
Posts: 122
Rep Power: 16
enry is on a distinguished road
Thanks a lot for your quikly replies!
IT WORKS (whitout including stdio.h ), but only as compiled!

Thanks!
enry is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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



All times are GMT -4. The time now is 22:44.