User:CYRIS JUNIX FORTRAN ADFLICTI/sandbox

CYRIS JUNIX FORTRAN, your pin is 758641. Please confirm your email address

= Fortran 95 language features = From Wikipedia, the free encyclopedia Jump to navigation		Jump to search

"Fortran language features" redirects here. For features of previous versions of the language, see Fortran § History.

This is an overview of Fortran 95 language features. Included are the additional features of TR-15581:Enhanced Data Type Facilities, that have been universally implemented. Old features that have been superseded by new ones are not described — few of those historic features are used in modern programs although most have been retained in the language to maintain backward compatibility. Although the current standard is Fortran 2008, even many of those features first introduced into Fortran 2003 are still being implemented.[1] The additional features of Fortran 2003 and Fortran 2008 are described by Metcalf, Reid and Cohen.[2][3]

Contents

 * 1 Language elements
 * 1.1 Basics
 * 1.2 Intrinsic data types
 * 1.2.1 Literal constants and kinds
 * 1.2.1.1 INTEGER
 * 1.2.1.2 REAL
 * 1.2.1.3 COMPLEX
 * 1.2.1.4 LOGICAL
 * 1.2.1.5 CHARACTER
 * 1.2.2 Number model and intrinsic functions
 * 1.3 Scalar variables
 * 1.4 Derived data types
 * 1.5 Implicit and explicit typing
 * 1.6 Arrays
 * 1.7 Data initialization
 * 1.7.1 PARAMETER attribute
 * 1.7.2 DATA statement
 * 1.7.3 Initialization expressions
 * 1.8 Specification expressions
 * 2 Expressions and assignments
 * 2.1 Scalar numeric
 * 2.2 Scalar relational operations
 * 2.3 Scalar characters
 * 2.4 Derived-data types
 * 2.5 Arrays
 * 3 Control statements
 * 3.1 Branching and conditions
 * 3.2 CASE construct
 * 3.3 DO construct
 * 4 Program units and procedures
 * 4.1 Definitions
 * 4.2 Internal procedures
 * 4.3 Modules
 * 4.4 Controlling accessibility
 * 4.5 Arguments
 * 4.6 Interface blocks
 * 4.7 Overloading and generic interfaces
 * 4.8 Recursion
 * 4.9 Pure Procedures
 * 5 Array handling
 * 5.1 Zero-sized arrays
 * 5.2 Assumed-shape arrays
 * 5.3 Automatic arrays
 * 5.4 ALLOCATABLE and ALLOCATE
 * 5.5 Elemental operations, assignments and procedures
 * 5.6 WHERE
 * 5.7 The FORALL Statement and Construct
 * 5.8 Array elements
 * 5.9 Array subobjects (sections)
 * 5.10 Arrays intrinsic functions
 * 6 Pointers
 * 6.1 Basics
 * 6.2 Association
 * 6.3 Pointers in expressions and assignments
 * 6.4 Pointer arguments
 * 6.5 Pointer functions
 * 6.6 Arrays of pointers
 * 6.7 Pointers as dynamic aliases
 * 7 Intrinsic procedures
 * 8 Data transfer
 * 8.1 Formatted input/output
 * 8.2 Internal files
 * 8.3 List-directed I/O
 * 8.4 Non-advancing I/O
 * 8.5 Edit descriptors
 * 8.5.1 Data edit descriptors
 * 8.5.2 Control edit descriptors
 * 8.6 Unformatted I/O
 * 8.7 Direct-access files
 * 9 Operations on external files
 * 9.1 File positioning statements
 * 9.2 The open statement
 * 9.3 The close statement
 * 9.4 The inquire statement
 * 10 References

Language elements
Fortran is case-insensitive. The convention of writing Fortran keywords in upper case and all other names in lower case is adopted in this article; except, by way of contrast, in the input/output descriptions (Data transfer and Operations on external files).

Basics
The basic component of the Fortran language is its character set. Its members are


 * the letters A ... Z and a ... z (which are equivalent outside a character context)
 * the numerals 0 ... 9
 * the underscore _
 * the special characters

Tokens that have a syntactic meaning to the compiler are built from those components. There are six classes of tokens: From the tokens, statements are built. These can be coded using the new free source form which does not require positioning in a rigid column structure: FUNCTION string_concat(s1, s2)                            ! This is a comment TYPE (string), INTENT(IN) :: s1, s2   TYPE (string) string_concat string_concat%string_data = s1%string_data(1:s1%length) // & s2%string_data(1:s2%length)                         ! This is a continuation string_concat%length = s1%length + s2%length END FUNCTION string_concat Note the trailing comments and the trailing continuation mark. There may be 39 continuation lines, and 132 characters per line. Blanks are significant. Where a token or character constant is split across two lines: ...       start_of& &_name ...  'a very long & &string' a leading  on the continued line is also required.

