reading an entire line of a file 
Author Message
 reading an entire line of a file

hi,

i was wondering if there was any way to read across a input file line
using f90.  i am trying to pick out lines of a file that have a certain
character at the end.  thank you!

cathleen



Tue, 11 Nov 2003 21:52:48 GMT  
 reading an entire line of a file

Quote:

> hi,

> i was wondering if there was any way to read across a input file line
> using f90.  i am trying to pick out lines of a file that have a certain
> character at the end.  thank you!

As long as your special character is not a blank, use

line_length = len_trim(input_line)
lastchar = input_line(line_length:)
if (lastchar .eq. specialchar) then
...

--
gus gassmann

"When in doubt, travel"
======================================================================
                     To reply, remove SPAM BLOCK



Tue, 11 Nov 2003 22:07:58 GMT  
 reading an entire line of a file

Quote:

>hi,

>i was wondering if there was any way to read across a input file line
>using f90.  i am trying to pick out lines of a file that have a certain
>character at the end.  thank you!

>cathleen

Hi, you can read an entire line of a file with:

READ(unitfile,10) string
10 FORMAT(A120)  ! A number large enough to include all the line

Javier Santamaria
Mechanical Engineer



Tue, 11 Nov 2003 22:08:30 GMT  
 reading an entire line of a file
Quote:

[snip]

> Hi, you can read an entire line of a file with:

> READ(unitfile,10) string
> 10 FORMAT(A120)  ! A number large enough to include all the line

I like this kind of problem since they're like the russian dolls (you
know the ones with a doll inside a doll inside a doll...)

The problem is of course "How do you know how long line to expect?".
Well theoretically you don't at least not if you're trying to write
something that's useful for many tasks, for many years and for many
platforms/compilers (some of which might be unknown when you write your
program). I go about this kind of problem with non-advancing read,
reading one character at a time. A good thing is to move the limitations
outside the routine by

                 character*(*),intent(out) :: aline(maxlength)

or

                 character*(*),intent(out) :: aline(:) !( in which case you need an
explicit interface)

or if you really want to play ball, you start dealing with pointers
and/or allocatable arrays.

That said, remember that it's not always wise to use the gun you shoot
elephants with when a mosqito is bugging you ;o)

/mattias



Wed, 12 Nov 2003 06:11:30 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. reading entire command line (under os/2)

2. Open specific file, read entire contents, close - no user interaction

3. Reading entire waveform from file?

4. reading an entire file as a string

5. how to read text files line by line?

6. reading file line by line

7. new question in how can i read data from file line by line

8. line-by-line file read

9. Read a text file line by line

10. adding entire line

11. Entire line as a variable

12. How to Remove entire lines

 

 
Powered by phpBB® Forum Software