title: Fortran pass an array to function
body: <p>I am trying to pass an array of unknown length to a function. I would also prefer the indices of a is the same as b. Is this possible?</p>
  
  <p>The program compiles but does run through the function.</p>
  
  <p>Any help would be appreciated.</p>
  
  <pre><code> function RealCumSum(i) result(j)
      real, dimension(1:), intent(in)  :: i ! input
      real, dimension(size(i)) :: j ! output
      integer :: m
  
      do m = 1,size(i)
          j(m) = sum(i(1:m))
      end do
  
   end function RealCumSum
  
   program xfunc
      implicit none
      real, dimension(2) :: a = (/ 3.2 , 2.5 /)
      real, dimension(2) :: b, RealCumSum
  
      b = RealCumSum(a)
  
      write(*,*) "cumulative sum of ",a," is ", b
   end program xfunc
  </code></pre>