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 18, 2018
1 parent 17aa706 commit d2da6f9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/fortran_ex2.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ $ ./a
```

# Derived Type
> - 유도타입(derived type)은 parameter 성질을 가질 수 업다.
> - 아래 예제와 같이 이미 정의된 유도 타입을 이용해 새로운 유도 타입을 정의할 수 있다.
> -
- **Example**
```fortran
Expand All @@ -104,18 +107,31 @@ program derivedtype
type coord_3d
real::x,y,z
end type coord_3d
type sphere
type(coord_3d) :: center
real :: radius
end type sphere
type(coord_3d)::pt1, pt2=coord_3d(2.0,2.0,2.0), pt3
type(sphere)::ball
ball=sphere(center=pt2,radius=3.0)
or
ball%center%x=2.0; ball%center%y=2.0; ball%center%z=2.0; ball%radius=3.0;
pt1%x=1.0; pt1%y=1.0; pt1%z=1.0
pt3=coord_3d(3.0,3.0,3.0)
print*, pt1
print*, pt2
print*, pt3
print*, ball
end program derivedtype
```
`sphere``coord_3d`**supertype**이다.
```bash
$ ./a.out
1.00000000 1.00000000 1.00000000
2.00000000 2.00000000 2.00000000
3.00000000 3.00000000 3.00000000
2.00000000 2.00000000 2.00000000 3.00000000
```

0 comments on commit d2da6f9

Please sign in to comment.