Jump to content

File size: Difference between revisions

m
No edit summary
Line 478:
 
=={{header|Fortran}}==
 
Since Fortran 95 the size of standard external files may be determined simply by using INQUIRE(SIZE=...).
The following previous example pertains to FORTRAN 77 and is now superceded.
<lang Fortran>
 
use :: iso_fortran_env, only : FILE_STORAGE_SIZE
implicit none
character(len=*),parameter :: filename(*)=[character(len=256) :: 'input.txt', '/input.txt']
integer :: file_size, i
do i=1,size(filename)
INQUIRE(FILE=filename(i), SIZE=file_size) ! return -1 if cannot determine file size
write(*,*)'size of file '//trim(filename(i))//' is ',file_size * FILE_STORAGE_SIZE /8,' bytes'
enddo
end
</lang>
 
The original example, now obsolete ...
 
Alas, although there is a statement <code>INQUIRE(FILE="Input.txt",EXIST = ISTHERE, RECL = RL, ''etc.'')</code> whereby a logical variable ISTHERE has a value (output: assigned left-to-right) according to whether a named file (input: assignment right-to-left) exists or not, and the parameter RECL returns the maximum allowed record length for the file, there is no parameter that reports how many records there are in the file so that the file size remains unknowable. Further, the value returned by RECL is not necessarily related to the file itself, but is likely to be a standard value such as 132, a default used when deciding on the line wrap length with free-format output as in <code>WRITE (6,*) stuff</code> but not necessarily being a limit on the length of a line written or read.
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.