/*
 * presnost.c
 *
 * Code generation for model "presnost".
 *
 * Model version              : 1.114
 * Simulink Coder version : 8.3 (R2012b) 20-Jul-2012
 * C source code generated on : Fri May 22 19:06:12 2015
 *
 * Target selection: rtwin.tlc
 * Note: GRT includes extra infrastructure and instrumentation for prototyping
 * Embedded hardware selection: Generic->32-bit x86 compatible
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */
#include "presnost.h"
#include "presnost_private.h"
#include "presnost_dt.h"

/* options for Real-Time Windows Target board 0 */
static double RTWinBoardOptions0[] = {
  9.0,
};

/* list of Real-Time Windows Target timers */
const int RTWinTimerCount = 1;
const double RTWinTimers[2] = {
  0.0001, 0.0,
};

/* list of Real-Time Windows Target boards */
const int RTWinBoardCount = 1;
RTWINBOARD RTWinBoards[1] = {
  { "Humusoft/MF624", 4294967295U, 1, RTWinBoardOptions0 },
};

/* Exported block states */
real_T rozdil;                         /* '<Root>/Data Store Memory' */
real_T final;                          /* '<Root>/Data Store Memory1' */

/* Block signals (auto storage) */
BlockIO_presnost presnost_B;

/* Continuous states */
ContinuousStates_presnost presnost_X;

/* Block states (auto storage) */
D_Work_presnost presnost_DWork;

/* Real-time model */
RT_MODEL_presnost presnost_M_;
RT_MODEL_presnost *const presnost_M = &presnost_M_;

/*
 * This function updates continuous states using the ODE3 fixed-step
 * solver algorithm
 */
static void rt_ertODEUpdateContinuousStates(RTWSolverInfo *si )
{
  /* Solver Matrices */
  static const real_T rt_ODE3_A[3] = {
    1.0/2.0, 3.0/4.0, 1.0
  };

  static const real_T rt_ODE3_B[3][3] = {
    { 1.0/2.0, 0.0, 0.0 },

    { 0.0, 3.0/4.0, 0.0 },

    { 2.0/9.0, 1.0/3.0, 4.0/9.0 }
  };

  time_T t = rtsiGetT(si);
  time_T tnew = rtsiGetSolverStopTime(si);
  time_T h = rtsiGetStepSize(si);
  real_T *x = rtsiGetContStates(si);
  ODE3_IntgData *id = (ODE3_IntgData *)rtsiGetSolverData(si);
  real_T *y = id->y;
  real_T *f0 = id->f[0];
  real_T *f1 = id->f[1];
  real_T *f2 = id->f[2];
  real_T hB[3];
  int_T i;
  int_T nXc = 1;
  rtsiSetSimTimeStep(si,MINOR_TIME_STEP);

  /* Save the state values at time t in y, we'll use x as ynew. */
  (void) memcpy(y, x,
                (uint_T)nXc*sizeof(real_T));

  /* Assumes that rtsiSetT and ModelOutputs are up-to-date */
  /* f0 = f(t,y) */
  rtsiSetdX(si, f0);
  presnost_derivatives();

  /* f(:,2) = feval(odefile, t + hA(1), y + f*hB(:,1), args(:)(*)); */
  hB[0] = h * rt_ODE3_B[0][0];
  for (i = 0; i < nXc; i++) {
    x[i] = y[i] + (f0[i]*hB[0]);
  }

  rtsiSetT(si, t + h*rt_ODE3_A[0]);
  rtsiSetdX(si, f1);
  presnost_output();
  presnost_derivatives();

  /* f(:,3) = feval(odefile, t + hA(2), y + f*hB(:,2), args(:)(*)); */
  for (i = 0; i <= 1; i++) {
    hB[i] = h * rt_ODE3_B[1][i];
  }

  for (i = 0; i < nXc; i++) {
    x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1]);
  }

  rtsiSetT(si, t + h*rt_ODE3_A[1]);
  rtsiSetdX(si, f2);
  presnost_output();
  presnost_derivatives();

  /* tnew = t + hA(3);
     ynew = y + f*hB(:,3); */
  for (i = 0; i <= 2; i++) {
    hB[i] = h * rt_ODE3_B[2][i];
  }

  for (i = 0; i < nXc; i++) {
    x[i] = y[i] + (f0[i]*hB[0] + f1[i]*hB[1] + f2[i]*hB[2]);
  }

  rtsiSetT(si, tnew);
  rtsiSetSimTimeStep(si,MAJOR_TIME_STEP);
}

