- #1
Sdakouls
- 8
- 0
Hi,
I'm trying to compile a code (.f95, compiling using gfortran) in which I'm using a 'do' loop to set the values in a complex array; the following little piece is giving me trouble:
Where x(i) is an array of 'double precision' numbers (which have already been set (and they are correct) in another 'do' loop, the details of which I have omitted for brevity), of the same dimension as y(i). When I try to compile I get the error message:
y(i) = (a + b*x(i)*x(i), 0.0)
_______________________1
Error: Expected a right parenthesis in expression at (1)(Note: I inserted the underscores in the second line of the error message myself to get the '1' in the right place.)
It was my understanding that to define a complex number in f95, one writes it in the form (c, d) where c & d can be integers or reals. If I replace the real part of the expression for y(i) by some explicitly real number such as (for example) 2.0, the program compiles and the problem goes away. This leads me to believe that my problem lies in the use of the array element(s) x(i) in the expression for y(i).
Also, I know that the number shown is real and the 0.0 in the imaginary slot is redundant, but I am actually going to need to do things like y(i) = (x(i), z(i)), which I can't progress to if I can't get the above to compile.
I'm new to f95 and I'm willing to bet that I've made some completely novice mistake. However, I'm at a loss here and any help would be very much appreciated.
Thank you.
I'm trying to compile a code (.f95, compiling using gfortran) in which I'm using a 'do' loop to set the values in a complex array; the following little piece is giving me trouble:
Code:
double precision, dimension(n) :: x
complex, dimension(n) :: y
do i=1, n
x(i) = ...
end do
do i=1, n
y(i) = (a + b*x(i)*x(i), 0.0)
end do
Where x(i) is an array of 'double precision' numbers (which have already been set (and they are correct) in another 'do' loop, the details of which I have omitted for brevity), of the same dimension as y(i). When I try to compile I get the error message:
y(i) = (a + b*x(i)*x(i), 0.0)
_______________________1
Error: Expected a right parenthesis in expression at (1)(Note: I inserted the underscores in the second line of the error message myself to get the '1' in the right place.)
It was my understanding that to define a complex number in f95, one writes it in the form (c, d) where c & d can be integers or reals. If I replace the real part of the expression for y(i) by some explicitly real number such as (for example) 2.0, the program compiles and the problem goes away. This leads me to believe that my problem lies in the use of the array element(s) x(i) in the expression for y(i).
Also, I know that the number shown is real and the 0.0 in the imaginary slot is redundant, but I am actually going to need to do things like y(i) = (x(i), z(i)), which I can't progress to if I can't get the above to compile.
I'm new to f95 and I'm willing to bet that I've made some completely novice mistake. However, I'm at a loss here and any help would be very much appreciated.
Thank you.
Last edited: