From: Philippe-A. Bourdin on
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.
From: Terence on
On Mar 18, 2:54 am, "Philippe-A. Bourdin" <bourdin....(a)googlemail.com>
wrote:
> 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.

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).
From: Jason Blevins on
On 2010-03-17, Terence <tbwright(a)cantv.net> wrote:
> On Mar 18, 2:54 am, "Philippe-A. Bourdin" <bourdin....(a)googlemail.com>
> wrote:
>> 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.
>
> 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).

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
From: Richard Maine on
Jason Blevins <jrblevin(a)sdf.lonestar.org> wrote:

> > On Mar 18, 2:54� am, "Philippe-A. Bourdin" <bourdin....(a)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
From: Tobias Burnus on
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
 |  Next  |  Last
Pages: 1 2
Prev: Best way for integer division
Next: oo fortran