title: Fortran: combine allocatable vectors in an array without copying and reshaping
body: <p>How can one combine bunch of large allocatable vectors in an array in Fortran? I'd like to avoid copying and reshaping using <code>reshape</code> as the arrays are <em>large</em>. The effect I want to achieve is just like Fortran's <code>equivalence</code>, to illustrate:</p>
  
  <pre><code>program test_equiv
      integer x(10), y(10), z(10), xyz(10,3)
      equivalence (x, xyz(1,1))
      equivalence (y, xyz(1,2))
      equivalence (z, xyz(1,3))
  
      x = 1
      y = 2
      z = 3
  
  ! and we can use just normal array syntax
      print *, xyz(3,:)
  end program
  </code></pre>
  
  <p>This will, however, not work with allocatable arrays. If it's about accessing vectors of matrix it can be easily implemented via pointers. But how can one combine vectors in a two dimensional array? Till now I came only to array of pointers which has problems:</p>
  
  <pre><code>program test_arofpntrs
  implicit none
  
  integer :: i
  integer, allocatable, target :: xs(:), ys(:), zs(:)
  
  type t_p_xs
    integer, pointer :: p_xs(:)
  end type t_p_xs
  
  type(t_p_xs), allocatable :: coords(:)
  
  allocate(coords(3), xs(10), ys(10), zs(10))
  
  xs = 1
  ys = 2
  zs = 3
  
  
  coords(1) % p_xs =&gt; xs
  coords(2) % p_xs =&gt; ys
  coords(3) % p_xs =&gt; zs
  
  print *, coords(1) % p_xs(:)
  
  ! this fails:
  !print *, coords(:) % p_xs(1)
  
  
  end program
  </code></pre>
  
  <p>This is ugly and one cannot access xs(i), ys(i), zs(i). Is it possible to do what I want without copies?</p>