title: fortran pass allocated array to main procedure
body: <p>I have a module with a function which takes a starting and ending point and reads in a <code>.txt</code> some float value. 
  I wish that function to return a table which I do not know how large it will be before it starts.</p>
  
  <p>I wish to use this function twice in the main program to make a third real array. But Fortran doesn't like it much.</p>
  
  <p>Here is my code for the function :</p>
  
  <pre><code>module ReadData
      !in this part, you need to know :
  !       -the starting (cannot be the first or second point)
  !       -end point
  !       -the file name (here : cham/comp or flow)
  !               change line 40 in case it is not AL026_Pd anymore
  !       -where it is on the file
      implicit none
  
      INTERFACE ReadP
          MODULE PROCEDURE ReadDataPressure
      END INTERFACE
  
      private :: ReadDataPressure
  
      contains
  
      function ReadDataPressure (whereabout,StartingPoint,EndingPoint) result (P1)
          !**********************
          !**decla in variables**
          character(50) :: whereabout !needed : cham/comp or flow
          real(8)       :: StartingPoint,EndingPoint
  
          !************************
          !**decla used variables**
          character(50) :: FileNameConstructed
          real(8)       :: deltat,CurrentTime,pressure
          integer(8)    :: i,k
  
          !**********************
          !**decla out variable**
          real(8),allocatable :: P1(:)
  
          !start of the programe itself
          write (FileNameConstructed,'(a,a,a)') "AL026_pd",whereabout,".txt"
          open(20,file=FileNameConstructed,status='old',action='read')
  
          read (20,*) deltat,pressure
          read (20,*) CurrentTime,pressure
          deltat=CurrentTime-deltat
          !now deltaT is the loop counter, but we "lost" two usable line in the process
          allocate (P1(1:int(((EndingPoint-StartingPoint)/deltat+1))))
  
          k=1
          do i=0,int((EndingPoint-2*deltat)/deltat)
              read (20,*) CurrentTime,pressure
              if (CurrentTime&gt;StartingPoint) then
                  P1(k)=pressure
                  k=k+1
                  write(*,*) p1(k)
              end if
          end do
      end function ReadDataPressure
  End module
  </code></pre>
  
  <p>and I wish to do something like this in the main program</p>
  
  <pre><code>a=ReadP(comp,350,750)
  b=ReadP(flow,350,750)
  do i=1; lenght_of_a
      m_ox(i)=squarreroot(a(i)-b(i))
  end do
  </code></pre>
  
  <p>end then write it in another file.</p>
  
  <p>I found : <a href="https://stackoverflow.com/questions/18402775/share-allocatable-arrays?newreg=21138513cfb24af3acd32a62c3107893">Share allocatable Arrays</a><br>
  <a href="https://stackoverflow.com/questions/22169365/fortran-allocatable-array-in-subroutine">FORTRAN - allocatable array in subroutine</a></p>
  
  <p>but they did not help me.</p>
  
  <p>One thinks perhaps 
  <a href="http://www.stanford.edu/class/me200c/tutorial_90/09_modules.html" rel="nofollow noreferrer">http://www.stanford.edu/class/me200c/tutorial_90/09_modules.html</a>
  is closer to the solution.</p>
  
  <p>But they don't want a table at the end, they use <code>Prod_A = PRODUCT(A)</code> so you do not know the dimension of <code>a</code>, but can do product or sum. But I want to keep it whole.</p>