Пример #1
0
/* Function Definitions */
void Cone(const emlrtStack *sp, real_T k, const emxArray_real_T *x, const
          emxArray_real_T *gridX, const emxArray_real_T *t, emxArray_real_T
          *vals)
{
    int32_T t_idx_0;
    int32_T i49;
    int32_T l;
    int32_T i50;
    int32_T i51;
    int32_T i52;
    int32_T i53;
    int32_T i54;
    emlrtStack st;
    st.prev = sp;
    st.tls = sp->tls;

    /*  calculate the matrix Cone for a specific space point x_k, for all times */
    /*  t_i in A */
    /*  points x_k=1:numel(spacePoints) */
    t_idx_0 = t->size[1];
    i49 = vals->size[0] * vals->size[1];
    vals->size[0] = t_idx_0;
    emxEnsureCapacity(sp, (emxArray__common *)vals, i49, (int32_T)sizeof(real_T),
                      &v_emlrtRTEI);
    t_idx_0 = x->size[1];
    i49 = vals->size[0] * vals->size[1];
    vals->size[1] = t_idx_0;
    emxEnsureCapacity(sp, (emxArray__common *)vals, i49, (int32_T)sizeof(real_T),
                      &v_emlrtRTEI);
    t_idx_0 = t->size[1] * x->size[1];
    for (i49 = 0; i49 < t_idx_0; i49++) {
        vals->data[i49] = 0.0;
    }

    t_idx_0 = 1;
    while (t_idx_0 - 1 <= t->size[1] - 1) {
        l = 0;
        while (l <= x->size[1] - 1) {
            i49 = vals->size[0];
            i50 = vals->size[1];
            i51 = 1 + l;
            i52 = x->size[1];
            i53 = (int32_T)emlrtIntegerCheckFastR2012b(k, &nb_emlrtDCI, sp);
            i54 = t->size[1];
            st.site = &le_emlrtRSI;
            vals->data[(emlrtDynamicBoundsCheckFastR2012b(t_idx_0, 1, i49,
                        &je_emlrtBCI, sp) + vals->size[0] * (emlrtDynamicBoundsCheckFastR2012b
                                (i51, 1, i50, &ke_emlrtBCI, sp) - 1)) - 1] = b_Ccoeff(&st, 1.0 + (real_T)
                                        l, x->data[emlrtDynamicBoundsCheckFastR2012b(i53, 1, i52, &le_emlrtBCI,
                                                   sp) - 1], t->data[emlrtDynamicBoundsCheckFastR2012b(t_idx_0, 1, i54,
                                                           &me_emlrtBCI, sp) - 1], gridX);
            l++;
            emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
        }

        t_idx_0++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }
}
Пример #2
0
real_T b_Dcoeff(const emlrtStack *sp, const real_T y[3], real_T j, real_T x,
                real_T t, const emxArray_real_T *timePoints)
{
  real_T vals;
  real_T a[3];
  int32_T aIdx;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;

  /*  Calculate the integral int_0^1(f(y,t_j)*A_{yj}(x,t)dy) by midpoint */
  /*  integration rule */
  /*  the spatial integration of all points y at time t_j */
  for (aIdx = 0; aIdx < 3; aIdx++) {
    a[aIdx] = 0.0;
  }

  vals = 0.0;
  st.site = &q_emlrtRSI;
  a[0] = Acoeff(&st, y[0], j, x, t, timePoints);
  for (aIdx = 0; aIdx < 2; aIdx++) {
    st.site = &r_emlrtRSI;
    a[aIdx + 1] = Acoeff(&st, y[aIdx + 1], j, x, t, timePoints);
    vals += 0.5 * (a[aIdx + 1] + a[aIdx]) * (y[aIdx + 1] - y[aIdx]);
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  return vals;
}
Пример #3
0
/* Function Definitions */
void PHYTransmit(testPHYTransmitStackData *SD, comm_SDRuTransmitter
                 *b_ObjSDRuTransmitter)
{
  OFDMDemodulator *unusedU1;
  OFDMDemodulator_1 *unusedU0;
  OFDMDemodulator_1 b_unusedU0;
  OFDMDemodulator b_unusedU1;
  int32_T framesTransmitted;

  /*  Send Messages */
  /* % Create message bits */
  /*  The output needs to be duplicated to long vectors to help prevent */
  /*  Underflow for the USRP */
  emlrtPushRtStackR2012b(&ve_emlrtRSI, emlrtRootTLSGlobal);
  b_generateOFDMSignal_TX2(&b_unusedU1, &b_unusedU0, &unusedU0, &unusedU1,
    SD->u2.f4.dataToTx, &SD->u2.f4.unusedU2);
  emlrtPopRtStackR2012b(&ve_emlrtRSI, emlrtRootTLSGlobal);

  /*  30 Dupe frames created (NOTE! author shouldcreate shorter simpler function) */
  /* % Run transmitter */
  /* increasing value will help receiver, 10 */
  /*  This should be longer to help transmit over periods when the RX is */
  /*  cleaning its buffer */
  for (framesTransmitted = 0; framesTransmitted < 10; framesTransmitted++) {
    emlrtPushRtStackR2012b(&ue_emlrtRSI, emlrtRootTLSGlobal);
    g_SystemCore_step(SD, b_ObjSDRuTransmitter, SD->u2.f4.dataToTx);
    emlrtPopRtStackR2012b(&ue_emlrtRSI, emlrtRootTLSGlobal);

    /* if mod(framesTransmitted,60) == 0 */
    /* end */
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal);
  }

  /* obj.pSDRuTransmitter.reset;%stop transmitting? */
}
Пример #4
0
/* Function Definitions */
void PHYTransmit(testMACRouterStackData *SD, const emlrtStack *sp,
                 comm_SDRuTransmitter *ObjSDRuTransmitter, comm_SDRuReceiver
                 *ObjSDRuReceiver, real_T originNodeID, real_T destNodeID)
{
  OFDMDemodulator_2 *unusedU1;
  OFDMDemodulator_3 *unusedU0;
  OFDMDemodulator_3 b_unusedU0;
  OFDMDemodulator_2 b_unusedU1;
  int32_T framesTransmitted;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;

  /*  Send Messages */
  /* % Create message bits */
  /*  The output needs to be duplicated to long vectors to help prevent */
  /*  Underflow for the USRP */
  st.site = &wu_emlrtRSI;
  b_generateOFDMSignal_TX2(&st, originNodeID, destNodeID, &b_unusedU1,
    &b_unusedU0, &unusedU0, &unusedU1, SD->u2.f7.dataToTx, &SD->u2.f7.unusedU2);

  /*  30 Dupe frames created (NOTE! author shouldcreate shorter simpler function) */
  /* % Run transmitter */
  /* increasing value will help receiver, 10 */
  /*  This should be longer to help transmit over periods when the RX is */
  /*  cleaning its buffer */
  for (framesTransmitted = 0; framesTransmitted < 10; framesTransmitted++) {
    st.site = &uu_emlrtRSI;
    i_SystemCore_step(SD, &st, ObjSDRuTransmitter, SD->u2.f7.dataToTx);

    /* if mod(framesTransmitted,60) == 0 */
    st.site = &vu_emlrtRSI;
    j_SystemCore_step(SD, &st, ObjSDRuReceiver);

    /*  Call used to prevent Overflow.  Essentially will clean up receive buffer, will be filled with crosstalk frames */
    /* end */
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  /* obj.pSDRuTransmitter.reset;%stop transmitting? */
}
Пример #5
0
/* Function Definitions */
void CalculateHeatSolution(const emlrtStack *sp, real_T N0, real_T N, const
  emxArray_real_T *t, const emxArray_real_T *gridT, const emxArray_real_T *x,
  const emxArray_real_T *u0, const emxArray_real_T *q0j, const emxArray_real_T
  *q1j, const emxArray_real_T *h0j, const emxArray_real_T *h1j, const
  emxArray_real_T *f, const emxArray_real_T *r, emxArray_real_T *u)
{
  emxArray_real_T *eta;
  int32_T i12;
  real_T sTime;
  int32_T loop_ub;
  int32_T i13;
  int32_T j;
  emxArray_real_T *b_f;
  int32_T i;
  real_T sSpace;
  int32_T tIdx;
  int32_T b_i;
  int32_T i14;
  int32_T i15;
  int32_T i16;
  int32_T i17;
  int32_T i18;
  int32_T i19;
  int32_T i20;
  int32_T i21;
  int32_T i22;
  int32_T i23;
  int32_T i24;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = sp;
  b_st.tls = sp->tls;
  c_st.prev = sp;
  c_st.tls = sp->tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &eta, 2, &f_emlrtRTEI, true);

  /*  get the solution for the inverse heat source, u(x,t),  */
  /*  N0 - number of space points */
  /*  N  - number of time points */
  /*  t  - time points */
  /*  gridT - time points grid */
  /*  x space points */
  /*  q0j flux at x=0 du/dn */
  /*  q1j flux at x=1 du/dn */
  /*  h0j boundary condition u(0,t) */
  /*  u1j boundary condition u(1,t) */
  /*  f multiplier of the source f(x,t)r(t) size[N N0] */
  /*  r calculated source term size [N,1] */
  i12 = eta->size[0] * eta->size[1];
  eta->size[0] = 1;
  sTime = emlrtNonNegativeCheckFastR2012b(N0, &eb_emlrtDCI, sp);
  eta->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(sTime, &db_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)eta, i12, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  sTime = emlrtNonNegativeCheckFastR2012b(N0, &eb_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(sTime, &db_emlrtDCI, sp);
  for (i12 = 0; i12 < loop_ub; i12++) {
    eta->data[i12] = 1.0;
  }

  i12 = (int32_T)N0;
  emlrtDynamicBoundsCheckFastR2012b(1, 1, i12, &tc_emlrtBCI, sp);
  eta->data[0] = 0.5;
  i12 = (int32_T)N0;
  i13 = (int32_T)N0;
  eta->data[emlrtDynamicBoundsCheckFastR2012b(i13, 1, i12, &uc_emlrtBCI, sp) - 1]
    = 0.5;
  i12 = u->size[0] * u->size[1];
  sTime = emlrtNonNegativeCheckFastR2012b(N, &gb_emlrtDCI, sp);
  u->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(sTime, &fb_emlrtDCI, sp);
  u->size[1] = (int32_T)N0;
  emxEnsureCapacity(sp, (emxArray__common *)u, i12, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  sTime = emlrtNonNegativeCheckFastR2012b(N, &gb_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(sTime, &fb_emlrtDCI, sp) *
    (int32_T)N0;
  for (i12 = 0; i12 < loop_ub; i12++) {
    u->data[i12] = 0.0;
  }

  j = 1;
  emxInit_real_T(sp, &b_f, 2, &e_emlrtRTEI, true);
  while (j - 1 <= (int32_T)N0 - 1) {
    /*  space index */
    emlrtForLoopVectorCheckR2012b(1.0, 1.0, N, mxDOUBLE_CLASS, (int32_T)N,
      &gc_emlrtRTEI, sp);
    i = 1;
    while (i - 1 <= (int32_T)N - 1) {
      /*  time index */
      sTime = 0.0;

      /*  cumulative sums */
      sSpace = 0.0;
      emlrtForLoopVectorCheckR2012b(1.0, 1.0, N, mxDOUBLE_CLASS, (int32_T)N,
        &hc_emlrtRTEI, sp);
      tIdx = 0;
      while (tIdx <= (int32_T)N - 1) {
        /*  time index */
        loop_ub = f->size[1];
        i12 = f->size[0];
        b_i = emlrtDynamicBoundsCheckFastR2012b(i, 1, i12, &sc_emlrtBCI, sp);
        i12 = b_f->size[0] * b_f->size[1];
        b_f->size[0] = 1;
        b_f->size[1] = loop_ub;
        emxEnsureCapacity(sp, (emxArray__common *)b_f, i12, (int32_T)sizeof
                          (real_T), &e_emlrtRTEI);
        for (i12 = 0; i12 < loop_ub; i12++) {
          b_f->data[b_f->size[0] * i12] = f->data[(b_i + f->size[0] * i12) - 1];
        }

        i12 = x->size[1];
        i13 = t->size[1];
        i14 = q0j->size[0];
        i15 = x->size[1];
        loop_ub = t->size[1];
        b_i = q1j->size[0];
        i16 = x->size[1];
        i17 = t->size[1];
        i18 = h0j->size[0];
        i19 = x->size[1];
        i20 = t->size[1];
        i21 = h1j->size[0];
        i22 = x->size[1];
        i23 = t->size[1];
        i24 = r->size[0];
        st.site = &bb_emlrtRSI;
        b_st.site = &cb_emlrtRSI;
        c_st.site = &db_emlrtRSI;
        sTime = ((((sTime + Acoeff(&st, 0.0, 1.0 + (real_T)tIdx, x->
          data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i12, &cd_emlrtBCI, sp) -
          1], t->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, i13, &dd_emlrtBCI,
          sp) - 1], gridT) * q0j->data[emlrtDynamicBoundsCheckFastR2012b(tIdx +
          1, 1, i14, &ed_emlrtBCI, sp) - 1]) + Acoeff(&st, 1.0, 1.0 + (real_T)
                    tIdx, x->data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i15,
          &fd_emlrtBCI, sp) - 1], t->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
          loop_ub, &gd_emlrtBCI, sp) - 1], gridT) * q1j->
                   data[emlrtDynamicBoundsCheckFastR2012b(tIdx + 1, 1, b_i,
                    &hd_emlrtBCI, sp) - 1]) - Bcoeff(&b_st, 0.0, 1.0 + (real_T)
                   tIdx, x->data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i16,
                    &id_emlrtBCI, sp) - 1], t->
                   data[emlrtDynamicBoundsCheckFastR2012b(i, 1, i17,
                    &jd_emlrtBCI, sp) - 1], gridT) * h0j->
                  data[emlrtDynamicBoundsCheckFastR2012b(tIdx + 1, 1, i18,
                   &kd_emlrtBCI, sp) - 1]) - Bcoeff(&b_st, 1.0, 1.0 + (real_T)
                  tIdx, x->data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i19,
                   &ld_emlrtBCI, sp) - 1], t->
                  data[emlrtDynamicBoundsCheckFastR2012b(i, 1, i20, &md_emlrtBCI,
                   sp) - 1], gridT) * h1j->
                 data[emlrtDynamicBoundsCheckFastR2012b(tIdx + 1, 1, i21,
                  &nd_emlrtBCI, sp) - 1]) + b_Dcoeff(&c_st, x, 1.0 + (real_T)
          tIdx, x->data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i22,
          &od_emlrtBCI, sp) - 1], t->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
          i23, &pd_emlrtBCI, sp) - 1], gridT, b_f) * r->
          data[emlrtDynamicBoundsCheckFastR2012b(tIdx + 1, 1, i24, &qd_emlrtBCI,
          sp) - 1];
        tIdx++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
      }

      loop_ub = 0;
      while (loop_ub <= (int32_T)N0 - 1) {
        /*  space index */
        i12 = x->size[1];
        i13 = t->size[1];
        i14 = u0->size[1];
        i15 = 1 + loop_ub;
        st.site = &eb_emlrtRSI;
        sSpace += b_Ccoeff(&st, 1.0 + (real_T)loop_ub, x->
                           data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i12,
          &yc_emlrtBCI, sp) - 1], t->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
          i13, &ad_emlrtBCI, sp) - 1], gridT) * u0->
          data[emlrtDynamicBoundsCheckFastR2012b(i15, 1, i14, &bd_emlrtBCI, sp)
          - 1];
        loop_ub++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
      }

      i12 = u->size[0];
      i13 = u->size[1];
      i14 = eta->size[1];
      u->data[(emlrtDynamicBoundsCheckFastR2012b(i, 1, i12, &vc_emlrtBCI, sp) +
               u->size[0] * (emlrtDynamicBoundsCheckFastR2012b(j, 1, i13,
                 &wc_emlrtBCI, sp) - 1)) - 1] = (sTime + sSpace) * eta->
        data[emlrtDynamicBoundsCheckFastR2012b(j, 1, i14, &xc_emlrtBCI, sp) - 1];
      i++;
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    j++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  emxFree_real_T(&b_f);
  emxFree_real_T(&eta);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Пример #6
