I have a program which reads a .csv file into an array and stores the values of the different variables into columns. I am trying to find the average value of the 2nd, 3rd and 4th columns (ivar1,ivar2,ivar3). I have the following code {this is just the loop to calculate the sum of the values and their average:
the sum of the columns are divided by 1000 because of a scaling factor and then by the value k which is the total number of lines read.
This seems like it should work but when I try to compile I return errors, could somebody give me some advice on this?
The rest of the code is here:
Code:
Do 11 k=1,n
Sum(U)=Sum(U)+((ABS(ivar(k)))
AVGFor=((Sum(U)/1000)/n)
11 continue
Write(*,*) 'AVGFor'
This seems like it should work but when I try to compile I return errors, could somebody give me some advice on this?
The rest of the code is here:
Code:
program rd
implicit none
integer stat, cmd_rc, num_lines, ivar1, ivar2, ivar3,u,k,n,AVGFor
real :: rvar
integer i
character*100 line
do i=1,10
read(*,*) line
end do
num_lines = 0
do
read(*,*,end=99, iostat=stat) rvar, ivar1, ivar2, ivar3
if (stat .ne. 0) then
write(*,*) 'Error reading data !'
exit
end if
num_lines = num_lines + 1
if (num_lines <= 10) then
write(*,*) num_lines, ':', rvar, ivar1, ivar2, ivar3
end if
end do
99 continue
[COLOR=#3465A4] Do 11 k=1,n
Sum(U)=Sum(U)+((ABS(ivar(k)))
AVGFor=((Sum(U)/1000)/n)
11 continue
Write(*,*) 'AVGFor'[/color]
write(*,*) '...done.'
write(*,*) 'Lines processed: ', num_lines
end program rd