# FORTRAN code question

• Comp Sci
Gold Member

## Homework Statement

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

## 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
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')

My question is: Is anything wrong in the fortran code here? Anything noticeable that would cause an error?

Related Engineering and Comp Sci Homework Help News on Phys.org
SteamKing
Staff Emeritus
Homework Helper

## Homework Statement

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

## 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
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')

My 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.

RJLiberator
Gold Member
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.

SteamKing
Staff Emeritus
Homework Helper
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.

RJLiberator
Gold Member
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.

Mark44
Mentor
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.

RJLiberator and SteamKing