how to handle reading empty file

  • Follow


hi,
I wish to read files, but also to be able to handle empty files since
so far the prog gives me a floating exception error and stops whenever 
it encounters such a file.
so, I basically wish to identify an empty file, state it is empty, and 
go on to the next file, the lot without crashing.

any ideas ?

many thanks!

G.
0
Reply tperzo (4) 12/31/2003 11:33:03 AM

On Wed, 31 Dec 2003 11:33:03 +0000, news <tperzo@wanadoo.fr>
 wrote in <bsu8og$52s$1@news-reader4.wanadoo.fr>:
> hi,
> I wish to read files, but also to be able to handle empty files since
> so far the prog gives me a floating exception error and stops whenever 
> it encounters such a file.
> so, I basically wish to identify an empty file, state it is empty, and 
> go on to the next file, the lot without crashing.

	What statement are you using to read the files?  Are you aware of
the END and ERR keywords in the READ statement?

-- 
Ivan Reid, Electronic & Computer Engineering,     ___     CMS  Collaboration,
Brunel University.     Ivan.Reid@brunel.ac.uk             Room 40-1-B12, CERN
        KotPT -- "for stupidity above and beyond the call of duty".
0
Reply Ivan.Reid (496) 12/31/2003 12:54:44 PM


"news" <tperzo@wanadoo.fr> wrote in message
news:bsu8og$52s$1@news-reader4.wanadoo.fr...
> hi,
> I wish to read files, but also to be able to handle empty files
since
> so far the prog gives me a floating exception error and stops
whenever
> it encounters such a file.
> so, I basically wish to identify an empty file, state it is empty,
and
> go on to the next file, the lot without crashing.
>
> any ideas ?
>
> many thanks!
>
> G.
>

f2003
   inquire (file='anyfile',size=isize)
   if (isize == 0) then

cvf
   open (1,file='anyfile',position='append')
   if (ftell(1) == 0) then


0
Reply dave_frank (2243) 12/31/2003 12:56:25 PM

Dr Ivan D. Reid wrote:

> On Wed, 31 Dec 2003 11:33:03 +0000, news <tperzo@wanadoo.fr>
>  wrote in <bsu8og$52s$1@news-reader4.wanadoo.fr>:
>> hi,
>> I wish to read files, but also to be able to handle empty files since
>> so far the prog gives me a floating exception error and stops whenever
>> it encounters such a file.
>> so, I basically wish to identify an empty file, state it is empty, and
>> go on to the next file, the lot without crashing.
> 
> What statement are you using to read the files?  Are you aware of
> the END and ERR keywords in the READ statement?
> 
open (unit=30,file="masterfile.dat")
read (30,*,END=805) filename

here the name contained in filename is in masterfile.dat
yes I have heard of the ERR command, but it does not seem to be recognized
by f77 under linux. (mandrake 9.1)
0
Reply igthibau (46) 1/2/2004 11:42:50 PM

igthibau <igthibau@wanadoo.fr> writes:

> yes I have heard of the ERR command, but it does not seem to be recognized
> by f77 under linux. (mandrake 9.1)

That seems unlikely.  It is standard f77, and I'm quite sure that I have
used it with g77 (which is what you'd presumably have as the f77 in
that distribution).  However, do note

1. It isn't a command (or statement either).  It is just a keyword,
   like the end=.  I assume you are probably using the wrong
   terminology, but occasionally it is worth checking assumptions
   like that, because sometimes the assumptions are wrong.

2. More likely to be your problem - hitting and end of file does not
   count as an error.

I really have trouble believing that the compiler doesn't recognize
a syntactically correct err=.  If it compiles without error, then
the compiler recognized it.  If it gives a compilation error message,
then I'd like to see the code and message; my natural assumption
would be that there was a syntax error...perhaps you spelled it error=
instead of err=, or perhaps you gave it a variable name (like
iostat= needs) instead of a statement number.

-- 
Richard Maine
email: my last name at domain
domain: sumertriangle dot net
0
Reply nospam47 (9742) 1/3/2004 3:08:08 AM

On Fri, 02 Jan 2004 23:42:50 +0000, igthibau <igthibau@wanadoo.fr>
 wrote in <bt4svo$elr$1@news-reader2.wanadoo.fr>:
> Dr Ivan D. Reid wrote:

>> What statement are you using to read the files?  Are you aware of
>> the END and ERR keywords in the READ statement?

> open (unit=30,file="masterfile.dat")
> read (30,*,END=805) filename
           ^
           |
> here the name contained in filename is in masterfile.dat
> yes I have heard of the ERR command, but it does not seem to be recognized
> by f77 under linux. (mandrake 9.1)

	Many of the problems seen here result from using wildcarded I/O
statements.  This could be one of them.  Whereas formatted read statements
will read the exact number of records specified, wildcarded reads will
keep trying to read new records until the input-variable list is satisfied.
This may not give the behaviour that is required (especially for a
character variable, as appears to be the case here).

	IF YOU CARE ABOUT THE BEHAVIOUR, ALWAYS USE EXPLICIT FORMAT!

-- 
Ivan Reid, Electronic & Computer Engineering,     ___     CMS  Collaboration,
Brunel University.     Ivan.Reid@brunel.ac.uk             Room 40-1-B12, CERN
        KotPT -- "for stupidity above and beyond the call of duty".
0
Reply Ivan.Reid (496) 1/3/2004 8:55:32 AM

5 Replies
56 Views

(page loaded in 0.119 seconds)

Similiar Articles:













7/22/2012 2:41:27 PM


Reply: