/* Include files */

#include "blascompat32.h"
#include "Hunt_crossley_Ident_sfun.h"
#include "c1_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 * c1_debug_family_names[19] = { "t1", "t2", "t3", "t4", "t5",
  "t6", "t7", "patm", "ps", "nargin", "nargout", "theta", "dtheta", "p", "uc",
  "ud", "ddtheta", "dp", "f" };

/* Function Declarations */
static void initialize_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void initialize_params_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void enable_c1_Hunt_crossley_Ident(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance);
static void disable_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void c1_update_debugger_state_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static const mxArray *get_sim_state_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void set_sim_state_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance, const mxArray *c1_st);
static void finalize_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void sf_c1_Hunt_crossley_Ident(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance);
static void initSimStructsc1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static void init_script_number_translation(uint32_T c1_machineNumber, uint32_T
  c1_chartNumber);
static const mxArray *c1_sf_marshallOut(void *chartInstanceVoid, void *c1_inData);
static real_T c1_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_f, const char_T *c1_identifier);
static real_T c1_b_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_u, const emlrtMsgIdentifier *c1_parentId);
static void c1_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c1_mxArrayInData, const char_T *c1_varName, void *c1_outData);
static void c1_eml_error(SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance);
static const mxArray *c1_b_sf_marshallOut(void *chartInstanceVoid, void
  *c1_inData);
static int32_T c1_c_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_u, const emlrtMsgIdentifier *c1_parentId);
static void c1_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c1_mxArrayInData, const char_T *c1_varName, void *c1_outData);
static uint8_T c1_d_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_b_is_active_c1_Hunt_crossley_Ident, const
  char_T *c1_identifier);
static uint8_T c1_e_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_u, const emlrtMsgIdentifier *c1_parentId);
static void init_dsm_address_info(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance);

/* Function Definitions */
static void initialize_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
  chartInstance->c1_sfEvent = CALL_EVENT;
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c1_is_active_c1_Hunt_crossley_Ident = 0U;
}

static void initialize_params_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

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

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

static void c1_update_debugger_state_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

static const mxArray *get_sim_state_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
  const mxArray *c1_st;
  const mxArray *c1_y = NULL;
  real_T c1_hoistedGlobal;
  real_T c1_u;
  const mxArray *c1_b_y = NULL;
  real_T c1_b_hoistedGlobal;
  real_T c1_b_u;
  const mxArray *c1_c_y = NULL;
  real_T c1_c_hoistedGlobal;
  real_T c1_c_u;
  const mxArray *c1_d_y = NULL;
  uint8_T c1_d_hoistedGlobal;
  uint8_T c1_d_u;
  const mxArray *c1_e_y = NULL;
  real_T *c1_ddtheta;
  real_T *c1_dp;
  real_T *c1_f;
  c1_f = (real_T *)ssGetOutputPortSignal(chartInstance->S, 3);
  c1_dp = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
  c1_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c1_st = NULL;
  c1_st = NULL;
  c1_y = NULL;
  sf_mex_assign(&c1_y, sf_mex_createcellarray(4), FALSE);
  c1_hoistedGlobal = *c1_ddtheta;
  c1_u = c1_hoistedGlobal;
  c1_b_y = NULL;
  sf_mex_assign(&c1_b_y, sf_mex_create("y", &c1_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c1_y, 0, c1_b_y);
  c1_b_hoistedGlobal = *c1_dp;
  c1_b_u = c1_b_hoistedGlobal;
  c1_c_y = NULL;
  sf_mex_assign(&c1_c_y, sf_mex_create("y", &c1_b_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c1_y, 1, c1_c_y);
  c1_c_hoistedGlobal = *c1_f;
  c1_c_u = c1_c_hoistedGlobal;
  c1_d_y = NULL;
  sf_mex_assign(&c1_d_y, sf_mex_create("y", &c1_c_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c1_y, 2, c1_d_y);
  c1_d_hoistedGlobal = chartInstance->c1_is_active_c1_Hunt_crossley_Ident;
  c1_d_u = c1_d_hoistedGlobal;
  c1_e_y = NULL;
  sf_mex_assign(&c1_e_y, sf_mex_create("y", &c1_d_u, 3, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c1_y, 3, c1_e_y);
  sf_mex_assign(&c1_st, c1_y, FALSE);
  return c1_st;
}

static void set_sim_state_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance, const mxArray *c1_st)
{
  const mxArray *c1_u;
  real_T *c1_ddtheta;
  real_T *c1_dp;
  real_T *c1_f;
  c1_f = (real_T *)ssGetOutputPortSignal(chartInstance->S, 3);
  c1_dp = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
  c1_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c1_doneDoubleBufferReInit = TRUE;
  c1_u = sf_mex_dup(c1_st);
  *c1_ddtheta = c1_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell
    (c1_u, 0)), "ddtheta");
  *c1_dp = c1_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell(c1_u, 1)),
    "dp");
  *c1_f = c1_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell(c1_u, 2)),
    "f");
  chartInstance->c1_is_active_c1_Hunt_crossley_Ident = c1_d_emlrt_marshallIn
    (chartInstance, sf_mex_dup(sf_mex_getcell(c1_u, 3)),
     "is_active_c1_Hunt_crossley_Ident");
  sf_mex_destroy(&c1_u);
  c1_update_debugger_state_c1_Hunt_crossley_Ident(chartInstance);
  sf_mex_destroy(&c1_st);
}

