Xrf fit

I think it is worse than that as farther down in the code it assumes the file is open and will raise other exception.s