Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2. !! File name: giannopoulos.f95 !!
  3. !!
  4. !! Giorgos Giannopoulos / Date: 16/6/2019 !!
  5. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6.  
  7. program giannopoulos
  8. implicit none
  9.  
  10. integer nlines ! number of lines of input file
  11. integer i
  12. integer valid ! number of valid data
  13. integer missing ! number of missing data
  14. real mo ! Mean value
  15. real s2 ! variance s^2
  16. real s ! standard deviation s
  17. real, dimension (:), allocatable :: array ! array to store valid data, dynamically allocated
  18. character(len=30) :: temp ! used to read file line by line and count *(missing data)
  19. character(len=30) :: date
  20. integer stat ! used in opening of input file
  21.  
  22. mo = 0.0;
  23. s2 = 0.0;
  24.  
  25. ! find # of lines in input file
  26. nlines = 0
  27. missing = 0
  28. open(24, file = 'giannopoulos.data', IOSTAT=stat, status = 'old')
  29. if (stat .ne. 0) then ! check if file exists
  30. write(*,*) "giannopoulos.data cannot be opened"
  31. stop 1 ! file doesn texist , terminate
  32. end if
  33. do
  34. read(24,'(A)',iostat=stat) temp
  35.  
  36. if (stat/=0) then
  37. exit ! end of file
  38. end if
  39. print*, temp
  40. if ( temp .eq. ' *' ) then
  41. missing = missing+1 !case of missing data
  42. end if
  43.  
  44. nlines = nlines + 1
  45. end do
  46. print*, nlines
  47. valid = nlines-2-missing ! number of valids = total - first 2 lines - missing data
  48.  
  49. ! allocate memory
  50. allocate ( array(valid) )
  51. rewind(24) ! to be able to read file from start again
  52. read(24,*) ! avoid first line, name of file
  53. read(24,*) ! avoid second line, date
  54.  
  55. ! read valid lines and store data in array
  56. do i = 1, valid
  57. read(24,*) array(i)
  58. print*, array(i)
  59. mo = mo + array(i)
  60. end do
  61. close(24)
  62.  
  63. mo = mo/valid ! estimate mean value
  64. do i = 1, valid
  65. s2 = s2 + (array(i)-mo)*(array(i)-mo)
  66. end do
  67. s2 = s2/(valid-1) ! estimate variance
  68. s = 0.0
  69. s = sqrt(s2) ! Standard deviation
  70.  
  71. call fdate(date)
  72. ! print output on screen
  73. print*, "---------------------------------------------"
  74. print*, "Giorgos Giannopoulos / NTUA"
  75. print*, "Date / Time ", date
  76. print*, "File Name: giannopoulos.f95"
  77. print*, "---------------------------------------------"
  78. print*, "Mean value: ", mo
  79. print*, "Variance: ", s2
  80. print*, "Standard deviation: ", s
  81. print*, "Number of missing data:", missing
  82. print*, "Number of valid data: ", valid
  83. print*, "---------------------------------------------"
  84.  
  85. ! print output on OutputFile.data
  86. open(25, file = 'OutputFile.data', status = 'replace')
  87. write(25,'(a)') "---------------------------------------------"
  88. write(25,'(a)') "Giorgos Giannopoulos / NTUA"
  89. write(25,'(a)') "Date / Time ", date
  90. write(25,'(a)') "File Name: giannopoulos.f95"
  91. write(25,'(a)') "---------------------------------------------"
  92. write(25,*) "Mean value: ", mo
  93. write(25,*) "Variance: ", s2
  94. write(25,*) "Standard deviation: ", s
  95. write(25,*) "Number of missing data:", missing
  96. write(25,*) "Number of valid data: ", valid
  97. write(25,'(a)') "---------------------------------------------"
  98. close(25)
  99.  
  100. ! free allocated memory
  101. deallocate (array)
  102. end program giannopoulos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement