For Programmers: Free Programming Magazines  


Home > Archive > Fortran > September 2005 > reading ascii file with header









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author reading ascii file with header
Ralf Schaa

2005-09-12, 3:56 am

Hi all,

I like to read an ascii file which has e.g. 5 header lines; beneath
that the data follows. How can I read the file starting at the
data-line?

Cheers
-Ralf

# header1
# header2
# header3
# header4
# header5
# header6
9.62801364263e-07 <----- first line to be read
-5.02069203805e-06
1.25268783953e-05
-1.99324417376e-05
..
..
..

Jan Vorbrüggen

2005-09-12, 7:59 am

You just read them, either with an empty format statement, or using a
character variable of arbitraty length with an A format.

Jan
David Frank

2005-09-12, 7:59 am


"Ralf Schaa" <schaa@geo.uni-koeln.de> wrote in message
news:1126514662.123004.40300@g14g2000cwa.googlegroups.com...
> Hi all,
>
> I like to read an ascii file which has e.g. 5 header lines; beneath
> that the data follows. How can I read the file starting at the
> data-line?
>
> Cheers
> -Ralf
>
> # header1
> # header2
> # header3
> # header4
> # header5
> # header6
> 9.62801364263e-07 <----- first line to be read
> -5.02069203805e-06
> 1.25268783953e-05
> -1.99324417376e-05
> .


do n = 1,5 ! skip 5 records from file #1
read(1,*)
end do



Michael Metcalf

2005-09-12, 6:58 pm


"Ralf Schaa" <schaa@geo.uni-koeln.de> wrote in message
news:1126514662.123004.40300@g14g2000cwa.googlegroups.com...
> Hi all,
>
> I like to read an ascii file which has e.g. 5 header lines; beneath
> that the data follows. How can I read the file starting at the
> data-line?


In addition to the other suggestions, don't forget the slash edit
descriptor. The following works for your example (when the sixth header line
is removed(!)):

read (1, '(4/)')
read (1, *) a

Regards,

Mike Metcalf


glen herrmannsfeldt

2005-09-12, 6:58 pm

Michael Metcalf wrote:

(snip)

> In addition to the other suggestions, don't forget the slash edit
> descriptor. The following works for your example (when the sixth header line
> is removed(!)):


> read (1, '(4/)')
> read (1, *) a


When did the repeat specifier get added to /?

Traditionally / was a format item separator, used instead of a comma.
Though it was usually allowed to put commas around /, it wasn't
required. I believe that '(4(/))' would have worked in F66 days,
though.

-- glen

Michael Metcalf

2005-09-12, 6:58 pm


"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:5fOdneCR8unAJ7jeRVn-gg@comcast.com...
> Michael Metcalf wrote:
>
> (snip)
>
>
>
> When did the repeat specifier get added to /?
>


In Fortran 90.

Regards,

Mike Metcalf


Richard E Maine

2005-09-12, 6:58 pm

In article <5fOdneCR8unAJ7jeRVn-gg@comcast.com>,
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

> When did the repeat specifier get added to /?


Never (at least it isn't there in either f77 or f2003; I didn't check
further).

> Traditionally / was a format item separator, used instead of a comma.
> Though it was usually allowed to put commas around /, it wasn't
> required.


"Traditionally" here means f66, at least in terms of standards. In f77
and later, the "/" was recategorized as an edit descriptor, although a
nonrepeatable one in f77. ("Nonrepeatable got broken up into "control"
and "character string" in f90, but they still aren't repeatable). It is
a special case of edit descriptor in that the commas are optional, but
it is now categorized as an edit descriptor instead of a separator.

> I believe that '(4(/))' would have worked in F66 days, though.


Probably, though I didn't bother to check the old fine print to make
sure. It will work today.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Richard E Maine

2005-09-12, 6:58 pm

In article <gajVe.31269$%w.4053@twister.nyc.rr.com>,
"Michael Metcalf" <michaelmetcalf@compuserve.com> wrote:

> "glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
> news:5fOdneCR8unAJ7jeRVn-gg@comcast.com...


>
> In Fortran 90.


It did? Ah. Oops. So I see. Although / is a control-edit-descriptor in
f90, and you can't have a repeat in front of a control-edit-descriptor,
I see that the / actually has a repeat as an optional part of the
specifier itself. I missed that last bit in a quick skim. (So my other
post saying that it never got added was wrong.)

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com