/* Include files */

#include "blascompat32.h"
#include "Hunt_crossley_Ident_sfun.h"
#include "c8_Hunt_crossley_Ident.h"
#include "mwmathutil.h"
#define CHARTINSTANCE_CHARTNUMBER      (chartInstance->chartNumber)
#define CHARTINSTANCE_INSTANCENUMBER   (chartInstance->instanceNumber)
#include "Hunt_crossley_Ident_sfun_debug_macros.h"

/* Type Definitions */

/* Named Constants */
#define CALL_EVENT                     (-1)

/* Variable Declarations */

/* Variable Definitions */
static const char * c8_debug_family_names[18] = { "p1", "p2", "t1", "t2", "t3",
  "patm", "ps", "f", "nargin", "nargout", "theta", "dtheta", "p", "uc", "ud",
  "tetaMCMC", "ddtheta", "dpMCMC" };

/* Function Declarations */
static void initialize_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void initialize_params_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void enable_c8_Hunt_crossley_Ident(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance);
static void disable_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void c8_update_debugger_state_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static const mxArray *get_sim_state_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void set_sim_state_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance, const mxArray *c8_st);
static void finalize_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void sf_c8_Hunt_crossley_Ident(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance);
static void initSimStructsc8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void init_script_number_translation(uint32_T c8_machineNumber, uint32_T
  c8_chartNumber);
static const mxArray *c8_sf_marshallOut(void *chartInstanceVoid, void *c8_inData);
static real_T c8_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_dpMCMC, const char_T *c8_identifier);
static real_T c8_b_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_u, const emlrtMsgIdentifier *c8_parentId);
static void c8_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c8_mxArrayInData, const char_T *c8_varName, void *c8_outData);
static const mxArray *c8_b_sf_marshallOut(void *chartInstanceVoid, void
  *c8_inData);
static void c8_eml_error(SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance);
static const mxArray *c8_c_sf_marshallOut(void *chartInstanceVoid, void
  *c8_inData);
static int32_T c8_c_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_u, const emlrtMsgIdentifier *c8_parentId);
static void c8_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c8_mxArrayInData, const char_T *c8_varName, void *c8_outData);
static uint8_T c8_d_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_b_is_active_c8_Hunt_crossley_Ident, const
  char_T *c8_identifier);
static uint8_T c8_e_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_u, const emlrtMsgIdentifier *c8_parentId);
static void init_dsm_address_info(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance);

/* Function Definitions */
static void initialize_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
  chartInstance->c8_sfEvent = CALL_EVENT;
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c8_is_active_c8_Hunt_crossley_Ident = 0U;
}

static void initialize_params_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

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

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

static void c8_update_debugger_state_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

static const mxArray *get_sim_state_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
  const mxArray *c8_st;
  const mxArray *c8_y = NULL;
  real_T c8_hoistedGlobal;
  real_T c8_u;
  const mxArray *c8_b_y = NULL;
  real_T c8_b_hoistedGlobal;
  real_T c8_b_u;
  const mxArray *c8_c_y = NULL;
  uint8_T c8_c_hoistedGlobal;
  uint8_T c8_c_u;
  const mxArray *c8_d_y = NULL;
  real_T *c8_ddtheta;
  real_T *c8_dpMCMC;
  c8_dpMCMC = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
  c8_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c8_st = NULL;
  c8_st = NULL;
  c8_y = NULL;
  sf_mex_assign(&c8_y, sf_mex_createcellarray(3), FALSE);
  c8_hoistedGlobal = *c8_ddtheta;
  c8_u = c8_hoistedGlobal;
  c8_b_y = NULL;
  sf_mex_assign(&c8_b_y, sf_mex_create("y", &c8_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c8_y, 0, c8_b_y);
  c8_b_hoistedGlobal = *c8_dpMCMC;
  c8_b_u = c8_b_hoistedGlobal;
  c8_c_y = NULL;
  sf_mex_assign(&c8_c_y, sf_mex_create("y", &c8_b_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c8_y, 1, c8_c_y);
  c8_c_hoistedGlobal = chartInstance->c8_is_active_c8_Hunt_crossley_Ident;
  c8_c_u = c8_c_hoistedGlobal;
  c8_d_y = NULL;
  sf_mex_assign(&c8_d_y, sf_mex_create("y", &c8_c_u, 3, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c8_y, 2, c8_d_y);
  sf_mex_assign(&c8_st, c8_y, FALSE);
  return c8_st;
}

static void set_sim_state_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance, const mxArray *c8_st)
{
  const mxArray *c8_u;
  real_T *c8_ddtheta;
  real_T *c8_dpMCMC;
  c8_dpMCMC = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
  c8_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c8_doneDoubleBufferReInit = TRUE;
  c8_u = sf_mex_dup(c8_st);
  *c8_ddtheta = c8_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell
    (c8_u, 0)), "ddtheta");
  *c8_dpMCMC = c8_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell(c8_u,
    1)), "dpMCMC");
  chartInstance->c8_is_active_c8_Hunt_crossley_Ident = c8_d_emlrt_marshallIn
    (chartInstance, sf_mex_dup(sf_mex_getcell(c8_u, 2)),
     "is_active_c8_Hunt_crossley_Ident");
  sf_mex_destroy(&c8_u);
  c8_update_debugger_state_c8_Hunt_crossley_Ident(chartInstance);
  sf_mex_destroy(&c8_st);
}

