Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

How to get filesize?

onkelhotte
New Contributor II
604 Views

Hi there,

I need to know the size of a file. I cant use Win32 for this because the code needs to run on windows and vms. SoI need a fortran specific way...

Thanks in advance,
Markus

0 Kudos
1 Reply
Steven_L_Intel1
Employee
604 Views
The only way that would work across those two systems is to open the file, read all the records and sum the size. If it is a formatted file and you don't want to count record separators (Windows), then something like this would work (I think)

SIZE=0
DO
READ (1,'(Q)',IOSTAT=IOS) RSIZE
IF (IOS /= 0) EXIT
SIZE = SIZE + RSIZE
END DO

Q is an extension that causes the number of unread bytes remaining in the record to be assigned to the next variable in the I/O list. It is supported by DEC/Compaq Fortran on VMS and by Intel Fortran.

If it is an unformatted file, this is harder.

An alternative is to write a utility routine to get the file size and use conditional compilation in that routine to use an OS-specific method.


0 Kudos
Reply