<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Construction of structure with nested derived-type components in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766234#M20244</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I've a problem to construct a scalar structure (derived-type variable) containing some allocatable derived-type variables.&lt;BR /&gt;The type definition and declaration of the structure looks something like that:&lt;BR /&gt;[fortran]Type :: MyType&lt;BR /&gt; type(MySubType1) ,dimension(:) ,allocatable :: SubVar1&lt;BR /&gt; type(MySubType2) :: SubVar2&lt;BR /&gt; End Type&lt;BR /&gt; &lt;BR /&gt; Type :: MySubType1&lt;BR /&gt; real ,dimension(:) ,allocatable :: rvar&lt;BR /&gt; integer ,dimension(:) ,allocatable :: ivar&lt;BR /&gt; End Type&lt;BR /&gt;&lt;BR /&gt; Type :: MySubType2&lt;BR /&gt; type(MySubSubType1) ,dimension(:) ,allocatable :: SubVar1&lt;BR /&gt; type(MySubSubType2) ,dimension(:) ,allocatable :: SubVar2&lt;BR /&gt; End Type&lt;BR /&gt;&lt;BR /&gt; type(MyType) :: Var &lt;BR /&gt; 
[/fortran] As you can see, in the present example the &lt;I&gt;Var&lt;/I&gt; variable is a scalar structure containing two derived-type components, one scalar and one allocatable array called &lt;I&gt;SubVar1&lt;/I&gt; and &lt;I&gt;SubVar2&lt;/I&gt; respectively.&lt;BR /&gt;&lt;BR /&gt;The problem is that I first construct the &lt;I&gt;SubVar1&lt;/I&gt; and &lt;I&gt;SubVar2&lt;/I&gt; variables and then I store them into the larger structure by simply copying the data using :&lt;BR /&gt;[fortran]Var%SubVar2 = SubVar2[/fortran] &lt;BR /&gt;However, by doing so, the components in SubVar2 are not allocated in the Var variable.&lt;BR /&gt;How can I transfert the allocation status into a new variable.&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 23 Mar 2012 13:58:58 GMT</pubDate>
    <dc:creator>FlyingHermes</dc:creator>
    <dc:date>2012-03-23T13:58:58Z</dc:date>
    <item>
      <title>Construction of structure with nested derived-type components</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766234#M20244</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I've a problem to construct a scalar structure (derived-type variable) containing some allocatable derived-type variables.&lt;BR /&gt;The type definition and declaration of the structure looks something like that:&lt;BR /&gt;[fortran]Type :: MyType&lt;BR /&gt; type(MySubType1) ,dimension(:) ,allocatable :: SubVar1&lt;BR /&gt; type(MySubType2) :: SubVar2&lt;BR /&gt; End Type&lt;BR /&gt; &lt;BR /&gt; Type :: MySubType1&lt;BR /&gt; real ,dimension(:) ,allocatable :: rvar&lt;BR /&gt; integer ,dimension(:) ,allocatable :: ivar&lt;BR /&gt; End Type&lt;BR /&gt;&lt;BR /&gt; Type :: MySubType2&lt;BR /&gt; type(MySubSubType1) ,dimension(:) ,allocatable :: SubVar1&lt;BR /&gt; type(MySubSubType2) ,dimension(:) ,allocatable :: SubVar2&lt;BR /&gt; End Type&lt;BR /&gt;&lt;BR /&gt; type(MyType) :: Var &lt;BR /&gt; 
[/fortran] As you can see, in the present example the &lt;I&gt;Var&lt;/I&gt; variable is a scalar structure containing two derived-type components, one scalar and one allocatable array called &lt;I&gt;SubVar1&lt;/I&gt; and &lt;I&gt;SubVar2&lt;/I&gt; respectively.&lt;BR /&gt;&lt;BR /&gt;The problem is that I first construct the &lt;I&gt;SubVar1&lt;/I&gt; and &lt;I&gt;SubVar2&lt;/I&gt; variables and then I store them into the larger structure by simply copying the data using :&lt;BR /&gt;[fortran]Var%SubVar2 = SubVar2[/fortran] &lt;BR /&gt;However, by doing so, the components in SubVar2 are not allocated in the Var variable.&lt;BR /&gt;How can I transfert the allocation status into a new variable.&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Mar 2012 13:58:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766234#M20244</guid>
      <dc:creator>FlyingHermes</dc:creator>
      <dc:date>2012-03-23T13:58:58Z</dc:date>
    </item>
    <item>
      <title>Construction of structure with nested derived-type components</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766235#M20245</link>
      <description>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.</description>
      <pubDate>Fri, 23 Mar 2012 14:36:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766235#M20245</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-03-23T14:36:35Z</dc:date>
    </item>
    <item>
      <title>Construction of structure with nested derived-type components</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766236#M20246</link>
      <description>Please, disreagared the previous post since I have found the (stupide) mistake which was creating the problem.&lt;BR /&gt;&lt;BR /&gt;The problem was simply that I used an &lt;I&gt;intent(out)&lt;/I&gt; statment where I should have an&lt;I&gt; intent(inout)&lt;/I&gt;.&lt;BR /&gt;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:&lt;BR /&gt;[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 &lt;I&gt;intent(out)&lt;/I&gt; so that each new component I was loading into the structure was easing the old component which have previousely been loaded into the structure.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Mar 2012 14:44:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766236#M20246</guid>
      <dc:creator>FlyingHermes</dc:creator>
      <dc:date>2012-03-23T14:44:38Z</dc:date>
    </item>
    <item>
      <title>Construction of structure with nested derived-type components</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766237#M20247</link>
      <description>Glad to hear it. This is an of example why posting paraphrases and snippets often hides the real problem.</description>
      <pubDate>Fri, 23 Mar 2012 15:33:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Construction-of-structure-with-nested-derived-type-components/m-p/766237#M20247</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-03-23T15:33:53Z</dc:date>
    </item>
  </channel>
</rss>

