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, DIMENSION(3), 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.
Return to corresponding overview page