static void finalize_c8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

static void sf_c8_Hunt_crossley_Ident(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance)
{
  int32_T c8_i0;
  real_T c8_hoistedGlobal;
  real_T c8_b_hoistedGlobal;
  real_T c8_c_hoistedGlobal;
  real_T c8_d_hoistedGlobal;
  real_T c8_e_hoistedGlobal;
  real_T c8_theta;
  real_T c8_dtheta;
  real_T c8_p;
  real_T c8_uc;
  real_T c8_ud;
  int32_T c8_i1;
  real_T c8_tetaMCMC[2];
  uint32_T c8_debug_family_var_map[18];
  real_T c8_p1;
  real_T c8_p2;
  real_T c8_t1;
  real_T c8_t2;
  real_T c8_t3;
  real_T c8_patm;
  real_T c8_ps;
  real_T c8_f;
  real_T c8_nargin = 6.0;
  real_T c8_nargout = 2.0;
  real_T c8_ddtheta;
  real_T c8_dpMCMC;
  real_T c8_b;
  real_T c8_y;
  real_T c8_b_b;
  real_T c8_b_y;
  real_T c8_c_b;
  real_T c8_c_y;
  real_T c8_x;
  real_T c8_b_x;
  real_T c8_a;
  real_T c8_d_b;
  real_T c8_d_y;
  real_T c8_c_x;
  real_T c8_d_x;
  real_T c8_e_y;
  real_T c8_e_x;
  real_T c8_f_x;
  real_T c8_b_a;
  real_T c8_e_b;
  real_T c8_g_x;
  real_T c8_h_x;
  real_T c8_c_a;
  real_T c8_f_b;
  real_T c8_f_y;
  real_T c8_i_x;
  real_T c8_j_x;
  real_T c8_g_y;
  real_T c8_k_x;
  real_T c8_l_x;
  real_T c8_d_a;
  real_T c8_g_b;
  real_T c8_e_a;
  real_T c8_h_b;
  real_T c8_h_y;
  real_T c8_A;
  real_T c8_B;
  real_T c8_m_x;
  real_T c8_i_y;
  real_T c8_n_x;
  real_T c8_j_y;
  real_T *c8_b_dpMCMC;
  real_T *c8_b_ddtheta;
  real_T *c8_b_ud;
  real_T *c8_b_uc;
  real_T *c8_b_p;
  real_T *c8_b_dtheta;
  real_T *c8_b_theta;
  real_T (*c8_b_tetaMCMC)[2];
  c8_b_dpMCMC = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
  c8_b_tetaMCMC = (real_T (*)[2])ssGetInputPortSignal(chartInstance->S, 5);
  c8_b_ud = (real_T *)ssGetInputPortSignal(chartInstance->S, 4);
  c8_b_uc = (real_T *)ssGetInputPortSignal(chartInstance->S, 3);
  c8_b_p = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c8_b_dtheta = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c8_b_theta = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  c8_b_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 7U, chartInstance->c8_sfEvent);
  _SFD_DATA_RANGE_CHECK(*c8_b_ddtheta, 0U);
  _SFD_DATA_RANGE_CHECK(*c8_b_theta, 1U);
  _SFD_DATA_RANGE_CHECK(*c8_b_dtheta, 2U);
  _SFD_DATA_RANGE_CHECK(*c8_b_p, 3U);
  _SFD_DATA_RANGE_CHECK(*c8_b_uc, 4U);
  _SFD_DATA_RANGE_CHECK(*c8_b_ud, 5U);
  for (c8_i0 = 0; c8_i0 < 2; c8_i0++) {
    _SFD_DATA_RANGE_CHECK((*c8_b_tetaMCMC)[c8_i0], 6U);
  }

  _SFD_DATA_RANGE_CHECK(*c8_b_dpMCMC, 7U);
  chartInstance->c8_sfEvent = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 7U, chartInstance->c8_sfEvent);
  c8_hoistedGlobal = *c8_b_theta;
  c8_b_hoistedGlobal = *c8_b_dtheta;
  c8_c_hoistedGlobal = *c8_b_p;
  c8_d_hoistedGlobal = *c8_b_uc;
  c8_e_hoistedGlobal = *c8_b_ud;
  c8_theta = c8_hoistedGlobal;
  c8_dtheta = c8_b_hoistedGlobal;
  c8_p = c8_c_hoistedGlobal;
  c8_uc = c8_d_hoistedGlobal;
  c8_ud = c8_e_hoistedGlobal;
  for (c8_i1 = 0; c8_i1 < 2; c8_i1++) {
    c8_tetaMCMC[c8_i1] = (*c8_b_tetaMCMC)[c8_i1];
  }

  sf_debug_symbol_scope_push_eml(0U, 18U, 18U, c8_debug_family_names,
    c8_debug_family_var_map);
  sf_debug_symbol_scope_add_eml_importable(&c8_p1, 0U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c8_p2, 1U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c8_t1, 2U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c8_t2, 3U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c8_t3, 4U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c8_patm, 5U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c8_ps, 6U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c8_f, 7U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c8_nargin, 8U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c8_nargout, 9U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c8_theta, 10U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c8_dtheta, 11U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c8_p, 12U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c8_uc, 13U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c8_ud, 14U, c8_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(c8_tetaMCMC, 15U, c8_b_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c8_ddtheta, 16U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c8_dpMCMC, 17U, c8_sf_marshallOut,
    c8_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 3);
  c8_p1 = c8_tetaMCMC[0];
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 3);
  c8_p2 = c8_tetaMCMC[1];
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 4);
  c8_t1 = 1408.5;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 5);
  c8_t2 = 132.28;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 6);
  c8_t3 = 3319.4;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 7);
  c8_patm = 101325.0;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 8);
  c8_ps = 800000.0;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 10);
  c8_b = c8_p - c8_patm;
  c8_y = 1408.5 * c8_b;
  c8_b_b = c8_dtheta;
  c8_b_y = 132.28 * c8_b_b;
  c8_c_b = c8_theta;
  c8_c_y = 3319.4 * c8_c_b;
  c8_ddtheta = (c8_y - c8_b_y) - c8_c_y;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 11);
  if (CV_EML_IF(0, 1, 0, c8_uc > 0.0)) {
    _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 12);
    c8_x = c8_ps - c8_p;
    c8_b_x = c8_x;
    c8_b_x = muDoubleScalarSign(c8_b_x);
    c8_a = c8_uc;
    c8_d_b = c8_b_x;
    c8_d_y = c8_a * c8_d_b;
    c8_c_x = c8_ps - c8_p;
    c8_d_x = c8_c_x;
    c8_e_y = muDoubleScalarAbs(c8_d_x);
    c8_e_x = c8_e_y;
    c8_f_x = c8_e_x;
    if (c8_f_x < 0.0) {
      c8_eml_error(chartInstance);
    }

    c8_f_x = muDoubleScalarSqrt(c8_f_x);
    c8_b_a = c8_d_y;
    c8_e_b = c8_f_x;
    c8_f = c8_b_a * c8_e_b;
  } else {
    _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 14);
    c8_g_x = c8_p - c8_patm;
    c8_h_x = c8_g_x;
    c8_h_x = muDoubleScalarSign(c8_h_x);
    c8_c_a = c8_ud;
    c8_f_b = c8_h_x;
    c8_f_y = c8_c_a * c8_f_b;
    c8_i_x = c8_p - c8_patm;
    c8_j_x = c8_i_x;
    c8_g_y = muDoubleScalarAbs(c8_j_x);
    c8_k_x = c8_g_y;
    c8_l_x = c8_k_x;
    if (c8_l_x < 0.0) {
      c8_eml_error(chartInstance);
    }

    c8_l_x = muDoubleScalarSqrt(c8_l_x);
    c8_d_a = c8_f_y;
    c8_g_b = c8_l_x;
    c8_f = c8_d_a * c8_g_b;
  }

  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, 17);
  c8_e_a = c8_p2;
  c8_h_b = c8_p;
  c8_h_y = c8_e_a * c8_h_b;
  c8_A = c8_p1 + c8_h_y;
  c8_B = c8_f;
  c8_m_x = c8_B;
  c8_i_y = c8_A;
  c8_n_x = c8_m_x;
  c8_j_y = c8_i_y;
  c8_dpMCMC = c8_n_x / c8_j_y;
  _SFD_EML_CALL(0U, chartInstance->c8_sfEvent, -17);
  sf_debug_symbol_scope_pop();
  *c8_b_ddtheta = c8_ddtheta;
  *c8_b_dpMCMC = c8_dpMCMC;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 7U, chartInstance->c8_sfEvent);
  sf_debug_check_for_state_inconsistency(_Hunt_crossley_IdentMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
}

