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

Fortran: Seeking data in files.

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 26, 2002, 12:08
Default Fortran: Seeking data in files.
  #1
cfd guy
Guest
 
Posts: n/a
Hi people,
I was wondering if I can extract a specific data from a file using a subroutine in FORTRAN. Which command can I use? Below, I'll show a simple example. Suppose that I have a file, TEST.DAT, and this file has the following lines:
. . . . . VAR = 10 VAR2 = 50 /* COMMENT */ TIME = 100 VAR3 = 30 . . . . .
I want to extract the value from TIME variable. How can I do that? Important, this variable doesn't remain constant in a certain line. Is there any function in FORTRAN that I can seek this characters ('TIME = ') and then READ it (100) in my subroutine? I hope anyone of you can help me.
Kind regards, cfd guy
  Reply With Quote

Old   April 27, 2002, 02:20
Default Re: Fortran: Seeking data in files.
  #2
Bob
Guest
 
Posts: n/a
It depends entirely on which Fortran compiler you are using. Each has their own string handling intrinsics. Try reading the manual or help file of yours under strings or intrinsic functions.
  Reply With Quote

Old   April 27, 2002, 14:09
Default Re: Fortran: Seeking data in files.
  #3
cfd guy
Guest
 
Posts: n/a
Thanks Bob,
I use Visual Compaq Fortran 6.5 under NT. I took a look at manuals several times and I didn't find a specific command for seeking strings in files.
cfd guy
  Reply With Quote

Old   April 28, 2002, 09:02
Default Re: Fortran: Seeking data in files.
  #4
andy
Guest
 
Posts: n/a
Native Fortran is good enough to handling this sort of thing directly. Read each line into a character buffer and then test/read it for whatever you want. Something like below should work (adding declarations and removing possible typos and the mangling by html).

1000 read( dn, '(a)', iostat=ierr ) buffer

if ( ierr .eq. 0 ) then

if ( buffer(1:6) .eq. 'TEST =' ) then

read( buffer(7,'(i8)' ) time

else

goto 1000

end if

end if

Of course, you could generalize it a bit and put it in a function or subroutine. (Curiously, this was one of the in-class exercises I used to set students many years ago when teaching Fortran.)

  Reply With Quote

Old   April 28, 2002, 10:55
Default Re: Fortran: Seeking data in files.
  #5
peter.zhao
Guest
 
Posts: n/a
CFD guy:

You can use the namelist input, which can be found in help file!

Good luck!
  Reply With Quote

Old   May 3, 2002, 13:03
Default Re: Fortran: Seeking data in files.
  #6
cfd guy
Guest
 
Posts: n/a
Thank you very much andy,
Your native fortran suggestion worked very well.
Kind regards, cfd guy
  Reply With Quote

Old   May 23, 2002, 23:30
Default How to do it in Matlab?
  #7
wen long
Guest
 
Posts: n/a
Then how to do it in Matlab? Thanks!
  Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF issue MASOUD Fluent UDF and Scheme Programming 14 December 6, 2012 14:39
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 19:56
critical error during installation of openfoam Fabio88 OpenFOAM Installation 21 June 2, 2010 04:01
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 21:51
grid data to be read by Fortran code seckin FLUENT 0 April 19, 2003 15:03


All times are GMT -4. The time now is 17:13.