This chapter describes each of the Fortran statements. Each description includes a brief summary of the statement, a syntax description, a complete description and an example. The statements are listed in alphabetical order.
At the top of each reference page is an indication of the origin of the statement. Categories of origin are: 77 for Fortran 77 statements that are essentially unchanged from the original Fortran 77 standard. The heading 90, indicates the statement is either new for Fortran 90, or significantly changed in Fortran 90 from its original Fortran 77 definition. The heading HPF, indicates that the statement has its origin in the HPF standard. The heading CMF indicates a CM Fortran feature (CM Fortran is a version of Fortran that was produced by Thinking Machines Corporation). Obsolescent indicates the statement is unchanged from the Fortran 77 definition and has a better replacement in Fortran 90. The final category is @, which indicates a statement that is a PGI extension to HPF/Fortran 90.
The ACCEPT statement has the same syntax as the PRINT statement and causes formatted input to be read on standard input, stdin. ACCEPT is identical to the READ statement with a unit specifier of asterisk (*).
Syntax
ACCEPT f [,iolist] ACCEPT namelist
Examples
ACCEPT *, IA, ZA ACCEPT 99, I, J, K ACCEPT SUM 99 FORMAT(I2, I4, I3)
See Also
READ, PRINT
The ALLOCATABLE specification statement (attribute) specifies that an array with fixed dimensions is available for a future ALLOCATE statement. An ALLOCATE statement allocates space for the allocatable array.
Syntax
ALLOCATABLE [ :: ] array-name [(deferred-array-spec)] [, array-name [(deferred-array-spec)]]...
Example
REAL SCORE(:), NAMES(:,:)
REAL, ALLOCATABLE, DIMENSION(:,:,:) :: TEST
ALLOCATABLE SCORE, NAMES
INTEGER, ALLOCATABLE:: REC1(: ,: , :)
See Also
ALLOCATE, DEALLOCATE
The ALLOCATE statement allocates storage for each pointer-based variable and allocatable array which appears in the statement. ALLOCATE also declares storage for deferred-shape arrays.
Syntax
ALLOCATE ( allocation-list [ , STAT= var ] )allocation-list is:
allocate-object [ allocate-shape-spec-list ]allocate-object is:
variable-nameallocate-shape-spec-list is:
structure-component
[ allocate-lower-bound : ] allocate-upper-bound
Description
For a pointer based variable, its associated pointer variable is defined with the address of the allocated memory area. If the specifier STAT= is present, successful execution of the ALLOCATE statement causes the status variable to be defined with a value of zero. If an error occurs during execution of the statement and the specifier STAT= is present, the status variable is defined to have the integer value one. If an error occurs and the specifier STAT= is not present, program execution is terminated.
For an ALLOCATABLE array, the array is allocated with the executable ALLOCATE statement.
Examples
REAL, ALLOCATABLE :: A(:), B(:)
ALLOCATE (A(10), B(SIZE(A))) REAL A(:,:)
N=3
M=1
ALLOCATE (A(1:11, M:N)) INTEGER FLAG, N
REAL, ALLOCATABLE:: B(:,:)
ALLOCATE (B(N,N),STAT=FLAG)
Syntax
ARRAY [::] array-name (array-spec)
[, array-name (array-spec) ] ...
Description
ARRAY can be used in a subroutine as a synonym for DIMENSION to establish an argument as an array, and in this case the declarator can use expressions formed from integer variables and constants to establish the dimensions (adjustable arrays). Note however that these integer variables must be either arguments or declared in COMMON; they cannot be local. Note that in this case the function of ARRAY is merely to supply a mapping of the argument to the subroutine code, and not to allocate storage.
The typing of the array in an ARRAY statement is defined by the initial letter of the array name in the same way as variable names, unless overridden by an IMPLICIT or type declaration statement. Arrays may appear in type declaration and COMMON statements but the array name can appear in only one array declaration.
Example
REAL, ARRAY(3:10):: ARRAY_ONEThis specifies ARRAY_ONE as a vector having eight elements with the lower bound of 3 and the upper bound of 10.
INTEGER, ARRAY(3,-2:2):: ARRAY_TWO
ARRAY_TWO as a matrix of two dimensions having fifteen elements. The first dimension has three elements and the second has five with bounds from -2 to 2.
Syntax
ASSIGN a TO b
Description
Executing an ASSIGN statement assigns a statement label to an integer variable. This is the only way that a variable may be defined with a statement label value. The statement label must be:
Example
ASSIGN 40 TO K
GO TO K
40 L = P + I + 56
When a BACKSPACE statement is executed the file connected to the specified unit is positioned before the preceding record.
Syntax
BACKSPACE unit BACKSPACE ([UNIT=]unit [,ERR=errs] [, IOSTAT=ios])
Description
If there is no preceding record the position of the file is not changed. A BACKSPACE statement cannot be executed on a file that does not exist. Do not issue a BACKSPACE statement for a file that is open for direct or append access.
Examples
BACKSPACE 4 BACKSPACE ( UNIT=3 ) BACKSPACE ( 7, IOSTAT=IOCHEK, ERR=50 )
The BLOCK DATA statement introduces a number of statements that initialize data values in COMMON blocks. No executable statements are allowed in a BLOCK DATA segment.
Syntax
BLOCK DATA [name] [specification] END [BLOCK DATA [name]]
Example
BLOCK DATA
COMMON /SIDE/ BASE, ANGLE, HEIGHT, WIDTH
INTEGER SIZE
PARAMETER (SIZE=100)
INTEGER BASE(0:SIZE)
REAL WIDTH(0:SIZE), ANGLE(0:SIZE)
DATA (BASE(I),I=0,SIZE)/SIZE*-1,-1/,
+ (WIDTH(I),I=0,SIZE)/SIZE*0.0,0.0/
END
The BYTE statement establishes the data type of a variable by explicitly attaching the name of a variable to a 1-byte integer. This overrides the implication of data typing by the initial letter of a symbolic name.
Syntax
BYTE name [/clist/], ...
Description
Byte statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. BYTE declaration statements must not be labeled.
Example
BYTE TB3, SEC, STORE (5,5)
Syntax
CALL subroutine [([ actual-arg-list]...])]
Description
Actual arguments can be expressions including: constants, scalar variables, function references and arrays.
Actual arguments can also be alternate return specifiers. Alternate return specifiers are labels prefixed by asterisks (*) or ampersands (&).
Examples
CALL CRASH ! no arguments
CALL BANG(1.0) ! one argument
CALL WALLOP(V, INT) ! two arguments
CALL ALTRET(I, *10, *20)
SUBROUTINE ONE
DIMENSION ARR ( 10, 10 )
REAL WORK
INTEGER ROW, COL
PI=3.142857
CALL EXPENS(ARR,ROW,COL,WORK,SIN(PI/2)+3.4)
RETURN
END
The CASE statement begins a case-statement-block portion of a SELECT CASE construct.
Syntax
[case-name:]SELECT CASE (case-expr) [ CASE selector [name] block] ... [ CASE DEFAULT [case-name] block END SELECT [case-name]
Example
SELECT CASE (FLAG)
CASE ( 1, 2, 3 )
TYPE=1
CASE ( 4:6 )
TYPE=2
CASE DEFAULT
TYPE=0
END SELECT
Type
Executable
See Also
SELECT CASE
The CHARACTER statement establishes the data type of a variable by explicitly attaching the name of a variable to a character data type. This overrides the implication of data typing by the initial letter of a symbolic name.
Syntax
The syntax for CHARACTER has two forms, the standard Fortran form and the PGI extended form. This section describes both syntax forms.
CHARACTER [character-selector] [, attribute-list ::] entity-list
([LEN=] type-param-value) * character-length [,]Character-selector also permits a KIND specification. Refer to the Fortran 90 handbook for more syntax details.
PGI Syntax Extension @
CHARACTER [*len][,] name [dimension] [*len] [/clist/], ...
Description
Character type declaration statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. Type declaration statements must not be labeled. Note: The data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
Examples
CHARACTER A*4, B*6, C CHARACTER (LEN=10):: NAMEA is 4 and B is 6 characters long and C is 1 character long. NAME is 10 characters long.
Syntax
CLOSE ([UNIT=] u [,ERR= errs ] [,DISP[OSE]= sta]
[,IOSTAT=ios] [,STATUS= sta] )
Description
A unit may be the subject of a CLOSE statement from within any program unit. If the unit specified does not exist or has no file connected to it the use of the CLOSE statement has no effect. Provided the file is still in existence it may be reconnected to the same or a different unit after the execution of a CLOSE statement. Note that an implicit CLOSE is executed when a program stops.
Example
In the following example the file on UNIT 6 is closed and deleted.
CLOSE(UNIT=6,STATUS='DELETE')
The COMMON statement defines global blocks of storage that are either sequential or non sequential. Each common block is identified by the symbolic name defined in the COMMON block.
Syntax
COMMON /[name ] /nlist [, /name/nlist]...
Description
The name of the COMMON block need not be supplied; without a name, the common is a BLANK COMMON. In this case the compiler uses a default name. There can be several COMMON block statements of the same name in a program segment; these are effectively treated as one statement, with variables concatenated from one COMMON statement of the same name to the next. This is an alternative to the use of continuation lines when declaring a common block with many symbols.
Common blocks with the same name that are declared in different program share the same storage area when combined into one executable program and they are defined using the SEQUENCE attribute. In HPF, a common block is non-sequential by default, unless there is an explicit SEQUENCE directive that specifies the array as sequential. Note this may require that older Fortran 77 programs assuming sequence association in COMMON statements have SEQUENCE statements for COMMON variables.
Example
DIMENSION R(10)This declares a common block called HOST Note the different types of declaration used for R (declared in a DIMENSION statement) and Q (declared in the COMMON statement).
COMMON /HOST/ A, R, Q(3), U
The declaration of HOST in a SUBROUTINE in the same executable program, with a different shape for its elements would require that the array be declared using the SEQUENCE attribute..
SUBROUTINE DEMOIf the main program has the common block declaration as in the previous example, the COMMON statement in the subroutine causes STORE(1) to correspond to A, STORE(2) to correspond to R(1), STORE(3) to correspond to R(2), and so on through to STORE(15) corresponding to the variable U.
!HPF$ SEQUENCE HOST
COMMON/HOST/STORE(15)
.
.
.
RETURN
END
Both character and non-character data may reside in one COMMON block. Data is aligned within the COMMON block in order to conform to machine-dependent alignment requirements.
Blank COMMON is always saved.
Blank COMMON may be data initialized.
See Also
The SEQUENCE directive.
The COMPLEX statement establishes the data type of a variable by explicitly attaching the name of a variable to a complex data type. This overrides the implication of data typing by the initial letter of a symbolic name.
Syntax
The syntax for COMPLEX has two forms, the standard Fortran form and the PGI extended form. This section describes both syntax forms.
COMPLEX [ ( [ KIND =] kind-value ) ] [, attribute-list ::] entity-listCOMPLEX permits a KIND specification. Refer to the Fortran 90 handbook for more syntax details.
PGI Syntax Extension @
COMPLEX name [*n] [dimensions] [/clist/] [, name] [/clist/] ...
Description
COMPLEX statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. COMPLEX statements must not be labeled. Note: The data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
Example
COMPLEX CURRENT
COMPLEX DIMENSION(8):: CONV1, FLUX1
The CONTAINS statement precedes a subprogram, a function or subroutine, that is defined inside a main program, external subprogram, or module subprogram (internal subprogram). The CONTAINS statement is a flag indicating the presence of a subroutine or function definition. An internal subprogram defines a scope for the internal subprogram's labels and names. Scoping is defined by use and host scoping rules within scoping units. Scoping units have the following precedence for names:
Syntax
SUBROUTINE X
INTEGER H, I
.
.
.
CONTAINS
SUBROUTINE Y
INTEGER I
I = I + H .
.
END SUBROUTINE Y
END SUBROUTINE X
Type
Non-executable
See Also
MODULE
The CONTINUE statement passes control to the next statement. It is supplied mainly to overcome the problem that transfer of control statements are not allowed to terminate a DO loop.
Syntax
CONTINUE
Example
DO 100 I = 1,10
SUM = SUM + ARRAY (I)
IF(SUM .GE. 1000.0) GOTO 200
100 CONTINUE
200 ...
The CYCLE statement interrupts a DO construct execution and continues with the next iteration of the loop.
Syntax
CYCLE [do-construct-name]
Example
DO
IF (A(I).EQ.0) CYCLE
B=100/A(I)
IF (B.EQ.5) EXIT
END DO
See Also
EXIT, DO
The DATA statement assigns initial values to variables before execution.
Syntax
DATA vlist/dlist/[[, ]vlist/dlist/]...
n*constant-value
Example
REAL A, B, C(3), D(2)This performs the following initialization:
DATA A, B, C(1), D /1.0, 2.0, 3.0, 2*4.0/
A = 1.0
B = 2.0
C(1) = 3.0
D(1) = 4.0
D(2) = 4.0
The DEALLOCATE statement causes the memory allocated for each pointer-based variable or allocatable array that appears in the statement to be deallocated (freed). Deallocate also deallocates storage for deferred-shape arrays.
Syntax
DEALLOCATE ( allocate-object-list [ , STAT= var ] )Where:
Description
If the specifier STAT= is present, successful execution of the statement causes var to be defined with the value of zero. If an error occurs during the execution of the statement and the specifier STAT= is present, the status variable is defined to have the integer value one. If an error occurs and the specifier STAT= is not present, program execution is terminated.
Examples
REAL, ALLOCATABLE :: X(:,:)
ALLOCATE (X(10,2)) X=0
DEALLOCATE (X)
The DECODE statement transfers data between variables or arrays in internal storage and translates that data from character form to internal form, according to format specifiers. Similar results can be accomplished using internal files with formatted sequential READ statements.
Syntax
DECODE (c, f, b [ ,IOSTAT= ios ] [, ERR= errs]) [ list ]
The DIMENSION statement defines the number of dimensions in an array and the number of elements in each dimension.
Syntax
DIMENSION [::] array-name (array-spec)
[, array-name (array-spec) ] ...
Description
DIMENSION can be used in a subroutine to establish an argument as an array, and in this case the declarator can use expressions formed from integer variables and constants to establish the dimensions (adjustable arrays). Note however that these integer variables must be either arguments or declared in COMMON; they cannot be local. Note that in this case the function of DIMENSION is merely to supply a mapping of the argument to the subroutine code, and not to allocate storage.
The typing of the array in a DIMENSION statement is defined by the initial letter of the array name in the same way as variable names. The letters I,J,K,L,M and N imply that the array is of INTEGER type and an array with a name starting with any of the letters A to H and O to Z will be of type REAL, unless overridden by an IMPLICIT or type declaration statement. Arrays may appear in type declaration and COMMON statements but the array name can appear in only one array declaration.
DIMENSION statements must not be labeled.
Examples
DIMENSION ARRAY1(3:10), ARRAY2(3,-2:2)This specifies ARRAY1 as a vector having eight elements with the lower bound of 3 and the upper bound of 10.
ARRAY2 as a matrix of two dimensions having fifteen elements. The first dimension has three elements and the second has five with bounds from -2 to 2.
CHARACTER B(0:20)*4This example sets up an array B with 21 character elements each having a length of four characters. Note that the character array has been dimensioned in a type declaration statement and therefore cannot subsequently appear in a DIMENSION statement.
The DOUBLE COMPLEX statement establishes the data type of a variable by explicitly attaching the name of a variable to a double complex data type. This overrides the implication of data typing by the initial letter of a symbolic name.
Syntax
The syntax for DOUBLE COMPLEX has two forms, a standard Fortran 90 entity based form, and the PGI extended form. This section describes both syntax forms.
DOUBLE COMPLEX [, attribute-list ::] entity-list
PGI Syntax Extension
DOUBLE COMPLEX name [/clist/] [, name] [/clist/]...
Description
Type declaration statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. Type declaration statements must not be labeled. Note: the data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
Examples
DOUBLE COMPLEX CURRENT, NEXT
The DOUBLE PRECISION statement establishes the data type of a variable by explicitly attaching the name of a variable to a double precision data type. This overrides the implication of data typing by the initial letter of a symbolic name.
Syntax
The syntax for DOUBLE PRECISION has two forms, a standard Fortran 90 entity based form, and the PGI extended form. This section describes both syntax forms.
DOUBLE PRECISION [, attribute-list ::] entity-list
PGI Syntax Extension
DOUBLE PRECISION name [/clist/] [, name] [/clist/]...
Description
Type declaration statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. Type declaration statements must not be labeled. Note: The data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
Example
DOUBLE PRECISION PLONG
The DO statement introduces an iterative loop and specifies the loop control index and parameters. There are two forms of DO statement, block and non-block (Fortran 77 style). There are two forms of block do statements, DO iterative and DO WHILE . Refer to the description of DO WHILE for more details on this form of DO statement.
Syntax DO BLOCK
[do-construct-name : ] DO [label ] [loop-control]
[execution-part-construct]
[label] END DO
Syntax DO NON-BLOCK
DO label [,] index = e1, e2 [, e3]
Description
The DO loop consists of all the executable statements after the specifying DO statement up to and including the labeled statement, called the terminal statement. The label is optional. If omitted, the terminal statement of the loop is an END DO statement.
Before execution of a DO loop, an iteration count is initialized for the loop. This value is the number of times the DO loop is executed, and is:
INT((e2-e1+e3)/e3)If the value obtained is negative or zero that the loop is not executed.
The DO loop is executed first with i taking the value e1, then the value (e1+e3), then the value (e1+e3+e3), etc.
It is possible to jump out of a DO loop and jump back in, as long as the do index variable has not been adjusted.
@ Nested DO loops may share the same labeled terminal statement if required. They may not share an END DO statement.
In a nested DO loop, it is legal to transfer control from an inner loop to an outer loop. It is illegal, however, to transfer into a nested loop from outside the loop.
Examples
DO 100 J = -10,10
DO 100 I = -5,5
100 SUM = SUM + ARRAY (I,J) DO
A(I)=A(I)+1
IF (A(I).EQ.4) EXIT
END DO DO I=1,N
A(I)=A(I)+1
END DO
The DO WHILE statement introduces a logical do loop and specifies the loop control expression.
The DO WHILE statement executes for as long as the logical expression continues to be true when tested at the beginning of each iteration. If expression is false, control transfers to the statement following the loop.
Syntax
DO [label[,]] WHILE expressionThe end of the loop is specified in the same way as for an iterative loop, either with a labeled statement or an END DO.
Description
The logical-expression is evaluated. If it is .FALSE., the loop is not entered. If it is .TRUE., the loop is executed once. Then logical-expression is evaluated again, and the cycle is repeated until the expression evaluates .FALSE..
Example
DO WHILE (K == 0) SUM = SUM + X END DO
The ENCODE statement transfers data between variables or arrays in internal storage and translates that data from internal to character form, according to format specifiers. Similar results can be accomplished using internal files with formatted sequential WRITE statements.
Syntax
ENCODE (c,f,b[,IOSTAT=ios] [,ERR=errs])[list]
The END statement terminates a segment of a Fortran program. There are several varieties of the END statement. Each is described below.
END Syntax
END
Description
The END statement has the same effect as a RETURN statement in a SUBROUTINE or FUNCTION, or the effect of a STOP statement in a PROGRAM program unit. END may be the last statement in a compilation or it may be followed by a new program unit.
END FILE u END FILE ([UNIT=]u, [,IOSTAT =ios] [,ERR=errs] )
Description
When an END FILE statement is executed an endfile record is written to the file as the next record. The file is then positioned after the endfile record. Note that only records written prior to the endfile record can be read later.
A BACKSPACE or REWIND statement must be used to reposition the file after an END FILE statement prior to the execution of any data transfer statement. A file is created if there is an END FILE statement for a file connected but not in existence.
For example:
END FILE(20) END FILE(UNIT=34, IOSTAT=IOERR, ERR=140)
The ENTRY statement allows a subroutine or function to have more than one entry point.
Syntax
ENTRY name [(variable, variable...)]
Description
The name of an ENTRY must not be used as a dummy argument in a FUNCTION, SUBROUTINE or ENTRY statement, nor may it appear in an EXTERNAL statement.
Within a function a variable name which is the same as the entry name may not appear in any statement that precedes the ENTRY statement, except in a type statement.
If name is of type character the names of each entry in the function and the function name must be of type character. If the function name or any entry name has a length of (*) all such names must have a length of (*); otherwise they must all have a length specification of the same integer value.
A name which is used as a dummy argument must not appear in an executable statement preceding the ENTRY statement unless it also appears in a FUNCTION, SUBROUTINE or ENTRY statement that precedes the executable statement. Neither must it appear in the expression of a statement function unless the name is also a dummy argument of the statement function, or appears in a FUNCTION or SUBROUTINE statement, or in an ENTRY statement that precedes the statement function statement.
If a dummy argument appears in an executable statement, execution of that statement is only permitted during the execution of a reference to the function or subroutine if the dummy argument appears in the dummy argument list of the procedure name referenced.
When a subroutine or function is called using the entry name, execution begins with the statement immediately following the ENTRY statement. If a function entry has no dummy arguments the function must be referenced by name() but a subroutine entry without dummy arguments may be called with or without the parentheses after the entry name.
An entry may be referenced from any program unit except the one in which it is defined.
The order, type, number and names of dummy arguments in an ENTRY statement can be different from those used in the FUNCTION, SUBROUTINE or other ENTRY statements in the same program unit but each reference must use an actual argument list which agrees in order, number and type with the dummy argument list of the corresponding FUNCTION, SUBROUTINE or ENTRY statement. When a subroutine name or an alternate return specifier is used as an actual argument there is no need to match the type.
Entry names within a FUNCTION subprogram need not be of the same data type as the function name, but they all must be consistent within one of the following groups of data types:
Example
FUNCTION SUM(TALL,SHORT,TINY)When the calling program calls the function SUM it can do so in one of three ways depending on which ENTRY point is desired.
.
SUM=TALL-(SHORT+TINY)
RETURN
ENTRY SUM1(X,LONG,TALL,WIDE,NARROW)
.
.
SUM1=(X*LONG)+(TALL*WIDE)+NARROW
RETURN
ENTRY SUM2(SHORT,SMALL,TALL,WIDE)
.
.
SUM2=(TALL-SMALL)+(WIDE-SHORT)
RETURN END
For example if the call is:
Z=SUM2(LITTLE,SMALL,BIG,HUGE)the ENTRY point is SUM2.
If the call is:
Z=SUM(T,X,Y)the ENTRY point is SUM and so on.
Syntax
EQUIVALENCE (list)[,(list)...]
Description
@ An array element may be identified with a single subscript in an EQUIVALENCE statement even though the array is defined to be a multidimensional array.
@ Equivalence of character and non-character data is allowed as long as misalignment of non-character data does not occur.
Records and record fields cannot be specified in EQUIVALENCE statements.
The statement can be used to make a single region of data memory have different types, so that for instance the imaginary part of a complex number can be treated as a real value. make arrays overlap, so that the same region of store can be dimensioned in several different ways.
Example
COMPLEX NUMIn the above example QWER(1) is the real part of NUM and QWER(2) is the imaginary part. EQUIVALENCE statements are illegal if there is any attempt to make a mapping of data memory inconsistent with its linear layout.
REAL QWER(2)
EQUIVALENCE (NUM,QWER(1))
The EXIT statement interrupts a DO construct execution and continues with the next statement after the loop.
Syntax
EXIT [do-construct-name]
Example
DO
IF (A(I).EQ.0) CYCLE
B=100/A(I)
IF (B.EQ.5) EXIT
END DO
See Also
CYCLE, DO
The EXTERNAL statement identifies a symbolic name as an external or dummy procedure. This procedure can then be used as an actual argument.
Syntax
EXTERNAL proc [,proc]..
Description
If an intrinsic function appears in an EXTERNAL statement an intrinsic function of the same name cannot then be referenced in the program unit. A symbolic name can appear only once in all the EXTERNAL statements of a program unit.
The EXTRINSIC statement identifies a symbolic name as an external or dummy procedure that is written in some language other than HPF.
Syntax
EXTRINSIC ( extrinsic-kind-keyword ) procedure name
Description
The EXTRINSIC procedure can then be used as an actual argument once it is defined. The call to an EXTRINSIC procedure should be semantically equivalent to the execution of an HPF procedure in that on return from the procedure, all processors are still available, and all data and templates will have the same distribution and alignment as when the procedure was called.
See Also
For a complete description of the pghpf extrinsic facility, along with examples, refer to Chapter 8 "Using Modules and Extrinsics", in the pghpf User's Guide.
The FORALL statement and the FORALL construct provide a parallel mechanism to assign values to the elements of an array. The FORALL statement is interpreted essentially as a series of single statement FORALL's.
Syntax
FORALL (forall-triplet-spec-list [, scalar-mask-expr] ) forall-assignment or FORALL (forall-triplet-spec-list [, scalar-mask-expr] ) forall-body [forall-body ]... END FORALLwhere forall-body is one of:
forall-assignment where-statement where-construct forall-statement forall-construct
Description
The FORALL statement is computed in four stages:
First, compute the valid set of index values. Second compute the active set of index values, taking into consideration the scalar-mask-expr. If no scalar-mask-expr is present, the valid set is the same as the active set of index values. Third, for each index value, the right-hand-side of the body of the FORALL is computed. Finally, the right-hand-side is assigned to the left-hand-side, for each index value.
Examples
FORALL (I = 1:3) A(I) = B(I) FORALL(I = 1:L, A(I) == 0.0) A(I) = R(I) FORALL (I = 1:3) A(I) = D(I) B(I) = C(I) * 2 END FORALL FORALL (I = 1:5) WHERE (A(I,:) /= 0.0) A(I,:) = A(I-1,:) + A(I+1,:) ELSEWHERE B(I,:) = A(6-I,:) END WHERE END FORALL
The FORMAT statement specifies format requirements for input or output.
Syntax
label FORMAT (list-items)
Description
Refer to Chapter 6, Input and Output Formatting, for more details on using the FORMAT statement.
Examples
WRITE (6,90) NPAGEproduces:
90 FORMAT('1PAGE NUMBER ',I2,16X,'SALES REPORT, Cont.')
PAGE NUMBER 10 SALES REPORT, Cont.The following example shows use of the tabulation specifier T:
PRINT 25produces:
25 FORMAT (T41,'COLUMN 2',T21,'COLUMN 1')
COLUMN 1 COLUMN 2
DIMENSION A(6)produces:
DO 10 I = 1,6
10 A(I) = 25.
TYPE 100,A
100 FORMAT(' ',F8.2,2PF8.2,F8.2) ! ' '
C ! gives single spacing
25.00 2500.00 2500.00Note that the effect of the scale factor continues until another scale factor is used.
2500.00 2500.00 2500.00
The FUNCTION statement introduces a program unit; the statements that follow all apply to the function itself and are laid out in the same order as those in a PROGRAM program unit.
Syntax
[function-prefix] FUNCTION name [*n] ([argument [,argument]...]) . . .
END [ FUNCTION [function-name]]
Description
The statements and names apply only to the function, except for subroutine or function references and the names of COMMON blocks. The function must be terminated by an END statement.
A function produces a result; this allows a function reference to appear in an expression, where the result is assumed to replace the actual reference. The symbolic name of the function must appear as a variable in the function, unless the RESULT keyword is used. The value of this variable, on exit from the function, is the result of the function. The function result is undefined if the variable has not been defined.
The type of a FUNCTION refers to the type of its result.
Recursion is allowed if the -Mrecursive option is used on the command-line and the RECURSIVE prefix is included in the function definition.
Examples
FUNCTION FRED(A,B,C)
REAL X
.
END
FUNCTION EMPTY() ! Note parentheses
END PROGRAM FUNCALL
.
SIDE=TOTAL(A,B,C)
.
END
FUNCTION TOTAL(X,Y,Z)
.
END FUNCTION AORB(A,B)
IF(A-B)1,2,3
1 AORB = A
RETURN
2 AORB = B
RETURN
3 AORB = A + B
RETURN
END
See Also
PURE, RECURSIVE, RESULT
The assigned GOTO statement transfers control so that the statement identified by the statement label is executed next. Internal procedures can be used in place of the ASSIGN statement used with an assigned GO TO.
Syntax
GOTO integer-variable-name[[,] (list)]
Examples
ASSIGN 50 TO K
GO TO K(50,90)
90 G=D**5
.
.
50 F=R/T
The computed GOTO statement allows transfer of control to one of a list of labels according to the value of an expression.
Syntax
GOTO (list) [,] expression
Example
READ *, A, B
GO TO (50,60,70)A
WRITE (*, 10) A, B
10 FORMAT (' ', I3, F10.4, 5X, 'A must be 1, 2
+ or 3')
STOP
50 X=A**B ! Come here if A has the value 1
GO TO 100
60 X=(A*56)*(B/3) !Come here if A is 2
GO TO 100
70 X=A*B ! Come here if A has the value 3
100 WRITE (*, 20) A, B, X
20 FORMAT (' ', I3, F10.4, 5X, F10.4)
The GOTO statement unconditionally transfers control to the statement with the label label. The statement label label must be declared within the code of the program unit containing the GOTO statement and must be unique within that program unit.
Syntax
GOTO label
Example
TOTAL=0.0
30 READ *, X
IF (X.GE.0) THEN
TOTAL=TOTAL+X
GOTO 30
END IF
The arithmetic IF statement transfers control to one of three labeled statements. The statement chosen depends upon the value of an arithmetic expression.
Syntax
IF (arithmetic-expression) label-1, label-2, label-3Control transfers to label-1, label-2 or label-3 if the result of the evaluation of the arithmetic-expression is less than zero, equal to zero or greater than zero respectively.
Example
IF X 10, 20, 30if X is less than zero then control is transferred to label 10.
if X equals zero then control is transferred to label 20.
if X is greater than zero then control is transferred to label 30.
The block IF statement consists of a series of statements that are conditionally executed.
Syntax
IF logical expression THENThe ELSE IF section is optional and may be repeated any number of times. Other IF blocks may be nested within the statements section of an ELSE IF block.
statements
ELSE IF logical expression THEN
statements
ELSE
statements
ENDIF
The ELSE section is optional and may occur only once. Other IF blocks may be nested within the statements section of an ELSE block.
Example
IF (I.GT.70) THEN
M=1
ELSE IF (I.LT.5) THEN
M=2
ELSE IF (I.LT.16) THEN
M=3
ENDIF
IF (I.LT.15) THEN
M = 4
ELSE
M=5
ENDIF
The IMPLICIT statement redefines the implied data type of symbolic names from their initial letter. Without the use of the IMPLICIT statement all names that begin with the letters I,J,K,L,M or N are assumed to be of type integer and all names beginning with any other letters are assumed to be real.
Syntax
IMPLICIT spec (a[,a]...) [,spec (a[,a]...)] IMPLICIT NONE
Description
IMPLICIT statements must not be labeled.
Symbol names may begin with a dollar sign ($) or underscore (_) character, both of which are of type REAL by default. In an IMPLICIT statement, these characters may be used in the same manner as other characters, but they cannot be used in a range specification.
The IMPLICIT NONE statement specifies that all symbolic names must be explicitly declared, otherwise an error is reported. If IMPLICT NONE is used, no other IMPLICIT can be present.
Examples
IMPLICIT REAL (L,N) IMPLICIT INTEGER (S,W-Z) IMPLICIT INTEGER (A-D,$,_)
The INCLUDE statement directs the compiler to start reading from another file.
Syntax
INCLUDE 'filename [/[NO]LIST]' INCLUDE "filename [/[NO]LIST]"The INCLUDE statement may be nested to a depth of 20 and can appear anywhere within a program unit as long as Fortran's statement-ordering restrictions are not violated.
@ The qualifiers /LIST and /NOLIST can be used to control whether the include file is expanded in the listing file (if generated). INCLUDEEither single or double quotes may be used.
If the final component of the file pathname is /LIST or /NOLIST, the compiler will assume it is a qualifier, unless an additional qualifier is supplied.
The filename and the /LIST or /NOLIST qualifier may be separated by blanks.
The include file is searched for in the following directories:
1. Each -I directory specified on the command-line.
2. The directory containing the file that contains the INCLUDE
statement
(the current working directory.)
3. The standard include area.
Example
INCLUDE '/mypath/list /list' This line includes a file named /mypath/list and expands it in the listing file, if a listing file is used.
Syntax
INQUIRE (FILE=filename, list) INQUIRE ([UNIT=]unit,list)In addition list may contain one of each of the following specifiers in any order, following the unit number if the optional UNIT specifier keyword is not supplied.
Description
When an INQUIRE by file statement is executed the following specifiers will only be assigned values if the file name is acceptable: nmd, fn, seq, dir, fmt and unf. num is defined, and acc, fm, rcl, nr and blnk may become defined only if od is defined as .TRUE..
When an INQUIRE by unit statement is executed the specifiers num, nmd, fn, acc, seq, dir, fm, fmt, unf, rcl, nr and blnk are assigned values provided that the unit exists and a file is connected to that unit. Should an error condition occur during the execution of an INQUIRE statement all the specifiers except ios become undefined.
Syntax
The syntax for INTEGER has two forms, a standard Fortran 90 attributed form, and the PGI extended form. This section describes both syntax forms.
INTEGER [([ KIND = kind-value ) ][, attribute-list ::] entity-listINTEGER permits a KIND specification. Refer to the Fortran 90 handbook for more syntax details.
PGI Syntax Extension
INTEGER [*n] [,] name [*n] [dimensions] [/clist/]...
Description
Integer type declaration statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. INTEGER statements must not be labeled. Note: The data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
Example
INTEGER TIME, SECOND, STORE (5,5)
Syntax
INTENT (intent-spec) [ :: ] dummy-arg-list
IN OUT INOUT
Description
With intent specified as IN, the subprogram argument must not be redefined by the subprogram.
With intent specified as OUT, the subprogram should use the argument to pass information to the calling program.
With intent specified as INOUT, the subprogram may use the value passed through the argument, but should also redefine the argument to pass information to the calling program.
See Also
OPTIONAL
Example
SUBROUTINE IN_OUT(R1,I1)
REAL, INTENT (IN)::R1
INTEGER, INTENT(OUT)::I1
I1=R1
END SUBROUTINE IN_OUT
The INTERFACE statement block makes an implicit procedure an explicit procedure where the dummy parameters and procedure type are known to the calling module. This statement is also used to overload a procedure name.
Syntax
INTERFACE [generic-spec] [interface-body]... [MODULE PROCEDURE procedure-name-list]... END INTERFACEwhere a generic-spec is either:
generic-name OPERATOR (defined operator) ASSIGNMENT (=)and the interface body specified the interface for a function or a subroutine:
function-statement [specification-part] END FUNCTION [function name] subroutine-statement [specification-part] END FUNCTION [subroutine name]
See Also
END INTERFACE
Example
INTERFACE
SUBROUTINE IN_OUT(R1,I1)
REAL, INTENT (IN)::R1
INTEGER, INTENT(OUT)::I1
END SUBROUTINE IN_OUT
END INTEFACE
An INTRINSIC statement identifies a symbolic name as an intrinsic function and allows it to be used as an actual argument.
Syntax
INTRINSIC func [,func]
Description
Do not use any of the following functions in INTRINSIC statements:
* type conversions:
INT, IFIX, IDINT, FLOAT, SNGL, REAL, DBLE, CMPLX, ICHAR, CHAR
* lexical relationships:
LGE, LGT, LLE, LLT
MAX, MAX0, AMAX1, DMAX1, AMAX0, MAX1, MIN, MIN0, AMIN1, DMIN1, AMIN0, MIN1When a specific name of an intrinsic function is used as an actual argument in a program unit it must appear in an INTRINSIC statement in that program unit. If the name used in an INTRINSIC statement is also the name of a generic intrinsic function, it retains its generic properties. A symbolic name can appear only once in all the INTRINSIC statements of a program unit and cannot be used in both an EXTERNAL and INTRINSIC statement in a program unit.
The following example illustrates the use of INTRINSIC and EXTERNAL:
EXTERNAL MYOWN
INTRINSIC SIN, COS
.
.
CALL TRIG (ANGLE,SIN,SINE)
.
CALL TRIG (ANGLE,MYOWN,COTANGENT)
.
CALL TRIG (ANGLE,COS,SINE) SUBROUTINE TRIG (X,F,Y)
Y=F(X)
RETURN
END
FUNCTION MYOWNIn this example, when TRIG is called with a second argument of SIN or COS the function reference F(X) references the intrinsic functions SIN and COS; however when TRIG is called with MYOWN as the second argument F(X) references the user function MYOWN.
MYOWN=COS(X)/SIN(X)
RETURN
END
Syntax
The syntax for LOGICAL has two forms, a standard Fortran 90 attributed form, and the PGI extended form. This section describes both syntax forms.
LOGICAL [ ( [ KIND = kind-value ) ] [, attribute-list ::] entity-listLOGICAL permits a KIND specification. Refer to the Fortran 90 handbook for more syntax details.
PGI Syntax Extension
LOGICAL [*n] [,] name [*n] [dimensions] [/clist/]
[, name] [*n][dimensions] [/clist/]...
Description
Logical type declaration statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. Type declaration statements must not be labeled. Note: The data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
Example
LOGICAL TIME, SECOND, STORE (5,5)
The MODULE statement specifies the entry point for a module program unit. A module defines a host environment of scope of the module, and may contain subprograms that are in the same scoping unit.
Syntax
MODULE [name] [specification-part] [ CONTAINS [module-subprogram-part]] END [MODULE [ module-name ]]
Example
MODULE MYOWN
REAL MEAN, TOTAL
INTEGER, ALLOCATABLE, DIMENSION(:):: A
CONTAINS
RECURSIVE INTEGER FUNCTION X(Y)
.
.
.
END FUNCTION X
END MODULE MYOWN
The NAMELIST statement allows for the definition of namelist groups for namelist-directed I/O.
Syntax
NAMELIST /group-name/ namelist [[,] /group-name/ namelist ]...
Example
In the following example a named group PERS consists of a name, an account, and a value.
CHARACTER*12 NAME
INTEGER*$ ACCOUNT
REAL*4 VALUE
NAMELIST /PERS/ NAME, ACCOUNT, VALUE
The NULLIFY statement disassociates a pointer from its target.
Syntax
NULLIFY (pointer-object-list)
Example
NULLIFY (PTR1)
See Also
ALLOCATE, DEALLOCATE
The OPEN statement connects an existing file to a unit; creates and connects a file to a unit; creates a file that is preconnected or changes certain specifiers of a connection between a file and a unit.
Syntax
OPEN ( list )
[UNIT=] uwhere the UNIT= is optional and the external unit specifier u is an integer.
In addition list may contain one of each of the following specifiers in any order, following the unit number if the optional UNIT specifier keyword is not supplied.
Description
The record length, RECL=, must be specified if a file is connected for direct access and optionally one of each of the other specifiers may be used.
The unit specified must exist and once connected by an OPEN statement can be referenced in any program unit of the executable program. If a file is connected to a unit it cannot be connected to a different unit by the OPEN statement.
If a unit is connected to an existing file, execution of an OPEN statement for that file is allowed. Where FILE= is not specified the file to be connected is the same as the file currently connected. If the file specified for connection to the unit does not exist but is the same as a preconnected file, the properties specified by the OPEN statement become part of the connection. However, if the file specified is not the same as the preconnected file this has the same effect as the execution of a CLOSE statement without a STATUS= specifier immediately before the execution of the OPEN statement. When the file to be connected is the same as the file already connected only the BLANK= specifier may be different from the one currently defined.
Example
In the following example a new file, BOOK, is created and connected to unit 12 for direct formatted input/output with a record length of 98 characters. Numeric values will have blanks ignored and E1 will be assigned some positive value if an error condition exists when the OPEN statement is executed; execution will then continue with the statement labeled 20. If no error condition pertains, E1 is assigned the value zero (0) and execution continues with the next statement.
OPEN( 12, IOSTAT=E1, ERR=20, FILE='BOOK',
+ BLANK='NULL', ACCESS='DIRECT', RECL=98,
+ FORM='FORMATTED',STATUS='NEW')
Environment Variables
For an OPEN statement which does not contain the FILE= specifier, an environment variable may be used to specify the file to be connected to the unit. If the environment variable FORddd exists, where ddd is a 3 digit string whose value is the unit, the environment variable's value is the name of the file to be opened.
VAX/VMS Fortran @
VAX/VMS introduces a number of extensions to the OPEN statement. Many of these relate only to the VMS file system and are not supported (e.g., KEYED access for indexed files). The following keywords for the OPEN statement have been added or augmented as shown below. Refer to Programming in VAX FORTRAN for additional details on these keywords.
The OPTIONAL specification statement (attribute) specifies dummy arguments that may be omitted or that are optional.
Syntax
OPTIONAL [::] dummy-arg-list
Examples
OPTIONAL :: VAR4, VAR5 OPTIONAL VAR6, VAR7 INTEGER, OPTIONAL:: VAR8, VAR9
See Also
INTENT
The OPTIONS statement confirms or overrides certain compiler command-line options.
Syntax
OPTIONS /option [/option ...]Table 3.1 shows what options are available for the OPTIONS statement.
Table 3.1 OPTIONS Statement
Option
Action Taken
CHECK=ALL
Enable
array bounds checking
CHECK=[NO]OVERFLOW
None
(recognized but ignored)
CHECK=[NO]BOUNDS
(Disable)
Enable array bounds checking
CHECK=[NO]UNDERFLOW
None
CHECK=NONE
Disable
array bounds checking
NOCHECK
Disable
array bounds checking
[NO]EXTEND_SOURCE
(Disable)
Enable the -Mextend option
[NO]G_FLOATING
None
[NO]REENTRANT
(Enable)
Disable optimizations that may result in code that is not reentrant.
The following restrictions apply to the OPTIONS statement:
The PARAMETER statement gives a symbolic name to a constant.
Syntax
PARAMETER (name = expression[,name = expression...] )
Examples
PARAMETER ( PI = 3.142 ) PARAMETER ( INDEX = 1024 ) PARAMETER ( INDEX3 = INDEX * 3 )
The PAUSE statement stops the program's execution. The PAUSE statement is obsolescent because a WRITE statement may send a message to any device, and a READ statement may be used to wait for a message from the same device.
Syntax
PAUSE [character-expression | digits ]The PAUSE statement stops the program's execution. The program may be restarted later and execution will then continue with the statement following the PAUSE statement.
The POINTER specification statement (attribute) declares a scalar variable to
be a pointer variable (of type INTEGER), and another variable to be its
target pointer-based variable. The target may be a scalar or an array of
any type.
Syntax
POINTER [::] object-name [ (deferred-shape-spec-list) ] [, object-name [ ( deferred-shape-spec-list ) ]]
Example
REAL, DIMENSION(:,:), POINTER:: X
The PRINT statement is a data transfer output statement.
Syntax
PRINT format-identifier [, iolist] or PRINT namelist-group
Description
When a PRINT statement is executed the following operations are carried out : data is transferred to the standard output device from the items specified in the output list and format specification.[*] The data are transferred between the specified destinations in the order specified by the input/output list. Every item whose value is to be transferred must be defined.
The PRIVATE statement specifies entities defined in a module are not accessible outside of the module. This statement is only valid in a module. The default specification for a module is PUBLIC.
Syntax
PRIVATE [:: [ access-id-list ]]
Description
Example
MODULE FORMULA
PRIVATE
PUBLIC :: VARA
.
.
.
END MODULE
Type
Non-executable
See Also
PUBLIC, MODULE
The PROGRAM statement specifies the entry point for the linked Fortran program.
Syntax
PROGRAM [name]
.
.
.
END [ PROGRAM [program-name]]
Description
The program statement specifies the entry point for the linked Fortran program. An END statement terminates the program.
The END PROGRAM statement terminates a main program unit that begins with the optional PROGRAM statement. The program name found in the END PROGRAM must match that in the PROGRAM statement.
Example
PROGRAM MYOWN
REAL MEAN, TOTAL
.
CALL TRIG(A,B,C,MEAN)
.
END
The PUBLIC statement specifies entities defined in a module are accessible outside of the module. This statement is only valid in a module. The default specification for a module is PUBLIC.
Syntax
PUBLIC [ :: [ access-id-list ]]
Example
MODULE FORMULA
PRIVATE
PUBLIC :: VARA
.
.
.
END MODULE
Type
Non-executable
See Also
PRIVATE, MODULE
The PURE attribute indicates whether a function or subroutine has side effects. This indicates if a subroutine or function can be used in a FORALL statement or construct or within an INDEPENDENT DO loop.
Syntax
PURE [type-specification] FUNCTIONor
type-specification PURE FUNCTIONor
PURE SUBROUTINE
Type
Non-executable
See Also
FUNCTION, SUBROUTINE
The READ statement is the data transfer input statement.
Syntax
READ ([unit=] u, format-identifier [,control-information) [iolist] READ format-identifier [,iolist] READ ([unit=] u, [NML=] namelist-group [,control-information])where the UNIT= is optional and the external unit specifier u is an integer.
In addition control-information is an optional control specification which can be any of the following: may contain one of each of the following specifiers in any order, following the unit number if the optional UNIT specifier keyword is not supplied.
Description
When a READ statement is executed the following operations are carried out : data is transferred from the standard input device to the items specified in the input and format specification.[*] The data are transferred between the specified destinations in the order specified by the input/output list. Every item whose value is to be transferred must be defined.
Example
READ(2,110) I,J,K
110 FORMAT(I2, I4, I3)
Syntax
The syntax for REAL has two forms, a standard Fortran 90 attributed form, and the PGI extended form. This section describes both syntax forms.
REAL [ ( [ KIND = kind-value ) ] [, attribute-list ::] entity-listREAL permits a KIND specification. Refer to the Fortran 90 handbook for more syntax details.
PGI Syntax Extension
REAL [*n] name [*n] [dimensions] [/clist/] [, name] [*n] [dimensions][/clist/]...
Description
The REAL type declaration statements may be used to dimension arrays explicitly in the same way as the DIMENSION statement. Type declaration statements must not be labeled. Note: The data type of a symbol may be explicitly declared only once. It is established by type declaration statement, IMPLICIT statement or by predefined typing rules. Explicit declaration of a type overrides any implicit declaration. An IMPLICIT statement overrides predefined typing rules.
The RECURSIVE statement indicates whether a function or subroutine may call itself recursively.
Syntax
RECURSIVE [type-specification] FUNCTIONor
type-specification RECURSIVE FUNCTIONor
RECURSIVE SUBROUTINE
Type
Non-executable
See Also
FUNCTION, SUBROUTINE
Syntax
RETURN
RETURN alternate Statement Obsolescent
The alternate RETURN statement is obsolescent for HPF and Fortran 90. Use the CASE statement where possible in new code. The alternate RETURN statement takes the following form:
RETURN expression
Example
SUBROUTINE FIX (A,B,*,*,C)
40 IF (T) 50, 60, 70
50 RETURN
60 RETURN 1
70 RETURN 2
END
PROGRAM FIXIT
CALL FIX(X, Y, *100, *200, S)
WRITE(*,5) X, S ! Come here if (T) < 0
STOP
100 WRITE(*, 10) X, Y ! Come here if (T) = 0
STOP
200 WRITE(*,20) Y, S ! Come here if (T) > 0
The REWIND statement positions the file at its beginning. The statement has no effect if the file is already positioned at the start or if the file is connected but does not exist.
Syntax
REWIND unit REWIND (unit,list)
Examples
REWIND 5 REWIND(2, ERR=30) REWIND(3, IOSTAT=IOERR)
Syntax
SAVE [v [, v ]...]
Description
Using a common-block name, preceded and followed by a slash, ensures that all entities within that COMMON block are saved. SAVE may be used without a list, in which case all the allowable entities within the program unit are saved (this has the same effect as using the -Msave command-line option). Dummy arguments, names of procedures and names of entities within a common block may not be specified in a SAVE statement. Use of the SAVE statement with local variables ensures the values of the local variables are retained for the next invocation of the SUBROUTINE or FUNCTION. Within a main program the SAVE statement is optional and has no effect.
When a RETURN or END is executed within a subroutine or function, all entities become undefined with the exception of:
Example
PROGRAM SAFE
.
CALL KEEP
.
SUBROUTINE KEEP
COMMON /LIST/ TOP, MIDDLE
INTEGER LOCAL1.
.
SAVE /LIST/, LOCAL1
The SELECT CASE statement begins a CASE construct.
Syntax
[case-name:]SELECT CASE (case-expr) [ CASE selector [name] block] ... [ CASE DEFAULT [case-name] block END SELECT [case-name]
Example
SELECT CASE (FLAG)
CASE ( 1, 2, 3 )
TYPE=1
CASE ( 4:6 )
TYPE=2
CASE DEFAULT
TYPE=0
END SELECT
Note, there is also an HPF SEQUENCE directive that specifies whether an array, common block, or equivalence is sequential or non-sequential. Refer to Chapter 4, HPF Directives for more information.
Syntax
TYPE [SEQUENCE] type-specification... END TYPE
Example
TYPE RECORD
SEQUENCE
CHARACTER NAME(25)
INTEGER CUST_NUM
REAL COST
END TYPE
The STOP statement stops the program's execution and precludes any further execution of the program.
Syntax
STOP [character-expression | digits ]
Syntax
[RECURSIVE] SUBROUTINE name & [(argument[,argument...])] & [specification-part] [execution-part] [internal-subspart] END [SUBROUTINE [name]]
Description
A SUBROUTINE must be terminated by an END statement. The statements and names in the subprogram only apply to the subroutine except for subroutine or function references and the names of COMMON blocks. Dummy arguments may be specified as * which indicates that the SUBROUTINE contains alternate returns.
Recursion is allowed if the -Mrecursive option is used on the command-line and the RECURSIVE prefix is included in the function definition.
Example
SUBROUTINE DAXTIM (A, X, Y, N, M, ITER, FP, TOH) INTEGER*4 N, M, ITER
REAL*8 A, X(N,M), Y(N,M), FP, TOH . . . END SUBROUTINE DAXTIM
See Also
PURE, RECURSIVE
The TARGET specification statement (attribute) specifies that a data type may
be the object of a pointer variable - that is pointed to by a pointer variable.
Likewise, types that do not have the TARGET attribute cannot be the target of a
pointer variable.
Syntax
TARGET [ :: ] object-name [(array-spec)] [, object-name [(array-spec)]]...
See Also
ALLOCATABLE, POINTER
The TYPE statement begins a derived type data specification or declares variables of a specified user-defined type.
Syntax Type Declaration
TYPE (type-name) [ , attribute-list :: ] entity-list
Syntax Derived Type Definition
TYPE [[ access-spec ] :: ] type-name [ private-sequence-statement ] ... component-definition-statement [ component-definition-statement ]... END TYPE [type-name]
The USE statement gives a program unit access to the public entities or to the named entities in the specified module.
Syntax
USE module-name [, rename-list ] USE module-name, ONLY: [ only-list ]
Description
A module-name file has an associated compiled .mod file that is included when the module is used. The .mod file is searched for in the following directories:
1. Each -I directory specified on the command-line.
2. The directory containing the file that contains the USE statement
(the current working directory.)
3. The standard include area.
Examples
USE MOD1 USE MOD2, TEMP => VAR USE MOD3, ONLY: RESULTS, SCORES => VAR2
Type
Non-executable
See Also
MODULE
The VOLATILE statement inhibits all optimizations on the variables, arrays and common blocks that it identifies.
Syntax
VOLATILE nitem [, nitem ...]
Description
If nitem names a common block, all members of the block are volatile. The volatile attribute of a variable is inherited by any direct or indirect equivalences, as shown in the example.
Example
COMMON /COM/ C1, C2
VOLATILE /COM/, DIR ! /COM/ and DIR are volatile
EQUIVALENCE (DIR, X) ! X is volatile
EQUIVALENCE (X, Y) ! Y is volatile
The WHERE statement and the WHERE END WHERE construct permit masked assignments to the elements of an array (or to a scalar, zero dimensional array).
Syntax WHERE Statement
WHERE (logical-array-expr) array-variable = array-expr
Syntax WHERE Construct
WHERE (logical-array-expr) array-assignments [ELSE WHERE array-assignments ] END WHERE
Description
This construct allows for conditional assignment to an array based on the result of a logical array expression. The logical array expression and the array assignments must involve arrays of the same shape.
Examples
INTEGER SCORE(30)
CHARACTER GRADE(30)
WHERE ( SCORE > 60 ) GRADE = 'P'
WHERE ( SCORE > 60 )
GRADE = 'P'
ELSE WHERE
GRADE = 'F'
END WHERE
Syntax
WRITE ([unit=] u, [,control-information) [iolist] WRITE ([unit=] u, [NML=] namelist-group [,control-information])where the UNIT= is optional and the external unit specifier u is an integer. This may also be a * indicating list-directed output.
In addition to the unit specification, control-information are optional control specifications, and may be any of those listed in the following (there are some limits on the allowed specifications depending on the type of output, for example, non-advancing, direct and sequential):
Description
When a WRITE statement is executed the following operations are carried out: data is transferred to the standard output device from the items specified in the output list and format specification.[*] The data are transferred between the specified destinations in the order specified by the input/output list. Every item whose value is to be transferred must be defined.
Example
WRITE (6,90) NPAGE
90 FORMAT('1PAGE NUMBER ',I2,16X,'SALES REPORT, Cont.')
[*] If an asterisk (*) is used instead of a format identifier, the list-directed formatting rules apply.
[*] If an asterisk (*) is used instead of a format identifier, the list-directed formatting rules apply.
[*] If an asterisk (*) is used instead of a format identifier, the list-directed formatting rules apply.