/* Include files */

#include <stddef.h>
#include "blas.h"
#include "untitled_sfun.h"
#include "c4_untitled.h"
#define CHARTINSTANCE_CHARTNUMBER      (chartInstance->chartNumber)
#define CHARTINSTANCE_INSTANCENUMBER   (chartInstance->instanceNumber)
#include "untitled_sfun_debug_macros.h"
#define _SF_MEX_LISTEN_FOR_CTRL_C(S)   sf_mex_listen_for_ctrl_c(sfGlobalDebugInstanceStruct,S);

/* Type Definitions */

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

/* Variable Declarations */

/* Variable Definitions */
static real_T _sfTime_;
static const char * c4_debug_family_names[10] = { "wp", "nargin", "nargout",
  "num", "lat", "lon", "alt", "tray", "check", "wp_track" };

/* Function Declarations */
static void initialize_c4_untitled(SFc4_untitledInstanceStruct *chartInstance);
static void initialize_params_c4_untitled(SFc4_untitledInstanceStruct
  *chartInstance);
static void enable_c4_untitled(SFc4_untitledInstanceStruct *chartInstance);
static void disable_c4_untitled(SFc4_untitledInstanceStruct *chartInstance);
static void c4_update_debugger_state_c4_untitled(SFc4_untitledInstanceStruct
  *chartInstance);
static const mxArray *get_sim_state_c4_untitled(SFc4_untitledInstanceStruct
  *chartInstance);
static void set_sim_state_c4_untitled(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_st);
static void finalize_c4_untitled(SFc4_untitledInstanceStruct *chartInstance);
static void sf_gateway_c4_untitled(SFc4_untitledInstanceStruct *chartInstance);
static void initSimStructsc4_untitled(SFc4_untitledInstanceStruct *chartInstance);
static void init_script_number_translation(uint32_T c4_machineNumber, uint32_T
  c4_chartNumber, uint32_T c4_instanceNumber);
static const mxArray *c4_sf_marshallOut(void *chartInstanceVoid, void *c4_inData);
static void c4_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId,
  c4_sMqmkO2ZoTueUSYwmuJBMYG *c4_y);
static void c4_b_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId, real_T c4_y[5]);
static void c4_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData);
static const mxArray *c4_b_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData);
static const mxArray *c4_c_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData);
static real_T c4_c_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_nargout, const char_T *c4_identifier);
static real_T c4_d_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId);
static void c4_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData);
static const mxArray *c4_d_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData);
static c4_spFfHEz6lgqav8fuHxhcakH c4_e_emlrt_marshallIn
  (SFc4_untitledInstanceStruct *chartInstance, const mxArray *c4_u, const
   emlrtMsgIdentifier *c4_parentId);
static void c4_c_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData);
static const mxArray *c4_e_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData);
static int32_T c4_f_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId);
static void c4_d_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData);
static uint8_T c4_g_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_b_is_active_c4_untitled, const char_T *c4_identifier);
static uint8_T c4_h_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId);
static void init_dsm_address_info(SFc4_untitledInstanceStruct *chartInstance);

/* Function Definitions */
static void initialize_c4_untitled(SFc4_untitledInstanceStruct *chartInstance)
{
  chartInstance->c4_sfEvent = CALL_EVENT;
  _sfTime_ = sf_get_time(chartInstance->S);
  chartInstance->c4_is_active_c4_untitled = 0U;
}

static void initialize_params_c4_untitled(SFc4_untitledInstanceStruct
  *chartInstance)
{
  (void)chartInstance;
}

static void enable_c4_untitled(SFc4_untitledInstanceStruct *chartInstance)
{
  _sfTime_ = sf_get_time(chartInstance->S);
}

static void disable_c4_untitled(SFc4_untitledInstanceStruct *chartInstance)
{
  _sfTime_ = sf_get_time(chartInstance->S);
}

static void c4_update_debugger_state_c4_untitled(SFc4_untitledInstanceStruct
  *chartInstance)
{
  (void)chartInstance;
}

static const mxArray *get_sim_state_c4_untitled(SFc4_untitledInstanceStruct
  *chartInstance)
{
  const mxArray *c4_st;
  const mxArray *c4_y = NULL;
  real_T c4_hoistedGlobal;
  real_T c4_u;
  const mxArray *c4_b_y = NULL;
  uint8_T c4_b_hoistedGlobal;
  uint8_T c4_b_u;
  const mxArray *c4_c_y = NULL;
  real_T *c4_wp_track;
  c4_wp_track = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c4_st = NULL;
  c4_st = NULL;
  c4_y = NULL;
  sf_mex_assign(&c4_y, sf_mex_createcellmatrix(2, 1), false);
  c4_hoistedGlobal = *c4_wp_track;
  c4_u = c4_hoistedGlobal;
  c4_b_y = NULL;
  sf_mex_assign(&c4_b_y, sf_mex_create("y", &c4_u, 0, 0U, 0U, 0U, 0), false);
  sf_mex_setcell(c4_y, 0, c4_b_y);
  c4_b_hoistedGlobal = chartInstance->c4_is_active_c4_untitled;
  c4_b_u = c4_b_hoistedGlobal;
  c4_c_y = NULL;
  sf_mex_assign(&c4_c_y, sf_mex_create("y", &c4_b_u, 3, 0U, 0U, 0U, 0), false);
  sf_mex_setcell(c4_y, 1, c4_c_y);
  sf_mex_assign(&c4_st, c4_y, false);
  return c4_st;
}

