fortran 90 overview - tables

Download Fortran 90 Overview - Tables

Post on 13-Nov-2014

1.478 views

Category:

Documents

3 download

Embed Size (px)

TRANSCRIPT

1

Fortran 90 OverviewJ.E. Akin, Copyright 1998

This overview of Fortran 90 (F90) features is presented as a series of tables that illustrate the syntax and abilities of F90. Frequently comparisons are made to similar features in the C++ and F77 languages and to the Matlab environment. These tables show that F90 has signicant improvements over F77 and matches or exceeds newer software capabilities found in C++ and Matlab for dynamic memory management, user dened data structures, matrix operations, operator denition and overloading, intrinsics for vector and parallel processors and the basic requirements for object-oriented programming. They are intended to serve as a condensed quick reference guide for programming in F90 and for understanding programs developed by others.

List of Tables1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Comment syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Intrinsic data types of variables . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relational operators (arithmetic and logical) . . . . . . . . . . . . . . . . . Precedence pecking order . . . . . . . . . . . . . . . . . . . . . . . . . . . Colon Operator Syntax and its Applications . . . . . . . . . . . . . . . . . Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Flow Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . Basic loop constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IF Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nested IF Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Logical IF-ELSE Constructs . . . . . . . . . . . . . . . . . . . . . . . . . Logical IF-ELSE-IF Constructs . . . . . . . . . . . . . . . . . . . . . . . Case Selection Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . F90 Optional Logic Block Names . . . . . . . . . . . . . . . . . . . . . . GO TO Break-out of Nested Loops . . . . . . . . . . . . . . . . . . . . . . Skip a Single Loop Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . Abort a Single Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F90 DOs Named for Control . . . . . . . . . . . . . . . . . . . . . . . . . Looping While a Condition is True . . . . . . . . . . . . . . . . . . . . . . Function denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arguments and return values of subprograms . . . . . . . . . . . . . . . . Dening and referring to global variables . . . . . . . . . . . . . . . . . . Bit Function Intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . The ACSII Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . F90 Character Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . How to type non-printing characters . . . . . . . . . . . . . . . . . . . . . Referencing Structure Components . . . . . . . . . . . . . . . . . . . . . . Dening New Types of Data Structure . . . . . . . . . . . . . . . . . . . . Nested Data Structure Denitions . . . . . . . . . . . . . . . . . . . . . . Declaring, initializing, and assigning components of user-dened datatypes F90 Derived Type Component Interpretation . . . . . . . . . . . . . . . . Denition of pointers and accessing their targets . . . . . . . . . . . . . . . Nulling a Pointer to Break Association with Target . . . . . . . . . . . . . Special Array Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . Array Operations in Programming Constructs . . . . . . . . . . . . . . . . Equivalent Fortran90 and M ATLAB Intrinsic Functions . . . . . . . . . . . Truncating Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F90 WHERE Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . F90 Array Operators with Logic Mask Control . . . . . . . . . . . . . . . Array initialization constructs . . . . . . . . . . . . . . . . . . . . . . . . . Array initialization constructs . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4 4 5 5 5 6 7 7 8 8 8 8 9 9 9 10 10 10 11 11 12 12 12 13 13 13 14 14 14 14 15 15 15 15 16 17 18 18 19 20 20

LIST OF TABLES43 44 45 46 47 48 49 Elementary matrix computational routines . . . . . . . Dynamic allocation of arrays and pointers . . . . . . . Automatic memory management of local scope arrays . F90 Single Inheritance Form . . . . . . . . . . . . . . F90 Selective Single Inheritance Form . . . . . . . . . F90 Single Inheritance Form, with Local Renaming . . F90 Multiple Selective Inheritance with Renaming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3 20 21 21 21 22 22 22

4

LIST OF TABLES

Language M ATLAB C F90 F77

Syntax% comment (to end of line) /*comment*/ ! comment (to end of line) * comment (to end of line)

Location anywhere anywhere anywhere column 1

Table 1: Comment syntax.

