Code to allow specification of gradient direction.