/* Include files */

#include "blascompat32.h"
#include "ental_sfun.h"
#include "c19_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 *c19_debug_family_names[4] = { "nargin", "nargout", "hh", "Hh"
};

/* Function Declarations */
static void initialize_c19_ental(SFc19_entalInstanceStruct *chartInstance);
static void initialize_params_c19_ental(SFc19_entalInstanceStruct *chartInstance);
static void enable_c19_ental(SFc19_entalInstanceStruct *chartInstance);
static void disable_c19_ental(SFc19_entalInstanceStruct *chartInstance);
static void c19_update_debugger_state_c19_ental(SFc19_entalInstanceStruct
  *chartInstance);
static const mxArray *get_sim_state_c19_ental(SFc19_entalInstanceStruct
  *chartInstance);
static void set_sim_state_c19_ental(SFc19_entalInstanceStruct *chartInstance,
  const mxArray *c19_st);
static void finalize_c19_ental(SFc19_entalInstanceStruct *chartInstance);
static void sf_c19_ental(SFc19_entalInstanceStruct *chartInstance);
static void compInitSubchartSimstructsFcn_c19_ental(SFc19_entalInstanceStruct
  *chartInstance);
static void init_script_number_translation(uint32_T c19_machineNumber, uint32_T
  c19_chartNumber);
static const mxArray *c19_sf_marshall(void *chartInstanceVoid, void *c19_u);
static const mxArray *c19_b_sf_marshall(void *chartInstanceVoid, void *c19_u);
static const mxArray *c19_c_sf_marshall(void *chartInstanceVoid, void *c19_u);
static void c19_emlrt_marshallIn(SFc19_entalInstanceStruct *chartInstance, const
  mxArray *c19_Hh, const char_T *c19_name, real_T c19_y[7185]);
static uint8_T c19_b_emlrt_marshallIn(SFc19_entalInstanceStruct *chartInstance,
  const mxArray *c19_b_is_active_c19_ental, const char_T *c19_name);
static void init_dsm_address_info(SFc19_entalInstanceStruct *chartInstance);

/* Function Definitions */
static void initialize_c19_ental(SFc19_entalInstanceStruct *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c19_is_active_c19_ental = 0U;
}

static void initialize_params_c19_ental(SFc19_entalInstanceStruct *chartInstance)
{
}

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

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

static void c19_update_debugger_state_c19_ental(SFc19_entalInstanceStruct
  *chartInstance)
{
}

static const mxArray *get_sim_state_c19_ental(SFc19_entalInstanceStruct
  *chartInstance)
{
  const mxArray *c19_st = NULL;
  const mxArray *c19_y = NULL;
  int32_T c19_i0;
  real_T c19_hoistedGlobal[7185];
  int32_T c19_i1;
  real_T c19_u[7185];
  const mxArray *c19_b_y = NULL;
  uint8_T c19_b_hoistedGlobal;
  uint8_T c19_b_u;
  const mxArray *c19_c_y = NULL;
  real_T (*c19_Hh)[7185];
  c19_Hh = (real_T (*)[7185])ssGetOutputPortSignal(chartInstance->S, 1);
  c19_st = NULL;
  c19_y = NULL;
  sf_mex_assign(&c19_y, sf_mex_createcellarray(2));
  for (c19_i0 = 0; c19_i0 < 7185; c19_i0 = c19_i0 + 1) {
    c19_hoistedGlobal[c19_i0] = (*c19_Hh)[c19_i0];
  }

  for (c19_i1 = 0; c19_i1 < 7185; c19_i1 = c19_i1 + 1) {
    c19_u[c19_i1] = c19_hoistedGlobal[c19_i1];
  }

  c19_b_y = NULL;
  sf_mex_assign(&c19_b_y, sf_mex_create("y", c19_u, 0, 0U, 1U, 0U, 2, 15, 479));
  sf_mex_setcell(c19_y, 0, c19_b_y);
  c19_b_hoistedGlobal = chartInstance->c19_is_active_c19_ental;
  c19_b_u = c19_b_hoistedGlobal;
  c19_c_y = NULL;
  sf_mex_assign(&c19_c_y, sf_mex_create("y", &c19_b_u, 3, 0U, 0U, 0U, 0));
  sf_mex_setcell(c19_y, 1, c19_c_y);
  sf_mex_assign(&c19_st, c19_y);
  return c19_st;
}

