/*
 * SLENGTH   A SIMULINK block that outputs the length of the input vector.
 * DSP Blockset S-Function to compute length of input vector.
 * This SIMULINK S-function outputs the length of the input vector;
 * it is called by the Length block in the DSP Blockset.
 *
 *   Syntax:  [sys, x0] = slength(t,x,u,flag)
 *
 *  Copyright 1995-2000 The MathWorks, Inc.
 *  $Revision: 1.9 $  $Date: 2000/05/05 20:16:11 $
 */

#define S_FUNCTION_NAME slength

#include "dsp_sim.h" 


static void mdlInitializeSizes(SimStruct *S)
{
#ifdef MATLAB_MEX_FILE
    mexWarnMsgTxt("Obsolete blocks calling the CMEX S-Function 'slength' have\n"
                  "been detected.  If you wish to upgrade this model, replace\n"
                  "all 'Length' blocks with the 'Width' block found in:\n"
                  "        'dsplib/Math Functions/Vector Math'\n"
                  "If you wish to disable this warning message, type\n"
                  "'warning off' at the MATLAB command line.\n\n");
#endif
    ssSetNumContStates(    S, 0);                 /* number of continuous states */
    ssSetNumDiscStates(    S, 0);                 /* number of discrete states */
    ssSetNumInputs(        S, DYNAMICALLY_SIZED); /* number of inputs */
    ssSetNumOutputs(       S, 1);                 /* number of outputs */
    ssSetDirectFeedThrough(S, 1);                 /* direct feedthrough flag */
    ssSetNumSampleTimes(   S, 1);                 /* number of sample times */
    ssSetNumInputArgs(     S, 0);                 /* number of input arguments */
    ssSetNumRWork(         S, 0);                 /* number of real work vector elements */
    ssSetNumIWork(         S, 0);                 /* number of integer work vector elements */
    ssSetNumPWork(         S, 0);                 /* number of pointer work vector elements */
    ssSetOptions(          S, SS_OPTION_EXCEPTION_FREE_CODE);
}


static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTimeEvent(S, 0, INHERITED_SAMPLE_TIME);
    ssSetOffsetTimeEvent(S, 0, 0.0);
}


static void mdlInitializeConditions(real_T *x0, SimStruct *S)
{
}


static void mdlOutputs(real_T *y, const real_T *x, const real_T *u, 
                       SimStruct *S, int_T tid)
{
    /* Determine the number of input elements: */
    y[0] = ssGetNumInputs(S);
}


static void mdlUpdate(real_T *x, const real_T *u, SimStruct *S, int_T tid)
{
}

static void mdlDerivatives(real_T *dx, const real_T *x, const real_T *u, 
                           SimStruct *S, int_T tid)
{
}

static void mdlTerminate(SimStruct *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
