A specification expression is an expression with limitations that you can use to specify items such as character lengths and array bounds.
A specification expression is a scalar, integer, restricted expression.
A restricted expression is an expression in which each operation is intrinsic and each primary is:
+---------------------------------Fortran 95---------------------------------+
+-----------------------------End of Fortran 95------------------------------+
+-------------------------------IBM Extension--------------------------------+
+----------------------------End of IBM Extension----------------------------+
+---------------------------------Fortran 95---------------------------------+
You can use a specification function in a specification expression. A function is a specification function if it is a pure function that is not an intrinsic, internal or statement function. A specification function cannot have a dummy procedure argument, and cannot be recursive.
+-----------------------------End of Fortran 95------------------------------+
A variable in a specification expression must have its type and type parameters, if any, specified by a previous declaration in the same scoping unit, or by the implicit typing rules in effect for the scoping unit, or by host or use association. If a variable in a specification expression is typed by the implicit typing rules, its appearance in any subsequent type declaration statement must confirm the implied type and type parameters.
If a specification expression includes a reference to an inquiry function for a type parameter or an array bound of an entity specified in the same specification part, the type parameter or array bound must be specified in a prior specification of the specification part. If a specification expression includes a reference to the value of an element of an array specified in the same specification part, the array bounds must be specified in a prior declaration. The prior specification can be to the left of the inquiry function in the same statement.
LBOUND(C,2)+6 ! C is an assumed-shape dummy array ABS(I)*J ! I and J are scalar integer variables 276/NN(4) ! NN is accessible through host association
+---------------------------------Fortran 95---------------------------------+
The following example shows how a user-defined pure function, fact, can be used in the specification expression of an array-valued function result variable:
MODULE MOD CONTAINS INTEGER PURE FUNCTION FACT(N) INTEGER, INTENT(IN) :: N ... END FUNCTION FACT END MODULE MOD PROGRAM P PRINT *, PERMUTE('ABCD') CONTAINS FUNCTION PERMUTE(ARG) USE MOD CHARACTER(*), INTENT(IN) :: ARG ... CHARACTER(LEN(ARG)) :: PERMUTE(FACT(LEN(ARG))) ... END FUNCTION PERMUTE END PROGRAM P
+-----------------------------End of Fortran 95------------------------------+