-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexample.f90
More file actions
47 lines (34 loc) · 1.05 KB
/
Copy pathexample.f90
File metadata and controls
47 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
! PWR080: Conditionally initialized variables can lead to undefined behavior
module options
implicit none
integer, parameter :: OPTION_HALF = 1
integer, parameter :: OPTION_DOUBLE = 2
integer, parameter :: OPTION_UNKNOWN = 3
end module options
program main
use iso_fortran_env, only: real32
use options, only: OPTION_HALF, OPTION_DOUBLE, OPTION_UNKNOWN
implicit none
real(kind=real32) :: array(4)
array = [0.25, 0.25, 0.25, 0.25]
print *, "Sum is:", transform_and_sum(array, OPTION_UNKNOWN)
contains
pure real(kind=real32) function transform_and_sum(array, option)
implicit none
real(kind=real32), intent(in) :: array(:)
integer, intent(in) :: option
real(kind=real32) :: sum
real(kind=real32) :: factor
integer :: i
sum = 0.0
if (option == OPTION_HALF) then
factor = 0.5
else if (option == OPTION_DOUBLE) then
factor = 2.0
end if
do i = 1, size(array, 1)
sum = sum + array(i) * factor
end do
transform_and_sum = sum
end function transform_and_sum
end program main