Hi there,
I have a similar problem as some of the people who have already submitted code snippets. This is my code:
Code:
void interpn(double *outgrid, double *gridx, double *gridy, double *gridxy, double *agrid1, double *agrid2, int ngrid, int ngrid2) {
alglib::real_1d_array gridxx;
gridxx.setcontent(ngrid,gridx);
alglib::real_1d_array gridyy;
gridyy.setcontent(ngrid2,gridy);
alglib::real_1d_array ingrid;
ingrid.setcontent(ngrid*ngrid2,gridxy);
alglib::spline1dinterpolant splone;
// build spline
alglib::spline2dbuildbicubicv(gridxx,ngrid,gridyy,ngrid2,ingrid,1,splone);
for (int ii=0; ii<ngrid; ii++) {
for (int jj=0; jj<ngrid2; jj++) {
for (int kk=0; kk<nstates_as; kk++){
for (int ll=0; ll<nstates_is; ll++){
outgrid[ii*ngrid2+jj+(kk+ll)*(ngrid*ngrid2)] = alglib::spline2dcalc(splone, agrid1[ii*ngrid2+jj], agrid2[ii*ngrid2+jj]);
}
}
}
}
}
.
.
.
interpn(&k2prime_bu[0][0][0][0],kkgrid,kmgrid,tempmat,&kprime[0][0][0][0],&kmprime[0][0][0][0],ngrid,ngrid2);
Most but not all of the arrays I pass to the function are from the C++ Boost library's multidimensional array library. Running this code gives me the dreaded
terminate called after throwing an instance of 'alglib::ap_error'. I know that the error is thrown at the point where the spline is build, i.e. at the point
Code:
alglib::spline2dbuildbicubicv(gridxx,ngrid,gridyy,ngrid2,ingrid,1,splone);
Any suggestions where I may be making a mistake here?
Thanks,
Eric