Fortran Help- maximum values - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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: 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
if (stat .ne. 0) then
write(*,*) 'File cannot be opened !'
go to 99
end if

num_lines = 0
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
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)
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.