Skip to content

Commit 6992500

Browse files
committed
fortran index subroutine demo
1 parent 1efedfd commit 6992500

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/tests/read_slice.f90

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
!! example of Fortran reading smaller array into slice of larger array via subroutine
2+
implicit none
3+
4+
type :: foo
5+
integer :: i44(4,4)
6+
end type foo
7+
8+
integer :: i, bigA(4,4)
9+
type(foo) :: B
10+
11+
bigA = -1
12+
13+
call getter(bigA(2:3,3:4))
14+
15+
do i = 1,size(bigA,1)
16+
print '(4I3)', bigA(i,:)
17+
enddo
18+
19+
! ----
20+
21+
B%i44 = -1
22+
23+
call getter(B%i44(2:3,3:4))
24+
25+
print *,''
26+
do i = 1,size(B%i44,1)
27+
print '(4I3)', B%i44(i,:)
28+
enddo
29+
30+
!! should print
31+
!! -1 -1 -1 -1
32+
!! -1 -1 1 2
33+
!! -1 -1 3 4
34+
!! -1 -1 -1 -1
35+
36+
contains
37+
38+
subroutine getter(A)
39+
integer, intent(out) :: A(2,2)
40+
41+
A = reshape([1,2,3,4], shape(A), order=[2,1])
42+
43+
end subroutine getter
44+
45+
end program

0 commit comments

Comments
 (0)