next up previous contents
Next: Allocatable Arrays Up: Arrays Previous: The RESHAPE Intrinsic Function

 

Array Constructors in Initialisation Statements

Named array constants of any rank can be created using the RESHAPE function as long as all components can be evaluated at compile time (just like in initialisation expressions):

    INTEGER, PARAMETER :: Unit_vec = (/1,1,1/)
    CHARACTER(LEN=*), DIMENSION(3), PARAMETER :: &
          lights = (/'RED  ','BLUE ','GREEN'/)
    REAL, DIMENSION(3,3), PARAMETER :: &
          unit_matrix = RESHAPE((/1,0,0,0,1,0,0,0,1/), (/3,3/))

Note how the string length of the PARAMETER lights can be assumed from the length of the constructor values. The strings in the constructor must all be the same length.

Previously defined constants (PARAMETER s) may also be used to initialise variables, consider,

    INTEGER, DIMENSION(3,3) :: &
          unit_matrix_T = RESHAPE(unit_matrix, (/3,3/), ORDER=(/2,1/))

This assigns the transpose of unit_matrix to unit_matrix_T.

Now try this question gif


next up previous contents
Next: Allocatable Arrays Up: Arrays Previous: The RESHAPE Intrinsic Function

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.