Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! File name: giannopoulos.f95 !!
- !!
- !! Giorgos Giannopoulos / Date: 16/6/2019 !!
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- program giannopoulos
- implicit none
- integer nlines ! number of lines of input file
- integer i
- integer valid ! number of valid data
- integer missing ! number of missing data
- real mo ! Mean value
- real s2 ! variance s^2
- real s ! standard deviation s
- real, dimension (:), allocatable :: array ! array to store valid data, dynamically allocated
- character(len=30) :: temp ! used to read file line by line and count *(missing data)
- character(len=30) :: date
- integer stat ! used in opening of input file
- mo = 0.0;
- s2 = 0.0;
- ! find # of lines in input file
- nlines = 0
- missing = 0
- open(24, file = 'giannopoulos.data', IOSTAT=stat, status = 'old')
- if (stat .ne. 0) then ! check if file exists
- write(*,*) "giannopoulos.data cannot be opened"
- stop 1 ! file doesn texist , terminate
- end if
- do
- read(24,'(A)',iostat=stat) temp
- if (stat/=0) then
- exit ! end of file
- end if
- print*, temp
- if ( temp .eq. ' *' ) then
- missing = missing+1 !case of missing data
- end if
- nlines = nlines + 1
- end do
- print*, nlines
- valid = nlines-2-missing ! number of valids = total - first 2 lines - missing data
- ! allocate memory
- allocate ( array(valid) )
- rewind(24) ! to be able to read file from start again
- read(24,*) ! avoid first line, name of file
- read(24,*) ! avoid second line, date
- ! read valid lines and store data in array
- do i = 1, valid
- read(24,*) array(i)
- print*, array(i)
- mo = mo + array(i)
- end do
- close(24)
- mo = mo/valid ! estimate mean value
- do i = 1, valid
- s2 = s2 + (array(i)-mo)*(array(i)-mo)
- end do
- s2 = s2/(valid-1) ! estimate variance
- s = 0.0
- s = sqrt(s2) ! Standard deviation
- call fdate(date)
- ! print output on screen
- print*, "---------------------------------------------"
- print*, "Giorgos Giannopoulos / NTUA"
- print*, "Date / Time ", date
- print*, "File Name: giannopoulos.f95"
- print*, "---------------------------------------------"
- print*, "Mean value: ", mo
- print*, "Variance: ", s2
- print*, "Standard deviation: ", s
- print*, "Number of missing data:", missing
- print*, "Number of valid data: ", valid
- print*, "---------------------------------------------"
- ! print output on OutputFile.data
- open(25, file = 'OutputFile.data', status = 'replace')
- write(25,'(a)') "---------------------------------------------"
- write(25,'(a)') "Giorgos Giannopoulos / NTUA"
- write(25,'(a)') "Date / Time ", date
- write(25,'(a)') "File Name: giannopoulos.f95"
- write(25,'(a)') "---------------------------------------------"
- write(25,*) "Mean value: ", mo
- write(25,*) "Variance: ", s2
- write(25,*) "Standard deviation: ", s
- write(25,*) "Number of missing data:", missing
- write(25,*) "Number of valid data: ", valid
- write(25,'(a)') "---------------------------------------------"
- close(25)
- ! free allocated memory
- deallocate (array)
- end program giannopoulos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement