Skip to content

Commit

Permalink
Update fortran_ex.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WonyoungCho committed Nov 24, 2018
1 parent ef2b0b7 commit 7d95502
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions docs/fortran_ex.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ $ ./a.out

# Array

- **Example - static**
- **Example - static array**

고정된 크기를 가지는 행렬이다.
```fortran
real a, b, c
dimension a(100), b(10,10), c(2,3,4)
Expand All @@ -168,7 +170,9 @@ or
real a(1:100), b(3:12,2:11), c(1:2,4:6,3:6)
```

- **Example - dynamic**
- **Example - dynamic array**

차원만 정해놓고 크기는 정해놓지 않은 행렬을 말한다.
```fortran
integer, dimension(:), allocatable :: string ! 1D
```
Expand All @@ -194,12 +198,49 @@ $ ./a.out
10 10 10 10 10
```

- **Example - pointer**
```fortran
real, target :: b(100,100)
real, pointer :: u(:,:), v(:), w(:,:)
- **Example - pointer array**

u => b(i:i+2, j:j+2)
allocate(w(m,n))
v => b(:,j)
행렬의 값을 **point**해서 가져간다.
```fortran
program pointer
implicit none
integer :: l, i, j, k, m, n
real, target :: b(6,6)=1
real, pointer :: u(:,:), v(:), w(:,:)
print *, b
print *, '---------'
m=3; n=2
i=2; j=4
n=6
do k=1,6
do l=1,6
b(l,k)=2*l+k
end do
end do
print *, b
print *, '---------'
u => b(i:i+2, j:j+2)
print *, u
print *, '---------'
allocate(w(m,n))
w = 9
v => b(:,j)
print *, v
print *, '---------'
v => w(i-1, 1:n:2)
print *, v
end program pointer
```
```sh
$ ./a.out
1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000
---------
3.00000000 5.00000000 7.00000000 9.00000000 11.0000000 13.0000000 4.00000000 6.00000000 8.00000000 10.0000000 12.0000000 14.0000000 5.00000000 7.00000000 9.00000000 11.0000000 13.0000000 15.0000000 6.00000000 8.00000000 10.0000000 12.0000000 14.0000000 16.0000000 7.00000000 9.00000000 11.0000000 13.0000000 15.0000000 17.0000000 8.00000000 10.0000000 12.0000000 14.0000000 16.0000000 18.0000000
---------
8.00000000 10.0000000 12.0000000 9.00000000 11.0000000 13.0000000 10.0000000 12.0000000 14.0000000
---------
6.00000000 8.00000000 10.0000000 12.0000000 14.0000000 16.0000000
---------
9.00000000 9.00000000 9.00000000
```

0 comments on commit 7d95502

Please sign in to comment.