Refined cubic spline code to maximize reuse of code across dimentions