static void set_sim_state_c19_ental(SFc19_entalInstanceStruct *chartInstance,
  const mxArray *c19_st)
{
  const mxArray *c19_u;
  real_T c19_dv0[7185];
  int32_T c19_i2;
  real_T (*c19_Hh)[7185];
  c19_Hh = (real_T (*)[7185])ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c19_doneDoubleBufferReInit = TRUE;
  c19_u = sf_mex_dup(c19_st);
  c19_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell(c19_u, 0)), "Hh",
                       c19_dv0);
  for (c19_i2 = 0; c19_i2 < 7185; c19_i2 = c19_i2 + 1) {
    (*c19_Hh)[c19_i2] = c19_dv0[c19_i2];
  }

  chartInstance->c19_is_active_c19_ental = c19_b_emlrt_marshallIn(chartInstance,
    sf_mex_dup(sf_mex_getcell(c19_u, 1)),
    "is_active_c19_ental");
  sf_mex_destroy(&c19_u);
  c19_update_debugger_state_c19_ental(chartInstance);
  sf_mex_destroy(&c19_st);
}

static void finalize_c19_ental(SFc19_entalInstanceStruct *chartInstance)
{
}

static void sf_c19_ental(SFc19_entalInstanceStruct *chartInstance)
{
  int32_T c19_i3;
  int32_T c19_i4;
  int32_T c19_previousEvent;
  int32_T c19_i5;
  real_T c19_hoistedGlobal[7185];
  int32_T c19_i6;
  real_T c19_hh[7185];
  uint32_T c19_debug_family_var_map[4];
  real_T c19_nargin = 1.0;
  real_T c19_nargout = 1.0;
  real_T c19_Hh[7185];
  int32_T c19_i7;
  int32_T c19_i8;
  real_T (*c19_b_Hh)[7185];
  real_T (*c19_b_hh)[7185];
  c19_b_hh = (real_T (*)[7185])ssGetInputPortSignal(chartInstance->S, 0);
  c19_b_Hh = (real_T (*)[7185])ssGetOutputPortSignal(chartInstance->S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 18);
  for (c19_i3 = 0; c19_i3 < 7185; c19_i3 = c19_i3 + 1) {
    _SFD_DATA_RANGE_CHECK((*c19_b_Hh)[c19_i3], 0U);
  }

  for (c19_i4 = 0; c19_i4 < 7185; c19_i4 = c19_i4 + 1) {
    _SFD_DATA_RANGE_CHECK((*c19_b_hh)[c19_i4], 1U);
  }

  c19_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 18);
  for (c19_i5 = 0; c19_i5 < 7185; c19_i5 = c19_i5 + 1) {
    c19_hoistedGlobal[c19_i5] = (*c19_b_hh)[c19_i5];
  }

  for (c19_i6 = 0; c19_i6 < 7185; c19_i6 = c19_i6 + 1) {
    c19_hh[c19_i6] = c19_hoistedGlobal[c19_i6];
  }

  sf_debug_symbol_scope_push_eml(0U, 4U, 4U, c19_debug_family_names,
    c19_debug_family_var_map);
  sf_debug_symbol_scope_add_eml(&c19_nargin, c19_b_sf_marshall, 0U);
  sf_debug_symbol_scope_add_eml(&c19_nargout, c19_b_sf_marshall, 1U);
  sf_debug_symbol_scope_add_eml(c19_hh, c19_sf_marshall, 2U);
  sf_debug_symbol_scope_add_eml(c19_Hh, c19_sf_marshall, 3U);
  CV_EML_FCN(0, 0);

  /*  M=15;N=479; */
  /*  rozptyl=0.5*10^8; */
  /*  nahoda=randn(M,N).*rozptyl; */
  /*  Hh=nahoda+hh; */
  /* bez nahody */
  _SFD_EML_CALL(0, 10);
  for (c19_i7 = 0; c19_i7 < 7185; c19_i7 = c19_i7 + 1) {
    c19_Hh[c19_i7] = c19_hh[c19_i7];
  }

  _SFD_EML_CALL(0, -10);
  sf_debug_symbol_scope_pop();
  for (c19_i8 = 0; c19_i8 < 7185; c19_i8 = c19_i8 + 1) {
    (*c19_b_Hh)[c19_i8] = c19_Hh[c19_i8];
  }

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

static void compInitSubchartSimstructsFcn_c19_ental(SFc19_entalInstanceStruct
  *chartInstance)
{
}

static void init_script_number_translation(uint32_T c19_machineNumber, uint32_T
  c19_chartNumber)
{
}

static const mxArray *c19_sf_marshall(void *chartInstanceVoid, void *c19_u)
{
  const mxArray *c19_y = NULL;
  int32_T c19_i9;
  int32_T c19_i10;
  int32_T c19_i11;
  real_T c19_b_u[7185];
  int32_T c19_i12;
  int32_T c19_i13;
  int32_T c19_i14;
  real_T c19_c_u[7185];
  const mxArray *c19_b_y = NULL;
  SFc19_entalInstanceStruct *chartInstance;
  chartInstance = (SFc19_entalInstanceStruct *)chartInstanceVoid;
  c19_y = NULL;
  c19_i9 = 0;
  for (c19_i10 = 0; c19_i10 < 479; c19_i10 = c19_i10 + 1) {
    for (c19_i11 = 0; c19_i11 < 15; c19_i11 = c19_i11 + 1) {
      c19_b_u[c19_i11 + c19_i9] = (*((real_T (*)[7185])c19_u))[c19_i11 + c19_i9];
    }

    c19_i9 = c19_i9 + 15;
  }

  c19_i12 = 0;
  for (c19_i13 = 0; c19_i13 < 479; c19_i13 = c19_i13 + 1) {
    for (c19_i14 = 0; c19_i14 < 15; c19_i14 = c19_i14 + 1) {
      c19_c_u[c19_i14 + c19_i12] = c19_b_u[c19_i14 + c19_i12];
    }

    c19_i12 = c19_i12 + 15;
  }

  c19_b_y = NULL;
  sf_mex_assign(&c19_b_y, sf_mex_create("y", c19_c_u, 0, 0U, 1U, 0U, 2, 15, 479));
  sf_mex_assign(&c19_y, c19_b_y);
  return c19_y;
}

static const mxArray *c19_b_sf_marshall(void *chartInstanceVoid, void *c19_u)
{
  const mxArray *c19_y = NULL;
  real_T c19_b_u;
  const mxArray *c19_b_y = NULL;
  SFc19_entalInstanceStruct *chartInstance;
  chartInstance = (SFc19_entalInstanceStruct *)chartInstanceVoid;
  c19_y = NULL;
  c19_b_u = *((real_T *)c19_u);
  c19_b_y = NULL;
  sf_mex_assign(&c19_b_y, sf_mex_create("y", &c19_b_u, 0, 0U, 0U, 0U, 0));
  sf_mex_assign(&c19_y, c19_b_y);
  return c19_y;
}

const mxArray *sf_c19_ental_get_eml_resolved_functions_info(void)
{
  const mxArray *c19_nameCaptureInfo = NULL;
  c19_nameCaptureInfo = NULL;
  sf_mex_assign(&c19_nameCaptureInfo, sf_mex_create("nameCaptureInfo", NULL, 0,
    0U, 1U, 0U, 2, 0, 1));
  return c19_nameCaptureInfo;
}

static const mxArray *c19_c_sf_marshall(void *chartInstanceVoid, void *c19_u)
{
  const mxArray *c19_y = NULL;
  boolean_T c19_b_u;
  const mxArray *c19_b_y = NULL;
  SFc19_entalInstanceStruct *chartInstance;
  chartInstance = (SFc19_entalInstanceStruct *)chartInstanceVoid;
  c19_y = NULL;
  c19_b_u = *((boolean_T *)c19_u);
  c19_b_y = NULL;
  sf_mex_assign(&c19_b_y, sf_mex_create("y", &c19_b_u, 11, 0U, 0U, 0U, 0));
  sf_mex_assign(&c19_y, c19_b_y);
  return c19_y;
}

static void c19_emlrt_marshallIn(SFc19_entalInstanceStruct *chartInstance, const
  mxArray *c19_Hh, const char_T *c19_name, real_T
  c19_y[7185])
{
  real_T c19_dv1[7185];
  int32_T c19_i15;
  sf_mex_import(c19_name, sf_mex_dup(c19_Hh), c19_dv1, 1, 0, 0U, 1, 0U, 2, 15,
                479);
  for (c19_i15 = 0; c19_i15 < 7185; c19_i15 = c19_i15 + 1) {
    c19_y[c19_i15] = c19_dv1[c19_i15];
  }

  sf_mex_destroy(&c19_Hh);
}

static uint8_T c19_b_emlrt_marshallIn(SFc19_entalInstanceStruct *chartInstance,
  const mxArray *c19_b_is_active_c19_ental, const
  char_T *c19_name)
{
  uint8_T c19_y;
  uint8_T c19_u0;
  sf_mex_import(c19_name, sf_mex_dup(c19_b_is_active_c19_ental), &c19_u0, 1, 3,
                0U, 0, 0U, 0);
  c19_y = c19_u0;
  sf_mex_destroy(&c19_b_is_active_c19_ental);
  return c19_y;
}

static void init_dsm_address_info(SFc19_entalInstanceStruct *chartInstance)
{
}

