This is a common symptom of a stack corruption. Probably, you are calling myfunction
with wrong arguments, but it can be somewhere deeper inside it. Check every call around and check the types of all arguments.
Be sure to use -check all
and -warn all
with ifort when debugging. That includes -warn interfaces
which is very helpful in similar problems, but because you are calling a C function it will probably not find the cause here.
EDIT - for 2 argument subroutine:
In your case make sure both arguments are double precision
or c_double
or real*8
depending on which type of declaration you use. Don't put any third argument there, as your first piece of code might suggest!
The modern way of interfacing this in Fortran 2003
would be:
interface
subroutine myfunction(arg1, arg2) bind(C, name="myfunction")
use iso_c_binding
real(c_double) :: arg1, arg2
end subroutine
end interface
which is put instead of the older (and optional) external myfunction
in the declaration part of your code.
In any case, carefully check the types and correct position of all the arguments, whatever the final number of them is.