- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've a problem to construct a scalar structure (derived-type variable) containing some allocatable derived-type variables.
The type definition and declaration of the structure looks something like that:
[fortran]Type :: MyType
type(MySubType1) ,dimension(:) ,allocatable :: SubVar1
type(MySubType2) :: SubVar2
End Type
Type :: MySubType1
real ,dimension(:) ,allocatable :: rvar
integer ,dimension(:) ,allocatable :: ivar
End Type
Type :: MySubType2
type(MySubSubType1) ,dimension(:) ,allocatable :: SubVar1
type(MySubSubType2) ,dimension(:) ,allocatable :: SubVar2
End Type
type(MyType) :: Var
[/fortran] As you can see, in the present example the Var variable is a scalar structure containing two derived-type components, one scalar and one allocatable array called SubVar1 and SubVar2 respectively.
The problem is that I first construct the SubVar1 and SubVar2 variables and then I store them into the larger structure by simply copying the data using :
[fortran]Var%SubVar2 = SubVar2[/fortran]
However, by doing so, the components in SubVar2 are not allocated in the Var variable.
How can I transfert the allocation status into a new variable.
Thanks.
I've a problem to construct a scalar structure (derived-type variable) containing some allocatable derived-type variables.
The type definition and declaration of the structure looks something like that:
[fortran]Type :: MyType
type(MySubType1) ,dimension(:) ,allocatable :: SubVar1
type(MySubType2) :: SubVar2
End Type
Type :: MySubType1
real ,dimension(:) ,allocatable :: rvar
integer ,dimension(:) ,allocatable :: ivar
End Type
Type :: MySubType2
type(MySubSubType1) ,dimension(:) ,allocatable :: SubVar1
type(MySubSubType2) ,dimension(:) ,allocatable :: SubVar2
End Type
type(MyType) :: Var
[/fortran] As you can see, in the present example the Var variable is a scalar structure containing two derived-type components, one scalar and one allocatable array called SubVar1 and SubVar2 respectively.
The problem is that I first construct the SubVar1 and SubVar2 variables and then I store them into the larger structure by simply copying the data using :
[fortran]Var%SubVar2 = SubVar2[/fortran]
However, by doing so, the components in SubVar2 are not allocated in the Var variable.
How can I transfert the allocation status into a new variable.
Thanks.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Would you please show us a complete sample program that demonstrates the problem? What you have written here should work, as far as I can see.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please, disreagared the previous post since I have found the (stupide) mistake which was creating the problem.
The problem was simply that I used an intent(out) statment where I should have an intent(inout).
Indeed, I do not directly copying the sub-structure into the upper structure but I am using a procedure which automatically load the sub-structure into the correct structure component. The loading procedure is the following:
[fortran]Subroutine Load_SubStr ( Str, SubStr ) implicit none type(Str_Type) ,intent(inout) :: Str class(*) ,intent(in) :: SubStr select type (SubStr) type is (MyType1); Str%SubStr1 = SubStr type is (MyType2); Str%SubStr2 = SubStr end select End Subroutine[/fortran] The bug was that te Str argument had the intent(out) so that each new component I was loading into the structure was easing the old component which have previousely been loaded into the structure.
The problem was simply that I used an intent(out) statment where I should have an intent(inout).
Indeed, I do not directly copying the sub-structure into the upper structure but I am using a procedure which automatically load the sub-structure into the correct structure component. The loading procedure is the following:
[fortran]Subroutine Load_SubStr ( Str, SubStr ) implicit none type(Str_Type) ,intent(inout) :: Str class(*) ,intent(in) :: SubStr select type (SubStr) type is (MyType1); Str%SubStr1 = SubStr type is (MyType2); Str%SubStr2 = SubStr end select End Subroutine[/fortran] The bug was that te Str argument had the intent(out) so that each new component I was loading into the structure was easing the old component which have previousely been loaded into the structure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad to hear it. This is an of example why posting paraphrases and snippets often hides the real problem.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page