Prev: How to define a user data type containing an array with dimensions decided in running time
Next: negative zeros and dot_product / matmul
From: Richard Maine on 15 May 2010 19:46 Hifi-Comp <wenbinyu.heaven(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 |