Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

MKL Interpolation gives strange results (fortran)

$
0
0

With the help of the reference manual for MKL data fitting i have tried to put together a I have a piece of fortran code for interpolation using MKL. It seems to me to give somewhat strange results (I don't know what I am missing here).:

  include 'mkl_df.f90'
  include 'mkl_dfti.f90'

  program TestMyFortranCode
  USE MKL_DF_TYPE
  USE MKL_DF
  use ISO_C_BINDING
  TYPE (DF_TASK) dftask
  integer(c_int),parameter  ::  NSITES = 1024
  integer(c_int)            ::  f_index(27)
  real(c_double)            ::  f(27)

  real(c_double) :: x(29)
  integer(c_int) :: nx
  integer(c_int) :: xhint
  real(c_double) :: y(29)
  integer(c_int) :: ny
  integer(c_int) :: yhint

  integer(c_int) :: sorder
  integer(c_int) :: stype
  real(c_double),target :: site(NSITES)
  integer(c_int) :: nsite
  integer(c_int) :: sitehint
  real(c_double) :: scoeff((size(x)-1)*DF_PP_CUBIC)
  integer(c_int) :: scoeffhint
  integer(c_int) :: bc_type

  integer(c_int) :: ndorder
  integer(c_int) :: nder
  integer(c_int) :: derorder(3)

  integer(c_int) :: calc_type
  integer(c_int) :: method

  real(c_double),target :: r(size(site))
  integer(c_int) :: rhint

  real(c_double),POINTER :: site_ptr(:)
  real(c_double),POINTER :: r_ptr(:)

  integer(c_int) :: error

  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  error = 0
  site = (/(i*1.0d0, i=0,NSITES-1)/)/(NSITES) !
  f_index=(/ (ii,ii=14,40)/)
  f=10d0**(f_index/10.0d0)
  x = (/-1.d0, f, 22100.d0/)/22050.d0

  nx    = size(x)
  xhint = DF_NO_HINT
  y = (/0.d0, 5.d0, 1.d0, -3.d0, -2.d0, -6.d0, -9.d0, -10.d0, -14.d0, -14.d0, &
        -15.d0, -15.d0, -16.d0, -20.d0, -24.d0, -19.d0, -10.d0, -13.d0, -15.d0, -16.d0, &
        -17.d0, -18.d0, -21.d0, -28.d0, -29.d0, -33.d0, -45.d0, -66.d0, -77.d0/)
  ny = 1
  yhint = DF_NO_HINT
  nsite      =  NSITES
  sitehint   = DF_NO_HINT

  sorder = DF_PP_CUBIC
  stype  = DF_PP_NATURAL

  scoeffhint = DF_UNIFORM_PARTITION

  bc_type = DF_BC_FREE_END
  rhint = DF_MATRIX_STORAGE_ROWS

  ndorder = 3
  derorder = (/1,0,1/)
  nder = 2

  error = dfdNewTask1D(dftask, nx, x, xhint, ny, y, yhint )
  error = dfdEditPPSpline1D( dftask, sorder, stype, bc_type,         && scoeff=scoeff, scoeffhint=scoeffhint )
  calc_type = DF_PP_SPLINE
  method = DF_METHOD_STD
  error = dfdConstruct1D( dftask, calc_type, method )
  calc_type = DF_INTERP
  method = DF_METHOD_PP
  site_ptr => site
  r_ptr    => r
  error = dfdInterpolate1D( dftask, calc_type, method,                  &&      nsite, site_ptr, sitehint, ndorder, derorder, r=r_ptr,    &&      rhint=rhint )

  error = dfDeleteTask( dftask )
  write (*,*) r_ptr
  end program TestMyFortranCode

y are the function values of x and site are the interpolation sites (x-values) that I want interpolated values for put in r.

The results for uneven indices looks somewhat as they should, closer to the y-values, but for even indices the results are more random (i.e. -68820.abc or 1013.xyz)

After running the function "dfdNewTask1D" the second value of dftask seems always to be 0 (zero) and the first value seems to get a large random value (I.e. 7424768) (from what I can read out from debug-mode in msvs). Don't know if this is as it should be??

Does anyone know what is going wrong, or if the results are normal, and then what are the results for even indices describing?

(I use MSVS 2013)


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>