| View previous topic :: View next topic |
| Author |
Message |
StamK
Joined: 12 Oct 2016 Posts: 171
|
Posted: Sun Nov 09, 2025 8:11 pm Post subject: SIZE keyword in INQUIRE |
|
|
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 |
|
 |
StamK
Joined: 12 Oct 2016 Posts: 171
|
Posted: Sun Nov 09, 2025 8:12 pm Post subject: |
|
|
| 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 |
|
 |
StamK
Joined: 12 Oct 2016 Posts: 171
|
Posted: Sun Nov 09, 2025 8:14 pm Post subject: |
|
|
It fails also when accessing via unit number
INQUIRE(UNIT=iunit, EXIST=fexists, SIZE=fsize, IOSTAT=ios) |
|
| Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 862 Location: Lanarkshire, Scotland.
|
Posted: Mon Nov 10, 2025 12:32 am Post subject: |
|
|
| The SIZE= specifier was added to the INQUIRE statement in Fortran 2003, i.e. after the Fortran 95 standard. |
|
| Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8302 Location: Salford, UK
|
Posted: Mon Nov 10, 2025 8:23 am Post subject: |
|
|
| Thank you for the feedback. I have made a note that these issues need investigating. |
|
| Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8302 Location: Salford, UK
|
Posted: Mon Nov 10, 2025 8:30 am Post subject: |
|
|
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 |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 862 Location: Lanarkshire, Scotland.
|
Posted: Mon Nov 10, 2025 11:09 am Post subject: |
|
|
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 |
|
 |
Robert

Joined: 29 Nov 2006 Posts: 462 Location: Manchester
|
Posted: Mon Nov 10, 2025 3:48 pm Post subject: Re: |
|
|
| 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 |
|
 |
StamK
Joined: 12 Oct 2016 Posts: 171
|
Posted: Mon Nov 10, 2025 9:10 pm Post subject: |
|
|
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 |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2627 Location: Sydney
|
Posted: Tue Nov 11, 2025 2:47 am Post subject: Re: |
|
|
| 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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8302 Location: Salford, UK
|
Posted: Wed Nov 19, 2025 12:19 pm Post subject: |
|
|
INQUIRE(SIZE=fsize....) has now been added for the next release of FTN95 and its library. It has been tested for INQUIRE by UNIT number and by FILE name.
FILE_SIZE@ can be expected to fail if the file is already open via Fortran OPEN or via OPENR@ etc. |
|
| Back to top |
|
 |
|