static void finalize_c1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

static void sf_c1_Hunt_crossley_Ident(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance)
{
  real_T c1_hoistedGlobal;
  real_T c1_b_hoistedGlobal;
  real_T c1_c_hoistedGlobal;
  real_T c1_d_hoistedGlobal;
  real_T c1_e_hoistedGlobal;
  real_T c1_theta;
  real_T c1_dtheta;
  real_T c1_p;
  real_T c1_uc;
  real_T c1_ud;
  uint32_T c1_debug_family_var_map[19];
  real_T c1_t1;
  real_T c1_t2;
  real_T c1_t3;
  real_T c1_t4;
  real_T c1_t5;
  real_T c1_t6;
  real_T c1_t7;
  real_T c1_patm;
  real_T c1_ps;
  real_T c1_nargin = 5.0;
  real_T c1_nargout = 3.0;
  real_T c1_ddtheta;
  real_T c1_dp;
  real_T c1_f;
  real_T c1_b;
  real_T c1_y;
  real_T c1_b_b;
  real_T c1_b_y;
  real_T c1_c_b;
  real_T c1_c_y;
  real_T c1_x;
  real_T c1_b_x;
  real_T c1_a;
  real_T c1_d_b;
  real_T c1_d_y;
  real_T c1_c_x;
  real_T c1_d_x;
  real_T c1_e_y;
  real_T c1_e_x;
  real_T c1_f_x;
  real_T c1_b_a;
  real_T c1_e_b;
  real_T c1_f_b;
  real_T c1_f_y;
  real_T c1_A;
  real_T c1_B;
  real_T c1_g_x;
  real_T c1_g_y;
  real_T c1_h_x;
  real_T c1_h_y;
  real_T c1_i_x;
  real_T c1_j_x;
  real_T c1_c_a;
  real_T c1_g_b;
  real_T c1_i_y;
  real_T c1_k_x;
  real_T c1_l_x;
  real_T c1_j_y;
  real_T c1_m_x;
  real_T c1_n_x;
  real_T c1_d_a;
  real_T c1_h_b;
  real_T c1_i_b;
  real_T c1_k_y;
  real_T c1_b_A;
  real_T c1_b_B;
  real_T c1_o_x;
  real_T c1_l_y;
  real_T c1_p_x;
  real_T c1_m_y;
  real_T *c1_b_f;
  real_T *c1_b_dp;
  real_T *c1_b_ddtheta;
  real_T *c1_b_ud;
  real_T *c1_b_uc;
  real_T *c1_b_p;
  real_T *c1_b_dtheta;
  real_T *c1_b_theta;
  c1_b_f = (real_T *)ssGetOutputPortSignal(chartInstance->S, 3);
  c1_b_dp = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
  c1_b_ud = (real_T *)ssGetInputPortSignal(chartInstance->S, 4);
  c1_b_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c1_b_uc = (real_T *)ssGetInputPortSignal(chartInstance->S, 3);
  c1_b_p = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c1_b_dtheta = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c1_b_theta = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 0U, chartInstance->c1_sfEvent);
  _SFD_DATA_RANGE_CHECK(*c1_b_theta, 0U);
  _SFD_DATA_RANGE_CHECK(*c1_b_dtheta, 1U);
  _SFD_DATA_RANGE_CHECK(*c1_b_p, 2U);
  _SFD_DATA_RANGE_CHECK(*c1_b_uc, 3U);
  _SFD_DATA_RANGE_CHECK(*c1_b_ddtheta, 4U);
  _SFD_DATA_RANGE_CHECK(*c1_b_ud, 5U);
  _SFD_DATA_RANGE_CHECK(*c1_b_dp, 6U);
  _SFD_DATA_RANGE_CHECK(*c1_b_f, 7U);
  chartInstance->c1_sfEvent = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 0U, chartInstance->c1_sfEvent);
  c1_hoistedGlobal = *c1_b_theta;
  c1_b_hoistedGlobal = *c1_b_dtheta;
  c1_c_hoistedGlobal = *c1_b_p;
  c1_d_hoistedGlobal = *c1_b_uc;
  c1_e_hoistedGlobal = *c1_b_ud;
  c1_theta = c1_hoistedGlobal;
  c1_dtheta = c1_b_hoistedGlobal;
  c1_p = c1_c_hoistedGlobal;
  c1_uc = c1_d_hoistedGlobal;
  c1_ud = c1_e_hoistedGlobal;
  sf_debug_symbol_scope_push_eml(0U, 19U, 19U, c1_debug_family_names,
    c1_debug_family_var_map);
  sf_debug_symbol_scope_add_eml(&c1_t1, 0U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c1_t2, 1U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c1_t3, 2U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c1_t4, 3U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c1_t5, 4U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c1_t6, 5U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c1_t7, 6U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c1_patm, 7U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c1_ps, 8U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c1_nargin, 9U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c1_nargout, 10U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml(&c1_theta, 11U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c1_dtheta, 12U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c1_p, 13U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c1_uc, 14U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml(&c1_ud, 15U, c1_sf_marshallOut);
  sf_debug_symbol_scope_add_eml_importable(&c1_ddtheta, 16U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c1_dp, 17U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  sf_debug_symbol_scope_add_eml_importable(&c1_f, 18U, c1_sf_marshallOut,
    c1_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 4);
  c1_t1 = 1408.5;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 5);
  c1_t2 = 132.28;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 6);
  c1_t3 = 3319.4;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 7);
  c1_t4 = -0.000214;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 8);
  c1_t5 = 6.12E-9;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 9);
  c1_t6 = -9.76E-5;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 10);
  c1_t7 = -1.9E-9;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 11);
  c1_patm = 101325.0;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 12);
  c1_ps = 800000.0;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 15);
  c1_b = c1_p - c1_patm;
  c1_y = 1408.5 * c1_b;
  c1_b_b = c1_dtheta;
  c1_b_y = 132.28 * c1_b_b;
  c1_c_b = c1_theta;
  c1_c_y = 3319.4 * c1_c_b;
  c1_ddtheta = (c1_y - c1_b_y) - c1_c_y;
  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 16);
  if (CV_EML_IF(0, 1, 0, c1_uc > 0.0)) {
    _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 17);
    c1_x = c1_ps - c1_p;
    c1_b_x = c1_x;
    c1_b_x = muDoubleScalarSign(c1_b_x);
    c1_a = c1_uc;
    c1_d_b = c1_b_x;
    c1_d_y = c1_a * c1_d_b;
    c1_c_x = c1_ps - c1_p;
    c1_d_x = c1_c_x;
    c1_e_y = muDoubleScalarAbs(c1_d_x);
    c1_e_x = c1_e_y;
    c1_f_x = c1_e_x;
    if (c1_f_x < 0.0) {
      c1_eml_error(chartInstance);
    }

    c1_f_x = muDoubleScalarSqrt(c1_f_x);
    c1_b_a = c1_d_y;
    c1_e_b = c1_f_x;
    c1_f = c1_b_a * c1_e_b;
    _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 18);
    c1_f_b = c1_p;
    c1_f_y = 6.12E-9 * c1_f_b;
    c1_A = c1_t4 + c1_f_y;
    c1_B = c1_f;
    c1_g_x = c1_B;
    c1_g_y = c1_A;
    c1_h_x = c1_g_x;
    c1_h_y = c1_g_y;
    c1_dp = c1_h_x / c1_h_y;
  } else {
    _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 20);
    c1_i_x = c1_p - c1_patm;
    c1_j_x = c1_i_x;
    c1_j_x = muDoubleScalarSign(c1_j_x);
    c1_c_a = c1_ud;
    c1_g_b = c1_j_x;
    c1_i_y = c1_c_a * c1_g_b;
    c1_k_x = c1_p - c1_patm;
    c1_l_x = c1_k_x;
    c1_j_y = muDoubleScalarAbs(c1_l_x);
    c1_m_x = c1_j_y;
    c1_n_x = c1_m_x;
    if (c1_n_x < 0.0) {
      c1_eml_error(chartInstance);
    }

    c1_n_x = muDoubleScalarSqrt(c1_n_x);
    c1_d_a = c1_i_y;
    c1_h_b = c1_n_x;
    c1_f = c1_d_a * c1_h_b;
    _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, 21);
    c1_i_b = c1_p;
    c1_k_y = -1.9E-9 * c1_i_b;
    c1_b_A = c1_t6 + c1_k_y;
    c1_b_B = c1_f;
    c1_o_x = c1_b_B;
    c1_l_y = c1_b_A;
    c1_p_x = c1_o_x;
    c1_m_y = c1_l_y;
    c1_dp = c1_p_x / c1_m_y;
  }

  _SFD_EML_CALL(0U, chartInstance->c1_sfEvent, -21);
  sf_debug_symbol_scope_pop();
  *c1_b_ddtheta = c1_ddtheta;
  *c1_b_dp = c1_dp;
  *c1_b_f = c1_f;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 0U, chartInstance->c1_sfEvent);
  sf_debug_check_for_state_inconsistency(_Hunt_crossley_IdentMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
}

static void initSimStructsc1_Hunt_crossley_Ident
  (SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
}

static void init_script_number_translation(uint32_T c1_machineNumber, uint32_T
  c1_chartNumber)
{
}

static const mxArray *c1_sf_marshallOut(void *chartInstanceVoid, void *c1_inData)
{
  const mxArray *c1_mxArrayOutData = NULL;
  real_T c1_u;
  const mxArray *c1_y = NULL;
  SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc1_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c1_mxArrayOutData = NULL;
  c1_u = *(real_T *)c1_inData;
  c1_y = NULL;
  sf_mex_assign(&c1_y, sf_mex_create("y", &c1_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c1_mxArrayOutData, c1_y, FALSE);
  return c1_mxArrayOutData;
}

static real_T c1_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_f, const char_T *c1_identifier)
{
  real_T c1_y;
  emlrtMsgIdentifier c1_thisId;
  c1_thisId.fIdentifier = c1_identifier;
  c1_thisId.fParent = NULL;
  c1_y = c1_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c1_f), &c1_thisId);
  sf_mex_destroy(&c1_f);
  return c1_y;
}

static real_T c1_b_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_u, const emlrtMsgIdentifier *c1_parentId)
{
  real_T c1_y;
  real_T c1_d0;
  sf_mex_import(c1_parentId, sf_mex_dup(c1_u), &c1_d0, 1, 0, 0U, 0, 0U, 0);
  c1_y = c1_d0;
  sf_mex_destroy(&c1_u);
  return c1_y;
}

static void c1_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c1_mxArrayInData, const char_T *c1_varName, void *c1_outData)
{
  const mxArray *c1_f;
  const char_T *c1_identifier;
  emlrtMsgIdentifier c1_thisId;
  real_T c1_y;
  SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc1_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c1_f = sf_mex_dup(c1_mxArrayInData);
  c1_identifier = c1_varName;
  c1_thisId.fIdentifier = c1_identifier;
  c1_thisId.fParent = NULL;
  c1_y = c1_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c1_f), &c1_thisId);
  sf_mex_destroy(&c1_f);
  *(real_T *)c1_outData = c1_y;
  sf_mex_destroy(&c1_mxArrayInData);
}

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

  sf_mex_assign(&c1_nameCaptureInfo, c1_m0, FALSE);
  sf_mex_emlrtNameCapturePostProcessR2012a(&c1_nameCaptureInfo);
  return c1_nameCaptureInfo;
}

static void c1_eml_error(SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance)
{
  int32_T c1_i1;
  static char_T c1_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 c1_u[30];
  const mxArray *c1_y = NULL;
  for (c1_i1 = 0; c1_i1 < 30; c1_i1++) {
    c1_u[c1_i1] = c1_varargin_1[c1_i1];
  }

  c1_y = NULL;
  sf_mex_assign(&c1_y, sf_mex_create("y", c1_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,
    c1_y));
}

