Comp Sci Solving FORTRAN Code Error: Is Anything Wrong?

  • Thread starter Thread starter RJLiberator
  • Start date Start date
  • Tags Tags
    Code Fortran
AI Thread Summary
The FORTRAN code encountered a runtime error related to floating-point reading, likely due to issues with the data format in "updateddata.txt." It was suggested to ensure that the arrays MASSNUMBER2 and ABUNDANCE2 are properly declared and that the data file contains at least 146 records formatted correctly. Adjustments to the FORMAT and READ statements were recommended, with a successful change to a simpler READ statement resolving the issue. The discussion highlighted the sensitivity of FORTRAN to data formatting and the importance of matching code expectations with file structure. Ultimately, the code began to run correctly after these modifications.
RJLiberator
Gold Member
Messages
1,094
Reaction score
63

Homework Statement


Working on a FORTRAN based code for some work.
Not sure what's wrong with it.

Homework Equations

The Attempt at a Solution


The section of the code that is causing the problem is:

Code:
  OPEN( UNIT = 17,FILE='updateddata.txt',STATUS='UNKNOWN')
  DO I = 1, 146
  READ( 17, 703) MASSNUMBER2(I), ABUNDANCE2(I)
703  FORMAT( I7, ES15.8)
  WRITE (*,*) MASSNUMBER2(I), ABUNDANCE2(I)
  END DO
  CLOSE ( UNIT = 17 )

My problem is I get a run time error when running the entire code:

At line 31 of Chisquared.f (unit = 17, file='updateddata.txt')
Fortran runtime error: Bad values during floating point readMy question is: Is anything wrong in the fortran code here? Anything noticeable that would cause an error?
 
Physics news on Phys.org
RJLiberator said:

Homework Statement


Working on a FORTRAN based code for some work.
Not sure what's wrong with it.

Homework Equations

The Attempt at a Solution


The section of the code that is causing the problem is:

Code:
  OPEN( UNIT = 17,FILE='updateddata.txt',STATUS='UNKNOWN')
  DO I = 1, 146
  READ( 17, 703) MASSNUMBER2(I), ABUNDANCE2(I)
703  FORMAT( I7, ES15.8)
  WRITE (*,*) MASSNUMBER2(I), ABUNDANCE2(I)
  END DO
  CLOSE ( UNIT = 17 )

My problem is I get a run time error when running the entire code:

At line 31 of Chisquared.f (unit = 17, file='updateddata.txt')
Fortran runtime error: Bad values during floating point readMy question is: Is anything wrong in the fortran code here? Anything noticeable that would cause an error?
Make sure that the arrays MASSNUMBER and ABUNDANCE2 are each declared to have at least 146 members. Make sure MASSNUMBER is type INTEGER and ABUNDANCE2 is type REAL.

Make sure that the data file "updatedata.txt" contains at least 146 records (lines).

If you have fewer than 146 members in each array, then you might want to add the option ERR=label to the READ statement, where label is the statement number for the program to goto if a read error is encountered.

Check the format of the data file "updatedata.txt" to make sure the first 7 columns of each record contain one INTEGER type data and the next 15 columns contain only one floating point number in scientific notation.

It might be a good idea to add the FORM = 'FORMATTED' option to the OPEN statement, to make sure the program knows what type of data to expect. You can also add the option ACCESS = 'SEQUENTIAL' for a regular text file of ASCII data.

The code tags must be in ALL CAPS in order to be recognized properly.
 
  • Like
Likes RJLiberator
Thanks for the pretty awesome help.

So far I've tried some of the suggestions, but no cigar.

I think the problem might lie in the formatting of the updateddata.txt file.

This file has the first 2 columns as mass number until it reaches the triple digit values. Then it has 3 columns dedicated to mass number. IT then tabs over to the abundance numbers in scientific form.
I might have to reformat this to make it work in fortran, is my guess.
 
RJLiberator said:
Thanks for the pretty awesome help.

So far I've tried some of the suggestions, but no cigar.

I think the problem might lie in the formatting of the updateddata.txt file.

This file has the first 2 columns as mass number until it reaches the triple digit values. Then it has 3 columns dedicated to mass number. IT then tabs over to the abundance numbers in scientific form.
I might have to reformat this to make it work in fortran, is my guess.
It might be easier to adjust the FORMAT and READ statements in your program to adapt to the format of the data file. You can judge which is the least amount of work.
 
  • Like
Likes RJLiberator
So, in the end, we decided to change read to: READ( 17, *) MASSNUMBER2(I), ABUNDANCE2(I)

Amongst other small problems, this seemed to solve the problem and the code is running.

FORTRAN is rather touchy.
 
RJLiberator said:
So, in the end, we decided to change read to: READ( 17, *) MASSNUMBER2(I), ABUNDANCE2(I)

Amongst other small problems, this seemed to solve the problem and the code is running.

FORTRAN is rather touchy.
I think that you'll find that most programming languages are rather touchy. They do what you tell them to do, not necessarily what you want them to do.
 
  • Like
Likes RJLiberator and SteamKing

Similar threads

Replies
7
Views
2K
Replies
8
Views
3K
Replies
3
Views
4K
Replies
13
Views
3K
Replies
1
Views
2K
Replies
2
Views
2K
Back
Top