Problems reading binary file in FORTRAN

Click For Summary
SUMMARY

The discussion centers on issues encountered while reading a binary file in FORTRAN using Compaq Visual Fortran 6.5. The user, Marcelo, successfully writes to the file 'hctd1_kxx.dat' but experiences crashes during the read operation after 256 iterations, despite the expected number of data points being 406924. The error message "forrtl: severe (67): input statement requires too much data" indicates a mismatch between the expected and actual data being read, suggesting potential issues with file size or data type consistency.

PREREQUISITES
  • Understanding of FORTRAN file I/O operations
  • Familiarity with binary file formats in FORTRAN
  • Knowledge of data types in FORTRAN, specifically integer*4 and real*4
  • Experience with error handling in FORTRAN programs
NEXT STEPS
  • Investigate the correct usage of the FORTRAN 'read' statement for binary files
  • Learn about the implications of file size and data type consistency in binary file operations
  • Explore debugging techniques for FORTRAN programs to identify data reading issues
  • Review documentation on Compaq Visual Fortran 6.5 for specific file handling features
USEFUL FOR

This discussion is beneficial for FORTRAN developers, particularly those working with binary file I/O, as well as anyone troubleshooting data reading issues in legacy FORTRAN applications.

marcelosousa1
Messages
1
Reaction score
0
I am having problems reading a binary file in FORTRAN. I know that the file was generated by the code below:

open(7,file='hctd1_kxx.dat',form='unformatted')
...
write(7) iscl
write(7) inode,npoints
write(7) (kxm(i)*(10**(prop(i))),i=1,npoints)
close(7)

iscl, inode, npoints are integer*4 and kxm(), prop() are real*4

I am trying to read the file using the code below (variables have consistent data types and sizes):

open(11,file='hctd1_kxx.dat',status='old', form='unformatted', ACTION='READ')
...
read(7) iscl
read(7) inode,npoints
read(7) (single(i),i=1,npoints)

The program reads OK until it reaches the line above, where it always crashes after performing 256 iterations (it should go to npoints=406924).

I tried different input files and opening the file using different options for the CONVERT specifier and it keeps crashing after the first 256 entries.

The error message I get is the following: "forrtl: severe (67): input statement requires too much data".

Does anyone have any suggestions?

Thanks a lot for your attention!

Marcelo
P.S.: my compiler is Compaq Visual Fortran 6.5
 
Technology news on Phys.org
Have you checked that it creates a file of the correct size before you try to read the data back?
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 33 ·
2
Replies
33
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
1K