Skip to content

Commit

Permalink
Update fortran_ex2.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WonyoungCho committed Dec 11, 2018
1 parent 820e747 commit f2e1eda
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions docs/fortran_ex2.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
# Array arguments

- **Example 1**
```fortran
program assumedshape
implicit none
interface
subroutine sub(ra,rb,rc)
integer, dimension(:,:), intent(in):: ra,rb
integer, dimension(0:,2:), intent(in):: rc
subroutine sub(ra,rb,rc,j,k)
implicit none
integer:: j,k
integer, dimension(0:,:), intent(in):: ra,rb
integer:: rc(j,*)
end subroutine sub
end interface
integer:: ra(3,3), rb(2,2)
integer:: rc1(0:2,2:2), rc2(0:3,2:3)
integer:: i
ra = reshape((/(i,i=1,9)/),(/3,3/))
rb = reshape((/(i,i=1,4)/),(/2,2/))
rc1= reshape((/(i,i=1,3)/),(/3,1/))
rc2= reshape((/(i,i=1,8)/),(/4,2/))
call sub(ra,rb,rc1)
call sub(ra,rb,rc2)
end program assumedshape
subroutine sub(ra,rb,rc)
integer, dimension(:,:), intent(in):: ra,rb
integer, dimension(0:,2:), intent(in):: rc
call sub(ra,rb,rc1,3,1)
call sub(ra,rb,rc2,4,2)
end program assumedshape
subroutine sub(ra,rb,rc,j,k)
implicit none
integer:: j,k
integer, dimension(0:,:), intent(in):: ra,rb
integer:: rc(j,*)
print*,'ra=',ra
print*,'rb=',rb
print*,'rc=',rc
print*,'rc=',rc(j,k)
end subroutine sub
```
`Subroutine`에 dummy 배열 사용이 가능하다.단, 차원과 형식이 일치해야 하며 `program`에 명시해 주어야 한다.


```sh
$ ./a
ra= 1 2 3 4 5 6 7 8 9
rb= 1 2 3 4
rc= 1 2 3
ra= 1 2 3 4 5 6 7 8 9
rb= 1 2 3 4
rc= 1 2 3 4 5 6 7 8
```

0 comments on commit f2e1eda

Please sign in to comment.