trouble with initializing array of complex type



Hi,
This problem seems strange to me. Hope I can get some help or hint from
you.
Let's first look at this following code:
************************CODE
1******************************************
program cmpx_init
complex, dimension(1:9):: a0
integer:: i

do i = 1,9
a0(i) = (0.1*i, 0.1*i)
end do

write(*,*) a0

end program cmpx_init
*************************************************************************
When compiled with g95, it gives me this error message:

In file cmpx_init.f90:6

a0(i) = (0.1*i, 0.1*i)
1
Error: Expected a right parenthesis in expression at (1)

With PGI Fortran 90 compiler, it also gives an error at this step.
I found out that the problem is with the variable "i" in the
initialization
expression, that is, when that expression is replaced by "a0(i) = (0.1,
0.1)",
the code will compile. What strikes me most is that the following code,
for a
real type array, compiles without any error or warning message. How can
a real array and a
complex array be treated so differently?

*****************************CODE
2****************************************
program real_init
real, dimension(1:9):: a0
integer:: i

do i = 1,9
a0(i) = 0.1*i
end do

write(*,*) a0

end program real_init
******************************************************************************

Any input is welcome. Programming with Fortran is really a hard thing,
to me.
Best regards,
Qingshan

.



Relevant Pages

  • Re: Why the compiler gives warning ?
    ... > "Except when it is the operand of the sizeof operator or the unary & ... > initial element of the array object and is not an lvalue." ... ignored' is an error message; it looks more like a warning. ... from the compiler. ...
    (comp.lang.c)
  • understanding segmentation faults
    ... Is "segmentation fault" an error message that is issued by the operating ... not a problem that the compiler vendors can easily solve. ... technical terminology an "array section"?). ...
    (comp.lang.fortran)
  • Re: problem with linked list
    ... main returns int in C. ... You cannot directly assign to an array in C like this (and this is what your ... compiler is telling you). ... > I am using the Borland c compiler an here is the error message: ...
    (comp.lang.c)
  • Re: Getting address of structure to string array / pointer problem
    ... How did you avoid getting an error message here. ... indirection from 'const struct testStruct *'". ... array of char. ... >It seems that compiler is only storing 8 bits of address of myStruct ...
    (comp.lang.c)
  • Re: Idea for ECMA/C# Standard - compile time hash for performance
    ... I agree with you the chance of a compiler change is slim, ... and then delegating to the standard hash for fields accessed less frequently. ... or the array lookup which would require the ... > 64-bit architecture) for each enum value that doesn't map to anything. ...
    (microsoft.public.dotnet.languages.csharp)