Fortran Help- maximum values

Hello I am currently working on a program that will take the values from a .csv file containing multiple data and analyzing them. The file can be found here: https://docs.google.com/file/d/0BzuDEPd26OcheVhiWlZ3STlZU0k/edit?usp=sharing The data in question starts in row 11 and is in the first 4 columns. In my program I have labeled these: rvar, ivar1, ivar2, ivar3. Rvar is the value corresponding to a time value in microseconds after start of recording whereas ivar1,ivar2,and ivar3 correspond to the value of the acceleration at that point. I have already calculated the average value of each of these columns.

My question is- how do I find the maximum value for ivar1, ivar2 and ivar3 (separately)?

My current code is below:
[code]program WSUPhys_csv
implicit none

integer :: stat, num_lines, ivar1, ivar2, ivar3
real :: rvar
character*80 :: line

write(*,*) "Reading file..."

! open input file
open(10,file='DATA-002.csv',status='old',iostat=stat)
if (stat .ne. 0) then
write(*,*) 'File cannot be opened !'
go to 99
end if

num_lines = 0
do
read(10,'(A)',end=99, iostat=stat) line
if (stat .ne. 0) then
write(*,*) 'Error reading data !'
go to 99
end if
! skip comment/header lines beginning with ";"
if (adjustl(trim(line(1:1))) .eq. ';') then
cycle
end if
! read string line into numeric variables
read(line,*) rvar, ivar1, ivar2, ivar3
num_lines = num_lines + 1
if (num_lines <= 10) then
write(*,*) num_lines, ':', rvar, ivar1, ivar2, ivar3
end if
Sum_ivar1 = Sum_ivar1 + ABS(ivar1)
Sum_ivar2 = Sum_ivar2 + ABS(ivar2)
Sum_ivar3 = Sum_ivar3 + ABS(ivar3)
Max
end do

! close file
99 continue
Avg_ivar1 = (Sum_ivar1 / num_lines)
Avg_ivar2 = (Sum_ivar2 / num_lines)
Avg_ivar3 = (Sum_ivar3 / num_lines)
close (10)
!
write(*,*) '...done.'
write(*,*) 'Lines processed: ', num_lines
write(*,*) 'Average vertical acceleration', Avg_ivar1/1000
write(*,*) 'Average sideways acceleration', Avg_ivar2/1000
write(*,*) 'Average forwards acceleration', Avg_ivar3/1000
end program WSUPhys_csv [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories