예제 #1
0
  /* Function: mdlCheckParameters =============================================
   * Abstract:
   *    Validate our parameters to verify they are okay.
   */
  static void mdlCheckParameters(SimStruct *S)
  {
      /* Check 1st parameter: A-Matrix */
      {
          if ( mxGetN(A_PARAM(S)) != NSTATES || !IS_PARAM_DOUBLE(A_PARAM(S)) ) {
              ssSetErrorStatus(S,"1st parameter to S-function "
                               "\"A-Matrix\" must be square and double");
              return;
          }
      }
 
      /* Check 2nd parameter: B-Matrix */
      {
          if (mxGetM(B_PARAM(S)) != NSTATES || !IS_PARAM_DOUBLE(B_PARAM(S)) ) {
              ssSetErrorStatus(S,"2nd parameter to S-function "
                               "\"B-Matrix\" is not dimensioned "
                               "correctly");
              return;
          }
      }
 
      /* Check 3rd parameter: C-Matrix */
      {
          if (mxGetN(C_PARAM(S)) != NSTATES || !IS_PARAM_DOUBLE(C_PARAM(S)) ) {
              ssSetErrorStatus(S,"3rd parameter to S-function "
                               "\"C-Matrix\" is not dimensioned "
                               "correctly");
              return;
          }
      }

      /* Check 4th parameter: D-Matrix */
      {
          if (mxGetM(D_PARAM(S)) != NOUTPUTS || 
              mxGetN(D_PARAM(S)) != NINPUTS || !IS_PARAM_DOUBLE(D_PARAM(S)) ) {
              ssSetErrorStatus(S,"4th parameter to S-function "
                               "\"D-Matrix\" is not dimensioned "
                               "correctly");
              return;
          }
      }

      /* Check 5th parameter: X0 */
      {
          if ( ((mxGetM(X0_PARAM(S)) != 0) && 
               (mxGetM(X0_PARAM(S)) != NSTATES)) || !OK_EMPTY_DOUBLE_PARAM(X0_PARAM(S)) ) {
              ssSetErrorStatus(S,"5th parameter to S-function "
                               "\"X0-Matrix\" is not dimensioned "
                               "correctly");
              return;
          }
      }
  }
예제 #2
0
/* Function: mdlInitializeConditions ========================================
 * Abstract:
 *    If the initial condition parameter (X0) is not an empty matrix,
 *    then use it to set up the initial conditions, otherwise,
 *    set the initial conditions to all 0.0
 */
static void mdlInitializeConditions(SimStruct *S)
{
    real_T *x0 = ssGetContStates(S);
    int_T  i, nStates;
 
    nStates = ssGetNumContStates(S);
    if (mxGetM(X0_PARAM(S)) != 0) {
        const real_T *pr = mxGetPr(X0_PARAM(S));

        for (i = 0; i < nStates; i++) {
            *x0++ = *pr++;
        }
    } else {
        for (i = 0; i < nStates; i++) {
            *x0++ = 0.0;
        }
    }
}
예제 #3
0
파일: muscle.cpp 프로젝트: minosniu/nerf-c
  /* Function: mdlCheckParameters =============================================
   * Abstract:
   *    Validate our parameters to verify they are okay.
   */
  static void mdlCheckParameters(SimStruct *S)
  {
      /* Check 1st parameter: MAGICNUM-Matrix */
      {
          if ( mxGetNumberOfElements(MAGICNUM_PARAM(S)) != NMAGICNUM || 
                  !IS_PARAM_DOUBLE(MAGICNUM_PARAM(S)) )
          {
              ssSetErrorStatus(S,"1st parameter to S-function "
                               "\"A-Matrix\" must be square and double");
              return;
          }
      }

      /* Check 2nd parameter: X0 */
      {
          if ( ((mxGetNumberOfElements(X0_PARAM(S)) != 0) && 
               (mxGetNumberOfElements(X0_PARAM(S)) != NSTATES)) || !OK_EMPTY_DOUBLE_PARAM(X0_PARAM(S)) ) {
              ssSetErrorStatus(S,"2nd parameter to S-function "
                               "\"X0-Matrix\" is not dimensioned "
                               "correctly");
              return;
          }
      }
  }