static const mxArray *c1_b_sf_marshallOut(void *chartInstanceVoid, void
  *c1_inData)
{
  const mxArray *c1_mxArrayOutData = NULL;
  int32_T c1_u;
  const mxArray *c1_y = NULL;
  SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc1_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c1_mxArrayOutData = NULL;
  c1_u = *(int32_T *)c1_inData;
  c1_y = NULL;
  sf_mex_assign(&c1_y, sf_mex_create("y", &c1_u, 6, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c1_mxArrayOutData, c1_y, FALSE);
  return c1_mxArrayOutData;
}

static int32_T c1_c_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_u, const emlrtMsgIdentifier *c1_parentId)
{
  int32_T c1_y;
  int32_T c1_i2;
  sf_mex_import(c1_parentId, sf_mex_dup(c1_u), &c1_i2, 1, 6, 0U, 0, 0U, 0);
  c1_y = c1_i2;
  sf_mex_destroy(&c1_u);
  return c1_y;
}

static void c1_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c1_mxArrayInData, const char_T *c1_varName, void *c1_outData)
{
  const mxArray *c1_b_sfEvent;
  const char_T *c1_identifier;
  emlrtMsgIdentifier c1_thisId;
  int32_T c1_y;
  SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc1_Hunt_crossley_IdentInstanceStruct *)chartInstanceVoid;
  c1_b_sfEvent = sf_mex_dup(c1_mxArrayInData);
  c1_identifier = c1_varName;
  c1_thisId.fIdentifier = c1_identifier;
  c1_thisId.fParent = NULL;
  c1_y = c1_c_emlrt_marshallIn(chartInstance, sf_mex_dup(c1_b_sfEvent),
    &c1_thisId);
  sf_mex_destroy(&c1_b_sfEvent);
  *(int32_T *)c1_outData = c1_y;
  sf_mex_destroy(&c1_mxArrayInData);
}

static uint8_T c1_d_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_b_is_active_c1_Hunt_crossley_Ident, const
  char_T *c1_identifier)
{
  uint8_T c1_y;
  emlrtMsgIdentifier c1_thisId;
  c1_thisId.fIdentifier = c1_identifier;
  c1_thisId.fParent = NULL;
  c1_y = c1_e_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c1_b_is_active_c1_Hunt_crossley_Ident), &c1_thisId);
  sf_mex_destroy(&c1_b_is_active_c1_Hunt_crossley_Ident);
  return c1_y;
}