/* Model output function */
void presnost_output(void)
{
  /* local block i/o variables */
  real_T rtb_Clock;
  real_T rtb_Step_h;
  real_T rtb_Step;
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* set solver stop time */
    if (!(presnost_M->Timing.clockTick0+1)) {
      rtsiSetSolverStopTime(&presnost_M->solverInfo,
                            ((presnost_M->Timing.clockTickH0 + 1) *
        presnost_M->Timing.stepSize0 * 4294967296.0));
    } else {
      rtsiSetSolverStopTime(&presnost_M->solverInfo,
                            ((presnost_M->Timing.clockTick0 + 1) *
        presnost_M->Timing.stepSize0 + presnost_M->Timing.clockTickH0 *
        presnost_M->Timing.stepSize0 * 4294967296.0));
    }
  }                                    /* end MajorTimeStep */

  /* Update absolute time of base rate at minor time step */
  if (rtmIsMinorTimeStep(presnost_M)) {
    presnost_M->Timing.t[0] = rtsiGetT(&presnost_M->solverInfo);
  }

  /* RTWBLOCK_START_COMMENT */
  /* Reset subsysRan breadcrumbs */
  srClearBC(presnost_DWork.EnabledSubsystem_SubsysRanBC);

  /* Reset subsysRan breadcrumbs */
  srClearBC(presnost_DWork.EnabledSubsystem1_SubsysRanBC);

  /* Step: '<S6>/Step' */
  /* RTWBLOCK_START_COMMENT */
  if (presnost_M->Timing.t[0] < presnost_P.Step_Time) {
    rtb_Step = presnost_P.Step_Y0;
  } else {
    rtb_Step = presnost_P.Step_YFinal;
  }

  /* End of Step: '<S6>/Step' */

  /* Clock: '<S6>/Clock' */
  rtb_Clock = presnost_M->Timing.t[0];

  /* Sum: '<S6>/Output' incorporates:
   *  Constant: '<S6>/Constant'
   *  Constant: '<S6>/Constant1'
   *  Product: '<S6>/Product'
   *  Sum: '<S6>/Sum'
   */
  presnost_B.Output = (rtb_Clock - presnost_P.Constant_Value) * rtb_Step +
    presnost_P.Constant1_Value;
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* Saturate: '<Root>/Saturation' */
    if (presnost_B.Output >= presnost_P.Saturation_UpperSat) {
      presnost_B.Saturation = presnost_P.Saturation_UpperSat;
    } else if (presnost_B.Output <= presnost_P.Saturation_LowerSat) {
      presnost_B.Saturation = presnost_P.Saturation_LowerSat;
    } else {
      presnost_B.Saturation = presnost_B.Output;
    }

    /* End of Saturate: '<Root>/Saturation' */

    /* ManualSwitch: '<S5>/Manual Switch' incorporates:
     *  Constant: '<S5>/Constant1'
     *  Constant: '<S5>/Constant2'
     */
    if (presnost_P.ManualSwitch_CurrentSetting == 1) {
      rtb_Step_h = presnost_P.Constant1_Value_f;
    } else {
      rtb_Step_h = presnost_P.Constant2_Value;
    }

    /* End of ManualSwitch: '<S5>/Manual Switch' */
    /* S-Function Block: <S5>/Frequency Output */
    {
      {
        RTBIO_DriverIO(0, FREQUENCYOUTPUT, IOWRITE, 1,
                       &presnost_P.FrequencyOutput_Channels,
                       &presnost_B.Saturation, &presnost_P.Strida_Value);
      }
    }

    /* S-Function Block: <S5>/DIR */
    {
      RTBIO_DriverIO(0, DIGITALOUTPUT, IOWRITE, 1, &presnost_P.DIR_Channels,
                     &rtb_Step_h, &presnost_P.DIR_BitMode);
    }

    /* S-Function Block: <S5>/Enable */
    {
      RTBIO_DriverIO(0, DIGITALOUTPUT, IOWRITE, 1, &presnost_P.Enable_Channels,
                     &presnost_P.Constant4_Value, &presnost_P.Enable_BitMode);
    }

    /* S-Function Block: <S5>/Encoder Input */
    {
      ENCODERINPARM parm;
      parm.quad = (QUADMODE) 0;
      parm.index = (INDEXPULSE) 2;
      parm.infilter = presnost_P.EncoderInput_InputFilter;
      RTBIO_DriverIO(0, ENCODERINPUT, IOREAD, 1,
                     &presnost_P.EncoderInput_Channels, &rtb_Step_h, &parm);
    }

    /* Gain: '<S5>/Gain' */
    presnost_B.Gain = presnost_P.Gain_Gain * rtb_Step_h;

    /* Step: '<Root>/Step' */
    if (presnost_M->Timing.t[1] < presnost_P.Step_Time_l) {
      rtb_Step_h = presnost_P.Step_Y0_c;
    } else {
      rtb_Step_h = presnost_P.Step_YFinal_n;
    }

    /* End of Step: '<Root>/Step' */
    /* S-Function Block: <Root>/Counter Input */
    {
      double inval[1];
      double* invalp = inval;
      COUNTERINPARM parm;
      DRVIOACTION action;
      int reset = rtb_Step_h != 0;
      action = (!presnost_DWork.CounterInput_IWORK.LastResetInput && reset) ?
        IOREADWITHRESET : IOREAD;
      parm.edge = (COUNTEREDGE) presnost_P.CounterInput_CtrEdge;
      parm.gate = (COUNTERGATE) presnost_P.CounterInput_CtrGate;
      RTBIO_DriverIO(0, COUNTERINPUT, action, 1,
                     &presnost_P.CounterInput_Channels, inval, &parm);
      presnost_B.CounterInput = (uint32_T) *invalp++;
      presnost_DWork.CounterInput_IWORK.LastResetInput = reset;
    }

    /* Gain: '<Root>/Gain2' */
    presnost_B.Gain2 = presnost_P.Gain2_Gain * presnost_B.Gain;
  }

  /* Step: '<Root>/Step1' */
  if (presnost_M->Timing.t[0] < presnost_P.Step1_Time) {
    presnost_B.Step1 = presnost_P.Step1_Y0;
  } else {
    presnost_B.Step1 = presnost_P.Step1_YFinal;
  }

  /* End of Step: '<Root>/Step1' */
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* UnitDelay: '<S1>/Delay Input1' */
    presnost_B.Uk1 = presnost_DWork.DelayInput1_DSTATE;
  }

  /* RelationalOperator: '<S1>/FixPt Relational Operator' */
  presnost_B.FixPtRelationalOperator = (presnost_B.Step1 > presnost_B.Uk1);
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* Outputs for Enabled SubSystem: '<Root>/Enabled Subsystem' incorporates:
     *  EnablePort: '<S3>/Enable'
     */
    if (presnost_B.FixPtRelationalOperator) {
      /* DataStoreWrite: '<S3>/Data Store Write' incorporates:
       *  Sum: '<S3>/Add'
       */
      rozdil = (real_T)presnost_B.CounterInput - presnost_B.Gain2;
      if (rtmIsMajorTimeStep(presnost_M)) {
        srUpdateBC(presnost_DWork.EnabledSubsystem_SubsysRanBC);
      }
    }

    /* End of Outputs for SubSystem: '<Root>/Enabled Subsystem' */

    /* Sum: '<Root>/Add' */
    presnost_B.Add = (real_T)presnost_B.CounterInput - presnost_B.Gain2;
  }

  /* Step: '<Root>/Step2' */
  if (presnost_M->Timing.t[0] < presnost_P.Step2_Time) {
    presnost_B.Step2 = presnost_P.Step2_Y0;
  } else {
    presnost_B.Step2 = presnost_P.Step2_YFinal;
  }

  /* End of Step: '<Root>/Step2' */
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* UnitDelay: '<S2>/Delay Input1' */
    presnost_B.Uk1_j = presnost_DWork.DelayInput1_DSTATE_h;
  }

  /* RelationalOperator: '<S2>/FixPt Relational Operator' */
  presnost_B.FixPtRelationalOperator_a = (presnost_B.Step2 > presnost_B.Uk1_j);
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* Outputs for Enabled SubSystem: '<Root>/Enabled Subsystem1' incorporates:
     *  EnablePort: '<S4>/Enable'
     */
    if (presnost_B.FixPtRelationalOperator_a) {
      /* DataStoreWrite: '<S4>/Data Store Write' */
      final = presnost_B.Add;
      if (rtmIsMajorTimeStep(presnost_M)) {
        srUpdateBC(presnost_DWork.EnabledSubsystem1_SubsysRanBC);
      }
    }

    /* End of Outputs for SubSystem: '<Root>/Enabled Subsystem1' */
  }

  /* TransferFcn: '<Root>/Transfer Fcn2' */
  presnost_B.TransferFcn2 = presnost_P.TransferFcn2_C*
    presnost_X.TransferFcn2_CSTATE;
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* Gain: '<Root>/Gain1' */
    presnost_B.Gain1 = presnost_P.Gain1_Gain * presnost_B.Gain;
  }

  /* Derivative: '<Root>/Derivative' */
  {
    real_T t = presnost_M->Timing.t[0];
    real_T timeStampA = presnost_DWork.Derivative_RWORK.TimeStampA;
    real_T timeStampB = presnost_DWork.Derivative_RWORK.TimeStampB;
    real_T *lastU = &presnost_DWork.Derivative_RWORK.LastUAtTimeA;
    if (timeStampA >= t && timeStampB >= t) {
      presnost_B.Derivative = 0.0;
    } else {
      real_T deltaT;
      real_T lastTime = timeStampA;
      if (timeStampA < timeStampB) {
        if (timeStampB < t) {
          lastTime = timeStampB;
          lastU = &presnost_DWork.Derivative_RWORK.LastUAtTimeB;
        }
      } else if (timeStampA >= t) {
        lastTime = timeStampB;
        lastU = &presnost_DWork.Derivative_RWORK.LastUAtTimeB;
      }

      deltaT = t - lastTime;
      presnost_B.Derivative = (presnost_B.Gain1 - *lastU++) / deltaT;
    }
  }

  if (rtmIsMajorTimeStep(presnost_M)) {
    /* DataStoreRead: '<Root>/Data Store Read' */
    presnost_B.DataStoreRead = rozdil;

    /* Sum: '<Root>/Add1' incorporates:
     *  DataStoreRead: '<Root>/Data Store Read1'
     */
    presnost_B.Add1 = final - presnost_B.DataStoreRead;
  }
}

/* Model update function */
void presnost_update(void)
{
  if (rtmIsMajorTimeStep(presnost_M)) {
    /* Update for UnitDelay: '<S1>/Delay Input1' */
    presnost_DWork.DelayInput1_DSTATE = presnost_B.Step1;

    /* Update for UnitDelay: '<S2>/Delay Input1' */
    presnost_DWork.DelayInput1_DSTATE_h = presnost_B.Step2;
  }

  /* Update for Derivative: '<Root>/Derivative' */
  {
    real_T timeStampA = presnost_DWork.Derivative_RWORK.TimeStampA;
    real_T timeStampB = presnost_DWork.Derivative_RWORK.TimeStampB;
    real_T* lastTime = &presnost_DWork.Derivative_RWORK.TimeStampA;
    real_T* lastU = &presnost_DWork.Derivative_RWORK.LastUAtTimeA;
    if (timeStampA != rtInf) {
      if (timeStampB == rtInf) {
        lastTime = &presnost_DWork.Derivative_RWORK.TimeStampB;
        lastU = &presnost_DWork.Derivative_RWORK.LastUAtTimeB;
      } else if (timeStampA >= timeStampB) {
        lastTime = &presnost_DWork.Derivative_RWORK.TimeStampB;
        lastU = &presnost_DWork.Derivative_RWORK.LastUAtTimeB;
      }
    }

    *lastTime = presnost_M->Timing.t[0];
    *lastU++ = presnost_B.Gain1;
  }

  if (rtmIsMajorTimeStep(presnost_M)) {
    rt_ertODEUpdateContinuousStates(&presnost_M->solverInfo);
  }

  /* Update absolute time for base rate */
  /* The "clockTick0" counts the number of times the code of this task has
   * been executed. The absolute time is the multiplication of "clockTick0"
   * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
   * overflow during the application lifespan selected.
   * Timer of this task consists of two 32 bit unsigned integers.
   * The two integers represent the low bits Timing.clockTick0 and the high bits
   * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment.
   */
  if (!(++presnost_M->Timing.clockTick0)) {
    ++presnost_M->Timing.clockTickH0;
  }

  presnost_M->Timing.t[0] = rtsiGetSolverStopTime(&presnost_M->solverInfo);

  {
    /* Update absolute timer for sample time: [0.0001s, 0.0s] */
    /* The "clockTick1" counts the number of times the code of this task has
     * been executed. The absolute time is the multiplication of "clockTick1"
     * and "Timing.stepSize1". Size of "clockTick1" ensures timer will not
     * overflow during the application lifespan selected.
     * Timer of this task consists of two 32 bit unsigned integers.
     * The two integers represent the low bits Timing.clockTick1 and the high bits
     * Timing.clockTickH1. When the low bit overflows to 0, the high bits increment.
     */
    if (!(++presnost_M->Timing.clockTick1)) {
      ++presnost_M->Timing.clockTickH1;
    }

    presnost_M->Timing.t[1] = presnost_M->Timing.clockTick1 *
      presnost_M->Timing.stepSize1 + presnost_M->Timing.clockTickH1 *
      presnost_M->Timing.stepSize1 * 4294967296.0;
  }
}