static void set_sim_state_c4_untitled(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_st)
{
  const mxArray *c4_u;
  real_T *c4_wp_track;
  c4_wp_track = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c4_doneDoubleBufferReInit = true;
  c4_u = sf_mex_dup(c4_st);
  *c4_wp_track = c4_c_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell
    (c4_u, 0)), "wp_track");
  chartInstance->c4_is_active_c4_untitled = c4_g_emlrt_marshallIn(chartInstance,
    sf_mex_dup(sf_mex_getcell(c4_u, 1)), "is_active_c4_untitled");
  sf_mex_destroy(&c4_u);
  c4_update_debugger_state_c4_untitled(chartInstance);
  sf_mex_destroy(&c4_st);
}

static void finalize_c4_untitled(SFc4_untitledInstanceStruct *chartInstance)
{
  (void)chartInstance;
}

static void sf_gateway_c4_untitled(SFc4_untitledInstanceStruct *chartInstance)
{
  int32_T c4_i0;
  int32_T c4_i1;
  real_T c4_num[5];
  int32_T c4_i2;
  real_T c4_lat[5];
  int32_T c4_i3;
  real_T c4_lon[5];
  int32_T c4_i4;
  real_T c4_alt[5];
  int32_T c4_i5;
  real_T c4_tray[5];
  int32_T c4_i6;
  real_T c4_check[5];
  uint32_T c4_debug_family_var_map[10];
  c4_spFfHEz6lgqav8fuHxhcakH c4_wp;
  real_T c4_nargin = 6.0;
  real_T c4_nargout = 1.0;
  c4_sMqmkO2ZoTueUSYwmuJBMYG c4_wp_track;
  int32_T c4_i7;
  int32_T c4_i8;
  int32_T c4_i9;
  int32_T c4_i10;
  int32_T c4_i11;
  int32_T c4_i12;
  real_T c4_b_wp_track;
  int32_T c4_i13;
  int32_T c4_i14;
  int32_T c4_i15;
  int32_T c4_i16;
  int32_T c4_i17;
  real_T *c4_c_wp_track;
  real_T (*c4_b_check)[5];
  real_T (*c4_b_tray)[5];
  real_T (*c4_b_alt)[5];
  real_T (*c4_b_lon)[5];
  real_T (*c4_b_lat)[5];
  real_T (*c4_b_num)[5];
  c4_b_check = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 5);
  c4_b_tray = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 4);
  c4_b_alt = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 3);
  c4_b_lon = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 2);
  c4_b_lat = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 1);
  c4_c_wp_track = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c4_b_num = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 0);
  _SFD_SYMBOL_SCOPE_PUSH(0U, 0U);
  _sfTime_ = sf_get_time(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 1U, chartInstance->c4_sfEvent);
  for (c4_i0 = 0; c4_i0 < 5; c4_i0++) {
    _SFD_DATA_RANGE_CHECK((*c4_b_num)[c4_i0], 0U);
  }

  chartInstance->c4_sfEvent = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 1U, chartInstance->c4_sfEvent);
  for (c4_i1 = 0; c4_i1 < 5; c4_i1++) {
    c4_num[c4_i1] = (*c4_b_num)[c4_i1];
  }

  for (c4_i2 = 0; c4_i2 < 5; c4_i2++) {
    c4_lat[c4_i2] = (*c4_b_lat)[c4_i2];
  }

  for (c4_i3 = 0; c4_i3 < 5; c4_i3++) {
    c4_lon[c4_i3] = (*c4_b_lon)[c4_i3];
  }

  for (c4_i4 = 0; c4_i4 < 5; c4_i4++) {
    c4_alt[c4_i4] = (*c4_b_alt)[c4_i4];
  }

  for (c4_i5 = 0; c4_i5 < 5; c4_i5++) {
    c4_tray[c4_i5] = (*c4_b_tray)[c4_i5];
  }

  for (c4_i6 = 0; c4_i6 < 5; c4_i6++) {
    c4_check[c4_i6] = (*c4_b_check)[c4_i6];
  }

  _SFD_SYMBOL_SCOPE_PUSH_EML(0U, 10U, 10U, c4_debug_family_names,
    c4_debug_family_var_map);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c4_wp, 0U, c4_d_sf_marshallOut,
    c4_c_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c4_nargin, 1U, c4_c_sf_marshallOut,
    c4_b_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c4_nargout, 2U, c4_c_sf_marshallOut,
    c4_b_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(c4_num, 3U, c4_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(c4_lat, 4U, c4_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(c4_lon, 5U, c4_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(c4_alt, 6U, c4_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(c4_tray, 7U, c4_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(c4_check, 8U, c4_b_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c4_wp_track, 9U, c4_sf_marshallOut,
    c4_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, 3);
  for (c4_i7 = 0; c4_i7 < 5; c4_i7++) {
    c4_wp_track.n[c4_i7] = c4_num[c4_i7];
  }

  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, 4);
  for (c4_i8 = 0; c4_i8 < 5; c4_i8++) {
    c4_wp_track.lon[c4_i8] = c4_lon[c4_i8];
  }

  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, 5);
  for (c4_i9 = 0; c4_i9 < 5; c4_i9++) {
    c4_wp_track.lat[c4_i9] = c4_lat[c4_i9];
  }

  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, 6);
  for (c4_i10 = 0; c4_i10 < 5; c4_i10++) {
    c4_wp.alt[c4_i10] = c4_alt[c4_i10];
  }

  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, 7);
  for (c4_i11 = 0; c4_i11 < 5; c4_i11++) {
    c4_wp_track.trayectoria[c4_i11] = c4_tray[c4_i11];
  }

  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, 8);
  for (c4_i12 = 0; c4_i12 < 5; c4_i12++) {
    c4_wp_track.ok[c4_i12] = c4_check[c4_i12];
  }

  _SFD_EML_CALL(0U, chartInstance->c4_sfEvent, -8);
  _SFD_SYMBOL_SCOPE_POP();
  c4_b_wp_track = (real_T)c4_wp_track;
  *c4_c_wp_track = c4_b_wp_track;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 1U, chartInstance->c4_sfEvent);
  _SFD_SYMBOL_SCOPE_POP();
  _SFD_CHECK_FOR_STATE_INCONSISTENCY(_untitledMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
  _SFD_DATA_RANGE_CHECK(*c4_c_wp_track, 1U);
  for (c4_i13 = 0; c4_i13 < 5; c4_i13++) {
    _SFD_DATA_RANGE_CHECK((*c4_b_lat)[c4_i13], 2U);
  }

  for (c4_i14 = 0; c4_i14 < 5; c4_i14++) {
    _SFD_DATA_RANGE_CHECK((*c4_b_lon)[c4_i14], 3U);
  }

  for (c4_i15 = 0; c4_i15 < 5; c4_i15++) {
    _SFD_DATA_RANGE_CHECK((*c4_b_alt)[c4_i15], 4U);
  }

  for (c4_i16 = 0; c4_i16 < 5; c4_i16++) {
    _SFD_DATA_RANGE_CHECK((*c4_b_tray)[c4_i16], 5U);
  }

  for (c4_i17 = 0; c4_i17 < 5; c4_i17++) {
    _SFD_DATA_RANGE_CHECK((*c4_b_check)[c4_i17], 6U);
  }
}

