fixed readcoeffs() to work for an arbitrary number of dimensions