calculate factor2pi instead of factor
use MAX_DIM to select max number of dimensions, really disable generation of 3D code if not requested