Tags:
1. Dec 20, 2018

### Ihatefortran

• New user's thread moved to the Homework Help forums, so no Template is shown.
Hey guys, new here and was hoping for some help.
Basically I have to use Fortran 77 to complete some questions for an assignment
The first thing to do is, read a bunch of numbers in a list format and then use these numbers to be entered within an equation.
The values I have are listed in a 1 column list eg
4.5252
4.541
5.522
etc

The equation I have is: XYZ (Where Z are the each value from that list, and X/Y are other values). I need to calculate an answer for each Z value.

So far, I'm stuck on even being able to read the file in the first place!
My code:

Code (Fortran):

PROGRAM Example
IMPLICIT NONE
INTEGER n
REAL phi(10)

OPEN(10,FILE='data.txt', FORM='FORMATTED',  STATUS='OLD')
phi=0.0
n=0
DO
n=n+1
ENDDO
10   CONTINUE
PRINT*, phi
END

When I compile the code just reads 0 for some reason.

Someone help?

Last edited by a moderator: Dec 20, 2018
2. Dec 20, 2018

### kuruman

It's been a while since I programmed in FORTRAN, but the READ statement looks incorrect. You bump index n and then do nothing with it. I would say
That should read the values into the array.

3. Dec 21, 2018

### Ihatefortran

Did the same thing, just keeps printing 0.00000's

4. Dec 21, 2018

### Staff: Mentor

Since this is FORTRAN 77, there shouldn't be a single instance of the variable phi that is not indexed, e.g., phi(n). You need to modify all 3 references to phi in this bit of code.

Also, arrays in FORTRAN start at index 1, so you should initialise n=1.

5. Dec 21, 2018

### FactChecker

There are a lot of places where the array phi is not indexed. You should fix them all before proceeding. And move your print inside the loop. And start n at 1.

6. Dec 23, 2018

### Ihatefortran

Thanks guys! Appreciate it.

7. Dec 24, 2018

### scottdave

I came across this late. It looks like you got it figured out? Hopefully you don't hate FORTRAN quite as much. Any new language is frustrating at the beginning, having to learn new syntax and different ways to accomplish a task.

8. Jan 1, 2019

### Ihatefortran

Thanks so much, sort of got the hang of it but still very stuck on another issue now!

9. Jan 1, 2019

### FactChecker

FYI. These problems are not FORTRAN-specific. The problems you had in this example would have been problems in a lot of languages.