Question about array ops on arrays of types of arrays of ...(ack)
Author Message Question about array ops on arrays of types of arrays of ...(ack)

Hi ya,

If I have a simple type, that contains an array, say something like

type blah
integer, pointer, dimension(:) :: a
real, pointer, dimension(:) :: r
end type blah

and then make up an array of "blah"'s (and allocate all the arrays
in each "blah"),

type(blah), dimension(20) ::  struct

can I then do array ops on the arrays in the structure as a whole?
ie to zero all the "r"'s at the moment I'd do

do i = 1, 20
struct(i)%r=0.0
enddo

But can you do something like

struct%r = 0.0

...and what happens when you do "struct = 0"?

I haven't tried to see if you can do this myself (yet), but would
be interested to know if f90 and/or compilers are smart enough
to swallow something like "struct%r = 0.0"

Thanks!

Richard

Tue, 12 May 1998 03:00:00 GMT  Question about array ops on arrays of types of arrays of ...(ack)

Quote:

>..
>>   type blah
>>     integer, pointer, dimension(:) :: a
>>     real, pointer, dimension(:) :: r
>>   end type blah
>..
>>   type(blah), dimension(20) ::  struct
>..
>> can you do something like

>>   struct%r = 0.0

>YES but you have to follow the rules. "struct%r" is considered to be
>an array of reals, so you can do any array op that works for reals.

I beg to differ.  The fourth constraint of section 6.1.2 says,

Constraint: In a data-ref, there must not be more than one part-ref
with nonzero rank.  A part-name to the right of a part-ref
with nonzero rank must not have the POINTER attribute.

(The "part-ref"s are the things separated by "%"; a "part-name" is the
name portion of a part-ref, i.e., without any parentheses or subscripts.)

In the above example, the data reference "struct%r" is illegal since both
struct and r have rank one.  The data reference, "struct(i)%r" is OK,
because "struct(i)" is an element of the struct array and thus a scalar
(rank zero) even though its two components, struct(i)%a and struct(i)%r,
are both vectors.

If the components of blah were fixed-size arrays, the data reference,
"struct%r(j)" would also be OK, and would represent a kind of array
section of struct.  However, in this example, the components _do_ have the
pointer attribute and so such a data reference is ruled out by the second
sentence of the above constraint (otherwise, struct would, in effect,
represent a "ragged array", since each struct(i)%r could be allocated with
a different size).

--

Stanford Linear Accelerator Center       | reflect those of SLAC,
MS 97; P.O. Box 4349; Stanford, CA 94309 | Stanford or the DOE

Fri, 15 May 1998 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages