<?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 It was totally my bad. Thank in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939793#M89693</link>
    <description>It was totally my bad. Thank you very much, mecej4.</description>
    <pubDate>Thu, 01 Nov 2012 17:03:51 GMT</pubDate>
    <dc:creator>sang186</dc:creator>
    <dc:date>2012-11-01T17:03:51Z</dc:date>
    <item>
      <title>Re-size array within a subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939788#M89688</link>
      <description>&lt;P&gt;I am trying to implement a push_back routine as below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SUBROUTINE push_back(array, val)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INTEGER,DIMENSION(:), ALLOCATABLE :: tmp_arr&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INTEGER, DIMENSION(:) :: array&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INTEGER val&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ALLOCATE(tmp_arr(0 : SIZE(array)))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; tmp_arr(0:(SIZE(array)-1))=array&lt;BR /&gt;&amp;nbsp; &amp;nbsp; tmp_arr(SIZE(array)) = val&lt;BR /&gt;&amp;nbsp; &amp;nbsp; DEALLOCATE(array) &lt;BR /&gt;&amp;nbsp; &amp;nbsp; ALLOCATE(array(0:SIZE(tmp_arr)-1))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CALL move_alloc(tmp_arr, array) &lt;BR /&gt;END SUBROUTINE push_back&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On resizing an allocatable array (declared ALLOCATABLE in the calling subroutine) , I get the following compile errors&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;error #6724: An allocate/deallocate object must have the ALLOCATABLE or POINTER attribute. [ARRAY]&lt;/LI&gt;
&lt;LI&gt;error #8195: The argument to the MOVE_ALLOC intrinsic subroutine shall be an allocatable object. [MOVE_ALLOC]&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I want the resize to work such that the data that is passed is not lost. However, by making array ALLOCATABLE within the subroutine , I would lose the existing data.&lt;BR /&gt;Any help with this would be great.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2012 16:23:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939788#M89688</guid>
      <dc:creator>sang186</dc:creator>
      <dc:date>2012-11-01T16:23:15Z</dc:date>
    </item>
    <item>
      <title>INTEGER, DIMENSION(:),</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939789#M89689</link>
      <description>INTEGER, DIMENSION(:), ALLOCATABLE :: array

you forgot to tell the compiler that "array" was also allocatable.
Les</description>
      <pubDate>Thu, 01 Nov 2012 16:30:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939789#M89689</guid>
      <dc:creator>Les_Neilson</dc:creator>
      <dc:date>2012-11-01T16:30:15Z</dc:date>
    </item>
    <item>
      <title>Is this something that you</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939790#M89690</link>
      <description>Is this something that you want to reach?

SUBROUTINE UTIL_ADDTO_ARRAYint2Allocarray(ToBeAdded,IntegerArray) !{
  !   This subroutine adds a single value to the end of an integer array.
  IMPLICIT NONE
  !** HEADER VARIABLES/ARGUMENTS
  INTEGER, INTENT(IN)  ::ToBeAdded
  INTEGER, ALLOCATABLE     ::IntegerArray(:)
  !*****************************************************************************
      !** LOCAL VARIABLES
      INTEGER          ::NewSize
      INTEGER          ::OldSize
      INTEGER, ALLOCATABLE ::CopyArray(:)
      !*************************************************************************
      
      IF (allocated(IntegerArray)) THEN
        OldSize=size(IntegerArray)
        NewSize = OldSize + 1
        ALLOCATE(CopyArray(NewSize))
        CALL MOVE_ALLOC(CopyArray, IntegerArray)
        IntegerArray(NewSize) = ToBeAdded
      ELSE
        ALLOCATE(IntegerArray(1))
        IntegerArray(1)=ToBeAdded
      ENDIF
      
  ENDSUBROUTINE UTIL_ADDTO_ARRAYint2Allocarray !}

Making the array allocatable within the subroutine does not lose your data.

regards,
Dirk</description>
      <pubDate>Thu, 01 Nov 2012 16:33:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939790#M89690</guid>
      <dc:creator>A__Valle</dc:creator>
      <dc:date>2012-11-01T16:33:29Z</dc:date>
    </item>
    <item>
      <title>On making array  'ALLOCATABLE</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939791#M89691</link>
      <description>On making array  'ALLOCATABLE ' with 

INTEGER, DIMENSION(:), ALLOCATABLE :: array

I would lose its existing allocation and its data and I would like to retain that.</description>
      <pubDate>Thu, 01 Nov 2012 16:36:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939791#M89691</guid>
      <dc:creator>sang186</dc:creator>
      <dc:date>2012-11-01T16:36:29Z</dc:date>
    </item>
    <item>
      <title>Sorry, It was my bad.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939792#M89692</link>
      <description>Sorry, It was my bad. 

I had overlooked the allocation of the array with a zero index in the calling function . It works now. 
@Les &amp;amp; @Dirk  - Thank you very much for the inputs.

Sangeetha</description>
      <pubDate>Thu, 01 Nov 2012 17:00:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939792#M89692</guid>
      <dc:creator>sang186</dc:creator>
      <dc:date>2012-11-01T17:00:10Z</dc:date>
    </item>
    <item>
      <title>It was totally my bad. Thank</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939793#M89693</link>
      <description>It was totally my bad. Thank you very much, mecej4.</description>
      <pubDate>Thu, 01 Nov 2012 17:03:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939793#M89693</guid>
      <dc:creator>sang186</dc:creator>
      <dc:date>2012-11-01T17:03:51Z</dc:date>
    </item>
    <item>
      <title>Merely declaring an argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939794#M89694</link>
      <description>Merely declaring an argument array to be ALLOCATABLE does not change its allocation status or contents.

The following program works fine
[fortran]
program tpush
IMPLICIT NONE
INTEGER, DIMENSION(:), ALLOCATABLE :: ivec
INTEGER :: val=4
ALLOCATE(ivec(3))
ivec=(/1,2,3/)
call push_back(ivec, val)
write(*,'(10I4)')ivec

contains
SUBROUTINE push_back(array, val)
    INTEGER,DIMENSION(:), ALLOCATABLE :: tmp_arr
    INTEGER, DIMENSION(:),ALLOCATABLE :: array
    INTEGER val
    ALLOCATE(tmp_arr(0 : SIZE(array)))
    tmp_arr(0:(SIZE(array)-1))=array
    tmp_arr(SIZE(array)) = val
    DEALLOCATE(array)
    ALLOCATE(array(0:SIZE(tmp_arr)-1))
    CALL move_alloc(tmp_arr, array)
END SUBROUTINE push_back
END PROGRAM tpush
[/fortran]

The program prints out

[bash]   1   2   3   4[/bash]
[&lt;I&gt;Complaints re ISDN forum software: (i) The program source code above appears single-spaced in edit mode, but appears mostly double spaced in browse mode; (ii) It is confusing when the OP replies to other people's responses and there are no response numbers to provide information on which response is being replied to .&lt;/I&gt;]</description>
      <pubDate>Thu, 01 Nov 2012 18:12:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939794#M89694</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2012-11-01T18:12:29Z</dc:date>
    </item>
    <item>
      <title>That's ok - we all make</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939795#M89695</link>
      <description>That's ok - we all make mistakes. Glad it now works
Les</description>
      <pubDate>Fri, 02 Nov 2012 07:58:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Re-size-array-within-a-subroutine/m-p/939795#M89695</guid>
      <dc:creator>Les_Neilson</dc:creator>
      <dc:date>2012-11-02T07:58:15Z</dc:date>
    </item>
  </channel>
</rss>

