Re: Multi-Dimensional Arrays. Is it possible more than seven dimensions?
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Multi-Dimensional Arrays. Is it possible more than seven dimensions?         

Group: comp.lang.fortran · Group Profile
Author: Damian
Date: Jul 14, 2008 06:11

On Jul 13, 9:03 pm, nos...@see.signature (Richard Maine) wrote:
> hotmail.com> wrote:
>> Hello. I have a problem on trying to define an array with eight
>> dimensions. I tried the following:
>> integer :: N=10
>> complex,dimension(-N:N,-N:N,0:1,0:1,-N:N,-N:N,0:1,0:1) :: P
>
>> , but i get an error when compiling that the array cannot have more
>> than seven dimensions.
>
> That's true. That is a limitation of the current Fortran standard.
>
>> Thank you for any recommendation on what to do, or suggestion about an
>> alternate solution.
>
> I can think of 3 off the top of my head.
>
> 1. As several of your dimensions are hardwired to have only 2 elements,
> you might be able to get by with something like 2 7-dimensional arrays.
>
> 2. You can have an array of derived-type, where the type consists of a
> single component that is in turn an array. There is some awkwardness in
> this in that you can't directly reference some slices (because of the
> restriction against arrays of arrays), but it does get it all in one
> object.
>
> 3. You could collapse 2 of the dimensions into 1, using a single index
> to map onto all the possible values of the 2 original indices. The last
> 2 dimensions would be an easy choice here.
>
> and sort of a 4th, but you can't do it until f2003 (I don't know whether
> gfortran supports that f2003 feature yet). You could define the whole
> thing as a 1-dimensional array and then make pointers to any slice that
> you happened to want, as long as the slice had no more than 7
> dimensions. The f2003 feature in question is allowing higher-rank
> pointers to have rank 1 targets.
>
> --
> Richard Maine | Good judgement comes from experience;
> email: last name at domain . net | experience comes from bad judgement.
> domain: summertriangle | -- Mark Twain

A variant on Richard's 4th idea might be to define a derived type that
holds a 1D array representing the unrolled 8D array and then define a
function whose first is an instance of that derived type and whose
remaining 8 arguments are the indices of the desired element. The
function could compute the jump from the base of the 1D array required
to retrieve the desired element and return that element. The
calculation would be fast and straightforward integer arithmetic and
the notation for inserting a reference to any particular element would
be fairly close to the intrinsic array notation.

Given

type array
complex, dimension(:), allocatable :: unrolled
end type

and naming the aforementioned function "element," you would reference
the element at the "origin," for example, in a formula as

type(array) :: a
complex :: val
val = element(a,0,0,0,0,0,0,0,0)

Of course, you would also need to write procedures for initializing
the array, printing it, etc. All this could be packaged up in a
module and used by other program units.

Damian
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Re: Helper to create multi-dimensional arrayscomp.lang.ruby ·