Here is the code snippet. The problem I have is that sometimes NRHS is equal to zero, even though I am passing the two correct objects into the mex function. An error is thrown about the number of arguments according to the error checks. The question is why would no arguments be passed if the function call from the m-file function is explicitly calling this mex file with the two correct objects as inputs?
SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
!
!
!$ USE OMP_LIB
IMPLICIT NONE
MWPOINTER PLHS(*), PRHS(*), mxDuplicateArray
MWSIZE NLHS, NRHS
CHARACTER(LEN=63) :: mxGetClassName
EXTERNAL AUTOSTOPWITHOUTERROR
MWSIZE mexAtExit
MWSIZE k
CHARACTER(LEN=100) :: NUMPROCSTR
!---------------------------------------------------------------------
! AVOID ERRORS WHEN DIVIDING BY ZERO ON WINDOWS PLATFORM
!---------------------------------------------------------------------
! This resets the floating point exception to allow divide by zero,
! overflow and invalid numbers.
!
#ifdef MSWIND
MWSIZE CONTROL
CALL GETCONTROLFPQQ(CONTROL)
CONTROL = CONTROL .OR. FPCW$ZERODIVIDE
CONTROL = CONTROL .OR. FPCW$INVALID
CONTROL = CONTROL .OR. FPCW$OVERFLOW
CALL SETCONTROLFPQQ(CONTROL)
#endif
! Set number of processors if not defined
#ifndef OMP_NUM_THREADS
# define OMP_NUM_THREADS 1
#endif
! WRITE(NUMPROCSTR,1001)OMP_NUM_THREADS
!1001 FORMAT('fprintf(''\\n\\n NUMBER OF PROCESSORS : ',I2,'\\n\\n'')')
! CALL MEXEVALSTRING(NUMPROCSTR)
!---------------------------------------------------------------------
! CHECK NUMBER OF INPUT ARGUMENTS AS WELL AS TYP OF OBJECTS BEING PASSED IN
!---------------------------------------------------------------------
if( NRHS /= 2 ) then
call mexErrMsgTxt("Two input arguments required into gateway function")
k=mexAtExit(AUTOSTOPWITHOUTERROR)
endif
if( mxGetClassName(PRHS(1)) /= "autofiles" ) then
call mexErrMsgTxt("Make sure a FileNames object is being passed as the first argument into the AUTO07gateway function")
k=mexAtExit(AUTOSTOPWITHOUTERROR)
endif
if( mxGetClassName(PRHS(2)) /= "autoinitcon" ) then
call mexErrMsgTxt("Make sure an InitialConditions object is being passed as the second argument into the AUTO07gateway function")
k=mexAtExit(AUTOSTOPWITHOUTERROR)
endif
CALL GETSIMOPTS(PRHS)
CALL RUN(NRHS, PRHS)
k=mexAtExit(AUTOSTOPWITHOUTERROR)
RETURN
END
!---------------------------------------------------------------------
! RUN IN 07P MODE
!---------------------------------------------------------------------
SUBROUTINE RUN(NRHS, PRHS)
USE AUTO_CONSTANTS
USE INTERFACES
IMPLICIT NONE
MWPOINTER PRHS(*)
MWSIZE NRHS
EXTERNAL AUTOSTOPWITHOUTERROR
MWSIZE mexAtExit
MWSIZE k
CHARACTER*63 FCNSTR
CALL COPYDSTOBJECTSTOAUTO(PRHS)
!
! Run the main continuation package "AUTO"
!
CALL AUTO()
!
!
RETURN
END