Sie sind auf Seite 1von 25

- FORTRAN

.
CFD .
) (FORmula TRANslation
.
.
. 90
CFD .
IBM . .
.
77 90 90 .
90 77 .
][2

Fortran I 1954

Fortran II 1958

Fortran IV 1958

Fortran 66 standard 1966

Fortran 77 standard 1978

Fortran 90 standard 1991

Fortran 95 standard 1996

. .
. C
. 40
. .
. .
) (Graphical User Interface
) API!( . Visual Basic Delphi
. GUI
FORTRAN (Dynamic Link Library) DLL .
) ( .
Ansys .

90
90 .
77 . 90 ,
. ,
90 C++ !77 , )

( . 95
.

Digital Visual Fortran

Visual Fortran . Visual Fortran


.
Microsoft Visual Studio .
. . .
File New .
New < File -1

Projects . ) Fortran Consol Application ,(Icon


. Project Name .
Application Fortran Consol < (tab)Project -2

OK . Finish .
OK . . .
.
.
New < File -3

Files . Fortran Free Format Source File ) 90


( . File Name .
. Add to project .
Free Format Source File Fortran < (tab)Files -4

OK . . .
.
PROGRAM hello_fortran
!This is comment in fortran file
CHARACTER::A
'WRITE(*,*) 'Hello dear user, Fortran is so easy
READ(*,*) A
END PROGRAM hello_fortran

).(File > Save or CTRL+S


) (Compile . Build > Build Hello.exe
F7 . . -
. . hello.exe

. .
)Hello.exe - 0 error(s), 0 warning(s

Debug F5 .
go ) (.


.
-1 )
!( .
. .
-2 .
-3 .


90 .
PROGRAM program_name
! Comment and program information
Declaration of variables and/or external functions
Program body
END PROGRAM program_name
Declaration and body of user-made functions

. 77 ! 77
. 77 :

7 72 .

1 5 6
) 19 !(.

1 5 5 )
GOTO .

C.

77 .
PROGRAM program_name
Comment and program information
Declare of variables and/or external functions
Body of program
END PROGRAM program_name
Declaration an body of user-made functions

77 :
PROGRAM hello_fortran

C This is comment in fortran file


CHARACTER::A
'WRITE(*,*) 'Hello dear user, Fortran is so easy
READ(*,*) A
END PROGRAM hello_fortran

) ( .
IMPLICIT NONE .
. ! .

.
)
( . .
.
.

34 .

) (A...Z, a...z) (0,1,..,9 - ) _ (


.

. 77
:

INTEGER

REAL ) 8(

DOUBLE ) 16 ( ] [

CHARACTER

LOGICAL

COMPLEX REAL 77
.

1234 1234.0 1.234E3 1.234D3

. ) (3.14,-1E5
AbBa .S .TRUE. .FALSE. )
(.

. .


) (Compiler . IMPILICIT

NONE . .

a..h o..z

i,j,k,l,m,n

) (:
REAL:: alpha, beta, c=10.0

]Variable_type::variable_name [=initial value

INTEGER:: count, hours, minutes=36

PARAMETER

)}PARAMETER ({list of names=value

)PARAMETER (pi=3.141592



) / - + ( * ) ( . ** .

.1 .
.
.2
.3
.4
A*B**n-C/D ) A*(B**n)-(C/D .
.

The image part with


relationship ID rId5 was not
found in the file.

The image part with relationship ID


rId6 was not found in the file.

.
. 1/5 0 1./5.
0.2 1d0/1d5 0.2 .
. 4 4. 4d0

.
.
variable = expression
The image part with relationship ID rId7
was not found in the file.

The image part with relationship ID rId8 was not found in the
file.

a .
.


. 77 > < , ...
.EQ. .
.EQ. equal to
.GE. greater or equal to
.GT. greater than
.LE. less than or equal to
.LT. less than
.NE. not equal to

90 90 > == => =< < >< .


) (A .EQ. B ) (A==B .
.


:
logical negative

.NOT.

logical and

.AND.

logical or

.OR.

logical equivalence

.EQV.

)logical non-equivalence (exclusive or

.NEQV.
T: TRUE, F:FALSE

.NOT. x

x .AND. y

x .OR. y

x .EQV. y

x .NEQV. y


77 . 77 :
CHARACTER name*length

:
CHARACTER array (size)*length

* .
)*(*CHARACTER format_scope
)!PARAMETER(format_scope=this is constant character

77 .
: . // .
)substring= string(start position: end position

, .
CHARACTER first_word*8, second_word*5, third_word*20
first_word=FORTRAN
)second_word=first_word(:3
)third_word=second_word // first_word(4:

third_word FOR TRAN )


