On Tue, 4 Nov 2003, Catherine Moroney wrote:
> Hi,
>
> I'm trying to declare an array of binary trees within a data
> structure and am running into compilation problems.
> (SGI IRIX 6.5.17, MIPSpro 7.3.2.1m compiler).
>
> Here's the structure that I would like to implement. Basically
> it's an array (of varying size) of binary trees. I want to
> declare several instances of this type(hits_type), that's why I've
> wrapped it in a structure.
>
> If I declare it as a pointer, the compiler doesn't recognize the
> individual btree(i) component as a pointer. If I declare it as a
> fixed-size array, the compiler thinks the "pointer" attribute is
> referring to the btree array itself. How can I tell the compiler
> that each individual data%btree(i) element is itself a pointer?
>
> TYPE BTREE_TYPE
> INTEGER*4 :: INDX
> TYPE(BTREE_TYPE), POINTER :: LEFT
> TYPE(BTREE_TYPE), POINTER :: RIGHT
> END TYPE BTREE_TYPE
>
> TYPE HITS_TYPE
> INTEGER :: NCAMS
> TYPE(BTREE_TYPE), DIMENSION(:), &
> POINTER :: BTREE ! Can't nullify
> ! this component
> TYPE(BTREE_TYPE), DIMENSION(9), &
> POINTER :: BTREE ! Won't compile
> END TYPE HITS_TYPE
>
>
> TYPE(HITS_TYPE) :: data
> nullify(data%btree(1))
this obviously won't work. data%btree(1) is an array element and not a
pointer. here's how i would do it (using a wrapper around BTREE_TYPE)
type BTREE_WRAP_TYPE
type(BTREE_TYPE), pointer :: my_btree => NULL() ! F95 specific
end type BTREE_WRAP_TYPE
type HITS_TYPE
integer :: NCAMS
type(BTREE_WRAP_TYPE), dimension(:), pointer :: BTREE_WRAP
end type HITS_TYPE
type(HITS_TYPE) :: data
now allocate data % btree_wrap to whatever size you want
allocate(data % btree_wrap (size))
nullify(data % btree_wrap(1) % btree) ! will work
it gets hairy pretty soon. IMHO, i would do this kind of stuff in c++ and
do the computationally intensive part in fortran (though mixed language
programming can be a real portability pain)
renchi
|