/* 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) {
	/* See sfuntmpl_doc.c for more details on the macros below */

	ssSetNumSFcnParams(S, 2); /* Number of expected parameters */
#if defined(MATLAB_MEX_FILE)
	if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
		mdlCheckParameters(S);
		if (ssGetErrorStatus(S) != NULL) {
			return;
		}
	} else {
		return; /* Parameter mismatch will be reported by Simulink. */
	}
#endif

	ssSetNumContStates(S, 0);
	ssSetNumDiscStates(S, 0);

	if (!ssSetNumInputPorts(S, 2))
		return;

	ssSetInputPortMatrixDimensions(S, 0, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED); // triangles
	ssSetInputPortDataType(S, 0, SS_UINT32);
	ssSetInputPortMatrixDimensions(S, 1, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED); // vertices

	for (int_T i = 0; i < ssGetNumInputPorts(S); ++i) {
		/*direct input signal access*/
		ssSetInputPortRequiredContiguous(S, i, true);

		/*
		 * Set direct feedthrough flag (1=yes, 0=no).
		 * A port has direct feedthrough if the input is used in either
		 * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
		 * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
		 */
		ssSetInputPortDirectFeedThrough(S, i, 1);
	}

	if (!ssSetNumOutputPorts(S, 0))
		return;

	ssSetNumSampleTimes(S, 1);
	ssSetNumRWork(S, 0);
	ssSetNumIWork(S, 0);
	ssSetNumPWork(S, 2); //GenericPub and frame id
	ssSetNumModes(S, 0);
	ssSetNumNonsampledZCs(S, 0);

	/* Specify the sim state compliance to be same as a built-in block */
	ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

	ssSetOptions(S, 0);
}
Beispiel #2
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(inputDimsInfo);
    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
    /*Input Port 0 */
    inputDimsInfo.width = INPUT_0_WIDTH;
    ssSetInputPortDimensionInfo(S,  0, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 0, INPUT_0_WIDTH, INPUT_DIMS_0_COL);
    ssSetInputPortFrameData(S,  0, IN_0_FRAME_BASED);

    ssSetInputPortDataType(S, 0, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  0, INPUT_0_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

    /*Input Port 1 */
    inputDimsInfo.width = INPUT_1_WIDTH;
    ssSetInputPortDimensionInfo(S,  1, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 1, INPUT_1_WIDTH, INPUT_DIMS_1_COL);
    ssSetInputPortFrameData(S,  1, IN_1_FRAME_BASED);

    ssSetInputPortDataType(S, 1, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  1, INPUT_1_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/


    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
    ssSetOutputPortDataType(S, 0, SS_INT32);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
static void mdlInitializeSizes( SimStruct *S )
/* ======================================================================== */
{
	int_T port;

	/* set number of expected parameters and check for a mismatch. */
	ssSetNumSFcnParams( S, NUM_PARAMS );
#if defined(MATLAB_MEX_FILE)
	if ( ssGetNumSFcnParams( S ) == ssGetSFcnParamsCount( S ) )
	{
		mdlCheckParameters( S );
		if ( ssGetErrorStatus( S ) != NULL )
			return;
	}else  {
		return;
	}
#endif

	/* sampling */
	ssSetNumSampleTimes( S, PORT_BASED_SAMPLE_TIMES );

	/* Set number of input ports and tunability */
	ssSetSFcnParamTunable( S, DEVICE_INDEX, SS_PRM_NOT_TUNABLE );

	/* set the resulting number of ports */
	if ( !ssSetNumInputPorts( S, 1 ) )
		return;

	port = 0;
	{
		const Frame_T	inputsFrames	= ( (double) mxGetScalar( ssGetSFcnParam( S, USE_FRAMES ) ) > 0.0) ? FRAME_YES : FRAME_NO;
		double		sample_time	= 1 / mxGetScalar( ssGetSFcnParam( S, SAMPLE_RATE ) );
		const int_T	buf_length	= (int_T) (double) mxGetScalar( ssGetSFcnParam( S, FRAME_LENGTH ) );
		const time_T	period		= (time_T) (sample_time * buf_length);

		ssSetInputPortMatrixDimensions( S, port, buf_length, 1 );
		ssSetInputPortComplexSignal( S, port, COMPLEX_YES );
		ssSetInputPortDataType( S, port, SS_DOUBLE );
		ssSetInputPortFrameData( S, port, inputsFrames );
		ssSetInputPortDirectFeedThrough( S, port, 1 );
		ssSetInputPortSampleTime( S, port, period );
		ssSetInputPortOffsetTime( S, port, 0.0 );
	}

	/* Set number of output ports */
	if ( !ssSetNumOutputPorts( S, 0 ) )
		return;
	/* data port properties */
	/* Prepare work Vectors */
	ssSetNumPWork( S, P_WORK_LENGTH );
	ssSetNumIWork( S, I_WORK_LENGTH );
	ssSetNumRWork( S, R_WORK_LENGTH );
	ssSetNumModes( S, 0 );
	ssSetNumNonsampledZCs( S, 0 );

	/* Specify the sim state compliance to be same as a built-in block */
	ssSetSimStateCompliance( S, USE_DEFAULT_SIM_STATE );

	ssSetOptions( S, 0 );
}
static void mdlInitializeSizes(SimStruct *S)
{
	ssSetNumSFcnParams(S, NUMBER_OF_PARAMS);
	if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
		return;
	}
	ssSetNumInputPorts(S, 1);
	ssSetNumOutputPorts(S, 0);
	ssSetInputPortMatrixDimensions(S, 0, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED);
	ssSetInputPortDirectFeedThrough(S, 0, 1);
	ssSetNumContStates(S, 0);
	ssSetNumDiscStates(S, 0);
	ssSetNumSampleTimes(S, 1);
	ssSetNumPWork(S, 1);
}
/* Function: mdlSetDefaultPortDimensionInfo ====================================
 *    This routine is called when Simulink is not able to find dimension
 *    candidates for ports with unknown dimensions. This function must set the
 *    dimensions of all ports with unknown dimensions.
 */
static void mdlSetDefaultPortDimensionInfo(SimStruct *S)
{
    char temp[3];
    int i;
    char* pp2=(char*)mxGetPr(ssGetSFcnParam(S,1));
    int param_width2=mxGetNumberOfElements(ssGetSFcnParam(S,1));  
    char* pp3=(char*)mxGetPr(ssGetSFcnParam(S,2));
    int param_width3=mxGetNumberOfElements(ssGetSFcnParam(S,2));  
    
    memset(temp, 0,3* sizeof(char));
    for (i=0;i<param_width2;i++)
        temp[i]=pp2[i*2];
    if( atoi(temp)<=0)
    {

        if(!ssSetInputPortMatrixDimensions(S, 0, 1, 1)) return;
    }
    else
    {
        /*if(!ssSetInputPortMatrixDimensions(S, 0, 1, atoi(temp))) return;remove?*/
    }
        
    memset(temp, 0,3* sizeof(char));
    for (i=0;i<param_width3;i++)	
	{
        temp[i]=pp3[i*2];
	printf("%c_",temp[i]);
}
    if( atoi(temp)>0)
    {

        if(!ssSetOutputPortMatrixDimensions(S, 0, 1, atoi(temp))) return;
    }
    else
    {
        if(!ssSetOutputPortMatrixDimensions(S, 0, 1, 1)) return;
    }

} /* end mdlSetDefaultPortDimensionInfo */
Beispiel #6
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(inputDimsInfo);
    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
    /*Input Port 0 */
    inputDimsInfo.width = INPUT_0_WIDTH;
    ssSetInputPortDimensionInfo(S,  0, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 0, INPUT_0_WIDTH, INPUT_DIMS_0_COL);
    ssSetInputPortFrameData(S,  0, IN_0_FRAME_BASED);

    ssSetInputPortDataType(S, 0, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  0, INPUT_0_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

    /*Input Port 1 */
    inputDimsInfo.width = INPUT_1_WIDTH;
    ssSetInputPortDimensionInfo(S,  1, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 1, INPUT_1_WIDTH, INPUT_DIMS_1_COL);
    ssSetInputPortFrameData(S,  1, IN_1_FRAME_BASED);

    ssSetInputPortDataType(S, 1, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  1, INPUT_1_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/

    /*Input Port 2 */
    inputDimsInfo.width = INPUT_2_WIDTH;
    ssSetInputPortDimensionInfo(S,  2, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 2, INPUT_2_WIDTH, INPUT_DIMS_2_COL);
    ssSetInputPortFrameData(S,  2, IN_2_FRAME_BASED);

    ssSetInputPortDataType(S, 2, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  2, INPUT_2_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 2, INPUT_2_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 2, 1); /*direct input signal access*/

    /*Input Port 3 */
    inputDimsInfo.width = INPUT_3_WIDTH;
    ssSetInputPortDimensionInfo(S,  3, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 3, INPUT_3_WIDTH, INPUT_DIMS_3_COL);
    ssSetInputPortFrameData(S,  3, IN_3_FRAME_BASED);

    ssSetInputPortDataType(S, 3, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  3, INPUT_3_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 3, INPUT_3_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 3, 1); /*direct input signal access*/

    /*Input Port 4 */
    inputDimsInfo.width = INPUT_4_WIDTH;
    ssSetInputPortDimensionInfo(S,  4, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 4, INPUT_4_WIDTH, INPUT_DIMS_4_COL);
    ssSetInputPortFrameData(S,  4, IN_4_FRAME_BASED);

    ssSetInputPortDataType(S, 4, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  4, INPUT_4_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 4, INPUT_4_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 4, 1); /*direct input signal access*/

    /*Input Port 5 */
    ssSetInputPortWidth(S,  5, INPUT_5_WIDTH); /* */
    ssSetInputPortDataType(S, 5, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  5, INPUT_5_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 5, INPUT_5_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 5, 1); /*direct input signal access*/

    /*Input Port 6 */
    ssSetInputPortWidth(S,  6, INPUT_6_WIDTH); /* */
    ssSetInputPortDataType(S, 6, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  6, INPUT_6_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 6, INPUT_6_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 6, 1); /*direct input signal access*/

    /*Input Port 7 */
    inputDimsInfo.width = INPUT_7_WIDTH;
    ssSetInputPortDimensionInfo(S, 7, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S ,7, INPUT_7_WIDTH, INPUT_DIMS_7_COL);
    ssSetInputPortFrameData(S, 7, IN_7_FRAME_BASED);
    ssSetInputPortDataType(S, 7, SS_DOUBLE);
    ssSetInputPortComplexSignal(S, 7, INPUT_7_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 7, INPUT_7_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 7, 1); /*direct input signal access*/

    /*Input Port 8 */
    inputDimsInfo.width = INPUT_8_WIDTH;
    ssSetInputPortDimensionInfo(S, 8, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S ,8, INPUT_8_WIDTH, INPUT_DIMS_8_COL);
    ssSetInputPortFrameData(S, 8, IN_8_FRAME_BASED);
    ssSetInputPortDataType(S, 8, SS_DOUBLE);
    ssSetInputPortComplexSignal(S, 8, INPUT_8_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 8, INPUT_8_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 8, 1); /*direct input signal access*/

    /*Input Port 9 */
    inputDimsInfo.width = INPUT_9_WIDTH;
    ssSetInputPortDimensionInfo(S, 9, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S ,9, INPUT_9_WIDTH, INPUT_DIMS_9_COL);
    ssSetInputPortFrameData(S, 9, IN_9_FRAME_BASED);
    ssSetInputPortDataType(S, 9, SS_DOUBLE);
    ssSetInputPortComplexSignal(S, 9, INPUT_9_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 9, INPUT_9_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 9, 1); /*direct input signal access*/

    /*Input Port 10 */
    inputDimsInfo.width = INPUT_10_WIDTH;
    ssSetInputPortDimensionInfo(S, 10, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S ,10, INPUT_10_WIDTH, INPUT_DIMS_10_COL);
    ssSetInputPortFrameData(S, 10, IN_10_FRAME_BASED);
    ssSetInputPortDataType(S, 10, SS_UINT8);
    ssSetInputPortComplexSignal(S, 10, INPUT_10_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 10, INPUT_10_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 10, 1); /*direct input signal access*/

    /*Input Port 11 */
    inputDimsInfo.width = INPUT_11_WIDTH;
    ssSetInputPortDimensionInfo(S, 11, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S ,11, INPUT_11_WIDTH, INPUT_DIMS_11_COL);
    ssSetInputPortFrameData(S, 11, IN_11_FRAME_BASED);
    ssSetInputPortDataType(S, 11, SS_UINT8);
    ssSetInputPortComplexSignal(S, 11, INPUT_11_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 11, INPUT_11_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 11, 1); /*direct input signal access*/

    /*Input Port 12 */
    inputDimsInfo.width = INPUT_12_WIDTH;
    ssSetInputPortDimensionInfo(S, 12, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S ,12, INPUT_12_WIDTH, INPUT_DIMS_12_COL);
    ssSetInputPortFrameData(S, 12, IN_12_FRAME_BASED);
    ssSetInputPortDataType(S, 12, SS_UINT8);
    ssSetInputPortComplexSignal(S, 12, INPUT_12_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 12, INPUT_12_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 12, 1); /*direct input signal access*/


    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
Beispiel #7
0
/* 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)
{
	int_T npar = ssGetSFcnParamsCount(S);
	/* options are optional as a third parameter */
	if ( npar==2 || npar==3 ) {
		ssSetNumSFcnParams(S, npar);  /* Number of expected parameters */
	}
	else {
		return;
	}

#ifdef MATLAB_MEX_FILE
    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
        mdlCheckParameters(S);
        if (ssGetErrorStatus(S) != NULL) {
            return;
        }
    } else {
        return; /* Parameter mismatch will be reported by Simulink */
    }
#endif

    /* no states because we do not need nothing to remember */
    ssSetNumContStates(S, 0); /* the number of continuous states */
    ssSetNumDiscStates(S, 0 ); /* the number of discrete states */

    /* inputs are M, q*/
    if (!ssSetNumInputPorts(S, 2)) return;
    /* input matrix M to port 0*/
    ssSetInputPortWidth(S, 0, NSTATES(S)*NSTATES(S));     
    ssSetInputPortMatrixDimensions(S, 0, NSTATES(S), NSTATES(S));  
    ssSetInputPortDirectFeedThrough(S, 0, 1); /* direct feedtrough for port 0*/

    /* input vector q to port 1*/
    ssSetInputPortWidth(S, 1, NSTATES(S));     
    ssSetInputPortVectorDimension(S, 1, NSTATES(S));
    ssSetInputPortDirectFeedThrough(S, 1, 1); /* direct feedtrough for port 1*/


    /* outputs are z, w, basis, exitflag, pivots, time */
    if (!ssSetNumOutputPorts(S, 6)) return;
    ssSetOutputPortWidth(S, 0, NSTATES(S)); /* output z to port 0 */
    ssSetOutputPortVectorDimension(S, 0, NSTATES(S));

    ssSetOutputPortWidth(S, 1, NSTATES(S)); /* output w to port 1 */
    ssSetOutputPortVectorDimension(S, 1, NSTATES(S));

    ssSetOutputPortWidth(S, 2, NSTATES(S)); /* basis to port 2 */
    ssSetOutputPortVectorDimension(S, 2, NSTATES(S));

    ssSetOutputPortWidth(S, 3, 1); /* exitflag to port 3 */
    ssSetOutputPortWidth(S, 4, 1); /* pivots to port 4 */
    ssSetOutputPortWidth(S, 5, 1); /* computation time to port 5 */

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 7); /* working vectors Mn, qn, r, c, x, pA, pB */
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* use PWorks to store values */
    ssSetSimStateCompliance(S, HAS_NO_SIM_STATE);

    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE );

}
/* Function: mdlSetDefaultPortDimensionInfo ===========================================
 * Abstract:
 *   In case no ports were specified, the default is an input port of width 2
 *   and an output port of width 1.
 */
static void mdlSetDefaultPortDimensionInfo(SimStruct *S) {
	ssSetInputPortMatrixDimensions(S, 0, 3, 1);
	ssSetInputPortMatrixDimensions(S, 1, 3, 3);
}