1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FORTRAN code question

  1. Apr 21, 2016 #1


    User Avatar
    Gold Member

    1. The problem statement, all variables and given/known data
    Working on a FORTRAN based code for some work.
    Not sure what's wrong with it.

    2. Relevant equations

    3. The attempt at a solution
    The section of the code that is causing the problem is:

    Code (Text):

      OPEN( UNIT = 17,FILE='updateddata.txt',STATUS='UNKNOWN')
      DO I = 1, 146
      READ( 17, 703) MASSNUMBER2(I), ABUNDANCE2(I)
    703  FORMAT( I7, ES15.8)
      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 read

    My question is: Is anything wrong in the fortran code here? Anything noticeable that would cause an error?
  2. jcsd
  3. Apr 22, 2016 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  4. Apr 22, 2016 #3


    User Avatar
    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.
  5. Apr 22, 2016 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  6. Apr 22, 2016 #5


    User Avatar
    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.
  7. Apr 22, 2016 #6


    Staff: Mentor

    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads - FORTRAN code question Date
FORTRAN: 2 conditions in 1 DO statement Aug 25, 2017
Fortran: Find a triangle's side, plus angles Dec 15, 2016
Help with MINUIT Fortran Code Oct 1, 2016
Fortran 95 code won't run Oct 23, 2015
Fortran code May 16, 2012