forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SIZE keyword in INQUIRE

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
StamK



Joined: 12 Oct 2016
Posts: 171

PostPosted: Sun Nov 09, 2025 8:11 pm    Post subject: SIZE keyword in INQUIRE Reply with quote

As per code below, Ftn95doesn't support the SIZE keyword in INQUIRE statements. This is quite important I think.

Code:

PROGRAM TEST_INQUIRE_SIZE
    IMPLICIT NONE
    INTEGER :: fsize, ios
    LOGICAL :: fexists

    INQUIRE(FILE='test_inquire_size.f90', EXIST=fexists, SIZE=fsize, IOSTAT=ios)

    WRITE(*,*) 'File exists:', fexists
    WRITE(*,*) 'File size:', fsize
    WRITE(*,*) 'IOSTAT:', ios

END PROGRAM
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 171

PostPosted: Sun Nov 09, 2025 8:12 pm    Post subject: Reply with quote

Also FILE_SIZE@ and FILE_SIZE8@ seem to fail with files that are already open , so they cannot be used unless we close the file in question file first.
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 171

PostPosted: Sun Nov 09, 2025 8:14 pm    Post subject: Reply with quote

It fails also when accessing via unit number
INQUIRE(UNIT=iunit, EXIST=fexists, SIZE=fsize, IOSTAT=ios)
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 858
Location: Lanarkshire, Scotland.

PostPosted: Mon Nov 10, 2025 12:32 am    Post subject: Reply with quote

The SIZE= specifier was added to the INQUIRE statement in Fortran 2003, i.e. after the Fortran 95 standard.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8290
Location: Salford, UK

PostPosted: Mon Nov 10, 2025 8:23 am    Post subject: Reply with quote

Thank you for the feedback. I have made a note that these issues need investigating.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8290
Location: Salford, UK

PostPosted: Mon Nov 10, 2025 8:30 am    Post subject: Reply with quote

StamK

FILE_SIZE@ works for me when the file is open in the editor.
Can you provide sample code with the context where it does not work.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 858
Location: Lanarkshire, Scotland.

PostPosted: Mon Nov 10, 2025 11:09 am    Post subject: Reply with quote

An alternative is to use fileinfo@ which works as shown below.
Code:
program test_inquire_size
    implicit none
    character(260) :: path
    integer(2) :: mode, dev, rdev, nlink, err
    integer(3) :: size, atime, mtime, ctime
    logical :: fexists
   
    path = 'freeformat1.f95'

    inquire(file=path, exist=fexists)
    if (.not. fexists) then
        print *, 'File does not exist.'
        stop
    end if

    call fileinfo@(trim(path)//char(0), mode, dev, rdev, nlink, size, atime, mtime, ctime, err)

    if (err .eq. 0) then
        print *, 'File exists:', fexists
        print *, 'File size (bytes):', size
        print *, 'Access time:', atime
        print *, 'Modified time:', mtime
        print *, 'Creation time:', ctime
    else
        print *, 'Error reading file info. Error code:', err
    end if
end program


Code:
 File exists:  T
 File size (bytes):         800
 Access time:  1762769130
 Modified time:  1762769130
 Creation time:  1760533762

C:\Arcadis 2025\0008
Back to top
View user's profile Send private message
Robert



Joined: 29 Nov 2006
Posts: 462
Location: Manchester

PostPosted: Mon Nov 10, 2025 3:48 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
StamK

FILE_SIZE@ works for me when the file is open in the editor.
Can you provide sample code with the context where it does not work.


StamK probably means open in the fopen sense. It doesn't seem unreasonable it wouldn't work especially if the file was open for writing.
Back to top
View user's profile Send private message Visit poster's website
StamK



Joined: 12 Oct 2016
Posts: 171

PostPosted: Mon Nov 10, 2025 9:10 pm    Post subject: Reply with quote

Yes, I meant in the fopen sense.
Regarding using fileinfo@ it would be possible in theory, but haven't tested if it fails for open files.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2625
Location: Sydney

PostPosted: Tue Nov 11, 2025 2:47 am    Post subject: Re: Reply with quote

StamK wrote:
It fails also when accessing via unit number
INQUIRE(UNIT=iunit, EXIST=fexists, SIZE=fsize, IOSTAT=ios)


My understanding is that INQUIRE ( ...,SIZE=... ) was included in Fortran 03 to support stream access.
Perhaps this support could be included as FTN95 now supports stream access, including files/records larger than 2GBytes.
Stream access is a very useful file access approach which is very portable between compilers, unlike Fortran unformatted file types.

Using stream access, you can also generate your own record headers/footers to replicate your preferred or other Fortran compiler's unformatted record structures. But be warned, with unformatted records larger than 2 GBytes, the record structures of other compilers become very messy.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group