<?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   in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163645#M143808</link>
    <description>&lt;P&gt;Ok, i will try to make it more clear&lt;/P&gt;

&lt;P&gt;Let's say i have a base type &lt;STRONG&gt;set&lt;/STRONG&gt;. A &lt;STRONG&gt;set &lt;/STRONG&gt;has a name &lt;STRONG&gt;set%name &lt;/STRONG&gt;and consists of an unknown amount of members &lt;STRONG&gt;set%members&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type set
  character(*) :: name
  integer(ik), allocatable :: members(:)
end type set&lt;/PRE&gt;

&lt;P&gt;Further i have a &lt;STRONG&gt;database &lt;/STRONG&gt;this database consits of a &lt;EM&gt;unknown&lt;/EM&gt; (at least at that point) amount of sets&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type database
  type(set), allocatable :: set(:)
  integer(ik) :: nsets
end type database&lt;/PRE&gt;

&lt;P&gt;Then an external input-file is read. There the amount of sets (database%nsets) in the database can be evaluated. And now i want to asign this dimension to the &lt;STRONG&gt;database%set(1:database%nsets)&lt;/STRONG&gt;. This works totally fine using:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;if (allocated(database%set)) deallocate(database%set) ; allocate(database%set(database%nsets))&lt;/PRE&gt;

&lt;P&gt;But since the code has a lot of lines (plus i have to use this multiple times) and the name of the types and their derived types are pretty long i wanted to put this into a suibroutine to improve readability since i am the only one woring on this code, but not the only one using it.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2017 17:09:00 GMT</pubDate>
    <dc:creator>Jan_M_</dc:creator>
    <dc:date>2017-08-08T17:09:00Z</dc:date>
    <item>
      <title>Problems when passing derived types to subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163641#M143804</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;i'm running in some trouble when trying to pass some derived types to subroutines for their allocation:&lt;/P&gt;

&lt;P&gt;here some small example i created to explaining my problem:&lt;/P&gt;

&lt;P&gt;the module containing the derived type:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;module type
  implicit none
  private
  public :: mt, rk, ik, ck

&amp;nbsp; integer, parameter :: digits = 8
&amp;nbsp; integer, parameter :: decades = 9
&amp;nbsp; integer, parameter :: rk = selected_real_kind(digits)
&amp;nbsp; integer, parameter :: ik = selected_int_kind(decades)
&amp;nbsp; integer, parameter :: ck = selected_char_kind('default')

  type set
    character(kind=ck,len=80) :: name
    integer(ik), allocatable :: members(:)
  end type set

  type mytype
    type(set), allocatable :: nset(:)
  end type mytype
&amp;nbsp; type(mytype) :: mt
end module type
&lt;/PRE&gt;

&lt;P&gt;and the module containing the subroutines:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;module allocating_sub 
  use type, only : ik, rk, ck
  implicit none
  private
  public :: allocating

  interface allocating
    module procedure allocating_real_1d, allocating_int_1d, allocating_char_1d
  end interface

contains

  subroutine allocating_real_1d(vec,length)
    implicit none
    real(rk), allocatable, intent(inout) :: vec(:)
    integer(ik), intent(in) :: length

    if(allocated(vec)) deallocate(vec)
    allocate(vec(length))
  end subroutine allocating_real_1d
  
  subroutine allocating_int_1d(vec,length)
    implicit none
    integer(ik), allocatable, intent(inout) :: vec(:)
    integer(ik), intent(in) :: length

    if(allocated(vec)) deallocate(vec)
    allocate(vec(length))
  end subroutine allocating_int_1d
  
  subroutine allocating_char_1d(vec,length)
    implicit none
    character(*), allocatable, intent(inout) :: vec(:)
    integer(ik), intent(in) :: length

    if(allocated(vec)) deallocate(vec)
    allocate(vec(length))
  end subroutine allocating_char_1d
  
end module allocating_sub&lt;/PRE&gt;

&lt;P&gt;and finaly the main part:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program test
  use type, only : ik, rk, ck, mt
  use allocating_sub
  implicit none

  integer(ik), parameter :: nnsets = 4

  call allocating (mt%nsets(:),nnsets)
end program test&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;when i try to run this i get the following error:&lt;/P&gt;

&lt;P&gt;error #6285: There is no matching specific subroutine for this generic subroutine call.&amp;nbsp;&amp;nbsp; [ALLOCATING]&amp;nbsp;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Now i am asking myself how to write a subroutine allocating_xx which is able to handle such structures.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;the following solution works but strongly impairs the readabilty of the main code if large type-structures are used:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;if (allocated(mt%nset)) deallocate(mt%nset) ; allocate(mt%nset(nnsets))&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Best regards,&lt;/P&gt;

&lt;P&gt;Jan&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 08:18:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163641#M143804</guid>
      <dc:creator>Jan_M_</dc:creator>
      <dc:date>2017-08-08T08:18:46Z</dc:date>
    </item>
    <item>
      <title>The problem is this:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163642#M143805</link>
      <description>&lt;P&gt;The problem is this:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt; call allocating (mt%nsets(:),nnsets)
&lt;/PRE&gt;

&lt;P&gt;Get rid of the (:) - it completely changes the meaning of what you're doing here. See &lt;A href="https://software.intel.com/en-us/blogs/2008/03/31/doctor-it-hurts-when-i-do-this"&gt;here&lt;/A&gt; for more.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:36:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163642#M143805</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-08-08T15:36:24Z</dc:date>
    </item>
    <item>
      <title>Hello Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163643#M143806</link>
      <description>&lt;P&gt;Hello Steve,&lt;/P&gt;

