jagged parameter arrays



I have some data that I would like to reference as a derived type
array. Something like

type xxx
integer :: n
integer, pointer :: j(:) ! j(1:n), allocate later
end type xxx

type(xxx) :: array(2)

In my particular case, I have different values of "n" for each
array(i) element, so these are jagged arrays, not rectangular arrays.

However, I know at compile time what the values of n and j(1:n)
should be for each element of the array. Furthermore, these values
do not change after their initial assignment, so if possible I would
like to make them parameters so that I would get compiler warnings
if, by mistake, I were to try to change them somewhere. The
"pointer" and "parameter" attributes are not compatible, so I can't
do this in a straightforward way.

Here is sort of what I would like to do:

type(xxx) :: array(2)= (/ &
& xxx(2,(/1,2/)), &
& xxx(4,(/1,2,3,4/)) /)

But I don't know how to define the type xxx in order to allow this.

I tried assigning the pointer to another array with initialization,
and that doesn't work either; apparently j(:)=>null() is the only
initialization allowed. Of course, I would really want to declare
the component arrays as allocatable or with fixed dimension rather
than pointer, but I will have to wait for F2003 for that.

I am doing this now with allocate statements for the arrays and
runtime assignments for both the "n" and j(1:n) values. This
somehow seems inelegant, as ultimately I have to store the
information twice in order to get it into the desired derived type
form. Is it possible to do this kind of jagged array initialization
at compile time? Is it possible to, in some roundabout way, achieve
the effect of parameters?

I could declare different types for the arrays of different
dimensions, but then I can't get the different array(i) elements to
point to these different types. I really want to reference these
things as

array(i)%j(k)

with variables, i and k, not just with constant indices. However,
if there is a different approach that achieves the goals, I would
like to know that too.

$.02 -Ron Shepard
.



Relevant Pages

  • Re: call by reference
    ... all parameters are passed by reference and at least if we ignore how ... arrays fit into the picture. ... is illegal to have the operand be anything except a variable. ... The situation gets a bit more interesting once you have aggregate ...
    (comp.lang.scheme)
  • Re: subroutine definitions
    ... > the reference directly in the parameter list. ... I seldom use statically declared arrays or hashes myself, unless they are scope to a ... written a lot of scripts that generate HTML reports from the data in the MySQL DB. ...
    (perl.beginners)
  • Re: Array comparison
    ... > Deep and recursive. ... the pointers and comparing their referents instead of comparing the ... >> arrays, then I think you also need to argue against assigning arrays. ... semantics (notably, reference counting). ...
    (alt.comp.lang.borland-delphi)
  • Re: A VB.NET Critique
    ... the declarations like so: ... in .NET are actually *reference* types its just that *some* of those ... from a language design point of view and is of more relevance to those ... > (such as arrays and strings) just eludes me somewhat; ...
    (comp.programming)
  • Re: arrays of arrays question
    ... can recall that in learning any language, ... them with arrays that i cannot make them work. ... references, then perhaps a reference to an array is a reference to a ...
    (comp.lang.perl.misc)