|
[Sponsors] |
April 26, 2002, 12:08 |
Fortran: Seeking data in files.
|
#1 |
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 |
|
April 27, 2002, 02:20 |
Re: Fortran: Seeking data in files.
|
#2 |
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.
|
|
April 27, 2002, 14:09 |
Re: Fortran: Seeking data in files.
|
#3 |
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 |
|
April 28, 2002, 09:02 |
Re: Fortran: Seeking data in files.
|
#4 |
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.) |
|
April 28, 2002, 10:55 |
Re: Fortran: Seeking data in files.
|
#5 |
Guest
Posts: n/a
|
CFD guy:
You can use the namelist input, which can be found in help file! Good luck! |
|
May 3, 2002, 13:03 |
Re: Fortran: Seeking data in files.
|
#6 |
Guest
Posts: n/a
|
Thank you very much andy,
Your native fortran suggestion worked very well. Kind regards, cfd guy |
|
May 23, 2002, 23:30 |
How to do it in Matlab?
|
#7 |
Guest
Posts: n/a
|
Then how to do it in Matlab? Thanks!
|
|
|
|
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 |