fortran 90

Download Fortran 90

Post on 23-Oct-2014

215 views

Category:

Documents

8 download

Embed Size (px)

TRANSCRIPT

90

Fortran 90 Programming Examples Including Fortran 90 CD

Omid Alizadeh CCGroup 1/1/2009

59 09 77 . 09 77 . COMPAQ FORTRAN 59 09 77 MICROSOFT VISUAL MICROSOFT . COMPAQ VISUAL FORTRAN .

Variable Declaration Execution Statement . END . . ) ( . . . :

: 1- 0 9 2- ) ( 3- _ 4- :5

Character blank = + * / ( ) , .'

Name )Blank (space Equal sign Plus sign Minus sign Asterisk Slash Left parenthesis Right parenthesis Comma Period (decimal )point Apostrophe

Character : ! " % & ; ? $

Name Colon Exclamation point Quotation mark Percent sign Ampersand Semicolon Less than Greater than Question mark Dollar sign (currency )symbol

. 5 ) (Label )+( 7 27 . . + & . ! C . . : **

6

* / + -

26+2 . 41 61 . . . :

)(** / * +// > < =< => = = =/ ..NOT ..AND ..OR ..EQV ..NEQV

.

. :7

2/6 - 2 * 3 + 4 ^ ^ ^ ^ 2 1 3 4 2/6 - 2 * )3 + 4( ^ ^ ^ ^ 1 2 3 4 2/)6 - 2 * 3 + 4( ^ ^ ^ ^ 2 1 3 4

7 =

11 =

2 =

2/)6 - 2 * )3 + 4(( ^ ^ ^ ^ 1 2 3 4

4 =

)4+3(/5 .5 4 +3

. ) NOT ( T T F F T F T F ..NOT F T F T ..AND T F F F ..OR T T T F ..EQV T F F T ..NEQV F T T F

// '

' ABCDEF .'('ABC'//'DE')//'F )''ABC'//('DE'//'F ''ABC'//'DE'//'F

:

< .LT. or

8

=< .LE. or = = .EQ. or =/ .NE. or > .GT. or => .GE. or

. .TRUE . .FALSE . . . 2+2 4 .4 . 2/1 0 1 2 5.0 . . . 2/ .1 5.0 .

9

. . . . . 1 . 2 . 3 . a A z 0 Z 9 _ ) underscore ( . ) 7up 1 ( ) Sin 3 ( . Sinx Flor A-B . Sinx . ) Sin(x Sin Sinx . Flor ) Floor ( . A-B ) (dash . . a z 62 . . StudentName Name . NAME name . StudentName Student_Name StudentName .

11

. :

2 3 ... 1.2 0.3 )32 21(

Integer Real

Complex

Character Logical

Integer 0 9 . Real ) . ( 2.0 2. .2 . Complex . . : Complex CN )2,1(=CN Print *,CN End CN )00000.2,00000.1( Real . Real . Double Precision . 21

. A B REAL A DOUBLE PRECISION B ).1(A=4*ATAN ).1(B=4*ATAN PRINT *,A,B END : 75210147295141.3 395141.3 . . BASIC : INTEGER*1 A A 8 -821 721 . 1 2 4 8 4 8 8* REAL DOUBLE PRESICION 4 . : INTEGER(1) A ) ( Integer , Real , Complex . . B . 2 ."1"B 10001B 100111B

2 . 8 O

'2110'B

61 Z . :31

61

2

8

01

0 1 2 3 4 5 6 7 8 9 A B C D E F

0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1011 0111 1111

00 10 20 30 40 50 60 70 01 11 21 31 41 51 61 71

0 1 2 3 4 5 6 7 8 9 01 11 21 31 41 51

text . Ali :Hello . Ali :Hello . ... . ... .

41

Logical . .True . .False . . . .True . .False . . Type . . : ... 2 1 1 text : 1Character text . : INTEGER A,B,C I N . IMPLICIT NONE IMPLICIT . : ... 2 1 Implicit . C T : IMPLICIT CHARACTER T,C :

51

)Implicit integer ( I-N )Implicit Real (A-H) , ( O-Z I N A H O Z . x1 x2 xn n x n : ... ) ( 2 ) ( 1 . 001 x : )001(Integer x . x 32 : 32=)5(X . ... )... , 2 , 1 ( 001 ) 452 ( )4,52(Real A 52 4 : : )4,:(Real A A 4 1 4 . : ... ) ... , 1 : 1( : )2:1-,:(Real A61

4 1- . ) : ( Allocate . : )3,:,:(Real Allocatable :: A ))3,4,21:11(Allocate (A Allocate 2 11 4 1 ) ( . ALLOCATE . ALLOCATE : ):(INTEGER*4, ALLOCATABLE:: A ))1(ALLOCATE(A ))2(ALLOCATE(A END ALLOCATE . ALLOCATED . . .TRUE . .FALSE . . : Allocatable Allocatable Allocate . 5.6 Visual Fortran Allocate Allocate . - Dimension

71

A B C )2,2( . : Real ,Dimension (2,2) ::A,B,C : )2,2(Real A(2,2) , B(2,2) , C Parameter . 295141.3 p : 295141.3 =Double Precision , Parameter :: P Read *,R 2**Print *,Area = , p*R Print *, S = , 2*p*R End . entity oriented attribute oriented entity oriented : ... 2 1 :: ... 2 1 Real Allocatable , Dimension (:) :: A,B attribute oriented : ... 2 1 ... 2 1 1 ... 2 1 2 ... Real A,B Dimension (:) A,B81

Allocatable A,B . . Kind . : Integer (Selected_INT_Kind(3)) A A 3 01- 301 . . : Real (Selected_Real_Kind(3,4))B B 3 4- 01 401 . Selected_INT_Kind Selected_Real_Kind : Integer (3) A Real (3,4) B : ... 1 )Character (Len=n ... 1 )Character (n ... 1 Character * n n . 1 . n m m>n n . Space . 1Character *4 C91

C1=Hello Hello Hell . 1Character *6 C C1=Hello Hello . )(Space .

02

. ) ( . )... 2 1( . : )ABS (x )CABS (x )DABS (x )IABS (x )ACOS (x )DACOS (x )AINT (x )DINT (x )ASIN (x )DSIN (x )ATAN (x )DTAN (x )ATAN2 (x )DTAN2 (x )CHAR (x )COS (x )CCOS (x )DCOS (x )CONJ (x )COSH (x )DCOSH (x22

Real Complex Integer Real Real Real Real Real Integer Real Complex Complex Real

Ascii

)DIM (x,y )IDIM (x,y )DPROD (x,y )EXP (x )CEXP (x )DEXP (x )ICHAR (x )INDEX (String,Substring )INT (x )IFIX (x )IDINT (x ) LEN( String )LOG (x )ALOG (x )CLOG (x )DLOG (x )LOG10 (x )ALOG10 (x )DLOG10 (x ),MAX (x,y ),MAX0 (x,y ),AMAX1 (x,y ),DMAX1 (x,y ),MAX1 (x,y ),AMAX0 (x,y ),MIN (x,y ),MIN0 (x,y ),AMIN1 (x,y ),DMIN1 (x,y32

Real Integer Real Real Complex Real Real Real Real Complex Real Real Real Integer Real Real Integer Real Integer Real

e e e

),MIN1 (x,y ),AMIN0 (x,y )MOD (x,y )AMOD (x,y )DMOD (x,y )REAL (x )FLOAT (x )SNGL (x )SIGN (x,y )DSIGN (x,y )ISIGN (x,y )SIN (x )CSIN (x )DSIN (x )SINH (x )DSINH (x )SQRT (x )CSQRT (x )DSQRT (x )TAN (x )DTAN (x )TANH (x )DTANH (x ) ADJUSTL ( String ) ADJUSTR (String ) TRIM ( String ) LEN_TRIM ( String42

Real Integer Integer Real Integer Integer Real Integer Real Complex Real Real Complex Real Real

x y x y x y

. ) ( . : ) ( IF . . : ) Then 1 ( IF )Then 2 ( Else IF . . . Else End IF Else IF Else ELSE IF Then . End IF . . Else Else Else . .

62

: Read *,I If ( I>=0 .AND. I= b must be true, they c = a ! are swapped if a < b a = b b = c END IF DO c = MOD(a, b) IF (c == 0) EXIT a = b b = c END DO ! now we have a Input) EXIT DO IF (MOD(Input,Divisor) /= 0 .OR. Input == 1) EXIT Count = Count + 1 WRITE(*,*) 'Factor # ', Count, ': ', Divisor Input = Input / D

Recommended

View more >