/**
 * sipmjcsf.c
 *
 *    ABSTRACT:
 *      The purpose of this sfunction is to call a simple legacy
 *      function during simulation:
 *
 *         void sipmj(single y1[size(u3,1)],single y2[size(u2,1)],boolean y3[1],single u1[],single u2[][],single u3[][],single u4[],single u5[],single u6[],single u7[],single u8[][],single u9[],single u10[],single u11[],single p1,int32 p2,single work1[size(u1,1)+4*size(u2,1)+6*size(u8,1)],int32 size(u2,1),int32 size(u3,1),int32 size(u8,1))
 *
 *    Simulink version           : 10.6 (R2022b) 13-May-2022
 *    C source code generated on : 27-Jan-2023 10:44:42
 *
 * THIS S-FUNCTION IS GENERATED BY THE LEGACY CODE TOOL AND MAY NOT WORK IF MODIFIED
 */

/**
     %%%-MATLAB_Construction_Commands_Start
     def = legacy_code('initialize');
     def.SFunctionName = 'sipmjcsf';
     def.OutputFcnSpec = 'void sipmj(single y1[size(u3,1)],single y2[size(u2,1)],boolean y3[1],single u1[],single u2[][],single u3[][],single u4[],single u5[],single u6[],single u7[],single u8[][],single u9[],single u10[],single u11[],single p1,int32 p2,single work1[size(u1,1)+4*size(u2,1)+6*size(u8,1)],int32 size(u2,1),int32 size(u3,1),int32 size(u8,1))';
     def.HeaderFiles = {'meq.h'};
     def.HostLibFiles = {'meqld('host')'};
     def.TargetLibFiles = {'meqld('target')'};
     def.IncPaths = {'C:\Users\amerle\codes\meq'};
     def.LibPaths = {'C:\Users\amerle\codes\meq'};
     legacy_code('sfcn_cmex_generate', def);
     legacy_code('compile', def);
     %%%-MATLAB_Construction_Commands_End
 */

/* Must specify the S_FUNCTION_NAME as the name of the S-function */
#define S_FUNCTION_NAME  sipmjcsf
#define S_FUNCTION_LEVEL 2

/**
 * Need to include simstruc.h for the definition of the SimStruct and
 * its associated macro definitions.
 */
#include "simstruc.h"

/* Specific header file(s) required by the legacy code function */
#include "meq.h"

#define EDIT_OK(S, P_IDX) \
       (!((ssGetSimMode(S)==SS_SIMMODE_SIZES_CALL_ONLY) && mxIsEmpty(ssGetSFcnParam(S, P_IDX))))


#define MDL_CHECK_PARAMETERS
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
/* Function: mdlCheckParameters ===========================================
 * Abstract:
 *   mdlCheckParameters verifies new parameter settings whenever parameter
 *   change or are re-evaluated during a simulation. When a simulation is
 *   running, changes to S-function parameters can occur at any time during
 *   the simulation loop.
 */
static void mdlCheckParameters(SimStruct *S)
{
    /* Check the parameter 1 */
    if (EDIT_OK(S, 0)) {
        int_T dimsArray[2] = {1, 1};

        /* Check the parameter attributes */
        ssCheckSFcnParamValueAttribs(S, 0, "P1", DYNAMICALLY_TYPED, 2, dimsArray, 0);
    } /* if */

    /* Check the parameter 2 */
    if (EDIT_OK(S, 1)) {
        int_T dimsArray[2] = {1, 1};

        /* Check the parameter attributes */
        ssCheckSFcnParamValueAttribs(S, 1, "P2", DYNAMICALLY_TYPED, 2, dimsArray, 0);
    } /* if */

}
#endif

#define MDL_PROCESS_PARAMETERS
#if defined(MDL_PROCESS_PARAMETERS) && defined(MATLAB_MEX_FILE)
/* Function: mdlProcessParameters =========================================
 * Abstract:
 *   Update run-time parameters.
 */
