Take the 2-minute tour ×

Is it possible to pass real part of a complex array to a subroutine in Fortran without storing the real part in another array and pass that? e.g. instead of

Z = complex array;

X = real(Z)

call foo(X)

Do the following

Z = complex array

call foo(real(Z))

This gives me a compiler error! I am using an intel compiler ifort.

share|improve this question
As per Bálint Aradi's answer, yes, this is allowed. The compiler error is likely coming from somewhere else. Please update your question with the compiler error, version, and minimal (actual code) example. –  milancurcic Feb 24 '13 at 16:37
It may also depend on your procedure foo, maybe you use some features that require an explicit interface and don't provide one or there may be some other kind of programming error. Without more code and the error message this question is unanswerable. –  Vladimir F Feb 24 '13 at 18:58

1 Answer 1

Sure, it works:

module testmod
  implicit none

  integer, parameter :: dp = kind(1.0d0)


  subroutine realsub(array)
    real(dp), intent(in) :: array(:)
    print *, array
  end subroutine realsub

end module testmod

program testprog
  use testmod
  implicit none

  complex(dp) :: array(3)

  array(:) = [ (1.0_dp, 1.0_dp), (3.0_dp, 2.0_dp), (-1.0_dp, 3.0_dp) ]
  call realsub(real(array))

end program testprog
share|improve this answer

Your Answer


