/* Include files */

#include "blascompat32.h"
#include "ental_sfun.h"
#include "c10_ental.h"
#define CHARTINSTANCE_CHARTNUMBER      (chartInstance->chartNumber)
#define CHARTINSTANCE_INSTANCENUMBER   (chartInstance->instanceNumber)
#include "ental_sfun_debug_macros.h"

/* Type Definitions */

/* Named Constants */

/* Variable Declarations */

/* Variable Definitions */
static const char *c10_debug_family_names[4] = { "p", "nargin", "nargout", "A" };

/* Function Declarations */
static void initialize_c10_ental(SFc10_entalInstanceStruct *chartInstance);
static void initialize_params_c10_ental(SFc10_entalInstanceStruct *chartInstance);
static void enable_c10_ental(SFc10_entalInstanceStruct *chartInstance);
static void disable_c10_ental(SFc10_entalInstanceStruct *chartInstance);
static void c10_update_debugger_state_c10_ental(SFc10_entalInstanceStruct
  *chartInstance);
static const mxArray *get_sim_state_c10_ental(SFc10_entalInstanceStruct
  *chartInstance);
static void set_sim_state_c10_ental(SFc10_entalInstanceStruct *chartInstance,
  const mxArray *c10_st);
static void finalize_c10_ental(SFc10_entalInstanceStruct *chartInstance);
static void sf_c10_ental(SFc10_entalInstanceStruct *chartInstance);
static void compInitSubchartSimstructsFcn_c10_ental(SFc10_entalInstanceStruct
  *chartInstance);
static void init_script_number_translation(uint32_T c10_machineNumber, uint32_T
  c10_chartNumber);
static const mxArray *c10_sf_marshall(void *chartInstanceVoid, void *c10_u);
static const mxArray *c10_b_sf_marshall(void *chartInstanceVoid, void *c10_u);
static const mxArray *c10_c_sf_marshall(void *chartInstanceVoid, void *c10_u);
static void c10_emlrt_marshallIn(SFc10_entalInstanceStruct *chartInstance, const
  mxArray *c10_A, const char_T *c10_name, real_T c10_y[13]);
static uint8_T c10_b_emlrt_marshallIn(SFc10_entalInstanceStruct *chartInstance,
  const mxArray *c10_b_is_active_c10_ental, const char_T *c10_name);
static void init_dsm_address_info(SFc10_entalInstanceStruct *chartInstance);

/* Function Definitions */
static void initialize_c10_ental(SFc10_entalInstanceStruct *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c10_is_active_c10_ental = 0U;
}

static void initialize_params_c10_ental(SFc10_entalInstanceStruct *chartInstance)
{
}

static void enable_c10_ental(SFc10_entalInstanceStruct *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
}

static void disable_c10_ental(SFc10_entalInstanceStruct *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
}

static void c10_update_debugger_state_c10_ental(SFc10_entalInstanceStruct
  *chartInstance)
{
}

static const mxArray *get_sim_state_c10_ental(SFc10_entalInstanceStruct
  *chartInstance)
{
  const mxArray *c10_st = NULL;
  const mxArray *c10_y = NULL;
  int32_T c10_i0;
  real_T c10_hoistedGlobal[13];
  int32_T c10_i1;
  real_T c10_u[13];
  const mxArray *c10_b_y = NULL;
  uint8_T c10_b_hoistedGlobal;
  uint8_T c10_b_u;
  const mxArray *c10_c_y = NULL;
  real_T (*c10_A)[13];
  c10_A = (real_T (*)[13])ssGetOutputPortSignal(chartInstance->S, 1);
  c10_st = NULL;
  c10_y = NULL;
  sf_mex_assign(&c10_y, sf_mex_createcellarray(2));
  for (c10_i0 = 0; c10_i0 < 13; c10_i0 = c10_i0 + 1) {
    c10_hoistedGlobal[c10_i0] = (*c10_A)[c10_i0];
  }

  for (c10_i1 = 0; c10_i1 < 13; c10_i1 = c10_i1 + 1) {
    c10_u[c10_i1] = c10_hoistedGlobal[c10_i1];
  }

  c10_b_y = NULL;
  sf_mex_assign(&c10_b_y, sf_mex_create("y", c10_u, 0, 0U, 1U, 0U, 1, 13));
  sf_mex_setcell(c10_y, 0, c10_b_y);
  c10_b_hoistedGlobal = chartInstance->c10_is_active_c10_ental;
  c10_b_u = c10_b_hoistedGlobal;
  c10_c_y = NULL;
  sf_mex_assign(&c10_c_y, sf_mex_create("y", &c10_b_u, 3, 0U, 0U, 0U, 0));
  sf_mex_setcell(c10_y, 1, c10_c_y);
  sf_mex_assign(&c10_st, c10_y);
  return c10_st;
}

static void set_sim_state_c10_ental(SFc10_entalInstanceStruct *chartInstance,
  const mxArray *c10_st)
{
  const mxArray *c10_u;
  real_T c10_dv0[13];
  int32_T c10_i2;
  real_T (*c10_A)[13];
  c10_A = (real_T (*)[13])ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c10_doneDoubleBufferReInit = TRUE;
  c10_u = sf_mex_dup(c10_st);
  c10_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell(c10_u, 0)), "A",
                       c10_dv0);
  for (c10_i2 = 0; c10_i2 < 13; c10_i2 = c10_i2 + 1) {
    (*c10_A)[c10_i2] = c10_dv0[c10_i2];
  }

  chartInstance->c10_is_active_c10_ental = c10_b_emlrt_marshallIn(chartInstance,
    sf_mex_dup(sf_mex_getcell(c10_u, 1)),
    "is_active_c10_ental");
  sf_mex_destroy(&c10_u);
  c10_update_debugger_state_c10_ental(chartInstance);
  sf_mex_destroy(&c10_st);
}

static void finalize_c10_ental(SFc10_entalInstanceStruct *chartInstance)
{
}

static void sf_c10_ental(SFc10_entalInstanceStruct *chartInstance)
{
  int32_T c10_i3;
  int32_T c10_previousEvent;
  uint32_T c10_debug_family_var_map[4];
  static const char *c10_sv0[4] = { "p", "nargin", "nargout", "A" };

  real_T c10_p;
  real_T c10_nargin = 0.0;
  real_T c10_nargout = 1.0;
  real_T c10_A[13];
  int32_T c10_i4;
  int32_T c10_i5;
  real_T (*c10_b_A)[13];
  c10_b_A = (real_T (*)[13])ssGetOutputPortSignal(chartInstance->S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 9);
  for (c10_i3 = 0; c10_i3 < 13; c10_i3 = c10_i3 + 1) {
    _SFD_DATA_RANGE_CHECK((*c10_b_A)[c10_i3], 0U);
  }

  c10_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 9);
  sf_debug_symbol_scope_push_eml(0U, 4U, 4U, c10_sv0, c10_debug_family_var_map);
  sf_debug_symbol_scope_add_eml(&c10_p, c10_b_sf_marshall, 0U);
  sf_debug_symbol_scope_add_eml(&c10_nargin, c10_b_sf_marshall, 1U);
  sf_debug_symbol_scope_add_eml(&c10_nargout, c10_b_sf_marshall, 2U);
  sf_debug_symbol_scope_add_eml(c10_A, c10_sf_marshall, 3U);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0, 4);
  c10_p = 13.0;
  _SFD_EML_CALL(0, 5);
  for (c10_i4 = 0; c10_i4 < 13; c10_i4 = c10_i4 + 1) {
    c10_A[c10_i4] = 1.0;
  }

  _SFD_EML_CALL(0, -5);
  sf_debug_symbol_scope_pop();
  for (c10_i5 = 0; c10_i5 < 13; c10_i5 = c10_i5 + 1) {
    (*c10_b_A)[c10_i5] = c10_A[c10_i5];
  }

  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 9);
  _sfEvent_ = c10_previousEvent;
  sf_debug_check_for_state_inconsistency(_entalMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
}

static void compInitSubchartSimstructsFcn_c10_ental(SFc10_entalInstanceStruct
  *chartInstance)
{
}

static void init_script_number_translation(uint32_T c10_machineNumber, uint32_T
  c10_chartNumber)
{
}

static const mxArray *c10_sf_marshall(void *chartInstanceVoid, void *c10_u)
{
  const mxArray *c10_y = NULL;
  int32_T c10_i6;
  real_T c10_b_u[13];
  int32_T c10_i7;
  real_T c10_c_u[13];
  const mxArray *c10_b_y = NULL;
  SFc10_entalInstanceStruct *chartInstance;
  chartInstance = (SFc10_entalInstanceStruct *)chartInstanceVoid;
  c10_y = NULL;
  for (c10_i6 = 0; c10_i6 < 13; c10_i6 = c10_i6 + 1) {
    c10_b_u[c10_i6] = (*((real_T (*)[13])c10_u))[c10_i6];
  }

  for (c10_i7 = 0; c10_i7 < 13; c10_i7 = c10_i7 + 1) {
    c10_c_u[c10_i7] = c10_b_u[c10_i7];
  }

  c10_b_y = NULL;
  sf_mex_assign(&c10_b_y, sf_mex_create("y", c10_c_u, 0, 0U, 1U, 0U, 1, 13));
  sf_mex_assign(&c10_y, c10_b_y);
  return c10_y;
}

