Re: F90 derived type component as array
- From: "Jugoslav Dujic" <jdujic@xxxxxxxxx>
- Date: Tue, 29 Nov 2005 14:56:52 +0100
kus@xxxxxxxx wrote:
| Sorry,
|
| is there in F90 some restriction(s) for using of components (which are
| really arrays) of derived types
| instead of arrays itself ?
|
| I.e. if I have for example something like
|
| TYPE twoarray
| real, dimension (:,:) ::A
| real, dimension (:,:) ::B
| END TYPE twoarray
|
| TYPE(twoarray), DIMENSION(100) ::struct
|
| - may I use struct(k)%B in any place where I may use simple
| 2-dimensional array ?
Yes. However, your syntax is not correct; the arrays have to
be either fixed-shape:
TYPE twoarray
real, dimension (42,55) ::A
real, dimension (19,38) ::B
END TYPE twoarray
or have pointer attribute:
real, dimension (:,:), POINTER ::A
real, dimension (:,:), POINTER ::B
which you can later ALLOCATE, or, under Fortran2003/TR15581,
allocatable attribute:
real, dimension (:,:), ALLOCATABLE ::A
real, dimension (:,:), ALLOCATABLE ::B
Most modern compilers support that, so I suggest you try it first.
Additionally, you can also use e.g. struct(:)%B(23,37) to refer to
all B(23,37) members of all structs (if you ever need it),
but you cannot use struct(:)%B(:,:) to refer to all B's in all
structs.
| BTW, do I understand correctly that (in reality) memory requirements
| for twoarray structure are
| simple size(A)+size(B), i.e. "mapping" to the memory of this type is
| simple "memory for A" and
| then "memory for B" w/o any "control" information ?
In reality, yes, that's right. POINTER and ALLOCATABLE components
introduce a tiny overhead, in order of magnitude of 20 bytes per
dimension (compiler-dependent).
--
Jugoslav
___________
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
.
- References:
- F90 derived type component as array
- From: kus
- F90 derived type component as array
- Prev by Date: Re: Compaq Visual Fortran discontinued: upgrade to Intel Visual Fortran?
- Next by Date: Re: printing logical variables as "true" and "false"
- Previous by thread: F90 derived type component as array
- Next by thread: tape i/o
- Index(es):
Relevant Pages
|