Just for fun, you can also make the large A matrix by using do-loops as
do i = 1, N
A( i, : ) = [ A1( i,: ), A2( i,: ), A3( i,: ) ]
A( i + N, : ) = [ A4( i,: ), A5( i,: ), A6( i,: ) ]
A( i + N*2, : ) = [ A7( i,: ), A8( i,: ), A9( i,: ) ]
enddo
which fills the A matrix in row-major way and so the small matrices also appear in that way. If really really necessary, this could also be written as one-liner as
A = transpose( reshape( &
[ ( [ A1( i,: ), A2( i,: ), A3( i,: ) ], i=1,N ), &
( [ A4( i,: ), A5( i,: ), A6( i,: ) ], i=1,N ), &
( [ A7( i,: ), A8( i,: ), A9( i,: ) ], i=1,N ) ], [N*3, N*3] ))
which turns out to be the transpose of the second array constructor in the @francescalus answer (in one-liner form)
A = reshape( &
[ ( [ A1( :,i ), A4( :,i ), A7( :,i ) ], i=1,N ), &
( [ A2( :,i ), A5( :,i ), A8( :,i ) ], i=1,N ), &
( [ A3( :,i ), A6( :,i ), A9( :,i ) ], i=1,N ) ], [N*3, N*3] )
To go one-step further, we may define hcat
and vcat
routines as in other languages (note here that explicit interface is necessary):
function hcat( A, B, C ) result( X )
integer, dimension(:,:) :: A, B, C
integer :: X( size(A,1), size(A,2)+size(B,2)+size(C,2) )
X = reshape( [ A, B, C ], shape( X ) )
endfunction
function vcat( A, B, C ) result( X )
integer, dimension(:,:) :: A, B, C
integer :: X( size(A,1)+size(B,1)+size(C,1), size(A,2) )
X = transpose( reshape( &
[ transpose(A), transpose(B), transpose(C) ], &
[ size(X,2), size(X,1) ] ) )
endfunction
then we can write
A = vcat( hcat( A1, A2, A3 ), hcat( A4, A5, A6 ), hcat( A7, A8, A9 ) )
which is somewhat more similar to the desired form in the question:
A = [ A1 A2 A3 ; A4 A5 A6 ; A7 A8 A9 ]