static void mdlProcessParameters(SimStruct *S)
{
    ssUpdateAllTunableParamsAsRunTimeParams(S);
}
#endif

/* Function: mdlInitializeSizes ===========================================
 * Abstract:
 *   The sizes information is used by Simulink to determine the S-function
 *   block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    /* Number of expected parameters */
    ssSetNumSFcnParams(S, 2);

    #if defined(MATLAB_MEX_FILE) 
    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
        /**
         * If the number of expected input parameters is not equal
         * to the number of parameters entered in the dialog box return.
         * Simulink will generate an error indicating that there is a
         * parameter mismatch.
         */
        mdlCheckParameters(S);
        if (ssGetErrorStatus(S) != NULL) return;
    } else {
        /* Return if number of expected != number of actual parameters */
        return;
    } /* if */
    #endif 

    /* Set the parameter's tunability */
    ssSetSFcnParamTunable(S, 0, 1);
    ssSetSFcnParamTunable(S, 1, 1);

    /* Set the number of work vectors */
    if (!ssSetNumDWork(S, 1)) return;
    ssSetNumPWork(S, 0);

    /* Configure the dwork 1 (work1) */
    ssSetDWorkDataType(S, 0, SS_SINGLE);
    ssSetDWorkUsageType(S, 0, SS_DWORK_USED_AS_DWORK);
    ssSetDWorkName(S, 0, "work1");
    ssSetDWorkWidth(S, 0, DYNAMICALLY_SIZED);
    ssSetDWorkComplexSignal(S, 0, COMPLEX_NO);

    /* Set the number of input ports */
    if (!ssSetNumInputPorts(S, 11)) return;

    /* Configure the input port 1 */
    ssSetInputPortDataType(S, 0, SS_SINGLE);
    {
        int_T u1Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 0, u1Width);
    }
    ssSetInputPortComplexSignal(S, 0, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 0, 1);
    ssSetInputPortAcceptExprInRTW(S, 0, 0);
    ssSetInputPortOverWritable(S, 0, 0);
    ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 0, 1);
    ssSetInputPortDimensionsMode(S, 0, FIXED_DIMS_MODE);

    /* Configure the input port 2 */
    ssSetInputPortDataType(S, 1, SS_SINGLE);
    {
        int_T u2NumRows = DYNAMICALLY_SIZED;
        int_T u2NumCols = DYNAMICALLY_SIZED;
        ssSetInputPortMatrixDimensions(S, 1, u2NumRows, u2NumCols);
    }
    ssSetInputPortComplexSignal(S, 1, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 1, 1);
    ssSetInputPortAcceptExprInRTW(S, 1, 0);
    ssSetInputPortOverWritable(S, 1, 0);
    ssSetInputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 1, 1);
    ssSetInputPortDimensionsMode(S, 1, FIXED_DIMS_MODE);

    /* Configure the input port 3 */
    ssSetInputPortDataType(S, 2, SS_SINGLE);
    {
        int_T u3NumRows = DYNAMICALLY_SIZED;
        int_T u3NumCols = DYNAMICALLY_SIZED;
        ssSetInputPortMatrixDimensions(S, 2, u3NumRows, u3NumCols);
    }
    ssSetInputPortComplexSignal(S, 2, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 2, 1);
    ssSetInputPortAcceptExprInRTW(S, 2, 0);
    ssSetInputPortOverWritable(S, 2, 0);
    ssSetInputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 2, 1);
    ssSetInputPortDimensionsMode(S, 2, FIXED_DIMS_MODE);

    /* Configure the input port 4 */
    ssSetInputPortDataType(S, 3, SS_SINGLE);
    {
        int_T u4Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 3, u4Width);
    }
    ssSetInputPortComplexSignal(S, 3, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 3, 1);
    ssSetInputPortAcceptExprInRTW(S, 3, 0);
    ssSetInputPortOverWritable(S, 3, 0);
    ssSetInputPortOptimOpts(S, 3, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 3, 1);
    ssSetInputPortDimensionsMode(S, 3, FIXED_DIMS_MODE);

    /* Configure the input port 5 */
    ssSetInputPortDataType(S, 4, SS_SINGLE);
    {
        int_T u5Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 4, u5Width);
    }
    ssSetInputPortComplexSignal(S, 4, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 4, 1);
    ssSetInputPortAcceptExprInRTW(S, 4, 0);
    ssSetInputPortOverWritable(S, 4, 0);
    ssSetInputPortOptimOpts(S, 4, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 4, 1);
    ssSetInputPortDimensionsMode(S, 4, FIXED_DIMS_MODE);

    /* Configure the input port 6 */
    ssSetInputPortDataType(S, 5, SS_SINGLE);
    {
        int_T u6Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 5, u6Width);
    }
    ssSetInputPortComplexSignal(S, 5, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 5, 1);
    ssSetInputPortAcceptExprInRTW(S, 5, 0);
    ssSetInputPortOverWritable(S, 5, 0);
    ssSetInputPortOptimOpts(S, 5, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 5, 1);
    ssSetInputPortDimensionsMode(S, 5, FIXED_DIMS_MODE);

    /* Configure the input port 7 */
    ssSetInputPortDataType(S, 6, SS_SINGLE);
    {
        int_T u7Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 6, u7Width);
    }
    ssSetInputPortComplexSignal(S, 6, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 6, 1);
    ssSetInputPortAcceptExprInRTW(S, 6, 0);
    ssSetInputPortOverWritable(S, 6, 0);
    ssSetInputPortOptimOpts(S, 6, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 6, 1);
    ssSetInputPortDimensionsMode(S, 6, FIXED_DIMS_MODE);

    /* Configure the input port 8 */
    ssSetInputPortDataType(S, 7, SS_SINGLE);
    {
        int_T u8NumRows = DYNAMICALLY_SIZED;
        int_T u8NumCols = DYNAMICALLY_SIZED;
        ssSetInputPortMatrixDimensions(S, 7, u8NumRows, u8NumCols);
    }
    ssSetInputPortComplexSignal(S, 7, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 7, 1);
    ssSetInputPortAcceptExprInRTW(S, 7, 0);
    ssSetInputPortOverWritable(S, 7, 0);
    ssSetInputPortOptimOpts(S, 7, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 7, 1);
    ssSetInputPortDimensionsMode(S, 7, FIXED_DIMS_MODE);

    /* Configure the input port 9 */
    ssSetInputPortDataType(S, 8, SS_SINGLE);
    {
        int_T u9Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 8, u9Width);
    }
    ssSetInputPortComplexSignal(S, 8, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 8, 1);
    ssSetInputPortAcceptExprInRTW(S, 8, 0);
    ssSetInputPortOverWritable(S, 8, 0);
    ssSetInputPortOptimOpts(S, 8, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 8, 1);
    ssSetInputPortDimensionsMode(S, 8, FIXED_DIMS_MODE);

    /* Configure the input port 10 */
    ssSetInputPortDataType(S, 9, SS_SINGLE);
    {
        int_T u10Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 9, u10Width);
    }
    ssSetInputPortComplexSignal(S, 9, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 9, 1);
    ssSetInputPortAcceptExprInRTW(S, 9, 0);
    ssSetInputPortOverWritable(S, 9, 0);
    ssSetInputPortOptimOpts(S, 9, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 9, 1);
    ssSetInputPortDimensionsMode(S, 9, FIXED_DIMS_MODE);

    /* Configure the input port 11 */
    ssSetInputPortDataType(S, 10, SS_SINGLE);
    {
        int_T u11Width = DYNAMICALLY_SIZED;
        ssSetInputPortWidth(S, 10, u11Width);
    }
    ssSetInputPortComplexSignal(S, 10, COMPLEX_NO);
    ssSetInputPortDirectFeedThrough(S, 10, 1);
    ssSetInputPortAcceptExprInRTW(S, 10, 0);
    ssSetInputPortOverWritable(S, 10, 0);
    ssSetInputPortOptimOpts(S, 10, SS_REUSABLE_AND_LOCAL);
    ssSetInputPortRequiredContiguous(S, 10, 1);
    ssSetInputPortDimensionsMode(S, 10, FIXED_DIMS_MODE);

    /* Set the number of output ports */
    if (!ssSetNumOutputPorts(S, 3)) return;

    /* Configure the output port 1 */
    ssSetOutputPortDataType(S, 0, SS_SINGLE);
    {
        int_T y1Width = DYNAMICALLY_SIZED;
        ssSetOutputPortWidth(S, 0, y1Width);
    }
    ssSetOutputPortComplexSignal(S, 0, COMPLEX_NO);
    ssSetOutputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
    ssSetOutputPortOutputExprInRTW(S, 0, 0);
    ssSetOutputPortDimensionsMode(S, 0, FIXED_DIMS_MODE);

    /* Configure the output port 2 */
    ssSetOutputPortDataType(S, 1, SS_SINGLE);
    {
        int_T y2Width = DYNAMICALLY_SIZED;
        ssSetOutputPortWidth(S, 1, y2Width);
    }
    ssSetOutputPortComplexSignal(S, 1, COMPLEX_NO);
    ssSetOutputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL);
    ssSetOutputPortOutputExprInRTW(S, 1, 0);
    ssSetOutputPortDimensionsMode(S, 1, FIXED_DIMS_MODE);

    /* Configure the output port 3 */
    ssSetOutputPortDataType(S, 2, SS_BOOLEAN);
    {
        int_T y3Width = 1;
        ssSetOutputPortWidth(S, 2, y3Width);
    }
    ssSetOutputPortComplexSignal(S, 2, COMPLEX_NO);
    ssSetOutputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL);
    ssSetOutputPortOutputExprInRTW(S, 2, 0);
    ssSetOutputPortDimensionsMode(S, 2, FIXED_DIMS_MODE);

    /* Register reserved identifiers to avoid name conflict */
    if (ssRTWGenIsCodeGen(S) || ssGetSimMode(S)==SS_SIMMODE_EXTERNAL) {

        /* Register reserved identifier for  */
        ssRegMdlInfo(S, "sipmj", MDL_INFO_ID_RESERVED, 0, 0, ssGetPath(S));
    } /* if */

    /* This S-function can be used in referenced model simulating in normal mode */
    ssSetModelReferenceNormalModeSupport(S, MDL_START_AND_MDL_PROCESS_PARAMS_OK);

    /* Set the number of sample time */
    ssSetNumSampleTimes(S, 1);

    /* Set the compliance for the operating point save/restore. */
    ssSetOperatingPointCompliance(S, USE_DEFAULT_OPERATING_POINT);

    ssSetArrayLayoutForCodeGen(S, SS_COLUMN_MAJOR);

    /* Set the Simulink version this S-Function has been generated in */
    ssSetSimulinkVersionGeneratedIn(S, "10.6");

    /**
     * All options have the form SS_OPTION_<name> and are documented in
     * matlabroot/simulink/include/simstruc.h. The options should be
     * bitwise or'd together as in
     *    ssSetOptions(S, (SS_OPTION_name1 | SS_OPTION_name2))
     */
    ssSetOptions(S,
        SS_OPTION_USE_TLC_WITH_ACCELERATOR |
        SS_OPTION_CAN_BE_CALLED_CONDITIONALLY |
        SS_OPTION_EXCEPTION_FREE_CODE |
        SS_OPTION_WORKS_WITH_CODE_REUSE |
        SS_OPTION_SFUNCTION_INLINED_FOR_RTW |
        SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME
    );
}

