title: Fortran 90 - "Segmentation fault - invalid memory reference" with scalable 3D array
body: <p>I have compiled a fortran 90 program with gfortran which builds a scalable 3D array in a way I want. Upon running, I get the following error:</p>
  
  <pre><code>Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
  
  Backtrace for this error:
  #0  0x10542ee42
  #1  0x10542f60e
  #2  0x7fff8d7895a9
  #3  0x10542575e
  #4  0x105425975
  #5  0x105425d0e
  Segmentation fault: 11
  </code></pre>
  
  <p>I believe this is a memory issue with the large 3D array, as it works if I decrease the dimensions, but is there anyway to get around this? Here is my code:</p>
  
  <pre><code>PROGRAM phantomtest
  IMPLICIT NONE
    INTEGER, PARAMETER:: columns=34, rows=34, diags=((4*columns)-6),  m=(4*columns)-6+(2*columns)
    REAL, ALLOCATABLE, DIMENSION(:,:,:)::phantom
    INTEGER :: i, j, k
    CHARACTER (LEN=3) :: nstring, nullstring=''
  
  ALLOCATE(phantom(columns,rows,m))
  phantom=0
  
  CALL Phantom_Making(phantom,columns,rows,diags,m)
  
  WRITE(nstring,FMT="(I3)"), columns
  PRINT*, nullstring
  DO k=1,m
    DO i=1,columns
      WRITE(*,FMT="("//nstring//"I2)") phantom(i,:,k)
    END DO
    PRINT *, nullstring
  END DO
  
  END PROGRAM phantomtest
  !---------------------------
  SUBROUTINE Phantom_Making(phantom,columns,rows,diags,m)
  IMPLICIT NONE
    INTEGER, INTENT(IN):: columns, rows, diags, m
    REAL, DIMENSION(columns,rows,m), INTENT(INOUT) :: phantom
    INTEGER :: i, j, k, l
  
  !Vertical and horizontal rays
  DO i=1,rows
    phantom(:,i,i) = 1
    phantom(i,:,i+(columns)+(diags/2)) = 1
  END DO
  
  !Diagonal rays
  phantom(1,2,1+columns) = 1
  phantom(2,1,1+columns) = 1
  phantom(1,columns-1,1+columns+(diags/2)+rows) = 1
  phantom(2,columns,1+columns+(diags/2)+rows) = 1
  j = columns-1
  
  DO k=2+columns, (diags/2)+columns
    phantom(2:columns,:,k) = phantom(1:(columns-1),:,k-1)
    IF (((k+1)-columns).LE.columns) phantom(1,k+1-columns,k)=1
  END DO
  
  DO l=columns+(diags/2)+rows+2, columns+(diags/2)+rows+1+(diags/2)
    j = j-1
    phantom(2:columns,:,l) = phantom(1:(columns-1),:,l-1)
    IF (j.GT.0) phantom(1,j,l) = 1
  END DO
  
  END SUBROUTINE
  </code></pre>