In C you can easily initialize an array using the curly braces syntax, if I remember correctly:
int* a = new int[] { 1, 2, 3, 4 };
How can you do the same in Fortran for two-dimensional arrays when you wish to initialize a matrix with specific test values for mathematical purposes? (Without having to doubly index every element on separate statements)
The array is either defined by
real, dimension(3, 3) :: a
or
real, dimension(:), allocatable :: a
You can do that using reshape and shape intrinsics. Something like:
But remember the column-major order. The array will be
after reshaping.
So to get:
you also need transpose intrinsic:
For more general example (allocatable 2D array with different dimensions), one needs size intrinsic: