Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get binary file size

Status
Not open for further replies.

gmauger

Technical User
Jun 28, 2006
1
US
Hi,

I have a simple script that reads binary files (unformatted, direct access). I'd like to generalize this program to accept any fortran file and internally determine the size of the array (assuming 4 bytes per number). The program currently has a parameter that sets the size (number of records) in the file to be read.

The best way I can think to do this would be to use a function that returns the size of a file, in bytes or record lengths, given an input file.

Does anyone know of such a function, or how to write one, or have any other solution?

thanks,
guillaume
 
It depends on which implementation of Fortran you're using. Some versions have service functions like fstat, lstat or stat which might enable you to find the file size but these are by no means standard.

Alternatively you can use system to execute some OS command to put the file size in a file and then read that file. A bit of a roundabout way of doing it but there is no standard way of doing this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top