I am writing a small piece of Fortran 90 code to compute some quantities using complex variables.
I have a subroutine with the following instructions:
complex, dimension(3) :: v
integer :: i
real:: tmp
do i = 1,3
tmp = vg(i)
v(i) = (tmp, 0.0)
enddo
v
is a complex array of length 3. vg
is an array of length 3 too whose elements are real.
When I compile the above code with gfortran 4.7.3 I get the following error:
v(i) = (tmp,0.0)
Error: Expected PARAMETER symbol in complex constant at (1)
I do not understand what's the problem.
The PARAMETER statement assigns a symbolic name to a constant. In this alternate form, the type of the constant expression determines the type of the name; no conversion is done.
Add PARAMETER in front of the double colon (::) and use a comma to separate the type name (i.e., REAL) and the word PARAMETER. Following each name, one should add an equal sign (=) followed by an expression. The value of this expression is then assigned the indicated name.
A literal constant is a datum whose value cannot change throughout the program unit. The form of the string representing a constant determines the value and data type of the constant. (For a named constant, defined by a PARAMETER statement, the name defines the data type.)
You have to use
v(i) = cmplx(tmp, 0.0)
Your syntax (re, im)
works only for constant expressions, i.e. when re
and im
are real or integer constants.
This means you cannot make a complex constant from a real variable and a real constant. You have to use the intrinsic function cmplx
which converts real
variables to complex
ones, or builds complex
variables from pairs of real
variables (or integer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With