<?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 Anders, in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143608#M137906</link>
    <description>&lt;P&gt;Anders,&lt;/P&gt;&lt;P&gt;When you supply code examples, please use the {...} code button to paste the text of the source code (select as Fortran format from the pull-down).&lt;/P&gt;&lt;P&gt;Pasting a screenshot makes it difficult for the readers to test your code.&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
    <pubDate>Wed, 18 Mar 2020 15:13:36 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2020-03-18T15:13:36Z</dc:date>
    <item>
      <title>Allocatable arrays of derived types</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143600#M137898</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to define a derived type PM consisting of an integer array ng(n1,n2) and a double vector zg(n3).&lt;/P&gt;&lt;P&gt;I wrote&lt;/P&gt;&lt;P&gt;:TYPE PM&lt;/P&gt;&lt;P&gt;INTEGER,ALLOCATABLE::ng(:,:)&lt;/P&gt;&lt;P&gt;DOUBLE PRECISION,ALLOCATABLE::zg(:)&lt;/P&gt;&lt;P&gt;END TYPE PM&lt;/P&gt;&lt;P&gt;n1, n2 and n3 are defined run time.&lt;/P&gt;&lt;P&gt;Then I finally want to allocate an array PMA&amp;nbsp; &amp;nbsp;with n4 of PM derived types.&amp;nbsp;&lt;/P&gt;&lt;P&gt;n4 is defined at run time.&lt;/P&gt;&lt;P&gt;How do I allocate PM and PMA?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Anders S&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:53:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143600#M137898</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-17T20:53:18Z</dc:date>
    </item>
    <item>
      <title>You can't allocate PM, it's a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143601#M137899</link>
      <description>&lt;P&gt;You can't allocate PM, it's a type.&lt;/P&gt;&lt;P&gt;First you allocate PMA:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;type(PM), allocatable :: PMA(:)
...
allocate (PMA(n4))&lt;/PRE&gt;

&lt;P&gt;This doesn't allocate the ng and zg components of each element - you'll need to loop through the elements of PMA and allocate those separately, if desired.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 21:09:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143601#M137899</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2020-03-17T21:09:12Z</dc:date>
    </item>
    <item>
      <title>Hi Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143602#M137900</link>
      <description>&lt;P&gt;Hi Steve,&lt;/P&gt;&lt;P&gt;Thanks a lot for your rapid and precise answer!&lt;/P&gt;&lt;P&gt;I coded and compiled your suggestions and they passed with no compile error.&lt;/P&gt;&lt;P&gt;I have attached my code just for documentation reasons.&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Anders S&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 21:57:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143602#M137900</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-17T21:57:32Z</dc:date>
    </item>
    <item>
      <title>Looks good.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143603#M137901</link>
      <description>&lt;P&gt;Looks good. Note that when you deallocate PMA, all the subcomponents get deallocated automatically.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 23:19:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143603#M137901</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2020-03-17T23:19:00Z</dc:date>
    </item>
    <item>
      <title>Hi,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143605#M137903</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It may be interesting to use the derived type PMA as a subroutine argument. I have checked this in various sources but&lt;/P&gt;&lt;P&gt;did not find any "clear advice". I made a "best effort guess" in the supplied code but I know it is wrong. I would be most&amp;nbsp;grateful to have this&lt;/P&gt;&lt;P&gt;matter clarified. Is there any best practice when it comes to defining derived types, e.g. using modules?&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Anders S&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 08:37:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143605#M137903</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-18T08:37:47Z</dc:date>
    </item>
    <item>
      <title>Quote:Anders S. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143606#M137904</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Anders S. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.. I have checked this in various sources but&amp;nbsp;did not find any "clear advice". ..&amp;nbsp;Is there any best practice when it comes to defining derived types, e.g. using modules?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Re: sources, have you looked at these?&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.amazon.com/FORTRAN-SCIENTISTS-ENGINEERS-Stephen-Chapman/dp/0073385891" target="_blank"&gt;https://www.amazon.com/FORTRAN-SCIENTISTS-ENGINEERS-Stephen-Chapman/dp/0073385891&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.amazon.com/Modern-Fortran-Style-Norman-Clerman/dp/052173052X" target="_blank"&gt;https://www.amazon.com/Modern-Fortran-Style-Norman-Clerman/dp/052173052X&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 12:17:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143606#M137904</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2020-03-18T12:17:35Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;INTEGER ERRINTEGER,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143607#M137905</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;&lt;BR /&gt;INTEGER ERR&lt;BR /&gt;INTEGER, ALLOCATABLE :: A(:), B(:)&lt;BR /&gt;...&lt;BR /&gt;ALLOCATE(A(10:25), B(SIZE(A)), STAT=ERR)&amp;nbsp; ! A is invalid as an argument to function SIZE&lt;BR /&gt;&amp;lt;&amp;lt;&lt;/P&gt;&lt;P&gt;As to which of A or B is allocated first, it is ambiguous at least to use SIZE(A) in this case. I think that the error message in the compiler version that you are using is inadequate. In Version 2020&lt;/P&gt;&lt;P&gt;error #6500: A bound in an allocate-shape-spec involves array inquiry about allocate-object in same ALLOCATE statement.&amp;nbsp;&amp;nbsp; &lt;A&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 15:08:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143607#M137905</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-03-18T15:08:59Z</dc:date>
    </item>
    <item>
      <title>Anders,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143608#M137906</link>
      <description>&lt;P&gt;Anders,&lt;/P&gt;&lt;P&gt;When you supply code examples, please use the {...} code button to paste the text of the source code (select as Fortran format from the pull-down).&lt;/P&gt;&lt;P&gt;Pasting a screenshot makes it difficult for the readers to test your code.&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 15:13:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143608#M137906</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-03-18T15:13:36Z</dc:date>
    </item>
    <item>
      <title>Hi,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143609#M137907</link>
      <description>&lt;PRE class="brush:fortran; class-name:dark;"&gt;PROGRAM test
IMPLICIT NONE
INTEGER i,n1,n2,n3,n4
TYPE PM
  INTEGER,ALLOCATABLE::ng(:,:)
  DOUBLE PRECISION,ALLOCATABLE::zg(:)
END TYPE PM
Type(PM),ALLOCATABLE::PMA(:)
n1=20
n2=2
n3=1000
n4=5
ALLOCATE(PMA(n4))
DO i=1,n4
  ALLOCATE(PMA(i)%ng(n1,n2))
  ALLOCATE(PMA(i)%zg(n3))
ENDDO
PMA(1)%zg(1)=3.14D0
CALL sub(PMA)
DEALLOCATE(PMA)
STOP
END
!------------------------------------------
SUBROUTINE sub(n1,n2,n3,n4,PMA)
IMPLICIT NONE
INTEGER,INTENT(IN)::n1,n2,n3,n4
TYPE PM
  INTEGER ng(n1,n2)
  DOUBLE PRECISION zg(n3)
END TYPE PM
TYPE(PM),DIMENSION(n4)::PMA
PRINT *,PMA(1)%zg(1)
RETURN
END&lt;/PRE&gt;

&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;FortranFan:&lt;/P&gt;
&lt;P&gt;Which of the books do you prefer?&lt;/P&gt;
&lt;P&gt;Jim:&lt;/P&gt;
&lt;P&gt;Sorry for my screen copy!&amp;nbsp; I have now supplied the code example in the right format.&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;
&lt;P&gt;Anders S&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 15:47:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143609#M137907</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-18T15:47:36Z</dc:date>
    </item>
    <item>
      <title>Quote:Anders S. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143610#M137908</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Anders S. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;FortranFan:&lt;/P&gt;&lt;P&gt;Which of the books do you prefer? ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Anders S.,&lt;/P&gt;&lt;P&gt;I recommend&amp;nbsp;both of above books.&amp;nbsp; I strongly recommend you get the first book by Stephen Chapman and go through it fully &lt;STRONG&gt;first&lt;/STRONG&gt;.&amp;nbsp; You can also consider a couple of other books but my suggestion will be to look at these after reviewing the book by Chapman:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.amazon.com/Modern-Fortran-Explained-Incorporating-Mathematics/dp/0198811896/ref=dp_ob_title_bk" target="_blank"&gt;https://www.amazon.com/Modern-Fortran-Explained-Incorporating-Mathematics/dp/0198811896/ref=dp_ob_title_bk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.amazon.com/Numerical-Computing-Fortran-Applied-Mathematics/dp/1611973112" target="_blank"&gt;https://www.amazon.com/Numerical-Computing-Fortran-Applied-Mathematics/dp/1611973112&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here's another reference:&lt;/P&gt;&lt;P&gt;&lt;A href="http://fortranwiki.org/fortran/show/HomePage" target="_blank"&gt;http://fortranwiki.org/fortran/show/HomePage&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 16:25:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143610#M137908</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2020-03-18T16:25:51Z</dc:date>
    </item>
    <item>
      <title>You have an error in your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143611#M137909</link>
      <description>&lt;P&gt;You have an error in your programming:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;...
CALL sub(PMA) !  *** 1 argument
...
SUBROUTINE sub(n1,n2,n3,n4,PMA) ! *** 5 arguments
&lt;/PRE&gt;

&lt;P&gt;If you select the compile time check to generate and warn for interface mismatch you will receive a warning&lt;/P&gt;
&lt;P&gt;Additionally:&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;SUBROUTINE sub(n1,n2,n3,n4,PMA)
IMPLICIT NONE
INTEGER,INTENT(IN)::n1,n2,n3,n4
TYPE PM
  INTEGER ng(n1,n2)
  DOUBLE PRECISION zg(n3)
END TYPE PM
&lt;/PRE&gt;

&lt;P&gt;Your type PM, as written, cannot use an undefined value for the array dimension values (not defined until run time).&lt;/P&gt;
&lt;P&gt;While (after fixing arguments) you could possibly use a Parameterized Derive-Type Statement:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-parameterized-type-statements" target="_blank"&gt;https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-parameterized-type-statements&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;In your situation it is not recommended. Something like the following could be used:&lt;/P&gt;

&lt;PRE class="brush:fortran; class-name:dark;"&gt;MODULE YourModuleName
    TYPE PM
      INTEGER,ALLOCATABLE::ng(:,:)
      DOUBLE PRECISION,ALLOCATABLE::zg(:)
    END TYPE PM
    contains
    SUBROUTINE sub(PMA)
        IMPLICIT NONE
        TYPE(PM), DIMENSION(:), ALLOCATABLE, INTENT(IN)::PMA
        ! following assunmes (requires) PMA is allocated, has index including 1, PMA(1)%zg is allocated and has index of 1
        ! place tests and error actions here
        
        PRINT *,PMA(1)%zg(1)
    END SUBROUTINE sub
END MODULE YourModuleName
    
PROGRAM test
    USE YourModuleName
    IMPLICIT NONE
    INTEGER i,n1,n2,n3,n4
    Type(PM),ALLOCATABLE::PMA(:)
    
    n1=20
    n2=2
    n3=1000
    n4=5
    ALLOCATE(PMA(n4))
    DO i=1,n4
      ALLOCATE(PMA(i)%ng(n1,n2))
      ALLOCATE(PMA(i)%zg(n3))
    ENDDO
    PMA(1)%zg(1)=3.14D0
    CALL sub(PMA)
    DEALLOCATE(PMA)
END PROGRAM test&lt;/PRE&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 17:59:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143611#M137909</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-03-18T17:59:19Z</dc:date>
    </item>
    <item>
      <title>Hi Jim,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143612#M137910</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;Thank you for your rapid and complete answer!&lt;/P&gt;&lt;P&gt;I had meanwhile searched the web and found a very similar problem and&lt;/P&gt;&lt;P&gt;rewritten the code, which resembled your answer. After a few corrections by looking&lt;/P&gt;&lt;P&gt;at your code, I arrived at the code below. I want to move the subroutine sub outside&lt;/P&gt;&lt;P&gt;the module as sub in the real case is a few hundred lines long. Compilation gives one error&lt;/P&gt;&lt;P&gt;which I have depicted. The error maybe come from moving sub outside the module?&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Anders S&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;MODULE PMd
  TYPE PM
    INTEGER,ALLOCATABLE::ng(:,:)
    DOUBLE PRECISION,ALLOCATABLE::zg(:)
  END TYPE PM
END MODULE PMd
!----------------------------------------------------------
PROGRAM test
USE PMd
IMPLICIT NONE
INTEGER i,n1,n2,n3,n4
TYPE(PM),ALLOCATABLE::PMA(:)

INTERFACE
  SUBROUTINE sub(PMA)
  USE PMd
  TYPE(PM) PMA
  END SUBROUTINE sub
END INTERFACE

n1=20; n2=2; n3=1000; n4=5
ALLOCATE(PMA(n4))
DO i=1,n4
  ALLOCATE(PMA(i)%ng(n1,n2));  ALLOCATE(PMA(i)%zg(n3))
ENDDO
PMA(1)%zg(1)=3.14D0
CALL sub(PMA)  &amp;lt;--------------------------------------error #6634
DEALLOCATE(PMA)
STOP
END PROGRAM test
!------------------------------------------------------------
SUBROUTINE sub(PMA)
USE PMd
IMPLICIT NONE
TYPE(PM),DIMENSION(:),ALLOCATABLE,INTENT(IN)::PMA
PRINT *,PMA(1)%zg(1)
RETURN
END SUBROUTINE sub

test.f90(27): error #6634: The shape matching rules of actual arguments
and dummy arguments have been violated.   [PMA]
pmd.mod : \&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 18:54:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143612#M137910</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-18T18:54:43Z</dc:date>
    </item>
    <item>
      <title>The following has error</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143613#M137911</link>
      <description>&lt;P&gt;The following has error actions:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;MODULE YourModuleName
    TYPE PM
      INTEGER,ALLOCATABLE::ng(:,:)
      DOUBLE PRECISION,ALLOCATABLE::zg(:)
    END TYPE PM
    contains
    SUBROUTINE sub(PMA)
        IMPLICIT NONE
        TYPE(PM), DIMENSION(:), ALLOCATABLE, INTENT(IN)::PMA
        if(.not. allocated(PMA)) then
            print *,"PMA not allocated"
            return
        endif
        if(size(PMA) &amp;lt; 1) then
            print *,"PMA must have size &amp;gt;= 1"
            return
        endif
        if((lbound(PMA,DIM=1) &amp;gt; 1) .or. (ubound(PMA,DIM=1) &amp;lt; 1)) then
            print *,"PMA(1) does not exist"
            return
        endif
        if(.not. allocated(PMA(1)%zg)) then
            print *,"PMA(1)%zg not allocated"
            return
        endif
        if(size(PMA(1)%zg) &amp;lt; 1) then
            print *,"PMA(1)%zg must have size &amp;gt;= 1"
            return
        endif
        if((lbound(PMA(1)%zg,DIM=1) &amp;gt; 1) .or. (ubound(PMA(1)%zg,DIM=1) &amp;lt; 1)) then
            print *,"PMA(1)%zg(1) does not exist"
            return
        endif
        
        PRINT *,PMA(1)%zg(1)
    END SUBROUTINE sub
END MODULE YourModuleName
    
