Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inquire size of a file

364 views
Skip to first unread message

Philippe-A. Bourdin

unread,
Mar 17, 2010, 11:54:17 AM3/17/10
to
Hello all,

just a simple question: how to inquire the file size of a given file?
As I heard (from intel support), it should work in ifort like this:
> integer :: n_chars
> inquire (file='foobar', size=n_chars)
But if I try this in gfortran 4.4 I always only get 32767 as result!
(This inquire usage is supposed to be Fortran 2003 standard.)

On the other hand, one was able to use the intrinsic STAT in gfortran,
since long time. But in the end I need a code, that runs on many
compilers... So, could someone with access to gfortran file a bug
report, or am I simply doing something wrong, here?

Thanks and best regards,
Philippe Bourdin.

Terence

unread,
Mar 17, 2010, 6:54:21 PM3/17/10
to
On Mar 18, 2:54 am, "Philippe-A. Bourdin" <bourdin....@googlemail.com>
wrote:

With all the SPAM I don't know have many members are still looking.
My guesses (only) are
1) the file doesn't exist and 7FFFh is a sign for this
2) n_chars is not integer(4)

I alwats get that information via a service call in DVF (taken over
and replaced with ifort by Intel).

Jason Blevins

unread,
Mar 17, 2010, 9:41:57 PM3/17/10
to

I've replicated this issue. The 32767 doesn't seem to be important
since the variable simply wasn't initialized. Here's my complete code
(initializing to 0):

program file_size
implicit none

integer :: sz = 0

print '("inquire by unit")'
open(15, FILE='foobar')
inquire(UNIT=15, SIZE=sz)
print '("size is ", i9, " bytes")', sz
close(15)

print '("inquire by file")'
inquire(FILE='foobar', SIZE=sz)
print '("size is ", i9, " bytes")', sz
end program file_size

The file 'foobar' exists and is 42 bytes in size.

% ifort --version
ifort (IFORT) 11.1 20090630
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.
% ifort -stand=f03 -o size size.f90
% ./size
inquire by unit
size is 42 bytes
inquire by file
size is 42 bytes

However:

% % gfortran --version
GNU Fortran (Debian 4.4.3-3) 4.4.3
Copyright (C) 2010 Free Software Foundation, Inc.
[...]
% gfortran -std=f2003 -o size size.f90
roark /tmp % ./size
inquire by unit
size is 0 bytes
inquire by file
size is 0 bytes

This is all on GNU/Linux with an x86_64 machine. As far as I could
tell at least, this seems to be correct usage of inquire. Maybe the
SIZE argument isn't being handled in gfortran? I dug around in the
source, but I got in over my head pretty quickly!

Jason

Richard Maine

unread,
Mar 17, 2010, 11:19:57 PM3/17/10
to
Jason Blevins <jrbl...@sdf.lonestar.org> wrote:

> > On Mar 18, 2:54Â am, "Philippe-A. Bourdin" <bourdin....@googlemail.com>
> > wrote:

> >> > inquire (file='foobar', size=n_chars)
> >>
> >> But if I try this in gfortran 4.4 I always only get 32767 as result!
> >> (This inquire usage is supposed to be Fortran 2003 standard.)

> This is all on GNU/Linux with an x86_64 machine. As far as I could


> tell at least, this seems to be correct usage of inquire. Maybe the
> SIZE argument isn't being handled in gfortran?

While it looks to be correct usage, Jason's observation that it is an
f2003 feature is also correct. It is not a standard f95 feature (unless
my eyes crossed while checking, but I did check twice).

Of course, nothing stops an f95 compiler from having some selected f2003
features such as this, but it isn't something you can take as a given.
It also seems reasonably plausible that it might be a feature relatively
newly added and thus not as thoroughly checked out as the older ones.

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

Tobias Burnus

unread,
Mar 18, 2010, 3:09:01 AM3/18/10
to
Philippe-A. Bourdin wrote:
> just a simple question: how to inquire the file size of a given file?
> As I heard (from intel support), it should work in ifort like this:
>> integer :: n_chars
>> inquire (file='foobar', size=n_chars)
> But if I try this in gfortran 4.4 I always only get 32767 as result!
> (This inquire usage is supposed to be Fortran 2003 standard.)

I have checked the source code of gfortran's run-time library (RTL;
"libgfortran") and it does not handle size= in INQUIRE at all; I assume
that the front-end handles it because size= is also supported in
transfer statements, which works (or at least is implemented in the RTL).

Seemingly, no one ever used that feature the last ~5 years. I have
filled a bugreport and think it will be fixed in the next few weeks for
GCC 4.5. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43409

As a non-standard work around: gfortran supports - as you already wrote
- the (F,L)STAT intrinsics, but this is of not very portable.

Tobias

Tobias Burnus

unread,
Mar 20, 2010, 1:53:27 PM3/20/10
to
Tobias Burnus wrote:
> Philippe-A. Bourdin wrote:
>
>> just a simple question: how to inquire the file size of a given file?
>> As I heard (from intel support), it should work in ifort like this:
>>
>>> integer :: n_chars
>>> inquire (file='foobar', size=n_chars)
>>
>> But if I try this in gfortran 4.4 I always only get 32767 as result!
>> (This inquire usage is supposed to be Fortran 2003 standard.)
>
> I have checked the source code of gfortran's run-time library (RTL;
> "libgfortran") and it does not handle size= in INQUIRE at all;

This has been fixed today for GCC 4.5. Thanks for the report!

Tobias

Phred Phungus

unread,
Mar 25, 2010, 8:42:33 PM3/25/10
to

Also, tja. Ich wette dass Du bei gfortran im Kaeferfixwettzeug in
diesem Entwicklungsjahr erst dran bist.
--
froederich

0 new messages