Storage byte integer single precision double precision complex Boolean argument pointer structure

M ATLAB a

C++char int float doubleb

F90character:: integer:: real:: real*8:: complex:: logical:: parameter:: pointer:: type::

F77character integer real double precision complex logical parameter

bool * struct

a M ATLAB 4 requires no variable type declaration; the only two distinct types in M ATLAB are strings and reals (which include complex). Booleans are just 0s and 1s treated as reals. M ATLAB 5 allows the user to select more types. b There is no specic data type for a complex variable in C++; they must be created by the programmer.

Table 2: Intrinsic data types of variables.

Description addition subtractionc multiplication division exponentiation remainder increment decrement parentheses (expression grouping)

M ATLAB a + * and .* / and ./ and .

()

C++ + * / powd % ++ -()

Fortranb + * / **

()

a When doing arithmetic operations on matrices in M ATLAB , a period (.) must be put before the operator if scalar arithmetic is desired. Otherwise, M ATLAB assumes matrix operations; gure out the difference between * and .*. Note that since matrix and scalar addition coincide, no .+ operator exists (same holds for subtraction). b Fortran 90 allows the user to change operators and to dene new operator symbols. c In all languages the minus sign is used for negation (i.e., changing sign). d In C++ the exponentiation is calculated by function pow .

Table 3: Arithmetic operators.

LIST OF TABLESDescription Equal to Not equal to Less than Less or equal Greater than Greater or equal Logical NOT Logical AND Logical inclusive OR Logical exclusive OR Logical equivalent Logical not equivalent M ATLAB == = < >= & !xor

5 C++ == != < >= ! && || == != F90 == /= < >=.NOT. .AND. .OR. .XOR. .EQV. .NEQV.

F77.EQ. .NE. .LT. .LE. .GT. .GE. .NOT. .AND. .OR. .XOR. .EQV. .NEQV.

== =

Table 4: Relational operators (arithmetic and logical). M ATLAB Operators() + -

C++ Operators() [] -> . ! ++ -- + - * & (type) sizeof * / % + -b > < =>

F90 Operatorsa() **

F77 Operators() **

* / + -b < >= == =

* / + -b // == /= < >= .NOT. .AND. .OR. .EQV. .NEQV.

& | =

== != && || | ?: = += -= *= /= %= &= = |= = ,

* / + -b // .EQ. .NE. .LT. .LE. .GT. .GE. .NOT. .AND. .OR. .EQV. .NEQV.

a User-dened b These

unary (binary) operators have the highest (lowest) precedence in F90. are binary operators representing addition and subtraction. Unary operators + and - have higher precedence.

Table 5: Precedence pecking order.B = Beginning, E = Ending, I = Increment

Syntax Default

F90B:E:I B: :E :

M ATLABB:I:E B: :E :

B E

Full range

Use Array subscript ranges Character positions in a string Loop control Array element generation

F90 yes yes no no

M ATLAB yes yes yes yes

Table 6: Colon Operator Syntax and its Applications.

6

LIST OF TABLES

conj(z) imag(z) fix(x) round(x) cos(x) sin(x) tan(x) acos(x) asin(x) atan(x) atan2(x,y) cosh(x) sinh(x) tanh(x) acosh(x) asinh(x) atanh(x)

cos(x) sin(x) tan(x) acos(x) asin(x) atan(x) atan2(x,y) cosh(x) sinh(x) tanh(x)

Table 7: Mathematical functions.

is used to calculate the arc tangent of computes the arc tangent of in the range .

b atan2(x,y)

in the range

a Differ

for

.

Description exponential natural log base 10 log square root raise to power ( ) absolute value smallest integer x largest integer x division remainder modulo complex conjugate imaginary part drop fraction round number cosine sine tangent arc cosine arc sine arc tangent arc tangentb hyperbolic cosine hyperbolic sine hyperbolic tangent hyperbolic arc cosine hyperbolic arc sine hyperbolic arctan

M ATLABexp(x) log(x) log1

Recommended

View more >