program test
implicit none;
character, allocatable :: a(:), a3d(:,:,:)
character :: NL = new_line( 'x' )
integer ni, nj, nchannels
integer i, j
ni = 3; nj = 4; nchannels = 5
! Original array
a = [ ( achar( iachar( 'a' ) + modulo( i - 1, 26 ) ), i = 1, ni * nj * nchannels ) ]
! Reshaped array
a3d = reshape( a, [nchannels,nj,ni] ) ! allocate, copy and reshape
! Print reshaped array
write( *, "( *( a ) )" ) ( ( a3d(:,j,i), NL, j = 1, nj ), NL, i = 1, ni )
deallocate( a, a3d )
end program test