Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran complex array assignment

  1. Apr 2, 2012 #1
    I have a an array of type complex. I am trying to assign a value to it in a loop, but I get a strange error "Unclassifiable statement at (1)". I really don't understand why.

    Code (Text):

    do t = 1, count
       real(in(t)) = cos(2 * pi * f0 * t)
       aimag(in(t))=sin(2 * pi * f0 * t)
    end do
     
    thanks.
     
  2. jcsd
  3. Apr 2, 2012 #2

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    The real() and imag() just return values, like all other Fortran functions. You can't use them to change the real or imaginary part of a complex number.

    This should work:
    Code (Text):

    do t = 1, count
      in(t) = ( cos(2 * pi * f0 * t) , sin(2 * pi * f0 * t) )
    enddo
     
     
  4. Apr 18, 2012 #3
    sorry for late reply.
    But unfortunately it doesn't work. Even in the following simple code:
    Code (Text):

    program test
      implicit none
      integer::t
      complex::in(4)
      do t = 1, 4
         in(t) = ( 2*t, 3*3 )
      end do
    end program test
     
    gfortran gives the following result:

    Code (Text):

    test.f95:6.18:

         in(t) = ( 2*t, 3*3 )
                         1
    Error: Expected a right parenthesis in expression at (1)
     
    any ideas?
     
  5. Apr 18, 2012 #4

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    Try in(t) = cmplx( 2*t, 3*3 )

    in(t) = (1.0, 2.0) should work for a constant value. Maybe it doesn't work for expressions.
     
  6. Apr 19, 2012 #5
    Yes. works perfectly now. :biggrin:

    many thanks.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran complex array assignment
  1. Fortran 3D array (Replies: 3)

Loading...