- #1
gjleigh10
- 2
- 1
Thread moved from the technical forums to the schoolwork forums
TL;DR Summary: I am beginning research as an undergrad in Physics and have an example file I must analyze for the mean of each column. I cannot use arrays. I need to take the sum of a column of data.
Hi all, I am new to fortran and programming in general, but I'm having issues with creating a code which will help me find the average of a column without using arrays. I am using an example data file to read the information into my program, and I want to take the sum of the first column. However, I am having a hard time finding out how to do this without arrays (especially when there is more than one column to sum individually.) Here is my data file:
And here is what I have written so far:
I am trying to make "a" the first column of data to read. I don't know if I did this correctly. Compiling this program gives me an error: 20 | write(8,*) sum = sum + i | 1 Error: Syntax error in WRITE statement at (1) I am trying to take the sum of every number in the column. Can someone point me in the right direction? Thank you very much.
Hi all, I am new to fortran and programming in general, but I'm having issues with creating a code which will help me find the average of a column without using arrays. I am using an example data file to read the information into my program, and I want to take the sum of the first column. However, I am having a hard time finding out how to do this without arrays (especially when there is more than one column to sum individually.) Here is my data file:
Code:
54
21
32
67
76
82
12
65
39
26
And here is what I have written so far:
Fortran:
program mean_analysis
implicit none
integer i
integer N
integer sum
integer a
sum = 0
N = 10
open(unit = 5, file="example.dat")
do i = 1, N
read(5,*) a
end do
close(5)
open(unit = 8, file="outputanalysis.dat")
do i = 1, N
write(8,*) sum = sum + i
end do
close(8)
end program
I am trying to make "a" the first column of data to read. I don't know if I did this correctly. Compiling this program gives me an error: 20 | write(8,*) sum = sum + i | 1 Error: Syntax error in WRITE statement at (1) I am trying to take the sum of every number in the column. Can someone point me in the right direction? Thank you very much.