Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Errors with fortran code, help!

  1. Jan 17, 2012 #1

    Having trouble with some code I am writing, where a subroutine returns the same value regardless of different variable inputs.

    C Calculate Yth and Chi values. Compute sum of Chi-squared.
    Subroutine Chisquared(CPREV,CHISQ)
    Real TIME(17),COUNTS(17),ERROR(17),YTH(17),CHI(17)


    Do K=1,17
    End Do

    Do L=1,17
    End Do

    Do M=1,17
    End Do


    The user inputs A, B, LAMDA1 and LAMDA2 but it always returns the same value of CPREV.
    Help please!!!
  2. jcsd
  3. Jan 17, 2012 #2


    User Avatar
    Homework Helper

    Looks like you need some basic debug. Suggest you first add a write statement in your subroutine to print out the values of A, B, LAMDA1 and LAMDA2 to confirm the values are what you expect.
  4. Jan 17, 2012 #3


    User Avatar
    Science Advisor
    Homework Helper

    Without seeing all of the code debugging this is just guessing, but the first two lines


    look a bit strange, considering that is the only thing you do with CHISQ.
  5. Jan 17, 2012 #4

    I've tried adding a write statement and it seems to have no problems with using the same variables (as input by the user in the main program).

    I've also got rid of that line of code CPREV=CHISQ.

    Still gives me the same value :confused:
  6. Jan 18, 2012 #5


    User Avatar
    Gold Member

    I haven't done fortran coding in a while but should not the COMMON staement be:
    Common TIME(17),ERROR(17),COUNTS(17),YTH(17),A,B,LAMDA1,LAMDA2

    and similar to one you have in your main part of the program?

    Just guessing that maybe TIME is a different variable then TIME(17)
  7. Jan 19, 2012 #6
    After throughly writing each step of the calculation (for YTH, CHI and CPREV), I found that the program was unable to handle the exponential function for certain values.

    So it works ok now... as long as LAMDA1 and LAMDA2 have values less than 0.01
  8. Mar 15, 2012 #7
    You need to post the entire program. This little piece needs values
    passed in COMMON.
  9. Mar 15, 2012 #8
    Ive solved it now

    Thanks anyway : )
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook