File: TransitiveKNN_part2.c

    1   /*
    2    * TransitiveKNN_part2.c
    3    *
    4    * Code generation for function 'TransitiveKNN_part2'
    5    *
    6    * C source code generated on: Mon Jan 05 13:12:27 2015
    7    *
    8    */
    9   
   10   /* Include files */
   11   #include "rt_nonfinite.h"
   12   #include "TransitiveKNN_part2.h"
   13   
   14   /* Type Definitions */
   15   #ifndef struct_emxArray__common
   16   #define struct_emxArray__common
   17   
   18   struct emxArray__common
   19   {
   20     void *data;
   21     int32_T *size;
   22     int32_T allocatedSize;
   23     int32_T numDimensions;
   24     boolean_T canFreeData;
   25   };
   26   
   27   #endif                                 /*struct_emxArray__common*/
   28   
   29   #ifndef typedef_emxArray__common
   30   #define typedef_emxArray__common
   31   
   32   typedef struct emxArray__common emxArray__common;
   33   
   34   #endif                                 /*typedef_emxArray__common*/
   35   
   36   #ifndef struct_emxArray_boolean_T
   37   #define struct_emxArray_boolean_T
   38   
   39   struct emxArray_boolean_T
   40   {
   41     boolean_T *data;
   42     int32_T *size;
   43     int32_T allocatedSize;
   44     int32_T numDimensions;
   45     boolean_T canFreeData;
   46   };
   47   
   48   #endif                                 /*struct_emxArray_boolean_T*/
   49   
   50   #ifndef typedef_emxArray_boolean_T
   51   #define typedef_emxArray_boolean_T
   52   
   53   typedef struct emxArray_boolean_T emxArray_boolean_T;
   54   
   55   #endif                                 /*typedef_emxArray_boolean_T*/
   56   
   57   #ifndef struct_emxArray_int32_T
   58   #define struct_emxArray_int32_T
   59   
   60   struct emxArray_int32_T
   61   {
   62     int32_T *data;
   63     int32_T *size;
   64     int32_T allocatedSize;
   65     int32_T numDimensions;
   66     boolean_T canFreeData;
   67   };
   68   
   69   #endif                                 /*struct_emxArray_int32_T*/
   70   
   71   #ifndef typedef_emxArray_int32_T
   72   #define typedef_emxArray_int32_T
   73   
   74   typedef struct emxArray_int32_T emxArray_int32_T;
   75   
   76   #endif                                 /*typedef_emxArray_int32_T*/
   77   
   78   /* Variable Definitions */
   79   static const volatile char_T *emlrtBreakCheckR2012bFlagVar;
   80   static emlrtRSInfo emlrtRSI = { 14, "TransitiveKNN_part2",
   81     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
   82   
   83   static emlrtRSInfo b_emlrtRSI = { 15, "TransitiveKNN_part2",
   84     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
   85   
   86   static emlrtRSInfo c_emlrtRSI = { 17, "TransitiveKNN_part2",
   87     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
   88   
   89   static emlrtRSInfo d_emlrtRSI = { 18, "TransitiveKNN_part2",
   90     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
   91   
   92   static emlrtRSInfo e_emlrtRSI = { 20, "TransitiveKNN_part2",
   93     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
   94   
   95   static emlrtRSInfo f_emlrtRSI = { 28, "TransitiveKNN_part2",
   96     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
   97   
   98   static emlrtRSInfo g_emlrtRSI = { 34, "TransitiveKNN_part2",
   99     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  100   
  101   static emlrtRSInfo h_emlrtRSI = { 11, "squeeze",
  102     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/squeeze.m" };
  103   
  104   static emlrtRSInfo i_emlrtRSI = { 22, "squeeze",
  105     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/squeeze.m" };
  106   
  107   static emlrtRSInfo j_emlrtRSI = { 52, "squeeze",
  108     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/squeeze.m" };
  109   
  110   static emlrtRSInfo k_emlrtRSI = { 9, "eml_int_forloop_overflow_check",
  111     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_int_forloop_overflow_check.m"
  112   };
  113   
  114   static emlrtRSInfo l_emlrtRSI = { 12, "eml_int_forloop_overflow_check",
  115     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_int_forloop_overflow_check.m"
  116   };
  117   
  118   static emlrtRSInfo m_emlrtRSI = { 20, "sort",
  119     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/sort.m" };
  120   
  121   static emlrtRSInfo n_emlrtRSI = { 34, "eml_sort",
  122     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  123   
  124   static emlrtRSInfo o_emlrtRSI = { 50, "eml_sort",
  125     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  126   
  127   static emlrtRSInfo p_emlrtRSI = { 62, "eml_sort",
  128     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  129   
  130   static emlrtRSInfo q_emlrtRSI = { 63, "eml_sort",
  131     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  132   
  133   static emlrtRSInfo r_emlrtRSI = { 66, "eml_sort",
  134     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  135   
  136   static emlrtRSInfo s_emlrtRSI = { 68, "eml_sort",
  137     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  138   
  139   static emlrtRSInfo t_emlrtRSI = { 69, "eml_sort",
  140     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  141   
  142   static emlrtRSInfo u_emlrtRSI = { 70, "eml_sort",
  143     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  144   
  145   static emlrtRSInfo v_emlrtRSI = { 71, "eml_sort",
  146     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  147   
  148   static emlrtRSInfo w_emlrtRSI = { 76, "eml_sort",
  149     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  150   
  151   static emlrtRSInfo x_emlrtRSI = { 78, "eml_sort",
  152     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  153   
  154   static emlrtRSInfo y_emlrtRSI = { 84, "eml_sort",
  155     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  156   
  157   emlrtRSInfo ab_emlrtRSI = { 19, "eml_assert_valid_dim",
  158     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_assert_valid_dim.m"
  159   };
  160   
  161   emlrtRSInfo bb_emlrtRSI = { 86, "eml_matrix_vstride",
  162     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_matrix_vstride.m"
  163   };
  164   
  165   emlrtRSInfo cb_emlrtRSI = { 50, "prodsize",
  166     "C:/Program Files/MATLAB/R2013b/toolbox/shared/coder/coder/+coder/+internal/prodsize.m"
  167   };
  168   
  169   emlrtRSInfo db_emlrtRSI = { 49, "prodsize",
  170     "C:/Program Files/MATLAB/R2013b/toolbox/shared/coder/coder/+coder/+internal/prodsize.m"
  171   };
  172   
  173   static emlrtRSInfo eb_emlrtRSI = { 37, "eml_sort_idx",
  174     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  175   
  176   static emlrtRSInfo fb_emlrtRSI = { 42, "eml_sort_idx",
  177     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  178   
  179   static emlrtRSInfo gb_emlrtRSI = { 134, "eml_sort_idx",
  180     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  181   
  182   static emlrtRSInfo hb_emlrtRSI = { 138, "eml_sort_idx",
  183     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  184   
  185   static emlrtRSInfo ib_emlrtRSI = { 139, "eml_sort_idx",
  186     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  187   
  188   static emlrtRSInfo jb_emlrtRSI = { 141, "eml_sort_idx",
  189     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  190   
  191   static emlrtRSInfo kb_emlrtRSI = { 148, "eml_sort_idx",
  192     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  193   
  194   static emlrtRSInfo lb_emlrtRSI = { 150, "eml_sort_idx",
  195     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  196   
  197   static emlrtRSInfo mb_emlrtRSI = { 154, "eml_sort_idx",
  198     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  199   
  200   static emlrtRSInfo nb_emlrtRSI = { 159, "eml_sort_idx",
  201     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  202   
  203   static emlrtRSInfo ob_emlrtRSI = { 142, "eml_sort_idx",
  204     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  205   
  206   static emlrtRSInfo pb_emlrtRSI = { 161, "eml_sort_idx",
  207     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  208   
  209   static emlrtRSInfo qb_emlrtRSI = { 163, "eml_sort_idx",
  210     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  211   
  212   static emlrtRSInfo rb_emlrtRSI = { 166, "eml_sort_idx",
  213     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  214   
  215   static emlrtRSInfo sb_emlrtRSI = { 168, "eml_sort_idx",
  216     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  217   
  218   static emlrtRSInfo tb_emlrtRSI = { 173, "eml_sort_idx",
  219     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  220   
  221   static emlrtRSInfo ub_emlrtRSI = { 176, "eml_sort_idx",
  222     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  223   
  224   static emlrtRSInfo vb_emlrtRSI = { 178, "eml_sort_idx",
  225     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  226   
  227   static emlrtRSInfo wb_emlrtRSI = { 182, "eml_sort_idx",
  228     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  229   
  230   static emlrtRSInfo xb_emlrtRSI = { 184, "eml_sort_idx",
  231     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  232   
  233   static emlrtRSInfo yb_emlrtRSI = { 185, "eml_sort_idx",
  234     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  235   
  236   static emlrtRSInfo ac_emlrtRSI = { 186, "eml_sort_idx",
  237     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  238   
  239   static emlrtRSInfo bc_emlrtRSI = { 189, "eml_sort_idx",
  240     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  241   
  242   emlrtRSInfo cc_emlrtRSI = { 20, "eml_sort_le",
  243     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_le.m" };
  244   
  245   emlrtRSInfo dc_emlrtRSI = { 53, "eml_sort_le",
  246     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_le.m" };
  247   
  248   static emlrtRSInfo ec_emlrtRSI = { 102, "diff",
  249     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  250   
  251   static emlrtRSInfo fc_emlrtRSI = { 100, "diff",
  252     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  253   
  254   static emlrtRSInfo gc_emlrtRSI = { 40, "diff",
  255     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  256   
  257   static emlrtRSInfo hc_emlrtRSI = { 16, "min",
  258     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/min.m" };
  259   
  260   static emlrtRSInfo ic_emlrtRSI = { 18, "eml_min_or_max",
  261     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_min_or_max.m" };
  262   
  263   emlrtRSInfo jc_emlrtRSI = { 59, "eml_min_or_max",
  264     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_min_or_max.m" };
  265   
  266   emlrtRSInfo kc_emlrtRSI = { 124, "eml_min_or_max",
  267     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_min_or_max.m" };
  268   
  269   emlrtRSInfo lc_emlrtRSI = { 55, "prodsize",
  270     "C:/Program Files/MATLAB/R2013b/toolbox/shared/coder/coder/+coder/+internal/prodsize.m"
  271   };
  272   
  273   static emlrtRSInfo mc_emlrtRSI = { 41, "find",
  274     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  275   
  276   static emlrtRSInfo nc_emlrtRSI = { 232, "find",
  277     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  278   
  279   static emlrtRSInfo oc_emlrtRSI = { 230, "find",
  280     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  281   
  282   static emlrtRSInfo pc_emlrtRSI = { 30, "ind2sub",
  283     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  284   
  285   static emlrtRSInfo qc_emlrtRSI = { 31, "ind2sub",
  286     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  287   
  288   static emlrtRSInfo rc_emlrtRSI = { 32, "ind2sub",
  289     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  290   
  291   static emlrtRSInfo sc_emlrtRSI = { 34, "ind2sub",
  292     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  293   
  294   static emlrtRSInfo tc_emlrtRSI = { 36, "ind2sub",
  295     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  296   
  297   static emlrtRSInfo uc_emlrtRSI = { 37, "ind2sub",
  298     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  299   
  300   static emlrtRSInfo vc_emlrtRSI = { 38, "ind2sub",
  301     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  302   
  303   static emlrtRSInfo wc_emlrtRSI = { 40, "ind2sub",
  304     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  305   
  306   static emlrtRSInfo xc_emlrtRSI = { 20, "eml_index_prod",
  307     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_index_prod.m" };
  308   
  309   static emlrtRSInfo yc_emlrtRSI = { 61, "ind2sub",
  310     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  311   
  312   static emlrtRSInfo ad_emlrtRSI = { 24, "indexIntRelop",
  313     "C:/Program Files/MATLAB/R2013b/toolbox/shared/coder/coder/+coder/+internal/indexIntRelop.m"
  314   };
  315   
  316   emlrtRSInfo bd_emlrtRSI = { 233, "indexIntRelop",
  317     "C:/Program Files/MATLAB/R2013b/toolbox/shared/coder/coder/+coder/+internal/indexIntRelop.m"
  318   };
  319   
  320   static emlrtRSInfo cd_emlrtRSI = { 48, "permute",
  321     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  322   
  323   static emlrtRSInfo dd_emlrtRSI = { 49, "permute",
  324     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  325   
  326   static emlrtRSInfo ed_emlrtRSI = { 56, "permute",
  327     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  328   
  329   static emlrtRSInfo fd_emlrtRSI = { 67, "permute",
  330     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  331   
  332   static emlrtRSInfo gd_emlrtRSI = { 69, "permute",
  333     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  334   
  335   static emlrtRSInfo hd_emlrtRSI = { 71, "permute",
  336     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  337   
  338   static emlrtRSInfo id_emlrtRSI = { 72, "permute",
  339     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  340   
  341   static emlrtRSInfo jd_emlrtRSI = { 75, "permute",
  342     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  343   
  344   static emlrtRSInfo kd_emlrtRSI = { 76, "permute",
  345     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  346   
  347   emlrtRSInfo ld_emlrtRSI = { 16, "eml_is_permutation",
  348     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_is_permutation.m"
  349   };
  350   
  351   emlrtRSInfo md_emlrtRSI = { 21, "eml_is_permutation",
  352     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_is_permutation.m"
  353   };
  354   
  355   emlrtRSInfo nd_emlrtRSI = { 12, "all",
  356     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/ops/all.m" };
  357   
  358   emlrtRSInfo od_emlrtRSI = { 225, "indexIntRelop",
  359     "C:/Program Files/MATLAB/R2013b/toolbox/shared/coder/coder/+coder/+internal/indexIntRelop.m"
  360   };
  361   
  362   static emlrtMCInfo emlrtMCI = { 52, 9, "eml_int_forloop_overflow_check",
  363     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_int_forloop_overflow_check.m"
  364   };
  365   
  366   static emlrtMCInfo b_emlrtMCI = { 51, 15, "eml_int_forloop_overflow_check",
  367     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_int_forloop_overflow_check.m"
  368   };
  369   
  370   emlrtMCInfo c_emlrtMCI = { 20, 5, "eml_assert_valid_dim",
  371     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_assert_valid_dim.m"
  372   };
  373   
  374   emlrtMCInfo d_emlrtMCI = { 18, 15, "eml_assert_valid_dim",
  375     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_assert_valid_dim.m"
  376   };
  377   
  378   static emlrtMCInfo e_emlrtMCI = { 46, 9, "diff",
  379     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  380   
  381   static emlrtMCInfo f_emlrtMCI = { 45, 19, "diff",
  382     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  383   
  384   emlrtMCInfo g_emlrtMCI = { 65, 1, "find",
  385     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  386   
  387   emlrtMCInfo h_emlrtMCI = { 123, 9, "find",
  388     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  389   
  390   emlrtMCInfo i_emlrtMCI = { 122, 19, "find",
  391     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  392   
  393   static emlrtMCInfo j_emlrtMCI = { 239, 9, "find",
  394     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  395   
  396   static emlrtMCInfo k_emlrtMCI = { 33, 5, "ind2sub",
  397     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  398   
  399   static emlrtMCInfo l_emlrtMCI = { 32, 15, "ind2sub",
  400     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  401   
  402   static emlrtRTEInfo emlrtRTEI = { 1, 60, "TransitiveKNN_part2",
  403     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  404   
  405   static emlrtRTEInfo b_emlrtRTEI = { 47, 1, "permute",
  406     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/permute.m" };
  407   
  408   static emlrtRTEInfo c_emlrtRTEI = { 127, 5, "find",
  409     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  410   
  411   static emlrtRTEInfo d_emlrtRTEI = { 15, 9, "TransitiveKNN_part2",
  412     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  413   
  414   static emlrtRTEInfo e_emlrtRTEI = { 16, 9, "TransitiveKNN_part2",
  415     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  416   
  417   static emlrtRTEInfo f_emlrtRTEI = { 17, 9, "TransitiveKNN_part2",
  418     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  419   
  420   static emlrtRTEInfo g_emlrtRTEI = { 19, 9, "TransitiveKNN_part2",
  421     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  422   
  423   static emlrtRTEInfo h_emlrtRTEI = { 1, 11, "TransitiveKNN_part2",
  424     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  425   
  426   static emlrtRTEInfo i_emlrtRTEI = { 33, 6, "find",
  427     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  428   
  429   static emlrtRTEInfo j_emlrtRTEI = { 34, 1, "ind2sub",
  430     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  431   
  432   static emlrtRTEInfo k_emlrtRTEI = { 21, 5, "squeeze",
  433     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/squeeze.m" };
  434   
  435   static emlrtRTEInfo l_emlrtRTEI = { 51, 1, "squeeze",
  436     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/squeeze.m" };
  437   
  438   static emlrtRTEInfo m_emlrtRTEI = { 52, 1, "eml_sort",
  439     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  440   
  441   static emlrtRTEInfo n_emlrtRTEI = { 53, 1, "eml_sort",
  442     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  443   
  444   static emlrtRTEInfo o_emlrtRTEI = { 61, 5, "eml_sort",
  445     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  446   
  447   static emlrtRTEInfo p_emlrtRTEI = { 78, 13, "eml_sort",
  448     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort.m" };
  449   
  450   static emlrtRTEInfo q_emlrtRTEI = { 27, 5, "eml_sort_idx",
  451     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  452   
  453   static emlrtRTEInfo r_emlrtRTEI = { 1, 20, "eml_sort_idx",
  454     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  455   
  456   static emlrtRTEInfo s_emlrtRTEI = { 145, 5, "eml_sort_idx",
  457     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_sort_idx.m" };
  458   
  459   static emlrtRTEInfo t_emlrtRTEI = { 1, 14, "diff",
  460     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  461   
  462   emlrtRTEInfo u_emlrtRTEI = { 71, 1, "diff",
  463     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  464   
  465   static emlrtRTEInfo v_emlrtRTEI = { 72, 1, "diff",
  466     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  467   
  468   static emlrtRTEInfo w_emlrtRTEI = { 1, 1, "TransitiveKNN_part2_api", "" };
  469   
  470   static emlrtRTEInfo x_emlrtRTEI = { 12, 1, "TransitiveKNN_part2",
  471     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  472   
  473   static emlrtRTEInfo y_emlrtRTEI = { 13, 5, "TransitiveKNN_part2",
  474     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  475   
  476   static emlrtBCInfo emlrtBCI = { -1, -1, 14, 49, "errorMat",
  477     "TransitiveKNN_part2",
  478     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  479   
  480   static emlrtBCInfo b_emlrtBCI = { -1, -1, 14, 51, "errorMat",
  481     "TransitiveKNN_part2",
  482     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  483   
  484   static emlrtBCInfo c_emlrtBCI = { -1, -1, 15, 39, "overSafeResults",
  485     "TransitiveKNN_part2",
  486     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  487   
  488   static emlrtBCInfo d_emlrtBCI = { -1, -1, 15, 41, "overSafeResults",
  489     "TransitiveKNN_part2",
  490     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  491   
  492   static emlrtBCInfo e_emlrtBCI = { -1, -1, 22, 29, "uOSRinds",
  493     "TransitiveKNN_part2",
  494     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  495   
  496   static emlrtECInfo emlrtECI = { -1, 22, 29, "TransitiveKNN_part2",
  497     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  498   
  499   static emlrtBCInfo f_emlrtBCI = { -1, -1, 24, 13, "uOSRFinalinds",
  500     "TransitiveKNN_part2",
  501     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  502   
  503   static emlrtECInfo b_emlrtECI = { -1, 24, 13, "TransitiveKNN_part2",
  504     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  505   
  506   static emlrtBCInfo g_emlrtBCI = { -1, -1, 25, 13, "uOSRFinalinds",
  507     "TransitiveKNN_part2",
  508     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  509   
  510   static emlrtBCInfo h_emlrtBCI = { -1, -1, 28, 20, "CSH_ann",
  511     "TransitiveKNN_part2",
  512     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  513   
  514   static emlrtBCInfo i_emlrtBCI = { -1, -1, 28, 22, "CSH_ann",
  515     "TransitiveKNN_part2",
  516     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  517   
  518   static emlrtECInfo c_emlrtECI = { -1, 28, 10, "TransitiveKNN_part2",
  519     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  520   
  521   static emlrtBCInfo j_emlrtBCI = { -1, -1, 28, 37, "CSH_ann",
  522     "TransitiveKNN_part2",
  523     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  524   
  525   static emlrtBCInfo k_emlrtBCI = { -1, -1, 28, 39, "CSH_ann",
  526     "TransitiveKNN_part2",
  527     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  528   
  529   static emlrtECInfo d_emlrtECI = { -1, 28, 27, "TransitiveKNN_part2",
  530     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  531   
  532   static emlrtBCInfo l_emlrtBCI = { -1, -1, 30, 22, "sortedErrors",
  533     "TransitiveKNN_part2",
  534     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  535   
  536   static emlrtBCInfo m_emlrtBCI = { -1, -1, 30, 24, "sortedErrors",
  537     "TransitiveKNN_part2",
  538     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  539   
  540   static emlrtECInfo e_emlrtECI = { -1, 30, 9, "TransitiveKNN_part2",
  541     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m" };
  542   
  543   static emlrtDCInfo emlrtDCI = { 8, 34, "TransitiveKNN_part2",
  544     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 1 };
  545   
  546   static emlrtDCInfo b_emlrtDCI = { 8, 34, "TransitiveKNN_part2",
  547     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 4 };
  548   
  549   static emlrtDCInfo c_emlrtDCI = { 8, 59, "TransitiveKNN_part2",
  550     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 1 };
  551   
  552   static emlrtDCInfo d_emlrtDCI = { 8, 59, "TransitiveKNN_part2",
  553     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 4 };
  554   
  555   static emlrtDCInfo e_emlrtDCI = { 9, 17, "TransitiveKNN_part2",
  556     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 1 };
  557   
  558   static emlrtDCInfo f_emlrtDCI = { 9, 17, "TransitiveKNN_part2",
  559     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 4 };
  560   
  561   static emlrtBCInfo n_emlrtBCI = { -1, -1, 16, 16, "OSR", "TransitiveKNN_part2",
  562     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  563   
  564   static emlrtBCInfo o_emlrtBCI = { -1, -1, 20, 34, "numUniqueResultsPerPixel",
  565     "TransitiveKNN_part2",
  566     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  567   
  568   static emlrtBCInfo p_emlrtBCI = { -1, -1, 20, 36, "numUniqueResultsPerPixel",
  569     "TransitiveKNN_part2",
  570     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  571   
  572   static emlrtBCInfo q_emlrtBCI = { -1, -1, 25, 42, "uOSRinds",
  573     "TransitiveKNN_part2",
  574     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  575   
  576   static emlrtBCInfo r_emlrtBCI = { -1, -1, 28, 63, "sOSR", "TransitiveKNN_part2",
  577     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  578   
  579   static emlrtBCInfo s_emlrtBCI = { -1, -1, 30, 31, "sErrors",
  580     "TransitiveKNN_part2",
  581     "C:/Users/admin/Downloads/CSH_code_v3/C_and_Mex/TransitiveKNN_part2.m", 0 };
  582   
  583   static emlrtRSInfo pd_emlrtRSI = { 14, "eml_index_rdivide",
  584     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_index_rdivide.m"
  585   };
  586   
  587   static emlrtRSInfo qd_emlrtRSI = { 45, "diff",
  588     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  589   
  590   static emlrtRSInfo rd_emlrtRSI = { 51, "eml_int_forloop_overflow_check",
  591     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_int_forloop_overflow_check.m"
  592   };
  593   
  594   static emlrtRSInfo sd_emlrtRSI = { 239, "find",
  595     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/find.m" };
  596   
  597   static emlrtRSInfo td_emlrtRSI = { 46, "diff",
  598     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/datafun/diff.m" };
  599   
  600   static emlrtRSInfo ud_emlrtRSI = { 33, "ind2sub",
  601     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/elmat/ind2sub.m" };
  602   
  603   static emlrtRSInfo vd_emlrtRSI = { 52, "eml_int_forloop_overflow_check",
  604     "C:/Program Files/MATLAB/R2013b/toolbox/eml/lib/matlab/eml/eml_int_forloop_overflow_check.m"
  605   };
  606   
  607   /* Function Declarations */
  608   static void b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  609     emlrtMsgIdentifier *parentId, emxArray_uint8_T *y);
  610   static const mxArray *b_emlrt_marshallOut(emxArray_real_T *u);
  611   static void b_emxInit_int32_T(const emlrtStack *sp, emxArray_int32_T **pEmxArray,
  612     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  613   static void b_emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  614     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  615   static const mxArray *b_message(const emlrtStack *sp, const mxArray *b,
  616     emlrtMCInfo *location);
  617   static real_T c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *k, const
  618     char_T *identifier);
  619   static const mxArray *c_emlrt_marshallOut(emxArray_real_T *u);
  620   static void c_emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  621     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  622   static void check_forloop_overflow_error(const emlrtStack *sp);
  623   static real_T d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  624     emlrtMsgIdentifier *parentId);
  625   static void d_emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  626     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  627   static void diff(const emlrtStack *sp, const emxArray_real_T *x, emxArray_real_T
  628                    *y);
  629   static int32_T div_s32(const emlrtStack *sp, int32_T numerator, int32_T
  630     denominator);
  631   static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  632     *overSafeResults, const char_T *identifier, emxArray_real_T *y);
  633   static void eml_sort(const emlrtStack *sp, const emxArray_real_T *x,
  634                        emxArray_real_T *y, emxArray_int32_T *idx);
  635   static void eml_sort_idx(const emlrtStack *sp, const emxArray_real_T *x,
  636     emxArray_int32_T *idx);
  637   static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *A, const
  638     char_T *identifier, emxArray_uint8_T *y);
  639   static const mxArray *emlrt_marshallOut(emxArray_real_T *u);
  640   static void emxEnsureCapacity(const emlrtStack *sp, emxArray__common *emxArray,
  641     int32_T oldNumel, int32_T elementSize, const emlrtRTEInfo *srcLocation);
  642   static void emxFree_boolean_T(emxArray_boolean_T **pEmxArray);
  643   static void emxFree_int32_T(emxArray_int32_T **pEmxArray);
  644   static void emxFree_real_T(emxArray_real_T **pEmxArray);
  645   static void emxFree_uint8_T(emxArray_uint8_T **pEmxArray);
  646   static void emxInit_boolean_T(const emlrtStack *sp, emxArray_boolean_T
  647     **pEmxArray, int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T
  648     doPush);
  649   static void emxInit_int32_T(const emlrtStack *sp, emxArray_int32_T **pEmxArray,
  650     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  651   static void emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  652     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  653   static void emxInit_uint8_T(const emlrtStack *sp, emxArray_uint8_T **pEmxArray,
  654     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush);
  655   static void error(const emlrtStack *sp, const mxArray *b, emlrtMCInfo *location);
  656   static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  657     emlrtMsgIdentifier *parentId, emxArray_real_T *y);
  658   static void g_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  659     emlrtMsgIdentifier *msgId, emxArray_uint8_T *ret);
  660   static real_T h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  661     emlrtMsgIdentifier *msgId);
  662   static void i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  663     emlrtMsgIdentifier *msgId, emxArray_real_T *ret);
  664   static const mxArray *message(const emlrtStack *sp, const mxArray *b, const
  665     mxArray *c, emlrtMCInfo *location);
  666   static void squeeze(const emlrtStack *sp, const emxArray_real_T *a,
  667                       emxArray_real_T *b);
  668   
  669   /* Function Definitions */
  670   static void b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  671     emlrtMsgIdentifier *parentId, emxArray_uint8_T *y)
  672   {
  673     g_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  674     emlrtDestroyArray(&u);
  675   }
  676   
  677   static const mxArray *b_emlrt_marshallOut(emxArray_real_T *u)
  678   {
  679     const mxArray *y;
  680     static const int32_T iv8[2] = { 0, 0 };
  681   
  682     const mxArray *m4;
  683     y = NULL;
  684     m4 = mxCreateNumericArray(2, (int32_T *)&iv8, mxDOUBLE_CLASS, mxREAL);
  685     mxSetData((mxArray *)m4, (void *)u->data);
  686     mxSetDimensions((mxArray *)m4, u->size, 2);
  687     emlrtAssign(&y, m4);
  688     return y;
  689   }
  690   
  691   static void b_emxInit_int32_T(const emlrtStack *sp, emxArray_int32_T **pEmxArray,
  692     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
  693   {
  694     emxArray_int32_T *emxArray;
  695     int32_T i;
  696     *pEmxArray = (emxArray_int32_T *)emlrtMallocMex(sizeof(emxArray_int32_T));
  697     if ((void *)*pEmxArray == NULL) {
  698       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  699     }
  700   
  701     if (doPush) {
  702       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
  703         emxFree_int32_T);
  704     }
  705   
  706     emxArray = *pEmxArray;
  707     emxArray->data = (int32_T *)NULL;
  708     emxArray->numDimensions = numDimensions;
  709     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
  710       * numDimensions));
  711     if ((void *)emxArray->size == NULL) {
  712       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  713     }
  714   
  715     emxArray->allocatedSize = 0;
  716     emxArray->canFreeData = TRUE;
  717     for (i = 0; i < numDimensions; i++) {
  718       emxArray->size[i] = 0;
  719     }
  720   }
  721   
  722   static void b_emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  723     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
  724   {
  725     emxArray_real_T *emxArray;
  726     int32_T i;
  727     *pEmxArray = (emxArray_real_T *)emlrtMallocMex(sizeof(emxArray_real_T));
  728     if ((void *)*pEmxArray == NULL) {
  729       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  730     }
  731   
  732     if (doPush) {
  733       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
  734         emxFree_real_T);
  735     }
  736   
  737     emxArray = *pEmxArray;
  738     emxArray->data = (real_T *)NULL;
  739     emxArray->numDimensions = numDimensions;
  740     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
  741       * numDimensions));
  742     if ((void *)emxArray->size == NULL) {
  743       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  744     }
  745   
  746     emxArray->allocatedSize = 0;
  747     emxArray->canFreeData = TRUE;
  748     for (i = 0; i < numDimensions; i++) {
  749       emxArray->size[i] = 0;
  750     }
  751   }
  752   
  753   static const mxArray *b_message(const emlrtStack *sp, const mxArray *b,
  754     emlrtMCInfo *location)
  755   {
  756     const mxArray *pArray;
  757     const mxArray *m7;
  758     pArray = b;
  759     return emlrtCallMATLABR2012b(sp, 1, &m7, 1, &pArray, "message", TRUE, location);
  760   }
  761   
  762   static real_T c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *k, const
  763     char_T *identifier)
  764   {
  765     real_T y;
  766     emlrtMsgIdentifier thisId;
  767     thisId.fIdentifier = identifier;
  768     thisId.fParent = NULL;
  769     y = d_emlrt_marshallIn(sp, emlrtAlias(k), &thisId);
  770     emlrtDestroyArray(&k);
  771     return y;
  772   }
  773   
  774   static const mxArray *c_emlrt_marshallOut(emxArray_real_T *u)
  775   {
  776     const mxArray *y;
  777     static const int32_T iv9[3] = { 0, 0, 0 };
  778   
  779     const mxArray *m5;
  780     y = NULL;
  781     m5 = mxCreateNumericArray(3, (int32_T *)&iv9, mxDOUBLE_CLASS, mxREAL);
  782     mxSetData((mxArray *)m5, (void *)u->data);
  783     mxSetDimensions((mxArray *)m5, u->size, 3);
  784     emlrtAssign(&y, m5);
  785     return y;
  786   }
  787   
  788   static void c_emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  789     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
  790   {
  791     emxArray_real_T *emxArray;
  792     int32_T i;
  793     *pEmxArray = (emxArray_real_T *)emlrtMallocMex(sizeof(emxArray_real_T));
  794     if ((void *)*pEmxArray == NULL) {
  795       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  796     }
  797   
  798     if (doPush) {
  799       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
  800         emxFree_real_T);
  801     }
  802   
  803     emxArray = *pEmxArray;
  804     emxArray->data = (real_T *)NULL;
  805     emxArray->numDimensions = numDimensions;
  806     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
  807       * numDimensions));
  808     if ((void *)emxArray->size == NULL) {
  809       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  810     }
  811   
  812     emxArray->allocatedSize = 0;
  813     emxArray->canFreeData = TRUE;
  814     for (i = 0; i < numDimensions; i++) {
  815       emxArray->size[i] = 0;
  816     }
  817   }
  818   
  819   /*
  820    *
  821    */
  822   static void check_forloop_overflow_error(const emlrtStack *sp)
  823   {
  824     const mxArray *y;
  825     static const int32_T iv4[2] = { 1, 34 };
  826   
  827     const mxArray *m1;
  828     char_T cv2[34];
  829     int32_T i;
  830     static const char_T cv3[34] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
  831       'l', 'b', 'o', 'x', ':', 'i', 'n', 't', '_', 'f', 'o', 'r', 'l', 'o', 'o',
  832       'p', '_', 'o', 'v', 'e', 'r', 'f', 'l', 'o', 'w' };
  833   
  834     const mxArray *b_y;
  835     static const int32_T iv5[2] = { 1, 23 };
  836   
  837     char_T cv4[23];
  838     static const char_T cv5[23] = { 'c', 'o', 'd', 'e', 'r', '.', 'i', 'n', 't',
  839       'e', 'r', 'n', 'a', 'l', '.', 'i', 'n', 'd', 'e', 'x', 'I', 'n', 't' };
  840   
  841     emlrtStack st;
  842     emlrtStack b_st;
  843     st.prev = sp;
  844     st.tls = sp->tls;
  845     b_st.prev = sp;
  846     b_st.tls = sp->tls;
  847     y = NULL;
  848     m1 = mxCreateCharArray(2, iv4);
  849     for (i = 0; i < 34; i++) {
  850       cv2[i] = cv3[i];
  851     }
  852   
  853     emlrtInitCharArrayR2013a(sp, 34, m1, cv2);
  854     emlrtAssign(&y, m1);
  855     b_y = NULL;
  856     m1 = mxCreateCharArray(2, iv5);
  857     for (i = 0; i < 23; i++) {
  858       cv4[i] = cv5[i];
  859     }
  860   
  861     emlrtInitCharArrayR2013a(sp, 23, m1, cv4);
  862     emlrtAssign(&b_y, m1);
  863     st.site = &rd_emlrtRSI;
  864     b_st.site = &vd_emlrtRSI;
  865     error(&st, message(&b_st, y, b_y, &emlrtMCI), &b_emlrtMCI);
  866   }
  867   
  868   static real_T d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  869     emlrtMsgIdentifier *parentId)
  870   {
  871     real_T y;
  872     y = h_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  873     emlrtDestroyArray(&u);
  874     return y;
  875   }
  876   
  877   static void d_emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
  878     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
  879   {
  880     emxArray_real_T *emxArray;
  881     int32_T i;
  882     *pEmxArray = (emxArray_real_T *)emlrtMallocMex(sizeof(emxArray_real_T));
  883     if ((void *)*pEmxArray == NULL) {
  884       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  885     }
  886   
  887     if (doPush) {
  888       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
  889         emxFree_real_T);
  890     }
  891   
  892     emxArray = *pEmxArray;
  893     emxArray->data = (real_T *)NULL;
  894     emxArray->numDimensions = numDimensions;
  895     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
  896       * numDimensions));
  897     if ((void *)emxArray->size == NULL) {
  898       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
  899     }
  900   
  901     emxArray->allocatedSize = 0;
  902     emxArray->canFreeData = TRUE;
  903     for (i = 0; i < numDimensions; i++) {
  904       emxArray->size[i] = 0;
  905     }
  906   }
  907   
  908   /*
  909    *
  910    */
  911   static void diff(const emlrtStack *sp, const emxArray_real_T *x, emxArray_real_T
  912                    *y)
  913   {
  914     int32_T iyLead;
  915     boolean_T overflow;
  916     const mxArray *b_y;
  917     static const int32_T iv6[2] = { 1, 36 };
  918   
  919     const mxArray *m2;
  920     char_T cv6[36];
  921     int32_T i;
  922     static const char_T cv7[36] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
  923       'l', 'b', 'o', 'x', ':', 'a', 'u', 't', 'o', 'D', 'i', 'm', 'I', 'n', 'c',
  924       'o', 'm', 'p', 'a', 't', 'i', 'b', 'i', 'l', 'i', 't', 'y' };
  925   
  926     emxArray_real_T *b_y1;
  927     real_T work_data_idx_0;
  928     int32_T m;
  929     real_T tmp1;
  930     real_T tmp2;
  931     emlrtStack st;
  932     emlrtStack b_st;
  933     emlrtStack c_st;
  934     st.prev = sp;
  935     st.tls = sp->tls;
  936     b_st.prev = &st;
  937     b_st.tls = st.tls;
  938     c_st.prev = sp;
  939     c_st.tls = sp->tls;
  940     emlrtHeapReferenceStackEnterFcnR2012b(sp);
  941     if (x->size[0] == 0) {
  942       iyLead = y->size[0] * y->size[1];
  943       y->size[0] = 0;
  944       y->size[1] = 1;
  945       emxEnsureCapacity(sp, (emxArray__common *)y, iyLead, (int32_T)sizeof(real_T),
  946                         &t_emlrtRTEI);
  947     } else {
  948       st.site = &gc_emlrtRSI;
  949       if (muIntScalarMin_sint32(x->size[0] - 1, 1) < 1) {
  950         iyLead = y->size[0] * y->size[1];
  951         y->size[0] = 0;
  952         y->size[1] = 0;
  953         emxEnsureCapacity(sp, (emxArray__common *)y, iyLead, (int32_T)sizeof
  954                           (real_T), &t_emlrtRTEI);
  955       } else {
  956         overflow = (x->size[0] != 1);
  957         if (overflow) {
  958         } else {
  959           b_y = NULL;
  960           m2 = mxCreateCharArray(2, iv6);
  961           for (i = 0; i < 36; i++) {
  962             cv6[i] = cv7[i];
  963           }
  964   
  965           emlrtInitCharArrayR2013a(sp, 36, m2, cv6);
  966           emlrtAssign(&b_y, m2);
  967           st.site = &qd_emlrtRSI;
  968           c_st.site = &td_emlrtRSI;
  969           error(&st, b_message(&c_st, b_y, &e_emlrtMCI), &f_emlrtMCI);
  970         }
  971   
  972         emxInit_real_T(sp, &b_y1, 1, &v_emlrtRTEI, TRUE);
  973         iyLead = b_y1->size[0];
  974         b_y1->size[0] = x->size[0] - 1;
  975         emxEnsureCapacity(sp, (emxArray__common *)b_y1, iyLead, (int32_T)sizeof
  976                           (real_T), &v_emlrtRTEI);
  977         i = x->size[0] - 1;
  978         if (!(i == 0)) {
  979           i = 1;
  980           iyLead = 0;
  981           work_data_idx_0 = x->data[0];
  982           st.site = &fc_emlrtRSI;
  983           if (2 > x->size[0]) {
  984             overflow = FALSE;
  985           } else {
  986             overflow = (x->size[0] > 2147483646);
  987           }
  988   
  989           if (overflow) {
  990             b_st.site = &l_emlrtRSI;
  991             check_forloop_overflow_error(&b_st);
  992           }
  993   
  994           for (m = 2; m <= x->size[0]; m++) {
  995             tmp1 = x->data[i];
  996             st.site = &ec_emlrtRSI;
  997             tmp2 = work_data_idx_0;
  998             work_data_idx_0 = tmp1;
  999             tmp1 -= tmp2;
 1000             i++;
 1001             b_y1->data[iyLead] = tmp1;
 1002             iyLead++;
 1003           }
 1004         }
 1005   
 1006         i = b_y1->size[0];
 1007         iyLead = y->size[0] * y->size[1];
 1008         y->size[0] = i;
 1009         emxEnsureCapacity(sp, (emxArray__common *)y, iyLead, (int32_T)sizeof
 1010                           (real_T), &t_emlrtRTEI);
 1011         iyLead = y->size[0] * y->size[1];
 1012         y->size[1] = 1;
 1013         emxEnsureCapacity(sp, (emxArray__common *)y, iyLead, (int32_T)sizeof
 1014                           (real_T), &t_emlrtRTEI);
 1015         i = b_y1->size[0];
 1016         for (iyLead = 0; iyLead < i; iyLead++) {
 1017           y->data[iyLead] = b_y1->data[iyLead];
 1018         }
 1019   
 1020         emxFree_real_T(&b_y1);
 1021       }
 1022     }
 1023   
 1024     emlrtHeapReferenceStackLeaveFcnR2012b(sp);
 1025   }
 1026   
 1027   static int32_T div_s32(const emlrtStack *sp, int32_T numerator, int32_T
 1028     denominator)
 1029   {
 1030     int32_T quotient;
 1031     uint32_T absNumerator;
 1032     uint32_T absDenominator;
 1033     int32_T quotientNeedsNegation;
 1034     if (denominator == 0) {
 1035       if (numerator >= 0) {
 1036         quotient = MAX_int32_T;
 1037       } else {
 1038         quotient = MIN_int32_T;
 1039       }
 1040   
 1041       emlrtDivisionByZeroErrorR2012b(0, sp);
 1042     } else {
 1043       if (numerator >= 0) {
 1044         absNumerator = (uint32_T)numerator;
 1045       } else {
 1046         absNumerator = (uint32_T)-numerator;
 1047       }
 1048   
 1049       if (denominator >= 0) {
 1050         absDenominator = (uint32_T)denominator;
 1051       } else {
 1052         absDenominator = (uint32_T)-denominator;
 1053       }
 1054   
 1055       quotientNeedsNegation = ((numerator < 0) != (denominator < 0));
 1056       absNumerator /= absDenominator;
 1057       if ((uint32_T)quotientNeedsNegation) {
 1058         quotient = -(int32_T)absNumerator;
 1059       } else {
 1060         quotient = (int32_T)absNumerator;
 1061       }
 1062     }
 1063   
 1064     return quotient;
 1065   }
 1066   
 1067   static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray
 1068     *overSafeResults, const char_T *identifier, emxArray_real_T *y)
 1069   {
 1070     emlrtMsgIdentifier thisId;
 1071     thisId.fIdentifier = identifier;
 1072     thisId.fParent = NULL;
 1073     f_emlrt_marshallIn(sp, emlrtAlias(overSafeResults), &thisId, y);
 1074     emlrtDestroyArray(&overSafeResults);
 1075   }
 1076   
 1077   /*
 1078    *
 1079    */
 1080   static void eml_sort(const emlrtStack *sp, const emxArray_real_T *x,
 1081                        emxArray_real_T *y, emxArray_int32_T *idx)
 1082   {
 1083     int32_T dim;
 1084     int32_T vlen;
 1085     emxArray_real_T *vwork;
 1086     int32_T i1;
 1087     uint32_T unnamed_idx_0;
 1088     int32_T vstride;
 1089     int32_T k;
 1090     boolean_T b3;
 1091     emxArray_int32_T *iidx;
 1092     int32_T ix;
 1093     emlrtStack st;
 1094     emlrtStack b_st;
 1095     st.prev = sp;
 1096     st.tls = sp->tls;
 1097     b_st.prev = &st;
 1098     b_st.tls = st.tls;
 1099     emlrtHeapReferenceStackEnterFcnR2012b(sp);
 1100     st.site = &n_emlrtRSI;
 1101     dim = 2;
 1102     if (x->size[0] != 1) {
 1103       dim = 1;
 1104     }
 1105   
 1106     st.site = &o_emlrtRSI;
 1107     if (dim <= 1) {
 1108       vlen = x->size[0];
 1109     } else {
 1110       vlen = 1;
 1111     }
 1112   
 1113     emxInit_real_T(sp, &vwork, 1, &m_emlrtRTEI, TRUE);
 1114     i1 = vwork->size[0];
 1115     vwork->size[0] = vlen;
 1116     emxEnsureCapacity(sp, (emxArray__common *)vwork, i1, (int32_T)sizeof(real_T),
 1117                       &m_emlrtRTEI);
 1118     i1 = y->size[0];
 1119     y->size[0] = x->size[0];
 1120     emxEnsureCapacity(sp, (emxArray__common *)y, i1, (int32_T)sizeof(real_T),
 1121                       &n_emlrtRTEI);
 1122     unnamed_idx_0 = (uint32_T)x->size[0];
 1123     i1 = idx->size[0];
 1124     idx->size[0] = (int32_T)unnamed_idx_0;
 1125     emxEnsureCapacity(sp, (emxArray__common *)idx, i1, (int32_T)sizeof(int32_T),
 1126                       &o_emlrtRTEI);
 1127     st.site = &p_emlrtRSI;
 1128     vstride = 1;
 1129     k = 1;
 1130     while (k <= dim - 1) {
 1131       vstride *= x->size[0];
 1132       k = 2;
 1133     }
 1134   
 1135     st.site = &q_emlrtRSI;
 1136     st.site = &q_emlrtRSI;
 1137     st.site = &r_emlrtRSI;
 1138     i1 = -1;
 1139     st.site = &s_emlrtRSI;
 1140     st.site = &t_emlrtRSI;
 1141     if (1 > vstride) {
 1142       b3 = FALSE;
 1143     } else {
 1144       b3 = (vstride > 2147483646);
 1145     }
 1146   
 1147     if (b3) {
 1148       b_st.site = &l_emlrtRSI;
 1149       check_forloop_overflow_error(&b_st);
 1150     }
 1151   
 1152     dim = 1;
 1153     b_emxInit_int32_T(sp, &iidx, 1, &p_emlrtRTEI, TRUE);
 1154     while (dim <= vstride) {
 1155       st.site = &u_emlrtRSI;
 1156       i1++;
 1157       st.site = &v_emlrtRSI;
 1158       ix = i1 + 1;
 1159       for (k = 0; k < vlen; k++) {
 1160         vwork->data[k] = x->data[ix - 1];
 1161         st.site = &w_emlrtRSI;
 1162         ix += vstride;
 1163       }
 1164   
 1165       st.site = &x_emlrtRSI;
 1166       eml_sort_idx(&st, vwork, iidx);
 1167       ix = i1;
 1168       for (k = 0; k < vlen; k++) {
 1169         y->data[ix] = vwork->data[iidx->data[k] - 1];
 1170         idx->data[ix] = iidx->data[k];
 1171         st.site = &y_emlrtRSI;
 1172         ix += vstride;
 1173       }
 1174   
 1175       dim++;
 1176     }
 1177   
 1178     emxFree_int32_T(&iidx);
 1179     emxFree_real_T(&vwork);
 1180     emlrtHeapReferenceStackLeaveFcnR2012b(sp);
 1181   }
 1182   
 1183   /*
 1184    *
 1185    */
 1186   static void eml_sort_idx(const emlrtStack *sp, const emxArray_real_T *x,
 1187     emxArray_int32_T *idx)
 1188   {
 1189     uint32_T unnamed_idx_0;
 1190     int32_T k;
 1191     boolean_T overflow;
 1192     boolean_T guard2 = FALSE;
 1193     emxArray_int32_T *idx0;
 1194     int32_T i;
 1195     int32_T i2;
 1196     int32_T j;
 1197     int32_T pEnd;
 1198     int32_T p;
 1199     int32_T q;
 1200     int32_T qEnd;
 1201     int32_T kEnd;
 1202     boolean_T guard1 = FALSE;
 1203     emlrtStack st;
 1204     emlrtStack b_st;
 1205     st.prev = sp;
 1206     st.tls = sp->tls;
 1207     b_st.prev = &st;
 1208     b_st.tls = st.tls;
 1209     emlrtHeapReferenceStackEnterFcnR2012b(sp);
 1210     unnamed_idx_0 = (uint32_T)x->size[0];
 1211     k = idx->size[0];
 1212     idx->size[0] = (int32_T)unnamed_idx_0;
 1213     emxEnsureCapacity(sp, (emxArray__common *)idx, k, (int32_T)sizeof(int32_T),
 1214                       &q_emlrtRTEI);
 1215     st.site = &eb_emlrtRSI;
 1216     if (x->size[0] == 0) {
 1217       st.site = &fb_emlrtRSI;
 1218     } else {
 1219       st.site = &gb_emlrtRSI;
 1220       overflow = (x->size[0] > 2147483646);
 1221       if (overflow) {
 1222         b_st.site = &l_emlrtRSI;
 1223         check_forloop_overflow_error(&b_st);
 1224       }
 1225   
 1226       for (k = 1; k <= x->size[0]; k++) {
 1227         idx->data[k - 1] = k;
 1228       }
 1229   
 1230       st.site = &hb_emlrtRSI;
 1231       st.site = &hb_emlrtRSI;
 1232       if (1 > x->size[0] - 1) {
 1233         overflow = FALSE;
 1234       } else {
 1235         overflow = (x->size[0] - 1 > 2147483645);
 1236       }
 1237   
 1238       if (overflow) {
 1239         b_st.site = &l_emlrtRSI;
 1240         check_forloop_overflow_error(&b_st);
 1241       }
 1242   
 1243       for (k = 1; k <= x->size[0] - 1; k += 2) {
 1244         st.site = &ib_emlrtRSI;
 1245         st.site = &ib_emlrtRSI;
 1246         guard2 = FALSE;
 1247         if (x->data[k - 1] <= x->data[k]) {
 1248           guard2 = TRUE;
 1249         } else if (muDoubleScalarIsNaN(x->data[k])) {
 1250           guard2 = TRUE;
 1251         } else {
 1252           overflow = FALSE;
 1253         }
 1254   
 1255         if (guard2 == TRUE) {
 1256           overflow = TRUE;
 1257         }
 1258   
 1259         if (overflow) {
 1260         } else {
 1261           st.site = &jb_emlrtRSI;
 1262           idx->data[k - 1] = k + 1;
 1263           st.site = &ob_emlrtRSI;
 1264           idx->data[k] = k;
 1265         }
 1266       }
 1267   
 1268       b_emxInit_int32_T(sp, &idx0, 1, &s_emlrtRTEI, TRUE);
 1269       k = idx0->size[0];
 1270       idx0->size[0] = x->size[0];
 1271       emxEnsureCapacity(sp, (emxArray__common *)idx0, k, (int32_T)sizeof(int32_T),
 1272                         &r_emlrtRTEI);
 1273       i = x->size[0];
 1274       for (k = 0; k < i; k++) {
 1275         idx0->data[k] = 1;
 1276       }
 1277   
 1278       i = 2;
 1279       while (i < x->size[0]) {
 1280         st.site = &kb_emlrtRSI;
 1281         i2 = i << 1;
 1282         j = 1;
 1283         st.site = &lb_emlrtRSI;
 1284         for (pEnd = 1 + i; pEnd < x->size[0] + 1; pEnd = qEnd + i) {
 1285           p = j;
 1286           q = pEnd - 1;
 1287           st.site = &mb_emlrtRSI;
 1288           qEnd = j + i2;
 1289           if (qEnd > x->size[0] + 1) {
 1290             qEnd = x->size[0] + 1;
 1291           }
 1292   
 1293           k = 0;
 1294           st.site = &nb_emlrtRSI;
 1295           kEnd = qEnd - j;
 1296           while (k + 1 <= kEnd) {
 1297             st.site = &pb_emlrtRSI;
 1298             guard1 = FALSE;
 1299             if (x->data[idx->data[p - 1] - 1] <= x->data[idx->data[q] - 1]) {
 1300               guard1 = TRUE;
 1301             } else if (muDoubleScalarIsNaN(x->data[idx->data[q] - 1])) {
 1302               guard1 = TRUE;
 1303             } else {
 1304               overflow = FALSE;
 1305             }
 1306   
 1307             if (guard1 == TRUE) {
 1308               overflow = TRUE;
 1309             }
 1310   
 1311             if (overflow) {
 1312               idx0->data[k] = idx->data[p - 1];
 1313               st.site = &qb_emlrtRSI;
 1314               p++;
 1315               if (p == pEnd) {
 1316                 while (q + 1 < qEnd) {
 1317                   st.site = &rb_emlrtRSI;
 1318                   k++;
 1319                   idx0->data[k] = idx->data[q];
 1320                   st.site = &sb_emlrtRSI;
 1321                   q++;
 1322                 }
 1323               }
 1324             } else {
 1325               idx0->data[k] = idx->data[q];
 1326               st.site = &tb_emlrtRSI;
 1327               q++;
 1328               if (q + 1 == qEnd) {
 1329                 while (p < pEnd) {
 1330                   st.site = &ub_emlrtRSI;
 1331                   k++;
 1332                   idx0->data[k] = idx->data[p - 1];
 1333                   st.site = &vb_emlrtRSI;
 1334                   p++;
 1335                 }
 1336               }
 1337             }
 1338   
 1339             st.site = &wb_emlrtRSI;
 1340             k++;
 1341           }
 1342   
 1343           st.site = &xb_emlrtRSI;
 1344           st.site = &yb_emlrtRSI;
 1345           for (k = 0; k + 1 <= kEnd; k++) {
 1346             st.site = &ac_emlrtRSI;
 1347             idx->data[(j + k) - 1] = idx0->data[k];
 1348           }
 1349   
 1350           j = qEnd;
 1351           st.site = &bc_emlrtRSI;
 1352         }
 1353   
 1354         i = i2;
 1355       }
 1356   
 1357       emxFree_int32_T(&idx0);
 1358     }
 1359   
 1360     emlrtHeapReferenceStackLeaveFcnR2012b(sp);
 1361   }
 1362   
 1363   static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *A, const
 1364     char_T *identifier, emxArray_uint8_T *y)
 1365   {
 1366     emlrtMsgIdentifier thisId;
 1367     thisId.fIdentifier = identifier;
 1368     thisId.fParent = NULL;
 1369     b_emlrt_marshallIn(sp, emlrtAlias(A), &thisId, y);
 1370     emlrtDestroyArray(&A);
 1371   }
 1372   
 1373   static const mxArray *emlrt_marshallOut(emxArray_real_T *u)
 1374   {
 1375     const mxArray *y;
 1376     static const int32_T iv7[4] = { 0, 0, 0, 0 };
 1377   
 1378     const mxArray *m3;
 1379     y = NULL;
 1380     m3 = mxCreateNumericArray(4, (int32_T *)&iv7, mxDOUBLE_CLASS, mxREAL);
 1381     mxSetData((mxArray *)m3, (void *)u->data);
 1382     mxSetDimensions((mxArray *)m3, u->size, 4);
 1383     emlrtAssign(&y, m3);
 1384     return y;
 1385   }
 1386   
 1387   static void emxEnsureCapacity(const emlrtStack *sp, emxArray__common *emxArray,
 1388     int32_T oldNumel, int32_T elementSize, const emlrtRTEInfo *srcLocation)
 1389   {
 1390     int32_T newNumel;
 1391     int32_T i;
 1392     void *newData;
 1393     newNumel = 1;
 1394     for (i = 0; i < emxArray->numDimensions; i++) {
 1395       newNumel = (int32_T)emlrtSizeMulR2012b((uint32_T)newNumel, (uint32_T)
 1396         emxArray->size[i], srcLocation, sp);
 1397     }
 1398   
 1399     if (newNumel > emxArray->allocatedSize) {
 1400       i = emxArray->allocatedSize;
 1401       if (i < 16) {
 1402         i = 16;
 1403       }
 1404   
 1405       while (i < newNumel) {
 1406         i = (int32_T)emlrtSizeMulR2012b((uint32_T)i, 2U, srcLocation, sp);
 1407       }
 1408   
 1409       newData = emlrtCallocMex((uint32_T)i, (uint32_T)elementSize);
 1410       if (newData == NULL) {
 1411         emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1412       }
 1413   
 1414       if (emxArray->data != NULL) {
 1415         memcpy(newData, emxArray->data, (uint32_T)(elementSize * oldNumel));
 1416         if (emxArray->canFreeData) {
 1417           emlrtFreeMex(emxArray->data);
 1418         }
 1419       }
 1420   
 1421       emxArray->data = newData;
 1422       emxArray->allocatedSize = i;
 1423       emxArray->canFreeData = TRUE;
 1424     }
 1425   }
 1426   
 1427   static void emxFree_boolean_T(emxArray_boolean_T **pEmxArray)
 1428   {
 1429     if (*pEmxArray != (emxArray_boolean_T *)NULL) {
 1430       if ((*pEmxArray)->canFreeData) {
 1431         emlrtFreeMex((void *)(*pEmxArray)->data);
 1432       }
 1433   
 1434       emlrtFreeMex((void *)(*pEmxArray)->size);
 1435       emlrtFreeMex((void *)*pEmxArray);
 1436       *pEmxArray = (emxArray_boolean_T *)NULL;
 1437     }
 1438   }
 1439   
 1440   static void emxFree_int32_T(emxArray_int32_T **pEmxArray)
 1441   {
 1442     if (*pEmxArray != (emxArray_int32_T *)NULL) {
 1443       if ((*pEmxArray)->canFreeData) {
 1444         emlrtFreeMex((void *)(*pEmxArray)->data);
 1445       }
 1446   
 1447       emlrtFreeMex((void *)(*pEmxArray)->size);
 1448       emlrtFreeMex((void *)*pEmxArray);
 1449       *pEmxArray = (emxArray_int32_T *)NULL;
 1450     }
 1451   }
 1452   
 1453   static void emxFree_real_T(emxArray_real_T **pEmxArray)
 1454   {
 1455     if (*pEmxArray != (emxArray_real_T *)NULL) {
 1456       if ((*pEmxArray)->canFreeData) {
 1457         emlrtFreeMex((void *)(*pEmxArray)->data);
 1458       }
 1459   
 1460       emlrtFreeMex((void *)(*pEmxArray)->size);
 1461       emlrtFreeMex((void *)*pEmxArray);
 1462       *pEmxArray = (emxArray_real_T *)NULL;
 1463     }
 1464   }
 1465   
 1466   static void emxFree_uint8_T(emxArray_uint8_T **pEmxArray)
 1467   {
 1468     if (*pEmxArray != (emxArray_uint8_T *)NULL) {
 1469       if ((*pEmxArray)->canFreeData) {
 1470         emlrtFreeMex((void *)(*pEmxArray)->data);
 1471       }
 1472   
 1473       emlrtFreeMex((void *)(*pEmxArray)->size);
 1474       emlrtFreeMex((void *)*pEmxArray);
 1475       *pEmxArray = (emxArray_uint8_T *)NULL;
 1476     }
 1477   }
 1478   
 1479   static void emxInit_boolean_T(const emlrtStack *sp, emxArray_boolean_T
 1480     **pEmxArray, int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T
 1481     doPush)
 1482   {
 1483     emxArray_boolean_T *emxArray;
 1484     int32_T i;
 1485     *pEmxArray = (emxArray_boolean_T *)emlrtMallocMex(sizeof(emxArray_boolean_T));
 1486     if ((void *)*pEmxArray == NULL) {
 1487       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1488     }
 1489   
 1490     if (doPush) {
 1491       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
 1492         emxFree_boolean_T);
 1493     }
 1494   
 1495     emxArray = *pEmxArray;
 1496     emxArray->data = (boolean_T *)NULL;
 1497     emxArray->numDimensions = numDimensions;
 1498     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
 1499       * numDimensions));
 1500     if ((void *)emxArray->size == NULL) {
 1501       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1502     }
 1503   
 1504     emxArray->allocatedSize = 0;
 1505     emxArray->canFreeData = TRUE;
 1506     for (i = 0; i < numDimensions; i++) {
 1507       emxArray->size[i] = 0;
 1508     }
 1509   }
 1510   
 1511   static void emxInit_int32_T(const emlrtStack *sp, emxArray_int32_T **pEmxArray,
 1512     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
 1513   {
 1514     emxArray_int32_T *emxArray;
 1515     int32_T i;
 1516     *pEmxArray = (emxArray_int32_T *)emlrtMallocMex(sizeof(emxArray_int32_T));
 1517     if ((void *)*pEmxArray == NULL) {
 1518       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1519     }
 1520   
 1521     if (doPush) {
 1522       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
 1523         emxFree_int32_T);
 1524     }
 1525   
 1526     emxArray = *pEmxArray;
 1527     emxArray->data = (int32_T *)NULL;
 1528     emxArray->numDimensions = numDimensions;
 1529     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
 1530       * numDimensions));
 1531     if ((void *)emxArray->size == NULL) {
 1532       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1533     }
 1534   
 1535     emxArray->allocatedSize = 0;
 1536     emxArray->canFreeData = TRUE;
 1537     for (i = 0; i < numDimensions; i++) {
 1538       emxArray->size[i] = 0;
 1539     }
 1540   }
 1541   
 1542   static void emxInit_real_T(const emlrtStack *sp, emxArray_real_T **pEmxArray,
 1543     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
 1544   {
 1545     emxArray_real_T *emxArray;
 1546     int32_T i;
 1547     *pEmxArray = (emxArray_real_T *)emlrtMallocMex(sizeof(emxArray_real_T));
 1548     if ((void *)*pEmxArray == NULL) {
 1549       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1550     }
 1551   
 1552     if (doPush) {
 1553       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
 1554         emxFree_real_T);
 1555     }
 1556   
 1557     emxArray = *pEmxArray;
 1558     emxArray->data = (real_T *)NULL;
 1559     emxArray->numDimensions = numDimensions;
 1560     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
 1561       * numDimensions));
 1562     if ((void *)emxArray->size == NULL) {
 1563       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1564     }
 1565   
 1566     emxArray->allocatedSize = 0;
 1567     emxArray->canFreeData = TRUE;
 1568     for (i = 0; i < numDimensions; i++) {
 1569       emxArray->size[i] = 0;
 1570     }
 1571   }
 1572   
 1573   static void emxInit_uint8_T(const emlrtStack *sp, emxArray_uint8_T **pEmxArray,
 1574     int32_T numDimensions, const emlrtRTEInfo *srcLocation, boolean_T doPush)
 1575   {
 1576     emxArray_uint8_T *emxArray;
 1577     int32_T i;
 1578     *pEmxArray = (emxArray_uint8_T *)emlrtMallocMex(sizeof(emxArray_uint8_T));
 1579     if ((void *)*pEmxArray == NULL) {
 1580       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1581     }
 1582   
 1583     if (doPush) {
 1584       emlrtPushHeapReferenceStackR2012b(sp, (void *)pEmxArray, (void (*)(void *))
 1585         emxFree_uint8_T);
 1586     }
 1587   
 1588     emxArray = *pEmxArray;
 1589     emxArray->data = (uint8_T *)NULL;
 1590     emxArray->numDimensions = numDimensions;
 1591     emxArray->size = (int32_T *)emlrtMallocMex((uint32_T)(sizeof(int32_T)
 1592       * numDimensions));
 1593     if ((void *)emxArray->size == NULL) {
 1594       emlrtHeapAllocationErrorR2012b(srcLocation, sp);
 1595     }
 1596   
 1597     emxArray->allocatedSize = 0;
 1598     emxArray->canFreeData = TRUE;
 1599     for (i = 0; i < numDimensions; i++) {
 1600       emxArray->size[i] = 0;
 1601     }
 1602   }
 1603   
 1604   static void error(const emlrtStack *sp, const mxArray *b, emlrtMCInfo *location)
 1605   {
 1606     const mxArray *pArray;
 1607     pArray = b;
 1608     emlrtCallMATLABR2012b(sp, 0, NULL, 1, &pArray, "error", TRUE, location);
 1609   }
 1610   
 1611   static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
 1612     emlrtMsgIdentifier *parentId, emxArray_real_T *y)
 1613   {
 1614     i_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
 1615     emlrtDestroyArray(&u);
 1616   }
 1617   
 1618   static void g_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
 1619     emlrtMsgIdentifier *msgId, emxArray_uint8_T *ret)
 1620   {
 1621     int32_T iv10[3];
 1622     boolean_T bv0[3];
 1623     int32_T i;
 1624     static const int8_T iv11[3] = { -1, -1, 3 };
 1625   
 1626     int32_T iv12[3];
 1627     for (i = 0; i < 3; i++) {
 1628       iv10[i] = iv11[i];
 1629       bv0[i] = TRUE;
 1630     }
 1631   
 1632     emlrtCheckVsBuiltInR2012b(sp, msgId, src, "uint8", FALSE, 3U, iv10, bv0, iv12);
 1633     ret->size[0] = iv12[0];
 1634     ret->size[1] = iv12[1];
 1635     ret->size[2] = iv12[2];
 1636     ret->allocatedSize = ret->size[0] * ret->size[1] * ret->size[2];
 1637     ret->data = (uint8_T *)mxGetData(src);
 1638     ret->canFreeData = FALSE;
 1639     emlrtDestroyArray(&src);
 1640   }
 1641   
 1642   static real_T h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
 1643     emlrtMsgIdentifier *msgId)
 1644   {
 1645     real_T ret;
 1646     emlrtCheckBuiltInR2012b(sp, msgId, src, "double", FALSE, 0U, 0);
 1647     ret = *(real_T *)mxGetData(src);
 1648     emlrtDestroyArray(&src);
 1649     return ret;
 1650   }
 1651   
 1652   static void i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
 1653     emlrtMsgIdentifier *msgId, emxArray_real_T *ret)
 1654   {
 1655     int32_T iv13[3];
 1656     boolean_T bv1[3];
 1657     int32_T i;
 1658     int32_T iv14[3];
 1659     for (i = 0; i < 3; i++) {
 1660       iv13[i] = -1;
 1661       bv1[i] = TRUE;
 1662     }
 1663   
 1664     emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", FALSE, 3U, iv13, bv1, iv14);
 1665     ret->size[0] = iv14[0];
 1666     ret->size[1] = iv14[1];
 1667     ret->size[2] = iv14[2];
 1668     ret->allocatedSize = ret->size[0] * ret->size[1] * ret->size[2];
 1669     ret->data = (real_T *)mxGetData(src);
 1670     ret->canFreeData = FALSE;
 1671     emlrtDestroyArray(&src);
 1672   }
 1673   
 1674   static const mxArray *message(const emlrtStack *sp, const mxArray *b, const
 1675     mxArray *c, emlrtMCInfo *location)
 1676   {
 1677     const mxArray *pArrays[2];
 1678     const mxArray *m6;
 1679     pArrays[0] = b;
 1680     pArrays[1] = c;
 1681     return emlrtCallMATLABR2012b(sp, 1, &m6, 2, pArrays, "message", TRUE, location);
 1682   }
 1683   
 1684   /*
 1685    *
 1686    */
 1687   static void squeeze(const emlrtStack *sp, const emxArray_real_T *a,
 1688                       emxArray_real_T *b)
 1689   {
 1690     int32_T k;
 1691     boolean_T overflow;
 1692     int32_T sqsz[3];
 1693     emlrtStack st;
 1694     emlrtStack b_st;
 1695     st.prev = sp;
 1696     st.tls = sp->tls;
 1697     b_st.prev = &st;
 1698     b_st.tls = st.tls;
 1699     st.site = &h_emlrtRSI;
 1700     k = 3;
 1701     while ((k > 2) && (a->size[2] == 1)) {
 1702       k = 2;
 1703     }
 1704   
 1705     if (k <= 2) {
 1706       k = b->size[0];
 1707       b->size[0] = 1;
 1708       emxEnsureCapacity(sp, (emxArray__common *)b, k, (int32_T)sizeof(real_T),
 1709                         &k_emlrtRTEI);
 1710       st.site = &i_emlrtRSI;
 1711       if (1 > a->size[2]) {
 1712         overflow = FALSE;
 1713       } else {
 1714         overflow = (a->size[2] > 2147483646);
 1715       }
 1716   
 1717       if (overflow) {
 1718         b_st.site = &l_emlrtRSI;
 1719         check_forloop_overflow_error(&b_st);
 1720       }
 1721   
 1722       for (k = 1; k <= a->size[2]; k++) {
 1723         b->data[0] = a->data[k - 1];
 1724       }
 1725     } else {
 1726       for (k = 0; k < 3; k++) {
 1727         sqsz[k] = 1;
 1728       }
 1729   
 1730       if (a->size[2] != 1) {
 1731         sqsz[0] = a->size[2];
 1732       }
 1733   
 1734       k = b->size[0];
 1735       b->size[0] = sqsz[0];
 1736       emxEnsureCapacity(sp, (emxArray__common *)b, k, (int32_T)sizeof(real_T),
 1737                         &l_emlrtRTEI);
 1738       st.site = &j_emlrtRSI;
 1739       if (1 > a->size[2]) {
 1740         overflow = FALSE;
 1741       } else {
 1742         overflow = (a->size[2] > 2147483646);
 1743       }
 1744   
 1745       if (overflow) {
 1746         b_st.site = &l_emlrtRSI;
 1747         check_forloop_overflow_error(&b_st);
 1748       }
 1749   
 1750       for (k = 0; k + 1 <= a->size[2]; k++) {
 1751         b->data[k] = a->data[k];
 1752       }
 1753     }
 1754   }
 1755   
 1756   /*
 1757    * function [CSH_ann,numUniqueResultsPerPixel,sortedErrors] = TransitiveKNN_part2(A,B,k,width,overSafeResults,errorMat)
 1758    */
 1759   void TransitiveKNN_part2(const emlrtStack *sp, const emxArray_uint8_T *A, const
 1760     emxArray_uint8_T *B, real_T k, real_T width, const emxArray_real_T
 1761     *overSafeResults, const emxArray_real_T *errorMat, emxArray_real_T *CSH_ann,
 1762     emxArray_real_T *numUniqueResultsPerPixel, emxArray_real_T *sortedErrors)
 1763   {
 1764     real_T d0;
 1765     int32_T plast;
 1766     int32_T i0;
 1767     real_T d1;
 1768     int32_T idx;
 1769     emxArray_real_T *b_CSH_ann;
 1770     int32_T i;
 1771     emxArray_real_T *OSR;
 1772     emxArray_real_T *sOSR;
 1773     emxArray_real_T *uOSRinds;
 1774     emxArray_real_T *uOSRFinalinds;
 1775     emxArray_real_T *sErrors;
 1776     emxArray_int32_T *r0;
 1777     emxArray_boolean_T *x;
 1778     emxArray_int32_T *ii;
 1779     emxArray_int32_T *v1;
 1780     emxArray_real_T *r1;
 1781     emxArray_real_T *b_overSafeResults;
 1782     emxArray_real_T *b_errorMat;
 1783     emxArray_int32_T *b_ii;
 1784     emxArray_real_T *b_sErrors;
 1785     int32_T j;
 1786     int32_T isrc;
 1787     boolean_T b0;
 1788     boolean_T exitg4;
 1789     boolean_T guard2 = FALSE;
 1790     const mxArray *y;
 1791     const mxArray *m0;
 1792     uint32_T siz_idx_0;
 1793     uint32_T siz_idx_1;
 1794     int32_T exitg3;
 1795     boolean_T guard1 = FALSE;
 1796     boolean_T b;
 1797     const mxArray *b_y;
 1798     static const int32_T iv0[2] = { 1, 36 };
 1799   
 1800     char_T cv0[36];
 1801     static const char_T cv1[36] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
 1802       'L', 'A', 'B', ':', 'i', 'n', 'd', '2', 's', 'u', 'b', '_', 'I', 'n', 'd',
 1803       'e', 'x', 'O', 'u', 't', 'O', 'f', 'R', 'a', 'n', 'g', 'e' };
 1804   
 1805     int32_T b_v1[1];
 1806     int32_T c_v1[1];
 1807     int32_T iv1[3];
 1808     uint32_T insz[4];
 1809     uint32_T outsz[4];
 1810     boolean_T exitg2;
 1811     boolean_T b_guard1 = FALSE;
 1812     static const int8_T iv2[4] = { 2, 3, 4, 1 };
 1813   
 1814     boolean_T b1;
 1815     int32_T iwork[4];
 1816     int32_T inc[4];
 1817     static const int8_T iv3[4] = { 1, 2, 3, 0 };
 1818   
 1819     boolean_T b2;
 1820     int32_T exitg1;
 1821     emlrtStack st;
 1822     emlrtStack b_st;
 1823     emlrtStack c_st;
 1824     emlrtStack d_st;
 1825     emlrtStack e_st;
 1826     st.prev = sp;
 1827     st.tls = sp->tls;
 1828     b_st.prev = &st;
 1829     b_st.tls = st.tls;
 1830     c_st.prev = &b_st;
 1831     c_st.tls = b_st.tls;
 1832     d_st.prev = &c_st;
 1833     d_st.tls = c_st.tls;
 1834     e_st.prev = &st;
 1835     e_st.tls = st.tls;
 1836     emlrtHeapReferenceStackEnterFcnR2012b(sp);
 1837   
 1838     /* 'TransitiveKNN_part2:3' [hA,wA,dA] = size(A); */
 1839     /* 'TransitiveKNN_part2:4' [hB,wB,dB] = size(B); */
 1840     /*  sort by errors and then take the k mappings of the k smallest [unique!] errors */
 1841     /* 'TransitiveKNN_part2:7' br_boundary_to_ignore = width-1; */
 1842     /* 'TransitiveKNN_part2:8' numUniqueResultsPerPixel = zeros(hA-br_boundary_to_ignore,wA-br_boundary_to_ignore); */
 1843     d0 = (real_T)A->size[0] - (width - 1.0);
 1844     d0 = emlrtNonNegativeCheckFastR2012b(d0, &b_emlrtDCI, sp);
 1845     plast = (int32_T)emlrtIntegerCheckFastR2012b(d0, &emlrtDCI, sp);
 1846     d0 = (real_T)A->size[1] - (width - 1.0);
 1847     d0 = emlrtNonNegativeCheckFastR2012b(d0, &d_emlrtDCI, sp);
 1848     emlrtIntegerCheckFastR2012b(d0, &c_emlrtDCI, sp);
 1849     i0 = numUniqueResultsPerPixel->size[0] * numUniqueResultsPerPixel->size[1];
 1850     numUniqueResultsPerPixel->size[0] = plast;
 1851     emxEnsureCapacity(sp, (emxArray__common *)numUniqueResultsPerPixel, i0,
 1852                       (int32_T)sizeof(real_T), &emlrtRTEI);
 1853     d0 = (real_T)A->size[0] - (width - 1.0);
 1854     d0 = emlrtNonNegativeCheckFastR2012b(d0, &b_emlrtDCI, sp);
 1855     emlrtIntegerCheckFastR2012b(d0, &emlrtDCI, sp);
 1856     d0 = (real_T)A->size[1] - (width - 1.0);
 1857     d0 = emlrtNonNegativeCheckFastR2012b(d0, &d_emlrtDCI, sp);
 1858     plast = (int32_T)emlrtIntegerCheckFastR2012b(d0, &c_emlrtDCI, sp);
 1859     i0 = numUniqueResultsPerPixel->size[0] * numUniqueResultsPerPixel->size[1];
 1860     numUniqueResultsPerPixel->size[1] = plast;
 1861     emxEnsureCapacity(sp, (emxArray__common *)numUniqueResultsPerPixel, i0,
 1862                       (int32_T)sizeof(real_T), &emlrtRTEI);
 1863     d0 = (real_T)A->size[0] - (width - 1.0);
 1864     d0 = emlrtNonNegativeCheckFastR2012b(d0, &b_emlrtDCI, sp);
 1865     d1 = (real_T)A->size[1] - (width - 1.0);
 1866     d1 = emlrtNonNegativeCheckFastR2012b(d1, &d_emlrtDCI, sp);
 1867     idx = (int32_T)emlrtIntegerCheckFastR2012b(d0, &emlrtDCI, sp) * (int32_T)
 1868       emlrtIntegerCheckFastR2012b(d1, &c_emlrtDCI, sp);
 1869     for (i0 = 0; i0 < idx; i0++) {
 1870       numUniqueResultsPerPixel->data[i0] = 0.0;
 1871     }
 1872   
 1873     b_emxInit_real_T(sp, &b_CSH_ann, 4, &h_emlrtRTEI, TRUE);
 1874   
 1875     /* 'TransitiveKNN_part2:9' CSH_ann = zeros(k,hA,wA,2); */
 1876     d0 = emlrtNonNegativeCheckFastR2012b(k, &f_emlrtDCI, sp);
 1877     emlrtIntegerCheckFastR2012b(d0, &e_emlrtDCI, sp);
 1878     i0 = b_CSH_ann->size[0] * b_CSH_ann->size[1] * b_CSH_ann->size[2] *
 1879       b_CSH_ann->size[3];
 1880     b_CSH_ann->size[0] = (int32_T)k;
 1881     emxEnsureCapacity(sp, (emxArray__common *)b_CSH_ann, i0, (int32_T)sizeof
 1882                       (real_T), &emlrtRTEI);
 1883     d0 = emlrtNonNegativeCheckFastR2012b(k, &f_emlrtDCI, sp);
 1884     emlrtIntegerCheckFastR2012b(d0, &e_emlrtDCI, sp);
 1885     plast = A->size[0];
 1886     i0 = b_CSH_ann->size[0] * b_CSH_ann->size[1] * b_CSH_ann->size[2] *
 1887       b_CSH_ann->size[3];
 1888     b_CSH_ann->size[1] = plast;
 1889     emxEnsureCapacity(sp, (emxArray__common *)b_CSH_ann, i0, (int32_T)sizeof
 1890                       (real_T), &emlrtRTEI);
 1891     d0 = emlrtNonNegativeCheckFastR2012b(k, &f_emlrtDCI, sp);
 1892     emlrtIntegerCheckFastR2012b(d0, &e_emlrtDCI, sp);
 1893     plast = A->size[1];
 1894     i0 = b_CSH_ann->size[0] * b_CSH_ann->size[1] * b_CSH_ann->size[2] *
 1895       b_CSH_ann->size[3];
 1896     b_CSH_ann->size[2] = plast;
 1897     b_CSH_ann->size[3] = 2;
 1898     emxEnsureCapacity(sp, (emxArray__common *)b_CSH_ann, i0, (int32_T)sizeof
 1899                       (real_T), &emlrtRTEI);
 1900     d0 = emlrtNonNegativeCheckFastR2012b(k, &f_emlrtDCI, sp);
 1901     idx = (int32_T)emlrtIntegerCheckFastR2012b(d0, &e_emlrtDCI, sp) * A->size[0] *
 1902       A->size[1] << 1;
 1903     for (i0 = 0; i0 < idx; i0++) {
 1904       b_CSH_ann->data[i0] = 0.0;
 1905     }
 1906   
 1907     /* 'TransitiveKNN_part2:10' sortedErrors = zeros(hA,wA,k); */
 1908     plast = A->size[0];
 1909     i0 = sortedErrors->size[0] * sortedErrors->size[1] * sortedErrors->size[2];
 1910     sortedErrors->size[0] = plast;
 1911     emxEnsureCapacity(sp, (emxArray__common *)sortedErrors, i0, (int32_T)sizeof
 1912                       (real_T), &emlrtRTEI);
 1913     plast = A->size[1];
 1914     i0 = sortedErrors->size[0] * sortedErrors->size[1] * sortedErrors->size[2];
 1915     sortedErrors->size[1] = plast;
 1916     emxEnsureCapacity(sp, (emxArray__common *)sortedErrors, i0, (int32_T)sizeof
 1917                       (real_T), &emlrtRTEI);
 1918     i0 = sortedErrors->size[0] * sortedErrors->size[1] * sortedErrors->size[2];
 1919     sortedErrors->size[2] = (int32_T)k;
 1920     emxEnsureCapacity(sp, (emxArray__common *)sortedErrors, i0, (int32_T)sizeof
 1921                       (real_T), &emlrtRTEI);
 1922     idx = A->size[0] * A->size[1] * (int32_T)k;
 1923     for (i0 = 0; i0 < idx; i0++) {
 1924       sortedErrors->data[i0] = 0.0;
 1925     }
 1926   
 1927     /*  CSH_errors = zeros(hA,wA,k); */
 1928     /* 'TransitiveKNN_part2:12' for i = 1 : hA-br_boundary_to_ignore */
 1929     d0 = (real_T)A->size[0] - (width - 1.0);
 1930     emlrtForLoopVectorCheckR2012b(1.0, 1.0, d0, mxDOUBLE_CLASS, (int32_T)d0,
 1931       &x_emlrtRTEI, sp);
 1932     i = 0;
 1933     emxInit_real_T(sp, &OSR, 1, &d_emlrtRTEI, TRUE);
 1934     emxInit_real_T(sp, &sOSR, 1, &e_emlrtRTEI, TRUE);
 1935     emxInit_real_T(sp, &uOSRinds, 1, &f_emlrtRTEI, TRUE);
 1936     emxInit_real_T(sp, &uOSRFinalinds, 1, &g_emlrtRTEI, TRUE);
 1937     emxInit_real_T(sp, &sErrors, 1, &emlrtRTEI, TRUE);
 1938     emxInit_int32_T(sp, &r0, 2, &emlrtRTEI, TRUE);
 1939     emxInit_boolean_T(sp, &x, 2, &emlrtRTEI, TRUE);
 1940     b_emxInit_int32_T(sp, &ii, 1, &i_emlrtRTEI, TRUE);
 1941     b_emxInit_int32_T(sp, &v1, 1, &j_emlrtRTEI, TRUE);
 1942     c_emxInit_real_T(sp, &r1, 2, &emlrtRTEI, TRUE);
 1943     d_emxInit_real_T(sp, &b_overSafeResults, 3, &emlrtRTEI, TRUE);
 1944     d_emxInit_real_T(sp, &b_errorMat, 3, &emlrtRTEI, TRUE);
 1945     b_emxInit_int32_T(sp, &b_ii, 1, &emlrtRTEI, TRUE);
 1946     emxInit_real_T(sp, &b_sErrors, 1, &emlrtRTEI, TRUE);
 1947     while (i <= (int32_T)d0 - 1) {
 1948       /* 'TransitiveKNN_part2:13' for j = 1 : wA-br_boundary_to_ignore */
 1949       d1 = (real_T)A->size[1] - (width - 1.0);
 1950       emlrtForLoopVectorCheckR2012b(1.0, 1.0, d1, mxDOUBLE_CLASS, (int32_T)d1,
 1951         &y_emlrtRTEI, sp);
 1952       j = 0;
 1953       while (j <= (int32_T)d1 - 1) {
 1954         /* 'TransitiveKNN_part2:14' [sErrors,sInds] = sort(squeeze(errorMat(i,j,:))); */
 1955         idx = errorMat->size[2];
 1956         i0 = errorMat->size[1];
 1957         plast = emlrtDynamicBoundsCheckFastR2012b(j + 1, 1, i0, &b_emlrtBCI, sp);
 1958         i0 = errorMat->size[0];
 1959         isrc = emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i0, &emlrtBCI, sp);
 1960         i0 = b_errorMat->size[0] * b_errorMat->size[1] * b_errorMat->size[2];
 1961         b_errorMat->size[0] = 1;
 1962         b_errorMat->size[1] = 1;
 1963         b_errorMat->size[2] = idx;
 1964         emxEnsureCapacity(sp, (emxArray__common *)b_errorMat, i0, (int32_T)sizeof
 1965                           (real_T), &emlrtRTEI);
 1966         for (i0 = 0; i0 < idx; i0++) {
 1967           b_errorMat->data[b_errorMat->size[0] * b_errorMat->size[1] * i0] =
 1968             errorMat->data[((isrc + errorMat->size[0] * (plast - 1)) +
 1969                             errorMat->size[0] * errorMat->size[1] * i0) - 1];
 1970         }
 1971   
 1972         st.site = &emlrtRSI;
 1973         squeeze(&st, b_errorMat, OSR);
 1974         st.site = &emlrtRSI;
 1975         b_st.site = &m_emlrtRSI;
 1976         eml_sort(&b_st, OSR, sErrors, v1);
 1977   
 1978         /* 'TransitiveKNN_part2:15' OSR = squeeze(overSafeResults(i,j,:)); */
 1979         idx = overSafeResults->size[2];
 1980         i0 = overSafeResults->size[1];
 1981         plast = emlrtDynamicBoundsCheckFastR2012b(j + 1, 1, i0, &d_emlrtBCI, sp);
 1982         i0 = overSafeResults->size[0];
 1983         isrc = emlrtDynamicBoundsCheckFastR2012b(i + 1, 1, i0, &c_emlrtBCI, sp);
 1984         i0 = b_overSafeResults->size[0] * b_overSafeResults->size[1] *
 1985           b_overSafeResults->size[2];
 1986         b_overSafeResults->size[0] = 1;
 1987         b_overSafeResults->size[1] = 1;
 1988         b_overSafeResults->size[2] = idx;
 1989         emxEnsureCapacity(sp, (emxArray__common *)b_overSafeResults, i0, (int32_T)
 1990                           sizeof(real_T), &emlrtRTEI);
 1991         for (i0 = 0; i0 < idx; i0++) {
 1992           b_overSafeResults->data[b_overSafeResults->size[0] *
 1993             b_overSafeResults->size[1] * i0] = overSafeResults->data[((isrc +
 1994             overSafeResults->size[0] * (plast - 1)) + overSafeResults->size[0] *
 1995             overSafeResults->size[1] * i0) - 1];
 1996         }
 1997   
 1998         st.site = &b_emlrtRSI;
 1999         squeeze(&st, b_overSafeResults, OSR);
 2000   
 2001         /* 'TransitiveKNN_part2:16' sOSR = OSR(sInds); */
 2002         i0 = sOSR->size[0];
 2003         sOSR->size[0] = v1->size[0];
 2004         emxEnsureCapacity(sp, (emxArray__common *)sOSR, i0, (int32_T)sizeof(real_T),
 2005                           &emlrtRTEI);
 2006         idx = v1->size[0];
 2007         for (i0 = 0; i0 < idx; i0++) {
 2008           plast = OSR->size[0];
 2009           isrc = v1->data[i0];
 2010           sOSR->data[i0] = OSR->data[emlrtDynamicBoundsCheckFastR2012b(isrc, 1,
 2011             plast, &n_emlrtBCI, sp) - 1];
 2012         }
 2013   
 2014         /* 'TransitiveKNN_part2:17' uOSRinds = find(diff(sOSR)~=0); */
 2015         st.site = &c_emlrtRSI;
 2016         b_st.site = &c_emlrtRSI;
 2017         diff(&b_st, sOSR, r1);
 2018         i0 = x->size[0] * x->size[1];
 2019         x->size[0] = r1->size[0];
 2020         x->size[1] = r1->size[1];
 2021         emxEnsureCapacity(&st, (emxArray__common *)x, i0, (int32_T)sizeof
 2022                           (boolean_T), &emlrtRTEI);
 2023         idx = r1->size[0] * r1->size[1];
 2024         for (i0 = 0; i0 < idx; i0++) {
 2025           x->data[i0] = (r1->data[i0] != 0.0);
 2026         }
 2027   
 2028         b_st.site = &mc_emlrtRSI;
 2029         isrc = x->size[0] * x->size[1];
 2030         idx = 0;
 2031         i0 = ii->size[0];
 2032         ii->size[0] = isrc;
 2033         emxEnsureCapacity(&b_st, (emxArray__common *)ii, i0, (int32_T)sizeof
 2034                           (int32_T), &c_emlrtRTEI);
 2035         c_st.site = &oc_emlrtRSI;
 2036         if (1 > isrc) {
 2037           b0 = FALSE;
 2038         } else {
 2039           b0 = (isrc > 2147483646);
 2040         }
 2041   
 2042         if (b0) {
 2043           d_st.site = &l_emlrtRSI;
 2044           check_forloop_overflow_error(&d_st);
 2045         }
 2046   
 2047         plast = 1;
 2048         exitg4 = FALSE;
 2049         while ((exitg4 == FALSE) && (plast <= isrc)) {
 2050           guard2 = FALSE;
 2051           if (x->data[plast - 1]) {
 2052             c_st.site = &nc_emlrtRSI;
 2053             idx++;
 2054             ii->data[idx - 1] = plast;
 2055             if (idx >= isrc) {
 2056               exitg4 = TRUE;
 2057             } else {
 2058               guard2 = TRUE;
 2059             }
 2060           } else {
 2061             guard2 = TRUE;
 2062           }
 2063   
 2064           if (guard2 == TRUE) {
 2065             plast++;
 2066           }
 2067         }
 2068   
 2069         if (idx <= isrc) {
 2070         } else {
 2071           y = NULL;
 2072           m0 = mxCreateString("Assertion failed.");
 2073           emlrtAssign(&y, m0);
 2074           c_st.site = &sd_emlrtRSI;
 2075           error(&c_st, y, &j_emlrtMCI);
 2076         }
 2077   
 2078         if (isrc == 1) {
 2079           if (idx == 0) {
 2080             i0 = ii->size[0];
 2081             ii->size[0] = 0;
 2082             emxEnsureCapacity(&b_st, (emxArray__common *)ii, i0, (int32_T)sizeof
 2083                               (int32_T), &emlrtRTEI);
 2084           }
 2085         } else {
 2086           if (1 > idx) {
 2087             idx = 0;
 2088           }
 2089   
 2090           i0 = b_ii->size[0];
 2091           b_ii->size[0] = idx;
 2092           emxEnsureCapacity(&b_st, (emxArray__common *)b_ii, i0, (int32_T)sizeof
 2093                             (int32_T), &emlrtRTEI);
 2094           for (i0 = 0; i0 < idx; i0++) {
 2095             b_ii->data[i0] = ii->data[i0];
 2096           }
 2097   
 2098           i0 = ii->size[0];
 2099           ii->size[0] = b_ii->size[0];
 2100           emxEnsureCapacity(&b_st, (emxArray__common *)ii, i0, (int32_T)sizeof
 2101                             (int32_T), &emlrtRTEI);
 2102           idx = b_ii->size[0];
 2103           for (i0 = 0; i0 < idx; i0++) {
 2104             ii->data[i0] = b_ii->data[i0];
 2105           }
 2106         }
 2107   
 2108         i0 = uOSRinds->size[0];
 2109         uOSRinds->size[0] = ii->size[0];
 2110         emxEnsureCapacity(&st, (emxArray__common *)uOSRinds, i0, (int32_T)sizeof
 2111                           (real_T), &emlrtRTEI);
 2112         idx = ii->size[0];
 2113         for (i0 = 0; i0 < idx; i0++) {
 2114           uOSRinds->data[i0] = ii->data[i0];
 2115         }
 2116   
 2117         /*  giving up (possibly) on the last index (diff gives a 1-shorter vector) */
 2118         /* 'TransitiveKNN_part2:18' kActual = length(uOSRinds); */
 2119         st.site = &d_emlrtRSI;
 2120   
 2121         /* 'TransitiveKNN_part2:19' uOSRFinalinds = zeros(k,1); */
 2122         i0 = uOSRFinalinds->size[0];
 2123         uOSRFinalinds->size[0] = (int32_T)k;
 2124         emxEnsureCapacity(sp, (emxArray__common *)uOSRFinalinds, i0, (int32_T)
 2125                           sizeof(real_T), &emlrtRTEI);
 2126         idx = (int32_T)k;
 2127         for (i0 = 0; i0 < idx; i0++) {
 2128           uOSRFinalinds->data[i0] = 0.0;
 2129         }
 2130   
 2131         /* 'TransitiveKNN_part2:20' numUniqueResultsPerPixel(i,j) = min(k,kActual); */
 2132         st.site = &e_emlrtRSI;
 2133         b_st.site = &hc_emlrtRSI;
 2134         c_st.site = &ic_emlrtRSI;
 2135         i0 = numUniqueResultsPerPixel->size[0];
 2136         plast = numUniqueResultsPerPixel->size[1];
 2137         numUniqueResultsPerPixel->data[(emlrtDynamicBoundsCheckFastR2012b(i + 1, 1,
 2138           i0, &o_emlrtBCI, sp) + numUniqueResultsPerPixel->size[0] *
 2139           (emlrtDynamicBoundsCheckFastR2012b(j + 1, 1, plast, &p_emlrtBCI, sp) - 1))
 2140           - 1] = muDoubleScalarMin(k, uOSRinds->size[0]);
 2141   
 2142         /* 'TransitiveKNN_part2:21' if kActual >= k */
 2143         if (uOSRinds->size[0] >= k) {
 2144           /* 'TransitiveKNN_part2:22' uOSRFinalinds = uOSRinds(1:k); */
 2145           if (1.0 > k) {
 2146             idx = 0;
 2147           } else {
 2148             i0 = uOSRinds->size[0];
 2149             emlrtDynamicBoundsCheckFastR2012b(1, 1, i0, &e_emlrtBCI, sp);
 2150             i0 = uOSRinds->size[0];
 2151             plast = (int32_T)k;
 2152             idx = emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &e_emlrtBCI, sp);
 2153           }
 2154   
 2155           emlrtVectorVectorIndexCheckR2012b(uOSRinds->size[0], 1, 1, idx,
 2156             &emlrtECI, sp);
 2157           i0 = uOSRFinalinds->size[0];
 2158           uOSRFinalinds->size[0] = idx;
 2159           emxEnsureCapacity(sp, (emxArray__common *)uOSRFinalinds, i0, (int32_T)
 2160                             sizeof(real_T), &emlrtRTEI);
 2161           for (i0 = 0; i0 < idx; i0++) {
 2162             uOSRFinalinds->data[i0] = uOSRinds->data[i0];
 2163           }
 2164         } else {
 2165           /* 'TransitiveKNN_part2:23' else */
 2166           /* 'TransitiveKNN_part2:24' uOSRFinalinds(1:kActual) = uOSRinds; */
 2167           if (1 > uOSRinds->size[0]) {
 2168             idx = 0;
 2169           } else {
 2170             i0 = (int32_T)k;
 2171             emlrtDynamicBoundsCheckFastR2012b(1, 1, i0, &f_emlrtBCI, sp);
 2172             i0 = (int32_T)k;
 2173             plast = uOSRinds->size[0];
 2174             idx = emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &f_emlrtBCI, sp);
 2175           }
 2176   
 2177           i0 = uOSRinds->size[0];
 2178           emlrtSizeEqCheck1DFastR2012b(idx, i0, &b_emlrtECI, sp);
 2179           i0 = r0->size[0] * r0->size[1];
 2180           r0->size[0] = 1;
 2181           r0->size[1] = idx;
 2182           emxEnsureCapacity(sp, (emxArray__common *)r0, i0, (int32_T)sizeof
 2183                             (int32_T), &emlrtRTEI);
 2184           for (i0 = 0; i0 < idx; i0++) {
 2185             r0->data[r0->size[0] * i0] = i0;
 2186           }
 2187   
 2188           idx = r0->size[0] * r0->size[1];
 2189           for (i0 = 0; i0 < idx; i0++) {
 2190             uOSRFinalinds->data[r0->data[i0]] = uOSRinds->data[i0];
 2191           }
 2192   
 2193           /* 'TransitiveKNN_part2:25' uOSRFinalinds(kActual+1:k) = uOSRinds(end); */
 2194           if ((real_T)uOSRinds->size[0] + 1.0 > k) {
 2195             i0 = 0;
 2196             plast = 0;
 2197           } else {
 2198             i0 = uOSRFinalinds->size[0];
 2199             plast = (int32_T)(uOSRinds->size[0] + 1U);
 2200             i0 = emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &g_emlrtBCI, sp)
 2201               - 1;
 2202             plast = uOSRFinalinds->size[0];
 2203             isrc = (int32_T)k;
 2204             plast = emlrtDynamicBoundsCheckFastR2012b(isrc, 1, plast, &g_emlrtBCI,
 2205               sp);
 2206           }
 2207   
 2208           isrc = r0->size[0] * r0->size[1];
 2209           r0->size[0] = 1;
 2210           r0->size[1] = plast - i0;
 2211           emxEnsureCapacity(sp, (emxArray__common *)r0, isrc, (int32_T)sizeof
 2212                             (int32_T), &emlrtRTEI);
 2213           idx = plast - i0;
 2214           for (plast = 0; plast < idx; plast++) {
 2215             r0->data[r0->size[0] * plast] = i0 + plast;
 2216           }
 2217   
 2218           idx = r0->size[0] * r0->size[1];
 2219           for (i0 = 0; i0 < idx; i0++) {
 2220             plast = uOSRinds->size[0];
 2221             isrc = uOSRinds->size[0];
 2222             uOSRFinalinds->data[r0->data[i0]] = uOSRinds->
 2223               data[emlrtDynamicBoundsCheckFastR2012b(isrc, 1, plast, &q_emlrtBCI,
 2224               sp) - 1];
 2225           }
 2226   
 2227           /*  returning duplicate copies in this case */
 2228         }
 2229   
 2230         /*  NN results: */
 2231         /* 'TransitiveKNN_part2:28' [CSH_ann(:,i,j,2),CSH_ann(:,i,j,1)] = ind2sub([hB,wB],sOSR(uOSRFinalinds)); */
 2232         st.site = &f_emlrtRSI;
 2233         siz_idx_0 = (uint32_T)B->size[0];
 2234         siz_idx_1 = (uint32_T)B->size[1];
 2235         idx = uOSRFinalinds->size[0];
 2236         for (i0 = 0; i0 < idx; i0++) {
 2237           plast = v1->size[0];
 2238           isrc = (int32_T)uOSRFinalinds->data[i0];
 2239           emlrtDynamicBoundsCheckFastR2012b(isrc, 1, plast, &r_emlrtBCI, &st);
 2240         }
 2241   
 2242         b_st.site = &pc_emlrtRSI;
 2243         b_st.site = &qc_emlrtRSI;
 2244         c_st.site = &xc_emlrtRSI;
 2245         b_st.site = &qc_emlrtRSI;
 2246         plast = (int32_T)siz_idx_0 * (int32_T)siz_idx_1;
 2247         b_st.site = &rc_emlrtRSI;
 2248         i0 = uOSRFinalinds->size[0];
 2249         idx = 0;
 2250         do {
 2251           exitg3 = 0;
 2252           if (idx <= i0 - 1) {
 2253             guard1 = FALSE;
 2254             if (sOSR->data[(int32_T)uOSRFinalinds->data[idx] - 1] >= 1.0) {
 2255               c_st.site = &yc_emlrtRSI;
 2256               if (plast >= sOSR->data[(int32_T)uOSRFinalinds->data[idx] - 1]) {
 2257                 b = TRUE;
 2258               } else {
 2259                 guard1 = TRUE;
 2260               }
 2261             } else {
 2262               guard1 = TRUE;
 2263             }
 2264   
 2265             if (guard1 == TRUE) {
 2266               b = FALSE;
 2267             }
 2268   
 2269             if (!b) {
 2270               b = FALSE;
 2271               exitg3 = 1;
 2272             } else {
 2273               idx++;
 2274             }
 2275           } else {
 2276             b = TRUE;
 2277             exitg3 = 1;
 2278           }
 2279         } while (exitg3 == 0);
 2280   
 2281         if (b) {
 2282         } else {
 2283           b_y = NULL;
 2284           m0 = mxCreateCharArray(2, iv0);
 2285           for (isrc = 0; isrc < 36; isrc++) {
 2286             cv0[isrc] = cv1[isrc];
 2287           }
 2288   
 2289           emlrtInitCharArrayR2013a(&st, 36, m0, cv0);
 2290           emlrtAssign(&b_y, m0);
 2291           b_st.site = &rc_emlrtRSI;
 2292           e_st.site = &ud_emlrtRSI;
 2293           error(&b_st, b_message(&e_st, b_y, &k_emlrtMCI), &l_emlrtMCI);
 2294         }
 2295   
 2296         b_st.site = &sc_emlrtRSI;
 2297         i0 = v1->size[0];
 2298         v1->size[0] = uOSRFinalinds->size[0];
 2299         emxEnsureCapacity(&b_st, (emxArray__common *)v1, i0, (int32_T)sizeof
 2300                           (int32_T), &emlrtRTEI);
 2301         idx = uOSRFinalinds->size[0];
 2302         for (i0 = 0; i0 < idx; i0++) {
 2303           v1->data[i0] = (int32_T)sOSR->data[(int32_T)uOSRFinalinds->data[i0] - 1]
 2304             - 1;
 2305         }
 2306   
 2307         b_st.site = &tc_emlrtRSI;
 2308         i0 = ii->size[0];
 2309         ii->size[0] = v1->size[0];
 2310         emxEnsureCapacity(&b_st, (emxArray__common *)ii, i0, (int32_T)sizeof
 2311                           (int32_T), &emlrtRTEI);
 2312         idx = v1->size[0];
 2313         for (i0 = 0; i0 < idx; i0++) {
 2314           c_st.site = &pd_emlrtRSI;
 2315           ii->data[i0] = div_s32(&c_st, v1->data[i0], (int32_T)siz_idx_0);
 2316         }
 2317   
 2318         b_st.site = &uc_emlrtRSI;
 2319         i0 = OSR->size[0];
 2320         OSR->size[0] = ii->size[0];
 2321         emxEnsureCapacity(&st, (emxArray__common *)OSR, i0, (int32_T)sizeof(real_T),
 2322                           &emlrtRTEI);
 2323         idx = ii->size[0];
 2324         for (i0 = 0; i0 < idx; i0++) {
 2325           OSR->data[i0] = ii->data[i0] + 1;
 2326         }
 2327   
 2328         b_st.site = &vc_emlrtRSI;
 2329         b_st.site = &vc_emlrtRSI;
 2330         i0 = v1->size[0];
 2331         emxEnsureCapacity(&b_st, (emxArray__common *)v1, i0, (int32_T)sizeof
 2332                           (int32_T), &emlrtRTEI);
 2333         idx = v1->size[0];
 2334         for (i0 = 0; i0 < idx; i0++) {
 2335           v1->data[i0] -= ii->data[i0] * (int32_T)siz_idx_0;
 2336         }
 2337   
 2338         b_st.site = &wc_emlrtRSI;
 2339         i0 = sOSR->size[0];
 2340         sOSR->size[0] = v1->size[0];
 2341         emxEnsureCapacity(&st, (emxArray__common *)sOSR, i0, (int32_T)sizeof
 2342                           (real_T), &emlrtRTEI);
 2343         idx = v1->size[0];
 2344         for (i0 = 0; i0 < idx; i0++) {
 2345           sOSR->data[i0] = v1->data[i0] + 1;
 2346         }
 2347   
 2348         idx = b_CSH_ann->size[0];
 2349         i0 = v1->size[0];
 2350         v1->size[0] = idx;
 2351         emxEnsureCapacity(sp, (emxArray__common *)v1, i0, (int32_T)sizeof(int32_T),
 2352                           &emlrtRTEI);
 2353         for (i0 = 0; i0 < idx; i0++) {
 2354           v1->data[i0] = i0;
 2355         }
 2356   
 2357         i0 = b_CSH_ann->size[1];
 2358         plast = i + 1;
 2359         emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &h_emlrtBCI, sp);
 2360         i0 = b_CSH_ann->size[2];
 2361         plast = j + 1;
 2362         emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &i_emlrtBCI, sp);
 2363         b_v1[0] = v1->size[0];
 2364         emlrtSubAssignSizeCheckR2012b(b_v1, 1, *(int32_T (*)[1])sOSR->size, 1,
 2365           &c_emlrtECI, sp);
 2366         idx = sOSR->size[0];
 2367         for (i0 = 0; i0 < idx; i0++) {
 2368           b_CSH_ann->data[((v1->data[i0] + b_CSH_ann->size[0] * i) +
 2369                            b_CSH_ann->size[0] * b_CSH_ann->size[1] * j) +
 2370             b_CSH_ann->size[0] * b_CSH_ann->size[1] * b_CSH_ann->size[2]] =
 2371             sOSR->data[i0];
 2372         }
 2373   
 2374         idx = b_CSH_ann->size[0];
 2375         i0 = v1->size[0];
 2376         v1->size[0] = idx;
 2377         emxEnsureCapacity(sp, (emxArray__common *)v1, i0, (int32_T)sizeof(int32_T),
 2378                           &emlrtRTEI);
 2379         for (i0 = 0; i0 < idx; i0++) {
 2380           v1->data[i0] = i0;
 2381         }
 2382   
 2383         i0 = b_CSH_ann->size[1];
 2384         plast = i + 1;
 2385         emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &j_emlrtBCI, sp);
 2386         i0 = b_CSH_ann->size[2];
 2387         plast = j + 1;
 2388         emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &k_emlrtBCI, sp);
 2389         c_v1[0] = v1->size[0];
 2390         emlrtSubAssignSizeCheckR2012b(c_v1, 1, *(int32_T (*)[1])OSR->size, 1,
 2391           &d_emlrtECI, sp);
 2392         idx = OSR->size[0];
 2393         for (i0 = 0; i0 < idx; i0++) {
 2394           b_CSH_ann->data[(v1->data[i0] + b_CSH_ann->size[0] * i) +
 2395             b_CSH_ann->size[0] * b_CSH_ann->size[1] * j] = OSR->data[i0];
 2396         }
 2397   
 2398         /*  sorted errors: */
 2399         /* 'TransitiveKNN_part2:30' sortedErrors(i,j,:) = sErrors(uOSRFinalinds); */
 2400         i0 = sortedErrors->size[0];
 2401         plast = i + 1;
 2402         emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &l_emlrtBCI, sp);
 2403         i0 = sortedErrors->size[1];
 2404         plast = j + 1;
 2405         emlrtDynamicBoundsCheckFastR2012b(plast, 1, i0, &m_emlrtBCI, sp);
 2406         idx = sortedErrors->size[2];
 2407         i0 = v1->size[0];
 2408         v1->size[0] = idx;
 2409         emxEnsureCapacity(sp, (emxArray__common *)v1, i0, (int32_T)sizeof(int32_T),
 2410                           &emlrtRTEI);
 2411         for (i0 = 0; i0 < idx; i0++) {
 2412           v1->data[i0] = i0;
 2413         }
 2414   
 2415         idx = uOSRFinalinds->size[0];
 2416         for (i0 = 0; i0 < idx; i0++) {
 2417           plast = sErrors->size[0];
 2418           isrc = (int32_T)uOSRFinalinds->data[i0];
 2419           emlrtDynamicBoundsCheckFastR2012b(isrc, 1, plast, &s_emlrtBCI, sp);
 2420         }
 2421   
 2422         iv1[0] = 1;
 2423         iv1[1] = 1;
 2424         iv1[2] = v1->size[0];
 2425         emlrtSubAssignSizeCheckR2012b(iv1, 3, *(int32_T (*)[1])uOSRFinalinds->size,
 2426           1, &e_emlrtECI, sp);
 2427         i0 = b_sErrors->size[0];
 2428         b_sErrors->size[0] = uOSRFinalinds->size[0];
 2429         emxEnsureCapacity(sp, (emxArray__common *)b_sErrors, i0, (int32_T)sizeof
 2430                           (real_T), &emlrtRTEI);
 2431         idx = uOSRFinalinds->size[0];
 2432         for (i0 = 0; i0 < idx; i0++) {
 2433           b_sErrors->data[i0] = sErrors->data[(int32_T)uOSRFinalinds->data[i0] - 1];
 2434         }
 2435   
 2436         plast = v1->size[0];
 2437         for (i0 = 0; i0 < plast; i0++) {
 2438           sortedErrors->data[(i + sortedErrors->size[0] * j) + sortedErrors->size
 2439             [0] * sortedErrors->size[1] * v1->data[i0]] = b_sErrors->data[i0];
 2440         }
 2441   
 2442         j++;
 2443         emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
 2444       }
 2445   
 2446       i++;
 2447       emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
 2448     }
 2449   
 2450     emxFree_real_T(&b_sErrors);
 2451     emxFree_int32_T(&b_ii);
 2452     emxFree_real_T(&b_errorMat);
 2453     emxFree_real_T(&b_overSafeResults);
 2454     emxFree_real_T(&r1);
 2455     emxFree_int32_T(&v1);
 2456     emxFree_int32_T(&ii);
 2457     emxFree_boolean_T(&x);
 2458     emxFree_int32_T(&r0);
 2459     emxFree_real_T(&sErrors);
 2460     emxFree_real_T(&uOSRFinalinds);
 2461     emxFree_real_T(&uOSRinds);
 2462     emxFree_real_T(&sOSR);
 2463     emxFree_real_T(&OSR);
 2464   
 2465     /* 'TransitiveKNN_part2:34' CSH_ann = permute(CSH_ann,[2,3,4,1]); */
 2466     st.site = &g_emlrtRSI;
 2467     for (i0 = 0; i0 < 4; i0++) {
 2468       insz[i0] = (uint32_T)b_CSH_ann->size[i0];
 2469     }
 2470   
 2471     outsz[0] = insz[1];
 2472     outsz[1] = insz[2];
 2473     outsz[2] = 2U;
 2474     outsz[3] = insz[0];
 2475     i0 = CSH_ann->size[0] * CSH_ann->size[1] * CSH_ann->size[2] * CSH_ann->size[3];
 2476     CSH_ann->size[0] = (int32_T)insz[1];
 2477     CSH_ann->size[1] = (int32_T)insz[2];
 2478     CSH_ann->size[2] = 2;
 2479     CSH_ann->size[3] = (int32_T)insz[0];
 2480     emxEnsureCapacity(&st, (emxArray__common *)CSH_ann, i0, (int32_T)sizeof(real_T),
 2481                       &b_emlrtRTEI);
 2482     b_st.site = &cd_emlrtRSI;
 2483     b = TRUE;
 2484     if (!((b_CSH_ann->size[0] == 0) || (b_CSH_ann->size[1] == 0) ||
 2485           (b_CSH_ann->size[2] == 0))) {
 2486       plast = 0;
 2487       idx = 0;
 2488       exitg2 = FALSE;
 2489       while ((exitg2 == FALSE) && (idx + 1 < 5)) {
 2490         b_guard1 = FALSE;
 2491         if (b_CSH_ann->size[iv2[idx] - 1] != 1) {
 2492           if (plast > iv2[idx]) {
 2493             b = FALSE;
 2494             exitg2 = TRUE;
 2495           } else {
 2496             plast = iv2[idx];
 2497             b_guard1 = TRUE;
 2498           }
 2499         } else {
 2500           b_guard1 = TRUE;
 2501         }
 2502   
 2503         if (b_guard1 == TRUE) {
 2504           idx++;
 2505         }
 2506       }
 2507     }
 2508   
 2509     if (b) {
 2510       plast = b_CSH_ann->size[0] * b_CSH_ann->size[1] * b_CSH_ann->size[2] << 1;
 2511       b_st.site = &dd_emlrtRSI;
 2512       c_st.site = &k_emlrtRSI;
 2513       if (1 > plast) {
 2514         b1 = FALSE;
 2515       } else {
 2516         b1 = (plast > 2147483646);
 2517       }
 2518   
 2519       if (b1) {
 2520         c_st.site = &l_emlrtRSI;
 2521         check_forloop_overflow_error(&c_st);
 2522       }
 2523   
 2524       for (idx = 0; idx + 1 <= plast; idx++) {
 2525         CSH_ann->data[idx] = b_CSH_ann->data[idx];
 2526       }
 2527     } else {
 2528       for (i0 = 0; i0 < 4; i0++) {
 2529         iwork[i0] = 1;
 2530       }
 2531   
 2532       for (idx = 0; idx < 3; idx++) {
 2533         b_st.site = &ed_emlrtRSI;
 2534         iwork[idx + 1] = iwork[idx] * (int32_T)insz[idx];
 2535       }
 2536   
 2537       for (i0 = 0; i0 < 4; i0++) {
 2538         inc[i0] = iwork[iv3[i0]];
 2539       }
 2540   
 2541       for (i0 = 0; i0 < 4; i0++) {
 2542         iwork[i0] = 0;
 2543       }
 2544   
 2545       plast = 0;
 2546       do {
 2547         isrc = 0;
 2548         for (idx = 0; idx < 3; idx++) {
 2549           b_st.site = &fd_emlrtRSI;
 2550           b_st.site = &fd_emlrtRSI;
 2551           isrc += iwork[idx + 1] * inc[idx + 1];
 2552         }
 2553   
 2554         b_st.site = &gd_emlrtRSI;
 2555         c_st.site = &k_emlrtRSI;
 2556         if (1U > insz[1]) {
 2557           b2 = FALSE;
 2558         } else {
 2559           b2 = (insz[1] > 2147483646U);
 2560         }
 2561   
 2562         if (b2) {
 2563           c_st.site = &l_emlrtRSI;
 2564           check_forloop_overflow_error(&c_st);
 2565         }
 2566   
 2567         for (idx = 1; idx <= (int32_T)insz[1]; idx++) {
 2568           CSH_ann->data[plast] = b_CSH_ann->data[isrc];
 2569           b_st.site = &hd_emlrtRSI;
 2570           plast++;
 2571           b_st.site = &id_emlrtRSI;
 2572           isrc += inc[0];
 2573         }
 2574   
 2575         idx = 1;
 2576         do {
 2577           exitg1 = 0;
 2578           b_st.site = &jd_emlrtRSI;
 2579           iwork[idx]++;
 2580           b_st.site = &kd_emlrtRSI;
 2581           c_st.site = &ad_emlrtRSI;
 2582           if (iwork[idx] < (int32_T)outsz[idx]) {
 2583             exitg1 = 2;
 2584           } else if (idx + 1 == 4) {
 2585             exitg1 = 1;
 2586           } else {
 2587             iwork[idx] = 0;
 2588             idx++;
 2589           }
 2590         } while (exitg1 == 0);
 2591       } while (!(exitg1 == 1));
 2592     }
 2593   
 2594     emxFree_real_T(&b_CSH_ann);
 2595     emlrtHeapReferenceStackLeaveFcnR2012b(sp);
 2596   }
 2597   
 2598   void TransitiveKNN_part2_api(emlrtStack *sp, const mxArray * const prhs[6],
 2599     const mxArray *plhs[3])
 2600   {
 2601     emxArray_uint8_T *A;
 2602     emxArray_uint8_T *B;
 2603     emxArray_real_T *overSafeResults;
 2604     emxArray_real_T *errorMat;
 2605     emxArray_real_T *CSH_ann;
 2606     emxArray_real_T *numUniqueResultsPerPixel;
 2607     emxArray_real_T *sortedErrors;
 2608     real_T k;
 2609     real_T width;
 2610     emlrtHeapReferenceStackEnterFcnR2012b(sp);
 2611     emxInit_uint8_T(sp, &A, 3, &w_emlrtRTEI, TRUE);
 2612     emxInit_uint8_T(sp, &B, 3, &w_emlrtRTEI, TRUE);
 2613     d_emxInit_real_T(sp, &overSafeResults, 3, &w_emlrtRTEI, TRUE);
 2614     d_emxInit_real_T(sp, &errorMat, 3, &w_emlrtRTEI, TRUE);
 2615     b_emxInit_real_T(sp, &CSH_ann, 4, &w_emlrtRTEI, TRUE);
 2616     c_emxInit_real_T(sp, &numUniqueResultsPerPixel, 2, &w_emlrtRTEI, TRUE);
 2617     d_emxInit_real_T(sp, &sortedErrors, 3, &w_emlrtRTEI, TRUE);
 2618   
 2619     /* Marshall function inputs */
 2620     emlrt_marshallIn(sp, emlrtAlias(prhs[0]), "A", A);
 2621     emlrt_marshallIn(sp, emlrtAlias(prhs[1]), "B", B);
 2622     k = c_emlrt_marshallIn(sp, emlrtAliasP(prhs[2]), "k");
 2623     width = c_emlrt_marshallIn(sp, emlrtAliasP(prhs[3]), "width");
 2624     e_emlrt_marshallIn(sp, emlrtAlias(prhs[4]), "overSafeResults", overSafeResults);
 2625     e_emlrt_marshallIn(sp, emlrtAlias(prhs[5]), "errorMat", errorMat);
 2626   
 2627     /* Invoke the target function */
 2628     TransitiveKNN_part2(sp, A, B, k, width, overSafeResults, errorMat, CSH_ann,
 2629                         numUniqueResultsPerPixel, sortedErrors);
 2630   
 2631     /* Marshall function outputs */
 2632     plhs[0] = emlrt_marshallOut(CSH_ann);
 2633     plhs[1] = b_emlrt_marshallOut(numUniqueResultsPerPixel);
 2634     plhs[2] = c_emlrt_marshallOut(sortedErrors);
 2635     sortedErrors->canFreeData = FALSE;
 2636     emxFree_real_T(&sortedErrors);
 2637     numUniqueResultsPerPixel->canFreeData = FALSE;
 2638     emxFree_real_T(&numUniqueResultsPerPixel);
 2639     CSH_ann->canFreeData = FALSE;
 2640     emxFree_real_T(&CSH_ann);
 2641     errorMat->canFreeData = FALSE;
 2642     emxFree_real_T(&errorMat);
 2643     overSafeResults->canFreeData = FALSE;
 2644     emxFree_real_T(&overSafeResults);
 2645     B->canFreeData = FALSE;
 2646     emxFree_uint8_T(&B);
 2647     A->canFreeData = FALSE;
 2648     emxFree_uint8_T(&A);
 2649     emlrtHeapReferenceStackLeaveFcnR2012b(sp);
 2650   }
 2651   
 2652   void TransitiveKNN_part2_atexit(emlrtStack *sp)
 2653   {
 2654     emlrtCreateRootTLS(&emlrtRootTLSGlobal, &emlrtContextGlobal, NULL, 1);
 2655     sp->tls = emlrtRootTLSGlobal;
 2656     emlrtEnterRtStackR2012b(sp);
 2657     emlrtLeaveRtStackR2012b(sp);
 2658     emlrtDestroyRootTLS(&emlrtRootTLSGlobal);
 2659   }
 2660   
 2661   void TransitiveKNN_part2_initialize(emlrtStack *sp, emlrtContext *aContext)
 2662   {
 2663     emlrtBreakCheckR2012bFlagVar = emlrtGetBreakCheckFlagAddressR2012b();
 2664     emlrtCreateRootTLS(&emlrtRootTLSGlobal, aContext, NULL, 1);
 2665     sp->tls = emlrtRootTLSGlobal;
 2666     emlrtClearAllocCountR2012b(sp, FALSE, 0U, 0);
 2667     emlrtEnterRtStackR2012b(sp);
 2668     emlrtFirstTimeR2012b(emlrtRootTLSGlobal);
 2669   }
 2670   
 2671   void TransitiveKNN_part2_terminate(emlrtStack *sp)
 2672   {
 2673     emlrtLeaveRtStackR2012b(sp);
 2674     emlrtDestroyRootTLS(&emlrtRootTLSGlobal);
 2675   }
 2676   
 2677   /* End of code generation (TransitiveKNN_part2.c) */
 2678