second_word(.


. LEN CHAR ICHAR
INDEX . .

LLE LGT LGE LLT


.



.
READ

.
READ *, {input list} or
}RAED([UNIT=] unit type, [FMT=] format) {input list

unit type 5
format . * .
READ (*,*) a, b, c

WRITE

.
}PRINT *,{output list
}WRITE([UNIT=] unit type, [FMT=] format) {output list

unit type READ format .


WRITE(*,*) The total is:, total

The total is: total .


- FORMAT

. .
format .

) 77 1 5 (. .
.
)FORMAT (format sequence

WRITE .
)FMT= (format sequence

.

* .

format sequence

FORMAT .
.
Data description
Iw, Iw.m

Integer

Ew.d, Ew.dEe, Fw.d,Gw.d, Gw.dEe

Floating Point

Lw

Logical

A, Aw

Character

:
:I

:F

:E

:G

:L

Data type

:A


:w

:m

:d

)(

:e

Any string

nX

:
'WRITE(UNIT=*,FMT=10) 'The frequency is', f, 'Hz
)FORMAT(1X, A, F10.5, A

10

f 15 5
. UNIT FMT
.
'WRITE(*,10) 'The frequency is', f, 'Hz
)FORMAT(1X, A, F10.5, A

10

:
.
2 . 2 .

The image part with relationship ID rId9 was not found in


the file.

. .

The image part with relationship ID rId10 was not found in the file.

.1
.2
.3
.4

.1-4

.2-4


" "

.3-4

.5

:
PROGRAM Equation_solver_fortran
! This is program calculate the real roots of second order equation
IMPLICIT NONE

! this is important to get used to this statment

! Variable decleration
CHARACTER::end_key
REAL::a,b,c
REAL::Delta, x1, x2
! Main Porgram
WRITE(*,*) Please enter the equation coefficients a*x^2+b*x+c
WRITE(*,*) a: ?
READ(*,*) a
WRITE(*,*) b: ?
READ(*,*) b
WRITE(*,*) c: ?
READ(*,*) c

Delta=b**2-4*a*c

IF (Delta >= 0) THEN


)x1=(b+SQRT(Delta))/(2*a
)x2=(b-SQRT(Delta))/(2*a
WRITE(*,*) The real roots are : , x1, x2
ELSE
!WRITE(*,*) This equation has no real root
ENDIF
READ(*,*) end_key
END PROGRAM Equation_solver_fortran

. .
. IF..THEN..ELSE )( SQRT
IF..THEN..ELSE )( SQRT
.
. .
.
. .
.


.
READ WRITE . UNIT .
UNIT * .
) (UNIT .

OPEN

. .
:

(ACCESS= access ,OPEN(UNIT= number, FILE= Name of file, STATUS= status

number ) 0 255
255 !( .
status NEW OLD
UNKNOWN SCRATCH
! REPLACE .
.
access DIRECT SEQUENTAL .
SEQUENTAL . .
.

CLOSE

. :
(UNIT= unit, STATUS = status) CLOSE

unit status KEEP DELETE .


.


Intrinsic Functions

. .
SIN, COS, ASIN, ACOS, TAN, ATAN, COTAN :

: ABS SQRT LOG, LOG10 EXP MIN,MAX


MOD...

DOT_PRODUCT, MATMUL, TRANSPOSE, :

.
!!

. Digital Visual Fortran
) help .(.
.
)}Result_variable = function_name({list of parameters

:
)a= sin(b

b a !

Intrinsic Subroutines

. !
. .
. CALL .
)}CALL subroutine_name({list of variables

:
SYSTEM_CLOCK ,DATE_AND_TIME, MVBITS, RANDOM_NUMBER, RANDOM_SEED

External Functions

. . :
)}type FUNCTION name ({dummy arguments

local variable declaration


body of function
name = expression
body of function continued if needed
END FUNCTION name

type ) ( . .
. .
"" .
arguments dummy 1 ) .
( . .
.
!
.
)REAL FUNCTION Newton (m1, m2, r
REAL:: gamma = 6.672E-11, m1, m2, r
Newton = -gamma*m1*m2/r**2
END Newton

Statement Functions

.
Function_name({list of parameters}) = expression

.

Newton(m1, m2, r) = -6.672E-11*m1*m2/r**2

External Subroutines

{name {dummy argument list SUBROUTINE


local variables declaration
body of subroutine
name END SUBROUTINE

) call by reference VAR arg Pascal &arg (C++


.
.

RETURN, SAVE, EXTERNAL, INTERNAL


) ( . RETURN .
.
.
) (STATIC ALLOCATION .
SAVE . :
]}SAVE [{list of local variables to be saved

.
.
}INTRINSIC {list of function names
}EXTERNAL {list of function names


PROGRAM func
EXTERNAL CTN
INTRINSIC SIN, COS

REAL::angle=0.785 !...pi/4

REAL::sine,cosine,tangent

CALL TRIG(angle,SIN,sine)
WRITE(*,*) 'SIN(0.785)=',sine

CALL TRIG(angle,COS,cosine)
WRITE(*,*) 'COS(0.785)=',cosine

CALL TRIG(angle,CTN,cotangent)
WRITE(*,*) 'COTAN(0.785)=',cotangent

READ*,r
END PROGRAM func

SUBROUTINE TRIG(X,F,Y)
Y = F(X)
RETURN
END SUBROUTINE TRIG

FUNCTION CTN(X)
CTN = COS(X)/SIN(X)
RETURN
END FUNCTION CTN


.
IF

. .
.
IF (First condition statement) THEN
First sequence of commands

ELSE IF (Second condition statement) THEN


Second sequence of commands
ELSE IF

ELSE
Alternative sequence of commands
END IF

:
IF (number .LT. 0) THEN
sign=-1
ELSE IF (number .GT. 0) THEN
sign=1
ELSE
sign=0
END IF

IF . ELSE THEN END IF .


IF (Condition statement) Statement to be executed
'IF (r==0) WRITE(*,*) 'r=0

Do

. GOTO )
( .
.
DO :
label: DO counter=start, limit, step
Sequence of commands to be looped through
END DO label

for while C .
EXIT CYCLE .
) (label GOTO!
:
]EXIT [name of loop
]CYCLE [name of loop


. .
. .
)REAL:: array(5
Outer: DO
READ(*,*) array
Inner: DO k=1, 5
IF (array(k)==0) CYCLE inner
IF (array(k)<0) EXIT
))Array(k)=1/SQRT(array(k
END DO inner
WRITE(*,*) array
END DO outer

) DO ( . EXIT
.
DO 77 :
DO label, counter=start, limit, step
Sequence of commands to be looped through
CONTINUE
GOTO

. .

label

GOTO label

! .

GOTO
.
STOP
! .
:
]STOP [message
Arrays


. .
.
)}type array_name({lower bound in nth dimention:Upper bound in nth dimention

.
50 70 1 20:
)REAL:: temperature(50:70, 1:20

)REAL:: temperature(50:70, 20

. 77 7 .
DO
) ( .
90
. .

55 12 temp 56
13 400 .
)temp = temperature(55,12
temperature(56,13) = 400.0

.
temperature .
WRITE(*,*) temperature


, ,
) (fixed-size array
! *
) ( .
.

:
Physics Department, State University of Michigan, September ,to FORTRAN Introduction ,Aloksandra Donev
reading recommended for 1999

: " "Visual C++ 6 1377


" " 1370
]http://www.pcc.qub.ac.uk/tec/courses/f90/ohp/header_ohMIF_1.html [2
]Help of Digital Visual FORTRAN standard edition V 6.0 [3

Das könnte Ihnen auch gefallen