Index: mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl ================================================================== --- mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl +++ mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl @@ -4,68 +4,53 @@ #define S_FUNCTION_NAME _sfun #define S_FUNCTION_LEVEL 2 #include "simstruc.h" -#include #include #include "_def.h" -static mxArray *dX = mxCreateDoubleMatrix (MTTNX , 1, mxREAL); static mxArray *P = mxCreateDoubleMatrix (MTTNPAR , 1, mxREAL); static mxArray *T = mxCreateDoubleMatrix (1 , 1, mxREAL); static mxArray *U = mxCreateDoubleMatrix (MTTNU , 1, mxREAL); static mxArray *X = mxCreateDoubleMatrix (MTTNX , 1, mxREAL); -static mxArray *Y = mxCreateDoubleMatrix (MTTNY , 1, mxREAL); static double *inputs = mxGetPr (U); -static double *outputs = mxGetPr (Y); static double *parameters = mxGetPr (P); -static double *rates = mxGetPr (dX); static double *states = mxGetPr (X); static double *simtime = mxGetPr (T); void update_parameters_from_simulink (SimStruct *S) { - std::cerr << "Parameters:\t"; for (int i = 0; i < MTTNPAR; i++) { parameters [i] = *mxGetPr (ssGetSFcnParam (S, i)); - std::cerr << parameters [i] << ' '; } - std::cerr << std::endl; } void update_states_from_simulink (SimStruct *S) { static double *x; - std::cerr << "States:\t\t"; x = ssGetContStates (S); for (int i = 0; i < MTTNX; i++) { states [i] = x [i]; - std::cerr << states [i] << ' '; } - std::cerr << std::endl; } void update_inputs_from_simulink (SimStruct *S) { - std::cerr << "Inputs:\t\t"; for (int i = 0; i < MTTNU; i++) { inputs [i] = *ssGetInputPortRealSignalPtrs (S, i)[0]; - std::cerr << inputs [i] << ' '; } - std::cerr << std::endl; } void update_simtime_from_simulink (SimStruct *S) { simtime [0] = ssGetT (S); - std::cerr << "Time:\t\t" << simtime [0] << std::endl; } // S-function methods static void mdlInitializeSizes(SimStruct *S) @@ -116,16 +101,13 @@ plhs[0] = X; prhs[0] = P; mexCallMATLAB (1, plhs, 1, prhs, "_state"); - std::cerr << "Initial states;\t"; for (int i = 0; i < MTTNX; i++) { ssGetContStates (S)[i] = states [i]; - std::cerr << states [i] << ' '; } - std::cerr << std::endl; } static void mdlOutputs(SimStruct *S, int_T tid) { static mxArray *plhs[1]; @@ -134,26 +116,23 @@ update_states_from_simulink (S); update_inputs_from_simulink (S); update_simtime_from_simulink (S); update_parameters_from_simulink (S); - plhs[0] = Y; prhs[0] = X; prhs[1] = U; prhs[2] = T; prhs[3] = P; UNUSED_ARG(tid); // not used in single tasking mode mexCallMATLAB (1, plhs, 4, prhs, "_odeo"); + double *outputs = mxGetPr (plhs[0]); - std::cerr << "Outputs:\t"; for (int i = 0; i < MTTNY; i++) { ssGetOutputPortRealSignal (S,i)[0] = outputs [i]; - std::cerr << outputs [i] << ' '; } - std::cerr << std::endl; } #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { @@ -163,24 +142,21 @@ update_states_from_simulink (S); update_inputs_from_simulink (S); update_simtime_from_simulink (S); update_parameters_from_simulink (S); - plhs[0] = dX; prhs[0] = X; prhs[1] = U; prhs[2] = T; prhs[3] = P; mexCallMATLAB (1, plhs, 4, prhs, "_ode"); - - std::cerr << "Rates:\t\t"; + double *rates= mxGetPr (plhs[0]); + for (int i = 0; i < MTTNX; i++) { ssGetdX (S)[i] = rates [i]; - std::cerr << rates [i] << ' '; } - std::cerr << std::endl; } static void mdlTerminate(SimStruct *S) { UNUSED_ARG(S);