- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to pass the array into subroutine.
Please look at my first program.
program t1
implicit none
integer, dimension(8) :: myarr
myarr = (/1,2,3,4,5,6,7,8/)
call passarr(myarr(5), 4)
contains
subroutine passarr(a,n)
integer, intent(in) :: N
integer, dimension(N), intent(in out) :: A
integer :: i
do i = 1, n
write(*,*) A(i)
end do
end subroutine passarr
end program t1
The results are
5
6
7
8
I want to implement this code for 2 dimensional arrary.
Please look at my second program.
program t2
implicit none
integer, dimension(8,2) :: myarr
integer :: i
myarr = reshape((/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16/),(/8,2/))
call passarr(myarr(5,:), 4)
contains
subroutine passarr(a,n)
integer, intent(in) :: N
integer, dimension(N,2), intent(in out) :: A
write(*,*) ''
do i = 1, n
write(*,*) A(i,:)
end do
end subroutine passarr
end program t2
I hope that the results are
5 13
6 14
7 15
8 16.
However, the result are
5 3616201
13 0
2052332597 2136218672
134253992 201362856.
what is wrong?
Thanks in advance to your advice.
Park
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
call passarr(myarr(5,:), 4)
by
call passarr(myarr(5:,:), 4)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
call passarr(myarr(5,:), 4)
by
call passarr(myarr(5:,:), 4)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page