Hi everybody. I found an access violation using a function, passed as argument inside another function.
The code is this:
function NRF_Hn(x, F_, G_, h) result(Hn)
implicit none
double precision , pointer :: Hn(:,:)
double precision, intent(in) :: x(:)
double precision, optional, intent(in) :: h(:)
procedure(INRFunctionDouble), optional :: F_
procedure(INRGradientDouble), optional :: G_
double precision, allocatable :: xplush(:)
double precision, allocatable :: xminush(:)
double precision, pointer :: gMinus(:)
double precision, pointer :: gPlus(:)
integer n , i
n = size(x)
allocate(Hn(n,n))
Hn = 0.0d0
!Creates x+h and x-h as Vectors
allocate(xPlusH(n))
allocate(xMinusH(n))
!Copy the x in Vectors
xPlusH = x
xMinusH = x
do i = 1 , n
xPlusH(i) = xPlush(i) + H(i)
xMinusH(i) = xMinush(i) - H(i)
gMinus => G_(xMinusH, F_,h) !<------ Access Violation Here !!!!
gPlus => G_( xPlusH, F_,h)
Hn(:,i) = (gPlus - gMinus)/(2.0d0*h(i))
xPlusH(i) = x(i)
xMinusH(i) = x(i)
end do
deallocate(xPlusH)
deallocate(xMinusH)
end function
This function is inside a class module.
I attached the minimum project that reproduce the error, can you help in understanding what's going wrong?