The Fortran 2008 Standard defines a maximum rank of 15. ifort
allows 31. gfortran
still does not support more than 7 dimensions as of May 2013 . So - if you really need all 22 dimensions, use ifort
- but be aware that this feature is an extension of the standard, other compilers might not compile your code.
EDIT: To sum up the discussion in the comments:
There are two problems - one related to the maximum dimensions and one related to the array size.
For compilers that do not allow for 22 dimensions, one could use one large array of rank 1 that holds all elements and calculate the index inside the element oneself using strides.
Internally all arrays are stored contiguous in memory - think of it as a large array of rank one and size N*M*... Fortran actually stores the resulting array in column-major format. So a matrix Z(NxM) is stored as a vector A(N*M), and access to the elements is calculated by strides: Z(3,4) is at index A( M*(4-1)+3 ). Note that the memory is the same for both arrays!
The next problem is the array size:
For n=2 the code works because than it fits into memory: 2**21*21=44040192 at complex (16 bytes) this amounts to 672 MB. At n=4 this becomes 4**21*21 which is 1344TB.