Skip to content

Commit 50ca2b2

Browse files
Add Use cases snippets
1 parent 6724c20 commit 50ca2b2

24 files changed

Lines changed: 444 additions & 0 deletions

Use-Cases/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FC = gfortran
2+
CC = gcc
3+
4+
FFLAGS ?= -c -cpp -Wall -Wuninitialized -Wmaybe-uninitialized
5+
CFLAGS ?= -c -Wall -Wuninitialized -Wmaybe-uninitialized
6+
7+
F90_SRCS := $(wildcard *.f90)
8+
C_SRCS := $(wildcard *.c)
9+
10+
PROGS := $(F90_SRCS:.f90=) $(C_SRCS:.c=)
11+
12+
.PHONY: all clean
13+
14+
all: $(PROGS)
15+
16+
%: %.f90
17+
$(FC) $(FFLAGS) $< -o $@
18+
19+
%: %.c
20+
$(CC) $(CFLAGS) $< -o $@
21+
22+
clean:
23+
-rm -f $(PROGS)

Use-Cases/chk158-1.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SUBROUTINE test_routine16(n, sum)
2+
IMPLICIT NONE
3+
INTEGER(KIND=4) :: n
4+
REAL(KIND=8), DIMENSION(100) :: A
5+
REAL(KIND=8) :: sum
6+
INTEGER(KIND=4) :: i
7+
8+
A(1) = 1.0
9+
10+
sum = 0.0
11+
DO i = 1, n
12+
sum = sum + A(i)
13+
END DO
14+
END SUBROUTINE

Use-Cases/chk159-2.f90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SUBROUTINE test_routine17(n, sum)
2+
IMPLICIT NONE
3+
INTEGER(KIND=4) :: n
4+
REAL(KIND=8), DIMENSION(100) :: A
5+
REAL(KIND=8) :: sum
6+
INTEGER(KIND=4) :: i
7+
8+
DO i = 4, 23
9+
A(i) = 1.0
10+
END DO
11+
12+
sum = 0.0
13+
DO i = 1, n
14+
sum = sum + A(i)
15+
END DO
16+
END SUBROUTINE

Use-Cases/pwr072-1.f90

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! This already is in the open-catalog in the PWR072 section: example.f90
2+
! PWR072: Explicitly declare the 'save' attribute or split the variable
3+
! initialization to prevent unintended behavior
4+
5+
program test_implicit_save
6+
implicit none
7+
integer, dimension(3) :: A = [1, 1, 1], B = [2, 2, 2]
8+
integer :: result
9+
10+
result = sum_array(A)
11+
print *, "Sum of A:", result ! Expected: 3
12+
13+
result = sum_array(B)
14+
print *, "Sum of B:", result ! Expected: 6
15+
16+
contains
17+
18+
integer function sum_array(array)
19+
implicit none
20+
integer, intent(in) :: array(:)
21+
integer :: result = 0
22+
integer :: i
23+
24+
do i = 1, size(array)
25+
result = result + array(i)
26+
end do
27+
28+
sum_array = result
29+
end function sum_array
30+
31+
end program test_implicit_save

Use-Cases/pwr072-2.f90

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! This already is in the open-catalog in the PWR072 section: solution.f90
2+
! PWR072: Explicitly declare the 'save' attribute or split the variable
3+
! initialization to prevent unintended behavior
4+
5+
program test_implicit_save
6+
implicit none
7+
integer, dimension(3) :: A = [1, 1, 1], B = [2, 2, 2]
8+
integer :: result
9+
10+
result = sum_array(A)
11+
print *, "Sum of A:", result ! Expected: 3
12+
13+
result = sum_array(B)
14+
print *, "Sum of B:", result ! Expected: 6
15+
16+
contains
17+
18+
pure integer function sum_array(array)
19+
implicit none
20+
integer, intent(in) :: array(:)
21+
integer :: result
22+
integer :: i
23+
24+
result = 0
25+
26+
do i = 1, size(array)
27+
result = result + array(i)
28+
end do
29+
30+
sum_array = result
31+
end function sum_array
32+
33+
end program test_implicit_save

Use-Cases/pwr079-1.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SUBROUTINE test_routine01()
2+
IMPLICIT NONE
3+
REAL(KIND=8) :: stopped
4+
5+
IF (stopped > 0.5) THEN
6+
WRITE(*,*) 'Loop exited before step n'
7+
ELSE
8+
WRITE(*,*) 'No early exit'
9+
END IF
10+
END SUBROUTINE

Use-Cases/pwr079-2.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SUBROUTINE test_routine02(n)
2+
IMPLICIT NONE
3+
INTEGER(KIND=4), INTENT(IN) :: n
4+
INTEGER(KIND=4) :: i
5+
REAL(KIND=4) :: sum
6+
7+
DO i = 1, n
8+
sum = sum + i
9+
END DO
10+
END SUBROUTINE

Use-Cases/pwr079-3.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SUBROUTINE test_routine03pointer(n)
2+
IMPLICIT NONE
3+
INTEGER(KIND=4), INTENT(IN) :: n
4+
INTEGER(KIND=4) :: i
5+
INTEGER, POINTER :: sum_pointer
6+
7+
DO i = 1, n
8+
sum_pointer = sum_pointer + i
9+
END DO
10+
END SUBROUTINE

Use-Cases/pwr079-4.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SUBROUTINE test_routine04(n)
2+
IMPLICIT NONE
3+
INTEGER(KIND=4), INTENT(IN) :: n
4+
REAL(KIND=8), DIMENSION(100) :: A
5+
REAL(KIND=8) :: sum
6+
INTEGER(KIND=4) :: i
7+
8+
sum = 0
9+
DO i = 1, n
10+
sum = sum + A(i)
11+
END DO
12+
END SUBROUTINE
13+

Use-Cases/pwr079-5.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SUBROUTINE test_routine05()
2+
IMPLICIT NONE
3+
REAL(KIND=8), DIMENSION(100) :: A
4+
5+
IF (A(3) > 0.5) THEN
6+
WRITE(*,*) 'Loop exited before step n'
7+
ELSE
8+
WRITE(*,*) 'No early exit'
9+
END IF
10+
END SUBROUTINE

0 commit comments

Comments
 (0)