static void initSimStructsc4_untitled(SFc4_untitledInstanceStruct *chartInstance)
{
  (void)chartInstance;
}

static void init_script_number_translation(uint32_T c4_machineNumber, uint32_T
  c4_chartNumber, uint32_T c4_instanceNumber)
{
  (void)c4_machineNumber;
  (void)c4_chartNumber;
  (void)c4_instanceNumber;
}

static const mxArray *c4_sf_marshallOut(void *chartInstanceVoid, void *c4_inData)
{
  const mxArray *c4_mxArrayOutData = NULL;
  c4_sMqmkO2ZoTueUSYwmuJBMYG c4_u;
  const mxArray *c4_y = NULL;
  int32_T c4_i18;
  real_T c4_b_u[5];
  const mxArray *c4_b_y = NULL;
  int32_T c4_i19;
  real_T c4_c_u[5];
  const mxArray *c4_c_y = NULL;
  int32_T c4_i20;
  real_T c4_d_u[5];
  const mxArray *c4_d_y = NULL;
  int32_T c4_i21;
  real_T c4_e_u[5];
  const mxArray *c4_e_y = NULL;
  int32_T c4_i22;
  real_T c4_f_u[5];
  const mxArray *c4_f_y = NULL;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_mxArrayOutData = NULL;
  c4_u = *(c4_sMqmkO2ZoTueUSYwmuJBMYG *)c4_inData;
  c4_y = NULL;
  sf_mex_assign(&c4_y, sf_mex_createstruct("structure", 2, 1, 1), false);
  for (c4_i18 = 0; c4_i18 < 5; c4_i18++) {
    c4_b_u[c4_i18] = c4_u.n[c4_i18];
  }

  c4_b_y = NULL;
  sf_mex_assign(&c4_b_y, sf_mex_create("y", c4_b_u, 0, 0U, 1U, 0U, 2, 1, 5),
                false);
  sf_mex_addfield(c4_y, c4_b_y, "n", "n", 0);
  for (c4_i19 = 0; c4_i19 < 5; c4_i19++) {
    c4_c_u[c4_i19] = c4_u.lon[c4_i19];
  }

  c4_c_y = NULL;
  sf_mex_assign(&c4_c_y, sf_mex_create("y", c4_c_u, 0, 0U, 1U, 0U, 2, 1, 5),
                false);
  sf_mex_addfield(c4_y, c4_c_y, "lon", "lon", 0);
  for (c4_i20 = 0; c4_i20 < 5; c4_i20++) {
    c4_d_u[c4_i20] = c4_u.lat[c4_i20];
  }

  c4_d_y = NULL;
  sf_mex_assign(&c4_d_y, sf_mex_create("y", c4_d_u, 0, 0U, 1U, 0U, 2, 1, 5),
                false);
  sf_mex_addfield(c4_y, c4_d_y, "lat", "lat", 0);
  for (c4_i21 = 0; c4_i21 < 5; c4_i21++) {
    c4_e_u[c4_i21] = c4_u.trayectoria[c4_i21];
  }

  c4_e_y = NULL;
  sf_mex_assign(&c4_e_y, sf_mex_create("y", c4_e_u, 0, 0U, 1U, 0U, 2, 1, 5),
                false);
  sf_mex_addfield(c4_y, c4_e_y, "trayectoria", "trayectoria", 0);
  for (c4_i22 = 0; c4_i22 < 5; c4_i22++) {
    c4_f_u[c4_i22] = c4_u.ok[c4_i22];
  }

  c4_f_y = NULL;
  sf_mex_assign(&c4_f_y, sf_mex_create("y", c4_f_u, 0, 0U, 1U, 0U, 2, 1, 5),
                false);
  sf_mex_addfield(c4_y, c4_f_y, "ok", "ok", 0);
  sf_mex_assign(&c4_mxArrayOutData, c4_y, false);
  return c4_mxArrayOutData;
}

