
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45


목차
Ch. 1. Introduction to Computing
Ch. 2. Basic Fortran
Ch. 3. Selective Execution
Ch. 4. Repetitive Execution
Ch. 5. Input/Output
Ch. 6. Programming with Functions
Ch. 7. Programming with Subroutines
Ch. 8. Arrays
Ch. 2. Basic Fortran
Ch. 3. Selective Execution
Ch. 4. Repetitive Execution
Ch. 5. Input/Output
Ch. 6. Programming with Functions
Ch. 7. Programming with Subroutines
Ch. 8. Arrays
본문내용
열
ex)
do j=1,3
do i=1,4
write(1,10) a(i,j)
end do
end do
ex)
do j=1,3
write(1,10) a(1,j), a(2,j), a(3,j)
end do
ex)
write(1,10) ((a(i,j), i=1,4), j=1,3)
ex)
write(1,10) (a(1,j), a(2,j), a(3,j), j=1,3)
* 3차원, 4차원 등 n차원 배열로도 확장하여 해석할 수 있다.
배열요소의 위치
a(m,n)
loc=m*(j-1)+i
ex) a(4,3)의 저장순서
: a(1,1), a(2,1), a(3,1), a(4,1), a(1,2), a(2,2), a(3,2), a(4,2), a(1,3), a(2,3), a(3,3), a(4,3)
loc=4*(2-1)+4=8
Data 문
data vlist/clist/, vlist/clist/, ......
: 변수나 배열에 초기치를 부여
Rule)
1) declaration 뒤에, 실행문 앞에 위치
2) vlist의 개수 : clist의 개수 (1:1 대응)
3) vlist와 clist는 data type assignment를 따른다.
4) n번 반복할 경우 n*clist
5) vlist에 배열명을 쓰면 배열 요소 전체를 의미
6) vlist의 배열에 implied do문 사용가능
ex)
data a/2.0/, b/3.0/
a=2.0 ; b=3.0
ex)
data a,b/2.0, 3.0/
ex)
data a,b/2*2.0/
ex)
real a(3)
data a/1.0, 2.0, 3.0/
ex)
real a(3)
data a/3*1.0/
ex)
real a(3)
data a/2*1.0, 2.0/
ex)
real a(3)
data (a(i), i=1,3)/3*1.0/
ex)
real a(2,3)
data a/2*1.0, 2*2.0, 2*3.0/
a(1,1)=1.0
a(1,2)=2.0
a(1,3)=3.0
a(2,1)=1.0
a(2,2)=2.0
a(2,3)=3.0
ex)
real a(2,3)
data((a(i,j), i=1,2), j=1,3)/4*1.0,2*3.0/
a(1,1)=1.0
a(1,2)=1.0
a(1,3)=3.0
a(2,1)=1.0
a(2,2)=1.0
a(2,3)=3.0
Complex Type Declaration
complex variable list
where variable list : variables or arrays
comments)
real part와 imaginary part 두부분으로 구성되므로 저장하는데 변수 하나당 2개의 기억장소가 필요하다. 즉 double precision과 마찬가지로 기억장소의 크기가 변수 하나당 2배의 크기가 요구된다.
ex) complex a
a=(1,0, 2.0)
write(*,*) a
이는 a=1.0+2.0i를 의미하며 화면에는 (1.0, 2.0)이 출력된다.
ex) complex a
data a/1.0, 2.0/
ex) 다음의 수학식들을 complex를 이용한 FORTRAN 식으로 표현한다.
&x=a+bi, ~y=c+di## & x+y=(a+c)+(b+d)i## & x*y=(ac-bd)+(ad+bc)i## & x over y = (ac+bd) over {(c^2 +d^2 )} + (bc-ad) over {(c^2 +d^2 )}i## & x^n = (a^2 + b^2 ) ^{n over 2} (cos n theta + i sin n theta ),~ where~ theta=tan^{-1} {({b over a })}
complex x,y,z,s,t,u
x=(1.0, 2.0)
y=(2.0, 3.0)
z=x+y
s=x*y
t=x/y
u=x**n
COMMON statement
: In order to make information available to main programs and subprograms. It literally specifies portions of memory that are shared in common by the main program and by all subprograms in which COMMON statements appear.
common var1, var2,..
comments)
변수나 배열을 공동영역(common area)의 한 장소에 할당하여 기억장소를 절약한다.
main program과 subprogramrks의 정보교환
1) argument를 통하여 양성적으로 전달
2) common을 이용한 음성적 전달
ex) common a, f(5)
ex) main program에서 common x,y,z
subprogram에서 common a,b,c
: 순서에 맞게 1:1대응이 되도록!
ex)
1) 양성적 정보교환
real a(3), b(5)
...
call temp(a,b)
...
stop
end
subroutine temp(x,y)
real x(3), y(5)
...
return
end
2) 음성적 정보교환
common a(3), b(5)
...
call temp
...
stop
end
subroutine temp
common x(3), y(5)
...
return
end
Labelled COMMON statement
common /name/ var1, var2, /name2/var3, var4
where name is any acceptable FORTRAN variable name, called the common block name, enclosed by slashes. (data type assignment 를 주의할 것)
ex)
common /a/x(10), y,z, /b/ t(2)
참고문헌
[1] Larry R. Nyhoff and Sanford C. Leestuma, 2001, "Introduction to Fortran 90 for Engineers And Scientists", Prentice-Hall, Inc.
[2] Martin O.H and Ali B, "Fortran77 for engineers and scientists", Brooks/Cole, pp. 455-457.
ex)
do j=1,3
do i=1,4
write(1,10) a(i,j)
end do
end do
ex)
do j=1,3
write(1,10) a(1,j), a(2,j), a(3,j)
end do
ex)
write(1,10) ((a(i,j), i=1,4), j=1,3)
ex)
write(1,10) (a(1,j), a(2,j), a(3,j), j=1,3)
* 3차원, 4차원 등 n차원 배열로도 확장하여 해석할 수 있다.
배열요소의 위치
a(m,n)
loc=m*(j-1)+i
ex) a(4,3)의 저장순서
: a(1,1), a(2,1), a(3,1), a(4,1), a(1,2), a(2,2), a(3,2), a(4,2), a(1,3), a(2,3), a(3,3), a(4,3)
loc=4*(2-1)+4=8
Data 문
data vlist/clist/, vlist/clist/, ......
: 변수나 배열에 초기치를 부여
Rule)
1) declaration 뒤에, 실행문 앞에 위치
2) vlist의 개수 : clist의 개수 (1:1 대응)
3) vlist와 clist는 data type assignment를 따른다.
4) n번 반복할 경우 n*clist
5) vlist에 배열명을 쓰면 배열 요소 전체를 의미
6) vlist의 배열에 implied do문 사용가능
ex)
data a/2.0/, b/3.0/
a=2.0 ; b=3.0
ex)
data a,b/2.0, 3.0/
ex)
data a,b/2*2.0/
ex)
real a(3)
data a/1.0, 2.0, 3.0/
ex)
real a(3)
data a/3*1.0/
ex)
real a(3)
data a/2*1.0, 2.0/
ex)
real a(3)
data (a(i), i=1,3)/3*1.0/
ex)
real a(2,3)
data a/2*1.0, 2*2.0, 2*3.0/
a(1,1)=1.0
a(1,2)=2.0
a(1,3)=3.0
a(2,1)=1.0
a(2,2)=2.0
a(2,3)=3.0
ex)
real a(2,3)
data((a(i,j), i=1,2), j=1,3)/4*1.0,2*3.0/
a(1,1)=1.0
a(1,2)=1.0
a(1,3)=3.0
a(2,1)=1.0
a(2,2)=1.0
a(2,3)=3.0
Complex Type Declaration
complex variable list
where variable list : variables or arrays
comments)
real part와 imaginary part 두부분으로 구성되므로 저장하는데 변수 하나당 2개의 기억장소가 필요하다. 즉 double precision과 마찬가지로 기억장소의 크기가 변수 하나당 2배의 크기가 요구된다.
ex) complex a
a=(1,0, 2.0)
write(*,*) a
이는 a=1.0+2.0i를 의미하며 화면에는 (1.0, 2.0)이 출력된다.
ex) complex a
data a/1.0, 2.0/
ex) 다음의 수학식들을 complex를 이용한 FORTRAN 식으로 표현한다.
&x=a+bi, ~y=c+di## & x+y=(a+c)+(b+d)i## & x*y=(ac-bd)+(ad+bc)i## & x over y = (ac+bd) over {(c^2 +d^2 )} + (bc-ad) over {(c^2 +d^2 )}i## & x^n = (a^2 + b^2 ) ^{n over 2} (cos n theta + i sin n theta ),~ where~ theta=tan^{-1} {({b over a })}
complex x,y,z,s,t,u
x=(1.0, 2.0)
y=(2.0, 3.0)
z=x+y
s=x*y
t=x/y
u=x**n
COMMON statement
: In order to make information available to main programs and subprograms. It literally specifies portions of memory that are shared in common by the main program and by all subprograms in which COMMON statements appear.
common var1, var2,..
comments)
변수나 배열을 공동영역(common area)의 한 장소에 할당하여 기억장소를 절약한다.
main program과 subprogramrks의 정보교환
1) argument를 통하여 양성적으로 전달
2) common을 이용한 음성적 전달
ex) common a, f(5)
ex) main program에서 common x,y,z
subprogram에서 common a,b,c
: 순서에 맞게 1:1대응이 되도록!
ex)
1) 양성적 정보교환
real a(3), b(5)
...
call temp(a,b)
...
stop
end
subroutine temp(x,y)
real x(3), y(5)
...
return
end
2) 음성적 정보교환
common a(3), b(5)
...
call temp
...
stop
end
subroutine temp
common x(3), y(5)
...
return
end
Labelled COMMON statement
common /name/ var1, var2, /name2/var3, var4
where name is any acceptable FORTRAN variable name, called the common block name, enclosed by slashes. (data type assignment 를 주의할 것)
ex)
common /a/x(10), y,z, /b/ t(2)
참고문헌
[1] Larry R. Nyhoff and Sanford C. Leestuma, 2001, "Introduction to Fortran 90 for Engineers And Scientists", Prentice-Hall, Inc.
[2] Martin O.H and Ali B, "Fortran77 for engineers and scientists", Brooks/Cole, pp. 455-457.
소개글