/* * nanmean_.c * * Code generation for function 'nanmean_' * * C source code generated on: Wed Aug 26 14:59:34 2015 * */ /* Include files */ #include "rt_nonfinite.h" #include "Select_Ground_Motions.h" #include "nanmean_.h" #include "Select_Ground_Motions_emxutil.h" #include "rdivide.h" #include "sum.h" #include "cholcov_.h" #include "Select_Ground_Motions_data.h" /* Variable Definitions */ static emlrtRSInfo mm_emlrtRSI = { 18, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtRSInfo nm_emlrtRSI = { 28, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtRSInfo om_emlrtRSI = { 29, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtRSInfo pm_emlrtRSI = { 31, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtRTEInfo uc_emlrtRTEI = { 1, 14, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtRTEInfo vc_emlrtRTEI = { 17, 1, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtRTEInfo wc_emlrtRTEI = { 22, 5, "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m" }; static emlrtBCInfo od_emlrtBCI = { -1, -1, 18, 1, "x", "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m", 0 }; static emlrtBCInfo pd_emlrtBCI = { -1, -1, 29, 5, "n", "nanmean_", "/home/sebenik/Projects/Ground_Motion_Selection/GMS_con_cms_1gmc_dynamicInput_501_jure/nanmean_.m", 0 }; /* Function Definitions */ void nanmean_(emxArray_real_T *x, emxArray_real_T *m) { emxArray_boolean_T *nans; int32_T iy; int32_T loop_ub; emxArray_int32_T *r34; int32_T b_x; int32_T ixstart; int32_T i13; int32_T ix; uint32_T sz[2]; emxArray_real_T *n; boolean_T overflow; real_T s; emxArray_boolean_T *b_n; emxArray_int32_T *r35; emxArray_real_T *r36; emlrtHeapReferenceStackEnterFcnR2012b(emlrtRootTLSGlobal); emxInit_boolean_T(&nans, 2, &vc_emlrtRTEI, TRUE); /* NANMEAN Mean value, ignoring NaNs. */ /* M = NANMEAN(X) returns the sample mean of X, treating NaNs as missing */ /* values. For vector input, M is the mean value of the non-NaN elements */ /* in X. For matrix input, M is a row vector containing the mean value of */ /* non-NaN elements in each column. For N-D arrays, NANMEAN operates */ /* along the first non-singleton dimension. */ /* */ /* NANMEAN(X,DIM) takes the mean along dimension DIM of X. */ /* */ /* See also MEAN, NANMEDIAN, NANSTD, NANVAR, NANMIN, NANMAX, NANSUM. */ /* Copyright 1993-2004 The MathWorks, Inc. */ /* Find NaNs and set them to zero */ iy = nans->size[0] * nans->size[1]; nans->size[0] = x->size[0]; nans->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)nans, iy, (int32_T)sizeof(boolean_T), &uc_emlrtRTEI); loop_ub = x->size[0] * x->size[1]; for (iy = 0; iy < loop_ub; iy++) { nans->data[iy] = muDoubleScalarIsNaN(x->data[iy]); } emxInit_int32_T(&r34, 1, &uc_emlrtRTEI, TRUE); emlrtPushRtStackR2012b(&mm_emlrtRSI, emlrtRootTLSGlobal); b_eml_li_find(nans, r34); emlrtPopRtStackR2012b(&mm_emlrtRSI, emlrtRootTLSGlobal); b_x = x->size[0]; ixstart = x->size[1]; loop_ub = r34->size[0]; for (iy = 0; iy < loop_ub; iy++) { i13 = b_x * ixstart; ix = r34->data[iy]; x->data[emlrtDynamicBoundsCheckFastR2012b(ix, 1, i13, &od_emlrtBCI, emlrtRootTLSGlobal) - 1] = 0.0; } emxFree_int32_T(&r34); /* Count up non-NaNs. */ emlrtPushRtStackR2012b(&nm_emlrtRSI, emlrtRootTLSGlobal); iy = nans->size[0] * nans->size[1]; emxEnsureCapacity((emxArray__common *)nans, iy, (int32_T)sizeof(boolean_T), &uc_emlrtRTEI); ixstart = nans->size[0]; b_x = nans->size[1]; loop_ub = ixstart * b_x; for (iy = 0; iy < loop_ub; iy++) { nans->data[iy] = !nans->data[iy]; } for (iy = 0; iy < 2; iy++) { sz[iy] = (uint32_T)nans->size[iy]; } b_emxInit_real_T(&n, 2, &wc_emlrtRTEI, TRUE); iy = n->size[0] * n->size[1]; n->size[0] = 1; n->size[1] = (int32_T)sz[1]; emxEnsureCapacity((emxArray__common *)n, iy, (int32_T)sizeof(real_T), &nc_emlrtRTEI); if ((nans->size[0] == 0) || (nans->size[1] == 0)) { iy = n->size[0] * n->size[1]; n->size[0] = 1; emxEnsureCapacity((emxArray__common *)n, iy, (int32_T)sizeof(real_T), &uc_emlrtRTEI); iy = n->size[0] * n->size[1]; n->size[1] = (int32_T)sz[1]; emxEnsureCapacity((emxArray__common *)n, iy, (int32_T)sizeof(real_T), &uc_emlrtRTEI); loop_ub = (int32_T)sz[1]; for (iy = 0; iy < loop_ub; iy++) { n->data[iy] = 0.0; } } else { ix = -1; iy = -1; emlrtPushRtStackR2012b(&gm_emlrtRSI, emlrtRootTLSGlobal); overflow = (nans->size[1] > 2147483646); if (overflow) { emlrtPushRtStackR2012b(&lc_emlrtRSI, emlrtRootTLSGlobal); check_forloop_overflow_error(); emlrtPopRtStackR2012b(&lc_emlrtRSI, emlrtRootTLSGlobal); } emlrtPopRtStackR2012b(&gm_emlrtRSI, emlrtRootTLSGlobal); for (loop_ub = 1; loop_ub <= nans->size[1]; loop_ub++) { ixstart = ix + 1; ix++; s = nans->data[ixstart]; emlrtPushRtStackR2012b(&hm_emlrtRSI, emlrtRootTLSGlobal); if (2 > nans->size[0]) { overflow = FALSE; } else { overflow = (nans->size[0] > 2147483646); } if (overflow) { emlrtPushRtStackR2012b(&lc_emlrtRSI, emlrtRootTLSGlobal); check_forloop_overflow_error(); emlrtPopRtStackR2012b(&lc_emlrtRSI, emlrtRootTLSGlobal); } emlrtPopRtStackR2012b(&hm_emlrtRSI, emlrtRootTLSGlobal); for (b_x = 2; b_x <= nans->size[0]; b_x++) { ix++; s += (real_T)nans->data[ix]; } iy++; n->data[iy] = s; } } emxFree_boolean_T(&nans); emxInit_boolean_T(&b_n, 2, &uc_emlrtRTEI, TRUE); emlrtPopRtStackR2012b(&nm_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&om_emlrtRSI, emlrtRootTLSGlobal); iy = b_n->size[0] * b_n->size[1]; b_n->size[0] = 1; b_n->size[1] = n->size[1]; emxEnsureCapacity((emxArray__common *)b_n, iy, (int32_T)sizeof(boolean_T), &uc_emlrtRTEI); loop_ub = n->size[0] * n->size[1]; for (iy = 0; iy < loop_ub; iy++) { b_n->data[iy] = (n->data[iy] == 0.0); } b_emxInit_int32_T(&r35, 2, &uc_emlrtRTEI, TRUE); eml_li_find(b_n, r35); emlrtPopRtStackR2012b(&om_emlrtRSI, emlrtRootTLSGlobal); b_x = n->size[1]; loop_ub = r35->size[0] * r35->size[1]; emxFree_boolean_T(&b_n); for (iy = 0; iy < loop_ub; iy++) { i13 = r35->data[iy]; n->data[emlrtDynamicBoundsCheckFastR2012b(i13, 1, b_x, &pd_emlrtBCI, emlrtRootTLSGlobal) - 1] = rtNaN; } emxFree_int32_T(&r35); b_emxInit_real_T(&r36, 2, &uc_emlrtRTEI, TRUE); /* prevent divideByZero warnings */ /* Sum up non-NaNs, and divide by the number of non-NaNs. */ emlrtPushRtStackR2012b(&pm_emlrtRSI, emlrtRootTLSGlobal); sum(x, r36); rdivide(r36, n, m); emlrtPopRtStackR2012b(&pm_emlrtRSI, emlrtRootTLSGlobal); emxFree_real_T(&r36); emxFree_real_T(&n); emlrtHeapReferenceStackLeaveFcnR2012b(emlrtRootTLSGlobal); } /* End of code generation (nanmean_.c) */