Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
EOF idiom?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bruce Bowler  
View profile  
 More options Apr 24 2009, 8:30 am
Newsgroups: comp.lang.fortran
From: Bruce Bowler <bbow...@bigelow.org>
Date: 24 Apr 2009 12:30:31 GMT
Local: Fri, Apr 24 2009 8:30 am
Subject: EOF idiom?
What's the (standard conforming) Fortran 95 way to deal with

10 read (blah,end=20)
   process stuff
   goto 10
20 close (blah)

In many other languages I'd do something like

read (blah)
do while not eof(blah)
  process stuff
  read (blah)
end do

but there doesn't seem to be an eof function in Fortran

Thanks
Bruce


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
feenberg  
View profile  
 More options Apr 24 2009, 9:01 am
Newsgroups: comp.lang.fortran
From: feenberg <feenb...@gmail.com>
Date: Fri, 24 Apr 2009 06:01:34 -0700 (PDT)
Local: Fri, Apr 24 2009 9:01 am
Subject: Re: EOF idiom?
On Apr 24, 8:30 am, Bruce Bowler <bbow...@bigelow.org> wrote:

> What's the (standard conforming) Fortran 95 way to deal with

> 10 read (blah,end=20)
>    process stuff
>    goto 10
> 20 close (blah)

That's the way I do it.

> In many other languages I'd do something like

> read (blah)
> do while not eof(blah)
>   process stuff
>   read (blah)
> end do

> but there doesn't seem to be an eof function in Fortran

The advantage of end= over eof(unit) is that the read statement
doesn't need to be repeated.
I'd say that was a real advantage in terms of "edit sensitivity". I
agree the statement numbers are
primitive.

I expect that somehow the INQUIRE statement can be used to create and
eof function (perhaps
with the POSITION qualifier equal to "APPEND"), but I haven't tried
that.

Daniel Feenberg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
michaelmetc...@compuserve.com  
View profile  
 More options Apr 24 2009, 9:01 am
Newsgroups: comp.lang.fortran
From: michaelmetc...@compuserve.com
Date: Fri, 24 Apr 2009 06:01:35 -0700 (PDT)
Local: Fri, Apr 24 2009 9:01 am
Subject: Re: EOF idiom?
On Apr 24, 2:30 pm, Bruce Bowler <bbow...@bigelow.org> wrote:

integer :: stat
do
   read(blah, iostat=stat)
   if(stat /= 0) exit
   process stuff
end do
close(blah)

This catches all conditions, not just EOF. If you want only that, then
end=label can be used, but that requires, yes, a label.

Regards,

Mike Metcalf


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jugoslav Dujic  
View profile  
 More options Apr 24 2009, 9:02 am
Newsgroups: comp.lang.fortran
From: Jugoslav Dujic <jdu...@yahoo.com>
Date: Fri, 24 Apr 2009 15:02:53 +0200
Local: Fri, Apr 24 2009 9:02 am
Subject: Re: EOF idiom?

Bruce Bowler wrote:
> What's the (standard conforming) Fortran 95 way to deal with

> 10 read (blah,end=20)
>    process stuff
>    goto 10
> 20 close (blah)

Well, the above is also a Fortran-95 way, but if you want to
avoid that abominable disgusting considered harmful
<small>just kidding</small> goto, you can do:

do
    read(blah, end=20)
    process stuff
end do
20 close(blah)

and in order to avoid that abominable disgusting label, you
can do:

Reading_loop: &
do
    read(blah, iostat=ierr)
    if (ierr<0) then
       exit Reading_loop
    else if (ierr>0) then
      stop "Sorry, I'm afraid that the file format is &
                  ¬ what I expected"
    end if
    process stuff
end do Reading_loop  !Named do-loop for extra points in fanciness
close(20)

--
Jugoslav
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ron Shepard  
View profile  
 More options Apr 24 2009, 3:36 pm
Newsgroups: comp.lang.fortran
From: Ron Shepard <ron-shep...@NOSPAM.comcast.net>
Date: Fri, 24 Apr 2009 14:36:42 -0500
Local: Fri, Apr 24 2009 3:36 pm
Subject: Re: EOF idiom?
In article <75dpn7F17gd1...@mid.individual.net>,
 Bruce Bowler <bbow...@bigelow.org> wrote:

> What's the (standard conforming) Fortran 95 way to deal with

> 10 read (blah,end=20)
>    process stuff
>    goto 10
> 20 close (blah)

I think this approach would work in any version of fortran since f77,
including f95.

> In many other languages I'd do something like

> read (blah)
> do while not eof(blah)
>   process stuff
>   read (blah)
> end do

You could do the same thing in f95.  Instead of eof(), you would check
the iostat value, but it is the same structure.  The esthetic problem
with this is that you have two read statements while one would suffice

Or, if you don't like "do while" (and many programmers don't), you could
write it with a single read statement as

do
   read(...,iostat=ioval)...
   if(ioval .ne. 0) exit
   process stuff
enddo

At least to my eye, that looks simpler and cleaner than your code above.  
It doesn't do exactly the same thing (it catches both eof and error
conditions), but you could generalize the test a little if appropriate.

$.02 -Ron Shepard


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giorgio Pastore  
View profile  
 More options Apr 24 2009, 4:41 pm
Newsgroups: comp.lang.fortran
From: Giorgio Pastore <past...@units.it>
Date: Fri, 24 Apr 2009 22:41:39 +0200
Local: Fri, Apr 24 2009 4:41 pm
Subject: Re: EOF idiom?
michaelmetc...@compuserve.com wrote:

...

>    read(blah, iostat=stat)
>    if(stat /= 0) exit
...
> This catches all conditions, not just EOF. If you want only that, then
> end=label can be used, but that requires, yes, a label.

Or, if the compiler is 2003 compliant, by using iso_fortran_env
intrinsic module, one could just write:

read(blah, iostat=stat)
if(stat==iostat_end)exit

which allows to detect the end-of-file condition only.

Giorgio


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Apr 24 2009, 5:25 pm
Newsgroups: comp.lang.fortran
From: nos...@see.signature (Richard Maine)
Date: Fri, 24 Apr 2009 14:25:23 -0700
Local: Fri, Apr 24 2009 5:25 pm
Subject: Re: EOF idiom?

Even without that constant, you could just check for iostat<0, as the
only other possible iostat value <0 is for end-of-record, which applies
only to non-advancing I/O.

However, in either case, note that I strongly recomend against having an
iostat specifier and then ignoring some of its possible values. If you
hit an error, you will just cover up its immediate symptoms, turning
them into more confusing later ones. Odds are that you don't want to do
the same thing for an error as for an end-of-file, but don't just ignore
it completely.

--
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »