Charge states of 15-140 MeV bromine ions and 15-162 MeV iodine ions in solid and gaseous media