Using complex part designators (Fortran 2008 new)
Ka_Lin 270003YYMN Visits (2510)
In the past, the intrinsic procedures REAL(z) and AIMAG(z) (where z is of type complex) were used to get the real part and imaginary part of z. For example,
COMPLEX :: z = (3.2, 2.1)
REAL(z) has the value 3.2.
AIMAG(z) has the value 2.1.
In Fortran 2008, you can use the complex part designators with the %RE and %IM selectors instead; that is,
z % RE has the value 3.2.
z % IM has the value 2.1.
You might benefit from the direct access to the real or imaginary part of complex entities by using the complex part designators as variables in assignment statements; typically when you want to directly set the real or imaginary part of a complex variable to a specific value. For example,
z % IM = 0.0 sets the imaginary part of z to zero.
(Authors: Ka Lin, Bardia Mahjour)