Below we shall give some advices of how to improve the performance of a code.
DO i = 1, n
IF ( var > 0 ) THEN
a(i) = 0.
ELSE
a(i) = b(i)
ENDIF
ENDDO
should be replaced by
IF ( var > 0 ) THEN
a(:) = 0.
ELSE
a(:) = b(:)
ENDIF