Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Variable rank of an array

dnoack
Beginner
352 Views
Hello all,
I would like to use an array with variable rank, i.e. in one run array(2,3), in another run array(3,4,5) and in another run array(5,4,3,2) ...
Please can anyone explain to me, how I can program this?
Thanks,
Dieter
0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
352 Views
Look at using C_F_POINTER

When the data is ina contiguous chunk you can convert the LOC of the first cell into a C_PTR and then use the C_PTR in C_F_POINTER to convert to a rank 1 through rank 7 array. The only limitation is the conversion produces an array with lower bounds of 1.

Jim Dempsey
0 Kudos
IanH
Honored Contributor II
352 Views
One approach is to make array have as many dimensions as you are ever going to need (seven is the maximum anyway) and leave the unneeded dimensions with an extent of one - array(2,3,1,1), array(3,4,5,1) array(5,4,3,2).

Or you could roll your own array indexing into a rank one array: array(idx_fn(array_size, [2,3])), where idx_fn calculates the appropriate rank one index to use.

Or a bit of both!
0 Kudos
Steven_L_Intel1
Employee
352 Views
Don't count on the rank being limited to 7. F2008 raises that to 15.

A proposal for F2008 (not in the standard but in a "Technical Report" being discussed) adds an "assumed rank" feature that would make such things easier.
0 Kudos
dnoack
Beginner
352 Views
Hello Jim,
unfortunatly I have make a misprint and have rated your postingas poor. Of course, this is not poor, but also a good answer.
I apologize for this but cannot correct my rating.

Dieter
0 Kudos
Reply