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.

  • 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. – francescalus Jan 20 '18 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 – stu abraham Jan 20 '18 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 – stu abraham Jan 20 '18 at 21:11
  • To check, you aren't using `'` or `"` as your quote marks, but some other? – francescalus Jan 20 '18 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 – stu abraham Jan 21 '18 at 13:04
  • are you intending to ask a new question each time you add a line to your code? Your implied do syntax is fubar. This is very simply stuff to look up in any textbook, tutorial, etc. – agentp Jan 21 '18 at 13:25
  • @agentp I'm asking a new question every time I've spent hours and got nowhere. I don't have a textbook, I need this finished tomorrow, and EVERY resource I've found online has so much assumed knowledge and is nonsense to me. So I wanted someone to quickly explain what I was doing wrong they have the time, as I'm really struggling to teach myself, and if not then they don't need to waste their time replying. – stu abraham Jan 21 '18 at 16:00
  • go here https://www.fortrantutorial.com/ click on "arrays and i/o" , scroll about half way down to "Implied Do Loop to write arrays" – agentp Jan 21 '18 at 16:16
  • @agentp thanks, I found that site a few days ago while struggling with something else, but it never came up while I was searching for help with this. I'll start reading through it now – stu abraham Jan 21 '18 at 16:36
  • Possible duplicate of [Fortran read input into dynamic array](https://stackoverflow.com/questions/8527919/fortran-read-input-into-dynamic-array) – LinFelix Jan 23 '18 at 23:56

0 Answers0