I need to check if the imaginary part is very small and sets it to zero if it is designed to eliminate some floating point errors that lead to very small non-zero imaginary parts when they should be zero.
My code is as follows:
kz2 = SQRT((n2*(2.0*PI*eta))**2 - kxarray(p)**2) kz1 = SQRT((n1*(2.0*PI*eta))**2 - kxarray(p)**2) if (aimag(kz2) < 0.0005) then kz2 = (REAL(kz2),0.0) end if if (aimag(kz1) < 0.0005) then kz1 = (REAL(kz1), 0.0) end if
Unfortunately, the compiler simply returns:
gaussian1.f90:122.18: kz2 = (REAL(kz2),0.0) 1 Error: Expected a right parenthesis in expression at (1) gaussian1.f90:126.18: kz1 = (REAL(kz1), 0.0) 1 Error: Expected a right parenthesis in expression at (1)
Any advice would be greatly appreciated - have I really solved this problem correctly?
UPDATE: I managed to avoid the problem by using:
if (aimag(kz2) < 0.0005) then kz2 = real(kz2) end if if (aimag(kz1) < 0.0005) then kz1 = real(kz1) end if
But what would I do if I wanted to set the imaginary part to a nonzero sum?
source share