The following example shows how to stop the execution on the error.
program f2003error
USE, INTRINSIC :: ISO_C_BINDING
use calceph
implicit none
integer res
real(8) jd0
real(8) dt
real(8) PV(6)
! set the error handler to stop on error
call calceph_seterrorhandler(2, C_NULL_FUNPTR)
! open the ephemeris file
res = calceph_sopen("example1.dat"//C_NULL_CHAR)
...
stop
end
The following example shows how to define a custom error handler function.
!/*-----------------------------------------------------------------*/
!/* custom error handler */
!/*-----------------------------------------------------------------*/
subroutine myhandler(msg, msglen) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
implicit none
character(kind=C_CHAR), dimension(msglen), intent(in) :: msg
integer(C_INT), VALUE, intent(in) :: msglen
write (*,*) "The calceph calls the function myhandler"
write (*,*) "The message contains ",msglen," characters"
write(*,*) "The error message is :"
write(*,*) "----------------------"
write(*,*) msg
write(*,*) "----------------------"
write(*,*) "The error handler returns"
end
!/*-----------------------------------------------------------------*/
!/* main program */
!/*-----------------------------------------------------------------*/
program f2003error
USE, INTRINSIC :: ISO_C_BINDING
use calceph
implicit none
integer res
real(8) jd0
real(8) dt
real(8) PV(6)
interface
subroutine myhandler(msg, msglen) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
implicit none
character(kind=C_CHAR), dimension(msglen), intent(in) &
& :: msg
integer(C_INT), VALUE, intent(in) :: msglen
end subroutine
end interface
! set the error handler to use my own callback
call calceph_seterrorhandler(3, c_funloc(myhandler))
! open the ephemeris file
res = calceph_sopen("example1.dat"//C_NULL_CHAR)
! ...
stop
end