Find input file size in Fortran 90

2019-09-13 19:30发布

问题:

I'm trying to create a progress indicator based on the total file size vs. file size read so far. I am working with a binary file.

open(unit=unitvector, file=vectorname, status='old',form='unformatted')
do while (ios.eq.0)
    read(unitvector,end=888,err=888, iostat=ios) KX, KY, KZ, KNAME, NV, NE, WEIGHT
    nkcount=nkcount+1
    call progress(FILE SIZE, PROGRESS SIZE)
    allocate( Vector(3,NV) )
    read(unitvector) (Vector(1,I),Vector(2,I),Vector(3,I),I=1,NV)
.
.
.
 end do

To compile i use:

ifort -warn all -traceback -free util.F fold2Bloch.f90 -o fold2Bloch

So every iteration of the loop I would call the subroutine progress and send the total file size and the size read so far. How can you find out the total size and size read so far? Or is there a better way to approach this progress indicator idea?

回答1:

To find the size (in bytes) of a file use the following:

inquire(unitvector, size=tot_len)

However, i still have no idea how to figure out what byte the pointer is at after a read() instruction. Please help.