0

I have written a program that does calculations using a given r and y-value, and have mostly got it ready.

The last thing I need to figure out is how to get a range of r and y values from my "data.txt" file.

The file includes the following values:

r       y

5     6334
10    1674
15     522
20     135
25      47
30      18
35       4
40       1

I need it to read these numbers, assign the left column as r-values and the right as y-values.

My current program minimizes the chi-squared by changing 3 variables (A, T and L) for a given r and y. So it needs to take the list of values, and find the A, T and L value that will minimize the TOTAL chi-squared for all r and y-values.

If anyone could help me with reading and creating the array it would be a huge help. I've tried doing my own research, but everything online has so much assumed knowledge and I can't understand what I'm supposed to do.

This is what I have written

    PROGRAM reader

        IMPLICIT NONE

    REAL, DIMENSION (8, 2) :: A
    Integer r, y, data (8,16)
OPEN (8 , FILE = &
"C:\Users\stuab\Desktop\fortran\Project\DataReader\data.txt" &
,FORM = "FORMATTED", STATUS ="OLD")



    READ (8, *) r , y

    print *, "Matrix A" / (8F2.2), &

    A ( r, y ), r = (8, 1), y = (8, 1)

END

Like I said, I don't understand what I'm supposed to write so this could make no sense for what I'm trying to do. I'm getting the message "Expecting a right parenthesis at the end of expression", and can't figure out why.

10
  • It would be useful if you could point to some of the documentation you have found, even if you find it impenetrable. After all, input/output is such a basic concept in programming (in its basic form) that it's hard for someone well-experienced to know exactly which bits are troubling. A proper description of the read statement and its applications is far too broad for an answer here, but questions like "I tried reading like this and this went wrong" are frequently answered. Commented Jan 20, 2018 at 20:39
  • @francescalus thanks for the reply. The first issue is the simple "Open" command comes back with "Invalid value for file specification", even if I input the entire path "C:\\....\data.txt" -------sorry pressed enter to return but it saved the comment, ill edit this comment when I'm done testing Commented Jan 20, 2018 at 20:58
  • @francescalus ok I have now updated my post with a new attempt, along with the errors. I don't know what most of what I've written means, it was copied over and edited from some other work Commented Jan 20, 2018 at 21:11
  • To check, you aren't using ' or " as your quote marks, but some other? Commented Jan 20, 2018 at 21:35
  • @francescalus I copied that piece of code straight from my tutor's notes, so I didn't even think that it could have been the wrong sort of quotation marks. But you were right, I fixed them and it solved my error. Now all it says is "Expecting a right parenthesis at the end of expression", I have updated my post to show this Commented Jan 21, 2018 at 13:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.