move repeated code to a macro, enable cpp for gfortran