Fortran 90 Reference Card

ADVERTISEMENT

Fortran 90 Reference Card
2 Control Constructs
subroutine foo(a,b,c,d,e,x,y)
subroutine definition
integer, intent(in) :: a
read-only dummy variable
if (expr) action
if statement
(c) 2008 Michael Goerz <goerz@physik.fu-berlin.de>
integer, intent(inout) :: b
read-write dummy variable
[name:] if (expr) then
if-construct
integer, intent(out) :: c
write-only dummy variable
block
real, optional :: d
For a complete reference, I highly recommend
optional named argument
else if (expr) then [name]
Adams, Brainerd, Martin, Smith, Wagener, Fortran 90 Handbook, Intertext Publications, 1992.
character (len=*) :: e
assumed length string
block
real, dimension (2:, :) :: x
assumed-shape dummy array
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
else [name]
real, dimension (10, *) :: y
To view a copy of this license, visit
assumed-size dummy array
block
if (present(d)) ...
presence check
end if [name]
1 Data Types
return
forced exit
select case (number)
select-statement
end subroutine foo
1.1 Simple Data Types
(entity-oriented declarations)
case (:0)
everything up to 0 (incl.)
call foo(1,2,3,e="s",x=a,y=b)
subroutine call
block
integer(specs) [,attrs] :: i=1 integer (with initialization)
[real] function f(a,g)
function definition
case (1:2)
number is 1 or 2
real(specs) [,attrs] :: r
real number
integer, intent(in) :: a
input parameter
block
complex(specs) [,attrs] :: z
complex number
[real :: f]
return type, if not in definition
case (3)
number is 3
logical(specs) [,attrs] :: b
boolean variable
interface
explicit interface block
block
character(specs) [,attrs] :: s string
real function g(x)
define dummy var as function
case (4:)
everything up from 4 (incl.)
real, parameter :: c = 2.998
constant declaration
real, intent(in) :: x
block
data i,j,k/3*0/
initialize i, j, k to 0
end function g
case default
fall-through case
s2=s(2:5); s2=s(:5); s2=s(5:)
substring extraction
end interface
block
attributes: parameter, pointer, target, allocatable,
end function f
end select
dimension, public, private, intent, optional, save,
recursive function f(x) ...
allow recursion
outer: do
controlled do-loop
external, intrinsic
incr(x) = x + 1
statement function
inner: do i=from,to,step
counter do-loop
specs: kind=..., for character: len=...
interface
explicit interface of externals
if (...) cycle inner
next iteration
1.1 Derived Data Types
interface body
ext. subroutine/function specs
if (...) exit outer
exit from named loop
end interface
type person
Define person as derived data
end do inner
interface generic-name
generic interface (overloading)
character(len=10) :: name
type
end do outer
interface body
external subroutines/functions
integer :: age
do while (expr)
do-while loop
module procedure list
internal subroutines/functions
end type person
block
end interface
type(person) :: me
instantiate person
end do
interface operator op
operator interface
me = person(“michael”, 24)
constructor
interface body
external functions
name = me%name
access structure component
module procedure list
3 Program Structure
internal functions
1.2 Arrays and Matrices
end interface
real, dimension(5) :: v
explicit array with index 1..5
program foo
main program
interface assignment (=)
conversion interface
real, dimension(-1:1,3) :: a
2D array, index -1..1, 1..3
use foo, lname => usename
used module, with rename
interface body
external subroutines
integer :: a(-10:5), b(10,20)
alternative array declaration
use foo2, only: [only-list]
selective use
module procedure list
internal subroutines
real, allocatable :: a(:)
alloc. array ("deferred shape")
implicit none
require variable declaration
end interface
a=real(5,5); data a/25*0.0/
initialize 2D array
interface; ...
explicit interfaces
a=(/1.2,b(2:6,:),3.5/)
array constructor
end interface
specification statements
4 Intrinsic Procedures
variable/type declarations, etc.
a=(/(I**2), I = 1, N)/)
implied-do array constructor
exec statements
statements
v = 1/v + a(1:5,5)
array expression
4.1 Transfer and Conversion Functions
stop 'message'
terminate program
allocate(a(5),b(2:4),stat=e)
array allocation
abs(a)
absolute value
contains
1.3 Pointers
(avoid!)
aimag(z)
imaginary part of complex z
internal-subprograms
subroutines, functions
real, pointer :: p
declare pointer
aint(x, kind), anint(x, kind)
to whole number real
end program foo
real, pointer :: a(:)
alloc. array ("deferred shape")
dble(a)
to double precision
module foo
module
real, target :: r
define target
cmplx(x,y, kind)
create x + iy (y optional)
use foo
used module
p => r
set pointer p to r
int(a, kind), nint(a, kind)
to int (truncated/rounded)
public :: f1, f2, ...
list public subroutines
associated(p, [target])
pointer associated with target?
real(x, kind)
to real
private
make private what's not public
nullify(p)
associate pointer with NUL
conj(z)
complex conjugate
interface; ...
explicit interfaces
1.4 Operators
char(i, kind), achar(i)
char of ASCII code (pure 7bit)
end interface
ichar(c), iachar(c)
ASCII code of character
.lt. .le. .eq. .ne. .gt. .ge.
relational operators
specification statements
variable/type declarations, etc.
.not. .and. .or. .eqv. .neqv.
logical operators
contains
logical(l, kind)
change kind of logical l
x**(-y)
internal-subprograms
ibits(i, pos, len)
extract sequence of bits
exponentiation
“ module subprgs.”
transfer(source, mold, size)
reinterpret data
'AB'//'CD'
string concatenation
end module foo

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2