0
void OFDMletters2bits(const emlrtStack *sp, const char_T str[80], real_T f[560])
{
  int32_T bits_size_idx_1;
  char_T bits_data[1280];
  int32_T i2;
  int32_T firstcol;
  int32_T j;
  boolean_T exitg1;
  boolean_T p;
  int32_T i;
  boolean_T exitg2;
  char_T b_bits_data[1280];
  const mxArray *y;
  const mxArray *m4;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;

  /*  Encode a string of ASCII text into bits(1,0) */
  st.site = &hf_emlrtRSI;
  bits_size_idx_1 = 16;
  for (i2 = 0; i2 < 1280; i2++) {
    bits_data[i2] = '0';
  }

  for (firstcol = 0; firstcol < 80; firstcol++) {
    for (j = 0; j < 16; j++) {
      if (((uint8_T)str[firstcol] & 1 << j) != 0) {
        bits_data[firstcol + 80 * (15 - j)] = '1';
      }
    }
  }

  firstcol = 16;
  j = 1;
  exitg1 = FALSE;
  while ((exitg1 == FALSE) && (j <= 15)) {
    p = FALSE;
    i = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (i <= 79)) {
      if (bits_data[i + 80 * (j - 1)] != '0') {
        p = TRUE;
        exitg2 = TRUE;
      } else {
        i++;
      }
    }

    if (p) {
      firstcol = j;
      exitg1 = TRUE;
    } else {
      j++;
    }
  }

  if (firstcol > 1) {
    for (j = firstcol; j < 17; j++) {
      for (i = 0; i < 80; i++) {
        bits_data[i + 80 * (j - firstcol)] = bits_data[i + 80 * (j - 1)];
      }
    }

    j = 17 - firstcol;
    for (i2 = 0; i2 < j; i2++) {
      memcpy(&b_bits_data[80 * i2], &bits_data[80 * i2], 80U * sizeof(char_T));
    }

    bits_size_idx_1 = 17 - firstcol;
    j = 17 - firstcol;
    for (i2 = 0; i2 < j; i2++) {
      memcpy(&bits_data[80 * i2], &b_bits_data[80 * i2], 80U * sizeof(char_T));
    }
  }

  for (firstcol = 0; firstcol < 80; firstcol++) {
    for (i = 0; i < 7; i++) {
      i2 = 1 + i;
      emlrtDynamicBoundsCheckFastR2012b(i2, 1, bits_size_idx_1, &c_emlrtBCI, sp);
      y = NULL;
      m4 = emlrtCreateString1(bits_data[firstcol + 80 * i]);
      emlrtAssign(&y, m4);
      st.site = &er_emlrtRSI;
      f[firstcol + 80 * i] = emlrt_marshallIn(&st, str2double(&st, y,
        &b_emlrtMCI), "str2double");
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }
}
Пример #7
0
void b_OFDMletters2bits(const emlrtStack *sp, real_T f[560])
{
  int32_T bits_size_idx_1;
  char_T bits_data[1280];
  int32_T i14;
  int32_T firstcol;
  static const char_T cv93[80] = { 'L', 'i', 'v', 'e', ' ', 'l', 'o', 'n', 'g',
    ' ', 'a', 'n', 'd', ' ', 'p', 'r', 'o', 's', 'p', 'e', 'r', ',', ' ', 'f',
    'r', 'o', 'm', ' ', 't', 'h', 'e', ' ', 'C', 'o', 'm', 'm', 'u', 'n', 'i',
    'c', 'a', 't', 'i', 'o', 'n', 's', ' ', 'S', 'y', 's', 't', 'e', 'm', ' ',
    'T', 'o', 'o', 'l', 'b', 'o', 'x', ' ', 'T', 'e', 'a', 'm', ' ', 'a', 't',
    ' ', 'M', 'a', 't', 'h', 'W', 'o', 'r', 'k', 's', '!' };

  uint16_T dk;
  int32_T j;
  boolean_T exitg1;
  boolean_T p;
  int32_T i;
  boolean_T exitg2;
  char_T b_bits_data[1280];
  const mxArray *y;
  const mxArray *m12;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;

  /*  Encode a string of ASCII text into bits(1,0) */
  st.site = &hf_emlrtRSI;
  bits_size_idx_1 = 16;
  for (i14 = 0; i14 < 1280; i14++) {
    bits_data[i14] = '0';
  }

  for (firstcol = 0; firstcol < 80; firstcol++) {
    dk = (uint16_T)cv93[firstcol];
    for (j = 0; j < 16; j++) {
      if ((dk & 1 << j) != 0) {
        bits_data[firstcol + 80 * (15 - j)] = '1';
      }
    }
  }

  firstcol = 16;
  j = 1;
  exitg1 = FALSE;
  while ((exitg1 == FALSE) && (j <= 15)) {
    p = FALSE;
    i = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (i <= 79)) {
      if (bits_data[i + 80 * (j - 1)] != '0') {
        p = TRUE;
        exitg2 = TRUE;
      } else {
        i++;
      }
    }

    if (p) {
      firstcol = j;
      exitg1 = TRUE;
    } else {
      j++;
    }
  }

  if (firstcol > 1) {
    for (j = firstcol; j < 17; j++) {
      for (i = 0; i < 80; i++) {
        bits_data[i + 80 * (j - firstcol)] = bits_data[i + 80 * (j - 1)];
      }
    }

    j = 17 - firstcol;
    for (i14 = 0; i14 < j; i14++) {
      memcpy(&b_bits_data[80 * i14], &bits_data[80 * i14], 80U * sizeof(char_T));
    }

    bits_size_idx_1 = 17 - firstcol;
    j = 17 - firstcol;
    for (i14 = 0; i14 < j; i14++) {
      memcpy(&bits_data[80 * i14], &b_bits_data[80 * i14], 80U * sizeof(char_T));
    }
  }

  for (firstcol = 0; firstcol < 80; firstcol++) {
    for (i = 0; i < 7; i++) {
      i14 = 1 + i;
      emlrtDynamicBoundsCheckFastR2012b(i14, 1, bits_size_idx_1, &c_emlrtBCI, sp);
      y = NULL;
      m12 = emlrtCreateString1(bits_data[firstcol + 80 * i]);
      emlrtAssign(&y, m12);
      st.site = &er_emlrtRSI;
      f[firstcol + 80 * i] = emlrt_marshallIn(&st, str2double(&st, y,
        &b_emlrtMCI), "str2double");
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }
}
void drr_151213_XRayInParam(const emlrtStack *sp, const emxArray_boolean_T
  *voxel_data, const real_T voxel_size_mm[3], const real_T detector_dimensions[2],
  const real_T XRayIntrinsicParam[12], const real_T voxel_corner_min[3], const
  real_T T_carm[16], emxArray_real_T *projection)
{
  const mxArray *y;
  static const int32_T iv0[2] = { 1, 32 };

  const mxArray *m0;
  char_T cv0[32];
  int32_T i;
  static const char_T cv1[32] = { 'v', 'o', 'x', 'e', 'l', '_', 'd', 'a', 't',
    'a', ' ', 'm', 'u', 's', 't', ' ', 'b', 'e', ' ', '3', '-', 'd', 'i', 'm',
    'e', 'n', 's', 'i', 'o', 'n', 'a', 'l' };

  int32_T i0;
  real_T pixel_size_mm_h;
  real_T pixel_size_mm_w;
  uint32_T voxDim[3];
  real_T voxPlanes__max[3];
  real_T source[3];
  real_T pixel_size_mmel_wn[3];
  real_T pixel_size_mmel_hn[3];
  real_T corner[3];
  int32_T ih;
  int32_T iw;
  real_T tstep[3];
  real_T tnext[3];
  real_T pixel_point_mm[3];
  real_T ray_source2pixel[3];
  real_T b_voxPlanes__max[3];
  real_T b_ray_source2pixel[3];
  real_T t_plane_min[3];
  real_T t_plane_max[3];
  real_T tmax;
  int32_T pixel_size_mmIntensity;
  boolean_T exitg8;
  boolean_T exitg7;
  boolean_T exitg6;
  real_T t_larger[4];
  real_T temp;
  boolean_T exitg5;
  boolean_T exitg4;
  boolean_T exitg3;
  real_T t_smaller[4];
  int32_T itmp;
  boolean_T exitg2;
  boolean_T exitg1;
  real_T iz;
  real_T tx;
  real_T ty;
  real_T tz;
  int32_T i1;
  int32_T i2;
  int32_T i3;
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;

  /* % Modificiation Notes */
  /*  15.12.04 */
  /*           - Release 기존의 파일을 참고로 하여 고성영이 수정하였음.  */
  /*           - DRR을 완벽하게 하지 않고, voxel에 한점이라도 만나면 on으로 계산함 */
  /*           - 계산속도가 향상되었음 */
  /*           - 젬스에 있는 X-ray와 테스트하여 검증하였음 */
  /*  15 12 13 : The function input has been changed to utilize the x-ray */
  /*             intrinsic parameter provided by GEMSS  % 151213 kosy */
  /* %function [projection] = drr (voxel_data, voxel_size_mm, detector_dimensions, pixel_size_mm, isocenter_mm, cbct_angles_deg) */
  /* Creates a 2D projection at each cbct_angle of voxel_data. the projection */
  /* axis is defined by the isocenter to which the source and center of */
  /* the detector are aligned. This simulation assumes standard Cone Beam CT */
  /* geometry (source to isocenter distance is 100 cm and source to detector */
  /* distance is 150cm). */
  /*  */
  /* voxel_data: must be a 3 dimensional matrix (typically of CT data) */
  /* voxel_size_mm: a 3 element vector listing the size (in mm) of the voxels */
  /*                along each dimension */
  /* detector_dimension: a 2 element vector listing the dimensions (number of */
  /*                     pixels) in each dimension (u,v) */
  /* pixel_size_mm: a number defining the height and width of each pixel */
  /*                (assumes square pixel) */
  /* isocenter_mm: a 3 element vector pointing from the origin (corner) of the */
  /*               matrix element(1,1,1) to the isocenter */
  /* cbct_angles_deg: a list of angles to generate projections */
  /*  */
  /* Retrun Variable */
  /* projection: a 3D matrix with the 3rd dimension representing the angle of */
  /* roatation */
  /*  */
  /* { */
  /*  Author: Michael M. Folkerts [email protected] */
  /*  Institution: UCSD Physics, UTSW Radiation Oncology */
  /*  Updated: 2014-July. */
  /*  Notes: Siddon's Incremental algorithm | modified to read in 3D matlab matrix | Simplified Input | No guarantees!! */
  /*  */
  /*  References:  */
  /*  R.L. Siddon, */
  /*  "Fast calculation of the exact radiological path for a three-dimensional CT */
  /*  array," Medical Physics 12, 252-255 (1985). */
  /*  */
  /*  F. Jacobs, E. Sundermann, B. De Sutter, M. Christiaens and I. Lemahieu, */
  /*  "A fast algorithm to calculate the exact radiological path through a pixel_size_mmel or voxel space," */
  /*  Journal of Computing and Information Technology 6, 89-94 (1998). */
  /*   */
  /*  G. Han, Z. Liang and J. You, */
  /*  "A fast ray tracing technique for TCT and ECT studies," */
  /*  IEEE Medical Imaging Conference 1999. */
  /* } */
  /* function [projection] = drr_good_151204 (voxel_data, voxel_size_mm, detector_dimensions, pixel_size_mm, voxel_corner_min, T_carm)  */
  /*  if(0) */
  /*      voxel_data = OUTPUTgrid; */
  /*      voxel_size_mm = voxel_size; */
  /*      detector_dimensions = detector_dimension; */
  /*      pixel_size_mm = pixel_size; */
  /*      isocenter_mm = isocenter; */
  /*      T_carm: Transformation matrix of C-arm (that is set at the middle of */
  /*              detector & source) with respect to Voxel coordinates */
  /* tic; */
  /* this will verify the size: */
  if (eml_ndims_varsized(*(int32_T (*)[3])voxel_data->size) != 3) {
    st.site = &emlrtRSI;
    y = NULL;
    m0 = emlrtCreateCharArray(2, iv0);
    for (i = 0; i < 32; i++) {
      cv0[i] = cv1[i];
    }

    emlrtInitCharArrayR2013a(&st, 32, m0, cv0);
    emlrtAssign(&y, m0);
    b_st.site = &b_emlrtRSI;
    error(&b_st, y, &emlrtMCI);
  }

  /* constants: */
  /* .0001; */
  /* .0001; */
  /* sounce to imager(detector) distance */
  /* source to axis distance %% RRI set the coordinate at the middle between source and the detector */
  /* initialize memory for speed: */
  i0 = projection->size[0] * projection->size[1];
  pixel_size_mm_h = emlrtNonNegativeCheckFastR2012b(detector_dimensions[0],
    &b_emlrtDCI, sp);
  projection->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_h,
    &emlrtDCI, sp);
  pixel_size_mm_h = emlrtNonNegativeCheckFastR2012b(detector_dimensions[1],
    &d_emlrtDCI, sp);
  projection->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_h,
    &c_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)projection, i0, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  pixel_size_mm_h = emlrtNonNegativeCheckFastR2012b(detector_dimensions[0],
    &b_emlrtDCI, sp);
  pixel_size_mm_w = emlrtNonNegativeCheckFastR2012b(detector_dimensions[1],
    &d_emlrtDCI, sp);
  i = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_h, &emlrtDCI, sp) *
    (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_w, &c_emlrtDCI, sp);
  for (i0 = 0; i0 < i; i0++) {
    projection->data[i0] = 0.0;
  }

  for (i0 = 0; i0 < 3; i0++) {
    voxDim[i0] = (uint32_T)voxel_data->size[i0];
  }

  /* [size(voxel_data,1), size(voxel_data,2), size(voxel_data,3)]; */
  /* voxDim_x = voxDim(1); */
  /* voxDim_y = voxDim(2); */
  /* voxDim_z = voxDim(3); */
  /* difine voxel boundaries: */
  /* vector from origin to source */
  /* vector from origin to CENTER of detector */
  /* extract the key information from the intrinsic parameters   % 151213 kosy modi */
  pixel_size_mm_h = 1105.0 / XRayIntrinsicParam[0];
  pixel_size_mm_w = 1105.0 / XRayIntrinsicParam[4];

  /* vector pointing left, parallel to detector */
  /* define incremental vectors: */
  /* define upper lefthand corner of detector: */
  /* corner = detector + ( center_pixel_w*pixel_size_mmel.wn + center_pixel_h*pixel_size_mmel.hn ); */
  for (i = 0; i < 3; i++) {
    voxPlanes__max[i] = voxel_corner_min[i] + voxel_size_mm[i] * (real_T)
      voxDim[i];

    /* define up: */
    /* up = [0,0,1]; */
    /*  width of projection image */
    /*  height of projection image */
    /*  direction from the detector to the source */
    /* end initialization timer: */
    /* init_time = toc */
    /* start tracing timer: */
    /* tic; */
    source[i] = 552.5 * T_carm[4 + i] + T_carm[12 + i];

    /* define pixel_size_mmel vectors: */
    /*  length of pixel_size_mmel */
    pixel_size_mmel_wn[i] = -pixel_size_mm_w * T_carm[i];
    pixel_size_mmel_hn[i] = -pixel_size_mm_h * T_carm[8 + i];
    corner[i] = (-552.5 * T_carm[4 + i] + T_carm[12 + i]) +
      (detector_dimensions[0] * (pixel_size_mm_w * T_carm[i]) +
       detector_dimensions[1] * (pixel_size_mm_h * T_carm[8 + i])) / 2.0;
  }

  emlrtForLoopVectorCheckR2012b(1.0, 1.0, detector_dimensions[0], mxDOUBLE_CLASS,
                                (int32_T)detector_dimensions[0], &d_emlrtRTEI,
    sp);
  ih = 1;
  while (ih - 1 <= (int32_T)detector_dimensions[0] - 1) {
    /* if(mod(ih,100)==0),fprintf('height:\t%i...\n',ih);end */
    emlrtForLoopVectorCheckR2012b(1.0, 1.0, detector_dimensions[1],
      mxDOUBLE_CLASS, (int32_T)detector_dimensions[1], &c_emlrtRTEI, sp);
    iw = 1;
    while (iw - 1 <= (int32_T)detector_dimensions[1] - 1) {
      /* pixel_point_mm = corner + (ih-1)*pixel_size_mmel.hp + (iw-1)*pixel_size_mmel.wp; %ray end point */
      /* ray to be traced */
      /*  find parametrized (t) voxel plane (min or max) intersections: */
      /*  PLANE = P1 + t(P2-P1) */
      /*  SK added */
      /*  t_x = (i-x1) / (x2-x1), t_y = (j-y1) / (y2-y1), t_z = (k-z1) / (z2-z1) */
      for (i = 0; i < 3; i++) {
        pixel_size_mm_h = (corner[i] + ((1.0 + (real_T)(ih - 1)) - 1.0) *
                           pixel_size_mmel_hn[i]) + ((1.0 + (real_T)(iw - 1)) -
          1.0) * pixel_size_mmel_wn[i];

        /* ray end point */
        pixel_size_mm_w = pixel_size_mm_h - source[i];
        tstep[i] = voxel_corner_min[i] - source[i];
        tnext[i] = pixel_size_mm_w + 2.2250738585072014E-308;
        b_voxPlanes__max[i] = voxPlanes__max[i] - source[i];
        b_ray_source2pixel[i] = pixel_size_mm_w + 2.2250738585072014E-308;
        pixel_point_mm[i] = pixel_size_mm_h;
        ray_source2pixel[i] = pixel_size_mm_w;
      }

      rdivide(tstep, tnext, t_plane_min);
      rdivide(b_voxPlanes__max, b_ray_source2pixel, t_plane_max);

      /*  compute (parametric) intersection values */
      /*  tmin = max { min{tx(0), tx(Nx)}, min{ty(0), ty(Ny)], min{tz(0), tz(Nz)}, 0.0 } */
      /*  tmax = min { max{tx(0), tx(Nx)}, max{ty(0), ty(Ny)], max{tz(0), tz(Nz)}, 1.0 } */
      /* t_larger = [ max([t_plane_min(1), t_plane_max(1)]), max([t_plane_min(2), t_plane_max(2)]), max([t_plane_min(3), t_plane_max(3)]), 1.0 ]; */
      /* t_smaller = [ min([t_plane_min(1), t_plane_max(1)]), min([t_plane_min(2), t_plane_max(2)]), min([t_plane_min(3), t_plane_max(3)]), 0.0 ]; */
      i = 1;
      tmax = t_plane_min[0];
      if (muDoubleScalarIsNaN(t_plane_min[0])) {
        pixel_size_mmIntensity = 2;
        exitg8 = false;
        while ((!exitg8) && (pixel_size_mmIntensity < 3)) {
          i = 2;
          if (!muDoubleScalarIsNaN(t_plane_max[0])) {
            tmax = t_plane_max[0];
            exitg8 = true;
          } else {
            pixel_size_mmIntensity = 3;
          }
        }
      }

      if ((i < 2) && (t_plane_max[0] > tmax)) {
        tmax = t_plane_max[0];
      }

      i = 1;
      pixel_size_mm_h = t_plane_min[1];
      if (muDoubleScalarIsNaN(t_plane_min[1])) {
        pixel_size_mmIntensity = 2;
        exitg7 = false;
        while ((!exitg7) && (pixel_size_mmIntensity < 3)) {
          i = 2;
          if (!muDoubleScalarIsNaN(t_plane_max[1])) {
            pixel_size_mm_h = t_plane_max[1];
            exitg7 = true;
          } else {
            pixel_size_mmIntensity = 3;
          }
        }
      }

      if ((i < 2) && (t_plane_max[1] > pixel_size_mm_h)) {
        pixel_size_mm_h = t_plane_max[1];
      }

      i = 1;
      pixel_size_mm_w = t_plane_min[2];
      if (muDoubleScalarIsNaN(t_plane_min[2])) {
        pixel_size_mmIntensity = 2;
        exitg6 = false;
        while ((!exitg6) && (pixel_size_mmIntensity < 3)) {
          i = 2;
          if (!muDoubleScalarIsNaN(t_plane_max[2])) {
            pixel_size_mm_w = t_plane_max[2];
            exitg6 = true;
          } else {
            pixel_size_mmIntensity = 3;
          }
        }
      }

      if ((i < 2) && (t_plane_max[2] > pixel_size_mm_w)) {
        pixel_size_mm_w = t_plane_max[2];
      }

      t_larger[0] = tmax;
      t_larger[1] = pixel_size_mm_h;
      t_larger[2] = pixel_size_mm_w;
      t_larger[3] = 1.0;
      i = 1;
      temp = t_plane_min[0];
      if (muDoubleScalarIsNaN(t_plane_min[0])) {
        pixel_size_mmIntensity = 2;
        exitg5 = false;
        while ((!exitg5) && (pixel_size_mmIntensity < 3)) {
          i = 2;
          if (!muDoubleScalarIsNaN(t_plane_max[0])) {
            temp = t_plane_max[0];
            exitg5 = true;
          } else {
            pixel_size_mmIntensity = 3;
          }
        }
      }

      if ((i < 2) && (t_plane_max[0] < temp)) {
        temp = t_plane_max[0];
      }

      i = 1;
      pixel_size_mm_h = t_plane_min[1];
      if (muDoubleScalarIsNaN(t_plane_min[1])) {
        pixel_size_mmIntensity = 2;
        exitg4 = false;
        while ((!exitg4) && (pixel_size_mmIntensity < 3)) {
          i = 2;
          if (!muDoubleScalarIsNaN(t_plane_max[1])) {
            pixel_size_mm_h = t_plane_max[1];
            exitg4 = true;
          } else {
            pixel_size_mmIntensity = 3;
          }
        }
      }

      if ((i < 2) && (t_plane_max[1] < pixel_size_mm_h)) {
        pixel_size_mm_h = t_plane_max[1];
      }

      i = 1;
      pixel_size_mm_w = t_plane_min[2];
      if (muDoubleScalarIsNaN(t_plane_min[2])) {
        pixel_size_mmIntensity = 2;
        exitg3 = false;
        while ((!exitg3) && (pixel_size_mmIntensity < 3)) {
          i = 2;
          if (!muDoubleScalarIsNaN(t_plane_max[2])) {
            pixel_size_mm_w = t_plane_max[2];
            exitg3 = true;
          } else {
            pixel_size_mmIntensity = 3;
          }
        }
      }

      if ((i < 2) && (t_plane_max[2] < pixel_size_mm_w)) {
        pixel_size_mm_w = t_plane_max[2];
      }

      t_smaller[0] = temp;
      t_smaller[1] = pixel_size_mm_h;
      t_smaller[2] = pixel_size_mm_w;
      t_smaller[3] = 0.0;
      i = 1;
      itmp = 0;
      if (muDoubleScalarIsNaN(temp)) {
        pixel_size_mmIntensity = 1;
        exitg2 = false;
        while ((!exitg2) && (pixel_size_mmIntensity + 1 < 5)) {
          i = pixel_size_mmIntensity + 1;
          if (!muDoubleScalarIsNaN(t_smaller[pixel_size_mmIntensity])) {
            temp = t_smaller[pixel_size_mmIntensity];
            itmp = pixel_size_mmIntensity;
            exitg2 = true;
          } else {
            pixel_size_mmIntensity++;
          }
        }
      }

      if (i < 4) {
        while (i + 1 < 5) {
          if (t_smaller[i] > temp) {
            temp = t_smaller[i];
            itmp = i;
          }

          i++;
        }
      }

      i = 1;
      if (muDoubleScalarIsNaN(tmax)) {
        pixel_size_mmIntensity = 2;
        exitg1 = false;
        while ((!exitg1) && (pixel_size_mmIntensity < 5)) {
          i = pixel_size_mmIntensity;
          if (!muDoubleScalarIsNaN(t_larger[pixel_size_mmIntensity - 1])) {
            tmax = t_larger[pixel_size_mmIntensity - 1];
            exitg1 = true;
          } else {
            pixel_size_mmIntensity++;
          }
        }
      }

      if (i < 4) {
        while (i + 1 < 5) {
          if (t_larger[i] < tmax) {
            tmax = t_larger[i];
          }

          i++;
        }
      }

      for (i0 = 0; i0 < 3; i0++) {
        pixel_point_mm[i0] = (real_T)(pixel_point_mm[i0] < source[i0]) * -2.0 +
          1.0;
      }

      if (temp < tmax) {
        /*  if ray intersects volume */
        /* find index for each dimension: */
        for (i = 0; i < 3; i++) {
          pixel_size_mm_h = muDoubleScalarFloor((((ray_source2pixel[i] * temp +
            source[i]) - voxel_corner_min[i]) + 2.2250738585072014E-308) /
            voxel_size_mm[i]);

          /* (parametric) intersection values... */
          /* makes 0 or 1 */
          tnext[i] = (voxel_corner_min[i] + ((pixel_size_mm_h +
            (pixel_point_mm[i] + 1.0) / 2.0) * voxel_size_mm[i] - source[i])) /
            (ray_source2pixel[i] + 2.2250738585072014E-308);

          /*  parametric value for next plane intersection */
          tstep[i] = muDoubleScalarAbs(voxel_size_mm[i] / (ray_source2pixel[i] +
            2.2250738585072014E-308));
          t_plane_min[i] = pixel_size_mm_h;
        }

        /*  parametric step size */
        /* address special cases... */
        if (temp == t_plane_max[emlrtDynamicBoundsCheckFastR2012b(itmp + 1, 1, 3,
             &c_emlrtBCI, sp) - 1]) {
          /* if intersection is a "max" plane */
          t_plane_min[itmp] = (real_T)voxDim[itmp] - 1.0;
          tnext[itmp] = temp + tstep[itmp];

          /* next plane crossing */
        } else {
          t_plane_min[itmp] = 0.0;
          tnext[itmp] = temp + tstep[itmp];

          /* next plane crossing */
        }

        /*  voxel index values(add one for matlab): */
        pixel_size_mm_h = t_plane_min[0] + 1.0;
        pixel_size_mm_w = t_plane_min[1] + 1.0;
        iz = t_plane_min[2] + 1.0;
        tx = tnext[0];
        ty = tnext[1];
        tz = tnext[2];
        pixel_size_mmIntensity = 0;

        /* uncomment to generate P-matrix: */
        /* pixel_size_mmNum = 1; */
        /* len = norm(ray_source2pixel); % ray length */
        while ((temp + 0.0001 < tmax) && (!(pixel_size_mm_h * pixel_size_mm_w *
                 iz == 0.0))) {
          if ((tx < ty) && (tx < tz)) {
            /*  실제 DRR을 그리지 않고, 한점이라도 지나면 해당 점에 포함시킴 */
            i0 = voxel_data->size[0];
            i = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_h,
              &k_emlrtDCI, sp);
            itmp = voxel_data->size[1];
            i1 = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_w,
              &l_emlrtDCI, sp);
            i2 = voxel_data->size[2];
            i3 = (int32_T)emlrtIntegerCheckFastR2012b(iz, &m_emlrtDCI, sp);
            if (voxel_data->data[((emlrtDynamicBoundsCheckFastR2012b(i, 1, i0,
                   &j_emlrtBCI, sp) + voxel_data->size[0] *
                                   (emlrtDynamicBoundsCheckFastR2012b(i1, 1,
                    itmp, &k_emlrtBCI, sp) - 1)) + voxel_data->size[0] *
                                  voxel_data->size[1] *
                                  (emlrtDynamicBoundsCheckFastR2012b(i3, 1, i2,
                   &l_emlrtBCI, sp) - 1)) - 1]) {
              pixel_size_mmIntensity = 255;
              tmax = rtMinusInf;
            }

            temp = tx;
            tx += tstep[0];
            pixel_size_mm_h += pixel_point_mm[0];
          } else if (ty < tz) {
            /*  실제 DRR을 그리지 않고, 한점이라도 지나면 해당 점에 포함시킴 */
            i0 = voxel_data->size[0];
            i = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_h,
              &h_emlrtDCI, sp);
            itmp = voxel_data->size[1];
            i1 = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_w,
              &i_emlrtDCI, sp);
            i2 = voxel_data->size[2];
            i3 = (int32_T)emlrtIntegerCheckFastR2012b(iz, &j_emlrtDCI, sp);
            if (voxel_data->data[((emlrtDynamicBoundsCheckFastR2012b(i, 1, i0,
                   &g_emlrtBCI, sp) + voxel_data->size[0] *
                                   (emlrtDynamicBoundsCheckFastR2012b(i1, 1,
                    itmp, &h_emlrtBCI, sp) - 1)) + voxel_data->size[0] *
                                  voxel_data->size[1] *
                                  (emlrtDynamicBoundsCheckFastR2012b(i3, 1, i2,
                   &i_emlrtBCI, sp) - 1)) - 1]) {
              pixel_size_mmIntensity = 255;
              tmax = rtMinusInf;
            }

            temp = ty;
            ty += tstep[1];
            pixel_size_mm_w += pixel_point_mm[1];
          } else {
            /*  실제 DRR을 그리지 않고, 한점이라도 지나면 해당 점에 포함시킴 */
            i0 = voxel_data->size[0];
            i = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_h,
              &e_emlrtDCI, sp);
            itmp = voxel_data->size[1];
            i1 = (int32_T)emlrtIntegerCheckFastR2012b(pixel_size_mm_w,
              &f_emlrtDCI, sp);
            i2 = voxel_data->size[2];
            i3 = (int32_T)emlrtIntegerCheckFastR2012b(iz, &g_emlrtDCI, sp);
            if (voxel_data->data[((emlrtDynamicBoundsCheckFastR2012b(i, 1, i0,
                   &d_emlrtBCI, sp) + voxel_data->size[0] *
                                   (emlrtDynamicBoundsCheckFastR2012b(i1, 1,
                    itmp, &e_emlrtBCI, sp) - 1)) + voxel_data->size[0] *
                                  voxel_data->size[1] *
                                  (emlrtDynamicBoundsCheckFastR2012b(i3, 1, i2,
                   &f_emlrtBCI, sp) - 1)) - 1]) {
              pixel_size_mmIntensity = 255;
              tmax = rtMinusInf;
            }

            temp = tz;
            tz += tstep[2];
            iz += pixel_point_mm[2];
          }

          emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
        }

        /* end while */
        i0 = projection->size[0];
        i = projection->size[1];
        projection->data[(emlrtDynamicBoundsCheckFastR2012b(ih, 1, i0,
          &m_emlrtBCI, sp) + projection->size[0] *
                          (emlrtDynamicBoundsCheckFastR2012b(iw, 1, i,
          &n_emlrtBCI, sp) - 1)) - 1] = pixel_size_mmIntensity;
      } else {
        /* if no intersections */
        i0 = projection->size[0];
        i = projection->size[1];
        projection->data[(emlrtDynamicBoundsCheckFastR2012b(ih, 1, i0, &emlrtBCI,
          sp) + projection->size[0] * (emlrtDynamicBoundsCheckFastR2012b(iw, 1,
          i, &b_emlrtBCI, sp) - 1)) - 1] = 0.0;
      }

      /* if intersections */
      /* uncomment to generate P-matrix: */
      /* rayCount = rayCount + 1; */
      iw++;
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    /* width */
    /* fprintf('\n'); */
    ih++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  /* height */
  /* uncomment to generate P-matrix: */
  /* matrix = matrix(1:mtxCount-1,:); */
  /* stop trace timer: */
  /* trace_time = toc */
  /* fprintf('\n') */
  /* function */
  /* } */
}
Пример #9
0
/* Function Definitions */
void CalculateC(const emlrtStack *sp, real_T N, real_T N0, const emxArray_real_T
                *t, const emxArray_real_T *gridX, emxArray_real_T *C)
{
  int32_T i9;
  real_T d5;
  real_T d6;
  int32_T loop_ub;
  int32_T i;
  int32_T k;
  int32_T b_C;
  real_T d7;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;

  /*  calculate the C matrix */
  /*  N- number of time points */
  /*  N0- number of space points */
  /*  t- time points */
  /*  gridX - grid for the space points */
  i9 = C->size[0] * C->size[1];
  d5 = 2.0 * N;
  d5 = emlrtNonNegativeCheckFastR2012b(d5, &ab_emlrtDCI, sp);
  C->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(d5, &y_emlrtDCI, sp);
  d5 = emlrtNonNegativeCheckFastR2012b(N0, &cb_emlrtDCI, sp);
  C->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(d5, &bb_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)C, i9, (int32_T)sizeof(real_T),
                    &d_emlrtRTEI);
  d5 = 2.0 * N;
  d5 = emlrtNonNegativeCheckFastR2012b(d5, &ab_emlrtDCI, sp);
  d6 = emlrtNonNegativeCheckFastR2012b(N0, &cb_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(d5, &y_emlrtDCI, sp) * (int32_T)
    emlrtIntegerCheckFastR2012b(d6, &bb_emlrtDCI, sp);
  for (i9 = 0; i9 < loop_ub; i9++) {
    C->data[i9] = 0.0;
  }

  emlrtForLoopVectorCheckR2012b(1.0, 1.0, N, mxDOUBLE_CLASS, (int32_T)N,
    &ec_emlrtRTEI, sp);
  i = 1;
  while (i - 1 <= (int32_T)N - 1) {
    /*  space */
    emlrtForLoopVectorCheckR2012b(1.0, 1.0, N0, mxDOUBLE_CLASS, (int32_T)N0,
      &fc_emlrtRTEI, sp);
    k = 0;
    while (k <= (int32_T)N0 - 1) {
      /*  time */
      d5 = 2.0 * (1.0 + (real_T)(i - 1));
      b_C = C->size[0];
      loop_ub = C->size[1];
      emlrtDynamicBoundsCheckFastR2012b(k + 1, 1, loop_ub, &mc_emlrtBCI, sp);
      i9 = t->size[1];
      st.site = &x_emlrtRSI;
      d6 = b_Ccoeff(&st, 1.0 + (real_T)k, 0.0, t->
                    data[emlrtDynamicBoundsCheckFastR2012b(i, 1, i9,
        &nc_emlrtBCI, sp) - 1], gridX);
      i9 = t->size[1];
      st.site = &y_emlrtRSI;
      d7 = b_Ccoeff(&st, 1.0 + (real_T)k, 1.0, t->
                    data[emlrtDynamicBoundsCheckFastR2012b(i, 1, i9,
        &oc_emlrtBCI, sp) - 1], gridX);
      i9 = (int32_T)(d5 + -1.0);
      C->data[(emlrtDynamicBoundsCheckFastR2012b(i9, 1, b_C, &pc_emlrtBCI, sp) +
               C->size[0] * k) - 1] = d6;
      i9 = (int32_T)d5;
      C->data[(emlrtDynamicBoundsCheckFastR2012b(i9, 1, b_C, &pc_emlrtBCI, sp) +
               C->size[0] * k) - 1] = d7;
      k++;
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    i++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }
}
Пример #10
0
/* Function Definitions */
void update_eq_17_state(const real_T xk_data[6250], const int32_T xk_size[2],
  const emxArray_real_T *vk, const real_T uk_data[250], const int32_T uk_size[1],
  real_T xkPlus_data[6250], int32_T xkPlus_size[2])
{
  int32_T i0;
  int32_T i1;
  uint8_T uv0[2];
  int32_T loop_ub;
  int32_T k;
  real_T xdot[17];
  real_T vk_data[100];
  real_T wi[3];
  real_T ai[3];
  real_T b_xk_data[25];
  real_T xk[9];
  real_T b_xk[3];
  real_T c_xk[3];
  real_T dv0[9];
  real_T B;
  real_T dv1[9];
  real_T d_xk[12];
  real_T dv2[12];
  static const int8_T b[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };

  real_T xkPlus[4];
  real_T dv3[9];
  real_T e_xk[9];
  real_T c_xk_data[25];
  real_T dv4[9];
  uint8_T tmp_data[25];
  int32_T iv0[1];
  static const int32_T iv1[1] = { 17 };

  real_T f_xk[17];

  /* xk: 17 x 2N+1, inertial position, inertial velocity, inertial quaternion, relative position, and relative quaternion */
  /* vk: 12 x 2N+1, noise on wi,(wj_est),ai,(vj_inertial) */
  /* uk[wi;ai;mag_i] : 9 x 2N+1 */
  /*  IMU measurements of me */
  emlrtVectorVectorIndexCheckR2012b(uk_size[0], 1, 1, 3, &l_emlrtECI,
    emlrtRootTLSGlobal);
  for (i0 = 0; i0 < 3; i0++) {
    i1 = 1 + i0;
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, uk_size[0], &j_emlrtBCI,
      emlrtRootTLSGlobal);
  }

  emlrtVectorVectorIndexCheckR2012b(uk_size[0], 1, 1, 3, &k_emlrtECI,
    emlrtRootTLSGlobal);
  for (i0 = 0; i0 < 3; i0++) {
    i1 = 4 + i0;
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, uk_size[0], &k_emlrtBCI,
      emlrtRootTLSGlobal);
  }

  for (i0 = 0; i0 < 2; i0++) {
    uv0[i0] = (uint8_T)xk_size[i0];
  }

  xkPlus_size[0] = uv0[0];
  xkPlus_size[1] = uv0[1];
  loop_ub = uv0[0] * uv0[1];
  for (i0 = 0; i0 < loop_ub; i0++) {
    xkPlus_data[i0] = 0.0;
  }

  k = 0;
  while (k <= xk_size[1] - 1) {
    i0 = (int32_T)(1.0 + (real_T)k);
    emlrtDynamicBoundsCheckFastR2012b(i0, 1, xk_size[1], &i_emlrtBCI,
      emlrtRootTLSGlobal);

    /*  hist position relative to my. My body frame */
    emlrtVectorVectorIndexCheckR2012b(xk_size[0], 1, 1, 3, &j_emlrtECI,
      emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 3; i0++) {
      i1 = 11 + i0;
      emlrtDynamicBoundsCheckFastR2012b(i1, 1, xk_size[0], &l_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    /*  my velocity */
    emlrtVectorVectorIndexCheckR2012b(xk_size[0], 1, 1, 3, &i_emlrtECI,
      emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 3; i0++) {
      i1 = 4 + i0;
      emlrtDynamicBoundsCheckFastR2012b(i1, 1, xk_size[0], &m_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    /*  my attitude */
    emlrtVectorVectorIndexCheckR2012b(xk_size[0], 1, 1, 4, &h_emlrtECI,
      emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      i1 = 7 + i0;
      emlrtDynamicBoundsCheckFastR2012b(i1, 1, xk_size[0], &n_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    /*  his attitude relative to mine. His body frame */
    emlrtVectorVectorIndexCheckR2012b(xk_size[0], 1, 1, 4, &g_emlrtECI,
      emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      i1 = 14 + i0;
      emlrtDynamicBoundsCheckFastR2012b(i1, 1, xk_size[0], &o_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    i0 = vk->size[1];
    i1 = (int32_T)(1.0 + (real_T)k);
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &h_emlrtBCI, emlrtRootTLSGlobal);
    memset(&xdot[0], 0, 17U * sizeof(real_T));
    i0 = vk->size[0];
    emlrtVectorVectorIndexCheckR2012b(i0, 1, 1, 3, &f_emlrtECI,
      emlrtRootTLSGlobal);
    i0 = vk->size[0];
    for (i1 = 0; i1 < 3; i1++) {
      loop_ub = 10 + i1;
      emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i0, &p_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    i0 = vk->size[0];
    emlrtVectorVectorIndexCheckR2012b(i0, 1, 1, 3, &e_emlrtECI,
      emlrtRootTLSGlobal);
    i0 = vk->size[0];
    for (i1 = 0; i1 < 3; i1++) {
      loop_ub = 4 + i1;
      emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i0, &q_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    i0 = vk->size[0];
    emlrtVectorVectorIndexCheckR2012b(i0, 1, 1, 3, &d_emlrtECI,
      emlrtRootTLSGlobal);
    i0 = vk->size[0];
    loop_ub = vk->size[0];
    for (i1 = 0; i1 < loop_ub; i1++) {
      vk_data[i1] = vk->data[i1 + vk->size[0] * k];
    }

    for (i1 = 0; i1 < 3; i1++) {
      loop_ub = 1 + i1;
      wi[i1] = uk_data[i1] + vk_data[emlrtDynamicBoundsCheckFastR2012b(loop_ub,
        1, i0, &r_emlrtBCI, emlrtRootTLSGlobal) - 1];
    }

    i0 = vk->size[0];
    emlrtVectorVectorIndexCheckR2012b(i0, 1, 1, 3, &c_emlrtECI,
      emlrtRootTLSGlobal);
    i0 = vk->size[0];
    loop_ub = vk->size[0];
    for (i1 = 0; i1 < loop_ub; i1++) {
      vk_data[i1] = vk->data[i1 + vk->size[0] * k];
    }

    for (i1 = 0; i1 < 3; i1++) {
      loop_ub = 7 + i1;
      ai[i1] = uk_data[i1 + 3] + vk_data[emlrtDynamicBoundsCheckFastR2012b
        (loop_ub, 1, i0, &s_emlrtBCI, emlrtRootTLSGlobal) - 1];
    }

    /*  cosine matrix */
    /* Tim Woodbury */
    /* modified for AERO 622 */
    /*  */
    /* [Y] = attpar(X,I,options) */
    /* Function to convert between attitude parametrizations */
    /*  */
    /* INPUTS: */
    /* X - matrix input of appropriate dimension (detailed later) */
    /* I - 2 x 1 indexing vector indicating the input (I(1)) and output (I(2)) */
    /*     attitude parametrizations, corresponding to the numbers in the section, */
    /*     "I/O SPECIFICATION PARAMETERS". */
    /* options - a data structure. Currently only allows output Euler angle */
    /*     sequence to be defined. Supported members are "seq" which should be a */
    /*     [3 x 1] vector describing the first, second, and third rotations in */
    /*     the desired output sequence. */
    /*  */
    /* OUTPUTS: */
    /* Y - output matrix of appropriate dimensions. */
    /*     All angles are in radians. */
    /*  */
    /* I/O SPECIFICATION PARAMETERS: */
    /* 1 - Direction cosine matrix, dimensions [3 x 3] */
    /* 2 - Euler principal axis/angle, [3 x 2]. [:,1] is the principal axis; */
    /*     [1,2] is the principal angle (rad). */
    /* 3 - 2-angle parametrization, [3 x 4] */
    /* 4 - Euler angle sequence, [3 x 2]. [:,1] are the rotation angles in radians,  */
    /*      and [2,1]-[2,2]-[2,3] is the rotation sequence.  */
    /*      [3-1-3] sequence is default for output. Other sequences may be specified */
    /*      by passing an optional data structure with a [3 x 1] member "seq" whose */
    /*      entries [a;b;c] correspond to the sequence a-b-c. Any input sequence */
    /*      may be used by specifying the second column of input appropriately. */
    /* 5 - Classical Rodrigues parameters [3 x 1] */
    /* 6 - quaternion [4 x 1]. The scalar part of the quaternion comes FIRST. */
    /* 7 - modified Rodrigues parameters [3 x 1] */
    /* 8 - exponential matrix, [3 x 3] */
    /* 9 - Cayley-Klein parameters, [2 x 2] */
    /* check if any options are passed */
    /* %check if output and inp are the same - if so do nothing */
    /* for each inp, convert to DCM */
    /* quaternion */
    /* disp('Input value specified as quaternion.'); */
    /* convert DCM to output form */
    /* DCM */
    /* disp('Output value specified as direction cosine matrix.'); */
    /*  time rate of my position */
    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      b_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    xk[0] = ((xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 7] -
              xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 8]) -
             xk_data[xk_size[0] * k + 9] * xk_data[xk_size[0] * k + 9]) +
      xk_data[xk_size[0] * k + 6] * xk_data[xk_size[0] * k + 6];
    xk[1] = 2.0 * (xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 8] +
                   xk_data[xk_size[0] * k + 9] * xk_data[xk_size[0] * k + 6]);
    xk[2] = 2.0 * (xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 9] -
                   xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 6]);
    xk[3] = 2.0 * (xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 8] -
                   xk_data[xk_size[0] * k + 9] * xk_data[xk_size[0] * k + 6]);
    xk[4] = ((xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 8] -
              xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 7]) -
             xk_data[xk_size[0] * k + 9] * xk_data[xk_size[0] * k + 9]) +
      xk_data[xk_size[0] * k + 6] * xk_data[xk_size[0] * k + 6];
    xk[5] = 2.0 * (xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 9] +
                   xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 6]);
    xk[6] = 2.0 * (xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 9] +
                   xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 6]);
    xk[7] = 2.0 * (xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 9] -
                   xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 6]);
    xk[8] = ((xk_data[xk_size[0] * k + 9] * xk_data[xk_size[0] * k + 9] -
              xk_data[xk_size[0] * k + 7] * xk_data[xk_size[0] * k + 7]) -
             xk_data[xk_size[0] * k + 8] * xk_data[xk_size[0] * k + 8]) +
      xk_data[xk_size[0] * k + 6] * xk_data[xk_size[0] * k + 6];
    for (i0 = 0; i0 < 3; i0++) {
      b_xk[i0] = b_xk_data[i0 + 3];
    }

    for (i0 = 0; i0 < 3; i0++) {
      c_xk[i0] = 0.0;
      for (i1 = 0; i1 < 3; i1++) {
        c_xk[i0] += xk[i0 + 3 * i1] * b_xk[i1];
      }

      xdot[i0] = c_xk[i0];
    }

    /*  time rate of my velocity */
    /* returns the cross product matrix of the vector x */
    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      b_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    dv0[0] = 0.0;
    dv0[3] = -wi[2];
    dv0[6] = wi[1];
    dv0[1] = wi[2];
    dv0[4] = 0.0;
    dv0[7] = -wi[0];
    dv0[2] = -wi[1];
    dv0[5] = wi[0];
    dv0[8] = 0.0;
    for (i0 = 0; i0 < 3; i0++) {
      b_xk[i0] = b_xk_data[i0 + 3];
    }

    for (i0 = 0; i0 < 3; i0++) {
      B = 0.0;
      for (i1 = 0; i1 < 3; i1++) {
        B += dv0[i0 + 3 * i1] * b_xk[i1];
      }

      c_xk[i0] = ai[i0] - B;
    }

    for (i0 = 0; i0 < 3; i0++) {
      xdot[3 + i0] = c_xk[i0];
    }

    /*  time rate of my attitude */
    /*  A matrix for qin */
    /* returns the cross product matrix of the vector x */
    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      b_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    dv1[0] = 0.0;
    dv1[3] = -xk_data[xk_size[0] * k + 9];
    dv1[6] = xk_data[xk_size[0] * k + 8];
    dv1[1] = xk_data[xk_size[0] * k + 9];
    dv1[4] = 0.0;
    dv1[7] = -xk_data[xk_size[0] * k + 7];
    dv1[2] = -xk_data[xk_size[0] * k + 8];
    dv1[5] = xk_data[xk_size[0] * k + 7];
    dv1[8] = 0.0;
    for (i0 = 0; i0 < 3; i0++) {
      d_xk[i0 << 2] = -b_xk_data[i0 + 7];
      for (i1 = 0; i1 < 3; i1++) {
        d_xk[(i1 + (i0 << 2)) + 1] = xk_data[xk_size[0] * k + 6] * (real_T)b[i1
          + 3 * i0] + dv1[i1 + 3 * i0];
      }

      for (i1 = 0; i1 < 4; i1++) {
        dv2[i1 + (i0 << 2)] = 0.5 * d_xk[i1 + (i0 << 2)];
      }
    }

    for (i0 = 0; i0 < 4; i0++) {
      xkPlus[i0] = 0.0;
      for (i1 = 0; i1 < 3; i1++) {
        xkPlus[i0] += dv2[i0 + (i1 << 2)] * wi[i1];
      }

      xdot[6 + i0] = xkPlus[i0];
    }

    /*  relative attitude cosine matrix */
    /* Tim Woodbury */
    /* modified for AERO 622 */
    /*  */
    /* [Y] = attpar(X,I,options) */
    /* Function to convert between attitude parametrizations */
    /*  */
    /* INPUTS: */
    /* X - matrix input of appropriate dimension (detailed later) */
    /* I - 2 x 1 indexing vector indicating the input (I(1)) and output (I(2)) */
    /*     attitude parametrizations, corresponding to the numbers in the section, */
    /*     "I/O SPECIFICATION PARAMETERS". */
    /* options - a data structure. Currently only allows output Euler angle */
    /*     sequence to be defined. Supported members are "seq" which should be a */
    /*     [3 x 1] vector describing the first, second, and third rotations in */
    /*     the desired output sequence. */
    /*  */
    /* OUTPUTS: */
    /* Y - output matrix of appropriate dimensions. */
    /*     All angles are in radians. */
    /*  */
    /* I/O SPECIFICATION PARAMETERS: */
    /* 1 - Direction cosine matrix, dimensions [3 x 3] */
    /* 2 - Euler principal axis/angle, [3 x 2]. [:,1] is the principal axis; */
    /*     [1,2] is the principal angle (rad). */
    /* 3 - 2-angle parametrization, [3 x 4] */
    /* 4 - Euler angle sequence, [3 x 2]. [:,1] are the rotation angles in radians,  */
    /*      and [2,1]-[2,2]-[2,3] is the rotation sequence.  */
    /*      [3-1-3] sequence is default for output. Other sequences may be specified */
    /*      by passing an optional data structure with a [3 x 1] member "seq" whose */
    /*      entries [a;b;c] correspond to the sequence a-b-c. Any input sequence */
    /*      may be used by specifying the second column of input appropriately. */
    /* 5 - Classical Rodrigues parameters [3 x 1] */
    /* 6 - quaternion [4 x 1]. The scalar part of the quaternion comes FIRST. */
    /* 7 - modified Rodrigues parameters [3 x 1] */
    /* 8 - exponential matrix, [3 x 3] */
    /* 9 - Cayley-Klein parameters, [2 x 2] */
    /* check if any options are passed */
    /* %check if output and inp are the same - if so do nothing */
    /* for each inp, convert to DCM */
    /* quaternion */
    /* disp('Input value specified as quaternion.'); */
    /* convert DCM to output form */
    /* DCM */
    /* disp('Output value specified as direction cosine matrix.'); */
    /*  relative angular velocity in j frame */
    /*  A matrix for q_ji */
    /* returns the cross product matrix of the vector x */
    /*  time rate of relative attitude */
    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      b_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    dv3[0] = 0.0;
    dv3[3] = -xk_data[xk_size[0] * k + 16];
    dv3[6] = xk_data[xk_size[0] * k + 15];
    dv3[1] = xk_data[xk_size[0] * k + 16];
    dv3[4] = 0.0;
    dv3[7] = -xk_data[xk_size[0] * k + 14];
    dv3[2] = -xk_data[xk_size[0] * k + 15];
    dv3[5] = xk_data[xk_size[0] * k + 14];
    dv3[8] = 0.0;
    for (i0 = 0; i0 < 3; i0++) {
      d_xk[i0 << 2] = -b_xk_data[i0 + 14];
      for (i1 = 0; i1 < 3; i1++) {
        d_xk[(i1 + (i0 << 2)) + 1] = xk_data[xk_size[0] * k + 13] * (real_T)b[i1
          + 3 * i0] + dv3[i1 + 3 * i0];
      }
    }

    loop_ub = vk->size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      vk_data[i0] = vk->data[i0 + vk->size[0] * k];
    }

    e_xk[0] = ((xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 14] -
                xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k + 15]) -
               xk_data[xk_size[0] * k + 16] * xk_data[xk_size[0] * k + 16]) +
      xk_data[xk_size[0] * k + 13] * xk_data[xk_size[0] * k + 13];
    e_xk[3] = 2.0 * (xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 15]
                     + xk_data[xk_size[0] * k + 16] * xk_data[xk_size[0] * k +
                     13]);
    e_xk[6] = 2.0 * (xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 16]
                     - xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k +
                     13]);
    e_xk[1] = 2.0 * (xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 15]
                     - xk_data[xk_size[0] * k + 16] * xk_data[xk_size[0] * k +
                     13]);
    e_xk[4] = ((xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k + 15] -
                xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 14]) -
               xk_data[xk_size[0] * k + 16] * xk_data[xk_size[0] * k + 16]) +
      xk_data[xk_size[0] * k + 13] * xk_data[xk_size[0] * k + 13];
    e_xk[7] = 2.0 * (xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k + 16]
                     + xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k +
                     13]);
    e_xk[2] = 2.0 * (xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 16]
                     + xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k +
                     13]);
    e_xk[5] = 2.0 * (xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k + 16]
                     - xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k +
                     13]);
    e_xk[8] = ((xk_data[xk_size[0] * k + 16] * xk_data[xk_size[0] * k + 16] -
                xk_data[xk_size[0] * k + 14] * xk_data[xk_size[0] * k + 14]) -
               xk_data[xk_size[0] * k + 15] * xk_data[xk_size[0] * k + 15]) +
      xk_data[xk_size[0] * k + 13] * xk_data[xk_size[0] * k + 13];
    for (i0 = 0; i0 < 3; i0++) {
      for (i1 = 0; i1 < 4; i1++) {
        dv2[i1 + (i0 << 2)] = 0.5 * d_xk[i1 + (i0 << 2)];
      }
    }

    for (i0 = 0; i0 < 3; i0++) {
      B = 0.0;
      for (i1 = 0; i1 < 3; i1++) {
        B += e_xk[i0 + 3 * i1] * wi[i1];
      }

      c_xk[i0] = vk_data[i0 + 3] - B;
    }

    for (i0 = 0; i0 < 4; i0++) {
      xkPlus[i0] = 0.0;
      for (i1 = 0; i1 < 3; i1++) {
        xkPlus[i0] += dv2[i0 + (i1 << 2)] * c_xk[i1];
      }

      xdot[13 + i0] = xkPlus[i0];
    }

    /*  time rate of relative position */
    /* returns the cross product matrix of the vector x */
    loop_ub = vk->size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      vk_data[i0] = vk->data[i0 + vk->size[0] * k];
    }

    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      b_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      c_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    dv4[0] = 0.0;
    dv4[3] = -wi[2];
    dv4[6] = wi[1];
    dv4[1] = wi[2];
    dv4[4] = 0.0;
    dv4[7] = -wi[0];
    dv4[2] = -wi[1];
    dv4[5] = wi[0];
    dv4[8] = 0.0;
    for (i0 = 0; i0 < 3; i0++) {
      b_xk[i0] = c_xk_data[i0 + 10];
    }

    for (i0 = 0; i0 < 3; i0++) {
      B = 0.0;
      for (i1 = 0; i1 < 3; i1++) {
        B += dv4[i0 + 3 * i1] * b_xk[i1];
      }

      c_xk[i0] = (vk_data[i0 + 9] - b_xk_data[i0 + 3]) - B;
    }

    for (i0 = 0; i0 < 3; i0++) {
      xdot[10 + i0] = c_xk[i0];
    }

    emlrtSizeEqCheck1DFastR2012b(xk_size[0], 17, &b_emlrtECI, emlrtRootTLSGlobal);
    loop_ub = uv0[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      tmp_data[i0] = (uint8_T)i0;
    }

    i0 = uv0[1];
    i1 = (int32_T)(1.0 + (real_T)k);
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &g_emlrtBCI, emlrtRootTLSGlobal);
    iv0[0] = uv0[0];
    emlrtSubAssignSizeCheckR2012b(iv0, 1, iv1, 1, &emlrtECI, emlrtRootTLSGlobal);
    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      b_xk_data[i0] = xk_data[i0 + xk_size[0] * k];
    }

    loop_ub = xk_size[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      c_xk_data[i0] = b_xk_data[i0];
    }

    for (i0 = 0; i0 < 17; i0++) {
      f_xk[i0] = c_xk_data[i0] + Ts * xdot[i0];
    }

    loop_ub = uv0[0];
    for (i0 = 0; i0 < loop_ub; i0++) {
      xkPlus_data[tmp_data[i0] + uv0[0] * k] = f_xk[i0];
    }

    /* re-normalize */
    i0 = uv0[1];
    i1 = (int32_T)(1.0 + (real_T)k);
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &f_emlrtBCI, emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      i1 = uv0[0];
      loop_ub = 7 + i0;
      emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i1, &t_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    i0 = uv0[1];
    i1 = 1 + k;
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &e_emlrtBCI, emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      i1 = uv0[0];
      loop_ub = 7 + i0;
      xkPlus[i0] = xkPlus_data[(emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i1,
        &u_emlrtBCI, emlrtRootTLSGlobal) + uv0[0] * k) - 1];
    }

    B = norm(xkPlus);
    i0 = uv0[1];
    i1 = 1 + k;
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &d_emlrtBCI, emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      xkPlus[i0] = xkPlus_data[(i0 + uv0[0] * k) + 6] / B;
    }

    for (i0 = 0; i0 < 4; i0++) {
      i1 = uv0[0];
      loop_ub = 7 + i0;
      xkPlus_data[(emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i1, &v_emlrtBCI,
        emlrtRootTLSGlobal) + uv0[0] * k) - 1] = xkPlus[i0];
    }

    i0 = uv0[1];
    i1 = (int32_T)(1.0 + (real_T)k);
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &c_emlrtBCI, emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      i1 = uv0[0];
      loop_ub = 14 + i0;
      emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i1, &w_emlrtBCI,
        emlrtRootTLSGlobal);
    }

    i0 = uv0[1];
    i1 = 1 + k;
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &b_emlrtBCI, emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      i1 = uv0[0];
      loop_ub = 14 + i0;
      xkPlus[i0] = xkPlus_data[(emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i1,
        &x_emlrtBCI, emlrtRootTLSGlobal) + uv0[0] * k) - 1];
    }

    B = norm(xkPlus);
    i0 = uv0[1];
    i1 = 1 + k;
    emlrtDynamicBoundsCheckFastR2012b(i1, 1, i0, &emlrtBCI, emlrtRootTLSGlobal);
    for (i0 = 0; i0 < 4; i0++) {
      xkPlus[i0] = xkPlus_data[(i0 + uv0[0] * k) + 13] / B;
    }

    for (i0 = 0; i0 < 4; i0++) {
      i1 = uv0[0];
      loop_ub = 14 + i0;
      xkPlus_data[(emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i1, &y_emlrtBCI,
        emlrtRootTLSGlobal) + uv0[0] * k) - 1] = xkPlus[i0];
    }

    k++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal);
  }
}
Пример #11
0
/* Function Definitions */
real_T Dcoeff(const emlrtStack *sp, const emxArray_real_T *y, real_T j, const
              emxArray_real_T *x, real_T t, const emxArray_real_T *timePoints,
              const emxArray_real_T *f)
{
  real_T vals;
  emxArray_real_T *a;
  int32_T i11;
  int32_T unnamed_idx_1;
  emxArray_real_T *r4;
  int32_T i12;
  int32_T i13;
  int32_T i14;
  int32_T i15;
  int32_T i16;
  int32_T i17;
  int32_T i18;
  int32_T i19;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &a, 2, &e_emlrtRTEI, true);

  /*  Calculate the integral int_0^1(f(y,t_j)*A_{yj}(x,t)dy) by midpoint */
  /*  integration rule */
  /*  the spatial integration of all points y at time t_j */
  i11 = a->size[0] * a->size[1];
  a->size[0] = 1;
  emxEnsureCapacity(sp, (emxArray__common *)a, i11, (int32_T)sizeof(real_T),
                    &d_emlrtRTEI);
  unnamed_idx_1 = y->size[1];
  i11 = a->size[0] * a->size[1];
  a->size[1] = unnamed_idx_1;
  emxEnsureCapacity(sp, (emxArray__common *)a, i11, (int32_T)sizeof(real_T),
                    &d_emlrtRTEI);
  unnamed_idx_1 = y->size[1];
  for (i11 = 0; i11 < unnamed_idx_1; i11++) {
    a->data[i11] = 0.0;
  }

  emxInit_real_T(sp, &r4, 2, &d_emlrtRTEI, true);
  vals = 0.0;
  i11 = y->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, i11, &ib_emlrtBCI, sp);
  st.site = &q_emlrtRSI;
  b_Acoeff(&st, y->data[0], j, x, t, timePoints, r4);
  i11 = r4->size[1];
  emlrtSizeEqCheck1DFastR2012b(1, i11, &c_emlrtECI, sp);
  unnamed_idx_1 = y->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, unnamed_idx_1, &jb_emlrtBCI, sp);
  i11 = r4->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, i11, &kb_emlrtBCI, sp);
  a->data[0] = r4->data[0];
  unnamed_idx_1 = 2;
  while (unnamed_idx_1 - 2 <= y->size[1] - 2) {
    i11 = y->size[1];
    st.site = &r_emlrtRSI;
    b_Acoeff(&st, y->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1,
              i11, &mb_emlrtBCI, sp) - 1], j, x, t, timePoints, r4);
    i11 = r4->size[1];
    emlrtSizeEqCheck1DFastR2012b(1, i11, &d_emlrtECI, sp);
    i11 = r4->size[1];
    emlrtDynamicBoundsCheckFastR2012b(1, 1, i11, &lb_emlrtBCI, sp);
    i11 = a->size[1];
    a->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1, i11,
      &nb_emlrtBCI, sp) - 1] = r4->data[0];
    i11 = a->size[1];
    i12 = f->size[1];
    i13 = a->size[1];
    i14 = unnamed_idx_1 - 1;
    i15 = f->size[1];
    i16 = unnamed_idx_1 - 1;
    i17 = y->size[1];
    i18 = y->size[1];
    i19 = unnamed_idx_1 - 1;
    vals += 0.5 * (a->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1,
      i11, &ob_emlrtBCI, sp) - 1] * f->data[emlrtDynamicBoundsCheckFastR2012b
                   (unnamed_idx_1, 1, i12, &pb_emlrtBCI, sp) - 1] + a->
                   data[emlrtDynamicBoundsCheckFastR2012b(i14, 1, i13,
      &qb_emlrtBCI, sp) - 1] * f->data[emlrtDynamicBoundsCheckFastR2012b(i16, 1,
      i15, &rb_emlrtBCI, sp) - 1]) * (y->data[emlrtDynamicBoundsCheckFastR2012b
      (unnamed_idx_1, 1, i17, &sb_emlrtBCI, sp) - 1] - y->
      data[emlrtDynamicBoundsCheckFastR2012b(i19, 1, i18, &tb_emlrtBCI, sp) - 1]);
    unnamed_idx_1++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  emxFree_real_T(&r4);
  emxFree_real_T(&a);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
  return vals;
}
Пример #12
0
/* Function Definitions */
void generateOFDMSignal(const emlrtStack *sp, OFDMDemodulator_1 *iobj_0,
  OFDMDemodulator_1 *iobj_1, OFDMDemodulator_1 **hPreambleDemod,
  OFDMDemodulator_1 **hDataDemod, creal_T r[25600], d_struct_T *tx)
{
  OFDMModulator_1 hDataMod;
  OFDMModulator hPreambleMod;
  creal_T shortPreambleOFDM[64];
  int32_T i;
  creal_T completeShortPreambleOFDM[160];
  creal_T longPreambleOFDM[64];
  creal_T completeLongPreambleOFDM[160];
  real_T originalData[560];
  real_T x[560];
  int32_T ib;
  real_T b_originalData[560];
  commcodegen_CRCGenerator_6 hGen;
  real_T dataWithCRC[563];
  commcodegen_BPSKModulator_1 hMod;
  creal_T modData[563];
  real_T varargin_1[13];
  int32_T k;
  commcodegen_BPSKModulator_1 *obj;
  const mxArray *y;
  static const int32_T iv54[2] = { 1, 45 };

  const mxArray *m10;
  char_T cv58[45];
  static const char_T cv59[45] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'y',
    's', 't', 'e', 'm', ':', 'm', 'e', 't', 'h', 'o', 'd', 'C', 'a', 'l', 'l',
    'e', 'd', 'W', 'h', 'e', 'n', 'R', 'e', 'l', 'e', 'a', 's', 'e', 'd', 'C',
    'o', 'd', 'e', 'g', 'e', 'n' };

  const mxArray *b_y;
  static const int32_T iv55[2] = { 1, 4 };

  char_T cv60[4];
  static const char_T cv61[4] = { 's', 't', 'e', 'p' };

  const mxArray *c_y;
  static const int32_T iv56[2] = { 1, 51 };

  char_T cv62[51];
  static const char_T cv63[51] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'y',
    's', 't', 'e', 'm', ':', 'm', 'e', 't', 'h', 'o', 'd', 'C', 'a', 'l', 'l',
    'e', 'd', 'W', 'h', 'e', 'n', 'L', 'o', 'c', 'k', 'e', 'd', 'R', 'e', 'l',
    'e', 'a', 's', 'e', 'd', 'C', 'o', 'd', 'e', 'g', 'e', 'n' };

  const mxArray *d_y;
  static const int32_T iv57[2] = { 1, 5 };

  char_T cv64[5];
  static const char_T cv65[5] = { 's', 'e', 't', 'u', 'p' };

  static const int8_T value[8] = { 13, 1, 1, 1, 1, 1, 1, 1 };

  boolean_T anyInputSizeChanged;
  boolean_T exitg2;
  static const int8_T iv58[8] = { 13, 1, 1, 1, 1, 1, 1, 1 };

  creal_T varargout_1[13];
  creal_T b_modData[576];
  creal_T ofdmData[576];
  comm_PNSequence_5 hPN;
  comm_PNSequence_5 *b_obj;
  static const int8_T iv59[8] = { 1, 0, 0, 0, 1, 0, 0, 1 };

  static const int8_T iv60[7] = { 0, 0, 0, 0, 0, 0, 1 };

  int8_T pilot[12];
  uint8_T tmp;
  uint8_T tmp2;
  int8_T pilots[48];
  int32_T ia;
  real_T b_pilots[48];
  creal_T b_r[960];
  creal_T preambles[320];
  creal_T c_r[1280];
  OFDMDemodulator_1 *object;
  int8_T b_data[4];
  int32_T exitg1;
  int32_T exponent;
  boolean_T b2;
  int32_T i12;
  const mxArray *e_y;
  static const int32_T iv61[2] = { 1, 13 };

  char_T cv66[13];
  static const char_T cv67[13] = { 'c', 'o', 'm', 'm', ':', 'O', 'F', 'D', 'M',
    ':', 'x', 'x', 'x' };

  static const creal_T dcv3[53] = { { 0.0, 0.0 }, { 0.0, 0.0 }, { 1.0, 1.0 }, {
      0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { -1.0, -1.0 }, { 0.0, 0.0 }, {
      0.0, 0.0 }, { 0.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0,
      0.0 }, { -1.0, -1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { -1.0,
      -1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 0.0
    }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, {
      0.0, 0.0 }, { -1.0, -1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { -
      1.0, -1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 1.0, 1.0 }, { 0.0,
      0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 0.0 }, { 0.0, 0.0
    }, { 0.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, {
      1.0, 1.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } };

  static const int8_T iv62[53] = { 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1,
    1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 0, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1,
    -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1 };

  static const int8_T iv63[48] = { 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 35, 36,
    37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53 };

  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  emlrtStack f_st;
  emlrtStack g_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  e_st.prev = &d_st;
  e_st.tls = d_st.tls;
  f_st.prev = &e_st;
  f_st.tls = e_st.tls;
  g_st.prev = &f_st;
  g_st.tls = f_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInitStruct_OFDMModulator_1(sp, &hDataMod, &s_emlrtRTEI, TRUE);
  emxInitStruct_OFDMModulator(sp, &hPreambleMod, &t_emlrtRTEI, TRUE);

  /*  generateOFDMSignal: Generate OFDM signal based on the 802.11a standard. */
  /*  This function returns the time domain signal and a structure containing */
  /*  details about the signal itself.  This information is required by the */
  /*  receiver to operate correctly. */
  /* % System Parameters */
  /*  OFDM modulator FFT size */
  /*  Enable moving averages for estimates */
  /* 1e3 */
  /*  Message to transmit */
  /*  String holder */
  /* coder.varsize('payloadMessage', [1, 80], [0 1]); */
  /* payloadMessage = ''; */
  /* % Create Short Preamble */
  /*  % [-27:-17] */
  /*  % [-16:-1] */
  /*  % [0:15] */
  /*  [16:27] */
  /*  % Create modulator */
  /*  hPreambleMod = OFDMModulator(... */
  /*      'NumGuardBandCarriers', [6; 5],... */
  /*      'CyclicPrefixLength',   0,... */
  /*      'FFTLength' ,           FFTLength,... */
  /*      'NumSymbols',           1);     */
  /*  Create modulator */
  st.site = &lk_emlrtRSI;
  OFDMModulator_OFDMModulator(&hPreambleMod);

  /*  Modulate and scale */
  st.site = &mk_emlrtRSI;
  SystemCore_step(&st, &hPreambleMod, shortPreambleOFDM);
  st.site = &mk_emlrtRSI;
  for (i = 0; i < 64; i++) {
    shortPreambleOFDM[i].re *= 1.4719601443879744;
    shortPreambleOFDM[i].im *= 1.4719601443879744;
  }

  /*  Form 10 Short Preambles */
  memcpy(&completeShortPreambleOFDM[0], &shortPreambleOFDM[0], sizeof(creal_T) <<
         6);
  memcpy(&completeShortPreambleOFDM[64], &shortPreambleOFDM[0], sizeof(creal_T) <<
         6);
  memcpy(&completeShortPreambleOFDM[128], &shortPreambleOFDM[0], sizeof(creal_T)
         << 5);

  /* % Create Long Preamble */
  /*  Modulate */
  st.site = &nk_emlrtRSI;
  b_SystemCore_step(&st, &hPreambleMod, longPreambleOFDM);

  /*  Form 2 Long Preambles */
  memcpy(&completeLongPreambleOFDM[0], &longPreambleOFDM[32], sizeof(creal_T) <<
         5);
  memcpy(&completeLongPreambleOFDM[32], &longPreambleOFDM[0], sizeof(creal_T) <<
         6);
  memcpy(&completeLongPreambleOFDM[96], &longPreambleOFDM[0], sizeof(creal_T) <<
         6);

  /* % Generate Data */
  /*  Use string as message */
  st.site = &ok_emlrtRSI;
  b_OFDMletters2bits(&st, originalData);
  st.site = &pk_emlrtRSI;
  for (i = 0; i < 80; i++) {
    for (ib = 0; ib < 7; ib++) {
      x[ib + 7 * i] = originalData[i + 80 * ib];
    }
  }

  memcpy(&b_originalData[0], &x[0], 560U * sizeof(real_T));

  /*  Generate CRC */
  st.site = &qk_emlrtRSI;
  b_CRCGenerator_CRCGenerator(&hGen);
  st.site = &rk_emlrtRSI;
  e_SystemCore_step(&st, &hGen, b_originalData, dataWithCRC);

  /*  Add CRC */
  /*  Construct modulator for each subcarrier */
  st.site = &sk_emlrtRSI;
  BPSKModulator_BPSKModulator(&hMod);

  /*  BPSK */
  /*  Apply modulator for each subcarrier */
  st.site = &tk_emlrtRSI;
  f_SystemCore_step(&st, &hMod, dataWithCRC, modData);

  /*  Pad IFFT */
  st.site = &uk_emlrtRSI;
  b_st.site = &u_emlrtRSI;
  emlrtRandu(varargin_1, 13);
  for (k = 0; k < 13; k++) {
    b_st.site = &v_emlrtRSI;
    b_st.site = &v_emlrtRSI;
    c_st.site = &p_emlrtRSI;
    varargin_1[k] = muDoubleScalarFloor(varargin_1[k] * 2.0);
  }

  st.site = &uk_emlrtRSI;
  obj = &hMod;
  if (!obj->isReleased) {
  } else {
    y = NULL;
    m10 = mxCreateCharArray(2, iv54);
    for (i = 0; i < 45; i++) {
      cv58[i] = cv59[i];
    }

    emlrtInitCharArrayR2013a(&st, 45, m10, cv58);
    emlrtAssign(&y, m10);
    b_y = NULL;
    m10 = mxCreateCharArray(2, iv55);
    for (i = 0; i < 4; i++) {
      cv60[i] = cv61[i];
    }

    emlrtInitCharArrayR2013a(&st, 4, m10, cv60);
    emlrtAssign(&b_y, m10);
    b_st.site = &cb_emlrtRSI;
    c_error(&b_st, message(&b_st, y, b_y, &emlrtMCI), &emlrtMCI);
  }

  if (!obj->isInitialized) {
    b_st.site = &cb_emlrtRSI;
    if (!obj->isInitialized) {
    } else {
      c_y = NULL;
      m10 = mxCreateCharArray(2, iv56);
      for (i = 0; i < 51; i++) {
        cv62[i] = cv63[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 51, m10, cv62);
      emlrtAssign(&c_y, m10);
      d_y = NULL;
      m10 = mxCreateCharArray(2, iv57);
      for (i = 0; i < 5; i++) {
        cv64[i] = cv65[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 5, m10, cv64);
      emlrtAssign(&d_y, m10);
      c_st.site = &cb_emlrtRSI;
      c_error(&c_st, message(&c_st, c_y, d_y, &emlrtMCI), &emlrtMCI);
    }

    c_st.site = &cb_emlrtRSI;
    obj->isInitialized = TRUE;
    d_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    e_st.site = &db_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    e_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    e_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    for (i = 0; i < 8; i++) {
      obj->inputVarSize1[i] = (uint32_T)value[i];
    }

    e_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    e_st.site = &cb_emlrtRSI;
    e_st.site = &cb_emlrtRSI;
    f_st.site = &gg_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    e_st.site = &gg_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &gg_emlrtRSI;
    d_st.site = &gg_emlrtRSI;
    e_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &gg_emlrtRSI;
    e_st.site = NULL;
  }

  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  d_st.site = &gg_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  anyInputSizeChanged = FALSE;
  k = 0;
  exitg2 = FALSE;
  while ((exitg2 == FALSE) && (k < 8)) {
    if (obj->inputVarSize1[k] != (uint32_T)iv58[k]) {
      anyInputSizeChanged = TRUE;
      c_st.site = &cb_emlrtRSI;
      for (i = 0; i < 8; i++) {
        obj->inputVarSize1[i] = (uint32_T)value[i];
      }

      d_st.site = &db_emlrtRSI;
      exitg2 = TRUE;
    } else {
      k++;
    }
  }

  if (anyInputSizeChanged) {
    b_st.site = &cb_emlrtRSI;
    b_st.site = &cb_emlrtRSI;
  }

  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  d_st.site = &gg_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  d_Nondirect_stepImpl(obj, varargin_1, varargout_1);
  memcpy(&b_modData[0], &modData[0], 563U * sizeof(creal_T));
  memcpy(&b_modData[563], &varargout_1[0], 13U * sizeof(creal_T));

  /*  Calculate required data sizes for correct receiver operation */
  /*  Save desired message size */
  /*  Save number of transmitted frames */
  /*  Convert data into subcarrier streams */
  st.site = &vk_emlrtRSI;
  memcpy(&ofdmData[0], &b_modData[0], 576U * sizeof(creal_T));

  /*  Create Pilots */
  st.site = &wk_emlrtRSI;
  b_obj = &hPN;

  /* System object Constructor function: comm.PNSequence */
  b_obj->S0_isInitialized = FALSE;
  b_obj->S1_isReleased = FALSE;
  for (i = 0; i < 8; i++) {
    b_obj->P0_Polynomial[i] = (uint8_T)iv59[i];
  }

  for (i = 0; i < 7; i++) {
    b_obj->P1_IniState[i] = 1;
    b_obj->P2_Mask[i] = (uint8_T)iv60[i];
  }

  st.site = &xk_emlrtRSI;
  b_obj = &hPN;
  if (!b_obj->S0_isInitialized) {
    b_obj->S0_isInitialized = TRUE;
    if (b_obj->S1_isReleased) {
      emlrtErrorWithMessageIdR2012b(&st, &bc_emlrtRTEI,
        "MATLAB:system:runtimeMethodCalledWhenReleasedCodegen", 0);
    }

    b_st.site = NULL;
    b_st.site = NULL;

    /* System object Initialization function: comm.PNSequence */
    for (ib = 0; ib < 7; ib++) {
      b_obj->W0_shiftReg[ib] = b_obj->P1_IniState[ib];
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, &b_st);
    }
  }

  b_st.site = NULL;

  /* System object Outputs function: comm.PNSequence */
  for (ib = 0; ib < 12; ib++) {
    tmp = 0;
    for (i = 0; i < 7; i++) {
      tmp = (uint8_T)((uint32_T)tmp + (uint8_T)((uint32_T)b_obj->P0_Polynomial[i
        + 1] * b_obj->W0_shiftReg[i]));
    }

    tmp &= 1;
    tmp2 = 0;
    for (i = 0; i < 7; i++) {
      tmp2 = (uint8_T)((uint32_T)tmp2 + (uint8_T)((uint32_T)b_obj->W0_shiftReg[i]
        * b_obj->P2_Mask[i]));
    }

    pilot[ib] = (int8_T)(tmp2 & 1);
    for (i = 5; i > -1; i += -1) {
      b_obj->W0_shiftReg[i + 1] = b_obj->W0_shiftReg[i];
    }

    b_obj->W0_shiftReg[0U] = tmp;
  }

  /*  Create pilot */
  st.site = &yk_emlrtRSI;
  ib = 0;
  for (i = 0; i < 4; i++) {
    ia = 0;
    for (k = 0; k < 12; k++) {
      pilots[ib] = pilot[ia];
      b_st.site = &ng_emlrtRSI;
      ia++;
      b_st.site = &og_emlrtRSI;
      ib++;
    }
  }

  /*  Expand to all pilot tones */
  st.site = &al_emlrtRSI;
  for (i = 0; i < 12; i++) {
    for (ib = 0; ib < 4; ib++) {
      b_pilots[ib + (i << 2)] = 2.0 * (real_T)(pilots[i + 12 * ib] < 1) - 1.0;
    }
  }

  /*  Bipolar to unipolar */
  st.site = &bl_emlrtRSI;
  for (i = 0; i < 12; i++) {
    b_pilots[3 + (i << 2)] = -b_pilots[3 + (i << 2)];
  }

  /*  Invert last pilot */
  /*  Construct Modulator */
  st.site = &cl_emlrtRSI;
  b_OFDMModulator_OFDMModulator(&st, &hDataMod);

  /*  Modulate */
  st.site = &dl_emlrtRSI;
  d_SystemCore_step(&st, &hDataMod, ofdmData, b_pilots, b_r);

  /*  Add preambles to data */
  memcpy(&preambles[0], &completeShortPreambleOFDM[0], 160U * sizeof(creal_T));
  memcpy(&preambles[160], &completeLongPreambleOFDM[0], 160U * sizeof(creal_T));
  memcpy(&c_r[0], &preambles[0], 320U * sizeof(creal_T));
  memcpy(&c_r[320], &b_r[0], 960U * sizeof(creal_T));

  /*  Repeat frame */
  st.site = &el_emlrtRSI;
  ib = 0;
  for (i = 0; i < 20; i++) {
    ia = 0;
    for (k = 0; k < 1280; k++) {
      r[ib] = c_r[ia];
      b_st.site = &ng_emlrtRSI;
      ia++;
      b_st.site = &og_emlrtRSI;
      ib++;
    }
  }

  /*  Save Demodulator object data for receiver */
  /* hDataDemod = get(OFDMDemodulator(hDataMod)); */
  /* hPreambleDemod = get(OFDMDemodulator(hPreambleMod)); */
  st.site = &fl_emlrtRSI;
  object = iobj_0;
  *hDataDemod = object;
  b_st.site = &jj_emlrtRSI;
  object = *hDataDemod;
  c_st.site = &y_emlrtRSI;
  d_st.site = &bb_emlrtRSI;
  d_st.site = &bb_emlrtRSI;
  object->isInitialized = FALSE;
  object->isReleased = FALSE;
  e_st.site = &cb_emlrtRSI;
  f_st.site = &db_emlrtRSI;
  e_st.site = &cb_emlrtRSI;
  f_st.site = &db_emlrtRSI;
  c_st.site = &y_emlrtRSI;
  c_st.site = &ab_emlrtRSI;
  b_st.site = &kj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &lj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &mj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &nj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &oj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &pj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &qj_emlrtRSI;
  c_st.site = &db_emlrtRSI;

  /* OFDMBase Base object for OFDMModulator and OFDMDemodulator System objects */
  /*  Copyright 2013 The MathWorks, Inc. */
  /* FFTLength FFT length */
  /*  Specify the IFFT length. This property can be set to an integer */
  /*  scalar. The value must be a power of two. The default value of */
  /*  this property is 64. */
  /* CyclicPrefixLength Cyclic prefix length */
  /*  Specify the cyclic prefix length. This property can be set to a */
  /*  non-negative interher scalar. The default value of this property is 16. */
  /* NumGuardBandCarriers Number of guard bands */
  /*  Specify the lower and upper guard bands in frequency domain.This */
  /*  property can be set to a non-nagative two-element vector.  */
  /*  The default setting of this property is [6 5]. */
  /* NumSymbols Number of OFDM symbols */
  /*  Specify the number of OFDM symbols at the output. The default value  */
  /*  of this property is 1. */
  /* PilotCarrierIndices Pilot subcarrier indices */
  /*  Specify the locations where pilots are to be inserted. You can */
  /*  set this property to a numeric scalar, column vector, matrix, or */
  /*  3-D array. The defalut value of the property is [-21; -7; 7; 21]. */
  /*  Nontunable ideally */
  /*  Constructor */
  /*      validateattributes(fftLen, {'numeric'}, ... */
  /*          {'real','scalar','integer','finite','>=',8}, ... */
  /*          [class(obj) '.' propName], propName);   */
  /*      validateattributes(CPLen, {'numeric'}, ... */
  /*          {'real','row','integer','nonnegative','finite'}, ... */
  /*          [class(obj) '.' propName], propName);   */
  /*      validateattributes(guardBands, {'numeric'}, ... */
  /*          {'real','integer','nonnegative','finite','size', [2, 1]}, ... */
  /*          [class(obj) '.' propName], propName);   */
  /*      validateattributes(numSym, {'numeric'}, ... */
  /*          {'real','scalar','integer','positive','finite'}, ... */
  /*          [class(obj) '.' propName], propName);   */
  /*      validateattributes(pilotIdx, {'numeric'}, ... */
  /*          {'real','integer','positive','finite','3d'}, ... */
  /*          [class(obj) '.' propName], propName);   */
  /*  Check the 3rd dimension for numTx */
  d_st.site = &uh_emlrtRSI;
  e_st.site = &vh_emlrtRSI;
  for (k = 0; k < 4; k++) {
    b_data[k] = (int8_T)(12 + 14 * k);
  }

  f_st.site = &mi_emlrtRSI;
  i = 0;
  f_st.site = &ki_emlrtRSI;
  f_st.site = &ji_emlrtRSI;
  k = 1;
  while (k <= 4) {
    ib = b_data[k - 1];
    do {
      exitg1 = 0;
      f_st.site = &ii_emlrtRSI;
      k++;
      if (k > 4) {
        exitg1 = 1;
      } else {
        f_st.site = &hi_emlrtRSI;
        frexp((real_T)ib / 2.0, &exponent);
        if (muDoubleScalarAbs(ib - b_data[k - 1]) < ldexp(1.0, exponent - 53)) {
          anyInputSizeChanged = TRUE;
        } else {
          anyInputSizeChanged = FALSE;
        }

        if (!anyInputSizeChanged) {
          exitg1 = 1;
        }
      }
    } while (exitg1 == 0);

    f_st.site = &gi_emlrtRSI;
    i++;
    b_data[i - 1] = (int8_T)ib;
    f_st.site = &fi_emlrtRSI;
    f_st.site = &fi_emlrtRSI;
  }

  f_st.site = &bi_emlrtRSI;
  f_st.site = &ai_emlrtRSI;
  f_st.site = &wh_emlrtRSI;
  if (1 > i) {
    b2 = FALSE;
  } else {
    b2 = (i > 2147483646);
  }

  if (b2) {
    g_st.site = &bg_emlrtRSI;
    check_forloop_overflow_error(&g_st);
  }

  d_st.site = &uh_emlrtRSI;
  d_st.site = &uh_emlrtRSI;
  if (1 > i) {
    i12 = 0;
  } else {
    i12 = i;
  }

  if (!(4 != i12)) {
  } else {
    e_y = NULL;
    m10 = mxCreateCharArray(2, iv61);
    for (i = 0; i < 13; i++) {
      cv66[i] = cv67[i];
    }

    emlrtInitCharArrayR2013a(&d_st, 13, m10, cv66);
    emlrtAssign(&e_y, m10);
    e_st.site = &mv_emlrtRSI;
    c_error(&e_st, b_message(&e_st, e_y, &g_emlrtMCI), &g_emlrtMCI);
  }

  /*  Error message:  */
  /*  If pilot index is 2-D, the indices per symbol must be unique; */
  /*  If pilot index is 3-D, the indices across transmit antennas per symbol must be unique. */
  c_st.site = &db_emlrtRSI;
  st.site = &gl_emlrtRSI;
  object = iobj_1;
  *hPreambleDemod = object;
  b_st.site = &jj_emlrtRSI;
  object = *hPreambleDemod;
  c_st.site = &y_emlrtRSI;
  d_st.site = &bb_emlrtRSI;
  d_st.site = &bb_emlrtRSI;
  object->isInitialized = FALSE;
  object->isReleased = FALSE;
  e_st.site = &cb_emlrtRSI;
  f_st.site = &db_emlrtRSI;
  e_st.site = &cb_emlrtRSI;
  f_st.site = &db_emlrtRSI;
  c_st.site = &y_emlrtRSI;
  c_st.site = &ab_emlrtRSI;
  b_st.site = &kj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &lj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &mj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &nj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &oj_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  c_st.site = &db_emlrtRSI;
  b_st.site = &pj_emlrtRSI;
  c_st.site = &db_emlrtRSI;

  /*  Calcuate OFDM frequency bin size */
  /*  Calculate locations of pilots without guardbands */
  /*  Calculate locations of subcarrier datastreams without guardbands */
  /* Remove guardband offsets */
  /* Remove index offsets for pilots and guardbands */
  /* dataSubcarrierIndexies([pilotLocationsWithoutGuardbands;DCNullLocation]) = [];%Remove pilot and DCNull locations */
  /*  Create return structure */
  for (i = 0; i < 560; i++) {
    tx->originalData[i] = b_originalData[i];
  }

  for (i = 0; i < 64; i++) {
    tx->shortPreambleOFDM[i] = shortPreambleOFDM[i];
  }

  for (i = 0; i < 160; i++) {
    tx->completeShortPreambleOFDM[i] = completeShortPreambleOFDM[i];
  }

  for (i = 0; i < 53; i++) {
    tx->shortPreamble[i] = dcv3[i];
  }

  for (i = 0; i < 53; i++) {
    tx->longPreamble[i] = iv62[i];
  }

  for (i = 0; i < 64; i++) {
    tx->longPreambleOFDM[i] = longPreambleOFDM[i];
  }

  for (i = 0; i < 160; i++) {
    tx->completeLongPreambleOFDM[i] = completeLongPreambleOFDM[i];
  }

  for (i = 0; i < 48; i++) {
    tx->pilots[i] = b_pilots[i];
  }

  for (i = 0; i < 320; i++) {
    tx->preambles[i] = preambles[i];
  }

  for (i = 0; i < 4; i++) {
    tx->pilotLocationsWithoutGuardbands[i] = 6.0 + 14.0 * (real_T)i;
  }

  tx->dataSubcarrierIndexies.size[0] = 1;
  tx->dataSubcarrierIndexies.size[1] = 48;
  for (i = 0; i < 48; i++) {
    tx->dataSubcarrierIndexies.data[i] = iv63[i];
  }

  tx->samplingFreq = 5.0E+6;
  tx->FFTLength = 64.0;
  tx->enableMA = TRUE;
  tx->numCarriers = 48.0;
  tx->padBits = 13.0;
  tx->numSamples = 576.0;
  tx->messageCharacters = 80.0;
  tx->numFrames = 20.0;
  tx->frameLength = 1280.0;
  tx->freqBin = 78125.0;
  tx->DecimationFactor = 0.0;
  tx->receiveBufferLength = 0.0;

  /*                              padBits: 13 */
  /*                           numSamples: 576 */
  /*                    messageCharacters: 80 */
  /*                            numFrames: 1000 */
  /*                          frameLength: 1280 */
  /*                              freqBin: 312500 */
  /*                           hDataDemod: [1x1 struct] */
  /*                       hPreambleDemod: [1x1 struct] */
  st.site = NULL;
  b_Destructor(&hPN);
  emxFreeStruct_OFDMModulator(&hPreambleMod);
  emxFreeStruct_OFDMModulator_1(&hDataMod);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Пример #13
0
void sammon(sammonStackData *SD, const real_T x[1000000], real_T y[2000], real_T
            *E)
{
  real_T B;
  int32_T i;
  real_T dv0[1000];
  int32_T b_i;
  boolean_T exitg1;
  real_T alpha1;
  real_T beta1;
  char_T TRANSB;
  char_T TRANSA;
  ptrdiff_t m_t;
  ptrdiff_t n_t;
  ptrdiff_t k_t;
  ptrdiff_t lda_t;
  ptrdiff_t ldb_t;
  ptrdiff_t ldc_t;
  double * alpha1_t;
  double * Aia0_t;
  double * Bib0_t;
  double * beta1_t;
  double * Cic0_t;
  real_T g[2000];
  real_T y2[2000];
  real_T b_y[2000];
  real_T c_y[2000];
  real_T d_y[2000];
  real_T e_y[2000];
  real_T b_g[2000];
  int32_T j;
  int32_T b_j;
  boolean_T exitg2;
  real_T dv1[1000];
  real_T E_new;

  /* #codgen */
  /*  */
  /*  SAMMON - apply Sammon's nonlinear mapping  */
  /*  */
  /*     Y = SAMMON(X) applies Sammon's nonlinear mapping procedure on */
  /*     multivariate data X, where each row represents a pattern and each column */
  /*     represents a feature.  On completion, Y contains the corresponding */
  /*     co-ordinates of each point on the map.  By default, a two-dimensional */
  /*     map is created.  Note if X contains any duplicated rows, SAMMON will */
  /*     fail (ungracefully).  */
  /*  */
  /*     [Y,E] = SAMMON(X) also returns the value of the cost function in E (i.e. */
  /*     the stress of the mapping). */
  /*  */
  /*     An N-dimensional output map is generated by Y = SAMMON(X,N) . */
  /*  */
  /*     A set of optimisation options can also be specified using a third */
  /*     argument, Y = SAMMON(X,N,OPTS) , where OPTS is a structure with fields: */
  /*  */
  /*        MaxIter        - maximum number of iterations */
  /*        TolFun         - relative tolerance on objective function */
  /*        MaxHalves      - maximum number of step halvings */
  /*        Input          - {'raw','distance'} if set to 'distance', X is  */
  /*                         interpreted as a matrix of pairwise distances. */
  /*        Display        - {'off', 'on', 'iter'} */
  /*        Initialisation - {'pca', 'random'} */
  /*  */
  /*     The default options structure can be retrieved by calling SAMMON with */
  /*     no parameters. */
  /*  */
  /*     References : */
  /*  */
  /*        [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data Structure */
  /*            Analysis", IEEE Transactions on Computers, vol. C-18, no. 5, */
  /*            pp 401-409, May 1969. */
  /*  */
  /*     See also : SAMMON_TEST */
  /*  */
  /*  File        : sammon.m */
  /*  */
  /*  Date        : Monday 12th November 2007. */
  /*  */
  /*  Author      : Gavin C. Cawley and Nicola L. C. Talbot */
  /*  */
  /*  Description : Simple vectorised MATLAB implementation of Sammon's non-linear */
  /*                mapping algorithm [1]. */
  /*  */
  /*  References  : [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data */
  /*                    Structure Analysis", IEEE Transactions on Computers, */
  /*                    vol. C-18, no. 5, pp 401-409, May 1969. */
  /*  */
  /*  History     : 10/08/2004 - v1.00 */
  /*                11/08/2004 - v1.10 Hessian made positive semidefinite */
  /*                13/08/2004 - v1.11 minor optimisation */
  /*                12/11/2007 - v1.20 initialisation using the first n principal */
  /*                                   components. */
  /*  */
  /*  Thanks      : Dr Nick Hamilton ([email protected]) for supplying the */
  /*                code for implementing initialisation using the first n */
  /*                principal components (introduced in v1.20). */
  /*  */
  /*  To do       : The current version does not take advantage of the symmetry */
  /*                of the distance matrix in order to allow for easy */
  /*                vectorisation.  This may not be a good choice for very large */
  /*                datasets, so perhaps one day I'll get around to doing a MEX */
  /*                version using the BLAS library etc. for very large datasets. */
  /*  */
  /*  Copyright   : (c) Dr Gavin C. Cawley, November 2007. */
  /*  */
  /*     This program is free software; you can redistribute it and/or modify */
  /*     it under the terms of the GNU General Public License as published by */
  /*     the Free Software Foundation; either version 2 of the License, or */
  /*     (at your option) any later version. */
  /*  */
  /*     This program is distributed in the hope that it will be useful, */
  /*     but WITHOUT ANY WARRANTY; without even the implied warranty of */
  /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
  /*     GNU General Public License for more details. */
  /*  */
  /*     You should have received a copy of the GNU General Public License */
  /*     along with this program; if not, write to the Free Software */
  /*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  /*  */
  /*  use the default options structure */
  /*  create distance matrix unless given by parameters */
  emlrtPushRtStackR2012b(&emlrtRSI, emlrtRootTLSGlobal);
  euclid(SD, x, x, SD->f2.D);
  emlrtPopRtStackR2012b(&emlrtRSI, emlrtRootTLSGlobal);

  /*  remaining initialisation */
  B = b_sum(SD->f2.D);
  eye(SD->f2.delta);
  for (i = 0; i < 1000000; i++) {
    SD->f2.D[i] += SD->f2.delta[i];
  }

  rdivide(1.0, SD->f2.D, SD->f2.Dinv);
  emlrtPushRtStackR2012b(&b_emlrtRSI, emlrtRootTLSGlobal);
  randn(y);
  emlrtPopRtStackR2012b(&b_emlrtRSI, emlrtRootTLSGlobal);
  emlrtPushRtStackR2012b(&c_emlrtRSI, emlrtRootTLSGlobal);
  b_euclid(SD, y, y, SD->f2.d);
  eye(SD->f2.delta);
  for (i = 0; i < 1000000; i++) {
    SD->f2.d[i] += SD->f2.delta[i];
  }

  emlrtPopRtStackR2012b(&c_emlrtRSI, emlrtRootTLSGlobal);
  rdivide(1.0, SD->f2.d, SD->f2.dinv);
  for (i = 0; i < 1000000; i++) {
    SD->f2.b_D[i] = SD->f2.D[i] - SD->f2.d[i];
  }

  power(SD->f2.b_D, SD->f2.delta);
  for (i = 0; i < 1000000; i++) {
    SD->f2.d[i] = SD->f2.delta[i] * SD->f2.Dinv[i];
  }

  d_sum(SD->f2.d, dv0);
  *E = e_sum(dv0);

  /*  get on with it */
  b_i = 0;
  exitg1 = FALSE;
  while ((exitg1 == FALSE) && (b_i < 500)) {
    /*  compute gradient, Hessian and search direction (note it is actually */
    /*  1/4 of the gradient and Hessian, but the step size is just the ratio */
    /*  of the gradient and the diagonal of the Hessian so it doesn't matter). */
    for (i = 0; i < 1000000; i++) {
      SD->f2.delta[i] = SD->f2.dinv[i] - SD->f2.Dinv[i];
    }

    emlrtPushRtStackR2012b(&d_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    for (i = 0; i < 2000; i++) {
      SD->f2.y_old[i] = 1.0;
      SD->f2.deltaone[i] = 0.0;
    }

    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&SD->f2.y_old[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&SD->f2.deltaone[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&d_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    memset(&g[0], 0, 2000U * sizeof(real_T));
    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&y[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&g[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 0; i < 2000; i++) {
      g[i] -= y[i] * SD->f2.deltaone[i];
    }

    emlrtPopRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
    c_power(SD->f2.dinv, SD->f2.delta);
    b_power(y, y2);
    emlrtPushRtStackR2012b(&f_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    memset(&b_y[0], 0, 2000U * sizeof(real_T));
    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&y2[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&b_y[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 0; i < 2000; i++) {
      c_y[i] = 2.0 * y[i];
    }

    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    memset(&d_y[0], 0, 2000U * sizeof(real_T));
    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&y[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&d_y[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    for (i = 0; i < 2000; i++) {
      SD->f2.y_old[i] = 1.0;
      e_y[i] = 0.0;
    }

    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&SD->f2.y_old[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&e_y[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&f_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 0; i < 2000; i++) {
      SD->f2.y_old[i] = ((b_y[i] - SD->f2.deltaone[i]) - c_y[i] * d_y[i]) + y2[i]
        * e_y[i];
      b_g[i] = -g[i];
    }

    b_abs(SD->f2.y_old, y2);
    for (i = 0; i < 2000; i++) {
      SD->f2.deltaone[i] = y2[i];
      SD->f2.y_old[i] = y[i];
    }

    b_rdivide(b_g, SD->f2.deltaone, y2);

    /*  use step-halving procedure to ensure progress is made */
    j = 1;
    b_j = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (b_j < 20)) {
      j = b_j + 1;
      for (i = 0; i < 2000; i++) {
        y[i] = SD->f2.y_old[i] + y2[i];
      }

      emlrtPushRtStackR2012b(&g_emlrtRSI, emlrtRootTLSGlobal);
      b_euclid(SD, y, y, SD->f2.d);
      eye(SD->f2.delta);
      for (i = 0; i < 1000000; i++) {
        SD->f2.d[i] += SD->f2.delta[i];
      }

      emlrtPopRtStackR2012b(&g_emlrtRSI, emlrtRootTLSGlobal);
      rdivide(1.0, SD->f2.d, SD->f2.dinv);
      for (i = 0; i < 1000000; i++) {
        SD->f2.b_D[i] = SD->f2.D[i] - SD->f2.d[i];
      }

      power(SD->f2.b_D, SD->f2.delta);
      for (i = 0; i < 1000000; i++) {
        SD->f2.d[i] = SD->f2.delta[i] * SD->f2.Dinv[i];
      }

      d_sum(SD->f2.d, dv1);
      E_new = e_sum(dv1);
      if (E_new < *E) {
        exitg2 = TRUE;
      } else {
        for (i = 0; i < 2000; i++) {
          y2[i] *= 0.5;
        }

        b_j++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar,
          emlrtRootTLSGlobal);
      }
    }

    /*  bomb out if too many halving steps are required */
    if ((j == 20) || (muDoubleScalarAbs((*E - E_new) / *E) < 1.0E-9)) {
      exitg1 = TRUE;
    } else {
      /*  evaluate termination criterion */
      /*  report progress */
      *E = E_new;
      b_i++;
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal);
    }
  }

  /*  fiddle stress to match the original Sammon paper */
  *E *= 0.5 / B;
}
Пример #14
0
/* Function Definitions */
void linearODESSEP2X4(const emxArray_real_T *T, const emxArray_real_T *I)
{
  int32_T i;
  real_T hoistedGlobal[17];
  int32_T j;
  int32_T b_i;
  real_T normA;
  real_T y[289];
  real_T F[289];
  boolean_T exitg2;
  real_T s;
  boolean_T exitg1;
  static const real_T theta[5] = { 0.01495585217958292, 0.253939833006323,
    0.95041789961629319, 2.097847961257068, 5.3719203511481517 };

  static const int8_T iv2[5] = { 3, 5, 7, 9, 13 };

  int32_T eint;
  real_T b_y[289];
  real_T beta1;
  char_T TRANSB;
  char_T TRANSA;
  ptrdiff_t m_t;
  ptrdiff_t n_t;
  ptrdiff_t k_t;
  ptrdiff_t lda_t;
  ptrdiff_t ldb_t;
  ptrdiff_t ldc_t;
  double * alpha1_t;
  double * Aia0_t;
  double * Bib0_t;
  double * beta1_t;
  double * Cic0_t;
  emlrtPushRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
  Q[0] = -k2 * A - L2 * J;
  Q[17] = k2 * A;
  Q[34] = L2 * J;
  Q[51] = 0.0;
  Q[68] = 0.0;
  Q[85] = 0.0;
  Q[102] = 0.0;
  Q[119] = 0.0;
  Q[136] = 0.0;
  Q[153] = 0.0;
  Q[170] = 0.0;
  Q[187] = 0.0;
  Q[204] = 0.0;
  Q[221] = 0.0;
  Q[238] = 0.0;
  Q[255] = 0.0;
  Q[272] = 0.0;
  Q[1] = k1;
  Q[18] = ((-k1 - k4 * A) - H2) - L2 * J;
  Q[35] = 0.0;
  Q[52] = L2 * J;
  Q[69] = 0.0;
  Q[86] = 0.0;
  Q[103] = k4 * A;
  Q[120] = 0.0;
  Q[137] = 0.0;
  Q[154] = 0.0;
  Q[171] = 0.0;
  Q[188] = 0.0;
  Q[205] = 0.0;
  Q[222] = H2;
  Q[239] = 0.0;
  Q[256] = 0.0;
  Q[273] = 0.0;
  Q[2] = L1;
  Q[19] = 0.0;
  Q[36] = (-k8 * A - L1) - L4 * J;
  Q[53] = k8 * A;
  Q[70] = L4 * J;
  Q[87] = 0.0;
  Q[104] = 0.0;
  Q[121] = 0.0;
  Q[138] = 0.0;
  Q[155] = 0.0;
  Q[172] = 0.0;
  Q[189] = 0.0;
  Q[206] = 0.0;
  Q[223] = 0.0;
  Q[240] = 0.0;
  Q[257] = 0.0;
  Q[274] = 0.0;
  Q[3] = 0.0;
  Q[20] = L1;
  Q[37] = k7;
  Q[54] = ((-k7 - k10 * A) - L1) - L4 * J;
  Q[71] = 0.0;
  Q[88] = L4 * J;
  Q[105] = 0.0;
  Q[122] = 0.0;
  Q[139] = k10 * A;
  Q[156] = 0.0;
  Q[173] = 0.0;
  Q[190] = 0.0;
  Q[207] = 0.0;
  Q[224] = 0.0;
  Q[241] = 0.0;
  Q[258] = 0.0;
  Q[275] = 0.0;
  Q[4] = 0.0;
  Q[21] = 0.0;
  Q[38] = L3;
  Q[55] = 0.0;
  Q[72] = -k8 * alpha * A - L3;
  Q[89] = k8 * alpha * A;
  Q[106] = 0.0;
  Q[123] = 0.0;
  Q[140] = 0.0;
  Q[157] = 0.0;
  Q[174] = 0.0;
  Q[191] = 0.0;
  Q[208] = 0.0;
  Q[225] = 0.0;
  Q[242] = 0.0;
  Q[259] = 0.0;
  Q[276] = 0.0;
  Q[5] = 0.0;
  Q[22] = 0.0;
  Q[39] = 0.0;
  Q[56] = L3;
  Q[73] = k7;
  Q[90] = (-k7 - k10 * alpha * A) - L3;
  Q[107] = 0.0;
  Q[124] = 0.0;
  Q[141] = 0.0;
  Q[158] = 0.0;
  Q[175] = k10 * alpha * A;
  Q[192] = 0.0;
  Q[209] = 0.0;
  Q[226] = 0.0;
  Q[243] = 0.0;
  Q[260] = 0.0;
  Q[277] = 0.0;
  Q[6] = 0.0;
  Q[23] = k3;
  Q[40] = 0.0;
  Q[57] = 0.0;
  Q[74] = 0.0;
  Q[91] = 0.0;
  Q[108] = ((-k3 - k6 * A) - H2) - L2 * J;
  Q[125] = k6 * A;
  Q[142] = L2 * J;
  Q[159] = 0.0;
  Q[176] = 0.0;
  Q[193] = 0.0;
  Q[210] = 0.0;
  Q[227] = 0.0;
  Q[244] = H2;
  Q[261] = 0.0;
  Q[278] = 0.0;
  Q[7] = 0.0;
  Q[24] = 0.0;
  Q[41] = 0.0;
  Q[58] = 0.0;
  Q[75] = 0.0;
  Q[92] = 0.0;
  Q[109] = k5;
  Q[126] = (-k5 - H2) - L2 * J;
  Q[143] = 0.0;
  Q[160] = L2 * J;
  Q[177] = 0.0;
  Q[194] = 0.0;
  Q[211] = 0.0;
  Q[228] = 0.0;
  Q[245] = 0.0;
  Q[262] = H2;
  Q[279] = 0.0;
  Q[8] = 0.0;
  Q[25] = 0.0;
  Q[42] = 0.0;
  Q[59] = k9;
  Q[76] = 0.0;
  Q[93] = 0.0;
  Q[110] = L1;
  Q[127] = 0.0;
  Q[144] = ((-k9 - k12 * A) - L1) - L4 * J;
  Q[161] = k12 * A;
  Q[178] = L4 * J;
  Q[195] = 0.0;
  Q[212] = 0.0;
  Q[229] = 0.0;
  Q[246] = 0.0;
  Q[263] = 0.0;
  Q[280] = 0.0;
  Q[9] = 0.0;
  Q[26] = 0.0;
  Q[43] = 0.0;
  Q[60] = 0.0;
  Q[77] = 0.0;
  Q[94] = 0.0;
  Q[111] = 0.0;
  Q[128] = L1;
  Q[145] = k11;
  Q[162] = (-k11 - L1) - L4 * J;
  Q[179] = 0.0;
  Q[196] = L4 * J;
  Q[213] = 0.0;
  Q[230] = 0.0;
  Q[247] = 0.0;
  Q[264] = 0.0;
  Q[281] = 0.0;
  Q[10] = 0.0;
  Q[27] = 0.0;
  Q[44] = 0.0;
  Q[61] = 0.0;
  Q[78] = 0.0;
  Q[95] = k9;
  Q[112] = 0.0;
  Q[129] = 0.0;
  Q[146] = L3;
  Q[163] = 0.0;
  Q[180] = (-k9 - k12 * alpha * A) - L3;
  Q[197] = k12 * alpha * A;
  Q[214] = 0.0;
  Q[231] = 0.0;
  Q[248] = 0.0;
  Q[265] = 0.0;
  Q[282] = 0.0;
  Q[11] = 0.0;
  Q[28] = 0.0;
  Q[45] = 0.0;
  Q[62] = 0.0;
  Q[79] = 0.0;
  Q[96] = 0.0;
  Q[113] = 0.0;
  Q[130] = 0.0;
  Q[147] = 0.0;
  Q[164] = L3;
  Q[181] = k11;
  Q[198] = -k11 - L3;
  Q[215] = 0.0;
  Q[232] = 0.0;
  Q[249] = 0.0;
  Q[266] = 0.0;
  Q[283] = 0.0;
  Q[12] = H1;
  Q[29] = 0.0;
  Q[46] = 0.0;
  Q[63] = 0.0;
  Q[80] = 0.0;
  Q[97] = 0.0;
  Q[114] = 0.0;
  Q[131] = 0.0;
  Q[148] = 0.0;
  Q[165] = 0.0;
  Q[182] = 0.0;
  Q[199] = 0.0;
  Q[216] = -k2 * A - H1;
  Q[233] = k2 * A;
  Q[250] = 0.0;
  Q[267] = 0.0;
  Q[284] = 0.0;
  Q[13] = 0.0;
  Q[30] = 0.0;
  Q[47] = 0.0;
  Q[64] = 0.0;
  Q[81] = 0.0;
  Q[98] = 0.0;
  Q[115] = 0.0;
  Q[132] = 0.0;
  Q[149] = 0.0;
  Q[166] = 0.0;
  Q[183] = 0.0;
  Q[200] = 0.0;
  Q[217] = k1;
  Q[234] = -k1 - k4 * A;
  Q[251] = k4 * A;
  Q[268] = 0.0;
  Q[285] = 0.0;
  Q[14] = 0.0;
  Q[31] = 0.0;
  Q[48] = 0.0;
  Q[65] = 0.0;
  Q[82] = 0.0;
  Q[99] = 0.0;
  Q[116] = 0.0;
  Q[133] = 0.0;
  Q[150] = 0.0;
  Q[167] = 0.0;
  Q[184] = 0.0;
  Q[201] = 0.0;
  Q[218] = 0.0;
  Q[235] = k3;
  Q[252] = -k3 - k6 * A;
  Q[269] = k6 * A;
  Q[286] = 0.0;
  Q[15] = 0.0;
  Q[32] = 0.0;
  Q[49] = 0.0;
  Q[66] = 0.0;
  Q[83] = 0.0;
  Q[100] = 0.0;
  Q[117] = 0.0;
  Q[134] = 0.0;
  Q[151] = 0.0;
  Q[168] = 0.0;
  Q[185] = 0.0;
  Q[202] = 0.0;
  Q[219] = 0.0;
  Q[236] = 0.0;
  Q[253] = k5;
  Q[270] = -k5 - H3;
  Q[287] = H3;
  Q[16] = H4;
  Q[33] = 0.0;
  Q[50] = 0.0;
  Q[67] = 0.0;
  Q[84] = 0.0;
  Q[101] = 0.0;
  Q[118] = 0.0;
  Q[135] = 0.0;
  Q[152] = 0.0;
  Q[169] = 0.0;
  Q[186] = 0.0;
  Q[203] = 0.0;
  Q[220] = 0.0;
  Q[237] = 0.0;
  Q[254] = 0.0;
  Q[271] = 0.0;
  Q[288] = -H4;
  Q_dirty |= 1U;
  emlrtPopRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
  i = 0;
  while (i <= T->size[0] - 1) {
    emlrtPushRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
    memcpy(&hoistedGlobal[0], &p0[0], 17U * sizeof(real_T));
    j = T->size[0];
    b_i = (int32_T)(1.0 + (real_T)i);
    emlrtDynamicBoundsCheckFastR2012b(b_i, 1, j, &bd_emlrtBCI,
      emlrtRootTLSGlobal);
    normA = T->data[i];
    for (j = 0; j < 289; j++) {
      y[j] = Q[j] * normA;
    }

    normA = 0.0;
    j = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (j < 17)) {
      s = 0.0;
      for (b_i = 0; b_i < 17; b_i++) {
        s += muDoubleScalarAbs(y[b_i + 17 * j]);
      }

      if (muDoubleScalarIsNaN(s)) {
        normA = rtNaN;
        exitg2 = TRUE;
      } else {
        if (s > normA) {
          normA = s;
        }

        j++;
      }
    }

    if (normA <= 5.3719203511481517) {
      b_i = 0;
      exitg1 = FALSE;
      while ((exitg1 == FALSE) && (b_i < 5)) {
        if (normA <= theta[b_i]) {
          emlrtPushRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
          PadeApproximantOfDegree(y, iv2[b_i], F);
          emlrtPopRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
          exitg1 = TRUE;
        } else {
          b_i++;
        }
      }
    } else {
      normA /= 5.3719203511481517;
      if ((!muDoubleScalarIsInf(normA)) && (!muDoubleScalarIsNaN(normA))) {
        normA = frexp(normA, &eint);
        j = eint;
      } else {
        j = 0;
      }

      s = j;
      if (normA == 0.5) {
        s = (real_T)j - 1.0;
      }

      normA = muDoubleScalarPower(2.0, s);
      emlrtPushRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
      for (j = 0; j < 289; j++) {
        b_y[j] = y[j] / normA;
      }

      PadeApproximantOfDegree(b_y, 13.0, F);
      emlrtPopRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtForLoopVectorCheckR2012b(1.0, 1.0, s, mxDOUBLE_CLASS, (int32_T)s,
        &l_emlrtRTEI, emlrtRootTLSGlobal);
      for (j = 0; j < (int32_T)s; j++) {
        emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal);
        memcpy(&y[0], &F[0], 289U * sizeof(real_T));
        emlrtPushRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal);
        normA = 1.0;
        beta1 = 0.0;
        TRANSB = 'N';
        TRANSA = 'N';
        memset(&F[0], 0, 289U * sizeof(real_T));
        emlrtPushRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        m_t = (ptrdiff_t)(17);
        emlrtPopRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&xb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        n_t = (ptrdiff_t)(17);
        emlrtPopRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&xb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&yb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        k_t = (ptrdiff_t)(17);
        emlrtPopRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&yb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&ac_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        lda_t = (ptrdiff_t)(17);
        emlrtPopRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&ac_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&bc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        ldb_t = (ptrdiff_t)(17);
        emlrtPopRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&bc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&cc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        ldc_t = (ptrdiff_t)(17);
        emlrtPopRtStackR2012b(&jc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&cc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&dc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        alpha1_t = (double *)(&normA);
        emlrtPopRtStackR2012b(&dc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&ec_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        Aia0_t = (double *)(&y[0]);
        emlrtPopRtStackR2012b(&ec_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&fc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        Bib0_t = (double *)(&y[0]);
        emlrtPopRtStackR2012b(&fc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&gc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        beta1_t = (double *)(&beta1);
        emlrtPopRtStackR2012b(&gc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&hc_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        Cic0_t = (double *)(&F[0]);
        emlrtPopRtStackR2012b(&hc_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&ic_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t,
              Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t);
        emlrtPopRtStackR2012b(&ic_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      }
    }

    for (j = 0; j < 17; j++) {
      p0[j] = 0.0;
      for (b_i = 0; b_i < 17; b_i++) {
        p0[j] += hoistedGlobal[b_i] * F[b_i + 17 * j];
      }
    }

    p0_dirty |= 1U;
    emlrtPopRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
    j = I->size[0];
    b_i = 1 + i;
    normA = Acell * 1.0E+12 * (g1 * (p0[6] + p0[7]) * (V - E1) + g2 * (((p0[8] +
      p0[9]) + p0[10]) + p0[11]) * (V - E2)) - I->
      data[emlrtDynamicBoundsCheckFastR2012b(b_i, 1, j, &cd_emlrtBCI,
      emlrtRootTLSGlobal) - 1];
    normA = muDoubleScalarAbs(normA);
    err += normA * normA;
    err_dirty |= 1U;
    i++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal);
  }
}
Пример #15
0
/* Function Definitions */
real_T Dcoeff(const emlrtStack *sp, const emxArray_real_T *y, real_T j, const
              emxArray_real_T *x, real_T t, const emxArray_real_T *gridT, const
              emxArray_real_T *f)
{
  real_T vals;
  emxArray_real_T *a;
  int32_T i57;
  int32_T unnamed_idx_1;
  emxArray_real_T *r7;
  int32_T i58;
  int32_T i59;
  int32_T i60;
  int32_T i61;
  int32_T i62;
  int32_T i63;
  int32_T i64;
  int32_T i65;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &a, 2, &c_emlrtRTEI, true);

  /*  Calculate the integral int_0^1(f(y,t_j)*A_{yj}(x,t)dy) by midpoint */
  /*  integration rule */
  /*  the spatial integration of all points y at time t_j */
  i57 = a->size[0] * a->size[1];
  a->size[0] = 1;
  emxEnsureCapacity(sp, (emxArray__common *)a, i57, (int32_T)sizeof(real_T),
                    &g_emlrtRTEI);
  unnamed_idx_1 = y->size[1];
  i57 = a->size[0] * a->size[1];
  a->size[1] = unnamed_idx_1;
  emxEnsureCapacity(sp, (emxArray__common *)a, i57, (int32_T)sizeof(real_T),
                    &g_emlrtRTEI);
  unnamed_idx_1 = y->size[1];
  for (i57 = 0; i57 < unnamed_idx_1; i57++) {
    a->data[i57] = 0.0;
  }

  emxInit_real_T(sp, &r7, 2, &g_emlrtRTEI, true);
  vals = 0.0;
  i57 = y->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, i57, &kb_emlrtBCI, sp);
  st.site = &v_emlrtRSI;
  b_Acoeff(&st, y->data[0], j, x, t, gridT, r7);
  i57 = r7->size[1];
  emlrtSizeEqCheck1DFastR2012b(1, i57, &k_emlrtECI, sp);
  unnamed_idx_1 = y->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, unnamed_idx_1, &jb_emlrtBCI, sp);
  i57 = r7->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, i57, &pe_emlrtBCI, sp);
  a->data[0] = r7->data[0];

  /*  y = 0:1/(numel(y)-2):1; */
  unnamed_idx_1 = 2;
  while (unnamed_idx_1 - 2 <= f->size[1] - 2) {
    i57 = y->size[1];
    st.site = &w_emlrtRSI;
    b_Acoeff(&st, y->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1,
              i57, &hc_emlrtBCI, sp) - 1], j, x, t, gridT, r7);
    i57 = r7->size[1];
    emlrtSizeEqCheck1DFastR2012b(1, i57, &l_emlrtECI, sp);
    i57 = r7->size[1];
    emlrtDynamicBoundsCheckFastR2012b(1, 1, i57, &qe_emlrtBCI, sp);
    i57 = a->size[1];
    a->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1, i57,
      &gc_emlrtBCI, sp) - 1] = r7->data[0];
    i57 = a->size[1];
    i58 = f->size[1];
    i59 = a->size[1];
    i60 = unnamed_idx_1 - 1;
    i61 = f->size[1];
    i62 = unnamed_idx_1 - 1;
    i63 = y->size[1];
    i64 = y->size[1];
    i65 = unnamed_idx_1 - 1;
    vals += 0.5 * (a->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1,
      i57, &ic_emlrtBCI, sp) - 1] * f->data[emlrtDynamicBoundsCheckFastR2012b
                   (unnamed_idx_1, 1, i58, &ib_emlrtBCI, sp) - 1] + a->
                   data[emlrtDynamicBoundsCheckFastR2012b(i60, 1, i59,
      &jc_emlrtBCI, sp) - 1] * f->data[emlrtDynamicBoundsCheckFastR2012b(i62, 1,
      i61, &hb_emlrtBCI, sp) - 1]) * (y->data[emlrtDynamicBoundsCheckFastR2012b
      (unnamed_idx_1, 1, i63, &kc_emlrtBCI, sp) - 1] - y->
      data[emlrtDynamicBoundsCheckFastR2012b(i65, 1, i64, &lc_emlrtBCI, sp) - 1]);
    unnamed_idx_1++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  emxFree_real_T(&r7);
  emxFree_real_T(&a);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
  return vals;
}
Пример #16
0
real_T b_Dcoeff(const emlrtStack *sp, const emxArray_real_T *y, real_T j, real_T
                x, real_T t, const emxArray_real_T *gridT, const emxArray_real_T
                *f)
{
  real_T vals;
  emxArray_real_T *a;
  int32_T i25;
  int32_T unnamed_idx_1;
  int32_T i26;
  int32_T i27;
  int32_T i28;
  int32_T i29;
  int32_T i30;
  int32_T i31;
  int32_T i32;
  int32_T i33;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &a, 2, &c_emlrtRTEI, true);

  /*  Calculate the integral int_0^1(f(y,t_j)*A_{yj}(x,t)dy) by midpoint */
  /*  integration rule */
  /*  the spatial integration of all points y at time t_j */
  i25 = a->size[0] * a->size[1];
  a->size[0] = 1;
  emxEnsureCapacity(sp, (emxArray__common *)a, i25, (int32_T)sizeof(real_T),
                    &g_emlrtRTEI);
  unnamed_idx_1 = y->size[1];
  i25 = a->size[0] * a->size[1];
  a->size[1] = unnamed_idx_1;
  emxEnsureCapacity(sp, (emxArray__common *)a, i25, (int32_T)sizeof(real_T),
                    &g_emlrtRTEI);
  unnamed_idx_1 = y->size[1];
  for (i25 = 0; i25 < unnamed_idx_1; i25++) {
    a->data[i25] = 0.0;
  }

  vals = 0.0;
  unnamed_idx_1 = y->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, unnamed_idx_1, &jb_emlrtBCI, sp);
  i25 = y->size[1];
  emlrtDynamicBoundsCheckFastR2012b(1, 1, i25, &kb_emlrtBCI, sp);
  st.site = &v_emlrtRSI;
  a->data[0] = Acoeff(&st, y->data[0], j, x, t, gridT);

  /*  y = 0:1/(numel(y)-2):1; */
  unnamed_idx_1 = 2;
  while (unnamed_idx_1 - 2 <= f->size[1] - 2) {
    i25 = a->size[1];
    i26 = y->size[1];
    st.site = &w_emlrtRSI;
    a->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1, i25,
      &gc_emlrtBCI, sp) - 1] = Acoeff(&st, y->
      data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1, i26, &hc_emlrtBCI,
      sp) - 1], j, x, t, gridT);
    i25 = a->size[1];
    i26 = f->size[1];
    i27 = a->size[1];
    i28 = unnamed_idx_1 - 1;
    i29 = f->size[1];
    i30 = unnamed_idx_1 - 1;
    i31 = y->size[1];
    i32 = y->size[1];
    i33 = unnamed_idx_1 - 1;
    vals += 0.5 * (a->data[emlrtDynamicBoundsCheckFastR2012b(unnamed_idx_1, 1,
      i25, &ic_emlrtBCI, sp) - 1] * f->data[emlrtDynamicBoundsCheckFastR2012b
                   (unnamed_idx_1, 1, i26, &ib_emlrtBCI, sp) - 1] + a->
                   data[emlrtDynamicBoundsCheckFastR2012b(i28, 1, i27,
      &jc_emlrtBCI, sp) - 1] * f->data[emlrtDynamicBoundsCheckFastR2012b(i30, 1,
      i29, &hb_emlrtBCI, sp) - 1]) * (y->data[emlrtDynamicBoundsCheckFastR2012b
      (unnamed_idx_1, 1, i31, &kc_emlrtBCI, sp) - 1] - y->
      data[emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &lc_emlrtBCI, sp) - 1]);
    unnamed_idx_1++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  emxFree_real_T(&a);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
  return vals;
}
Пример #17
0
void locateShortpreamble(const emlrtStack *sp, const real_T M_data[1224], real_T
  *preambleEstimatedLocation, real_T *numPeaks)
{
  int32_T ixstart;
  real_T thresholdNorm;
  int32_T ix;
  boolean_T exitg1;
  boolean_T b_M_data[1224];
  int32_T ii_size[1];
  int32_T ii_data[1224];
  int32_T MLocations_size_idx_0;
  int32_T loop_ub;
  real_T MLocations_data[1224];
  int16_T unnamed_idx_0;
  int32_T peaks_data[1224];
  int32_T i20;
  real_T b_MLocations_data[1224];
  int32_T MLocations_size[1];
  real_T MLocations[8];
  int32_T ib_size[1];
  int32_T ib_data[8];
  int32_T ia_size[1];
  int32_T ia_data[8];
  int32_T c_size[1];
  real_T c_data[8];
  int32_T peaks_size[1];
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;

  /*  Locate of the start of the actual preamble from timing metric */
  /* % Find peaks of correlation */
  /*  Adjust threshold */
  st.site = &pp_emlrtRSI;
  b_st.site = &we_emlrtRSI;
  ixstart = 1;
  thresholdNorm = M_data[0];
  if (muDoubleScalarIsNaN(M_data[0])) {
    ix = 2;
    exitg1 = FALSE;
    while ((exitg1 == FALSE) && (ix <= 1224)) {
      ixstart = ix;
      if (!muDoubleScalarIsNaN(M_data[ix - 1])) {
        thresholdNorm = M_data[ix - 1];
        exitg1 = TRUE;
      } else {
        ix++;
      }
    }
  }

  if (ixstart < 1224) {
    while (ixstart + 1 <= 1224) {
      if (M_data[ixstart] > thresholdNorm) {
        thresholdNorm = M_data[ixstart];
      }

      ixstart++;
    }
  }

  st.site = &pp_emlrtRSI;
  thresholdNorm *= 0.6;
  st.site = &qp_emlrtRSI;
  for (ixstart = 0; ixstart < 1224; ixstart++) {
    b_M_data[ixstart] = (M_data[ixstart] > thresholdNorm);
  }

  b_st.site = &vc_emlrtRSI;
  b_eml_find(b_M_data, ii_data, ii_size);

  /*  Correct estimate to start of preamble not its center */
  MLocations_size_idx_0 = ii_size[0];
  loop_ub = ii_size[0];
  for (ixstart = 0; ixstart < loop_ub; ixstart++) {
    MLocations_data[ixstart] = (real_T)ii_data[ixstart] - 9.0;
  }

  /*  Frame Detection */
  unnamed_idx_0 = (int16_T)ii_size[0];
  loop_ub = (int16_T)ii_size[0];
  for (ixstart = 0; ixstart < loop_ub; ixstart++) {
    peaks_data[ixstart] = 0;
  }

  /*  Determine correct peak  */
  st.site = &rp_emlrtRSI;
  ix = 0;
  while (ix <= ii_size[0] - 1) {
    ixstart = ix + 1;
    emlrtDynamicBoundsCheckFastR2012b(ixstart, 1, ii_size[0], &cb_emlrtBCI, sp);
    if (ix + 1 > ii_size[0]) {
      ixstart = 1;
      i20 = 1;
    } else {
      ixstart = emlrtDynamicBoundsCheckFastR2012b(ix + 1, 1, ii_size[0],
        &db_emlrtBCI, sp);
      i20 = emlrtDynamicBoundsCheckFastR2012b(ii_size[0], 1, ii_size[0],
        &db_emlrtBCI, sp) + 1;
    }

    emlrtVectorVectorIndexCheckR2012b(ii_size[0], 1, 1, i20 - ixstart,
      &s_emlrtECI, sp);
    st.site = &sp_emlrtRSI;
    b_st.site = &eq_emlrtRSI;
    MLocations_size[0] = i20 - ixstart;
    loop_ub = i20 - ixstart;
    for (i20 = 0; i20 < loop_ub; i20++) {
      b_MLocations_data[i20] = MLocations_data[(ixstart + i20) - 1];
    }

    for (ixstart = 0; ixstart < 8; ixstart++) {
      MLocations[ixstart] = MLocations_data[ix] + (16.0 + 16.0 * (real_T)ixstart);
    }

    c_st.site = &fq_emlrtRSI;
    do_vectors(&c_st, b_MLocations_data, MLocations_size, MLocations, c_data,
               c_size, ia_data, ia_size, ib_data, ib_size);
    st.site = &sp_emlrtRSI;
    ixstart = (int16_T)ii_size[0];
    peaks_data[emlrtDynamicBoundsCheckFastR2012b(ix + 1, 1, ixstart,
      &gb_emlrtBCI, sp) - 1] = c_size[0];
    ix++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  /*  Have at least 5 peaks for positive match */
  /*  (TUNABLE) */
  peaks_size[0] = (int16_T)ii_size[0];
  loop_ub = (int16_T)ii_size[0];
  for (ixstart = 0; ixstart < loop_ub; ixstart++) {
    b_M_data[ixstart] = (peaks_data[ixstart] < 7);
  }

  st.site = &tp_emlrtRSI;
  eml_li_find(&st, b_M_data, peaks_size, ii_data, ii_size);
  loop_ub = ii_size[0];
  for (ixstart = 0; ixstart < loop_ub; ixstart++) {
    i20 = (int16_T)MLocations_size_idx_0;
    peaks_data[emlrtDynamicBoundsCheckFastR2012b(ii_data[ixstart], 1, i20,
      &eb_emlrtBCI, sp) - 1] = 0;
  }

  /*  Pick earliest peak in time */
  if (!(unnamed_idx_0 == 0)) {
    st.site = &up_emlrtRSI;
    b_st.site = &ir_emlrtRSI;
    ixstart = peaks_data[0];
    loop_ub = 1;
    if (unnamed_idx_0 > 1) {
      for (ix = 2; ix <= unnamed_idx_0; ix++) {
        if (peaks_data[ix - 1] > ixstart) {
          ixstart = peaks_data[ix - 1];
          loop_ub = ix;
        }
      }
    }

    *numPeaks = ixstart;
    if (ixstart > 0) {
      *preambleEstimatedLocation =
        MLocations_data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1,
        MLocations_size_idx_0, &fb_emlrtBCI, sp) - 1];
    } else {
      *preambleEstimatedLocation = -1.0;

      /*  no desirable location found */
    }
  } else {
    *preambleEstimatedLocation = -1.0;
    *numPeaks = 0.0;
  }

  /*  Normalize max peaks found */
  st.site = &vp_emlrtRSI;
  b_st.site = &j_emlrtRSI;
  *numPeaks /= 8.0;
}
Пример #18
0
/* Function Definitions */
void OFDMbits2letters(const emlrtStack *sp, const boolean_T bits_data[560],
                      const int32_T bits_size[2], real_T Letters_data[80],
                      int32_T Letters_size[1])
{
  real_T a;
  int32_T i32;
  int32_T i33;
  boolean_T p;
  const mxArray *y;
  static const int32_T iv237[2] = { 1, 28 };

  const mxArray *m43;
  char_T cv284[28];
  int32_T i;
  static const char_T cv285[28] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'N', 'o', 'n', 'I', 'n', 't', 'e', 'g', 'e', 'r', 'I',
    'n', 'p', 'u', 't' };

  const mxArray *b_y;
  const mxArray *c_y;
  int32_T maxdimlen;
  boolean_T y_data[560];
  const mxArray *d_y;
  static const int32_T iv238[2] = { 1, 40 };

  char_T cv286[40];
  static const char_T cv287[40] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'g', 'e', 't', 'R', 'e', 's', 'h', 'a', 'p', 'e', 'D',
    'i', 'm', 's', '_', 'n', 'o', 't', 'S', 'a', 'm', 'e', 'N', 'u', 'm', 'e',
    'l' };

  boolean_T b_bits_data[560];
  char_T s[7];
  int32_T exitg1;
  const mxArray *e_y;
  static const int32_T iv239[2] = { 1, 34 };

  char_T cv288[34];
  static const char_T cv289[34] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 'b', 'i',
    'n', '2', 'd', 'e', 'c', ':', 'I', 'l', 'l', 'e', 'g', 'a', 'l', 'B', 'i',
    'n', 'a', 'r', 'y', 'S', 't', 'r', 'i', 'n', 'g' };

  real_T varargin_1;
  real_T p2;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &b_st;
  d_st.tls = b_st.tls;
  e_st.prev = &st;
  e_st.tls = st.tls;

  /*  OFDMbits2letters: Convert input bits from a double array to ascii */
  /*  integers, which can be converted to letters by the char() function */
  /*  Make input into column */
  /* Trim extra bits */
  st.site = &qab_emlrtRSI;
  st.site = &qab_emlrtRSI;
  b_st.site = &m_emlrtRSI;
  c_st.site = &n_emlrtRSI;
  a = (real_T)(bits_size[0] * bits_size[1]) / 7.0;
  st.site = &qab_emlrtRSI;
  b_floor(&a);
  st.site = &qab_emlrtRSI;
  a *= 7.0;
  if (1.0 > a) {
    i32 = 0;
  } else {
    i32 = bits_size[0] * bits_size[1];
    emlrtDynamicBoundsCheckFastR2012b(1, 1, i32, &rb_emlrtBCI, sp);
    i32 = bits_size[0] * bits_size[1];
    i33 = (int32_T)a;
    i32 = emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &rb_emlrtBCI, sp);
  }

  emlrtVectorVectorIndexCheckR2012b(bits_size[0] * bits_size[1], 1, 1, i32,
    &x_emlrtECI, sp);

  /* Shape into letters */
  st.site = &rab_emlrtRSI;
  st.site = &rab_emlrtRSI;
  b_st.site = &m_emlrtRSI;
  c_st.site = &n_emlrtRSI;
  a = (real_T)i32 / 7.0;
  st.site = &rab_emlrtRSI;
  b_st.site = &tab_emlrtRSI;
  c_st.site = &uab_emlrtRSI;
  if (a != muDoubleScalarFloor(a)) {
    p = FALSE;
  } else {
    p = TRUE;
  }

  if (p) {
    c_st.site = &uab_emlrtRSI;
    p = TRUE;
  } else {
    p = FALSE;
  }

  if (p) {
  } else {
    y = NULL;
    m43 = mxCreateCharArray(2, iv237);
    for (i = 0; i < 28; i++) {
      cv284[i] = cv285[i];
    }

    emlrtInitCharArrayR2013a(&b_st, 28, m43, cv284);
    emlrtAssign(&y, m43);
    b_y = NULL;
    m43 = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
    *(int32_T *)mxGetData(m43) = MIN_int32_T;
    emlrtAssign(&b_y, m43);
    c_y = NULL;
    m43 = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
    *(int32_T *)mxGetData(m43) = MAX_int32_T;
    emlrtAssign(&c_y, m43);
    c_st.site = &uab_emlrtRSI;
    d_st.site = &bcb_emlrtRSI;
    c_error(&c_st, c_message(&d_st, y, b_y, c_y, &ac_emlrtMCI), &bc_emlrtMCI);
  }

  c_st.site = &ny_emlrtRSI;
  c_st.site = &ny_emlrtRSI;
  b_st.site = &ky_emlrtRSI;
  c_st.site = &af_emlrtRSI;
  maxdimlen = i32;
  if (1 > i32) {
    maxdimlen = 1;
  }

  b_st.site = &ky_emlrtRSI;
  c_st.site = &af_emlrtRSI;
  if (i32 < maxdimlen) {
  } else {
    maxdimlen = i32;
  }

  if (7 > maxdimlen) {
    b_st.site = &jy_emlrtRSI;
    c_eml_error(&b_st);
  }

  if ((int8_T)(int32_T)a > maxdimlen) {
    b_st.site = &jy_emlrtRSI;
    c_eml_error(&b_st);
  }

  b_st.site = &iy_emlrtRSI;
  c_st.site = &v_emlrtRSI;
  if (i32 == 7 * (int32_T)a) {
  } else {
    d_y = NULL;
    m43 = mxCreateCharArray(2, iv238);
    for (i = 0; i < 40; i++) {
      cv286[i] = cv287[i];
    }

    emlrtInitCharArrayR2013a(&st, 40, m43, cv286);
    emlrtAssign(&d_y, m43);
    b_st.site = &iy_emlrtRSI;
    e_st.site = &rbb_emlrtRSI;
    c_error(&b_st, b_message(&e_st, d_y, &tb_emlrtMCI), &ub_emlrtMCI);
  }

  b_st.site = &hy_emlrtRSI;
  c_st.site = &dg_emlrtRSI;
  for (maxdimlen = 0; maxdimlen + 1 <= i32; maxdimlen++) {
    y_data[maxdimlen] = bits_data[maxdimlen];
  }

  for (i32 = 0; i32 < 7; i32++) {
    maxdimlen = (int32_T)a;
    for (i33 = 0; i33 < maxdimlen; i33++) {
      b_bits_data[i33 + (int32_T)a * i32] = y_data[i32 + 7 * i33];
    }
  }

  /* Convert bits to letters */
  Letters_size[0] = (int32_T)a;
  maxdimlen = (int32_T)a;
  for (i32 = 0; i32 < maxdimlen; i32++) {
    Letters_data[i32] = 0.0;
  }

  i = 0;
  while (i <= (int32_T)a - 1) {
    st.site = &sab_emlrtRSI;
    i32 = (int32_T)a;
    i33 = 1 + i;
    emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &qb_emlrtBCI, &st);
    b_st.site = &of_emlrtRSI;
    b_st.site = &vab_emlrtRSI;
    for (maxdimlen = 0; maxdimlen < 7; maxdimlen++) {
      s[maxdimlen] = '0';
      if (b_bits_data[i + (int32_T)a * maxdimlen]) {
        s[maxdimlen] = '1';
      }
    }

    st.site = &sab_emlrtRSI;
    b_st.site = &wab_emlrtRSI;
    maxdimlen = 0;
    do {
      exitg1 = 0;
      if (maxdimlen < 7) {
        if ((s[maxdimlen] != '0') && (s[maxdimlen] != '1')) {
          p = FALSE;
          exitg1 = 1;
        } else {
          maxdimlen++;
        }
      } else {
        p = TRUE;
        exitg1 = 1;
      }
    } while (exitg1 == 0);

    if (p) {
    } else {
      e_y = NULL;
      m43 = mxCreateCharArray(2, iv239);
      for (maxdimlen = 0; maxdimlen < 34; maxdimlen++) {
        cv288[maxdimlen] = cv289[maxdimlen];
      }

      emlrtInitCharArrayR2013a(&st, 34, m43, cv288);
      emlrtAssign(&e_y, m43);
      b_st.site = &wab_emlrtRSI;
      e_st.site = &qbb_emlrtRSI;
      c_error(&b_st, b_message(&e_st, e_y, &cc_emlrtMCI), &dc_emlrtMCI);
    }

    b_st.site = &xab_emlrtRSI;
    varargin_1 = 0.0;
    p2 = 1.0;
    for (maxdimlen = 0; maxdimlen < 7; maxdimlen++) {
      if (s[6 - maxdimlen] == '1') {
        varargin_1 += p2;
      }

      p2 += p2;
    }

    st.site = &sab_emlrtRSI;
    i32 = (int32_T)varargin_1;
    emlrtDynamicBoundsCheckFastR2012b(i32, 0, 255, &emlrtBCI, &st);
    i32 = (int32_T)a;
    i33 = 1 + i;
    Letters_data[emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &sb_emlrtBCI, sp)
      - 1] = (int8_T)varargin_1;
    i++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }
}
Пример #19
0
/* Function Definitions */
void linearODESSEP2X4(const emxArray_real_T *T, const emxArray_real_T *I)
{
  int32_T i;
  real_T hoistedGlobal[9];
  int32_T j;
  int32_T b_i;
  real_T normA;
  real_T y[81];
  real_T F[81];
  boolean_T exitg2;
  real_T s;
  boolean_T exitg1;
  static const real_T theta[5] = { 0.01495585217958292, 0.253939833006323,
    0.95041789961629319, 2.097847961257068, 5.3719203511481517 };

  static const int8_T iv2[5] = { 3, 5, 7, 9, 13 };

  int32_T eint;
  real_T b_y[81];
  real_T beta1;
  char_T TRANSB;
  char_T TRANSA;
  ptrdiff_t m_t;
  ptrdiff_t n_t;
  ptrdiff_t k_t;
  ptrdiff_t lda_t;
  ptrdiff_t ldb_t;
  ptrdiff_t ldc_t;
  double * alpha1_t;
  double * Aia0_t;
  double * Bib0_t;
  double * beta1_t;
  double * Cic0_t;
  emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);

  /* global k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 k12 L1 L2 L3 L4 H1 H2 H3 H4 g1 g2 E1 E2 alpha A J Q; */
  /* Right */
  /* [C1,C2,C3,Q1,Q2,Q3,D1,D2,Z] */
  Q[0] = -k2 * A - L2 * J;
  Q[9] = L2 * J;
  Q[18] = 0.0;
  Q[27] = k2 * A;
  Q[36] = 0.0;
  Q[45] = 0.0;
  Q[54] = 0.0;
  Q[63] = 0.0;
  Q[72] = 0.0;
  Q[1] = L1;
  Q[10] = (-k4 * A - L1) - L4 * J;
  Q[19] = L4 * J;
  Q[28] = 0.0;
  Q[37] = k4 * A;
  Q[46] = 0.0;
  Q[55] = 0.0;
  Q[64] = 0.0;
  Q[73] = 0.0;
  Q[2] = 0.0;
  Q[11] = L3;
  Q[20] = -k6 * A - L3;
  Q[29] = 0.0;
  Q[38] = 0.0;
  Q[47] = k6 * A;
  Q[56] = 0.0;
  Q[65] = 0.0;
  Q[74] = 0.0;
  Q[3] = k1;
  Q[12] = 0.0;
  Q[21] = 0.0;
  Q[30] = (-k1 - L2 * J) - H2;
  Q[39] = L2 * J;
  Q[48] = 0.0;
  Q[57] = 0.0;
  Q[66] = H2;
  Q[75] = 0.0;
  Q[4] = 0.0;
  Q[13] = k3;
  Q[22] = 0.0;
  Q[31] = L1;
  Q[40] = (-k3 - L1) - L4 * J;
  Q[49] = L4 * J;
  Q[58] = 0.0;
  Q[67] = 0.0;
  Q[76] = 0.0;
  Q[5] = 0.0;
  Q[14] = 0.0;
  Q[23] = k5;
  Q[32] = 0.0;
  Q[41] = L3;
  Q[50] = -k5 - L3;
  Q[59] = 0.0;
  Q[68] = 0.0;
  Q[77] = 0.0;
  Q[6] = H1;
  Q[15] = 0.0;
  Q[24] = 0.0;
  Q[33] = 0.0;
  Q[42] = 0.0;
  Q[51] = 0.0;
  Q[60] = -k2 * A - H1;
  Q[69] = k2 * A;
  Q[78] = 0.0;
  Q[7] = 0.0;
  Q[16] = 0.0;
  Q[25] = 0.0;
  Q[34] = 0.0;
  Q[43] = 0.0;
  Q[52] = 0.0;
  Q[61] = k1;
  Q[70] = -k1 - H3;
  Q[79] = H3;
  Q[8] = H4;
  Q[17] = 0.0;
  Q[26] = 0.0;
  Q[35] = 0.0;
  Q[44] = 0.0;
  Q[53] = 0.0;
  Q[62] = 0.0;
  Q[71] = 0.0;
  Q[80] = -H4;
  Q_dirty |= 1U;
  emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
  i = 0;
  while (i <= T->size[0] - 1) {
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    memcpy(&hoistedGlobal[0], &p0[0], 9U * sizeof(real_T));
    j = T->size[0];
    b_i = (int32_T)(1.0 + (real_T)i);
    emlrtDynamicBoundsCheckFastR2012b(b_i, 1, j, &t_emlrtBCI, emlrtRootTLSGlobal);
    normA = T->data[i];
    for (j = 0; j < 81; j++) {
      y[j] = Q[j] * normA;
    }

    normA = 0.0;
    j = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (j < 9)) {
      s = 0.0;
      for (b_i = 0; b_i < 9; b_i++) {
        s += muDoubleScalarAbs(y[b_i + 9 * j]);
      }

      if (muDoubleScalarIsNaN(s)) {
        normA = rtNaN;
        exitg2 = TRUE;
      } else {
        if (s > normA) {
          normA = s;
        }

        j++;
      }
    }

    if (normA <= 5.3719203511481517) {
      b_i = 0;
      exitg1 = FALSE;
      while ((exitg1 == FALSE) && (b_i < 5)) {
        if (normA <= theta[b_i]) {
          emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
          PadeApproximantOfDegree(y, iv2[b_i], F);
          emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
          exitg1 = TRUE;
        } else {
          b_i++;
        }
      }
    } else {
      normA /= 5.3719203511481517;
      if ((!muDoubleScalarIsInf(normA)) && (!muDoubleScalarIsNaN(normA))) {
        normA = frexp(normA, &eint);
        j = eint;
      } else {
        j = 0;
      }

      s = j;
      if (normA == 0.5) {
        s = (real_T)j - 1.0;
      }

      normA = muDoubleScalarPower(2.0, s);
      emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
      for (j = 0; j < 81; j++) {
        b_y[j] = y[j] / normA;
      }

      PadeApproximantOfDegree(b_y, 13.0, F);
      emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
      emlrtForLoopVectorCheckR2012b(1.0, 1.0, s, mxDOUBLE_CLASS, (int32_T)s,
        &g_emlrtRTEI, emlrtRootTLSGlobal);
      for (j = 0; j < (int32_T)s; j++) {
        emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal);
        memcpy(&y[0], &F[0], 81U * sizeof(real_T));
        emlrtPushRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
        normA = 1.0;
        beta1 = 0.0;
        TRANSB = 'N';
        TRANSA = 'N';
        memset(&F[0], 0, 81U * sizeof(real_T));
        emlrtPushRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        m_t = (ptrdiff_t)(9);
        emlrtPopRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        n_t = (ptrdiff_t)(9);
        emlrtPopRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        k_t = (ptrdiff_t)(9);
        emlrtPopRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        lda_t = (ptrdiff_t)(9);
        emlrtPopRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        ldb_t = (ptrdiff_t)(9);
        emlrtPopRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        ldc_t = (ptrdiff_t)(9);
        emlrtPopRtStackR2012b(&rb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        alpha1_t = (double *)(&normA);
        emlrtPopRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        Aia0_t = (double *)(&y[0]);
        emlrtPopRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        Bib0_t = (double *)(&y[0]);
        emlrtPopRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&ob_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        beta1_t = (double *)(&beta1);
        emlrtPopRtStackR2012b(&ob_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        Cic0_t = (double *)(&F[0]);
        emlrtPopRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPushRtStackR2012b(&qb_emlrtRSI, emlrtRootTLSGlobal);
        emlrt_checkEscapedGlobals();
        dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t,
              Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t);
        emlrtPopRtStackR2012b(&qb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
      }
    }

    for (j = 0; j < 9; j++) {
      p0[j] = 0.0;
      for (b_i = 0; b_i < 9; b_i++) {
        p0[j] += hoistedGlobal[b_i] * F[b_i + 9 * j];
      }
    }

    p0_dirty |= 1U;
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    j = I->size[0];
    b_i = 1 + i;
    normA = Acell * 1.0E+12 * (g1 * p0[3] * (V - E1) + g2 * (p0[4] + p0[5]) * (V
      - E2)) - I->data[emlrtDynamicBoundsCheckFastR2012b(b_i, 1, j, &u_emlrtBCI,
      emlrtRootTLSGlobal) - 1];
    normA = muDoubleScalarAbs(normA);
    err += normA * normA;
    err_dirty |= 1U;
    i++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal);
  }
}
Пример #20
0
/* Function Definitions */
static boolean_T b_MACLayerTransmitter(testMACTransmitterStackData *SD, const
  emlrtStack *sp, comm_AGC *ObjAGC, comm_SDRuReceiver *ObjSDRuReceiver,
  comm_SDRuTransmitter *ObjSDRuTransmitter, commcodegen_CRCDetector *ObjDetect,
  OFDMDemodulator_1 *ObjPreambleDemod, OFDMDemodulator_1 *ObjDataDemod, const
  c_struct_T *estimate, const e_struct_T *tx, const real_T messageBits_data[563],
  char_T previousMessage_data[77], int32_T previousMessage_size[2])
{
  boolean_T msgStatus;
  int32_T tries;
  int32_T state;
  real_T decisions[10];
  real_T destNodeID;
  int16_T i36;
  comm_SDRuTransmitter *obj;
  boolean_T flag;
  boolean_T exitg1;
  comm_AGC *b_ObjAGC;
  comm_SDRuReceiver *b_ObjSDRuReceiver;
  commcodegen_CRCDetector *b_ObjDetect;
  OFDMDemodulator_1 *b_ObjPreambleDemod;
  OFDMDemodulator_1 *b_ObjDataDemod;
  int32_T originNodeID;
  real_T timeouts;
  int32_T Response_size[2];
  int32_T exitg10;
  boolean_T guard1 = FALSE;
  static const char_T b[7] = { 'T', 'i', 'm', 'e', 'o', 'u', 't' };

  char_T Response_data[80];
  int32_T messageBits_size[2];
  real_T b_messageBits_data[563];
  int8_T sza[2];
  int32_T exitg16;
  int32_T exitg15;
  static const char_T cv343[7] = { 'T', 'i', 'm', 'e', 'o', 'u', 't' };

  int32_T exitg14;
  int32_T exitg13;
  static const char_T cv344[9] = { 'C', 'R', 'C', ' ', 'E', 'r', 'r', 'o', 'r' };

  int8_T szb[2];
  int32_T exitg12;
  int32_T exitg11;
  int32_T loop_ub;
  static const char_T b_b[9] = { 'D', 'u', 'p', 'l', 'i', 'c', 'a', 't', 'e' };

  char_T b_Response_data[80];
  int32_T exitg9;
  int32_T exitg8;
  boolean_T b_guard1 = FALSE;
  int32_T exitg7;
  int32_T exitg6;
  static const char_T cv345[9] = { 'D', 'u', 'p', 'l', 'i', 'c', 'a', 't', 'e' };

  int32_T exitg5;
  int32_T exitg4;
  int32_T exitg3;
  int32_T exitg2;
  static const char_T cv346[3] = { 'A', 'C', 'K' };

  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;

  /*            %Objects */
  /*          %Structs */
  /*   %Values/Vectors */
  /* % This function is called when the node wants to transmit something */
  /*  % Sense spectrum and wait until it is unoccupied */
  for (tries = 0; tries < 4; tries++) {
    /*  try only so many times */
    for (state = 0; state < 10; state++) {
      st.site = &xl_emlrtRSI;
      SpectrumSenseP25(SD, &st, ObjAGC, ObjSDRuReceiver, decisions);
      destNodeID = muDoubleScalarRound(decisions[state]);
      if (destNodeID < 32768.0) {
        if (destNodeID >= -32768.0) {
          i36 = (int16_T)destNodeID;
        } else {
          i36 = MIN_int16_T;
        }
      } else if (destNodeID >= 32768.0) {
        i36 = MAX_int16_T;
      } else {
        i36 = 0;
      }

      st.site = &yl_emlrtRSI;
      d_fprintf(&st, (int16_T)(1 + state), i36);
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    /*      if occupied */
    /*          fprintf('MAC| Spectrum occupied, listening...\n'); */
    /*          %Recover signal and/or wait */
    /*          lookingForACK = false; */
    /*          %MACLayerReceiver(PHY,lookingForACK); */
    /*      else% Yay we can transmit now */
    /*          break; */
    /*      end     */
    /*      if tries >=4 */
    /*          fprintf('MAC| Spectrum Busy, try again later\n'); */
    /*          return; */
    /*      end */
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  msgStatus = FALSE;

  /*  Adjust offset for node */
  st.site = &am_emlrtRSI;
  f_fprintf(&st, 1, tx->offsetTable[0]);
  st.site = &bm_emlrtRSI;
  obj = ObjSDRuTransmitter;
  b_st.site = &gb_emlrtRSI;
  obj->CenterFrequency = 2.24E+9 + tx->offsetTable[0];
  c_st.site = &ck_emlrtRSI;
  b_st.site = &gb_emlrtRSI;
  if (obj->isInitialized && (!obj->isReleased)) {
    flag = TRUE;
  } else {
    flag = FALSE;
  }

  if (flag) {
    obj->TunablePropsChanged = TRUE;
    obj->tunablePropertyChanged[1] = TRUE;
  }

  /* % Spectrum clear, send message */
  tries = 0;
  exitg1 = FALSE;
  while ((exitg1 == FALSE) && (tries < 4)) {
    /*  Send message */
    /* %originator */
    /* %destination */
    st.site = &cm_emlrtRSI;
    PHYTransmit(SD, &st, ObjSDRuTransmitter, ObjSDRuReceiver, tx->nodeNum);

    /*  Listen for acknowledgement */
    /* fprintf('###########################################\n'); */
    st.site = &dm_emlrtRSI;
    h_fprintf(&st);

    /*  Call Receiver */
    /*            %Objects */
    /*          %Structs */
    /*   %Values/Vectors */
    st.site = &em_emlrtRSI;
    b_ObjAGC = ObjAGC;
    b_ObjSDRuReceiver = ObjSDRuReceiver;
    obj = ObjSDRuTransmitter;
    b_ObjDetect = ObjDetect;
    b_ObjPreambleDemod = ObjPreambleDemod;
    b_ObjDataDemod = ObjDataDemod;

    /*            %Objects */
    /*          %Structs */
    /*   %Values/Vectors */
    /*  This function is called when the node is just listening to the spectrum */
    /*  waiting for a message to be transmitted to them */
    /* % Listen to the spectrum */
    /*  previousMessage will be updated for next run */
    /*            %Objects */
    /*          %Structs */
    /*   %Values/Vectors */
    b_st.site = &rt_emlrtRSI;

    /*            %Objects */
    /*          %Structs */
    /*   %Values/Vectors */
    /* Initialize values */
    originNodeID = -1;
    destNodeID = -1.0;

    /*  0 = Call PHY Receiver */
    /*  1 = Timeout */
    /*  2 = Corrupt Message */
    /*  3 = Message Reception Successfull */
    /*  Duplicates are checked at the last stage */
    state = 0;

    /*  Initial state */
    timeouts = 0.0;

    /*  Counter */
    /*  Message string holder */
    emlrtDimSizeGeqCheckFastR2012b(80, 0, &y_emlrtECI, &b_st);
    Response_size[0] = 1;
    Response_size[1] = 0;

    /*  Run system */
    do {
      exitg10 = 0;

      /*     %% Process Messages */
      guard1 = FALSE;
      switch (state) {
       case 0:
        /* Wait for message */
        if (timeouts > 10.0) {
          emlrtDimSizeGeqCheckFastR2012b(80, 7, &db_emlrtECI, &b_st);
          Response_size[0] = 1;
          Response_size[1] = 7;
          for (state = 0; state < 7; state++) {
            Response_data[state] = b[state];
          }

          exitg10 = 1;
        } else {
          /*  Call Physical Layer */
          /*            %Objects */
          /*          %Structs */
          /*   %Values/Vectors */
          SD->f15.estimate = *estimate;
          messageBits_size[0] = 1;
          messageBits_size[1] = 563;
          memcpy(&b_messageBits_data[0], &messageBits_data[0], 563U * sizeof
                 (real_T));
          c_st.site = &eu_emlrtRSI;
          PHYReceive(SD, &c_st, b_ObjAGC, b_ObjSDRuReceiver, b_ObjDetect,
                     b_ObjPreambleDemod, b_ObjDataDemod, &SD->f15.estimate,
                     tx->shortPreambleOFDM, tx->longPreamble, tx->pilots,
                     tx->pilotLocationsWithoutGuardbands,
                     tx->dataSubcarrierIndexies.data,
                     tx->dataSubcarrierIndexies.size, b_messageBits_data,
                     messageBits_size, Response_data, Response_size);

          /*  Choose next state */
          c_st.site = &fu_emlrtRSI;
          flag = FALSE;
          for (state = 0; state < 2; state++) {
            sza[state] = (int8_T)Response_size[state];
          }

          state = 0;
          do {
            exitg16 = 0;
            if (state < 2) {
              if (sza[state] != 1 + 6 * state) {
                exitg16 = 1;
              } else {
                state++;
              }
            } else {
              state = 0;
              exitg16 = 2;
            }
          } while (exitg16 == 0);

          if (exitg16 == 1) {
          } else {
            do {
              exitg15 = 0;
              if (state <= Response_size[1] - 1) {
                if (Response_data[state] != cv343[state]) {
                  exitg15 = 1;
                } else {
                  state++;
                }
              } else {
                flag = TRUE;
                exitg15 = 1;
              }
            } while (exitg15 == 0);
          }

          if (flag) {
            state = 1;
          } else {
            c_st.site = &gu_emlrtRSI;
            flag = FALSE;
            for (state = 0; state < 2; state++) {
              sza[state] = (int8_T)Response_size[state];
            }

            state = 0;
            do {
              exitg14 = 0;
              if (state < 2) {
                if (sza[state] != 1 + (state << 3)) {
                  exitg14 = 1;
                } else {
                  state++;
                }
              } else {
                state = 0;
                exitg14 = 2;
              }
            } while (exitg14 == 0);

            if (exitg14 == 1) {
            } else {
              do {
                exitg13 = 0;
                if (state <= Response_size[1] - 1) {
                  if (Response_data[state] != cv344[state]) {
                    exitg13 = 1;
                  } else {
                    state++;
                  }
                } else {
                  flag = TRUE;
                  exitg13 = 1;
                }
              } while (exitg13 == 0);
            }

            if (flag || (Response_size[1] == 0)) {
              state = 2;
            } else {
              /*  Successfully decoded */
              state = 3;
            }
          }

          /*  Timeout occured     */
          guard1 = TRUE;
        }
        break;

       case 1:
        timeouts++;
        if (timeouts > 10.0) {
          /* if DebugFlag;fprintf('DL| Max timeouts reached\n');end */
          c_st.site = &du_emlrtRSI;
          l_fprintf(&c_st);
          emlrtDimSizeGeqCheckFastR2012b(80, 7, &cb_emlrtECI, &b_st);
          Response_size[0] = 1;
          Response_size[1] = 7;
          for (state = 0; state < 7; state++) {
            Response_data[state] = b[state];
          }

          exitg10 = 1;
        } else {
          state = 0;

          /* Get another message */
          /*  Message corrupted     */
          guard1 = TRUE;
        }
        break;

       case 2:
        timeouts += 0.01;
        state = 0;

        /* Get another message */
        /*  Default: Message successfully received     */
        guard1 = TRUE;
        break;

       case 3:
        /* otherwise */
        /* disp(['DL| MSG: ',Response]) */
        /* disp(['DL| Timeouts: ',num2str(timeouts)]) */
        /*  Final Duplication check */
        c_st.site = &bu_emlrtRSI;
        flag = FALSE;
        for (state = 0; state < 2; state++) {
          sza[state] = (int8_T)previousMessage_size[state];
        }

        for (state = 0; state < 2; state++) {
          szb[state] = (int8_T)Response_size[state];
        }

        state = 0;
        do {
          exitg12 = 0;
          if (state < 2) {
            if (sza[state] != szb[state]) {
              exitg12 = 1;
            } else {
              state++;
            }
          } else {
            state = 0;
            exitg12 = 2;
          }
        } while (exitg12 == 0);

        if (exitg12 == 1) {
        } else {
          do {
            exitg11 = 0;
            if (state <= previousMessage_size[1] - 1) {
              if (previousMessage_data[state] != Response_data[state]) {
                exitg11 = 1;
              } else {
                state++;
              }
            } else {
              flag = TRUE;
              exitg11 = 1;
            }
          } while (exitg11 == 0);
        }

        if (flag) {
          /* Dupe */
          /* if DebugFlag;fprintf('DL| Duplicate Message\n');end */
          c_st.site = &cu_emlrtRSI;
          j_fprintf(&c_st);
          previousMessage_size[0] = 1;
          previousMessage_size[1] = Response_size[1];
          loop_ub = Response_size[1];
          for (state = 0; state < loop_ub; state++) {
            previousMessage_data[previousMessage_size[0] * state] =
              Response_data[Response_size[0] * state];
          }

          /* Update history for next iteration */
          state = Response_size[1] - 2;
          originNodeID = (uint8_T)
            Response_data[emlrtDynamicBoundsCheckFastR2012b(state, 1,
            Response_size[1], &wb_emlrtBCI, &b_st) - 1] - 48;

          /* extract node ID and convert char to number */
          state = Response_size[1] - 1;
          destNodeID = (real_T)(uint8_T)
            Response_data[emlrtDynamicBoundsCheckFastR2012b(state, 1,
            Response_size[1], &xb_emlrtBCI, &b_st) - 1] - 48.0;

          /* extract node ID and convert char to number */
          emlrtDimSizeGeqCheckFastR2012b(80, 9, &ab_emlrtECI, &b_st);
          Response_size[0] = 1;
          Response_size[1] = 9;
          for (state = 0; state < 9; state++) {
            Response_data[state] = b_b[state];
          }

          /* Tell upper layers duplicate */
        } else {
          /* No Dupe */
          previousMessage_size[0] = 1;
          previousMessage_size[1] = Response_size[1];
          loop_ub = Response_size[1];
          for (state = 0; state < loop_ub; state++) {
            previousMessage_data[previousMessage_size[0] * state] =
              Response_data[Response_size[0] * state];
          }

          /* Update history for next iteration */
          state = Response_size[1] - 2;
          originNodeID = (uint8_T)
            Response_data[emlrtDynamicBoundsCheckFastR2012b(state, 1,
            Response_size[1], &ub_emlrtBCI, &b_st) - 1] - 48;

          /* extract node ID and convert char to number */
          state = Response_size[1] - 1;
          destNodeID = (real_T)(uint8_T)
            Response_data[emlrtDynamicBoundsCheckFastR2012b(state, 1,
            Response_size[1], &vb_emlrtBCI, &b_st) - 1] - 48.0;

          /* extract node ID and convert char to number */
          if (1 > Response_size[1] - 3) {
            loop_ub = 0;
          } else {
            emlrtDynamicBoundsCheckFastR2012b(1, 1, Response_size[1],
              &tb_emlrtBCI, &b_st);
            state = Response_size[1] - 3;
            loop_ub = emlrtDynamicBoundsCheckFastR2012b(state, 1, Response_size
              [1], &tb_emlrtBCI, &b_st);
          }

          emlrtDimSizeGeqCheckFastR2012b(80, loop_ub, &bb_emlrtECI, &b_st);
          for (state = 0; state < loop_ub; state++) {
            b_Response_data[state] = Response_data[state];
          }

          Response_size[0] = 1;
          Response_size[1] = loop_ub;
          for (state = 0; state < loop_ub; state++) {
            Response_data[state] = b_Response_data[state];
          }

          /* Remove identifer key and nodeIDs */
        }

        exitg10 = 1;
        break;

       default:
        guard1 = TRUE;
        break;
      }

      if (guard1 == TRUE) {
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, &b_st);
      }
    } while (exitg10 == 0);

    /*  Final check */
    c_st.site = &hu_emlrtRSI;
    if (muDoubleScalarAbs(destNodeID) > 3.0) {
      destNodeID = tx->nodeNum;

      /*  Something went wrong, probably corrupt message, reset to self */
    }

    /* % Possible response messages */
    /*  1.) Timeout */
    /*  2.) Some message */
    b_st.site = &st_emlrtRSI;
    flag = FALSE;
    for (state = 0; state < 2; state++) {
      sza[state] = (int8_T)Response_size[state];
    }

    state = 0;
    do {
      exitg9 = 0;
      if (state < 2) {
        if (sza[state] != 1 + 6 * state) {
          exitg9 = 1;
        } else {
          state++;
        }
      } else {
        state = 0;
        exitg9 = 2;
      }
    } while (exitg9 == 0);

    if (exitg9 == 1) {
    } else {
      do {
        exitg8 = 0;
        if (state <= Response_size[1] - 1) {
          if (Response_data[state] != cv343[state]) {
            exitg8 = 1;
          } else {
            state++;
          }
        } else {
          flag = TRUE;
          exitg8 = 1;
        }
      } while (exitg8 == 0);
    }

    b_guard1 = FALSE;
    if (!flag) {
      b_st.site = &st_emlrtRSI;
      flag = FALSE;
      for (state = 0; state < 2; state++) {
        sza[state] = (int8_T)Response_size[state];
      }

      state = 0;
      do {
        exitg7 = 0;
        if (state < 2) {
          if (sza[state] != 1 + (state << 3)) {
            exitg7 = 1;
          } else {
            state++;
          }
        } else {
          state = 0;
          exitg7 = 2;
        }
      } while (exitg7 == 0);

      if (exitg7 == 1) {
      } else {
        do {
          exitg6 = 0;
          if (state <= Response_size[1] - 1) {
            if (Response_data[state] != cv345[state]) {
              exitg6 = 1;
            } else {
              state++;
            }
          } else {
            flag = TRUE;
            exitg6 = 1;
          }
        } while (exitg6 == 0);
      }

      if (!flag) {
        /* fprintf('###########################################\n'); */
        b_st.site = &tt_emlrtRSI;
        n_fprintf(&b_st, Response_data, Response_size);
        b_st.site = &ut_emlrtRSI;
        p_fprintf(&b_st, (int16_T)originNodeID);
      } else {
        b_guard1 = TRUE;
      }
    } else {
      b_guard1 = TRUE;
    }

    if (b_guard1 == TRUE) {
      b_st.site = &vt_emlrtRSI;
      flag = FALSE;
      for (state = 0; state < 2; state++) {
        sza[state] = (int8_T)Response_size[state];
      }

      state = 0;
      do {
        exitg5 = 0;
        if (state < 2) {
          if (sza[state] != 1 + (state << 3)) {
            exitg5 = 1;
          } else {
            state++;
          }
        } else {
          state = 0;
          exitg5 = 2;
        }
      } while (exitg5 == 0);

      if (exitg5 == 1) {
      } else {
        do {
          exitg4 = 0;
          if (state <= Response_size[1] - 1) {
            if (Response_data[state] != cv345[state]) {
              exitg4 = 1;
            } else {
              state++;
            }
          } else {
            flag = TRUE;
            exitg4 = 1;
          }
        } while (exitg4 == 0);
      }

      if (flag) {
        b_st.site = &wt_emlrtRSI;
        r_fprintf(&b_st);

        /*     %% Send ACK */
        b_st.site = &xt_emlrtRSI;
        f_fprintf(&b_st, (int16_T)originNodeID, tx->
                  offsetTable[emlrtDynamicBoundsCheckFastR2012b(originNodeID, 1,
                   3, &yb_emlrtBCI, &st) - 1]);
        b_st.site = &yt_emlrtRSI;
        c_st.site = &gb_emlrtRSI;
        obj->CenterFrequency = 2.24E+9 + tx->offsetTable[originNodeID - 1];
        c_st.site = &gb_emlrtRSI;
        if (obj->isInitialized && (!obj->isReleased)) {
          flag = TRUE;
        } else {
          flag = FALSE;
        }

        if (flag) {
          obj->TunablePropsChanged = TRUE;
          obj->tunablePropertyChanged[1] = TRUE;
        }

        /*  Adjust offset for node */
        b_st.site = &au_emlrtRSI;
        b_PHYTransmit(SD, &b_st, obj, b_ObjSDRuReceiver, originNodeID,
                      destNodeID);
      }
    }

    st.site = &fm_emlrtRSI;
    flag = FALSE;
    for (state = 0; state < 2; state++) {
      sza[state] = (int8_T)Response_size[state];
    }

    state = 0;
    do {
      exitg3 = 0;
      if (state < 2) {
        if (sza[state] != 1 + (state << 1)) {
          exitg3 = 1;
        } else {
          state++;
        }
      } else {
        state = 0;
        exitg3 = 2;
      }
    } while (exitg3 == 0);

    if (exitg3 == 1) {
    } else {
      do {
        exitg2 = 0;
        if (state <= Response_size[1] - 1) {
          if (Response_data[state] != cv346[state]) {
            exitg2 = 1;
          } else {
            state++;
          }
        } else {
          flag = TRUE;
          exitg2 = 1;
        }
      } while (exitg2 == 0);
    }

    if (flag) {
      st.site = &gm_emlrtRSI;
      t_fprintf(&st);
      msgStatus = TRUE;
      exitg1 = TRUE;
    } else {
      st.site = &hm_emlrtRSI;
      v_fprintf(&st);
      if (tries + 1 >= 4) {
        st.site = &im_emlrtRSI;
        x_fprintf(&st);
        st.site = &jm_emlrtRSI;
        ab_fprintf(&st);
        st.site = &km_emlrtRSI;
        x_fprintf(&st);
        exitg1 = TRUE;
      } else {
        tries++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
      }
    }
  }

  return msgStatus;
}
Пример #21
0
/* Function Definitions */
void CalculateABBStarD(const emlrtStack *sp, real_T N, const emxArray_real_T *t,
  const emxArray_real_T *gridT, const emxArray_real_T *x, const emxArray_real_T *
  f, emxArray_real_T *A, emxArray_real_T *B, emxArray_real_T *Bstar,
  emxArray_real_T *D)
{
  int32_T i4;
  real_T d1;
  real_T d2;
  int32_T loop_ub;
  int32_T i;
  emxArray_real_T *a;
  int32_T j;
  int32_T deltaij;
  int32_T b_A;
  real_T d3;
  real_T d4;
  real_T b1j0i;
  real_T b1j1i;
  int32_T i5;
  int32_T i6;
  int32_T i7;
  int32_T i8;
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);

  /*  Calculate A and B, B*, and D */
  /*  N is the number of time points */
  /*  grid T is the time points grid on which the solution is calculated  */
  /*  f is the multiplicative function for the source f(x,t)*r(t), size [N, */
  /*  N0], with N0 the number of space points */
  i4 = A->size[0] * A->size[1];
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &j_emlrtDCI, sp);
  A->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &i_emlrtDCI, sp);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &l_emlrtDCI, sp);
  A->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &k_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)A, i4, (int32_T)sizeof(real_T),
                    &b_emlrtRTEI);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &j_emlrtDCI, sp);
  d2 = 2.0 * N;
  d2 = emlrtNonNegativeCheckFastR2012b(d2, &l_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(d1, &i_emlrtDCI, sp) * (int32_T)
    emlrtIntegerCheckFastR2012b(d2, &k_emlrtDCI, sp);
  for (i4 = 0; i4 < loop_ub; i4++) {
    A->data[i4] = 0.0;
  }

  i4 = B->size[0] * B->size[1];
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &n_emlrtDCI, sp);
  B->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &m_emlrtDCI, sp);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &p_emlrtDCI, sp);
  B->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &o_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)B, i4, (int32_T)sizeof(real_T),
                    &b_emlrtRTEI);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &n_emlrtDCI, sp);
  d2 = 2.0 * N;
  d2 = emlrtNonNegativeCheckFastR2012b(d2, &p_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(d1, &m_emlrtDCI, sp) * (int32_T)
    emlrtIntegerCheckFastR2012b(d2, &o_emlrtDCI, sp);
  for (i4 = 0; i4 < loop_ub; i4++) {
    B->data[i4] = 0.0;
  }

  i4 = Bstar->size[0] * Bstar->size[1];
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &r_emlrtDCI, sp);
  Bstar->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &q_emlrtDCI, sp);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &t_emlrtDCI, sp);
  Bstar->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &s_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)Bstar, i4, (int32_T)sizeof(real_T),
                    &b_emlrtRTEI);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &r_emlrtDCI, sp);
  d2 = 2.0 * N;
  d2 = emlrtNonNegativeCheckFastR2012b(d2, &t_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(d1, &q_emlrtDCI, sp) * (int32_T)
    emlrtIntegerCheckFastR2012b(d2, &s_emlrtDCI, sp);
  for (i4 = 0; i4 < loop_ub; i4++) {
    Bstar->data[i4] = 0.0;
  }

  i4 = D->size[0] * D->size[1];
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &v_emlrtDCI, sp);
  D->size[0] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &u_emlrtDCI, sp);
  d1 = emlrtNonNegativeCheckFastR2012b(N, &x_emlrtDCI, sp);
  D->size[1] = (int32_T)emlrtIntegerCheckFastR2012b(d1, &w_emlrtDCI, sp);
  emxEnsureCapacity(sp, (emxArray__common *)D, i4, (int32_T)sizeof(real_T),
                    &b_emlrtRTEI);
  d1 = 2.0 * N;
  d1 = emlrtNonNegativeCheckFastR2012b(d1, &v_emlrtDCI, sp);
  d2 = emlrtNonNegativeCheckFastR2012b(N, &x_emlrtDCI, sp);
  loop_ub = (int32_T)emlrtIntegerCheckFastR2012b(d1, &u_emlrtDCI, sp) * (int32_T)
    emlrtIntegerCheckFastR2012b(d2, &w_emlrtDCI, sp);
  for (i4 = 0; i4 < loop_ub; i4++) {
    D->data[i4] = 0.0;
  }

  emlrtForLoopVectorCheckR2012b(1.0, 1.0, N, mxDOUBLE_CLASS, (int32_T)N,
    &dc_emlrtRTEI, sp);
  i = 0;
  emxInit_real_T(sp, &a, 2, &c_emlrtRTEI, true);
  while (i <= (int32_T)N - 1) {
    /*  time */
    emlrtForLoopVectorCheckR2012b(1.0, 1.0, N, mxDOUBLE_CLASS, (int32_T)N,
      &cc_emlrtRTEI, sp);
    j = 0;
    while (j <= (int32_T)N - 1) {
      /*  time */
      deltaij = (1.0 + (real_T)i == 1.0 + (real_T)j);
      d1 = 2.0 * (1.0 + (real_T)i);
      loop_ub = A->size[0];
      d2 = 2.0 * (1.0 + (real_T)j);
      b_A = A->size[1];
      i4 = t->size[1];
      st.site = &n_emlrtRSI;
      d3 = Acoeff(&st, 0.0, 1.0 + (real_T)j, 0.0, t->
                  data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &qb_emlrtBCI, sp) - 1], gridT);
      i4 = t->size[1];
      st.site = &n_emlrtRSI;
      d4 = Acoeff(&st, 1.0, 1.0 + (real_T)j, 0.0, t->
                  data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &rb_emlrtBCI, sp) - 1], gridT);
      i4 = t->size[1];
      st.site = &o_emlrtRSI;
      b1j0i = Acoeff(&st, 0.0, 1.0 + (real_T)j, 1.0, t->
                     data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &sb_emlrtBCI, sp) - 1], gridT);
      i4 = t->size[1];
      st.site = &o_emlrtRSI;
      b1j1i = Acoeff(&st, 1.0, 1.0 + (real_T)j, 1.0, t->
                     data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &tb_emlrtBCI, sp) - 1], gridT);
      i4 = (int32_T)(d1 + -1.0);
      i5 = (int32_T)(d2 + -1.0);
      A->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &ub_emlrtBCI,
                sp) + A->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &vb_emlrtBCI, sp) - 1)) - 1] = d3;
      i4 = (int32_T)(d1 + -1.0);
      i5 = (int32_T)d2;
      A->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &ub_emlrtBCI,
                sp) + A->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &vb_emlrtBCI, sp) - 1)) - 1] = d4;
      i4 = (int32_T)d1;
      i5 = (int32_T)(d2 + -1.0);
      A->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &ub_emlrtBCI,
                sp) + A->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &vb_emlrtBCI, sp) - 1)) - 1] = b1j0i;
      i4 = (int32_T)d1;
      i5 = (int32_T)d2;
      A->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &ub_emlrtBCI,
                sp) + A->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &vb_emlrtBCI, sp) - 1)) - 1] = b1j1i;

      /*  temp terms */
      i4 = t->size[1];
      st.site = &p_emlrtRSI;
      b1j0i = Bcoeff(&st, 1.0, 1.0 + (real_T)j, 0.0, t->
                     data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &wb_emlrtBCI, sp) - 1], gridT);
      i4 = t->size[1];
      st.site = &q_emlrtRSI;
      b1j1i = Bcoeff(&st, 1.0, 1.0 + (real_T)j, 1.0, t->
                     data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &xb_emlrtBCI, sp) - 1], gridT);
      d1 = 2.0 * (1.0 + (real_T)i);
      loop_ub = B->size[0];
      d2 = 2.0 * (1.0 + (real_T)j);
      b_A = B->size[1];
      i4 = t->size[1];
      st.site = &r_emlrtRSI;
      d3 = Bcoeff(&st, 0.0, 1.0 + (real_T)j, 0.0, t->
                  data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &yb_emlrtBCI, sp) - 1], gridT);
      i4 = t->size[1];
      st.site = &s_emlrtRSI;
      d4 = Bcoeff(&st, 0.0, 1.0 + (real_T)j, 1.0, t->
                  data[emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i4,
        &ac_emlrtBCI, sp) - 1], gridT);
      i4 = (int32_T)(d1 + -1.0);
      i5 = (int32_T)(d2 + -1.0);
      B->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &bc_emlrtBCI,
                sp) + B->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &cc_emlrtBCI, sp) - 1)) - 1] = d3 + 0.5 * (real_T)deltaij;
      i4 = (int32_T)(d1 + -1.0);
      i5 = (int32_T)d2;
      B->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &bc_emlrtBCI,
                sp) + B->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &cc_emlrtBCI, sp) - 1)) - 1] = b1j0i;
      i4 = (int32_T)d1;
      i5 = (int32_T)(d2 + -1.0);
      B->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &bc_emlrtBCI,
                sp) + B->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &cc_emlrtBCI, sp) - 1)) - 1] = d4;
      i4 = (int32_T)d1;
      i5 = (int32_T)d2;
      B->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub, &bc_emlrtBCI,
                sp) + B->size[0] * (emlrtDynamicBoundsCheckFastR2012b(i5, 1, b_A,
                 &cc_emlrtBCI, sp) - 1)) - 1] = b1j1i + 0.5 * (real_T)deltaij;
      d1 = 2.0 * (1.0 + (real_T)i);
      loop_ub = Bstar->size[0];
      d2 = 2.0 * (1.0 + (real_T)j);
      b_A = Bstar->size[1];
      i4 = (int32_T)(d1 + -1.0);
      i5 = (int32_T)(d2 + -1.0);
      Bstar->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub,
        &dc_emlrtBCI, sp) + Bstar->size[0] * (emlrtDynamicBoundsCheckFastR2012b
        (i5, 1, b_A, &ec_emlrtBCI, sp) - 1)) - 1] = b1j0i;
      i4 = (int32_T)(d1 + -1.0);
      i5 = (int32_T)d2;
      Bstar->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub,
        &dc_emlrtBCI, sp) + Bstar->size[0] * (emlrtDynamicBoundsCheckFastR2012b
        (i5, 1, b_A, &ec_emlrtBCI, sp) - 1)) - 1] = -b1j0i;
      i4 = (int32_T)d1;
      i5 = (int32_T)(d2 + -1.0);
      Bstar->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub,
        &dc_emlrtBCI, sp) + Bstar->size[0] * (emlrtDynamicBoundsCheckFastR2012b
        (i5, 1, b_A, &ec_emlrtBCI, sp) - 1)) - 1] = b1j1i + (real_T)deltaij /
        2.0;
      i4 = (int32_T)d1;
      i5 = (int32_T)d2;
      Bstar->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, loop_ub,
        &dc_emlrtBCI, sp) + Bstar->size[0] * (emlrtDynamicBoundsCheckFastR2012b
        (i5, 1, b_A, &ec_emlrtBCI, sp) - 1)) - 1] = -b1j1i - 0.5 * (real_T)
        deltaij;
      st.site = &t_emlrtRSI;
      i4 = t->size[1];
      i5 = i + 1;
      emlrtDynamicBoundsCheckFastR2012b(i5, 1, i4, &pb_emlrtBCI, &st);
      i4 = f->size[0];
      i5 = i + 1;
      emlrtDynamicBoundsCheckFastR2012b(i5, 1, i4, &ob_emlrtBCI, &st);

      /*  Calculate the integral int_0^1(f(y,t_j)*A_{yj}(x,t)dy) by midpoint */
      /*  integration rule */
      /*  the spatial integration of all points y at time t_j */
      i4 = a->size[0] * a->size[1];
      a->size[0] = 1;
      emxEnsureCapacity(&st, (emxArray__common *)a, i4, (int32_T)sizeof(real_T),
                        &b_emlrtRTEI);
      loop_ub = x->size[1];
      i4 = a->size[0] * a->size[1];
      a->size[1] = loop_ub;
      emxEnsureCapacity(&st, (emxArray__common *)a, i4, (int32_T)sizeof(real_T),
                        &b_emlrtRTEI);
      loop_ub = x->size[1];
      for (i4 = 0; i4 < loop_ub; i4++) {
        a->data[i4] = 0.0;
      }

      b1j0i = 0.0;
      loop_ub = x->size[1];
      emlrtDynamicBoundsCheckFastR2012b(1, 1, loop_ub, &jb_emlrtBCI, &st);
      i4 = x->size[1];
      emlrtDynamicBoundsCheckFastR2012b(1, 1, i4, &kb_emlrtBCI, &st);
      b_st.site = &v_emlrtRSI;
      a->data[0] = Acoeff(&b_st, x->data[0], 1.0 + (real_T)j, 0.0, t->data[i],
                          gridT);

      /*  y = 0:1/(numel(y)-2):1; */
      i4 = f->size[1];
      loop_ub = 2;
      while (loop_ub - 2 <= i4 - 2) {
        i5 = a->size[1];
        b_A = x->size[1];
        b_st.site = &w_emlrtRSI;
        a->data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i5, &gc_emlrtBCI,
          &st) - 1] = Acoeff(&b_st, x->data[emlrtDynamicBoundsCheckFastR2012b
                             (loop_ub, 1, b_A, &hc_emlrtBCI, &st) - 1], 1.0 +
                             (real_T)j, 0.0, t->data[i], gridT);
        i5 = f->size[1];
        emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i5, &ib_emlrtBCI, &st);
        i5 = f->size[1];
        b_A = loop_ub - 1;
        emlrtDynamicBoundsCheckFastR2012b(b_A, 1, i5, &hb_emlrtBCI, &st);
        i5 = a->size[1];
        b_A = a->size[1];
        deltaij = loop_ub - 1;
        i6 = x->size[1];
        i7 = x->size[1];
        i8 = loop_ub - 1;
        b1j0i += 0.5 * (a->data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i5,
          &ic_emlrtBCI, &st) - 1] * f->data[i + f->size[0] * (loop_ub - 1)] +
                        a->data[emlrtDynamicBoundsCheckFastR2012b(deltaij, 1,
          b_A, &jc_emlrtBCI, &st) - 1] * f->data[i + f->size[0] * (loop_ub - 2)])
          * (x->data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i6,
              &kc_emlrtBCI, &st) - 1] - x->
             data[emlrtDynamicBoundsCheckFastR2012b(i8, 1, i7, &lc_emlrtBCI, &st)
             - 1]);
        loop_ub++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, &st);
      }

      st.site = &u_emlrtRSI;
      i4 = t->size[1];
      i5 = i + 1;
      emlrtDynamicBoundsCheckFastR2012b(i5, 1, i4, &nb_emlrtBCI, &st);
      i4 = f->size[0];
      i5 = i + 1;
      emlrtDynamicBoundsCheckFastR2012b(i5, 1, i4, &mb_emlrtBCI, &st);

      /*  Calculate the integral int_0^1(f(y,t_j)*A_{yj}(x,t)dy) by midpoint */
      /*  integration rule */
      /*  the spatial integration of all points y at time t_j */
      i4 = a->size[0] * a->size[1];
      a->size[0] = 1;
      emxEnsureCapacity(&st, (emxArray__common *)a, i4, (int32_T)sizeof(real_T),
                        &b_emlrtRTEI);
      loop_ub = x->size[1];
      i4 = a->size[0] * a->size[1];
      a->size[1] = loop_ub;
      emxEnsureCapacity(&st, (emxArray__common *)a, i4, (int32_T)sizeof(real_T),
                        &b_emlrtRTEI);
      loop_ub = x->size[1];
      for (i4 = 0; i4 < loop_ub; i4++) {
        a->data[i4] = 0.0;
      }

      b1j1i = 0.0;
      loop_ub = x->size[1];
      emlrtDynamicBoundsCheckFastR2012b(1, 1, loop_ub, &jb_emlrtBCI, &st);
      i4 = x->size[1];
      emlrtDynamicBoundsCheckFastR2012b(1, 1, i4, &kb_emlrtBCI, &st);
      b_st.site = &v_emlrtRSI;
      a->data[0] = Acoeff(&b_st, x->data[0], 1.0 + (real_T)j, 1.0, t->data[i],
                          gridT);

      /*  y = 0:1/(numel(y)-2):1; */
      i4 = f->size[1];
      loop_ub = 2;
      while (loop_ub - 2 <= i4 - 2) {
        i5 = a->size[1];
        b_A = x->size[1];
        b_st.site = &w_emlrtRSI;
        a->data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i5, &gc_emlrtBCI,
          &st) - 1] = Acoeff(&b_st, x->data[emlrtDynamicBoundsCheckFastR2012b
                             (loop_ub, 1, b_A, &hc_emlrtBCI, &st) - 1], 1.0 +
                             (real_T)j, 1.0, t->data[i], gridT);
        i5 = f->size[1];
        emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i5, &ib_emlrtBCI, &st);
        i5 = f->size[1];
        b_A = loop_ub - 1;
        emlrtDynamicBoundsCheckFastR2012b(b_A, 1, i5, &hb_emlrtBCI, &st);
        i5 = a->size[1];
        b_A = a->size[1];
        deltaij = loop_ub - 1;
        i6 = x->size[1];
        i7 = x->size[1];
        i8 = loop_ub - 1;
        b1j1i += 0.5 * (a->data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i5,
          &ic_emlrtBCI, &st) - 1] * f->data[i + f->size[0] * (loop_ub - 1)] +
                        a->data[emlrtDynamicBoundsCheckFastR2012b(deltaij, 1,
          b_A, &jc_emlrtBCI, &st) - 1] * f->data[i + f->size[0] * (loop_ub - 2)])
          * (x->data[emlrtDynamicBoundsCheckFastR2012b(loop_ub, 1, i6,
              &kc_emlrtBCI, &st) - 1] - x->
             data[emlrtDynamicBoundsCheckFastR2012b(i8, 1, i7, &lc_emlrtBCI, &st)
             - 1]);
        loop_ub++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, &st);
      }

      d1 = 2.0 * (1.0 + (real_T)i);
      b_A = D->size[0];
      loop_ub = D->size[1];
      emlrtDynamicBoundsCheckFastR2012b(j + 1, 1, loop_ub, &lb_emlrtBCI, sp);
      i4 = (int32_T)(d1 + -1.0);
      D->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, b_A, &fc_emlrtBCI, sp) +
               D->size[0] * j) - 1] = b1j0i;
      i4 = (int32_T)d1;
      D->data[(emlrtDynamicBoundsCheckFastR2012b(i4, 1, b_A, &fc_emlrtBCI, sp) +
               D->size[0] * j) - 1] = b1j1i;
      j++;
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
    }

    i++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }

  emxFree_real_T(&a);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}