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

instead?

...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  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem with with Array of U8 to Array of Array of Boolean

2. convert 2d array to 1d array without using shift registers and build array

3. Arrays: Build array in multiple for loops or replace array elements

4. Multidimensional array vs. array of array

5. adjustable-array-p, adjust-array and array-destruction

6. Array scan in type declared array

7. Ada83 array of pointers to unconstrained array type

8. typed structured array or simple fortan array?

9. DEALLOCATE of a derived type array containing pointer array components

10. (typep (make-array 10 :element-type 'bit) '(array bit (10)))

11. Improve efficiency of 3 big array ops.

12. F90 array ops slower than plain code?

 

 
Powered by phpBB® Forum Software