sundials icon indicating copy to clipboard operation
sundials copied to clipboard

Fortran interface to NVector returns a pointer with the wrong dimension

Open Nicholaswogan opened this issue 3 years ago • 2 comments

When using the Fortran 2003 interface to Sundial, retrieved arrays from NVectors are not the correct dimension

https://github.com/LLNL/sundials/blob/e2f29c34f324829302037a1492db480be8828084/src/sundials/fmod/fsundials_nvector_mod.f90#L824

The Fortran-C interface assumes NVector arrays are always length 1. So, for example when I do

type(N_Vector)        :: sunvec_y
real(c_double), pointer :: yvec(:)

yvec => FN_VGetArrayPointer(sunvec_y)

then yvec is a fortran pointer to an array of length 1, instead of the actual length of the NVector. Instead, yvec should be given the proper length during the call to FN_VGetArrayPointer

Nicholaswogan avatar Jun 20 '22 23:06 Nicholaswogan

You can try changing the line

call c_f_pointer(fresult, swig_result, [1])

to

call c_f_pointer(fresult, swig_result, [F_NVGetLength(v)])

balos1 avatar Jun 21 '22 00:06 balos1

That works (returned array has right dimension) except you have a little typo. It should be

call c_f_pointer(fresult, swig_result, [FN_VGetLength(v)])

Nicholaswogan avatar Jun 21 '22 00:06 Nicholaswogan

Temporary fix in place with #214.

balos1 avatar Oct 19 '22 18:10 balos1