Automatic conversion of source form for existing programs can be carried out by convert.f90.

Its options are


 * significant blank handling;
 * indentation;
 * CONTINUE replaced by END DO;
 * name added to subprogram END statement; and
 * INTEGER*2 etc. syntax converted.

Intrinsic data types
Fortran has five intrinsic data types:,  ,  ,   and. Each of those types can be additionally characterized by a kind. Kind, basically, defines internal representation of the type: for the three numeric types, it defines the precision and range, and for the other two, the specifics of storage representation. Thus, it is an abstract concept which models the limits of data types' representation; it is expressed as a member of a set of whole numbers (e.g. it may be {1, 2, 4, 8} for integers, denoting bytes of storage), but those values are not specified by the Standard and not portable. For every type, there is a default kind, which is used if no kind is explicitly specified. For each intrinsic type, there is a corresponding form of literal constant. The numeric types  and   can only be signed (there is no concept of sign for type  ).

INTEGER
Integer literal constants of the default kind take the form 1  0   -999   32767   +10 Kind can be defined as a named constant. If the desired range is ±10kind, the portable syntax for defining the appropriate kind,  is INTEGER, PARAMETER :: two_bytes = SELECTED_INT_KIND(4) that allows subsequent definition of constants of the form -1234_two_bytes  +1_two_bytes Here,  is the kind type parameter; it can also be an explicit default integer literal constant, like -1234_2 but such use is non-portable.

The KIND function supplies the value of a kind type parameter: KIND(1)           KIND(1_two_bytes) and the  function supplies the actual decimal range (so the user must make the actual mapping to bytes): RANGE(1_two_bytes) Also, in  (initialization) statements, binary (B), octal (O) and hexadecimal (Z) constants may be used (often informally referred to as "BOZ constants"): B'01010101'  O'01234567'   Z'10fa'

REAL
There are at least two real kinds—the default and one with greater precision (this replaces ). functions returns the kind number for desired range and precision; for at least 9 decimal digits of precision and a range of 10−99 to 1099, it can be specified as: INTEGER, PARAMETER :: long = SELECTED_REAL_KIND(9, 99) and literals subsequently specified as 1.7_long Also, there are the intrinsic functions KIND(1.7_long)  PRECISION(1.7_long)   RANGE(1.7_long) that give in turn the kind type value, the actual precision (here at least 9), and the actual range (here at least 99).

COMPLEX
data type is built of two integer or real components: (1, 3.7_long)

LOGICAL
There are only two basic values of logical constants:  and. Here, there may also be different kinds. Logicals don't have their own kind inquiry functions, but use the kinds specified for s; default kind of   is the same as of INTEGER. .FALSE. .true._one_byte and the  function operates as expected: KIND(.TRUE.)

CHARACTER
The forms of literal constants for  data type are 'A string'  "Another"   'A "quote"'   ' (the last being an empty string). Different kinds are allowed (for example, to distinguish ASCII and UNICODE strings), but not widely supported by compilers. Again, the kind value is given by the  function: KIND('ASCII')

Number model and intrinsic functions
The numeric types are based on number models with associated inquiry functions (whose values are independent of the values of their arguments; arguments are used only to provide kind). These functions are important for portable numerical software:

Scalar variables
Scalar variables corresponding to the five intrinsic types are specified as follows: INTEGER(KIND=2) :: i REAL(KIND=long) :: a COMPLEX        :: current LOGICAL        :: Pravda CHARACTER(LEN=20) :: word CHARACTER(LEN=2, KIND=Kanji) :: kanji_word where the optional  parameter specifies a non-default kind, and the   notation delimits the type and attributes from variable name(s) and their optional initial values, allowing full variable specification and initialization to be typed in one statement (in previous standards, attributes and initializers had to be declared in several statements). While it is not required in above examples (as there are no additional attributes and initialization), most Fortran-90 programmers acquire the habit to use it everywhere.

specifier is applicable only to s and specifies the string length (replacing the older   form). The explicit  and   specifiers are optional: CHARACTER(2, Kanji) :: kanji_word works just as well.

There are some other interesting character features. Just as a substring as in CHARACTER(80) :: line ... = line(i:i)                    ! substring was previously possible, so now is the substring '0123456789'(i:i) Also, zero-length strings are allowed: line(i:i-1)      ! zero-length string Finally, there is a set of intrinsic character functions, examples being

Derived data types
For derived data types, the form of the type must be defined first: TYPE person CHARACTER(10) name REAL         age END TYPE person and then, variables of that type can be defined: TYPE(person) you, me To select components of a derived type,  qualifier is used: you%age Literal constants of derived types have the form  : you = person('Smith', 23.5)