static void initSimStructsc8_Hunt_crossley_Ident
  (SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

static void init_script_number_translation(uint32_T c8_machineNumber, uint32_T
  c8_chartNumber)
{
}

static const mxArray *c8_sf_marshallOut(void *chartInstanceVoid, void *c8_inData)
{
  const mxArray *c8_mxArrayOutData = NULL;
  real_T c8_u;
  const mxArray *c8_y = NULL;
  SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c8_mxArrayOutData = NULL;
  c8_u = *(real_T *)c8_inData;
  c8_y = NULL;
  sf_mex_assign(&c8_y, sf_mex_create("y", &c8_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c8_mxArrayOutData, c8_y, FALSE);
  return c8_mxArrayOutData;
}

static real_T c8_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_dpMCMC, const char_T *c8_identifier)
{
  real_T c8_y;
  emlrtMsgIdentifier c8_thisId;
  c8_thisId.fIdentifier = c8_identifier;
  c8_thisId.fParent = NULL;
  c8_y = c8_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c8_dpMCMC), &c8_thisId);
  sf_mex_destroy(&c8_dpMCMC);
  return c8_y;
}

static real_T c8_b_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_u, const emlrtMsgIdentifier *c8_parentId)
{
  real_T c8_y;
  real_T c8_d0;
  sf_mex_import(c8_parentId, sf_mex_dup(c8_u), &c8_d0, 1, 0, 0U, 0, 0U, 0);
  c8_y = c8_d0;
  sf_mex_destroy(&c8_u);
  return c8_y;
}

