Современный Фортран_учебник
.pdf82
, . -
+ .
«=»
! «=». ' -
. -
# «=» , -
. ' ! !, -
, ! -
«=». 0, k=k+1 , *
k 1. / -
, # * , ! .
%
,
.
3.4. If Do
– If
' $ + ! #
. '
! *. / if + 0, 1, 2, 3, …. ( -
elseif ( ) then , , +-
Select case ! .
% 21.
( # ( )
|
|
|
|
2-' |
|
|
|
|
If |
||
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
If ( _ ) then |
|||||
|
|
|
|
||||||||
|
|
||||||||||
|
|
|
|
|
|
|
|
$ _then then else |
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
|
|
$ _then |
|
|
|
$ _else |
|
$ _else else endif |
||||
|
|
|
|
|
|
|
|
|
|
|
endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83
% 22.
& ( $ _else)
|
2-' |
If |
|||||
|
|
|
|
|
|
||
|
|
|
|
|
|||
|
|
|
|
||||
|
If ( _ ) then |
||||||
|
|
||||||
|
|||||||
|
|
|
|
|
|
||
|
|
|
|
|
|
$ _then then endif |
|
|
|
$ _then |
|
||||
|
|
|
|
endif |
|||
|
|
|
|
|
|
||
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% 23.
2 , - ,
2-' |
If |
|||
|
|
|
|
|
|
|
|
If ( _ ) |
|
|
|
|||
|
||||
|
' |
|||
|
||||
|
If (x<0) y=abs(x)
' -# , !-
–
3 – DO
< + ( ) - # . / do
do …
…$ _do… enddo
:
−;
−( +);
−( ).
( Exit Cycle
# # # ( ! #) -
! !:
−Exit – # ,
enddo # +*
Exit _ ;
−Cycle – # enddo $ -
Cycle _ .
|
|
|
|
|
84 |
|
|
|
|
|
|
|
|
% 24. |
|
2 |
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
2-' |
|
Do |
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Do |
|
$ _do, |
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
if ( _ ) exit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enddo ! do |
|
|
|
|
( DO |
|
|
||
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- - !,
$ _DO ! # exit
# .
|
|
|
|
|
|
|
|
% 25. |
|
< + ( ) |
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2-' |
Do |
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
' , |
|
|
|
|
|
|
|
|
|
|
|
|
|
< > |
|
|
|
||||
|
|
|
|
||||||
|
|
|
|
Do while( ) |
|
||||
|
|
|
|
|
|
|
|||
|
|
|
|
$ _do |
|
||||
|
|
|
|
|
|
|
|||
|
|
|
DO |
|
|
||||
|
|
|
|
|
enddo ! do |
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
)
' Do – ! , -
* * . -
|
xk − xn + step |
||
kp = Max |
0, Int |
|
. |
|
|||
|
|
step |
|
|
|
|
0 xn, xk step – ,
# . int( ) + !
, +, . ! max : max (0, +) => + max (0, –) => 0 max (0, 0) => 0 .
85
% 26. < . & , +
2-' |
Do |
|
do x = xn, xk, step |
|
|
|
do = xn, xk, step |
|||
|
|
|
|
|||||
|
|
|
|
|
|
|
|
$ _do |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enddo |
||
|
|
( |
DO |
|
||||
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
||
|
|
|
|
|
|
< , ! kp=0,
xn > xk |
|
xn < xk |
|
|
|
step > 0 |
|
step < 0 |
9 step +* :
−step≠0;
−. Do i= 1,10,1 Do i = 1,10 – + step=1;
−step>0, x , x > xk;
−step<0, x , x < xk.
' x . ( , . #, + -#,
+ . % 27.
< . ' -# .
|
# -' |
||||
|
2-' |
|
|
# |
|
|
|
|
5 ! # – ; |
||
|
|
xn, xk, step – , - |
|||
|
|
|
|||
|
x = xn |
|
. |
||
|
|
|
|
||
kp |
|
1) do x=xn,xk,step |
|||
|
2) |
$ _do |
|||
kp=Max(0, Int((xk - xn) / step) + 1); k=kp |
3) enddo |
||||
1) |
|
|
4) - |
||
|
k = 0? |
4) |
|
||
|
|
enddo – . (3), |
|||
2) |
_do |
|
|||
+ +* |
|||||
|
|||||
|
|
: |
|||
3) x = x + step |
|
||||
|
− x, |
||||
|
|
|
|||
|
k = k - 1 |
|
− ! k 1, |
||
|
|
− # (1). |
|||
|
|
|
-# -
+* :
86
−x do
– ! $ _do *;
−# ! ! $ _do , ! .
kp x;
−xn, xk, step ! – .
* ;
−cycle, $ _do, (2)
# end do – (3);
−Exit, $ _do, , -
# (4) –
+* end do;
− ! x -
x = xn + step *kp, # # -
x [xn,xk].
< x #:
−# xn, xk, step x = xk;
−# xn, xk, step x = xk. ': kp -
x=x+step, ! step + x. % !, :
−! ! – !
inta, + ! * + + x. /-
kp . ! !
; int ! , x !
!, # ! # integer inta, kp; real x
kp = . . |
. ! |
|
do int = |
0, kp-1 |
! kp – |
x = xn |
+ inta * |
step |
! $ _do enddo
−«!» * , « » do
: do x = xn, xk + step/2, step
−! , !+ -
!+, , 4, 8, 0.25
$ _do ! do.
. . & -
write ,
, # !, ,
.
|
87 |
|
' # do |
||
DO y = -1., 1., 0.125 |
! |
17 |
do x = -1., 1., 0.125 |
! |
17 |
WRITE(1,*) x,y |
! |
289=17*17 |
enddo |
|
|
ENDDO |
|
|
289 y.
3.5. #$ where forall
4 ! # # -95
, ( * ). ' !
! # ! ! . ' +* -
Do While, If Select case, ,
. # . 4 +* # # -
! % , . 5. 0
+* +
(*, )
% , . -
! : where forall (! Fortran-95).
where
where if ,# -
# , , !
|
|
% 28. |
if where |
||
|
|
|
Оператор if |
|
Оператор where |
if ( - ) then ! 2 |
$ |
where ( _ ) ! ; $ |
...! блок ДА |
|
....! блок ДА - _действия, конформные условию |
else if |
|
else where |
....! блок НЕТ |
|
.... ! блок НЕТ - действия, конформные условию |
end if |
|
end where |
|
|
|
if ( - ) then ! 1 |
$ |
where ( _ ) ! . $ |
...! блок ДА |
|
....! блок ДА - действия, конформные условию |
end if |
|
end where |
|
|
|
if ( - ) ! |
where(конформное_условие ) ! % |
|
! без блоков |
|
! $ $ |
& # if where – . & -
! ! :
−if ,
;
−where – . , -
, ,
# , -
% .
88
# where do – -
! . ', do ! !
- +, where
, , ! -
. !, ! do where:
−Do !;
−where , !.
% where - . , ! -
. ! ! ! ! -
+* # .
, !, where
do if.
' , +* # where:
−;
−. # +
- ! !
where;
−+ ! # ;
−+ .
/ , – . ! -
, ! ! – , . - ! !+:
−! +* IFC;
−;
−, ,
;
−# # ! -
# !, -
;
−,
+ ., ,
.
: # . ' -
.
1.,
# ! “ +* #”
Real SumObr
Real,dimension(1:10,1:10) :: A
SumObr=Sum( 1/A, A/=0 )
89
&
−1/A ”! 0” -
A;
−A/=0.
2. Obr !
# where
Real SumObr
Real,dimension (1:10,1:10):: A, Obr
where (A/=0 ) |
! $ |
|
Obr=1/A |
! |
– $ |
else where |
|
|
Obr=0 |
! |
– $ $ |
end where |
|
|
SumObr=Sum(Obr)
3. !
where
Real SumObr real,dimension(1:10,1:10) :: A,Obr
Obr=0;
where (A/=0) Obr=1/A ! $ $
SumObr=Sum(Obr)
forall
where +* ,
forall - # #. 8 + - + . ( +
. '-
! + -
forall , + -
. 5 forall
+ where. 8 Do While forall -
, Do While +* , *
, . (
+ ! .
%, +* ,
+
forall (5= , ..[, _ ]) -
_ _%
forall (5= , .. &
90
5= [, _ _ ] )
!, % ,
!$
end forall
. 0 . #
# do forall.
: diaPro – # .
.
1. ' ! do if real,dimension(1:10,1:10) :: A
real diaPro; integer i diaPro =1
do i=1,10
if( A(i,i)/=0) diaPro = diaPro* A(i,i) enddo
2. 5 do forall,
real,dimension(1:10,1:10) :: A real Diapro; integer i
Diapro =1
Forall(i=1:10, A(i,i)/=0) Diapro = Diapro* A(i,i)
( * Diapro = diapro* A(i,i) –
. , Forall: diaPro –
, A(i,i) # 1:10.
3. ' ! ! forall real,dimension(1:10,1:10) :: A real,dimension(1:10) :: Diagonal
real diaPro; integer i Diagonal =1;
forall (i=1:10, A(i,i)/=0) Diagonal(i)= A(i,i) diaPro= product(Diagonal)
4. 0 *!+ where
4 forall ! :
- |
where - + 3; |
- |
do - + |
|
#; |
-do - forall . +
, forall.
& . do forall - + :
-do . + -
;
91
- forall . + - ,
! -
, :
% do - +- * # ; forall - +- * # .
+ where !
forall, forall ! !
where:
-, forall !: where (A /= 0.0) B=1.0/A
- сами напишите;
-, +* forall ! !
forall (i=1:n, j=1:n) H(i,j) = 1.0/(i+j-1)
-. . H(i, j) -
+ 1.0/ (i + j - 1) + # i j 1 n.
Forall :
-, ! # ;
-, -
+* ;
-! , ,
# ! # ;
-,
! - forall;
-.
' , +* forall:
-+ # # -
;
-+ ;
;
-+ -
! ;
-+ ! # -
.
', . , ! !- # . forall
*, ,:
-! , ;
-! !, ! !;
-! ! ! -
, # :
1.+* , IFC;
2.# .