static void c4_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId,
  c4_sMqmkO2ZoTueUSYwmuJBMYG *c4_y)
{
  emlrtMsgIdentifier c4_thisId;
  static const char * c4_fieldNames[5] = { "n", "lon", "lat", "trayectoria",
    "ok" };

  c4_thisId.fParent = c4_parentId;
  sf_mex_check_struct(c4_parentId, c4_u, 5, c4_fieldNames, 0U, NULL);
  c4_thisId.fIdentifier = "n";
  c4_b_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getfield(c4_u, "n", "n",
    0)), &c4_thisId, c4_y->n);
  c4_thisId.fIdentifier = "lon";
  c4_b_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getfield(c4_u, "lon",
    "lon", 0)), &c4_thisId, c4_y->lon);
  c4_thisId.fIdentifier = "lat";
  c4_b_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getfield(c4_u, "lat",
    "lat", 0)), &c4_thisId, c4_y->lat);
  c4_thisId.fIdentifier = "trayectoria";
  c4_b_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getfield(c4_u,
    "trayectoria", "trayectoria", 0)), &c4_thisId, c4_y->trayectoria);
  c4_thisId.fIdentifier = "ok";
  c4_b_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getfield(c4_u, "ok",
    "ok", 0)), &c4_thisId, c4_y->ok);
  sf_mex_destroy(&c4_u);
}

static void c4_b_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId, real_T c4_y[5])
{
  real_T c4_dv0[5];
  int32_T c4_i23;
  (void)chartInstance;
  sf_mex_import(c4_parentId, sf_mex_dup(c4_u), c4_dv0, 1, 0, 0U, 1, 0U, 2, 1, 5);
  for (c4_i23 = 0; c4_i23 < 5; c4_i23++) {
    c4_y[c4_i23] = c4_dv0[c4_i23];
  }

  sf_mex_destroy(&c4_u);
}

static void c4_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData)
{
  const mxArray *c4_wp_track;
  const char_T *c4_identifier;
  emlrtMsgIdentifier c4_thisId;
  c4_sMqmkO2ZoTueUSYwmuJBMYG c4_y;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_wp_track = sf_mex_dup(c4_mxArrayInData);
  c4_identifier = c4_varName;
  c4_thisId.fIdentifier = c4_identifier;
  c4_thisId.fParent = NULL;
  c4_emlrt_marshallIn(chartInstance, sf_mex_dup(c4_wp_track), &c4_thisId, &c4_y);
  sf_mex_destroy(&c4_wp_track);
  *(c4_sMqmkO2ZoTueUSYwmuJBMYG *)c4_outData = c4_y;
  sf_mex_destroy(&c4_mxArrayInData);
}