static void c8_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c8_mxArrayInData, const char_T *c8_varName, void *c8_outData)
{
  const mxArray *c8_dpMCMC;
  const char_T *c8_identifier;
  emlrtMsgIdentifier c8_thisId;
  real_T c8_y;
  SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c8_dpMCMC = sf_mex_dup(c8_mxArrayInData);
  c8_identifier = c8_varName;
  c8_thisId.fIdentifier = c8_identifier;
  c8_thisId.fParent = NULL;
  c8_y = c8_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c8_dpMCMC), &c8_thisId);
  sf_mex_destroy(&c8_dpMCMC);
  *(real_T *)c8_outData = c8_y;
  sf_mex_destroy(&c8_mxArrayInData);
}

static const mxArray *c8_b_sf_marshallOut(void *chartInstanceVoid, void
  *c8_inData)
{
  const mxArray *c8_mxArrayOutData = NULL;
  int32_T c8_i2;
  real_T c8_b_inData[2];
  int32_T c8_i3;
  real_T c8_u[2];
  const mxArray *c8_y = NULL;
  SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c8_mxArrayOutData = NULL;
  for (c8_i2 = 0; c8_i2 < 2; c8_i2++) {
    c8_b_inData[c8_i2] = (*(real_T (*)[2])c8_inData)[c8_i2];
  }

  for (c8_i3 = 0; c8_i3 < 2; c8_i3++) {
    c8_u[c8_i3] = c8_b_inData[c8_i3];
  }

  c8_y = NULL;
  sf_mex_assign(&c8_y, sf_mex_create("y", c8_u, 0, 0U, 1U, 0U, 2, 2, 1), FALSE);
  sf_mex_assign(&c8_mxArrayOutData, c8_y, FALSE);
  return c8_mxArrayOutData;
}

const mxArray *sf_c8_Hunt_crossley_Ident_get_eml_resolved_functions_info(void)
{
  const mxArray *c8_nameCaptureInfo;
  c8_ResolvedFunctionInfo c8_info[11];
  c8_ResolvedFunctionInfo (*c8_b_info)[11];
  const mxArray *c8_m0 = NULL;
  int32_T c8_i4;
  c8_ResolvedFunctionInfo *c8_r0;
  c8_nameCaptureInfo = NULL;
  c8_nameCaptureInfo = NULL;
  c8_b_info = (c8_ResolvedFunctionInfo (*)[11])c8_info;
  (*c8_b_info)[0].context = "";
  (*c8_b_info)[0].name = "mtimes";
  (*c8_b_info)[0].dominantType = "double";
  (*c8_b_info)[0].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/ops/mtimes.m";
  (*c8_b_info)[0].fileTimeLo = 1289510692U;
  (*c8_b_info)[0].fileTimeHi = 0U;
  (*c8_b_info)[0].mFileTimeLo = 0U;
  (*c8_b_info)[0].mFileTimeHi = 0U;
  (*c8_b_info)[1].context = "";
  (*c8_b_info)[1].name = "sign";
  (*c8_b_info)[1].dominantType = "double";
  (*c8_b_info)[1].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/sign.m";
  (*c8_b_info)[1].fileTimeLo = 1286813350U;
  (*c8_b_info)[1].fileTimeHi = 0U;
  (*c8_b_info)[1].mFileTimeLo = 0U;
  (*c8_b_info)[1].mFileTimeHi = 0U;
  (*c8_b_info)[2].context =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/sign.m";
  (*c8_b_info)[2].name = "eml_scalar_sign";
  (*c8_b_info)[2].dominantType = "double";
  (*c8_b_info)[2].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/eml_scalar_sign.m";
  (*c8_b_info)[2].fileTimeLo = 1307642238U;
  (*c8_b_info)[2].fileTimeHi = 0U;
  (*c8_b_info)[2].mFileTimeLo = 0U;
  (*c8_b_info)[2].mFileTimeHi = 0U;
  (*c8_b_info)[3].context = "";
  (*c8_b_info)[3].name = "abs";
  (*c8_b_info)[3].dominantType = "double";
  (*c8_b_info)[3].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/abs.m";
  (*c8_b_info)[3].fileTimeLo = 1286813294U;
  (*c8_b_info)[3].fileTimeHi = 0U;
  (*c8_b_info)[3].mFileTimeLo = 0U;
  (*c8_b_info)[3].mFileTimeHi = 0U;
  (*c8_b_info)[4].context =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/abs.m";
  (*c8_b_info)[4].name = "eml_scalar_abs";
  (*c8_b_info)[4].dominantType = "double";
  (*c8_b_info)[4].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/eml_scalar_abs.m";
  (*c8_b_info)[4].fileTimeLo = 1286813312U;
  (*c8_b_info)[4].fileTimeHi = 0U;
  (*c8_b_info)[4].mFileTimeLo = 0U;
  (*c8_b_info)[4].mFileTimeHi = 0U;
  (*c8_b_info)[5].context = "";
  (*c8_b_info)[5].name = "sqrt";
  (*c8_b_info)[5].dominantType = "double";
  (*c8_b_info)[5].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/sqrt.m";
  (*c8_b_info)[5].fileTimeLo = 1286813352U;
  (*c8_b_info)[5].fileTimeHi = 0U;
  (*c8_b_info)[5].mFileTimeLo = 0U;
  (*c8_b_info)[5].mFileTimeHi = 0U;
  (*c8_b_info)[6].context =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/sqrt.m";
  (*c8_b_info)[6].name = "eml_error";
  (*c8_b_info)[6].dominantType = "char";
  (*c8_b_info)[6].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/eml/eml_error.m";
  (*c8_b_info)[6].fileTimeLo = 1305309000U;
  (*c8_b_info)[6].fileTimeHi = 0U;
  (*c8_b_info)[6].mFileTimeLo = 0U;
  (*c8_b_info)[6].mFileTimeHi = 0U;
  (*c8_b_info)[7].context =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/sqrt.m";
  (*c8_b_info)[7].name = "eml_scalar_sqrt";
  (*c8_b_info)[7].dominantType = "double";
  (*c8_b_info)[7].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/elfun/eml_scalar_sqrt.m";
  (*c8_b_info)[7].fileTimeLo = 1286813338U;
  (*c8_b_info)[7].fileTimeHi = 0U;
  (*c8_b_info)[7].mFileTimeLo = 0U;
  (*c8_b_info)[7].mFileTimeHi = 0U;
  (*c8_b_info)[8].context = "";
  (*c8_b_info)[8].name = "mldivide";
  (*c8_b_info)[8].dominantType = "double";
  (*c8_b_info)[8].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/ops/mldivide.p";
  (*c8_b_info)[8].fileTimeLo = 1342801944U;
  (*c8_b_info)[8].fileTimeHi = 0U;
  (*c8_b_info)[8].mFileTimeLo = 1319724566U;
  (*c8_b_info)[8].mFileTimeHi = 0U;
  (*c8_b_info)[9].context =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/ops/mldivide.p";
  (*c8_b_info)[9].name = "rdivide";
  (*c8_b_info)[9].dominantType = "double";
  (*c8_b_info)[9].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/ops/rdivide.m";
  (*c8_b_info)[9].fileTimeLo = 1286813444U;
  (*c8_b_info)[9].fileTimeHi = 0U;
  (*c8_b_info)[9].mFileTimeLo = 0U;
  (*c8_b_info)[9].mFileTimeHi = 0U;
  (*c8_b_info)[10].context =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/ops/rdivide.m";
  (*c8_b_info)[10].name = "eml_div";
  (*c8_b_info)[10].dominantType = "double";
  (*c8_b_info)[10].resolved =
    "[ILXE]$matlabroot$/toolbox/eml/lib/matlab/eml/eml_div.m";
  (*c8_b_info)[10].fileTimeLo = 1313338810U;
  (*c8_b_info)[10].fileTimeHi = 0U;
  (*c8_b_info)[10].mFileTimeLo = 0U;
  (*c8_b_info)[10].mFileTimeHi = 0U;
  sf_mex_assign(&c8_m0, sf_mex_createstruct("nameCaptureInfo", 1, 11), FALSE);
  for (c8_i4 = 0; c8_i4 < 11; c8_i4++) {
    c8_r0 = &c8_info[c8_i4];
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", c8_r0->context, 15,
      0U, 0U, 0U, 2, 1, strlen(c8_r0->context)), "context", "nameCaptureInfo",
                    c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", c8_r0->name, 15, 0U,
      0U, 0U, 2, 1, strlen(c8_r0->name)), "name", "nameCaptureInfo", c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", c8_r0->dominantType,
      15, 0U, 0U, 0U, 2, 1, strlen(c8_r0->dominantType)), "dominantType",
                    "nameCaptureInfo", c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", c8_r0->resolved, 15,
      0U, 0U, 0U, 2, 1, strlen(c8_r0->resolved)), "resolved", "nameCaptureInfo",
                    c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", &c8_r0->fileTimeLo,
      7, 0U, 0U, 0U, 0), "fileTimeLo", "nameCaptureInfo", c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", &c8_r0->fileTimeHi,
      7, 0U, 0U, 0U, 0), "fileTimeHi", "nameCaptureInfo", c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", &c8_r0->mFileTimeLo,
      7, 0U, 0U, 0U, 0), "mFileTimeLo", "nameCaptureInfo", c8_i4);
    sf_mex_addfield(c8_m0, sf_mex_create("nameCaptureInfo", &c8_r0->mFileTimeHi,
      7, 0U, 0U, 0U, 0), "mFileTimeHi", "nameCaptureInfo", c8_i4);
  }

  sf_mex_assign(&c8_nameCaptureInfo, c8_m0, FALSE);
  sf_mex_emlrtNameCapturePostProcessR2012a(&c8_nameCaptureInfo);
  return c8_nameCaptureInfo;
}

static void c8_eml_error(SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
  int32_T c8_i5;
  static char_T c8_varargin_1[30] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o',
    'o', 'l', 'b', 'o', 'x', ':', 's', 'q', 'r', 't', '_', 'd', 'o', 'm', 'a',
    'i', 'n', 'E', 'r', 'r', 'o', 'r' };

  char_T c8_u[30];
  const mxArray *c8_y = NULL;
  for (c8_i5 = 0; c8_i5 < 30; c8_i5++) {
    c8_u[c8_i5] = c8_varargin_1[c8_i5];
  }

  c8_y = NULL;
  sf_mex_assign(&c8_y, sf_mex_create("y", c8_u, 10, 0U, 1U, 0U, 2, 1, 30), FALSE);
  sf_mex_call_debug("error", 0U, 1U, 14, sf_mex_call_debug("message", 1U, 1U, 14,
    c8_y));
}

static const mxArray *c8_c_sf_marshallOut(void *chartInstanceVoid, void
  *c8_inData)
{
  const mxArray *c8_mxArrayOutData = NULL;
  int32_T c8_u;
  const mxArray *c8_y = NULL;
  SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c8_mxArrayOutData = NULL;
  c8_u = *(int32_T *)c8_inData;
  c8_y = NULL;
  sf_mex_assign(&c8_y, sf_mex_create("y", &c8_u, 6, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c8_mxArrayOutData, c8_y, FALSE);
  return c8_mxArrayOutData;
}

static int32_T c8_c_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_u, const emlrtMsgIdentifier *c8_parentId)
{
  int32_T c8_y;
  int32_T c8_i6;
  sf_mex_import(c8_parentId, sf_mex_dup(c8_u), &c8_i6, 1, 6, 0U, 0, 0U, 0);
  c8_y = c8_i6;
  sf_mex_destroy(&c8_u);
  return c8_y;
}

static void c8_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c8_mxArrayInData, const char_T *c8_varName, void *c8_outData)
{
  const mxArray *c8_b_sfEvent;
  const char_T *c8_identifier;
  emlrtMsgIdentifier c8_thisId;
  int32_T c8_y;
  SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c8_b_sfEvent = sf_mex_dup(c8_mxArrayInData);
  c8_identifier = c8_varName;
  c8_thisId.fIdentifier = c8_identifier;
  c8_thisId.fParent = NULL;
  c8_y = c8_c_emlrt_marshallIn(chartInstance, sf_mex_dup(c8_b_sfEvent),
    &c8_thisId);
  sf_mex_destroy(&c8_b_sfEvent);
  *(int32_T *)c8_outData = c8_y;
  sf_mex_destroy(&c8_mxArrayInData);
}

static uint8_T c8_d_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_b_is_active_c8_Hunt_crossley_Ident, const
  char_T *c8_identifier)
{
  uint8_T c8_y;
  emlrtMsgIdentifier c8_thisId;
  c8_thisId.fIdentifier = c8_identifier;
  c8_thisId.fParent = NULL;
  c8_y = c8_e_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c8_b_is_active_c8_Hunt_crossley_Ident), &c8_thisId);
  sf_mex_destroy(&c8_b_is_active_c8_Hunt_crossley_Ident);
  return c8_y;
}

static uint8_T c8_e_emlrt_marshallIn(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c8_u, const emlrtMsgIdentifier *c8_parentId)
{
  uint8_T c8_y;
  uint8_T c8_u0;
  sf_mex_import(c8_parentId, sf_mex_dup(c8_u), &c8_u0, 1, 3, 0U, 0, 0U, 0);
  c8_y = c8_u0;
  sf_mex_destroy(&c8_u);
  return c8_y;
}

static void init_dsm_address_info(SFc8_Hunt_crossley_IdentInstanceStruct
  *chartInstance)
{
}

/* SFunction Glue Code */
void sf_c8_Hunt_crossley_Ident_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(2781752621U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(3084904604U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(1716012848U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(291054117U);
}

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

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

  {
    mxArray *mxChecksum = mxCreateString("f3OAC6X2kNiAo0UyfWeacC");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

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

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

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      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));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"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,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"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,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"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,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"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,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"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,5,"type",mxType);
    }

    mxSetField(mxData,5,"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,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      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));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"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,1,"type",mxType);
    }

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

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

  return(mxAutoinheritanceInfo);
}

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

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

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 3, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c8_Hunt_crossley_Ident_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)) {
    SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
    chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *) ((ChartInfoStruct
      *)(ssGetUserData(S)))->chartInstance;
    if (ssIsFirstInitCond(S) && fullDebuggerInitialization==1) {
      /* do this only if simulation is starting */
      {
        unsigned int chartAlreadyPresent;
        chartAlreadyPresent = sf_debug_initialize_chart
          (_Hunt_crossley_IdentMachineNumber_,
           8,
           1,
           1,
           8,
           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(_Hunt_crossley_IdentMachineNumber_,
            chartInstance->chartNumber);
          sf_debug_set_chart_disable_implicit_casting
            (_Hunt_crossley_IdentMachineNumber_,chartInstance->chartNumber,1);
          sf_debug_set_chart_event_thresholds(_Hunt_crossley_IdentMachineNumber_,
            chartInstance->chartNumber,
            0,
            0,
            0);
          _SFD_SET_DATA_PROPS(0,2,0,1,"ddtheta");
          _SFD_SET_DATA_PROPS(1,1,1,0,"theta");
          _SFD_SET_DATA_PROPS(2,1,1,0,"dtheta");
          _SFD_SET_DATA_PROPS(3,1,1,0,"p");
          _SFD_SET_DATA_PROPS(4,1,1,0,"uc");
          _SFD_SET_DATA_PROPS(5,1,1,0,"ud");
          _SFD_SET_DATA_PROPS(6,1,1,0,"tetaMCMC");
          _SFD_SET_DATA_PROPS(7,2,0,1,"dpMCMC");
          _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 MATLAB Function Model Coverage */
        _SFD_CV_INIT_EML(0,1,1,1,0,0,0,0,0,0,0);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,351);
        _SFD_CV_INIT_EML_IF(0,1,0,227,234,274,325);
        _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);
        }

        _SFD_SET_DATA_COMPILED_PROPS(0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)c8_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(2,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(3,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(4,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(5,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)NULL);

        {
          unsigned int dimVector[2];
          dimVector[0]= 2;
          dimVector[1]= 1;
          _SFD_SET_DATA_COMPILED_PROPS(6,SF_DOUBLE,2,&(dimVector[0]),0,0,0,0.0,
            1.0,0,0,(MexFcnForType)c8_b_sf_marshallOut,(MexInFcnForType)NULL);
        }

        _SFD_SET_DATA_COMPILED_PROPS(7,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c8_sf_marshallOut,(MexInFcnForType)c8_sf_marshallIn);

        {
          real_T *c8_ddtheta;
          real_T *c8_theta;
          real_T *c8_dtheta;
          real_T *c8_p;
          real_T *c8_uc;
          real_T *c8_ud;
          real_T *c8_dpMCMC;
          real_T (*c8_tetaMCMC)[2];
          c8_dpMCMC = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
          c8_tetaMCMC = (real_T (*)[2])ssGetInputPortSignal(chartInstance->S, 5);
          c8_ud = (real_T *)ssGetInputPortSignal(chartInstance->S, 4);
          c8_uc = (real_T *)ssGetInputPortSignal(chartInstance->S, 3);
          c8_p = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
          c8_dtheta = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
          c8_theta = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
          c8_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
          _SFD_SET_DATA_VALUE_PTR(0U, c8_ddtheta);
          _SFD_SET_DATA_VALUE_PTR(1U, c8_theta);
          _SFD_SET_DATA_VALUE_PTR(2U, c8_dtheta);
          _SFD_SET_DATA_VALUE_PTR(3U, c8_p);
          _SFD_SET_DATA_VALUE_PTR(4U, c8_uc);
          _SFD_SET_DATA_VALUE_PTR(5U, c8_ud);
          _SFD_SET_DATA_VALUE_PTR(6U, *c8_tetaMCMC);
          _SFD_SET_DATA_VALUE_PTR(7U, c8_dpMCMC);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration
        (_Hunt_crossley_IdentMachineNumber_,chartInstance->chartNumber,
         chartInstance->instanceNumber);
    }
  }
}

