From: Hifi-Comp on
My particular situation is that n, the dimension of vector, remains
the same throughout the program and there are many variables (scalars,
vectors, matrices) of type User_Data. And I do not perform "allocate"
statement for each such variable.




On May 15, 7:46 pm, nos...(a)see.signature (Richard Maine) wrote:
> Hifi-Comp <wenbinyu.hea...(a)gmail.com> wrote:
> > I am thinking to create a user data type containing an array with
> > dimensions decided in running time.
>
> > Currently I have the following:
>
> > INTEGER,PARAMETER:: n=3
>
> > TYPE,PUBLIC:: User_Data
> >       REAL(DBL_AD)::scale
> >       REAL(DBL_AD)::vector(n)
> > END TYPE User_Data
>
> > I guess I need to use pointers.
>
> Allocatables are far better. Pointers can be twisted into doing the
> trick, but it is a hack, and has hackish consequences (that things won't
> work intuitively). Pointers are basically for... pointing. Allocatables
> are for allocating. You do need iether f95+TR or f2003 for allocatable
> components, but most compilers have f95+TR these days.
>
> As in, change your vector component declaration to
>
>   real(dbl_ad), allocatable :: vector(:)
>
> Then if x is a variable of type user_data, do
>
>   allocate(x%vector(whatever_size_you need))
>
> or use any other method of allocating allocatables (such as the f2003
> allocate-on-assignment or the move_alloc intrinsic).
>
> --
> Richard Maine                    | Good judgment comes from experience;
> email: last name at domain . net | experience comes from bad judgment.
> domain: summertriangle           |  -- Mark Twain