&lt;P&gt;thank you for your fast reply.&lt;/P&gt;

&lt;P&gt;I already tried this, but the error still remains.&lt;/P&gt;

&lt;P&gt;This would work totally fine if mt%nset was the final / lowest "level" of the type mt.&lt;/P&gt;

&lt;P&gt;I only get this error if "sublevels" like mt%nset%name exist and i try to allocate mt%nset(1:nnsets) via subroutine call.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;small correction&lt;/STRONG&gt; to the above code: mt%nsets has to be mt%nset&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:51:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163643#M143806</guid>
      <dc:creator>Jan_M_</dc:creator>
      <dc:date>2017-08-08T15:51:00Z</dc:date>
    </item>
    <item>
      <title>Ok. You did need to remove</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163644#M143807</link>
      <description>&lt;P&gt;Ok. You did need to remove the (:) as the (:) makes the argument incompatible with the ALLOCATABLE attribute.&lt;/P&gt;

&lt;P&gt;The more basic problem is that you are passing something of type SET where the generic has corresponding dummy arguments of type real, integer or character. &amp;nbsp;It's not clear to me what you want to do here - how do you want to decide what type to allocate?&lt;/P&gt;

&lt;P&gt;There seems to be something missing here. Can you explain in more detail what you want to accomplish? If you want a component that can be of multiple types, you could make it CLASS(*) but then would have to explicitly specify the type when allocating.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 16:44:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163644#M143807</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-08-08T16:44:45Z</dc:date>
    </item>
    <item>
      <title> </title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163645#M143808</link>
      <description>&lt;P&gt;Ok, i will try to make it more clear&lt;/P&gt;

&lt;P&gt;Let's say i have a base type &lt;STRONG&gt;set&lt;/STRONG&gt;. A &lt;STRONG&gt;set &lt;/STRONG&gt;has a name &lt;STRONG&gt;set%name &lt;/STRONG&gt;and consists of an unknown amount of members &lt;STRONG&gt;set%members&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type set
  character(*) :: name
  integer(ik), allocatable :: members(:)
end type set&lt;/PRE&gt;

&lt;P&gt;Further i have a &lt;STRONG&gt;database &lt;/STRONG&gt;this database consits of a &lt;EM&gt;unknown&lt;/EM&gt; (at least at that point) amount of sets&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type database
  type(set), allocatable :: set(:)
  integer(ik) :: nsets
end type database&lt;/PRE&gt;

&lt;P&gt;Then an external input-file is read. There the amount of sets (database%nsets) in the database can be evaluated. And now i want to asign this dimension to the &lt;STRONG&gt;database%set(1:database%nsets)&lt;/STRONG&gt;. This works totally fine using:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;if (allocated(database%set)) deallocate(database%set) ; allocate(database%set(database%nsets))&lt;/PRE&gt;

&lt;P&gt;But since the code has a lot of lines (plus i have to use this multiple times) and the name of the types and their derived types are pretty long i wanted to put this into a suibroutine to improve readability since i am the only one woring on this code, but not the only one using it.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 17:09:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163645#M143808</guid>
      <dc:creator>Jan_M_</dc:creator>
      <dc:date>2017-08-08T17:09:00Z</dc:date>
    </item>
    <item>
      <title>What you describe here is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163646#M143809</link>
      <description>&lt;P&gt;What you describe here is easy, but I don't see how it relates to having integer, real and character allocating routines. You can have a single allocate routine that gets passed database%set and allocates it to the desired size.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 17:37:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163646#M143809</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-08-08T17:37:08Z</dc:date>
    </item>
    <item>
      <title>I wanted total create a multi</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163647#M143810</link>
      <description>I wanted total create a multi-purpose subroutine to be able to allocate types, reals, integers, and characters by calling the overloaded subroutine "allocating". But it seems like I complicated things way too much...</description>
      <pubDate>Tue, 08 Aug 2017 17:59:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163647#M143810</guid>
      <dc:creator>Jan_M_</dc:creator>
      <dc:date>2017-08-08T17:59:51Z</dc:date>
    </item>
    <item>
      <title>Quote:Jan M. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163648#M143811</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Jan M. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;.. it seems like I complicated things way too much...&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;@Jan M.,&lt;/P&gt;

&lt;P&gt;With (re)allocate on assignment facility in the Fortran standard that is very convenient with intrinsic types as well as derived types whose components do not have attributes that might complicate matters (e.g., POINTERs) or subcomponents thereof, do you even need the overloaded "allocating" procedure?&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-standard-realloc-lhs" target="_blank"&gt;https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-standard-realloc-lhs&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 19:32:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163648#M143811</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2017-08-08T19:32:09Z</dc:date>
    </item>
    <item>
      <title>Hello FortranFan,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163649#M143812</link>
      <description>&lt;P&gt;Hello FortranFan,&lt;/P&gt;

&lt;P&gt;thank you very much, i was not aware of this compiler-option (i found out it was turned off).&lt;/P&gt;

&lt;P&gt;You are right, considering this i don't need the overloaded subroutine.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 06:14:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Problems-when-passing-derived-types-to-subroutine/m-p/1163649#M143812</guid>
      <dc:creator>Jan_M_</dc:creator>
      <dc:date>2017-08-10T06:14:21Z</dc:date>
    </item>
  </channel>
</rss>

