A statistical method to determine total H2O and CO2 budgets in magmas