static void eml_li_find(const emlrtStack *sp, const boolean_T x_data[1224],
  const int32_T x_size[1], int32_T y_data[1224], int32_T y_size[1])
{
  int32_T k;
  const mxArray *y;
  const mxArray *m25;
  int32_T i;
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &dr_emlrtRSI;
  k = compute_nones(&st, x_data, x_size[0]);
  if (k <= x_size[0]) {
  } else {
    y = NULL;
    m25 = mxCreateString("Assertion failed.");
    emlrtAssign(&y, m25);
    st.site = &ov_emlrtRSI;
    c_error(&st, y, &db_emlrtMCI);
  }

  emlrtNonNegativeCheckFastR2012b(k, &c_emlrtDCI, sp);
  y_size[0] = k;
  k = 0;
  st.site = &er_emlrtRSI;
  for (i = 1; i <= x_size[0]; i++) {
    if (x_data[i - 1]) {
      y_data[k] = i;
      st.site = &fr_emlrtRSI;
      k++;
    }
  }
}
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 */
  /* } */
}
Exemple #3
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);
  }
}
/* 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);
}
/* 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);
}