/* Derivatives for root system: '<Root>' */
void presnost_derivatives(void)
{
  /* Derivatives for TransferFcn: '<Root>/Transfer Fcn2' */
  {
    ((StateDerivatives_presnost *) presnost_M->ModelData.derivs)
      ->TransferFcn2_CSTATE = presnost_B.Derivative;
    ((StateDerivatives_presnost *) presnost_M->ModelData.derivs)
      ->TransferFcn2_CSTATE += (presnost_P.TransferFcn2_A)*
      presnost_X.TransferFcn2_CSTATE;
  }
}

/* Model initialize function */
void presnost_initialize(void)
{
  /* S-Function Block: <S5>/Frequency Output */
  {
    {
      RTBIO_DriverIO(0, FREQUENCYOUTPUT, IOWRITE, 1,
                     &presnost_P.FrequencyOutput_Channels,
                     &presnost_P.FrequencyOutput_Frequency,
                     &presnost_P.FrequencyOutput_Duty);
    }
  }

  /* S-Function Block: <S5>/DIR */

  /* no initial value should be set */

  /* S-Function Block: <S5>/Enable */

  /* no initial value should be set */

  /* Start for DataStoreMemory: '<Root>/Data Store Memory' */
  rozdil = presnost_P.DataStoreMemory_InitialValue;

  /* Start for DataStoreMemory: '<Root>/Data Store Memory1' */
  final = presnost_P.DataStoreMemory1_InitialValue;

  /* S-Function Block: <S5>/Encoder Input */
  {
    ENCODERINPARM parm;
    parm.quad = (QUADMODE) 0;
    parm.index = (INDEXPULSE) 2;
    parm.infilter = presnost_P.EncoderInput_InputFilter;
    RTBIO_DriverIO(0, ENCODERINPUT, IORESET, 1,
                   &presnost_P.EncoderInput_Channels, NULL, &parm);
  }

  /* S-Function Block: <Root>/Counter Input */
  {
    COUNTERINPARM parm;
    parm.edge = (COUNTEREDGE) presnost_P.CounterInput_CtrEdge;
    parm.gate = (COUNTERGATE) presnost_P.CounterInput_CtrGate;
    RTBIO_DriverIO(0, COUNTERINPUT, IORESET, 1,
                   &presnost_P.CounterInput_Channels, NULL, &parm);
  }

  /* InitializeConditions for UnitDelay: '<S1>/Delay Input1' */
  presnost_DWork.DelayInput1_DSTATE = presnost_P.DelayInput1_InitialCondition;

  /* InitializeConditions for UnitDelay: '<S2>/Delay Input1' */
  presnost_DWork.DelayInput1_DSTATE_h =
    presnost_P.DelayInput1_InitialCondition_g;

  /* InitializeConditions for TransferFcn: '<Root>/Transfer Fcn2' */
  presnost_X.TransferFcn2_CSTATE = 0.0;

  /* InitializeConditions for Derivative: '<Root>/Derivative' */
  presnost_DWork.Derivative_RWORK.TimeStampA = rtInf;
  presnost_DWork.Derivative_RWORK.TimeStampB = rtInf;
}

/* Model terminate function */
void presnost_terminate(void)
{
  /* S-Function Block: <S5>/Frequency Output */
  {
    {
      RTBIO_DriverIO(0, FREQUENCYOUTPUT, IOWRITE, 1,
                     &presnost_P.FrequencyOutput_Channels,
                     &presnost_P.FrequencyOutput_FrequencyFinalValue,
                     &presnost_P.FrequencyOutput_DutyFinalValue);
    }
  }

  /* S-Function Block: <S5>/DIR */

  /* no final value should be set */

  /* S-Function Block: <S5>/Enable */
  {
    RTBIO_DriverIO(0, DIGITALOUTPUT, IOWRITE, 1, &presnost_P.Enable_Channels,
                   &presnost_P.Enable_FinalValue, &presnost_P.Enable_BitMode);
  }
}

/*========================================================================*
 * Start of Classic call interface                                        *
 *========================================================================*/

/* Solver interface called by GRT_Main */
#ifndef USE_GENERATED_SOLVER

void rt_ODECreateIntegrationData(RTWSolverInfo *si)
{
  UNUSED_PARAMETER(si);
  return;
}                                      /* do nothing */

void rt_ODEDestroyIntegrationData(RTWSolverInfo *si)
{
  UNUSED_PARAMETER(si);
  return;
}                                      /* do nothing */