PROGRAM test
    USE YourModuleName
    IMPLICIT NONE
    INTEGER i,n1,n2,n3,n4
    Type(PM),ALLOCATABLE::PMA(:)
    
    n1=20
    n2=2
    n3=1000
    n4=5
    ALLOCATE(PMA(n4))
    DO i=1,n4
      ALLOCATE(PMA(i)%ng(n1,n2))
      ALLOCATE(PMA(i)%zg(n3))
    ENDDO
    PMA(1)%zg(1)=3.14D0
    CALL sub(PMA)
    DEALLOCATE(PMA)
    CALL sub(PMA)   ! "PMA not allocated"
    ALLOCATE(PMA(0))
    CALL sub(PMA)   ! "PMA must have size &amp;gt;= 1"
    DEALLOCATE(PMA)
    ALLOCATE(PMA(2:3))
    CALL sub(PMA)   ! "PMA(1) does not exist"
    DEALLOCATE(PMA)
    ALLOCATE(PMA(4))
    CALL sub(PMA)   ! "PMA(1)%zg not allocated"
    ALLOCATE(PMA(1)%zg(0))
    CALL sub(PMA)   ! "PMA(1)%zg must have size &amp;gt;= 1"
    DEALLOCATE(PMA(1)%zg)
    ALLOCATE(PMA(1)%zg(2:3))
    CALL sub(PMA)   ! "PMA(1)%zg(1) does not exist"
    DEALLOCATE(PMA)
END PROGRAM test&lt;/PRE&gt;

&lt;P&gt;For an unexplained reason I had to include ",DIM=1" on the lbound and ubound intrinsic functions.&lt;/P&gt;
&lt;P&gt;Steve L, perhaps you can shed light on this requirement. DIM=1 should have been implicit&lt;/P&gt;
&lt;P&gt;Anders,&lt;/P&gt;
&lt;P&gt;Note that sub requires PMA to be an allocatable&amp;nbsp; array. There would be an issue if your code requires sub to be called with a non-allocatable array as well as allocatable. I will let you address this issue.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 18:56:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143613#M137911</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-03-18T18:56:00Z</dc:date>
    </item>
    <item>
      <title>Hi Jim,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143614#M137912</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;PMA will always be allocatable in order to adjust to the actual dimensions of the problem, e.g. the number of subgroups when&lt;/P&gt;&lt;P&gt;the MPI communicator has been split.&lt;/P&gt;&lt;P&gt;Hi FortranFan,&lt;/P&gt;&lt;P&gt;Thanks again for your advice. I have found that working on a physical problem, physics, mathematics and numerics takes a lot of&lt;/P&gt;&lt;P&gt;gunpowder leading to little left to dive in writing nice code that use all functionality of Fortran. I guess you have already noticed&amp;nbsp;that...&lt;/P&gt;&lt;P&gt;Therefore, the IDZ support is invaluable!&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Anders S&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 19:08:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143614#M137912</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-18T19:08:43Z</dc:date>
    </item>
    <item>
      <title>In your post #13, line 17 or</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143615#M137913</link>
      <description>&lt;P&gt;In your post #13, line 17 or the interface to SUB states PMA is a scalar (single) as opposed to an array.&lt;/P&gt;&lt;P&gt;Further, it is bad practice to place the INTERFACE in the caller's code as opposed to the preferred location of being in a MODULE. Locating the interface within a module reduces potential errors later as interface checking is always assured.&lt;/P&gt;&lt;P&gt;Jim Demspey&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 20:12:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143615#M137913</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-03-18T20:12:56Z</dc:date>
    </item>
    <item>
      <title>Hi Jim,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143616#M137914</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;I think with your final comment I have got my problem solved!&lt;/P&gt;&lt;P&gt;Thanks all contributors!&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Anders S&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 20:40:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143616#M137914</guid>
      <dc:creator>Anders_S_1</dc:creator>
      <dc:date>2020-03-18T20:40:20Z</dc:date>
    </item>
    <item>
      <title>when mecej4 set up the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143604#M137902</link>
      <description>&lt;P&gt;when mecej4 set up the allocatable in MAGNI -- he used stat=err?&amp;nbsp; Is this still a good idea?&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;INTEGER ERR
INTEGER, ALLOCATABLE :: A(:), B(:)
...
ALLOCATE(A(10:25), B(SIZE(A)), STAT=ERR)  ! A is invalid as an argument to function SIZE&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 00:20:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-arrays-of-derived-types/m-p/1143604#M137902</guid>
      <dc:creator>JohnNichols</dc:creator>
      <dc:date>2020-03-18T00:20:13Z</dc:date>
    </item>
  </channel>
</rss>