static const mxArray *c10_b_sf_marshall(void *chartInstanceVoid, void *c10_u)
{
  const mxArray *c10_y = NULL;
  real_T c10_b_u;
  const mxArray *c10_b_y = NULL;
  SFc10_entalInstanceStruct *chartInstance;
  chartInstance = (SFc10_entalInstanceStruct *)chartInstanceVoid;
  c10_y = NULL;
  c10_b_u = *((real_T *)c10_u);
  c10_b_y = NULL;
  sf_mex_assign(&c10_b_y, sf_mex_create("y", &c10_b_u, 0, 0U, 0U, 0U, 0));
  sf_mex_assign(&c10_y, c10_b_y);
  return c10_y;
}

const mxArray *sf_c10_ental_get_eml_resolved_functions_info(void)
{
  const mxArray *c10_nameCaptureInfo = NULL;
  c10_ResolvedFunctionInfo c10_info[1];
  c10_ResolvedFunctionInfo (*c10_b_info)[1];
  const mxArray *c10_m0 = NULL;
  int32_T c10_i8;
  c10_ResolvedFunctionInfo *c10_r0;
  c10_nameCaptureInfo = NULL;
  c10_b_info = (c10_ResolvedFunctionInfo (*)[1])c10_info;
  (*c10_b_info)[0].context = "";
  (*c10_b_info)[0].name = "ones";
  (*c10_b_info)[0].dominantType = "double";
  (*c10_b_info)[0].resolved = "[B]ones";
  (*c10_b_info)[0].fileLength = 0U;
  (*c10_b_info)[0].fileTime1 = 0U;
  (*c10_b_info)[0].fileTime2 = 0U;
  sf_mex_assign(&c10_m0, sf_mex_createstruct("nameCaptureInfo", 1, 1));
  for (c10_i8 = 0; c10_i8 < 1; c10_i8 = c10_i8 + 1) {
    c10_r0 = &c10_info[c10_i8];
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo", c10_r0->context, 15,
      0U, 0U, 0U, 2, 1, strlen(c10_r0->context)), "context"
                    , "nameCaptureInfo", c10_i8);
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo", c10_r0->name, 15,
      0U, 0U, 0U, 2, 1, strlen(c10_r0->name)), "name",
                    "nameCaptureInfo", c10_i8);
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo",
      c10_r0->dominantType, 15, 0U, 0U, 0U, 2, 1, strlen(c10_r0->dominantType)),
                    "dominantType", "nameCaptureInfo", c10_i8);
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo", c10_r0->resolved,
      15, 0U, 0U, 0U, 2, 1, strlen(c10_r0->resolved)),
                    "resolved", "nameCaptureInfo", c10_i8);
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo", &c10_r0->fileLength,
      7, 0U, 0U, 0U, 0), "fileLength", "nameCaptureInfo",
                    c10_i8);
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo", &c10_r0->fileTime1,
      7, 0U, 0U, 0U, 0), "fileTime1", "nameCaptureInfo",
                    c10_i8);
    sf_mex_addfield(c10_m0, sf_mex_create("nameCaptureInfo", &c10_r0->fileTime2,
      7, 0U, 0U, 0U, 0), "fileTime2", "nameCaptureInfo",
                    c10_i8);
  }

  sf_mex_assign(&c10_nameCaptureInfo, c10_m0);
  return c10_nameCaptureInfo;
}

static const mxArray *c10_c_sf_marshall(void *chartInstanceVoid, void *c10_u)
{
  const mxArray *c10_y = NULL;
  boolean_T c10_b_u;
  const mxArray *c10_b_y = NULL;
  SFc10_entalInstanceStruct *chartInstance;
  chartInstance = (SFc10_entalInstanceStruct *)chartInstanceVoid;
  c10_y = NULL;
  c10_b_u = *((boolean_T *)c10_u);
  c10_b_y = NULL;
  sf_mex_assign(&c10_b_y, sf_mex_create("y", &c10_b_u, 11, 0U, 0U, 0U, 0));
  sf_mex_assign(&c10_y, c10_b_y);
  return c10_y;
}

