On Tue, 03 Jul 2007 09:52:34 +0900, Van Snyder <[log in to unmask]>
wrote:
> Rank cannot be determined at run time, nor is it planned to provide for
> this in Fortran 2008. It's unlikely it will ever be done, since rank is
> an intrinsic part of compile-time generic procedure resolution.
Right, but there are lots of individual variable-rank things one can do
that
are pretty easy, if a bit messy. Many of these don't involve much more
than
what one can already do in F77, but F2003 makes some things a bit easier
with its rank-remapping facility.
E.g.,
to apply some generic procedure "PROCESS", which does different things
for different ranks,
SUBROUTINE s(array,totalsize,rank,shape)
REAL,TARGET :: array(totalsize)
INTEGER rank,shape(rank)
REAL,POINTER :: p1(:),p2(:,:),p3(:,:,:)
SELECT CASE(rank)
CASE (3)
p3(1:shape(1),1:shape(2),1:shape(3)) => array
CALL process(p3)
...
This is better than using RESHAPE since it allows the called procedure
to update the array (and maybe also avoids a copy). If you don't have
rank remapping available you can achieve a similar effect via a set of
helper procedures.) If you find yourself wanting to do it a lot, rather
than having this code everywhere you could make a data type with a base
array component and a set of pointers that are different-rank "views"
of that base array.
Basically, the current choices probably boil down to using sequence
association tricks to do what you want, or to emulating variable-rank
in a single-rank array.
Cheers,
--
Malcolm Cohen, Nihon Numerical Algorithms Group KK, Tokyo, Japan.
|