Gold ends marginally lower but books solid July performance