I’m working on a function that should ideally work for an input array that may have, in different calls, rank 0, 1, 2 or 3.
SELECT RANK seems like doing the job, but as it’s a new feature and the rest of the code is mostly F90 I hesitate a bit to introduce it.
Alternatively, I can always declare a 3D arrays and then keep number of elements in one or two or all three dimensions equal to 1. However, than the code starts to look really ugly (it’s a long code with dozen of variables like that) and I’d rather have some more elegant solution.
What do you do in such situation? Any recommendations? Any example?
So one option you can consider is to take advantage of the Fortran facility where the target of a RANK-N array pointer can be a RANK-1 array. This can greatly simplify the code structure depending on your needs.
That is, elevate your code design a step higher so that the circumstances where you get into situations where you require subroutines with dummy arguments of different ranks are greatly diminished or eliminated altogether.