static const mxArray *c4_b_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData)
{
  const mxArray *c4_mxArrayOutData = NULL;
  int32_T c4_i24;
  real_T c4_b_inData[5];
  int32_T c4_i25;
  real_T c4_u[5];
  const mxArray *c4_y = NULL;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_mxArrayOutData = NULL;
  for (c4_i24 = 0; c4_i24 < 5; c4_i24++) {
    c4_b_inData[c4_i24] = (*(real_T (*)[5])c4_inData)[c4_i24];
  }

  for (c4_i25 = 0; c4_i25 < 5; c4_i25++) {
    c4_u[c4_i25] = c4_b_inData[c4_i25];
  }

  c4_y = NULL;
  sf_mex_assign(&c4_y, sf_mex_create("y", c4_u, 0, 0U, 1U, 0U, 2, 1, 5), false);
  sf_mex_assign(&c4_mxArrayOutData, c4_y, false);
  return c4_mxArrayOutData;
}

static const mxArray *c4_c_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData)
{
  const mxArray *c4_mxArrayOutData = NULL;
  real_T c4_u;
  const mxArray *c4_y = NULL;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_mxArrayOutData = NULL;
  c4_u = *(real_T *)c4_inData;
  c4_y = NULL;
  sf_mex_assign(&c4_y, sf_mex_create("y", &c4_u, 0, 0U, 0U, 0U, 0), false);
  sf_mex_assign(&c4_mxArrayOutData, c4_y, false);
  return c4_mxArrayOutData;
}

static real_T c4_c_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_nargout, const char_T *c4_identifier)
{
  real_T c4_y;
  emlrtMsgIdentifier c4_thisId;
  c4_thisId.fIdentifier = c4_identifier;
  c4_thisId.fParent = NULL;
  c4_y = c4_d_emlrt_marshallIn(chartInstance, sf_mex_dup(c4_nargout), &c4_thisId);
  sf_mex_destroy(&c4_nargout);
  return c4_y;
}

static real_T c4_d_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId)
{
  real_T c4_y;
  real_T c4_d0;
  (void)chartInstance;
  sf_mex_import(c4_parentId, sf_mex_dup(c4_u), &c4_d0, 1, 0, 0U, 0, 0U, 0);
  c4_y = c4_d0;
  sf_mex_destroy(&c4_u);
  return c4_y;
}

static void c4_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData)
{
  const mxArray *c4_nargout;
  const char_T *c4_identifier;
  emlrtMsgIdentifier c4_thisId;
  real_T c4_y;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_nargout = sf_mex_dup(c4_mxArrayInData);
  c4_identifier = c4_varName;
  c4_thisId.fIdentifier = c4_identifier;
  c4_thisId.fParent = NULL;
  c4_y = c4_d_emlrt_marshallIn(chartInstance, sf_mex_dup(c4_nargout), &c4_thisId);
  sf_mex_destroy(&c4_nargout);
  *(real_T *)c4_outData = c4_y;
  sf_mex_destroy(&c4_mxArrayInData);
}

static const mxArray *c4_d_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData)
{
  const mxArray *c4_mxArrayOutData = NULL;
  c4_spFfHEz6lgqav8fuHxhcakH c4_u;
  const mxArray *c4_y = NULL;
  int32_T c4_i26;
  real_T c4_b_u[5];
  const mxArray *c4_b_y = NULL;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_mxArrayOutData = NULL;
  c4_u = *(c4_spFfHEz6lgqav8fuHxhcakH *)c4_inData;
  c4_y = NULL;
  sf_mex_assign(&c4_y, sf_mex_createstruct("structure", 2, 1, 1), false);
  for (c4_i26 = 0; c4_i26 < 5; c4_i26++) {
    c4_b_u[c4_i26] = c4_u.alt[c4_i26];
  }

  c4_b_y = NULL;
  sf_mex_assign(&c4_b_y, sf_mex_create("y", c4_b_u, 0, 0U, 1U, 0U, 2, 1, 5),
                false);
  sf_mex_addfield(c4_y, c4_b_y, "alt", "alt", 0);
  sf_mex_assign(&c4_mxArrayOutData, c4_y, false);
  return c4_mxArrayOutData;
}

static c4_spFfHEz6lgqav8fuHxhcakH c4_e_emlrt_marshallIn
  (SFc4_untitledInstanceStruct *chartInstance, const mxArray *c4_u, const
   emlrtMsgIdentifier *c4_parentId)
{
  c4_spFfHEz6lgqav8fuHxhcakH c4_y;
  emlrtMsgIdentifier c4_thisId;
  static const char * c4_fieldNames[1] = { "alt" };

  c4_thisId.fParent = c4_parentId;
  sf_mex_check_struct(c4_parentId, c4_u, 1, c4_fieldNames, 0U, NULL);
  c4_thisId.fIdentifier = "alt";
  c4_b_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getfield(c4_u, "alt",
    "alt", 0)), &c4_thisId, c4_y.alt);
  sf_mex_destroy(&c4_u);
  return c4_y;
}

