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

Counting records in files

kdkeefer
Beginner
350 Views
Hi,
I have a formatted file containing 1000-2000 records. I would like to ALLOCATE an array for these numbers, but I don't know how many are in the file. The standard techniques I'm familiar with are either to write the number of records in the title line of the file (it gets read by Excel also) or to read records from the file with no input list and count the number that have been read when EOF is reached. These date from the '70's. Are there more intelligent/sophisticated/elegant solutions to the problem now?
Regards,
Keith
0 Kudos
1 Reply
emc-nyc
Beginner
350 Views
I suspect that counting lines is the only way to go. After all, the file systems used by Windows (and Linux and U*x) don't really have the concept of a 'record', so the only way to find out how many records there are in a file is to count end-of-line markers.

On other o/s, such as VMS or MVS, some files have fixed length records, so the number of records is just file size divided by record length.
0 Kudos
Reply