Slicing value returned from function

Alberto Luaces aluaces@udc.es
Mon May 12 10:48:00 GMT 2014


Hi,

is it possible to get only certain elements returned from a function?  I
have not been able to do so,

vec3 = matmul(m, v)(1:3)

but it seems to work implicitly when passing that value as an argument
to a different function:

--8<---------------cut here---------------start------------->8---
subroutine printv(v)
  implicit none
  integer, dimension(3), intent(in):: v

  print *, v
end subroutine printv

program name
  implicit none
  integer, dimension(4,4):: m
  integer, dimension(4):: v

  v=[1, 1, 1, 1]
  m=reshape([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [4, 4])

  call printv(matmul(m, v)) ! This takes only the first three elements

end program name
--8<---------------cut here---------------end--------------->8---

Thanks,

-- 
Alberto



More information about the Fortran mailing list