Data I/O problems in FORTRAN 77

In summary, the conversation discusses a problem with reading and writing data from a file using a specific code. The issue is identified as an incorrect input format and a solution is suggested using list-directed input. The conversation also mentions potential issues with the output file status.
  • #1
Ashiley
1
0
Hello, every one:

I have a piece of data like this:

1999 1 1 0.0 1 1.0000000e+00 -9.9900000e+02 4.8646021e-01 0
1999 1 1 0.5 1 1.0208334e+00 -9.9900000e+02 4.9180925e-01 0
1999 1 1 1.0 1 1.0416666e+00 -9.9900000e+02 3.7898308e-01 0
1999 1 1 1.5 1 1.0625000e+00 -9.9900000e+02 3.5607040e-01 0

The first three column are integers, as well as the fifth (three digits) and the last one (one digit). I put them into a data file: x.dat and tried to read them in and output to another data file: y.dat, in which there is a comma between two columns.

I used the following code but got error:
INTEGER A(4), B(4), C(4), D(4), E(4)
REAL F(4)
DOUBLE PRECISION S1(4), S2(4), S3(4)

OPEN (66, FILE = 'x.dat', STATUS = 'OLD')
OPEN (9, FILE = 'y.dat', STATUS = 'NEW')

READ (66, 20) A(1), B(1), C(1), F(1), D(1), S1(1), S2(1), S3(1), E(1)
20 FORMAT(I4, I2, I2, F4.1, I3, 3E13.7, I1)

WRITE(9, 30) S1(1), S2(1), S3(1)

30 FORMAT(3(E13.7, ','))

I didn't read all data in but the first row and I have error message:
"writing sequential formatted external I0"
"Aborted"

Could some one here point out my mistakes? Thank you!

Ashiley
 
Technology news on Phys.org
  • #2
If the data you posted was an accurate cut-and-paste from the file, your input format is wrong - specifically "3E13.7" doesn't match the file. The second number is 14 characters long, and there are also blanks between the numbers.

Assuming the data values are always separated by blanks, it's easier to use list-directed (or free format) input.
READ (66, *) A(1), B(1), C(1), F(1), D(1), S1(1), S2(1), S3(1), E(1)
No FORMAT statement required.

Trying to open the output file with status='new' won't work if the file already exists, i.e. the program might work the first time you run it, but not second time. Unless you really want to protect yourself from accidentally overwriting an existing file, the default status='unknown' works fine. It either creates a new file, or overwrites an existing one.
 

Related to Data I/O problems in FORTRAN 77

What is a Data I/O problem in FORTRAN 77?

A Data I/O (input/output) problem in FORTRAN 77 refers to any issue that occurs when reading or writing data in a FORTRAN 77 program. This can include incorrect data being read or written, data not being read or written at all, or errors in the formatting of the data.

What are the common causes of Data I/O problems in FORTRAN 77?

Some common causes of Data I/O problems in FORTRAN 77 include incorrect data types being used, incorrect file specifications, and errors in the program logic. It is also important to ensure that the data is formatted correctly and that the file being accessed is in the correct location.

How can I troubleshoot Data I/O problems in FORTRAN 77?

To troubleshoot Data I/O problems in FORTRAN 77, you can check for errors in the code, make sure the correct data types and file specifications are being used, and ensure that the data is properly formatted. You can also use debugging tools or print statements to track the flow of data through the program.

What are some best practices for avoiding Data I/O problems in FORTRAN 77?

To avoid Data I/O problems in FORTRAN 77, it is important to carefully plan and design your program before writing any code. This includes choosing appropriate data types, using standard file specifications, and properly formatting your data. Additionally, regularly testing and debugging your code can help catch any potential issues early on.

Are there any specific techniques for handling Data I/O problems in FORTRAN 77?

One technique for handling Data I/O problems in FORTRAN 77 is to use error handling mechanisms, such as error trapping or exception handling, to detect and handle any issues that may arise during data input or output. Another technique is to use file processing routines, such as OPEN, CLOSE, READ, and WRITE, to properly manage data access and avoid errors.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
Replies
58
Views
3K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top