static void c4_c_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData)
{
  const mxArray *c4_wp;
  const char_T *c4_identifier;
  emlrtMsgIdentifier c4_thisId;
  c4_spFfHEz6lgqav8fuHxhcakH c4_y;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_wp = sf_mex_dup(c4_mxArrayInData);
  c4_identifier = c4_varName;
  c4_thisId.fIdentifier = c4_identifier;
  c4_thisId.fParent = NULL;
  c4_y = c4_e_emlrt_marshallIn(chartInstance, sf_mex_dup(c4_wp), &c4_thisId);
  sf_mex_destroy(&c4_wp);
  *(c4_spFfHEz6lgqav8fuHxhcakH *)c4_outData = c4_y;
  sf_mex_destroy(&c4_mxArrayInData);
}

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

static const mxArray *c4_e_sf_marshallOut(void *chartInstanceVoid, void
  *c4_inData)
{
  const mxArray *c4_mxArrayOutData = NULL;
  int32_T c4_u;
  const mxArray *c4_y = NULL;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_mxArrayOutData = NULL;
  c4_u = *(int32_T *)c4_inData;
  c4_y = NULL;
  sf_mex_assign(&c4_y, sf_mex_create("y", &c4_u, 6, 0U, 0U, 0U, 0), false);
  sf_mex_assign(&c4_mxArrayOutData, c4_y, false);
  return c4_mxArrayOutData;
}

static int32_T c4_f_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId)
{
  int32_T c4_y;
  int32_T c4_i27;
  (void)chartInstance;
  sf_mex_import(c4_parentId, sf_mex_dup(c4_u), &c4_i27, 1, 6, 0U, 0, 0U, 0);
  c4_y = c4_i27;
  sf_mex_destroy(&c4_u);
  return c4_y;
}

static void c4_d_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c4_mxArrayInData, const char_T *c4_varName, void *c4_outData)
{
  const mxArray *c4_b_sfEvent;
  const char_T *c4_identifier;
  emlrtMsgIdentifier c4_thisId;
  int32_T c4_y;
  SFc4_untitledInstanceStruct *chartInstance;
  chartInstance = (SFc4_untitledInstanceStruct *)chartInstanceVoid;
  c4_b_sfEvent = sf_mex_dup(c4_mxArrayInData);
  c4_identifier = c4_varName;
  c4_thisId.fIdentifier = c4_identifier;
  c4_thisId.fParent = NULL;
  c4_y = c4_f_emlrt_marshallIn(chartInstance, sf_mex_dup(c4_b_sfEvent),
    &c4_thisId);
  sf_mex_destroy(&c4_b_sfEvent);
  *(int32_T *)c4_outData = c4_y;
  sf_mex_destroy(&c4_mxArrayInData);
}

static uint8_T c4_g_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_b_is_active_c4_untitled, const char_T *c4_identifier)
{
  uint8_T c4_y;
  emlrtMsgIdentifier c4_thisId;
  c4_thisId.fIdentifier = c4_identifier;
  c4_thisId.fParent = NULL;
  c4_y = c4_h_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c4_b_is_active_c4_untitled), &c4_thisId);
  sf_mex_destroy(&c4_b_is_active_c4_untitled);
  return c4_y;
}

static uint8_T c4_h_emlrt_marshallIn(SFc4_untitledInstanceStruct *chartInstance,
  const mxArray *c4_u, const emlrtMsgIdentifier *c4_parentId)
{
  uint8_T c4_y;
  uint8_T c4_u0;
  (void)chartInstance;
  sf_mex_import(c4_parentId, sf_mex_dup(c4_u), &c4_u0, 1, 3, 0U, 0, 0U, 0);
  c4_y = c4_u0;
  sf_mex_destroy(&c4_u);
  return c4_y;
}

static void init_dsm_address_info(SFc4_untitledInstanceStruct *chartInstance)
{
  (void)chartInstance;
}

/* SFunction Glue Code */
#ifdef utFree
#undef utFree
#endif

#ifdef utMalloc
#undef utMalloc
#endif

#ifdef __cplusplus

extern "C" void *utMalloc(size_t size);
extern "C" void utFree(void*);

#else

extern void *utMalloc(size_t size);
extern void utFree(void*);

#endif

void sf_c4_untitled_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(1484354151U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(3413956384U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(2373681683U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(2055343637U);
}

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

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

  {
    mxArray *mxChecksum = mxCreateString("FnM2mRvt33X0hfWVf88QF");
    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)(5);
      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)(5);
      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)(5);
      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)(5);
      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)(5);
      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)(1);
      pr[1] = (double)(5);
      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,1,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));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

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

  return(mxAutoinheritanceInfo);
}

mxArray *sf_c4_untitled_third_party_uses_info(void)
{
  mxArray * mxcell3p = mxCreateCellMatrix(1,0);
  return(mxcell3p);
}

