# Fortran complex array assignment

• Fortran
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:
do t = 1, count
real(in(t)) = cos(2 * pi * f0 * t)
aimag(in(t))=sin(2 * pi * f0 * t)
end do

thanks.

AlephZero
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:
do t = 1, count
in(t) = ( cos(2 * pi * f0 * t) , sin(2 * pi * f0 * t) )
enddo

This should work:
Code:
do t = 1, count
in(t) = ( cos(2 * pi * f0 * t) , sin(2 * pi * f0 * t) )
enddo

But unfortunately it doesn't work. Even in the following simple code:
Code:
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:
test.f95:6.18:

in(t) = ( 2*t, 3*3 )
1
Error: Expected a right parenthesis in expression at (1)

any ideas?

AlephZero