SHARE
TWEET

fortran spread code

a guest Sep 12th, 2013 104 Never
  1. program sandbox
  2.     implicit none
  3.     real, dimension(2, 2) :: p
  4.     real, dimension(:, :), allocatable :: q
  5.     integer i, n
  6.  
  7.     n = 3
  8.     allocate(q(2, 2*n))
  9.  
  10.     print *, "p"
  11.     p = reshape([1, 3, 2, 4], shape(p))
  12.     do i=1, 2
  13.         print *, p(i, :)
  14.     end do
  15.  
  16.     print *, "spread"
  17.     q = reshape(spread(transpose(p), 2, n), [2, 2*n], order=[2, 1])
  18.     do i=1, 2
  19.         print *, q(i, :)
  20.     end do
  21.     deallocate(q)
  22. end program sandbox
RAW Paste Data
Top