mxArray *sf_c4_untitled_updateBuildInfo_args_info(void)
{
  mxArray *mxBIArgs = mxCreateCellMatrix(1,0);
  return mxBIArgs;
}

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

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

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 2, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c4_untitled_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)) {
    SFc4_untitledInstanceStruct *chartInstance;
    ChartRunTimeInfo * crtInfo = (ChartRunTimeInfo *)(ssGetUserData(S));
    ChartInfoStruct * chartInfo = (ChartInfoStruct *)(crtInfo->instanceInfo);
    chartInstance = (SFc4_untitledInstanceStruct *) chartInfo->chartInstance;
    if (ssIsFirstInitCond(S) && fullDebuggerInitialization==1) {
      /* do this only if simulation is starting */
      {
        unsigned int chartAlreadyPresent;
        chartAlreadyPresent = sf_debug_initialize_chart
          (sfGlobalDebugInstanceStruct,
           _untitledMachineNumber_,
           4,
           1,
           1,
           0,
           7,
           0,
           0,
           0,
           0,
           0,
           &(chartInstance->chartNumber),
           &(chartInstance->instanceNumber),
           (void *)S);

        /* Each instance must initialize ist own list of scripts */
        init_script_number_translation(_untitledMachineNumber_,
          chartInstance->chartNumber,chartInstance->instanceNumber);
        if (chartAlreadyPresent==0) {
          /* this is the first instance */
          sf_debug_set_chart_disable_implicit_casting
            (sfGlobalDebugInstanceStruct,_untitledMachineNumber_,
             chartInstance->chartNumber,1);
          sf_debug_set_chart_event_thresholds(sfGlobalDebugInstanceStruct,
            _untitledMachineNumber_,
            chartInstance->chartNumber,
            0,
            0,
            0);
          _SFD_SET_DATA_PROPS(0,1,1,0,"num");
          _SFD_SET_DATA_PROPS(1,2,0,1,"wp_track");
          _SFD_SET_DATA_PROPS(2,1,1,0,"lat");
          _SFD_SET_DATA_PROPS(3,1,1,0,"lon");
          _SFD_SET_DATA_PROPS(4,1,1,0,"alt");
          _SFD_SET_DATA_PROPS(5,1,1,0,"tray");
          _SFD_SET_DATA_PROPS(6,1,1,0,"check");
          _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,0,0,0,0,0,0,0,0);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,170);

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

        _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c4_c_sf_marshallOut,(MexInFcnForType)c4_b_sf_marshallIn);

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

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

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

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

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

        {
          real_T *c4_wp_track;
          real_T (*c4_num)[5];
          real_T (*c4_lat)[5];
          real_T (*c4_lon)[5];
          real_T (*c4_alt)[5];
          real_T (*c4_tray)[5];
          real_T (*c4_check)[5];
          c4_check = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 5);
          c4_tray = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 4);
          c4_alt = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 3);
          c4_lon = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 2);
          c4_lat = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 1);
          c4_wp_track = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
          c4_num = (real_T (*)[5])ssGetInputPortSignal(chartInstance->S, 0);
          _SFD_SET_DATA_VALUE_PTR(0U, *c4_num);
          _SFD_SET_DATA_VALUE_PTR(1U, c4_wp_track);
          _SFD_SET_DATA_VALUE_PTR(2U, *c4_lat);
          _SFD_SET_DATA_VALUE_PTR(3U, *c4_lon);
          _SFD_SET_DATA_VALUE_PTR(4U, *c4_alt);
          _SFD_SET_DATA_VALUE_PTR(5U, *c4_tray);
          _SFD_SET_DATA_VALUE_PTR(6U, *c4_check);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration(sfGlobalDebugInstanceStruct,
        _untitledMachineNumber_,chartInstance->chartNumber,
        chartInstance->instanceNumber);
    }
  }
}

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

