(j3.2006) How to assign to the declared-type part of a polymorphic allocatable array?
Van Snyder
Van.Snyder
Fri Sep 23 14:41:26 EDT 2016
Another solution:
Assuming the polymorphic thing is a component, give the parent object
the target attribute, create a nonpolymorphic pointer of the same
declared type as the component
Let the object be Q and the polymorphic component be Geo, with a
declared type of H_t.
target :: Q
type(h_t), pointer :: Nonpolymorphic_Handle
Nonpolymorphic_handle => Q%Geo
Nonpolymorphic_handle = New_Geolocation
All the solutions are uglier than
Q%Geo(:) = New_Geolocation
On Fri, 2016-09-23 at 12:48 +0000, Clune, Thomas L. (GSFC-6101) wrote:
> Nice. I guess I?ve had a blind eye towards using TYPE instead of CLASS in this context.
>
> - Tom
>
>
> > On Sep 23, 2016, at 4:55 AM, Cohen Malcolm <malcolm at nag-j.co.jp> wrote:
> >
> > <<<
> > Is there a way to assign to the declared-type part of a polymorphic
> > allocatable array, other than one component at a time?
> >>>>
> >
> > Yes, use a procedure, for example:
> >
> > Elemental Subroutine assign_t_only(a,b)
> > Type(t),Intent(Out) :: a
> > Type(t),Intent(In) :: b
> > a = b
> > End Subroutine
> >
> > That handles things with a declared type of T whether polymorphic or not, to
> > handle things with a declared type that is an extension of T you need only
> > use the additional procedure:
> >
> > Elemental Subroutine assign_t_only_e(aa,bb)
> > Class(t),Intent(InOut) :: aa
> > Class(t),Intent(In) :: bb
> > Call assign_t_only(aa,bb)
> > End Subroutine
> >
> > (This second one could be a type-bound procedure of T, and the first could
> > be an internal procedure of the second.)
> >
> > Cheers,
> > --
> > ........................Malcolm Cohen, Nihon NAG, Tokyo.
> >
> > _______________________________________________
> > J3 mailing list
> > J3 at mailman.j3-fortran.org
> > http://mailman.j3-fortran.org/mailman/listinfo/j3
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
More information about the J3
mailing list