Help Files: Fortran77: Complex





     HELP                      Sep. 15, 1984               F77/COMPLEX



     Complex and Double Complex Constants, Variables and Intrinsic Functions

     Declare single precision complex variables as type  'complex'  or
     'complex*8';  declare double precision complex variables as 'dou-
     ble complex' or 'complex*16'.

     Here is an example illustrating the use of single precision  com-
     plex variables and constants:

                     implicit complex (c)
                     data x1/8.5/, x2/9.2/

             c               create c1 from a complex constant
                     c1 = (1.1,2.1)
             c               create c2 from two real variables
                     c2 = cmplx( x1, x2 )

             c               take complex square root of c1 using
             c                       the generic function name
                     c3 = sqrt(c1)

             c               get the real part of c3
                     xreal1 = c3
                     xreal2 = real(c3)
             c               get imaginary part with generic 'imag()'
                     ximag = imag( c3 )
             c               find the conjugate of c3
                     c4 = conjg(c3)

                     print *, c1,c2,c3,c4,x1,x2,xreal1,xreal2,ximag
                     end

     The same example in double precision:

                     implicit double complex (z)
                     implicit double precision (d)
                     data d1/8.5d0/, d2/9.2d0/

                     z1 = (1.1d0,2.1d0)
                     z2 = dcmplx( d1, d2 )
                     z3 = sqrt(z1)
                     dxreal1 = z3
             c               dreal() would also work
                     dxreal2 = dble(z3)
                     dximag = imag( z3 )
                     z4 = conjg(z3)

                     print *, z1,z2,z3,z4,d1,d2,dxreal1,dxreal2,dximag
                     end

     To create a complex value from real variables, use 'cmplx()'.  To
     create  a  double  complex value from double precision variables,
     use 'dcmplx()'.  The generic function names, that work with  both
     complex and double complex, are:

          imag(), conjg(), sqrt(), abs(), exp(), log(), sin(), cos()

     If you declare the function to be external and pass the  function
     name  to  a  procedure,  you must use the specific function name.
     For single precision, they are:

         aimag(), conjg(),csqrt(),cabs(),cexp(),clog(),csin(),ccos()

     and for double precision, they are:

         dimag(),dconjg(),zsqrt(),zabs(),zexp(),zlog(),zsin(),zcos()

             


Comments to decf@euler.berkeley.edu
© 1998 UC Regents