static void c10_emlrt_marshallIn(SFc10_entalInstanceStruct *chartInstance, const
  mxArray *c10_A, const char_T *c10_name, real_T
  c10_y[13])
{
  real_T c10_dv1[13];
  int32_T c10_i9;
  sf_mex_import(c10_name, sf_mex_dup(c10_A), c10_dv1, 1, 0, 0U, 1, 0U, 1, 13);
  for (c10_i9 = 0; c10_i9 < 13; c10_i9 = c10_i9 + 1) {
    c10_y[c10_i9] = c10_dv1[c10_i9];
  }

  sf_mex_destroy(&c10_A);
}

static uint8_T c10_b_emlrt_marshallIn(SFc10_entalInstanceStruct *chartInstance,
  const mxArray *c10_b_is_active_c10_ental, const
  char_T *c10_name)
{
  uint8_T c10_y;
  uint8_T c10_u0;
  sf_mex_import(c10_name, sf_mex_dup(c10_b_is_active_c10_ental), &c10_u0, 1, 3,
                0U, 0, 0U, 0);
  c10_y = c10_u0;
  sf_mex_destroy(&c10_b_is_active_c10_ental);
  return c10_y;
}

static void init_dsm_address_info(SFc10_entalInstanceStruct *chartInstance)
{
}

