jagged parameter arrays
- From: Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 29 Aug 2005 01:34:39 -0500
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
.
- Follow-Ups:
- Re: jagged parameter arrays
- From: David Frank
- Re: jagged parameter arrays
- Prev by Date: Re: Algorithm for "1st Tuesday", "last Saturday", etc.
- Next by Date: Re: little isprime challenge
- Previous by thread: Algorithm for "1st Tuesday", "last Saturday", etc.
- Next by thread: Re: jagged parameter arrays
- Index(es):
Relevant Pages
|
|