static const char* sf_get_instance_specialization()
{
  return "0Faq6R1CNH5oFzNlMIjI1C";
}

static void sf_opaque_initialize_c8_Hunt_crossley_Ident(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar)->S,0);
  initialize_params_c8_Hunt_crossley_Ident
    ((SFc8_Hunt_crossley_IdentInstanceStruct*) chartInstanceVar);
  initialize_c8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_enable_c8_Hunt_crossley_Ident(void *chartInstanceVar)
{
  enable_c8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_disable_c8_Hunt_crossley_Ident(void *chartInstanceVar)
{
  disable_c8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_gateway_c8_Hunt_crossley_Ident(void *chartInstanceVar)
{
  sf_c8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

extern const mxArray* sf_internal_get_sim_state_c8_Hunt_crossley_Ident(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_c8_Hunt_crossley_Ident
    ((SFc8_Hunt_crossley_IdentInstanceStruct*)chartInfo->chartInstance);/* raw sim ctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c8_Hunt_crossley_Ident();/* 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];
}

extern void sf_internal_set_sim_state_c8_Hunt_crossley_Ident(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_c8_Hunt_crossley_Ident();/* 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_c8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInfo->chartInstance, mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static const mxArray* sf_opaque_get_sim_state_c8_Hunt_crossley_Ident(SimStruct*
  S)
{
  return sf_internal_get_sim_state_c8_Hunt_crossley_Ident(S);
}

static void sf_opaque_set_sim_state_c8_Hunt_crossley_Ident(SimStruct* S, const
  mxArray *st)
{
  sf_internal_set_sim_state_c8_Hunt_crossley_Ident(S, st);
}

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

    finalize_c8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
      chartInstanceVar);
    free((void *)chartInstanceVar);
    ssSetUserData(S,NULL);
  }

  unload_Hunt_crossley_Ident_optimization_info();
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  initSimStructsc8_Hunt_crossley_Ident((SFc8_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c8_Hunt_crossley_Ident(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_c8_Hunt_crossley_Ident
      ((SFc8_Hunt_crossley_IdentInstanceStruct*)(((ChartInfoStruct *)
         ssGetUserData(S))->chartInstance));
  }
}

static void mdlSetWorkWidths_c8_Hunt_crossley_Ident(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
    mxArray *infoStruct = load_Hunt_crossley_Ident_optimization_info();
    int_T chartIsInlinable =
      (int_T)sf_is_chart_inlinable(S,sf_get_instance_specialization(),infoStruct,
      8);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,sf_get_instance_specialization(),
                infoStruct,8,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,
      sf_get_instance_specialization(),infoStruct,8,
      "gatewayCannotBeInlinedMultipleTimes"));
    if (chartIsInlinable) {
      ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 3, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 4, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 5, SS_REUSABLE_AND_LOCAL);
      sf_mark_chart_expressionable_inputs(S,sf_get_instance_specialization(),
        infoStruct,8,6);
      sf_mark_chart_reusable_outputs(S,sf_get_instance_specialization(),
        infoStruct,8,2);
    }

    sf_set_rtw_dwork_info(S,sf_get_instance_specialization(),infoStruct,8);
    ssSetHasSubFunctions(S,!(chartIsInlinable));
  } else {
  }

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(2830527393U));
  ssSetChecksum1(S,(3863487314U));
  ssSetChecksum2(S,(3487270167U));
  ssSetChecksum3(S,(1862597343U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
  ssSupportsMultipleExecInstances(S,1);
}

static void mdlRTW_c8_Hunt_crossley_Ident(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S)) {
    ssWriteRTWStrParam(S, "StateflowChartType", "Embedded MATLAB");
  }
}

static void mdlStart_c8_Hunt_crossley_Ident(SimStruct *S)
{
  SFc8_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc8_Hunt_crossley_IdentInstanceStruct *)malloc(sizeof
    (SFc8_Hunt_crossley_IdentInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc8_Hunt_crossley_IdentInstanceStruct));
  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_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.initializeChart =
    sf_opaque_initialize_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.terminateChart =
    sf_opaque_terminate_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.disableChart =
    sf_opaque_disable_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.getSimState =
    sf_opaque_get_sim_state_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.setSimState =
    sf_opaque_set_sim_state_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.getSimStateInfo =
    sf_get_sim_state_info_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.mdlStart = mdlStart_c8_Hunt_crossley_Ident;
  chartInstance->chartInfo.mdlSetWorkWidths =
    mdlSetWorkWidths_c8_Hunt_crossley_Ident;
  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 c8_Hunt_crossley_Ident_method_dispatcher(SimStruct *S, int_T method, void
  *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c8_Hunt_crossley_Ident(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c8_Hunt_crossley_Ident(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c8_Hunt_crossley_Ident(S);
    break;

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