static uint8_T c1_e_emlrt_marshallIn(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance, const mxArray *c1_u, const emlrtMsgIdentifier *c1_parentId)
{
  uint8_T c1_y;
  uint8_T c1_u0;
  sf_mex_import(c1_parentId, sf_mex_dup(c1_u), &c1_u0, 1, 3, 0U, 0, 0U, 0);
  c1_y = c1_u0;
  sf_mex_destroy(&c1_u);
  return c1_y;
}

static void init_dsm_address_info(SFc1_Hunt_crossley_IdentInstanceStruct
  *chartInstance)
{
}

/* SFunction Glue Code */
void sf_c1_Hunt_crossley_Ident_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(3025498722U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(3774023157U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(3921688179U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(1236815290U);
}

mxArray *sf_c1_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("91yIviWir9tYzN9YsdpGYE");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

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

    mxArray *mxData = mxCreateStructMatrix(1,5,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));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

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

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

    mxArray *mxData = mxCreateStructMatrix(1,3,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));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

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

  return(mxAutoinheritanceInfo);
}

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

  mxArray *mxInfo = mxCreateStructMatrix(1, 1, 2, infoFields);
  const char *infoEncStr[] = {
    "100 S1x4'type','srcId','name','auxInfo'{{M[1],M[5],T\"ddtheta\",},{M[1],M[11],T\"dp\",},{M[1],M[12],T\"f\",},{M[8],M[0],T\"is_active_c1_Hunt_crossley_Ident\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 4, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c1_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)) {
    SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance;
    chartInstance = (SFc1_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_,
           1,
           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,1,1,0,"theta");
          _SFD_SET_DATA_PROPS(1,1,1,0,"dtheta");
          _SFD_SET_DATA_PROPS(2,1,1,0,"p");
          _SFD_SET_DATA_PROPS(3,1,1,0,"uc");
          _SFD_SET_DATA_PROPS(4,2,0,1,"ddtheta");
          _SFD_SET_DATA_PROPS(5,1,1,0,"ud");
          _SFD_SET_DATA_PROPS(6,2,0,1,"dp");
          _SFD_SET_DATA_PROPS(7,2,0,1,"f");
          _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,378);
        _SFD_CV_INIT_EML_IF(0,1,0,237,244,305,377);
        _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)c1_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(2,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(3,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(4,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)c1_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(5,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(6,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)c1_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(7,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c1_sf_marshallOut,(MexInFcnForType)c1_sf_marshallIn);

        {
          real_T *c1_theta;
          real_T *c1_dtheta;
          real_T *c1_p;
          real_T *c1_uc;
          real_T *c1_ddtheta;
          real_T *c1_ud;
          real_T *c1_dp;
          real_T *c1_f;
          c1_f = (real_T *)ssGetOutputPortSignal(chartInstance->S, 3);
          c1_dp = (real_T *)ssGetOutputPortSignal(chartInstance->S, 2);
          c1_ud = (real_T *)ssGetInputPortSignal(chartInstance->S, 4);
          c1_ddtheta = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
          c1_uc = (real_T *)ssGetInputPortSignal(chartInstance->S, 3);
          c1_p = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
          c1_dtheta = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
          c1_theta = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
          _SFD_SET_DATA_VALUE_PTR(0U, c1_theta);
          _SFD_SET_DATA_VALUE_PTR(1U, c1_dtheta);
          _SFD_SET_DATA_VALUE_PTR(2U, c1_p);
          _SFD_SET_DATA_VALUE_PTR(3U, c1_uc);
          _SFD_SET_DATA_VALUE_PTR(4U, c1_ddtheta);
          _SFD_SET_DATA_VALUE_PTR(5U, c1_ud);
          _SFD_SET_DATA_VALUE_PTR(6U, c1_dp);
          _SFD_SET_DATA_VALUE_PTR(7U, c1_f);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration
        (_Hunt_crossley_IdentMachineNumber_,chartInstance->chartNumber,
         chartInstance->instanceNumber);
    }
  }
}

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

static void sf_opaque_initialize_c1_Hunt_crossley_Ident(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar)->S,0);
  initialize_params_c1_Hunt_crossley_Ident
    ((SFc1_Hunt_crossley_IdentInstanceStruct*) chartInstanceVar);
  initialize_c1_Hunt_crossley_Ident((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_enable_c1_Hunt_crossley_Ident(void *chartInstanceVar)
{
  enable_c1_Hunt_crossley_Ident((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_disable_c1_Hunt_crossley_Ident(void *chartInstanceVar)
{
  disable_c1_Hunt_crossley_Ident((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_gateway_c1_Hunt_crossley_Ident(void *chartInstanceVar)
{
  sf_c1_Hunt_crossley_Ident((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

extern const mxArray* sf_internal_get_sim_state_c1_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_c1_Hunt_crossley_Ident
    ((SFc1_Hunt_crossley_IdentInstanceStruct*)chartInfo->chartInstance);/* raw sim ctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c1_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_c1_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_c1_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_c1_Hunt_crossley_Ident((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInfo->chartInstance, mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static const mxArray* sf_opaque_get_sim_state_c1_Hunt_crossley_Ident(SimStruct*
  S)
{
  return sf_internal_get_sim_state_c1_Hunt_crossley_Ident(S);
}

static void sf_opaque_set_sim_state_c1_Hunt_crossley_Ident(SimStruct* S, const
  mxArray *st)
{
  sf_internal_set_sim_state_c1_Hunt_crossley_Ident(S, st);
}

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

    finalize_c1_Hunt_crossley_Ident((SFc1_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)
{
  initSimStructsc1_Hunt_crossley_Ident((SFc1_Hunt_crossley_IdentInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c1_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_c1_Hunt_crossley_Ident
      ((SFc1_Hunt_crossley_IdentInstanceStruct*)(((ChartInfoStruct *)
         ssGetUserData(S))->chartInstance));
  }
}

static void mdlSetWorkWidths_c1_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,
      1);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,sf_get_instance_specialization(),
                infoStruct,1,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,
      sf_get_instance_specialization(),infoStruct,1,
      "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);
      sf_mark_chart_expressionable_inputs(S,sf_get_instance_specialization(),
        infoStruct,1,5);
      sf_mark_chart_reusable_outputs(S,sf_get_instance_specialization(),
        infoStruct,1,3);
    }

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

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(1295249195U));
  ssSetChecksum1(S,(2121992805U));
  ssSetChecksum2(S,(3085635942U));
  ssSetChecksum3(S,(4224325162U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
  ssSupportsMultipleExecInstances(S,1);
}

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

static void mdlStart_c1_Hunt_crossley_Ident(SimStruct *S)
{
  SFc1_Hunt_crossley_IdentInstanceStruct *chartInstance;
  chartInstance = (SFc1_Hunt_crossley_IdentInstanceStruct *)malloc(sizeof
    (SFc1_Hunt_crossley_IdentInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc1_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_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.initializeChart =
    sf_opaque_initialize_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.terminateChart =
    sf_opaque_terminate_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.disableChart =
    sf_opaque_disable_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.getSimState =
    sf_opaque_get_sim_state_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.setSimState =
    sf_opaque_set_sim_state_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.getSimStateInfo =
    sf_get_sim_state_info_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.mdlStart = mdlStart_c1_Hunt_crossley_Ident;
  chartInstance->chartInfo.mdlSetWorkWidths =
    mdlSetWorkWidths_c1_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 c1_Hunt_crossley_Ident_method_dispatcher(SimStruct *S, int_T method, void
  *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c1_Hunt_crossley_Ident(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c1_Hunt_crossley_Ident(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c1_Hunt_crossley_Ident(S);
    break;

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