/* SFunction Glue Code */
void sf_c10_ental_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(3496582433U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(2921660105U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(3196073322U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(1139453441U);
}

mxArray *sf_c10_ental_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(1481521062U);
    pr[1] = (double)(1910828319U);
    pr[2] = (double)(3395658632U);
    pr[3] = (double)(2787405495U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(13);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}

static mxArray *sf_get_sim_state_info_c10_ental(void)
{
  const char *infoFields[] = { "chartChecksum", "varInfo" };

  mxArray *mxInfo = mxCreateStructMatrix(1, 1, 2, infoFields);
  const char *infoEncStr[] = {
    "100 S1x2'type','srcId','name','auxInfo'{{M[1],M[5],T\"A\",},{M[8],M[0],T\"is_active_c10_ental\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 2, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c10_ental_get_check_sum(&mxChecksum);
  mxSetField(mxInfo, 0, infoFields[0], mxChecksum);
  mxSetField(mxInfo, 0, infoFields[1], mxVarInfo);
  return mxInfo;
}

static void chart_debug_initialization(SimStruct *S, unsigned int
  fullDebuggerInitialization)
{
  if (!sim_mode_is_rtw_gen(S)) {
    SFc10_entalInstanceStruct *chartInstance;
    chartInstance = (SFc10_entalInstanceStruct *) ((ChartInfoStruct *)
      (ssGetUserData(S)))->chartInstance;
    if (ssIsFirstInitCond(S) && fullDebuggerInitialization==1) {
      /* do this only if simulation is starting */
      {
        unsigned int chartAlreadyPresent;
        chartAlreadyPresent = sf_debug_initialize_chart(_entalMachineNumber_,
          10,
          1,
          1,
          1,
          0,
          0,
          0,
          0,
          0,
          &(chartInstance->chartNumber),
          &(chartInstance->instanceNumber),
          ssGetPath(S),
          (void *)S);
        if (chartAlreadyPresent==0) {
          /* this is the first instance */
          init_script_number_translation(_entalMachineNumber_,
            chartInstance->chartNumber);
          sf_debug_set_chart_disable_implicit_casting(_entalMachineNumber_,
            chartInstance->chartNumber,1);
          sf_debug_set_chart_event_thresholds(_entalMachineNumber_,
            chartInstance->chartNumber,
            0,
            0,
            0);
          _SFD_SET_DATA_PROPS(0,2,0,1,"A");
          _SFD_STATE_INFO(0,0,2);
          _SFD_CH_SUBSTATE_COUNT(0);
          _SFD_CH_SUBSTATE_DECOMP(0);
        }

        _SFD_CV_INIT_CHART(0,0,0,0);

        {
          _SFD_CV_INIT_STATE(0,0,0,0,0,0,NULL,NULL);
        }

        _SFD_CV_INIT_TRANS(0,0,NULL,NULL,0,NULL);

        /* Initialization of EML Model Coverage */
        _SFD_CV_INIT_EML(0,1,0,0,0,0,0,0,0);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,55);
        _SFD_TRANS_COV_WTS(0,0,0,1,0);
        if (chartAlreadyPresent==0) {
          _SFD_TRANS_COV_MAPS(0,
                              0,NULL,NULL,
                              0,NULL,NULL,
                              1,NULL,NULL,
                              0,NULL,NULL);
        }

        {
          unsigned int dimVector[1];
          dimVector[0]= 13;
          _SFD_SET_DATA_COMPILED_PROPS(0,SF_DOUBLE,1,&(dimVector[0]),0,0,0,0.0,
            1.0,0,0,(MexFcnForType)c10_sf_marshall);
        }

        {
          real_T (*c10_A)[13];
          c10_A = (real_T (*)[13])ssGetOutputPortSignal(chartInstance->S, 1);
          _SFD_SET_DATA_VALUE_PTR(0U, *c10_A);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration(_entalMachineNumber_,
        chartInstance->chartNumber,chartInstance->instanceNumber);
    }
  }
}

static void sf_opaque_initialize_c10_ental(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc10_entalInstanceStruct*) chartInstanceVar)->S,
    0);
  initialize_params_c10_ental((SFc10_entalInstanceStruct*) chartInstanceVar);
  initialize_c10_ental((SFc10_entalInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_enable_c10_ental(void *chartInstanceVar)
{
  enable_c10_ental((SFc10_entalInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_disable_c10_ental(void *chartInstanceVar)
{
  disable_c10_ental((SFc10_entalInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_gateway_c10_ental(void *chartInstanceVar)
{
  sf_c10_ental((SFc10_entalInstanceStruct*) chartInstanceVar);
}

static mxArray* sf_internal_get_sim_state_c10_ental(SimStruct* S)
{
  ChartInfoStruct *chartInfo = (ChartInfoStruct*) ssGetUserData(S);
  mxArray *plhs[1] = { NULL };

  mxArray *prhs[4];
  int mxError = 0;
  prhs[0] = mxCreateString("chart_simctx_raw2high");
  prhs[1] = mxCreateDoubleScalar(ssGetSFuncBlockHandle(S));
  prhs[2] = (mxArray*) get_sim_state_c10_ental((SFc10_entalInstanceStruct*)
    chartInfo->chartInstance);         /* raw sim ctx */
  prhs[3] = sf_get_sim_state_info_c10_ental();/* state var info */
  mxError = sf_mex_call_matlab(1, plhs, 4, prhs, "sfprivate");
  mxDestroyArray(prhs[0]);
  mxDestroyArray(prhs[1]);
  mxDestroyArray(prhs[2]);
  mxDestroyArray(prhs[3]);
  if (mxError || plhs[0] == NULL) {
    sf_mex_error_message("Stateflow Internal Error: \nError calling 'chart_simctx_raw2high'.\n");
  }

  return plhs[0];
}

static void sf_internal_set_sim_state_c10_ental(SimStruct* S, const mxArray *st)
{
  ChartInfoStruct *chartInfo = (ChartInfoStruct*) ssGetUserData(S);
  mxArray *plhs[1] = { NULL };

  mxArray *prhs[4];
  int mxError = 0;
  prhs[0] = mxCreateString("chart_simctx_high2raw");
  prhs[1] = mxCreateDoubleScalar(ssGetSFuncBlockHandle(S));
  prhs[2] = mxDuplicateArray(st);      /* high level simctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c10_ental();/* state var info */
  mxError = sf_mex_call_matlab(1, plhs, 4, prhs, "sfprivate");
  mxDestroyArray(prhs[0]);
  mxDestroyArray(prhs[1]);
  mxDestroyArray(prhs[2]);
  mxDestroyArray(prhs[3]);
  if (mxError || plhs[0] == NULL) {
    sf_mex_error_message("Stateflow Internal Error: \nError calling 'chart_simctx_high2raw'.\n");
  }

  set_sim_state_c10_ental((SFc10_entalInstanceStruct*)chartInfo->chartInstance,
    mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static mxArray* sf_opaque_get_sim_state_c10_ental(SimStruct* S)
{
  return sf_internal_get_sim_state_c10_ental(S);
}

static void sf_opaque_set_sim_state_c10_ental(SimStruct* S, const mxArray *st)
{
  sf_internal_set_sim_state_c10_ental(S, st);
}

static void sf_opaque_terminate_c10_ental(void *chartInstanceVar)
{
  if (chartInstanceVar!=NULL) {
    SimStruct *S = ((SFc10_entalInstanceStruct*) chartInstanceVar)->S;
    if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
      sf_clear_rtw_identifier(S);
    }

    finalize_c10_ental((SFc10_entalInstanceStruct*) chartInstanceVar);
    free((void *)chartInstanceVar);
    ssSetUserData(S,NULL);
  }
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  compInitSubchartSimstructsFcn_c10_ental((SFc10_entalInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c10_ental(SimStruct *S)
{
  int i;
  for (i=0;i<ssGetNumRunTimeParams(S);i++) {
    if (ssGetSFcnParamTunable(S,i)) {
      ssUpdateDlgParamAsRunTimeParam(S,i);
    }
  }

  if (sf_machine_global_initializer_called()) {
    initialize_params_c10_ental((SFc10_entalInstanceStruct*)(((ChartInfoStruct *)
      ssGetUserData(S))->chartInstance));
  }
}

static void mdlSetWorkWidths_c10_ental(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
    int_T chartIsInlinable =
      (int_T)sf_is_chart_inlinable(S,"ental","ental",10);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,"ental","ental",10,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,"ental","ental",10,
      "gatewayCannotBeInlinedMultipleTimes"));
    if (chartIsInlinable) {
      sf_mark_chart_reusable_outputs(S,"ental","ental",10,1);
    }

    sf_set_rtw_dwork_info(S,"ental","ental",10);
    ssSetHasSubFunctions(S,!(chartIsInlinable));
  } else {
  }

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(708278146U));
  ssSetChecksum1(S,(4199865534U));
  ssSetChecksum2(S,(3659004483U));
  ssSetChecksum3(S,(3902780655U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
}

static void mdlRTW_c10_ental(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S)) {
    sf_write_symbol_mapping(S, "ental", "ental",10);
    ssWriteRTWStrParam(S, "StateflowChartType", "Embedded MATLAB");
  }
}

static void mdlStart_c10_ental(SimStruct *S)
{
  SFc10_entalInstanceStruct *chartInstance;
  chartInstance = (SFc10_entalInstanceStruct *)malloc(sizeof
    (SFc10_entalInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc10_entalInstanceStruct));
  if (chartInstance==NULL) {
    sf_mex_error_message("Could not allocate memory for chart instance.");
  }

  chartInstance->chartInfo.chartInstance = chartInstance;
  chartInstance->chartInfo.isEMLChart = 1;
  chartInstance->chartInfo.chartInitialized = 0;
  chartInstance->chartInfo.sFunctionGateway = sf_opaque_gateway_c10_ental;
  chartInstance->chartInfo.initializeChart = sf_opaque_initialize_c10_ental;
  chartInstance->chartInfo.terminateChart = sf_opaque_terminate_c10_ental;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c10_ental;
  chartInstance->chartInfo.disableChart = sf_opaque_disable_c10_ental;
  chartInstance->chartInfo.getSimState = sf_opaque_get_sim_state_c10_ental;
  chartInstance->chartInfo.setSimState = sf_opaque_set_sim_state_c10_ental;
  chartInstance->chartInfo.getSimStateInfo = sf_get_sim_state_info_c10_ental;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c10_ental;
  chartInstance->chartInfo.mdlStart = mdlStart_c10_ental;
  chartInstance->chartInfo.mdlSetWorkWidths = mdlSetWorkWidths_c10_ental;
  chartInstance->chartInfo.extModeExec = NULL;
  chartInstance->chartInfo.restoreLastMajorStepConfiguration = NULL;
  chartInstance->chartInfo.restoreBeforeLastMajorStepConfiguration = NULL;
  chartInstance->chartInfo.storeCurrentConfiguration = NULL;
  chartInstance->S = S;
  ssSetUserData(S,(void *)(&(chartInstance->chartInfo)));/* register the chart instance with simstruct */
  init_dsm_address_info(chartInstance);
  if (!sim_mode_is_rtw_gen(S)) {
  }

  sf_opaque_init_subchart_simstructs(chartInstance->chartInfo.chartInstance);
  chart_debug_initialization(S,1);
}

void c10_ental_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c10_ental(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c10_ental(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c10_ental(S);
    break;

   default:
    /* Unhandled method */
    sf_mex_error_message("Stateflow Internal Error:\n"
                         "Error calling c10_ental_method_dispatcher.\n"
                         "Can't handle method %d.\n", method);
    break;
  }
}
