- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For years I have used DIMAG to extract the imaginary part of a double precision complex number and store it into a double precision real.
I am trying nowtocode with keeping portability in mind (using parameterized real kinds, for instance).
For the real part, one can write the following:
INTEGER,PARAMETER :: DP = SELECTED_REAL_KIND(15,100) ! (This definition can go into a module...)
REAL(DP) R
COMPLEX(DP) C
R = REAL(C,KIND=DP)
But what about the same kind of construct for the imaginary part? There is no IMAG generic function that can be used with the same syntax, only type specific functions such as DIMAG and so on...
Is there another way to do this, without resorting to type specific functions such as AIMAG, DIMAG ... a solution which defeats the portability purpose?
Thanks!!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
AIMAG is the generic name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Consider creating a GENERIC INTERFACE which returns the imaginary part of the complex number in the same precision of the complex number
FUNCTION IMAGINARY_SP(C)
REAL(SP) :: IMAGINARY_SP
COMPLEX(SP) :: C
IMAGINARY_SP = REAL(C,KIND=SP)
END FUNCTION IMAGINARY_SP
FUNCTION IMAGINARY_DP(C)
REAL(DP) :: IMAGINARY_DP
COMPLEX(DP) :: C
IMAGINARY_DP = REAL(C,KIND=DP)
END FUNCTION IMAGINARY_DP
...
INTERFACE IMAGINARY
FUNCTION IMAGINARY_SP(C)
REAL(SP) :: IMAGINARY_SP
COMPLEX(SP) :: C
END FUNCTION IMAGINARY_SP
FUNCTION IMAGINARY_DP(C)
REAL(DP) :: IMAGINARY_DP
COMPLEX(DP) :: C
END FUNCTION IMAGINARY_DP
END INTERFACE IMAGINARY
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page