/* SFunction Glue Code */
void sf_c19_ental_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(3587688044U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(3262839706U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(1238655190U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(2024376364U);
}

mxArray *sf_c19_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)(1467137556U);
    pr[1] = (double)(1615233994U);
    pr[2] = (double)(2180065189U);
    pr[3] = (double)(454036263U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    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)(15);
      pr[1] = (double)(479);
      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,"inputs",mxData);
  }

  {
    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)(15);
      pr[1] = (double)(479);
      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_c19_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\"Hh\",},{M[8],M[0],T\"is_active_c19_ental\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 2, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c19_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)) {
    SFc19_entalInstanceStruct *chartInstance;
    chartInstance = (SFc19_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_,
          19,
          1,
          1,
          2,
          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,"Hh");
          _SFD_SET_DATA_PROPS(1,1,1,0,"hh");
          _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,131);
        _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[2];
          dimVector[0]= 15;
          dimVector[1]= 479;
          _SFD_SET_DATA_COMPILED_PROPS(0,SF_DOUBLE,2,&(dimVector[0]),0,0,0,0.0,
            1.0,0,0,(MexFcnForType)c19_sf_marshall);
        }

        {
          unsigned int dimVector[2];
          dimVector[0]= 15;
          dimVector[1]= 479;
          _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,2,&(dimVector[0]),0,0,0,0.0,
            1.0,0,0,(MexFcnForType)c19_sf_marshall);
        }

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

static void sf_opaque_initialize_c19_ental(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc19_entalInstanceStruct*) chartInstanceVar)->S,
    0);
  initialize_params_c19_ental((SFc19_entalInstanceStruct*) chartInstanceVar);
  initialize_c19_ental((SFc19_entalInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_enable_c19_ental(void *chartInstanceVar)
{
  enable_c19_ental((SFc19_entalInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_disable_c19_ental(void *chartInstanceVar)
{
  disable_c19_ental((SFc19_entalInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_gateway_c19_ental(void *chartInstanceVar)
{
  sf_c19_ental((SFc19_entalInstanceStruct*) chartInstanceVar);
}

static mxArray* sf_internal_get_sim_state_c19_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_c19_ental((SFc19_entalInstanceStruct*)
    chartInfo->chartInstance);         /* raw sim ctx */
  prhs[3] = sf_get_sim_state_info_c19_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_c19_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_c19_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_c19_ental((SFc19_entalInstanceStruct*)chartInfo->chartInstance,
    mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static mxArray* sf_opaque_get_sim_state_c19_ental(SimStruct* S)
{
  return sf_internal_get_sim_state_c19_ental(S);
}

static void sf_opaque_set_sim_state_c19_ental(SimStruct* S, const mxArray *st)
{
  sf_internal_set_sim_state_c19_ental(S, st);
}

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

    finalize_c19_ental((SFc19_entalInstanceStruct*) chartInstanceVar);
    free((void *)chartInstanceVar);
    ssSetUserData(S,NULL);
  }
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  compInitSubchartSimstructsFcn_c19_ental((SFc19_entalInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c19_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_c19_ental((SFc19_entalInstanceStruct*)(((ChartInfoStruct *)
      ssGetUserData(S))->chartInstance));
  }
}

static void mdlSetWorkWidths_c19_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",19);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,"ental","ental",19,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,"ental","ental",19,
      "gatewayCannotBeInlinedMultipleTimes"));
    if (chartIsInlinable) {
      ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
      sf_mark_chart_expressionable_inputs(S,"ental","ental",19,1);
      sf_mark_chart_reusable_outputs(S,"ental","ental",19,1);
    }

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

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(2984958123U));
  ssSetChecksum1(S,(1229196350U));
  ssSetChecksum2(S,(26144739U));
  ssSetChecksum3(S,(1130236535U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
}

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

static void mdlStart_c19_ental(SimStruct *S)
{
  SFc19_entalInstanceStruct *chartInstance;
  chartInstance = (SFc19_entalInstanceStruct *)malloc(sizeof
    (SFc19_entalInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc19_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_c19_ental;
  chartInstance->chartInfo.initializeChart = sf_opaque_initialize_c19_ental;
  chartInstance->chartInfo.terminateChart = sf_opaque_terminate_c19_ental;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c19_ental;
  chartInstance->chartInfo.disableChart = sf_opaque_disable_c19_ental;
  chartInstance->chartInfo.getSimState = sf_opaque_get_sim_state_c19_ental;
  chartInstance->chartInfo.setSimState = sf_opaque_set_sim_state_c19_ental;
  chartInstance->chartInfo.getSimStateInfo = sf_get_sim_state_info_c19_ental;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c19_ental;
  chartInstance->chartInfo.mdlStart = mdlStart_c19_ental;
  chartInstance->chartInfo.mdlSetWorkWidths = mdlSetWorkWidths_c19_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 c19_ental_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c19_ental(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c19_ental(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c19_ental(S);
    break;

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