Professional Documents
Culture Documents
Contents
Introduction to Fortran 95 Language
Meta language used in this compact summary
Structure of files that can be compiled
Executable Statements and Constructs
Declarations
Key words (other than I/O)
Key words related to I/O
Operators
Constants
Input/Output Statements
Formats
Intrinsic Functions
Other Links
old
common, dimension, equivalence now obsolete
module <name>
implicit none
converted by W eb2PDFConvert.com
<declarations>
end module <name>
subroutine <name>
implicit none
<declarations>
<executable statements>
end subroutine <name>
old
use: <name>(arg1, arg2, ... argn) as variable
required somewhere in execution
optional, end causes automatic return
stop
stop <integer>
stop <string>
return
do <variable>=<from>,<to> [,<increment>]
<statements>
exit
if (<boolean expression>) exit
cycle
if (<boolean expression>) cycle
end do
do while (<boolean expression>)
...
end do
do
...
end do
old
Declarations
There are five (5) basic types: integer, real, complex, character and logical.
There may be any number of user derived types. A modern (not old) declaration
starts with a type, has attributes, then ::, then variable(s) names
integer i, pivot, query
old
old
real (selected_real_kind(15,300) :: x
complex :: z
logical, parameter :: what_if = .true.
character, parameter :: me = "Jon Squire"
type <name>
declarations
end type <name>
optional
parameter
pointer
private
public
save
target
Note:
argument is optional
declaring a constant, can not be changed later
declaring a pointer
in a module, a private declaration
in a module, a public declaration
keep value from one call to the next, static
can be pointed to by a pointer
not all combinations of attributes are legal
save
select case
stop
subroutine
target
then
type
type ( )
use
where
while
attribute,
construct,
statement,
construct,
attribute,
part of if
construct,
statement,
statement,
construct,
construct,
statement,
statement,
statement,
statement,
statement,
statement,
statement,
statement,
statement,
statement,
Operators
**
exponentiation
*
multiplication
/
division
+
addition
subtraction
//
concatenation
==
.eq. equality
/=
.ne. not equal
<
.lt. less than
>
.gt. greater than
<=
.le. less than or equal
>=
.ge. greater than or equal
.not.
complement, negation
.and.
logical and
.or.
logical or
.eqv.
logical equivalence
.neqv.
logical not equivalence, exclusive or
.eq.
.ne.
.lt.
.gt.
.le.
.ge.
==
/=
<
>
<=
>=
equality, old
not equal. old
less than, old
greater than, old
less than or equal, old
greater than or equal, old
Other punctuation:
/ ... /
(/ ... /)
6*1.0
(i:j:k)
(:j)
(i:)
(:)
Constants
Logical constants:
.true.
.false.
True
False
Integer constants:
0
-1
123456789
Real constants:
0.0
1.0
-1.0
123.456
7.1E+10
-52.715E-30
converted by W eb2PDFConvert.com
Complex constants:
(0.0, 0.0)
(-123.456E+30, 987.654E-29)
Character constants:
"ABC"
'ABC'
"a" "123'abc$%#@!"
'a' '123"abc$%#@!'
Input/Output Statements
open (<unit number>)
open (unit=<unit number>, file=<file name>, iostat=<variable>)
open (unit=<unit number>, ... many more, see below )
close (<unit number>)
close (unit=<unit number>, iostat=<variable>,
err=<statement number>, status="KEEP")
read (<unit number>) <input list>
read (unit=<unit number>, fmt=<format>, iostat=<variable>,
end=<statement number>, err=<statement number>) <input list>
read (unit=<unit number>, rec=<record number>) <input list>
write (<unit number>) <output list>
write (unit=<unit number>, fmt=<format>, iostat=<variable>,
err=<statement number>) <output list>
write (unit=<unit number>, rec=<record number>) <output list>
print *, <output list>
print "(<your format here, use apostrophe, not quote>)", <output list>
rewind <unit number>
rewind (<unit number>, err=<statement number>)
backspace <unit number>
backspace (<unit number>, iostat=<variable>)
endfile <unit number>
endfile (<unit number>, err=<statement number>, iostat=<variable>)
inquire ( <unit number>, exists = <variable>)
inquire ( file=<"name">, opened = <variable1>, access = <variable2> )
inquire ( iolength = <variable> ) x, y, A ! gives "recl" for "open"
namelist /<name>/ <variable list>
defines a name list
read(*,nml=<name>)
reads some/all variables in namelist
write(*,nml=<name>)
writes all variables in namelist
&<name> <variable>=<value> ... <variable=value> / data for namelist read
Input / Output specifiers
access
action
advance
blank
delim
end
eor
err
exist
file
fmt
form
iolength
iostat
name
named
nml
nextrec
number
opened
pad
position
rec
recl
size
status
unit
one
one
one
=
=
=
=
=
=
one
=
=
=
=
=
=
=
=
one
one
=
=
=
one
=
of "yes" "no"
of "null" "zero"
of "apostrophe" "quote" "none"
<integer statement number> old
<integer statement number> old
<integer statement number> old
<logical variable>
<"file name">
<"(format)"> or <character variable> format
of "formatted" "unformatted" "undefined"
<integer variable, size of unformatted record>
<integer variable> 0==good, negative==eof, positive==bad
<character variable for file name>
<logical variable>
<namelist name>
<integer variable>
one greater than written
<integer variable unit number>
<logical variable>
of "yes" "no"
of "asis" "rewind" "append"
<integer record number>
<integer unformatted record size>
<integer variable> number of characters read before eor
of "old" "new" "unknown" "replace" "scratch" "keep"
<integer unit number>
Individual questions
direct
=
<character
formatted =
<character
read
=
<character
readwrite =
<character
sequential =
<character
unformatted =
<character
write
=
<character
variable>
variable>
variable>
variable>
variable>
variable>
variable>
"yes"
"yes"
"yes"
"yes"
"yes"
"yes"
"yes"
"no"
"no"
"no"
"no"
"no"
"no"
"no"
"unknown"
"unknown"
"unknown"
"unknown"
"unknown"
"unknown"
"unknown"
Formats
format
examples:
print "(3I5,/(2X,3F7.2/))", <output list>
write(6, '(a,E15.6E3/a,G15.2)' ) <output list>
read(unit=11, fmt="(i4, 4(f3.0,TR1))" ) <input list>
A format includes the opening and closing parenthesis.
A format consists of format items and format control items separated by comma.
A format may contain grouping parenthesis with an optional repeat count.
Format Items, data edit descriptors:
key: w
m
d
e
c
n
is
is
is
is
is
is
cAw
data of type character (w is optional)
cBw.m data of type integer with binary base
cDw.d data of type real -- same as E, old double precision
cEw.d or Ew.dEe data of type real
cENw.d or ENw.dEe data of type real -- exponent a multiple of 3
cESw.d or ESw.dEe data of type real -- first digit non zero
cFw.d data of type real -- no exponent printed
cGw.d or Gw.dEe data of type real -- auto format to F or E
nH
n characters follow the H, no list item
cIw.m data of type integer
cLw
data of type logical -- .true. or .false.
cOw.m data of type integer with octal base
cZw.m data of type integer with hexadecimal base
"<string>" literal characters to output, no list item
'<string>' literal characters to output, no list item
Format Control Items, control edit descriptors:
BN
BZ
nP
S
SP
SS
Tn
TLn
TRn
nX
/
:
note: when there are more items in the input list than format items, the
repeat rules for formats applies.
<output list> can be:
a constant
a variable
an expression
an array name
an implied do ((A(i,j),j=1,n) ,i=1,m)
note: when there are more items in the output list than format items, the
repeat rules for formats applies.
Repeat Rules for Formats:
Each format item is used with a list item. They are used in order.
When there are more list items than format items, then the following
rule applies: There is an implied end of record, /, at the closing
parenthesis of the format, this is processed. Scan the format backwards
to the first left parenthesis. Use the repeat count, if any, in front
of this parenthesis, continue to process format items and list items.
Note: an infinite loop is possible
print "(3I5/(1X/))", I, J, K, L
Intrinsic Functions
Intrinsic Functions are presented in alphabetical order and then grouped
by topic. The function name appears first. The argument(s) and result
give an indication of the type(s) of argument(s) and results.
[,dim=] indicates an optional argument "dim".
"mask" must be logical and usually conformable.
"character" and "string" are used interchangeably.
A brief description or additional information may appear.
Intrinsic Functions (alphabetical):
abs(integer_real_complex) result(integer_real_complex)
achar(integer) result(character) integer to character
acos(real) result(real) arccosine |real| 1.0 0resultPi
adjustl(character) result(character) left adjust, blanks go to back
adjustr(character) result(character) right adjust, blanks to front
aimag(complex) result(real) imaginary part
aint(real [,kind=]) result(real) truncate to integer toward zero
all(mask [,dim]) result(logical) true if all elements of mask are true
allocated(array) result(logical) true if array is allocated in memory
anint(real [,kind=]) result(real) round to nearest integer
any(mask [,dim=}) result(logical) true if any elements of mask are true
asin(real) result(real) arcsine |real| 1.0 -Pi/2resultPi/2
associated(pointer [,target=]) result(logical) true if pointing
atan(real) result(real) arctangent -Pi/2resultPi/2
atan2(y=real,x=real) result(real) arctangent -PiresultPi
bit_size(integer) result(integer) size in bits in model of argument
btest(i=integer,pos=integer) result(logical) true if pos has a 1, pos=0..
ceiling(real) result(real) truncate to integer toward infinity
char(integer [,kind=]) result(character) integer to character [of kind]
cmplx(x=real [,y=real] [kind=]) result(complex) x+iy
conjg(complex) result(complex) reverse the sign of the imaginary part
cos(real_complex) result(real_complex) cosine
cosh(real) result(real) hyperbolic cosine
count(mask [,dim=]) result(integer) count of true entries in mask
cshift(array,shift [,dim=]) circular shift elements of array, + is right
date_and_time([date=] [,time=] [,zone=] [,values=]) y,m,d,utc,h,m,s,milli
dble(integer_real_complex) result(real_kind_double) convert to double
digits(integer_real) result(integer) number of bits to represent model
dim(x=integer_real,y=integer_real) result(integer_real) proper subtraction
dot_product(vector_a,vector_b) result(integer_real_complex) inner product
dprod(x=real,y=real) result(x_times_y_double) double precision product
converted by W eb2PDFConvert.com
converted by W eb2PDFConvert.com
Other Links
Go to top
Last updated 8/23/2009 for html, from 1998 version
converted by W eb2PDFConvert.com