In my code, I have a subroutine that takes a 5th-rank array as argument and uses a local variable, which is a 4-th rank array sharing the first 4 indices.
I'm trying to find a more concise way to express the size declaration in
subroutine mysub(momentum)
complex, intent(in) :: momentum(:,:,:,:,:)
complex :: prefactor( &
& size(momentum,1), size(momentum,2), size(momentum,4) &
& size(momentum,5) )
...
end subroutine mysub
The verbosity of the size declaration harms readability, especially when variable names are even longer than here.
If this was octave/matlab I'd pre-allocate prefactor
by writing
prefactor = zeros(size(momentum)([1 2 4 5]))
Does Fortran 90 support something similarly concise? I know that it could be solved using preprocessor macros, such as
#define XSIZE2(array,a,b) SIZE(array,a), SIZE(array,b)
#define XSIZE3(array,a,b,c) SIZE(array,a), SIZE(array,b), SIZE(array,c)
#define XSIZE4(array,a,b,c,d) SIZE(array,a), SIZE(array,b), SIZE(array,c), SIZE(array,d)
but introducing such definitions would probably harm the readability more than it helps.
See Question&Answers more detail:
os