void rt_ODEUpdateContinuousStates(RTWSolverInfo *si)
{
  UNUSED_PARAMETER(si);
  return;
}                                      /* do nothing */

#endif

void MdlOutputs(int_T tid)
{
  presnost_output();

  /* tid is required for a uniform function interface.
   * Argument tid is not used in the function. */
  UNUSED_PARAMETER(tid);
}

void MdlUpdate(int_T tid)
{
  presnost_update();

  /* tid is required for a uniform function interface.
   * Argument tid is not used in the function. */
  UNUSED_PARAMETER(tid);
}

void MdlInitializeSizes(void)
{
}

void MdlInitializeSampleTimes(void)
{
}

void MdlInitialize(void)
{
}

void MdlStart(void)
{
  presnost_initialize();
}

void MdlTerminate(void)
{
  presnost_terminate();
}

RT_MODEL_presnost *presnost(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* non-finite (run-time) assignments */
  presnost_P.EncoderInput_InputFilter = rtInf;

  /* initialize real-time model */
  (void) memset((void *)presnost_M, 0,
                sizeof(RT_MODEL_presnost));

  {
    /* Setup solver object */
    rtsiSetSimTimeStepPtr(&presnost_M->solverInfo,
                          &presnost_M->Timing.simTimeStep);
    rtsiSetTPtr(&presnost_M->solverInfo, &rtmGetTPtr(presnost_M));
    rtsiSetStepSizePtr(&presnost_M->solverInfo, &presnost_M->Timing.stepSize0);
    rtsiSetdXPtr(&presnost_M->solverInfo, &presnost_M->ModelData.derivs);
    rtsiSetContStatesPtr(&presnost_M->solverInfo,
                         &presnost_M->ModelData.contStates);
    rtsiSetNumContStatesPtr(&presnost_M->solverInfo,
      &presnost_M->Sizes.numContStates);
    rtsiSetErrorStatusPtr(&presnost_M->solverInfo, (&rtmGetErrorStatus
      (presnost_M)));
    rtsiSetRTModelPtr(&presnost_M->solverInfo, presnost_M);
  }

  rtsiSetSimTimeStep(&presnost_M->solverInfo, MAJOR_TIME_STEP);
  presnost_M->ModelData.intgData.y = presnost_M->ModelData.odeY;
  presnost_M->ModelData.intgData.f[0] = presnost_M->ModelData.odeF[0];
  presnost_M->ModelData.intgData.f[1] = presnost_M->ModelData.odeF[1];
  presnost_M->ModelData.intgData.f[2] = presnost_M->ModelData.odeF[2];
  presnost_M->ModelData.contStates = ((real_T *) &presnost_X);
  rtsiSetSolverData(&presnost_M->solverInfo, (void *)
                    &presnost_M->ModelData.intgData);
  rtsiSetSolverName(&presnost_M->solverInfo,"ode3");

  /* Initialize timing info */
  {
    int_T *mdlTsMap = presnost_M->Timing.sampleTimeTaskIDArray;
    mdlTsMap[0] = 0;
    mdlTsMap[1] = 1;
    presnost_M->Timing.sampleTimeTaskIDPtr = (&mdlTsMap[0]);
    presnost_M->Timing.sampleTimes = (&presnost_M->Timing.sampleTimesArray[0]);
    presnost_M->Timing.offsetTimes = (&presnost_M->Timing.offsetTimesArray[0]);

    /* task periods */
    presnost_M->Timing.sampleTimes[0] = (0.0);
    presnost_M->Timing.sampleTimes[1] = (0.0001);

    /* task offsets */
    presnost_M->Timing.offsetTimes[0] = (0.0);
    presnost_M->Timing.offsetTimes[1] = (0.0);
  }

  rtmSetTPtr(presnost_M, &presnost_M->Timing.tArray[0]);

  {
    int_T *mdlSampleHits = presnost_M->Timing.sampleHitArray;
    mdlSampleHits[0] = 1;
    mdlSampleHits[1] = 1;
    presnost_M->Timing.sampleHits = (&mdlSampleHits[0]);
  }

  rtmSetTFinal(presnost_M, 13.0);
  presnost_M->Timing.stepSize0 = 0.0001;
  presnost_M->Timing.stepSize1 = 0.0001;

  /* External mode info */
  presnost_M->Sizes.checksums[0] = (4173951350U);
  presnost_M->Sizes.checksums[1] = (1841136717U);
  presnost_M->Sizes.checksums[2] = (1223356931U);
  presnost_M->Sizes.checksums[3] = (965589952U);

  {
    static const sysRanDType rtAlwaysEnabled = SUBSYS_RAN_BC_ENABLE;
    static RTWExtModeInfo rt_ExtModeInfo;
    static const sysRanDType *systemRan[3];
    presnost_M->extModeInfo = (&rt_ExtModeInfo);
    rteiSetSubSystemActiveVectorAddresses(&rt_ExtModeInfo, systemRan);
    systemRan[0] = &rtAlwaysEnabled;
    systemRan[1] = (sysRanDType *)&presnost_DWork.EnabledSubsystem_SubsysRanBC;
    systemRan[2] = (sysRanDType *)&presnost_DWork.EnabledSubsystem1_SubsysRanBC;
    rteiSetModelMappingInfoPtr(presnost_M->extModeInfo,
      &presnost_M->SpecialInfo.mappingInfo);
    rteiSetChecksumsPtr(presnost_M->extModeInfo, presnost_M->Sizes.checksums);
    rteiSetTPtr(presnost_M->extModeInfo, rtmGetTPtr(presnost_M));
  }

  presnost_M->solverInfoPtr = (&presnost_M->solverInfo);
  presnost_M->Timing.stepSize = (0.0001);
  rtsiSetFixedStepSize(&presnost_M->solverInfo, 0.0001);
  rtsiSetSolverMode(&presnost_M->solverInfo, SOLVER_MODE_SINGLETASKING);

  /* block I/O */
  presnost_M->ModelData.blockIO = ((void *) &presnost_B);
  (void) memset(((void *) &presnost_B), 0,
                sizeof(BlockIO_presnost));

  /* parameters */
  presnost_M->ModelData.defaultParam = ((real_T *)&presnost_P);

  /* states (continuous) */
  {
    real_T *x = (real_T *) &presnost_X;
    presnost_M->ModelData.contStates = (x);
    (void) memset((void *)&presnost_X, 0,
                  sizeof(ContinuousStates_presnost));
  }

  /* states (dwork) */
  presnost_M->Work.dwork = ((void *) &presnost_DWork);
  (void) memset((void *)&presnost_DWork, 0,
                sizeof(D_Work_presnost));

  /* exported global states */
  rozdil = 0.0;
  final = 0.0;

  /* data type transition information */
  {
    static DataTypeTransInfo dtInfo;
    (void) memset((char_T *) &dtInfo, 0,
                  sizeof(dtInfo));
    presnost_M->SpecialInfo.mappingInfo = (&dtInfo);
    dtInfo.numDataTypes = 14;
    dtInfo.dataTypeSizes = &rtDataTypeSizes[0];
    dtInfo.dataTypeNames = &rtDataTypeNames[0];

    /* Block I/O transition table */
    dtInfo.B = &rtBTransTable;

    /* Parameters transition table */
    dtInfo.P = &rtPTransTable;
  }

  /* Initialize Sizes */
  presnost_M->Sizes.numContStates = (1);/* Number of continuous states */
  presnost_M->Sizes.numY = (0);        /* Number of model outputs */
  presnost_M->Sizes.numU = (0);        /* Number of model inputs */
  presnost_M->Sizes.sysDirFeedThru = (0);/* The model is not direct feedthrough */
  presnost_M->Sizes.numSampTimes = (2);/* Number of sample times */
  presnost_M->Sizes.numBlocks = (53);  /* Number of blocks */
  presnost_M->Sizes.numBlockIO = (17); /* Number of block outputs */
  presnost_M->Sizes.numBlockPrms = (55);/* Sum of parameter "widths" */
  return presnost_M;
}

/*========================================================================*
 * End of Classic call interface                                          *
 *========================================================================*/
