Problems reading binary file in FORTRAN

In summary, The user is having trouble reading a binary file in FORTRAN that was generated using the code provided. They have tried reading the file using a different code with consistent data types and sizes, but it crashes after 256 iterations. The error message received is "forrtl: severe (67): input statement requires too much data". The user also mentions trying different input files and options for the CONVERT specifier, but the issue persists. They are using Compaq Visual Fortran 6.5 as their compiler.
  • #1
marcelosousa1
1
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
  • #2
Have you checked that it creates a file of the correct size before you try to read the data back?
 
  • #3


I understand the frustration of encountering errors while trying to read a binary file in FORTRAN. It is important to carefully check the data types and sizes of the variables used in both the writing and reading processes to ensure compatibility. In this case, it seems that the issue may lie in the way the file was written. The code provided for writing the file uses the "unformatted" form, which means that the data is written without any additional formatting information. This can sometimes cause issues when trying to read the file, as the program may not know how to properly interpret the data.

I would suggest trying to write the file using the "formatted" form, which includes additional formatting information that can help with reading the file. Additionally, it may be helpful to check the documentation for your compiler to see if there are any specific options or settings that need to be used when reading unformatted files.

If the issue persists, it may also be helpful to reach out to your compiler's support team for further assistance. They may have more specific insights or suggestions on how to resolve this issue.

In general, when encountering errors while reading binary files in FORTRAN, it is important to carefully check the code for any potential issues with data types, sizes, and formatting. It may also be helpful to use debugging tools to track the flow of the program and identify where the error is occurring. I hope this information helps and good luck with your research.
 

1. What is a binary file in FORTRAN?

A binary file in FORTRAN is a file that contains data in binary format, which means that the data is stored in a series of 0s and 1s. This format is different from a text file, where the data is stored in human-readable characters.

2. Why would I encounter problems reading a binary file in FORTRAN?

There are several reasons why you may encounter problems reading a binary file in FORTRAN. Some possible reasons include not having the correct file access mode, not properly specifying the data types in the file, or not handling the endianness (the order of the bytes) correctly.

3. How can I fix problems reading a binary file in FORTRAN?

To fix problems reading a binary file in FORTRAN, you should first check that you are using the correct file access mode, such as "read" or "write". Then, make sure that you are properly specifying the data types in the file, such as integers or floating-point numbers. If you are dealing with binary data from another system, you may also need to handle the endianness correctly by using the appropriate conversion functions.

4. Can I use any FORTRAN compiler to read a binary file?

Yes, you can use any FORTRAN compiler to read a binary file. However, different compilers may have different default file access modes or ways of handling binary data, so it is important to consult the compiler's documentation or use compiler-specific functions for reading binary files.

5. Are there any alternative methods for reading a binary file in FORTRAN?

Yes, there are alternative methods for reading a binary file in FORTRAN. Some options include using built-in functions such as "read" or "readf", using external libraries or modules that provide specialized functions for reading binary files, or using low-level I/O routines. It is best to choose the method that is most suitable for your specific application.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
4
Views
740
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
4
Views
605
Back
Top