Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Expected PARAMETER symbol in complex constant at (1)

Tags:

fortran

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.

like image 253
Matteo Parsani Avatar asked Nov 19 '13 14:11

Matteo Parsani


People also ask

What is PARAMETER statement in fortran?

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.

How do I write a parameter in Fortran?

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.

How do you define a constant in Fortran?

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.)


1 Answers

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).

like image 116
Vladimir F Героям слава Avatar answered Oct 25 '22 06:10

Vladimir F Героям слава