Fixed out of bounds error in trilinearinterpolation