Gold gains $40 during week as US dollar dips