Index: mttroot/mtt/bin/trans/mtt_header ================================================================== --- mttroot/mtt/bin/trans/mtt_header +++ mttroot/mtt/bin/trans/mtt_header @@ -10,10 +10,18 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.50 2002/05/15 14:22:25 geraint +## Code for Simulink S-function target written direct to sfun.cc instead of +## calling .mexglx files. This eliminates the sfun dependency on Octave +## ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine +## (can't test this yet). +## +## added sfun.zip target to create source code to export. +## ## Revision 1.49 2002/05/11 01:14:17 geraint ## Fix for [ 553218 ] simpar.oct and simpar.m different. ## Translation added between ColumnVector in base .cc and Octave_map in .oct. ## ## Revision 1.48 2002/05/08 14:51:03 geraint @@ -208,10 +216,13 @@ rep=$2 language=$3 fun_name=${1}_${2} other=$4 # Anything else eg stdin + +insertor=\<\< # help emacs sh-mode out with C++ lines + if [ -z "$system" ]; then echo 'Usage: mtt_header sys rep lang [stdin]' exit fi @@ -467,18 +478,16 @@ var_declaration="double " minusone="-1" map="_map" declaredummies=yes ;; - sfun) - modeline="// -*-c++-*- Put Emacs into c++-mode"; - Lc='//' - Rc='' + c) + modeline="/* -*-c-*- Put Emacs into c-mode */"; + Lc='/*' + Rc='*/' Lb='[' Rb=']' - start="## BEGIN Code" - finish="## END Code" constant_declaration="const double " var_declaration="double " minusone="-1" ;; *) @@ -851,27 +860,27 @@ ;; esac done } -map_mex_inputs () +map_mex_cc_inputs () { s=${1:-""} # comma separated input list if [ -z ${s:-""} ];then return; fi c=`get_field ${s} 0` # count of inputs i=0 cat <"} args=${2:-""} cat < ${TMP} - echo "## END Code" >> ${TMP} + c) + mtt_header ${SYS} ${REP} "c" > ${TMP} find_code ${TMP} head > ${OUT} find_code ${IN} body |\ decrement_indices |\ - fix_comment_delimiter |\ + fix_comment_delimiter c |\ fix_pow |\ strip_junk |\ ${PARSER} >> ${OUT} find_code ${TMP} foot >> ${OUT} rm ${TMP} @@ -190,11 +196,11 @@ find_code ${TMP} head > ${OUT} rep_declarations >> ${OUT} find_code ${IN} body |\ decrement_indices |\ fortran_to_c_paren |\ - fix_comment_delimiter |\ + fix_comment_delimiter cc |\ fix_pow |\ strip_junk |\ ${PARSER} >> ${OUT} rep_footer >> ${OUT} find_code ${TMP} foot >> ${OUT} Index: mttroot/mtt/cc/sympar_txt2h.sh ================================================================== --- mttroot/mtt/cc/sympar_txt2h.sh +++ mttroot/mtt/cc/sympar_txt2h.sh @@ -1,8 +1,12 @@ #! /bin/sh # $Id$ # $Log$ +# Revision 1.5 2002/04/28 18:58:06 geraint +# Fixed [ 549658 ] awk should be gawk. +# Replaced calls to awk with call to gawk. +# # Revision 1.4 2001/08/24 21:41:04 geraint # Fixed problem with declaration when there are no numerical parameters. # # Revision 1.3 2001/03/19 02:28:53 geraint # Branch merge: merging-ode2odes-exe back to MAIN. @@ -54,11 +58,11 @@ IN=${SYS}_sympar.txt OUT=${SYS}_sympar.h declare_sys_param () { -cat ${IN} | gawk '(NF>0){printf ("static double %s MTT_UNUSED;\t// %s\n", tolower($1), $2)}' +cat ${IN} | gawk '(NF>0){printf ("static double %s MTT_UNUSED;\t/* %s\t*/\n", tolower($1), $2)}' } declare_temp_vars () { for name in ${TMP_VAR_NAMES} Index: mttroot/mtt/lib/rep/sfun_rep/Makefile ================================================================== --- mttroot/mtt/lib/rep/sfun_rep/Makefile +++ mttroot/mtt/lib/rep/sfun_rep/Makefile @@ -1,29 +1,51 @@ #! /usr/bin/make -f -SRC = $(SYS)_sfun.cc $(SYS)_def.h $(SYS)_ae.sfun $(SYS)_ode.sfun $(SYS)_odeo.sfun $(SYS)_state.sfun - all: $(SYS)_sfun.mexglx -$(SYS)_sfun.mexglx: $(SRC) - mex $(SYS)_sfun.cc +$(SYS)_sfun.mexglx: $(SYS)_sfun.c $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx + echo Creating $@ + mex $(SYS)_sfun.c + cp *_sfun*mexglx .. + +$(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl + echo Creating $@ + cat $^ | sed 's//$(SYS)/g' > $@ + +$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c $(SYS)_def.h $(SYS)_ae.c + echo Creating $@ + mex $(SYS)_sfun_ae.c -$(SYS)_sfun.cc:: ${MTT_REP}/sfun_rep/sfun.cc.tmpl +$(SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/ae.c.tmpl + echo Creating $@ cat $^ | sed 's//$(SYS)/g' > $@ -$(SYS)_sfun.zip: $(SRC) +$(SYS)_sfun.zip: $(SYS)_sfun.c $(SYS)_sfun_ae.c $(SYS)_def.h $(SYS)_sympar.h $(SYS)_ae.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c README + echo Creating $@ zip $@ $^ -$(SYS)_ae.sfun: $(SYS)_ae.m - ${MTT_CC}/mtt_m2cc.sh $(SYS) ae sfun cat - -$(SYS)_ode.sfun: $(SYS)_ode.m - ${MTT_CC}/mtt_m2cc.sh $(SYS) ode sfun cat - -$(SYS)_odeo.sfun: $(SYS)_odeo.m - ${MTT_CC}/mtt_m2cc.sh $(SYS) odeo sfun cat - -$(SYS)_state.sfun: $(SYS)_state.m - ${MTT_CC}/mtt_m2cc.sh $(SYS) state sfun cat +README:: ${MTT_REP}/sfun_rep/README.tmpl + echo Creating $@ + cat $^ | sed 's//$(SYS)/g' > $@ + +$(SYS)_ae.c: $(SYS)_ae.m + echo Creating $@ + ${MTT_CC}/mtt_m2cc.sh $(SYS) ae c cat + +$(SYS)_numpar.c: $(SYS)_numpar.m + echo Creating $@ + ${MTT_CC}/mtt_m2cc.sh $(SYS) numpar c cat + +$(SYS)_ode.c: $(SYS)_ode.m + echo Creating $@ + ${MTT_CC}/mtt_m2cc.sh $(SYS) ode c cat + +$(SYS)_odeo.c: $(SYS)_odeo.m + echo Creating $@ + ${MTT_CC}/mtt_m2cc.sh $(SYS) odeo c cat + +$(SYS)_state.c: $(SYS)_state.m + echo Creating $@ + ${MTT_CC}/mtt_m2cc.sh $(SYS) state c cat %:: mtt -q $(OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'` ADDED mttroot/mtt/lib/rep/sfun_rep/README.tmpl Index: mttroot/mtt/lib/rep/sfun_rep/README.tmpl ================================================================== --- /dev/null +++ mttroot/mtt/lib/rep/sfun_rep/README.tmpl @@ -0,0 +1,8 @@ + +To build a Simulink funtion of the model without using MTT: + +mex _sfun.c + +If numerical solution of algebraic equations is also required: + +mex _sfun_ae.c ADDED mttroot/mtt/lib/rep/sfun_rep/ae.c.tmpl Index: mttroot/mtt/lib/rep/sfun_rep/ae.c.tmpl ================================================================== --- /dev/null +++ mttroot/mtt/lib/rep/sfun_rep/ae.c.tmpl @@ -0,0 +1,106 @@ +/* -*-c-*- Put emacs into c-mode */ + +#include +#include + +#include +#include "_def.h" + +/* utility procedures */ + +double * +array_of_double (size_t n) +{ + void *p = calloc (n, sizeof (double)); + if (! p) { + fprintf (stderr, "*** Error: failed to allocate memory\n"); + } + return (double *) p; +} + +/* system equations */ + +static double * +_ae (double *mttyz, + const double *mttx, + const double *mttu, + const double mttt, + const double *mttpar) +{ +#include "_ae.c" +} + +/* generic mex function */ + +#ifdef __cplusplus +extern "C" { +#endif + +void +mexFunction (int nlhs, mxArray *plhs[], + int nrhs, const mxArray *prhs[]) +{ + double *mttyz; /* residuals */ + + double *mttx; /* states */ + double *mttu; /* known + unknown inputs */ + double mttt; /* time */ + double *mttpar; /* parameters */ + + unsigned int i; + double *p; + + mttyz = array_of_double (MTTNYZ); + + mttx = array_of_double (MTTNX); + mttu = array_of_double (MTTNU + MTTNYZ); + mttpar = array_of_double (MTTNPAR); + + /* get trial values */ + p = mxGetPr (prhs[0]); + for (i = 0; i < MTTNYZ; i++) { + mttu[MTTNU + i] = p[i]; + } + + /* get states */ + p = mxGetPr (prhs[1]); + for (i = 0; i < MTTNX; i++) { + mttx[i] = p[i]; + } + + /* get known inputs */ + p = mxGetPr (prhs[2]); + for (i = 0; i < MTTNU; i++) { + mttu[i] = p[i]; + } + + /* get time */ + p = mxGetPr (prhs[3]); + mttt = *p; + + /* get parameters */ + p = mxGetPr (prhs[4]); + for (i = 0; i < MTTNPAR; i++) { + mttpar[i] = p[i]; + } + + /* evaluate residuals */ + _ae (mttyz, mttx, mttu, mttt, mttpar); + + /* return residuals */ + plhs[0] = mxCreateDoubleMatrix (MTTNYZ, 1, mxREAL); + p = mxGetPr (plhs[0]); + for (i = 0; i < MTTNYZ; i++) { + p[i] = mttyz[i]; + } + + /* release memory */ + free (mttx); + free (mttu); + free (mttpar); + free (mttyz); +} + +#ifdef __cplusplus +} +#endif ADDED mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl Index: mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl ================================================================== --- /dev/null +++ mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl @@ -0,0 +1,315 @@ +/* -*-c-*- + * _sfun.c: + * Matlab S-function simulation of + */ + +#define S_FUNCTION_NAME _sfun +#define S_FUNCTION_LEVEL 2 + +#if (0) /* DEBUG? */ +#define PRINT_ENTER(f) fprintf (stderr, "Entered %s\n", f) +#define PRINT_LEAVE(f) fprintf (stderr, "Leaving %s\n", f) +#else +#define PRINT_ENTER(f) +#define PRINT_LEAVE(f) +#endif /* DEBUG? */ + +#include +#include + +#include "simstruc.h" +#include "_def.h" + +static double *mttdx; /* pointer to rates */ +static double *mttu; /* pointer to inputs */ +static double *mttpar; /* pointer to parameters */ +static double *mttx; /* pointer to states */ +static double *mtty; /* pointer to outputs */ +static double *mttyz; /* pointer to residuals */ +static double mttt; /* time */ + +static unsigned int i; /* loop counter */ + +/* system equations */ + +static void +_ae (void) +{ +#include "_ae.c" +} + +static void +_ode (void) +{ +#include "_ode.c" +} + +static void +_odeo (void) +{ +#include "_odeo.c" +} + +static void +_state (void) +{ +#include "_state.c" +} + +/* utility procedures */ + +static double * +array_of_double (size_t n) +{ + void *p = calloc (n, sizeof (double)); + if (! p) { + fprintf (stderr, "*** Error: failed to allocate memory\n"); + } + return (double *) p; +} + +static void +initialise_arrays (void) +{ + PRINT_ENTER("initialise_arrays"); + + mttdx = array_of_double (MTTNX); + mttpar = array_of_double (MTTNPAR); + mttu = array_of_double (MTTNU + MTTNYZ); + mttx = array_of_double (MTTNX); + mtty = array_of_double (MTTNY); + mttyz = array_of_double (MTTNYZ); + + PRINT_LEAVE("initialise_arrays"); +} + +static void +update_states_from_simulink (SimStruct *S) +{ + PRINT_ENTER("update_states_from_simulink"); + for (i = 0; i < MTTNX; i++) { + mttx[i] = ssGetContStates (S)[i]; + } + PRINT_LEAVE("update_states_from_simulink"); +} + +static void +update_inputs_from_simulink (SimStruct *S) +{ + PRINT_ENTER("update_inputs_from_simulink"); + for (i = 0; i < MTTNU; i++) { + mttu[i] = *ssGetInputPortRealSignalPtrs (S, i)[0]; + } + PRINT_LEAVE("update_inputs_from_simulink"); +} + +static void +update_inputs_from_solver (void) +{ + mxArray *MTT_MATLAB_P; + mxArray *MTT_MATLAB_T; + mxArray *MTT_MATLAB_U; + mxArray *MTT_MATLAB_Ui; + mxArray *MTT_MATLAB_X; + + double *p; + + PRINT_ENTER ("update_inputs_from_solver"); + + /* starting value for solver - start with zero */ + MTT_MATLAB_Ui = mxCreateDoubleMatrix (MTTNYZ, 1, mxREAL); + mxSetName (MTT_MATLAB_Ui, "MTT_Ui"); + p = mxGetPr (MTT_MATLAB_Ui); + for (i = 0; i < MTTNYZ; i++) { + p[i] = 0.0; + } + mexPutArray (MTT_MATLAB_Ui, "base"); + + /* put states into matlab workspace */ + MTT_MATLAB_X = mxCreateDoubleMatrix (MTTNX, 1, mxREAL); + mxSetName (MTT_MATLAB_X, "MTT_X"); + p = mxGetPr (MTT_MATLAB_X); + for (i = 0; i < MTTNX; i++) { + p[i] = mttx[i]; + } + mexPutArray (MTT_MATLAB_X, "base"); + + /* put known inputs into matlab workspace */ + MTT_MATLAB_U = mxCreateDoubleMatrix (MTTNU, 1, mxREAL); + mxSetName (MTT_MATLAB_U, "MTT_U"); + p = mxGetPr (MTT_MATLAB_U); + for (i = 0; i < MTTNU; i++) { + p[i] = mttu[i]; + } + mexPutArray (MTT_MATLAB_U, "base"); + + /* put time into matlab workspace */ + MTT_MATLAB_T = mxCreateDoubleMatrix (1, 1, mxREAL); + mxSetName (MTT_MATLAB_T, "MTT_T"); + *mxGetPr (MTT_MATLAB_T) = mttt; + mexPutArray (MTT_MATLAB_T, "base"); + + /* put parameters into matlab workspace */ + MTT_MATLAB_P = mxCreateDoubleMatrix (MTTNPAR, 1, mxREAL); + mxSetName (MTT_MATLAB_P, "MTT_P"); + p = mxGetPr (MTT_MATLAB_P); + for (i = 0; i < MTTNPAR; i++) { + p[i] = mttpar[i]; + } + mexPutArray (MTT_MATLAB_P, "base"); + + /* call fsolve */ + mexEvalString ("MTT_Ui = fsolve (@_sfun_ae, MTT_Ui, optimset('display','off'), MTT_X, MTT_U, MTT_T, MTT_P);"); + + /* retrieve result */ + MTT_MATLAB_Ui = mexGetArray ("MTT_Ui", "base"); + p = mxGetPr (MTT_MATLAB_Ui); + for (i = 0; i < MTTNYZ; i++) { + mttu[MTTNU + i] = p[i]; + } + + /* free memory */ + mxDestroyArray (MTT_MATLAB_P); + mxDestroyArray (MTT_MATLAB_T); + mxDestroyArray (MTT_MATLAB_U); + mxDestroyArray (MTT_MATLAB_Ui); + mxDestroyArray (MTT_MATLAB_X); + + PRINT_LEAVE ("update_inputs_from_solver"); +} + +static void +update_simtime_from_simulink (SimStruct *S) +{ + PRINT_ENTER("update_simtime_from_simulink"); + mttt = ssGetT (S); + PRINT_LEAVE("update_simtime_from_simulink"); +} + +/* S-function methods */ + +static void mdlInitializeSizes(SimStruct *S) +{ + PRINT_ENTER("mdlInitializeSizes"); + ssSetNumSFcnParams(S, 0); + if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { + PRINT_LEAVE("mdlInitializeSizes"); + return; + } + + ssSetNumContStates(S, MTTNX); + ssSetNumDiscStates(S, 0); + + if (!ssSetNumInputPorts(S, MTTNU)) return; + for (i = 0; i < MTTNU; i++) { + ssSetInputPortWidth(S, i, 1); + ssSetInputPortDirectFeedThrough(S, i, 1); + } + + if (!ssSetNumOutputPorts(S, MTTNY)) return; + for (i = 0; i < MTTNY; i++) { + ssSetOutputPortWidth(S, i, 1); + } + + ssSetNumSampleTimes(S, 1); + ssSetNumRWork(S, 0); + ssSetNumIWork(S, 0); + ssSetNumPWork(S, 0); + ssSetNumModes(S, 0); + ssSetNumNonsampledZCs(S, 0); + + ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); + + initialise_arrays (); + PRINT_LEAVE("mdlInitializeSizes"); +} + +static void mdlInitializeSampleTimes(SimStruct *S) +{ + PRINT_ENTER("mdlInitializeSampleTimes"); + ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); + ssSetOffsetTime(S, 0, 0.0); + PRINT_LEAVE("mdlInitializeSampleTimes"); +} + +#define MDL_INITIALIZE_CONDITIONS +static void mdlInitializeConditions(SimStruct *S) +{ +#include "_sympar.h" + + PRINT_ENTER("mdlInitializeConditions"); + +#include "_numpar.c" + + _state (); + + for (i = 0; i < MTTNX; i++) { + ssGetContStates (S)[i] = mttx[i]; + } + + PRINT_LEAVE("leaving mdlInitializeConditions"); +} + +static void mdlOutputs(SimStruct *S, int_T tid) +{ + PRINT_ENTER("entered mdlOutputs"); + + update_states_from_simulink (S); + update_inputs_from_simulink (S); + if (MTTNYZ > 0) { + update_inputs_from_solver (); + } + update_simtime_from_simulink (S); + + UNUSED_ARG(tid); /* not used in single tasking mode */ + + _odeo (); + + for (i = 0; i < MTTNY; i++) { + ssGetOutputPortRealSignal (S,i)[0] = mtty[i]; + } + + PRINT_LEAVE("leaving mdlOutputs"); +} + +#define MDL_DERIVATIVES +static void mdlDerivatives(SimStruct *S) +{ + PRINT_ENTER("entered mdlDerivatives\n"); + + update_states_from_simulink (S); + update_inputs_from_simulink (S); + if (MTTNYZ > 0) { + update_inputs_from_solver (); + } + update_simtime_from_simulink (S); + + _ode (); + + for (i = 0; i < MTTNX; i++) { + ssGetdX (S)[i] = mttdx[i]; + } + + PRINT_LEAVE("leaving mdlDerivatives"); +} + +static void mdlTerminate(SimStruct *S) +{ + PRINT_ENTER("entered mdlTerminate"); + UNUSED_ARG(S); + + free (mttdx); + free (mttpar); + free (mttu); + free (mttx); + free (mtty); + free (mttyz); + + PRINT_LEAVE("leaving mdlTerminate"); +} + +#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ +#include "simulink.c" /* MEX-file interface mechanism */ +#else +#include "cg_sfun.h" /* Code generation registration function */ +#endif DELETED mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl Index: mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl ================================================================== --- mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl +++ /dev/null @@ -1,150 +0,0 @@ -// -*-c++-*- -// _sfun.c: -// Matlab S-function simulation of - -#define S_FUNCTION_NAME _sfun -#define S_FUNCTION_LEVEL 2 - -#include "simstruc.h" -#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 mxArray *YZ = mxCreateDoubleMatrix (MTTNYZ , 1, mxREAL); - -static double *mttdx = mxGetPr (dX); -static double *mttu = mxGetPr (U); -static double *mttpar = mxGetPr (P); -static double *mttx = mxGetPr (X); -static double *mtty = mxGetPr (Y); -static double *mttyz = mxGetPr (YZ); -static double *mtttp = mxGetPr (T); - -void -update_parameters_from_simulink (SimStruct *S) -{ - for (int i = 0; i < MTTNPAR; i++) { - mttpar [i] = *mxGetPr (ssGetSFcnParam (S, i)); - } -} - -void -update_states_from_simulink (SimStruct *S) -{ - static double *x; - x = ssGetContStates (S); - for (int i = 0; i < MTTNX; i++) { - mttx [i] = x [i]; - } -} - -void -update_inputs_from_simulink (SimStruct *S) -{ - for (int i = 0; i < MTTNU; i++) { - mttu [i] = *ssGetInputPortRealSignalPtrs (S, i)[0]; - } -} - -void -update_simtime_from_simulink (SimStruct *S) -{ - mtttp [0] = ssGetT (S); -} - -// S-function methods - -static void mdlInitializeSizes(SimStruct *S) -{ - ssSetNumSFcnParams(S, MTTNPAR); - if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { - return; - } - - ssSetNumContStates(S, MTTNX); - ssSetNumDiscStates(S, 0); - - if (!ssSetNumInputPorts(S, MTTNU)) return; - for (int i = 0; i < MTTNU; i++) { - ssSetInputPortWidth(S, i, 1); - ssSetInputPortDirectFeedThrough(S, i, 1); - } - - if (!ssSetNumOutputPorts(S, MTTNY)) return; - for (int i = 0; i < MTTNY; i++) { - ssSetOutputPortWidth(S, i, 1); - } - - ssSetNumSampleTimes(S, 1); - ssSetNumRWork(S, 0); - ssSetNumIWork(S, 0); - ssSetNumPWork(S, 0); - ssSetNumModes(S, 0); - ssSetNumNonsampledZCs(S, 0); - - ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); -} - -static void mdlInitializeSampleTimes(SimStruct *S) -{ - ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); - ssSetOffsetTime(S, 0, 0.0); -} - -#define MDL_INITIALIZE_CONDITIONS -static void mdlInitializeConditions(SimStruct *S) -{ - update_parameters_from_simulink (S); - -#include "_state.sfun" - - for (int i = 0; i < MTTNX; i++) { - ssGetContStates (S)[i] = mttx [i]; - } -} - -static void mdlOutputs(SimStruct *S, int_T tid) -{ - update_states_from_simulink (S); - update_inputs_from_simulink (S); - update_simtime_from_simulink (S); - update_parameters_from_simulink (S); - - UNUSED_ARG(tid); // not used in single tasking mode - -#include "_odeo.sfun" - - for (int i = 0; i < MTTNY; i++) { - ssGetOutputPortRealSignal (S,i)[0] = mtty [i]; - } -} - -#define MDL_DERIVATIVES -static void mdlDerivatives(SimStruct *S) -{ - update_states_from_simulink (S); - update_inputs_from_simulink (S); - update_simtime_from_simulink (S); - update_parameters_from_simulink (S); - -#include "_ode.sfun" - - for (int i = 0; i < MTTNX; i++) { - ssGetdX (S)[i] = mttdx [i]; - } -} - -static void mdlTerminate(SimStruct *S) -{ - UNUSED_ARG(S); -} - -#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ -#include "simulink.c" /* MEX-file interface mechanism */ -#else -#include "cg_sfun.h" /* Code generation registration function */ -#endif