How to implement a spline subroutine in my code

Also the OP should look at Carl De Boor’s PPPACK,
https://people.sc.fsu.edu/~jburkardt//f_src/pppack/pppack.html

Plus a better option than a pure cubic spline is a monotonic piece-wise cubic routine like PCHIPS (I think @jacobwilliams has a refactored version) and the Akima family of splines from the ACM repository. Also, just about all computer graphics and CAGD books that cover the math will have a spline routine of some kind.

Also, NASA’s cfdtools github directory has several spline routines in the interplib directory.