There're several issues with the subroutine AkimaSpline_MKL that you're using for Akima cubic interpolation.
1. Before calling dfdNewTask1D() function you set ny=nx. This is wrong, because setting ny=nx means that you will construct coefficients for nx Akima cubic splines on the same partition at once. But you only need coefficients for 1 spline. So, to fix the issue please make following change in your code:
! Create Data Fitting task
ny = 1
errcode = dfdNewTask1D(task, nx, xx, xhint, ny, yy, yhint)
This was the cause of access violation in you application. There were no enough memory for construction of nx splines.
2. datahint parameter is initialized incorrectly when calling dfdInterpolate1D. You should either skip it, because it's unnecessary in your case, or make following change to the code:
datahint(1) = 1.d0 ! Dimension of the task
datahint(2) = dble(DF_NO_APRIORI_INFO) ! No additional information about breakpoints or sites is provided.
3. Interpolation results are packed into r array - parameter of dfdInterpolate1D function, they aren't returned as the functions' result.
It will be better to use following code sequence to obtain interpolation result:
errcode = dfdInterpolate1D(task, DF_INTERP, DF_METHOD_PP, nsite, site, sitehint, ndorder, dorder, datahint, r, rhint)
Y = r(1)
After applying those three changes described above the code should start working as expected.
Please seefixed file in attachment.
Thanks a lot ! I did very basic mistakes that I should not have done !
I have changed the code according to your suggestions but unfortunately the dfdInterpolate1D function returns always 0 in r(1) whatever the value stored in site(1). If I have correctly understood, the site() array contains the x values for which one wants an interpolation and the r() array contains the results ?
dorder: Array of size ndorder that defines the order of the derivatives to be computed at the interpolation sites. If all the elements in dorder are zero, the library computes the spline values only. If you do not need interpolation computations, set ndorder to zero and pass a NULL pointer to dorder.
Phil, hello again,
The examples provided by you disclosed the issue in MKL Akima spline construction, which wasn't caught by our internal testing. Thank you very much for your efforts!
Indeed, coeficients of Akima spline are calculated incorrectly for two beginning and two ending intervals. This issue isplanned to be fixed in further MKL releases. Hopefully you will try one ofthem.