Dick, Alexsander, Daniel, etc.:
Thanks for the responses. That helps. I think derived types will work for
what I need to do.
Thanks again and best regards.
Edward.
> -----Original Message-----
> From: Dick Hendrickson [SMTP:[log in to unmask]]
> Sent: Thursday, February 21, 2002 11:43 AM
> To: Fortran 90 List; [log in to unmask]
> Subject: Re: Can an array element contain another array?
>
> I'm not quite sure what you are asking, but that won't stop me from
> answering ;-( .
>
> Two things come to mind. You can use a higher dimensioned array
> to "contain" smaller dimensioned arrays. Something like:
>
> real composite (10,7,3)
> ...
> composite(1,:,:) = something that is a 7 by 3 array
> composite(2,:,:) = something that is a 7 by 3 array
> ...
> composite(10,:,:) = something that is a 7 by 3 array
> ...
> composite(I,:,:) = composite(J,:,:) + composite(k,:,:)
>
> the last line does some work on various "array" elements of composite.
> Once you get the composite array built up, you can treat sections of
> it as "pseudo array elements". The drawback is that you need to
> use the : notation for the "array element" parts.
>
> An other choice would be derived types. Something like:
> type has_arrays
> real X(7,3)
> end type
> type (has_arrays) composite(10)
> That creates an array of ten elements. Each element is a 7 by 3
> array.
> composite(1) = something that is a 7 by 3 array ! similar to above
> ...
> composit(I) = composite(J) + composite(K)
>
> The drawback is that you'll have to define functions to do the
> add operation and any other operations you need, since fortran
> doesn't intrinsically define operations between two things of
> type "has_arrays".
>
> You could avoid defining operators by explicitly using the
> components of composite.
> composit(I)%X = composite(J)%X + composite(K)%X
>
> This explicitly adds two 7 by 3 arrays and stores them into an
> explicit 7 by 3 array.
>
> If you need the sub arrays to be different sizes you can add
> the pointer attribute to the X component
> type has_arrays
> real,pointer :: X(7,3)
> end type
> But now you'll have to manage the memory of each component,
> usually by an ALLOCATE statement, and make sure the I, J, and
> K arrays have the right shape if you want to do the add above.
>
> Hope this gives you some ideas.
>
> Dick Hendrickson
>
>
>
> Edward Osei wrote:
> >
> > Hi folks:
> >
> > I was wondering whether Fortran 90/95 allows assignment of arrays to
> > elements of other arrays (i.e. can array elements contain arrays)? If
> not,
> > is there a possibility of including that feature in future fortran
> > implementations?
> >
> > Thanks and best regards.
> > Edward.
> >
> > Edward Osei
> > Senior Research Economist
> > Mailing Address:
> > Texas Institute for Applied Environmental Research
> > Box T-0410
> > Stephenville, TX 76402
> >
> > Phone: (254)968-9583
> > Fax: (254)968-9790
> > Email: [log in to unmask]
|