static void sf_opaque_initialize_c4_untitled(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc4_untitledInstanceStruct*) chartInstanceVar)
    ->S,0);
  initialize_params_c4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
  initialize_c4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_enable_c4_untitled(void *chartInstanceVar)
{
  enable_c4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_disable_c4_untitled(void *chartInstanceVar)
{
  disable_c4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
}

static void sf_opaque_gateway_c4_untitled(void *chartInstanceVar)
{
  sf_gateway_c4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
}

extern const mxArray* sf_internal_get_sim_state_c4_untitled(SimStruct* S)
{
  ChartRunTimeInfo * crtInfo = (ChartRunTimeInfo *)(ssGetUserData(S));
  ChartInfoStruct * chartInfo = (ChartInfoStruct *)(crtInfo->instanceInfo);
  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_c4_untitled((SFc4_untitledInstanceStruct*)
    chartInfo->chartInstance);         /* raw sim ctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c4_untitled();/* 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_c4_untitled(SimStruct* S, const mxArray
  *st)
{
  ChartRunTimeInfo * crtInfo = (ChartRunTimeInfo *)(ssGetUserData(S));
  ChartInfoStruct * chartInfo = (ChartInfoStruct *)(crtInfo->instanceInfo);
  mxArray *plhs[1] = { NULL };

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

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

static const mxArray* sf_opaque_get_sim_state_c4_untitled(SimStruct* S)
{
  return sf_internal_get_sim_state_c4_untitled(S);
}

static void sf_opaque_set_sim_state_c4_untitled(SimStruct* S, const mxArray *st)
{
  sf_internal_set_sim_state_c4_untitled(S, st);
}

static void sf_opaque_terminate_c4_untitled(void *chartInstanceVar)
{
  if (chartInstanceVar!=NULL) {
    SimStruct *S = ((SFc4_untitledInstanceStruct*) chartInstanceVar)->S;
    ChartRunTimeInfo * crtInfo = (ChartRunTimeInfo *)(ssGetUserData(S));
    if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
      sf_clear_rtw_identifier(S);
      unload_untitled_optimization_info();
    }

    finalize_c4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
    utFree((void *)chartInstanceVar);
    if (crtInfo != NULL) {
      utFree((void *)crtInfo);
    }

    ssSetUserData(S,NULL);
  }
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  initSimStructsc4_untitled((SFc4_untitledInstanceStruct*) chartInstanceVar);
}

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

  if (sf_machine_global_initializer_called()) {
    ChartRunTimeInfo * crtInfo = (ChartRunTimeInfo *)(ssGetUserData(S));
    ChartInfoStruct * chartInfo = (ChartInfoStruct *)(crtInfo->instanceInfo);
    initialize_params_c4_untitled((SFc4_untitledInstanceStruct*)
      (chartInfo->chartInstance));
  }
}

static void mdlSetWorkWidths_c4_untitled(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
    mxArray *infoStruct = load_untitled_optimization_info();
    int_T chartIsInlinable =
      (int_T)sf_is_chart_inlinable(sf_get_instance_specialization(),infoStruct,4);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(sf_get_instance_specialization(),
                infoStruct,4,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop
      (sf_get_instance_specialization(),infoStruct,4,
       "gatewayCannotBeInlinedMultipleTimes"));
    sf_update_buildInfo(sf_get_instance_specialization(),infoStruct,4);
    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,4,6);
      sf_mark_chart_reusable_outputs(S,sf_get_instance_specialization(),
        infoStruct,4,1);
    }

    {
      unsigned int outPortIdx;
      for (outPortIdx=1; outPortIdx<=1; ++outPortIdx) {
        ssSetOutputPortOptimizeInIR(S, outPortIdx, 1U);
      }
    }

    {
      unsigned int inPortIdx;
      for (inPortIdx=0; inPortIdx < 6; ++inPortIdx) {
        ssSetInputPortOptimizeInIR(S, inPortIdx, 1U);
      }
    }

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

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(147735145U));
  ssSetChecksum1(S,(935999717U));
  ssSetChecksum2(S,(4233175224U));
  ssSetChecksum3(S,(3733732766U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
  ssSupportsMultipleExecInstances(S,1);
}

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

static void mdlStart_c4_untitled(SimStruct *S)
{
  SFc4_untitledInstanceStruct *chartInstance;
  ChartRunTimeInfo * crtInfo = (ChartRunTimeInfo *)utMalloc(sizeof
    (ChartRunTimeInfo));
  chartInstance = (SFc4_untitledInstanceStruct *)utMalloc(sizeof
    (SFc4_untitledInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc4_untitledInstanceStruct));
  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_c4_untitled;
  chartInstance->chartInfo.initializeChart = sf_opaque_initialize_c4_untitled;
  chartInstance->chartInfo.terminateChart = sf_opaque_terminate_c4_untitled;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c4_untitled;
  chartInstance->chartInfo.disableChart = sf_opaque_disable_c4_untitled;
  chartInstance->chartInfo.getSimState = sf_opaque_get_sim_state_c4_untitled;
  chartInstance->chartInfo.setSimState = sf_opaque_set_sim_state_c4_untitled;
  chartInstance->chartInfo.getSimStateInfo = sf_get_sim_state_info_c4_untitled;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c4_untitled;
  chartInstance->chartInfo.mdlStart = mdlStart_c4_untitled;
  chartInstance->chartInfo.mdlSetWorkWidths = mdlSetWorkWidths_c4_untitled;
  chartInstance->chartInfo.extModeExec = NULL;
  chartInstance->chartInfo.restoreLastMajorStepConfiguration = NULL;
  chartInstance->chartInfo.restoreBeforeLastMajorStepConfiguration = NULL;
  chartInstance->chartInfo.storeCurrentConfiguration = NULL;
  chartInstance->chartInfo.debugInstance = sfGlobalDebugInstanceStruct;
  chartInstance->S = S;
  crtInfo->instanceInfo = (&(chartInstance->chartInfo));
  crtInfo->isJITEnabled = false;
  ssSetUserData(S,(void *)(crtInfo));  /* 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 c4_untitled_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c4_untitled(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c4_untitled(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c4_untitled(S);
    break;

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