Catherine Moroney writes:
> How can I tell the compiler
> that each individual data%btree(i) element is itself a pointer?
Your subject line tells the whole story in this case. You can't
(directly) have an array of pointers in Fortran. As you have noticed,
the otherwise "obvious" syntax for such a thing
> TYPE(BTREE_TYPE), DIMENSION(:), POINTER :: BTREE
Is a pointer to an array instead of an array of pointers. As an
aside, pointer arrays are always dynamically sized. You can't do
fixed size ones such as
> TYPE(BTREE_TYPE), DIMENSION(9), POINTER :: BTREE
But back to the original question. Note my qualifier "directly".
You can get most of the effect of an array of pointers. This is
a quite common question - enough so that I tend to refer to the
"usual trick," which is to make a derived type that has a pointer
as its only component, such as
type btree_ptr_type
type(btree_type), pointer :: btree
end type
Then you can have an array of btree_ptr_type as in
type(btree_ptr_type), dimension(9) :: btree_ptr
or you could make this array a pointer in turn (so as to be able
to dynamically size it) like
type(btree_ptr_type), dimension(:), pointer :: btree_ptrs
The btree_ptr_type does introduce another level into the structure,
so instead of your
> TYPE(HITS_TYPE) :: data
> nullify(data%btree(1))
you would need something like
TYPE(HITS_TYPE) :: data
allocate(data%btree_ptrs(9)) !-- If you use the dynamically sized
!-- version, you need this before you
!-- can refer to one of the elements.
!-- Otherwise, omit this.
nullify(data%btree_ptrs(1)%btree)
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|