/* Function: mdlInitializeSampleTimes =====================================
 * Abstract:
 *   This function is used to specify the sample time(s) for your
 *   S-function. You must register the same number of sample times as
 *   specified in ssSetNumSampleTimes.
 */
static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
    ssSetOffsetTime(S, 0, FIXED_IN_MINOR_STEP_OFFSET);

    #if defined(ssSetModelReferenceSampleTimeDefaultInheritance)
    ssSetModelReferenceSampleTimeDefaultInheritance(S);
    #endif
}

#define MDL_SET_INPUT_PORT_DIMENSION_INFO
#if defined(MDL_SET_INPUT_PORT_DIMENSION_INFO) && defined(MATLAB_MEX_FILE)
/* Function: mdlSetInputPortDimensionInfo =================================
 * Abstract:
 *   This method is called with the candidate dimensions for an input port
 *   with unknown dimensions. If the proposed dimensions are acceptable, the
 *   method should go ahead and set the actual port dimensions.
 *   If they are unacceptable an error should be generated via
 *   ssSetErrorStatus.
 *   Note that any other input or output ports whose dimensions are
 *   implicitly defined by virtue of knowing the dimensions of the given
 *   port can also have their dimensions set.
 */
static void mdlSetInputPortDimensionInfo(SimStruct *S, int_T portIndex, const DimsInfo_T *dimsInfo)
{
    /* Set input port dimension */
    if(!ssSetInputPortDimensionInfo(S, portIndex, dimsInfo)) return;

    /* Set output port 1 dimension */
    {
        int_T y1Width = ssGetInputPortDimensions(S, 2)[0];
        if (y1Width!=DYNAMICALLY_SIZED && y1Width < 1) { ssSetErrorStatus(S, "Output 1: the current width is < 1"); return; }
        if (y1Width != DYNAMICALLY_SIZED) {
            ssSetOutputPortWidth(S, 0, y1Width);
        } /* if */
    }

    /* Set output port 2 dimension */
    {
        int_T y2Width = ssGetInputPortDimensions(S, 1)[0];
        if (y2Width!=DYNAMICALLY_SIZED && y2Width < 1) { ssSetErrorStatus(S, "Output 2: the current width is < 1"); return; }
        if (y2Width != DYNAMICALLY_SIZED) {
            ssSetOutputPortWidth(S, 1, y2Width);
        } /* if */
    }
}
#endif

#define MDL_SET_OUTPUT_PORT_DIMENSION_INFO
#if defined(MDL_SET_OUTPUT_PORT_DIMENSION_INFO) && defined(MATLAB_MEX_FILE)
/* Function: mdlSetOutputPortDimensionInfo ================================
 * Abstract:
 *   This method is called with the candidate dimensions for an output port
 *   with unknown dimensions. If the proposed dimensions are acceptable, the
 *   method should go ahead and set the actual port dimensions.
 *   If they are unacceptable an error should be generated via
 *   ssSetErrorStatus.
 *   Note that any other input or output ports whose dimensions are
 *   implicitly defined by virtue of knowing the dimensions of the given
 *   port can also have their dimensions set.
 */
static void mdlSetOutputPortDimensionInfo(SimStruct *S, int_T portIndex, const DimsInfo_T *dimsInfo)
{
    /* Set output port dimension */
    if(!ssSetOutputPortDimensionInfo(S, portIndex, dimsInfo)) return;
    {
        int_T y1Width = ssGetInputPortDimensions(S, 2)[0];
        if (y1Width!=DYNAMICALLY_SIZED && y1Width < 1) { ssSetErrorStatus(S, "Output 1: the current width is < 1"); return; }
        if (y1Width != DYNAMICALLY_SIZED) {
            if ((dimsInfo->numDims != 1) || (dimsInfo->width != y1Width)) {
                ssSetErrorStatus(S, "Invalid output port width. The output signal 1 must be a 1D signal.");
            }
        } /* if */
    }
    {
        int_T y2Width = ssGetInputPortDimensions(S, 1)[0];
        if (y2Width!=DYNAMICALLY_SIZED && y2Width < 1) { ssSetErrorStatus(S, "Output 2: the current width is < 1"); return; }
        if (y2Width != DYNAMICALLY_SIZED) {
            if ((dimsInfo->numDims != 1) || (dimsInfo->width != y2Width)) {
                ssSetErrorStatus(S, "Invalid output port width. The output signal 2 must be a 1D signal.");
            }
        } /* if */
    }
}
#endif

#define MDL_SET_DEFAULT_PORT_DIMENSION_INFO
#if defined(MDL_SET_DEFAULT_PORT_DIMENSION_INFO) && defined(MATLAB_MEX_FILE)
/* Function: mdlSetDefaultPortDimensionInfo ===============================
 * Abstract:
 *   This method is called when there is not enough information in your
 *   model to uniquely determine the port dimensionality of signals
 *   entering or leaving your block. When this occurs, Simulink's
 *   dimension propagation engine calls this method to ask you to set
 *   your S-functions default dimensions for any input and output ports
 *   that are dynamically sized.
 *   If you do not provide this method and you have dynamically sized ports
 *   where Simulink does not have enough information to propagate the
 *   dimensionality to your S-function, then Simulink will set these unknown
 *   ports to the 'block width' which is determined by examining any known
 *   ports. If there are no known ports, the width will be set to 1.
 */
static void mdlSetDefaultPortDimensionInfo(SimStruct *S)
{

    /* Set input port 1 default dimension */
    if (ssGetInputPortWidth(S, 0) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 0, 1);
    } /* if */

    /* Set input port 2 default dimension */
    if (ssGetInputPortWidth(S, 1) == DYNAMICALLY_SIZED) {
        if (!ssSetInputPortMatrixDimensions(S, 1, 1, 1)) return;
    } /* if */

    /* Set input port 3 default dimension */
    if (ssGetInputPortWidth(S, 2) == DYNAMICALLY_SIZED) {
        if (!ssSetInputPortMatrixDimensions(S, 2, 1, 1)) return;
    } /* if */

    /* Set input port 4 default dimension */
    if (ssGetInputPortWidth(S, 3) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 3, 1);
    } /* if */

    /* Set input port 5 default dimension */
    if (ssGetInputPortWidth(S, 4) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 4, 1);
    } /* if */

    /* Set input port 6 default dimension */
    if (ssGetInputPortWidth(S, 5) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 5, 1);
    } /* if */

    /* Set input port 7 default dimension */
    if (ssGetInputPortWidth(S, 6) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 6, 1);
    } /* if */

    /* Set input port 8 default dimension */
    if (ssGetInputPortWidth(S, 7) == DYNAMICALLY_SIZED) {
        if (!ssSetInputPortMatrixDimensions(S, 7, 1, 1)) return;
    } /* if */

    /* Set input port 9 default dimension */
    if (ssGetInputPortWidth(S, 8) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 8, 1);
    } /* if */

    /* Set input port 10 default dimension */
    if (ssGetInputPortWidth(S, 9) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 9, 1);
    } /* if */

    /* Set input port 11 default dimension */
    if (ssGetInputPortWidth(S, 10) == DYNAMICALLY_SIZED) {
        ssSetInputPortWidth(S, 10, 1);
    } /* if */

    /* Set output port 1 default dimension */
    {
        int_T y1Width = ssGetInputPortDimensions(S, 2)[0];
        if (y1Width!=DYNAMICALLY_SIZED && y1Width < 1) { ssSetErrorStatus(S, "Output 1: the current width is < 1"); return; }
        if (y1Width != DYNAMICALLY_SIZED) {
            ssSetOutputPortWidth(S, 0, y1Width);
        } /* if */
    }

    /* Set output port 2 default dimension */
    {
        int_T y2Width = ssGetInputPortDimensions(S, 1)[0];
        if (y2Width!=DYNAMICALLY_SIZED && y2Width < 1) { ssSetErrorStatus(S, "Output 2: the current width is < 1"); return; }
        if (y2Width != DYNAMICALLY_SIZED) {
            ssSetOutputPortWidth(S, 1, y2Width);
        } /* if */
    }
}
#endif

#define MDL_SET_WORK_WIDTHS
#if defined(MDL_SET_WORK_WIDTHS) && defined(MATLAB_MEX_FILE)
/* Function: mdlSetWorkWidths =============================================
 * Abstract:
 *   The optional method, mdlSetWorkWidths is called after input port
 *   width, output port width, and sample times of the S-function have
 *   been determined to set any state and work vector sizes which are
 *   a function of the input, output, and/or sample times. 
 *   Run-time parameters are registered in this method using methods 
 *   ssSetNumRunTimeParams, ssSetRunTimeParamInfo, and related methods.
 */
static void mdlSetWorkWidths(SimStruct *S)
{
    /* Set number of run-time parameters */
    if (!ssSetNumRunTimeParams(S, 2)) return;

    /* Register the run-time parameter 1 */
    ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", ssGetDataTypeId(S, "single"));

    /* Register the run-time parameter 2 */
    ssRegDlgParamAsRunTimeParam(S, 1, 1, "p2", ssGetDataTypeId(S, "int32"));

    /* Set DWork 1 width */
    ssSetDWorkWidth(S, 0, ssGetInputPortWidth(S, 0)+4*ssGetInputPortDimensions(S, 1)[0]+6*ssGetInputPortDimensions(S, 7)[0]);
}
#endif

/* Function: mdlOutputs ===================================================
 * Abstract:
 *   In this function, you compute the outputs of your S-function
 *   block. Generally outputs are placed in the output vector(s),
 *   ssGetOutputPortSignal.
 */
static void mdlOutputs(SimStruct *S, int_T tid)
{

    /* Get access to Parameter/Input/Output/DWork data */
    real32_T* y1 = (real32_T*) ssGetOutputPortSignal(S, 0);
    real32_T* y2 = (real32_T*) ssGetOutputPortSignal(S, 1);
    boolean_T* y3 = (boolean_T*) ssGetOutputPortSignal(S, 2);
    real32_T* u1 = (real32_T*) ssGetInputPortSignal(S, 0);
    real32_T* u2 = (real32_T*) ssGetInputPortSignal(S, 1);
    real32_T* u3 = (real32_T*) ssGetInputPortSignal(S, 2);
    real32_T* u4 = (real32_T*) ssGetInputPortSignal(S, 3);
    real32_T* u5 = (real32_T*) ssGetInputPortSignal(S, 4);
    real32_T* u6 = (real32_T*) ssGetInputPortSignal(S, 5);
    real32_T* u7 = (real32_T*) ssGetInputPortSignal(S, 6);
    real32_T* u8 = (real32_T*) ssGetInputPortSignal(S, 7);
    real32_T* u9 = (real32_T*) ssGetInputPortSignal(S, 8);
    real32_T* u10 = (real32_T*) ssGetInputPortSignal(S, 9);
    real32_T* u11 = (real32_T*) ssGetInputPortSignal(S, 10);
    real32_T* p1 = (real32_T*) ssGetRunTimeParamInfo(S, 0)->data;
    int32_T* p2 = (int32_T*) ssGetRunTimeParamInfo(S, 1)->data;
    real32_T* work1 = (real32_T*) ssGetDWork(S, 0);
    int32_T expr1 = (int32_T) (ssGetInputPortDimensions(S, 1)[0]);
    int32_T expr2 = (int32_T) (ssGetInputPortDimensions(S, 2)[0]);
    int32_T expr3 = (int32_T) (ssGetInputPortDimensions(S, 7)[0]);


    /* Call the legacy code function */
    sipmj(y1, y2, y3, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, *p1, *p2, work1, expr1, expr2, expr3);
}

/* Function: mdlTerminate =================================================
 * Abstract:
 *   In this function, you should perform any actions that are necessary
 *   at the termination of a simulation.
 */
static void mdlTerminate(SimStruct *S)
{
}

/* Required S-function trailer */
#ifdef    MATLAB_MEX_FILE
# include "simulink.c"
#else
# include "cg_sfun.h"
#endif

