@@ -136,9 +136,10 @@ class matlabEval : public NOMAD::Evaluator {
136
136
{
137
137
char errstr[1024 ];
138
138
bool stop = false ;
139
- int i, j, n = x.size (), status ;
139
+ int i, j, n = x.size ();
140
140
double *xm, *fvals;
141
141
mxLogical *sur;
142
+ mxArray *status = nullptr ;
142
143
count_eval = true ; // mexErrMsgTxt will kill MEX
143
144
144
145
// Check for Ctrl-C
@@ -162,7 +163,7 @@ class matlabEval : public NOMAD::Evaluator {
162
163
}
163
164
// Call MATLAB Objective
164
165
try {
165
- status = mexCallMATLAB (1 , fun->plhs , fun->nrhs , fun->prhs , fun->f );
166
+ status = mexCallMATLABWithTrap (1 , fun->plhs , fun->nrhs , fun->prhs , fun->f );
166
167
}
167
168
// Note if these errors occur it is due to errors in MATLAB code, no way to recover?
168
169
catch (exception &e) {
@@ -206,7 +207,7 @@ class matlabEval : public NOMAD::Evaluator {
206
207
xm[i] = x[i].value ();
207
208
// Call MATLAB Constraint
208
209
try {
209
- status = mexCallMATLAB (1 , con->plhs , con->nrhs , con->prhs , con->f );
210
+ status = mexCallMATLABWithTrap (1 , con->plhs , con->nrhs , con->prhs , con->f );
210
211
}
211
212
catch (...)
212
213
{
@@ -254,7 +255,7 @@ class matlabEval : public NOMAD::Evaluator {
254
255
memcpy (mxGetPr (iterF->prhs [2 ]), fvals, sizeof (double ));
255
256
memcpy (mxGetPr (iterF->prhs [3 ]), xm, n * sizeof (double ));
256
257
try {
257
- status = mexCallMATLAB (1 , iterF->plhs , 4 , iterF->prhs , iterF->f );
258
+ status = mexCallMATLABWithTrap (1 , iterF->plhs , 4 , iterF->prhs , iterF->f );
258
259
}
259
260
catch (...)
260
261
{
@@ -668,9 +669,7 @@ void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
668
669
mexPrintf (" ------------------------------------------------------------------\n " );
669
670
mexEvalString (" drawnow;" ); // flush draw buffer
670
671
}
671
- // Let this file sort out errors
672
- mexSetTrapFlag (1 );
673
-
672
+
674
673
// Reset tags and bbe (C.Tribes 3/14)
675
674
NOMAD::Eval_Point::reset_tags_and_bbes ();
676
675
@@ -771,8 +770,6 @@ void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
771
770
772
771
// Return cout to initial buffer
773
772
std::cout.rdbuf (cout_sbuf);
774
- // Return error control to default
775
- mexSetTrapFlag (0 );
776
773
777
774
// Free Memory
778
775
if (mSEval ) delete mSEval ; mSEval = NULL ;
@@ -784,14 +781,15 @@ void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
784
781
// Determine Variable Return Types + # Objectives + #NL Constraints (only OPTI Version)
785
782
vector<NOMAD::bb_output_type> detRetTypes (usrFcn *fun, mxArray *out_types, int *nobj, usrFcn *con, int *ncon, double *x0, size_t n)
786
783
{
787
- int i, j, stat;
784
+ int i, j;
785
+ mxArray *status = nullptr ;
788
786
789
787
// Test Blackbox / Objective Evaluation
790
788
fun->plhs [0 ] = NULL ;
791
789
memcpy (mxGetPr (fun->prhs [fun->xrhs ]), x0, n * sizeof (double ));
792
790
// Call MATLAB Objective
793
- stat = mexCallMATLAB (1 , fun->plhs , fun->nrhs , fun->prhs , fun->f );
794
- if (stat )
791
+ status = mexCallMATLABWithTrap (1 , fun->plhs , fun->nrhs , fun->prhs , fun->f );
792
+ if (status )
795
793
mexErrMsgTxt (" Error calling Objective Function!" );
796
794
// Ensure we have a real column
797
795
if (mxGetN (fun->plhs [0 ]) > mxGetM (fun->plhs [0 ]))
@@ -811,8 +809,8 @@ vector<NOMAD::bb_output_type> detRetTypes(usrFcn *fun, mxArray *out_types, int *
811
809
con->plhs [0 ] = NULL ;
812
810
memcpy (mxGetPr (con->prhs [con->xrhs ]), x0, n * sizeof (double ));
813
811
// Call MATLAB Objective
814
- stat = mexCallMATLAB (1 , con->plhs , con->nrhs , con->prhs , con->f );
815
- if (stat )
812
+ status = mexCallMATLABWithTrap (1 , con->plhs , con->nrhs , con->prhs , con->f );
813
+ if (status )
816
814
mexErrMsgTxt (" Error calling Constraint Function!" );
817
815
// Ensure we have a real column
818
816
if (mxGetN (con->plhs [0 ]) > mxGetM (con->plhs [0 ]))
0 commit comments