[Numpy-discussion] Recovering from a STOP ?
Wed Mar 14 08:28:38 CDT 2012
I'm working with some large inherited F90 code that needs to be wrapped in
Python. if the code base itself cannot be modified (it's a static archive), some
additional F90 files were written to help the interaction with the code. Writing
a python extension combining the archive and these additional files is rather
straightforward using F2PY, the extension loads, all is well but...
...when a problem occurs in a subroutine deep in the base code, it calls another
routine (say, ENDRUN) which itself uses a STOP statement. As you know, this
statement not only exits the fortran code, but makes the extension and then the
I patched ENDRUN use STOP, I tried to call a C external function instead of
*- ENDRUN.f90 -*
character(LEN=*), intent(in) :: C_NOM
! write(*, *) C_NOM
end subroutine ENDRUN
*- ENDRUNWRAP.f90 -*
character(LEN=*), intent(in) :: message
end subroutine pyraise_runtime
end module endrun_wrap
*- pyraise_runtime.c -*
void pyraise_runtime_(char *message);
void pyraise_runtime_(char *message)
printf("calling PyErr_SetString(PyExc_RuntimeError, message)\n");
Alas, the RuntimeError doesn't look like it's passed back to the interpreter,
which still crashes. (Adding a Py_Exit(-1) at the end of pyraise_runtime at
least let the interpreter do some extra cleaning after the fortran code stopped,
Note that ENDRUN is never supposed to be called directly by the user (so no
point to define a callback function via f2py, right ?).
Any idea would be quite welcome.
Thanks an awful lot in advance.
PS: Oh, BTW, I'm limited to numpy 1.4.1 and the f2py that comes with it...
More information about the NumPy-Discussion