inserted some error checking in read_spectrum