/* * File: Select_Ground_Motions.c * * MATLAB Coder version : 2.8 * C/C++ source code generated on : 08-Nov-2016 04:31:59 */ #include #include #include "rt_nonfinite.h" #include "Select_Ground_Motions.h" /* Type Definitions */ #ifndef struct_emxArray__common #define struct_emxArray__common struct emxArray__common { void *data; int *size; int allocatedSize; int numDimensions; boolean_T canFreeData; }; #endif /*struct_emxArray__common*/ #ifndef typedef_emxArray__common #define typedef_emxArray__common typedef struct emxArray__common emxArray__common; #endif /*typedef_emxArray__common*/ #ifndef struct_emxArray_boolean_T #define struct_emxArray_boolean_T struct emxArray_boolean_T { boolean_T *data; int *size; int allocatedSize; int numDimensions; boolean_T canFreeData; }; #endif /*struct_emxArray_boolean_T*/ #ifndef typedef_emxArray_boolean_T #define typedef_emxArray_boolean_T typedef struct emxArray_boolean_T emxArray_boolean_T; #endif /*typedef_emxArray_boolean_T*/ #ifndef struct_emxArray_creal_T #define struct_emxArray_creal_T struct emxArray_creal_T { creal_T *data; int *size; int allocatedSize; int numDimensions; boolean_T canFreeData; }; #endif /*struct_emxArray_creal_T*/ #ifndef typedef_emxArray_creal_T #define typedef_emxArray_creal_T typedef struct emxArray_creal_T emxArray_creal_T; #endif /*typedef_emxArray_creal_T*/ #ifndef struct_emxArray_int32_T #define struct_emxArray_int32_T struct emxArray_int32_T { int *data; int *size; int allocatedSize; int numDimensions; boolean_T canFreeData; }; #endif /*struct_emxArray_int32_T*/ #ifndef typedef_emxArray_int32_T #define typedef_emxArray_int32_T typedef struct emxArray_int32_T emxArray_int32_T; #endif /*typedef_emxArray_int32_T*/ /* Variable Definitions */ static unsigned int method; static unsigned int state; static unsigned int b_state[2]; static unsigned int c_state[625]; /* Function Declarations */ static void AtonacijskoTip1(double m, double d, double koefAtonacijsko_b1, double koefAtonacijsko_b2, double koefAtonacijsko_b3, double koefAtonacijsko_b4, double koefAtonacijsko_h0, double koefAtonacijsko_r0, double koefAtonacijsko_bSB, double koefAtonacijsko_bSC, double koefAtonacijsko_bSD, double koefAtonacijsko_sigma, double koefAtonacijsko_SB, double koefAtonacijsko_SC, double koefAtonacijsko_SD, double *lnY, double *sigma); static void SP1996hor(double Period, double ecSoilCode, double *koefAtonacijsko_b1, double *koefAtonacijsko_b2, double *koefAtonacijsko_b3, double *koefAtonacijsko_b4, double *koefAtonacijsko_h0, double *koefAtonacijsko_r0, double *koefAtonacijsko_bSB, double *koefAtonacijsko_bSC, double * koefAtonacijsko_bSD, double *koefAtonacijsko_sigma, double *koefAtonacijsko_SB, double *koefAtonacijsko_SC, double *koefAtonacijsko_SD); static void all(const emxArray_real_T *x, emxArray_boolean_T *y); static boolean_T any(const emxArray_boolean_T *x); static void b_abs(const emxArray_real_T *x, emxArray_real_T *y); static boolean_T b_all(const emxArray_boolean_T *x); static void b_any(const emxArray_boolean_T *x, emxArray_boolean_T *y); static void b_diag(const emxArray_creal_T *v, emxArray_creal_T *d); static void b_eml_matlab_zlartg(const creal_T f, const creal_T g, double *cs, creal_T *sn); static void b_eml_null_assignment(emxArray_real_T *x, double idx); static void b_emxInit_boolean_T(emxArray_boolean_T **pEmxArray, int numDimensions); static void b_emxInit_creal_T(emxArray_creal_T **pEmxArray, int numDimensions); static void b_emxInit_int32_T(emxArray_int32_T **pEmxArray, int numDimensions); static void b_emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions); static void b_exp(emxArray_real_T *x); static void b_log(emxArray_real_T *x); static void b_round(emxArray_real_T *x); static void b_sqrt(emxArray_real_T *x); static void b_std(const emxArray_real_T *varargin_1, emxArray_real_T *y); static double b_sum(const emxArray_real_T *x); static double baker_jayaram_correlation(double T1, double T2); static void c_abs(const emxArray_real_T *x, emxArray_real_T *y); static boolean_T c_all(const emxArray_boolean_T *x); static boolean_T c_any(const emxArray_boolean_T *x); static void c_eml_rand_mt19937ar_stateful_i(void); static void c_emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions); static void c_exp(emxArray_real_T *x); static void c_log(emxArray_real_T *x); static void c_sqrt(creal_T *x); static void cholcov_(const emxArray_real_T *Sigma, emxArray_real_T *T, double *p); static void d_abs(const double x[20], double y[20]); static void d_sqrt(emxArray_real_T *x); static void diag(const emxArray_real_T *v, emxArray_real_T *d); static void e_abs(const double x[501], double y[501]); static void eig(const emxArray_real_T *A, emxArray_creal_T *V, emxArray_creal_T * D); static void eml_matlab_zggbal(emxArray_creal_T *A, int *ilo, int *ihi, emxArray_int32_T *rscale); static void eml_matlab_zggev(emxArray_creal_T *A, int *info, emxArray_creal_T *alpha1, emxArray_creal_T *beta1, emxArray_creal_T *V); static void eml_matlab_zhgeqz(emxArray_creal_T *A, int ilo, int ihi, emxArray_creal_T *Z, int *info, emxArray_creal_T *alpha1, emxArray_creal_T *beta1); static void eml_matlab_zlartg(const creal_T f, const creal_T g, double *cs, creal_T *sn, creal_T *r); static void eml_matlab_ztgevc(const emxArray_creal_T *A, emxArray_creal_T *V); static void eml_null_assignment(emxArray_real_T *x, double idx); static double eml_qrsolve(const emxArray_real_T *A, const emxArray_real_T *B); static void eml_rand_init(void); static void eml_rand_mcg16807_stateful_init(void); static void eml_rand_shr3cong_stateful_init(void); static void eml_sort(emxArray_real_T *x, emxArray_int32_T *idx); static void eml_sort_idx(emxArray_real_T *x, emxArray_int32_T *idx); static double eml_xnrm2(int n, const emxArray_real_T *x); static void eml_xscal(int n, double a, emxArray_real_T *x); static void emxEnsureCapacity(emxArray__common *emxArray, int oldNumel, int elementSize); static void emxFree_boolean_T(emxArray_boolean_T **pEmxArray); static void emxFree_creal_T(emxArray_creal_T **pEmxArray); static void emxFree_int32_T(emxArray_int32_T **pEmxArray); static void emxFree_real_T(emxArray_real_T **pEmxArray); static void emxInit_boolean_T(emxArray_boolean_T **pEmxArray, int numDimensions); static void emxInit_creal_T(emxArray_creal_T **pEmxArray, int numDimensions); static void emxInit_int32_T(emxArray_int32_T **pEmxArray, int numDimensions); static void emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions); static double eps(double x); static void f_abs(const emxArray_boolean_T *x, emxArray_real_T *y); static void genrand_uint32_vector(unsigned int mt[625], unsigned int u[2]); static double genrandu(unsigned int mt[625]); static double interp1(const double varargin_1[15], const double varargin_2[15], double varargin_3); static void inv(const emxArray_real_T *x, emxArray_real_T *y); static boolean_T isequal(const emxArray_real_T *varargin_1); static boolean_T issorted(const emxArray_real_T *x); static void linspace(double n1, emxArray_real_T *y); static void mean(const emxArray_real_T *x, emxArray_real_T *y); static void merge(emxArray_int32_T *idx, emxArray_real_T *x, int offset, int np, int nq); static void merge_block(emxArray_int32_T *idx, emxArray_real_T *x, int offset, int n, int preSortLevel); static void mpower(const emxArray_real_T *a, emxArray_real_T *c); static void mrdivide(emxArray_real_T *A, const emxArray_real_T *B); static void mvnrnd_(const emxArray_real_T *mu, const emxArray_real_T *sigma, emxArray_real_T *r); static void nanmean_(emxArray_real_T *x, emxArray_real_T *m); static void power(const emxArray_real_T *a, emxArray_real_T *y); static void randn(double varargin_2, emxArray_real_T *r); static void rdivide(const emxArray_real_T *x, const emxArray_real_T *y, emxArray_real_T *z); static void repmat(const emxArray_real_T *a, double varargin_2, emxArray_real_T * b); static void rng(double arg1); static double rt_hypotd_snf(double u0, double u1); static double rt_powd_snf(double u0, double u1); static double rt_roundd_snf(double u); static void skew(const emxArray_real_T *x, emxArray_real_T *s); static double sum(const emxArray_real_T *x); /* Function Definitions */ /* * Arguments : double m * double d * double koefAtonacijsko_b1 * double koefAtonacijsko_b2 * double koefAtonacijsko_b3 * double koefAtonacijsko_b4 * double koefAtonacijsko_h0 * double koefAtonacijsko_r0 * double koefAtonacijsko_bSB * double koefAtonacijsko_bSC * double koefAtonacijsko_bSD * double koefAtonacijsko_sigma * double koefAtonacijsko_SB * double koefAtonacijsko_SC * double koefAtonacijsko_SD * double *lnY * double *sigma * Return Type : void */ static void AtonacijskoTip1(double m, double d, double koefAtonacijsko_b1, double koefAtonacijsko_b2, double koefAtonacijsko_b3, double koefAtonacijsko_b4, double koefAtonacijsko_h0, double koefAtonacijsko_r0, double koefAtonacijsko_bSB, double koefAtonacijsko_bSC, double koefAtonacijsko_bSD, double koefAtonacijsko_sigma, double koefAtonacijsko_SB, double koefAtonacijsko_SC, double koefAtonacijsko_SD, double *lnY, double *sigma) { *sigma = koefAtonacijsko_sigma; /* fF=bFn*Fn+bFs*Fs+bFr*Fr+bFt*Ft+bFu*Fu; */ *lnY = (((koefAtonacijsko_b1 + koefAtonacijsko_b2 * m) + koefAtonacijsko_b3 * log(sqrt(d * d + koefAtonacijsko_h0 * koefAtonacijsko_h0) + koefAtonacijsko_r0)) + koefAtonacijsko_b4 * (sqrt(d * d + koefAtonacijsko_h0 * koefAtonacijsko_h0) + koefAtonacijsko_r0)) + ((koefAtonacijsko_bSB * koefAtonacijsko_SB + koefAtonacijsko_bSC * koefAtonacijsko_SC) + koefAtonacijsko_bSD * koefAtonacijsko_SD); } /* * %%%sabeta pugliese 1996 koeficienti * Arguments : double Period * double ecSoilCode * double *koefAtonacijsko_b1 * double *koefAtonacijsko_b2 * double *koefAtonacijsko_b3 * double *koefAtonacijsko_b4 * double *koefAtonacijsko_h0 * double *koefAtonacijsko_r0 * double *koefAtonacijsko_bSB * double *koefAtonacijsko_bSC * double *koefAtonacijsko_bSD * double *koefAtonacijsko_sigma * double *koefAtonacijsko_SB * double *koefAtonacijsko_SC * double *koefAtonacijsko_SD * Return Type : void */ static void SP1996hor(double Period, double ecSoilCode, double *koefAtonacijsko_b1, double *koefAtonacijsko_b2, double *koefAtonacijsko_b3, double *koefAtonacijsko_b4, double *koefAtonacijsko_h0, double *koefAtonacijsko_r0, double *koefAtonacijsko_bSB, double *koefAtonacijsko_bSC, double * koefAtonacijsko_bSD, double *koefAtonacijsko_sigma, double *koefAtonacijsko_SB, double *koefAtonacijsko_SC, double *koefAtonacijsko_SD) { int SB; int SC; int SD; double b1; int low_i; int low_ip1; int high_i; int mid_i; static const double dv1[15] = { 0.0, 0.04, 0.067, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.752, 1.0, 1.493, 2.0, 3.03, 4.0 }; double r; static const double dv2[15] = { -3.597, -2.994, -2.422, -2.079, -2.001, -2.174, -2.926, -4.311, -5.278, -6.722, -7.629, -8.927, -9.887, -11.155, -11.962 }; double dv3[15]; double dv4[15]; double dv5[15]; double dv6[15]; static const double dv7[15] = { 0.705, 0.629, 0.587, 0.564, 0.587, 0.629, 0.725, 0.921, 1.048, 1.22, 1.312, 1.428, 1.497, 1.554, 1.577 }; static const double x[15] = { 0.0, 0.04, 0.067, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.752, 1.0, 1.493, 2.0, 3.03, 4.0 }; static const double dv8[15] = { 5.8, 5.8, 7.2, 7.3, 6.7, 6.3, 5.7, 5.3, 5.0, 4.4, 4.0, 3.5, 3.1, 2.5, 2.1 }; static const double dv9[15] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.15, 0.265, 0.359, 0.534, 0.557, 0.484, 0.424, 0.348, 0.299 }; static const double dv10[15] = { 0.389, 0.299, 0.299, 0.299, 0.299, 0.299, 0.38, 0.484, 0.507, 0.276, 0.115, 0.023, 0.0, 0.0, 0.0 }; static const double dv11[15] = { 0.398, 0.419, 0.419, 0.437, 0.461, 0.495, 0.564, 0.608, 0.624, 0.652, 0.668, 0.679, 0.684, 0.684, 0.684 }; /* %%%%% Soil type%%%%%%% */ /* %%%%% Soil type%%%%%%% */ if (ecSoilCode == 1.0) { /* Rock */ SB = 0; SC = 0; SD = 0; } else if (ecSoilCode == 2.0) { /* Stiff soil */ SB = 1; SC = 0; SD = 0; } else if (ecSoilCode == 3.0) { /* Soft soil */ SB = 0; SC = 1; SD = 0; } else { SB = 0; SC = 0; SD = 1; } /* fault distance */ b1 = rtNaN; if (rtIsNaN(Period) || (Period > 4.0) || (Period < 0.0)) { } else { low_i = 1; low_ip1 = 2; high_i = 15; while (high_i > low_ip1) { mid_i = (low_i + high_i) >> 1; if (Period >= dv1[mid_i - 1]) { low_i = mid_i; low_ip1 = mid_i + 1; } else { high_i = mid_i; } } r = (Period - dv1[low_i - 1]) / (dv1[low_i] - dv1[low_i - 1]); if (r == 0.0) { b1 = dv2[low_i - 1]; } else if (r == 1.0) { b1 = dv2[low_i]; } else if (dv2[low_i - 1] == dv2[low_i]) { b1 = dv2[low_i - 1]; } else { b1 = (1.0 - r) * dv2[low_i - 1] + r * dv2[low_i]; } } for (low_i = 0; low_i < 15; low_i++) { dv3[low_i] = -1.0; } memset(&dv4[0], 0, 15U * sizeof(double)); memset(&dv5[0], 0, 15U * sizeof(double)); memset(&dv6[0], 0, 15U * sizeof(double)); *koefAtonacijsko_b1 = b1; *koefAtonacijsko_b2 = interp1(x, dv7, Period); *koefAtonacijsko_b3 = interp1(x, dv3, Period); *koefAtonacijsko_b4 = interp1(x, dv4, Period); *koefAtonacijsko_h0 = interp1(x, dv8, Period); *koefAtonacijsko_r0 = interp1(x, dv5, Period); *koefAtonacijsko_bSB = interp1(x, dv9, Period); *koefAtonacijsko_bSC = interp1(x, dv10, Period); *koefAtonacijsko_bSD = interp1(x, dv6, Period); *koefAtonacijsko_sigma = interp1(x, dv11, Period); *koefAtonacijsko_SB = SB; *koefAtonacijsko_SC = SC; *koefAtonacijsko_SD = SD; } /* * Arguments : const emxArray_real_T *x * emxArray_boolean_T *y * Return Type : void */ static void all(const emxArray_real_T *x, emxArray_boolean_T *y) { unsigned int outsize[2]; int i2; int iy; int i; int i1; boolean_T exitg1; for (i2 = 0; i2 < 2; i2++) { outsize[i2] = (unsigned int)x->size[i2]; } i2 = y->size[0] * y->size[1]; y->size[0] = 1; emxEnsureCapacity((emxArray__common *)y, i2, (int)sizeof(boolean_T)); i2 = y->size[0] * y->size[1]; y->size[1] = (int)outsize[1]; emxEnsureCapacity((emxArray__common *)y, i2, (int)sizeof(boolean_T)); iy = (int)outsize[1]; for (i2 = 0; i2 < iy; i2++) { y->data[i2] = true; } i2 = 0; iy = -1; for (i = 1; i <= x->size[1]; i++) { i1 = i2 + 1; i2 += x->size[0]; iy++; exitg1 = false; while ((!exitg1) && (i1 <= i2)) { if (x->data[i1 - 1] == 0.0) { y->data[iy] = false; exitg1 = true; } else { i1++; } } } } /* * Arguments : const emxArray_boolean_T *x * Return Type : boolean_T */ static boolean_T any(const emxArray_boolean_T *x) { boolean_T y; int ix; boolean_T exitg1; boolean_T b0; y = false; ix = 1; exitg1 = false; while ((!exitg1) && (ix <= x->size[1])) { b0 = !x->data[ix - 1]; if (!b0) { y = true; exitg1 = true; } else { ix++; } } return y; } /* * Arguments : const emxArray_real_T *x * emxArray_real_T *y * Return Type : void */ static void b_abs(const emxArray_real_T *x, emxArray_real_T *y) { unsigned int unnamed_idx_0; int k; unnamed_idx_0 = (unsigned int)x->size[0]; k = y->size[0]; y->size[0] = (int)unnamed_idx_0; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); for (k = 0; k < x->size[0]; k++) { y->data[k] = fabs(x->data[k]); } } /* * Arguments : const emxArray_boolean_T *x * Return Type : boolean_T */ static boolean_T b_all(const emxArray_boolean_T *x) { boolean_T y; int ix; boolean_T exitg1; y = true; ix = 1; exitg1 = false; while ((!exitg1) && (ix <= x->size[1])) { if (!x->data[ix - 1]) { y = false; exitg1 = true; } else { ix++; } } return y; } /* * Arguments : const emxArray_boolean_T *x * emxArray_boolean_T *y * Return Type : void */ static void b_any(const emxArray_boolean_T *x, emxArray_boolean_T *y) { unsigned int outsize[2]; int i2; int iy; int i; int i1; boolean_T exitg1; boolean_T b1; for (i2 = 0; i2 < 2; i2++) { outsize[i2] = (unsigned int)x->size[i2]; } i2 = y->size[0] * y->size[1]; y->size[0] = 1; emxEnsureCapacity((emxArray__common *)y, i2, (int)sizeof(boolean_T)); i2 = y->size[0] * y->size[1]; y->size[1] = (int)outsize[1]; emxEnsureCapacity((emxArray__common *)y, i2, (int)sizeof(boolean_T)); iy = (int)outsize[1]; for (i2 = 0; i2 < iy; i2++) { y->data[i2] = false; } i2 = 0; iy = -1; for (i = 1; i <= x->size[1]; i++) { i1 = i2 + 1; i2 += x->size[0]; iy++; exitg1 = false; while ((!exitg1) && (i1 <= i2)) { b1 = !x->data[i1 - 1]; if (!b1) { y->data[iy] = true; exitg1 = true; } else { i1++; } } } } /* * Arguments : const emxArray_creal_T *v * emxArray_creal_T *d * Return Type : void */ static void b_diag(const emxArray_creal_T *v, emxArray_creal_T *d) { int j; int dlen; int stride; if ((v->size[0] == 1) && (v->size[1] == 1)) { j = d->size[0]; d->size[0] = 1; emxEnsureCapacity((emxArray__common *)d, j, (int)sizeof(creal_T)); d->data[0] = v->data[0]; } else { if (0 < v->size[1]) { if (v->size[0] <= v->size[1]) { dlen = v->size[0]; } else { dlen = v->size[1]; } stride = v->size[0] + 1; } else { dlen = 0; stride = 0; } j = d->size[0]; d->size[0] = dlen; emxEnsureCapacity((emxArray__common *)d, j, (int)sizeof(creal_T)); for (j = 0; j + 1 <= dlen; j++) { d->data[j] = v->data[j * stride]; } } } /* * Arguments : const creal_T f * const creal_T g * double *cs * creal_T *sn * Return Type : void */ static void b_eml_matlab_zlartg(const creal_T f, const creal_T g, double *cs, creal_T *sn) { double scale; double f2s; double g2; double fs_re; double fs_im; double gs_re; double gs_im; boolean_T guard1 = false; double g2s; scale = fabs(f.re); f2s = fabs(f.im); if (f2s > scale) { scale = f2s; } f2s = fabs(g.re); g2 = fabs(g.im); if (g2 > f2s) { f2s = g2; } if (f2s > scale) { scale = f2s; } fs_re = f.re; fs_im = f.im; gs_re = g.re; gs_im = g.im; guard1 = false; if (scale >= 7.4428285367870146E+137) { do { fs_re *= 1.3435752215134178E-138; fs_im *= 1.3435752215134178E-138; gs_re *= 1.3435752215134178E-138; gs_im *= 1.3435752215134178E-138; scale *= 1.3435752215134178E-138; } while (!(scale < 7.4428285367870146E+137)); guard1 = true; } else if (scale <= 1.3435752215134178E-138) { if ((g.re == 0.0) && (g.im == 0.0)) { *cs = 1.0; sn->re = 0.0; sn->im = 0.0; } else { do { fs_re *= 7.4428285367870146E+137; fs_im *= 7.4428285367870146E+137; gs_re *= 7.4428285367870146E+137; gs_im *= 7.4428285367870146E+137; scale *= 7.4428285367870146E+137; } while (!(scale > 1.3435752215134178E-138)); guard1 = true; } } else { guard1 = true; } if (guard1) { scale = fs_re * fs_re + fs_im * fs_im; g2 = gs_re * gs_re + gs_im * gs_im; f2s = g2; if (1.0 > g2) { f2s = 1.0; } if (scale <= f2s * 2.0041683600089728E-292) { if ((f.re == 0.0) && (f.im == 0.0)) { *cs = 0.0; scale = rt_hypotd_snf(gs_re, gs_im); sn->re = gs_re / scale; sn->im = -gs_im / scale; } else { g2s = sqrt(g2); *cs = rt_hypotd_snf(fs_re, fs_im) / g2s; f2s = fabs(f.re); g2 = fabs(f.im); if (g2 > f2s) { f2s = g2; } if (f2s > 1.0) { scale = rt_hypotd_snf(f.re, f.im); fs_re = f.re / scale; fs_im = f.im / scale; } else { f2s = 7.4428285367870146E+137 * f.re; g2 = 7.4428285367870146E+137 * f.im; scale = rt_hypotd_snf(f2s, g2); fs_re = f2s / scale; fs_im = g2 / scale; } gs_re /= g2s; gs_im = -gs_im / g2s; sn->re = fs_re * gs_re - fs_im * gs_im; sn->im = fs_re * gs_im + fs_im * gs_re; } } else { f2s = sqrt(1.0 + g2 / scale); *cs = 1.0 / f2s; scale += g2; fs_re = f2s * fs_re / scale; fs_im = f2s * fs_im / scale; sn->re = fs_re * gs_re - fs_im * -gs_im; sn->im = fs_re * -gs_im + fs_im * gs_re; } } } /* * Arguments : emxArray_real_T *x * double idx * Return Type : void */ static void b_eml_null_assignment(emxArray_real_T *x, double idx) { int nrowx; int ncolx; int j; int i; emxArray_real_T *b_x; nrowx = x->size[0] - 1; ncolx = x->size[1]; for (j = 0; j + 1 <= ncolx; j++) { for (i = (int)idx; i <= nrowx; i++) { x->data[(i + x->size[0] * j) - 1] = x->data[i + x->size[0] * j]; } } if (1 > nrowx) { ncolx = 0; } else { ncolx = nrowx; } b_emxInit_real_T(&b_x, 2); nrowx = x->size[1]; j = b_x->size[0] * b_x->size[1]; b_x->size[0] = ncolx; b_x->size[1] = nrowx; emxEnsureCapacity((emxArray__common *)b_x, j, (int)sizeof(double)); for (j = 0; j < nrowx; j++) { for (i = 0; i < ncolx; i++) { b_x->data[i + b_x->size[0] * j] = x->data[i + x->size[0] * j]; } } j = x->size[0] * x->size[1]; x->size[0] = b_x->size[0]; x->size[1] = b_x->size[1]; emxEnsureCapacity((emxArray__common *)x, j, (int)sizeof(double)); ncolx = b_x->size[1]; for (j = 0; j < ncolx; j++) { nrowx = b_x->size[0]; for (i = 0; i < nrowx; i++) { x->data[i + x->size[0] * j] = b_x->data[i + b_x->size[0] * j]; } } emxFree_real_T(&b_x); } /* * Arguments : emxArray_boolean_T **pEmxArray * int numDimensions * Return Type : void */ static void b_emxInit_boolean_T(emxArray_boolean_T **pEmxArray, int numDimensions) { emxArray_boolean_T *emxArray; int i; *pEmxArray = (emxArray_boolean_T *)malloc(sizeof(emxArray_boolean_T)); emxArray = *pEmxArray; emxArray->data = (boolean_T *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_creal_T **pEmxArray * int numDimensions * Return Type : void */ static void b_emxInit_creal_T(emxArray_creal_T **pEmxArray, int numDimensions) { emxArray_creal_T *emxArray; int i; *pEmxArray = (emxArray_creal_T *)malloc(sizeof(emxArray_creal_T)); emxArray = *pEmxArray; emxArray->data = (creal_T *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_int32_T **pEmxArray * int numDimensions * Return Type : void */ static void b_emxInit_int32_T(emxArray_int32_T **pEmxArray, int numDimensions) { emxArray_int32_T *emxArray; int i; *pEmxArray = (emxArray_int32_T *)malloc(sizeof(emxArray_int32_T)); emxArray = *pEmxArray; emxArray->data = (int *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_real_T **pEmxArray * int numDimensions * Return Type : void */ static void b_emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions) { emxArray_real_T *emxArray; int i; *pEmxArray = (emxArray_real_T *)malloc(sizeof(emxArray_real_T)); emxArray = *pEmxArray; emxArray->data = (double *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void b_exp(emxArray_real_T *x) { int i10; int k; i10 = x->size[1]; for (k = 0; k < i10; k++) { x->data[k] = exp(x->data[k]); } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void b_log(emxArray_real_T *x) { int i11; int k; i11 = x->size[1]; for (k = 0; k < i11; k++) { x->data[k] = log(x->data[k]); } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void b_round(emxArray_real_T *x) { int i16; int k; i16 = x->size[0] * x->size[1]; for (k = 0; k < i16; k++) { x->data[k] = rt_roundd_snf(x->data[k]); } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void b_sqrt(emxArray_real_T *x) { int i12; int k; i12 = x->size[1]; for (k = 0; k < i12; k++) { x->data[k] = sqrt(x->data[k]); } } /* * Arguments : const emxArray_real_T *varargin_1 * emxArray_real_T *y * Return Type : void */ static void b_std(const emxArray_real_T *varargin_1, emxArray_real_T *y) { int n; int d; unsigned int sz[2]; int iy; int ix; int i; int b_ix; double xbar; int k; double r; double b_y; n = varargin_1->size[0] - 2; if (varargin_1->size[0] > 1) { d = varargin_1->size[0] - 1; } else { d = varargin_1->size[0]; } for (iy = 0; iy < 2; iy++) { sz[iy] = (unsigned int)varargin_1->size[iy]; } iy = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)y, iy, (int)sizeof(double)); if ((varargin_1->size[0] == 0) || (varargin_1->size[1] == 0)) { iy = y->size[0] * y->size[1]; y->size[0] = 1; emxEnsureCapacity((emxArray__common *)y, iy, (int)sizeof(double)); iy = y->size[0] * y->size[1]; y->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)y, iy, (int)sizeof(double)); ix = (int)sz[1]; for (iy = 0; iy < ix; iy++) { y->data[iy] = 0.0; } } else { ix = 0; iy = -1; for (i = 1; i <= varargin_1->size[1]; i++) { iy++; b_ix = ix; xbar = varargin_1->data[ix]; for (k = 0; k <= n; k++) { b_ix++; xbar += varargin_1->data[b_ix]; } xbar /= (double)(n + 2); b_ix = ix; r = varargin_1->data[ix] - xbar; b_y = r * r; for (k = 0; k <= n; k++) { b_ix++; r = varargin_1->data[b_ix] - xbar; b_y += r * r; } b_y /= (double)d; y->data[iy] = b_y; ix = (ix + n) + 2; } } b_sqrt(y); } /* * Arguments : const emxArray_real_T *x * Return Type : double */ static double b_sum(const emxArray_real_T *x) { double y; int k; if (x->size[1] == 0) { y = 0.0; } else { y = x->data[0]; for (k = 2; k <= x->size[1]; k++) { y += x->data[k - 1]; } } return y; } /* * Created by Jack Baker, 2/28/07 (updated 6/25/2007) * Compute the correlation of epsilons for the NGA ground motion models * * The function is strictly emperical, fitted over the range the range 0.01s <= T1, T2 <= 10s * * Documentation is provided in the following document: * Baker, J.W. and Jayaram, N., "Correlation of spectral acceleration values from NGA ground * motion models," Earthquake Spectra, (in review). * Arguments : double T1 * double T2 * Return Type : double */ static double baker_jayaram_correlation(double T1, double T2) { double rho; double C2; double T_min; double T_max; double b_T_min; double x; double C3; double C4; /* INPUT */ /* */ /* T1, T2 = The two periods of interest. The periods may be equal, */ /* and there is no restriction on which one is larger. */ /* */ /* INPUT */ /* */ /* rho = The predicted correlation coefficient */ C2 = 0.0; if ((T1 <= T2) || rtIsNaN(T2)) { T_min = T1; } else { T_min = T2; } if ((T1 >= T2) || rtIsNaN(T2)) { T_max = T1; } else { T_max = T2; } if (T_min >= 0.109) { b_T_min = T_min; } else { b_T_min = 0.109; } x = cos(1.5707963267948966 - log(T_max / b_T_min) * 0.366); if (T_max < 0.2) { C2 = 1.0 - 0.105 * (1.0 - 1.0 / (1.0 + exp(100.0 * T_max - 5.0))) * (T_max - T_min) / (T_max - 0.0099); } if (T_max < 0.109) { C3 = C2; } else { C3 = 1.0 - x; } C4 = (1.0 - x) + 0.5 * (sqrt(C3) - C3) * (1.0 + cos(3.1415926535897931 * T_min / 0.109)); if (T_max <= 0.109) { rho = C2; } else if (T_min > 0.109) { rho = 1.0 - x; } else if (T_max < 0.2) { if ((C2 <= C4) || rtIsNaN(C4)) { rho = C2; } else { rho = C4; } } else { rho = C4; } return rho; } /* * Arguments : const emxArray_real_T *x * emxArray_real_T *y * Return Type : void */ static void c_abs(const emxArray_real_T *x, emxArray_real_T *y) { unsigned int uv0[2]; int i7; int k; for (i7 = 0; i7 < 2; i7++) { uv0[i7] = (unsigned int)x->size[i7]; } i7 = y->size[0] * y->size[1]; y->size[0] = (int)uv0[0]; y->size[1] = (int)uv0[1]; emxEnsureCapacity((emxArray__common *)y, i7, (int)sizeof(double)); i7 = x->size[0] * x->size[1]; for (k = 0; k < i7; k++) { y->data[k] = fabs(x->data[k]); } } /* * Arguments : const emxArray_boolean_T *x * Return Type : boolean_T */ static boolean_T c_all(const emxArray_boolean_T *x) { boolean_T y; int ix; boolean_T exitg1; y = true; ix = 1; exitg1 = false; while ((!exitg1) && (ix <= x->size[0])) { if (!x->data[ix - 1]) { y = false; exitg1 = true; } else { ix++; } } return y; } /* * Arguments : const emxArray_boolean_T *x * Return Type : boolean_T */ static boolean_T c_any(const emxArray_boolean_T *x) { boolean_T y; int ix; boolean_T exitg1; boolean_T b2; y = false; ix = 1; exitg1 = false; while ((!exitg1) && (ix <= x->size[0])) { b2 = !x->data[ix - 1]; if (!b2) { y = true; exitg1 = true; } else { ix++; } } return y; } /* * Arguments : void * Return Type : void */ static void c_eml_rand_mt19937ar_stateful_i(void) { unsigned int r; int mti; memset(&c_state[0], 0, 625U * sizeof(unsigned int)); r = 5489U; c_state[0] = 5489U; for (mti = 0; mti < 623; mti++) { r = (r ^ r >> 30U) * 1812433253U + (1 + mti); c_state[mti + 1] = r; } c_state[624] = 624U; } /* * Arguments : emxArray_real_T **pEmxArray * int numDimensions * Return Type : void */ static void c_emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions) { emxArray_real_T *emxArray; int i; *pEmxArray = (emxArray_real_T *)malloc(sizeof(emxArray_real_T)); emxArray = *pEmxArray; emxArray->data = (double *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void c_exp(emxArray_real_T *x) { int i18; int k; i18 = x->size[0] * x->size[1]; for (k = 0; k < i18; k++) { x->data[k] = exp(x->data[k]); } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void c_log(emxArray_real_T *x) { int i15; int k; i15 = x->size[0] * x->size[1]; for (k = 0; k < i15; k++) { x->data[k] = log(x->data[k]); } } /* * Arguments : creal_T *x * Return Type : void */ static void c_sqrt(creal_T *x) { double absxi; double absxr; if (x->im == 0.0) { if (x->re < 0.0) { absxi = 0.0; absxr = sqrt(fabs(x->re)); } else { absxi = sqrt(x->re); absxr = 0.0; } } else if (x->re == 0.0) { if (x->im < 0.0) { absxi = sqrt(-x->im / 2.0); absxr = -absxi; } else { absxi = sqrt(x->im / 2.0); absxr = absxi; } } else if (rtIsNaN(x->re) || rtIsNaN(x->im)) { absxi = rtNaN; absxr = rtNaN; } else if (rtIsInf(x->im)) { absxi = rtInf; absxr = x->im; } else if (rtIsInf(x->re)) { if (x->re < 0.0) { absxi = 0.0; absxr = rtInf; } else { absxi = rtInf; absxr = 0.0; } } else { absxr = fabs(x->re); absxi = fabs(x->im); if ((absxr > 4.4942328371557893E+307) || (absxi > 4.4942328371557893E+307)) { absxr *= 0.5; absxi *= 0.5; absxi = rt_hypotd_snf(absxr, absxi); if (absxi > absxr) { absxi = sqrt(absxi) * sqrt(1.0 + absxr / absxi); } else { absxi = sqrt(absxi) * 1.4142135623730951; } } else { absxi = sqrt((rt_hypotd_snf(absxr, absxi) + absxr) * 0.5); } if (x->re > 0.0) { absxr = 0.5 * (x->im / absxi); } else { if (x->im < 0.0) { absxr = -absxi; } else { absxr = absxi; } absxi = 0.5 * (x->im / absxr); } } x->re = absxi; x->im = absxr; } /* * CHOLCOV Cholesky-like decomposition for covariance matrix. * T = CHOLCOV(SIGMA) computes T such that SIGMA = T'*T. SIGMA must be * square, symmetric, and positive semi-definite. If SIGMA is positive * definite, then T is the square, upper triangular Cholesky factor. * * If SIGMA is not positive definite, T is computed from an eigenvalue * decomposition of SIGMA. T is not necessarily triangular or square in * this case. Any eigenvectors whose corresponding eigenvalue is close to * zero (within a small tolerance) are omitted. If any remaining * eigenvalues are negative, T is empty. * * [T,P] = CHOLCOV(SIGMA) returns the number of negative eigenvalues of * SIGMA, and T is empty if P>0. If P==0, SIGMA is positive semi-definite. * * If SIGMA is not square and symmetric, P is NaN and T is empty. * * [T,P] = CHOLCOV(SIGMA,0) returns P==0 if SIGMA is positive definite, and * T is the Cholesky factor. If SIGMA is not positive definite, P is a * positive integer and T is empty. [...] = CHOLCOV(SIGMA,1) is equivalent * to [...] = CHOLCOV(SIGMA). * * Example: * Factor a rank-deficient covariance matrix C. * C = [2 1 1 2;1 2 1 2;1 1 2 2;2 2 2 3] * T = cholcov(C) * C2 = T'*T * Generate data with this covariance (aside from random variation). * C3 = cov(randn(10000,3)*T) * * See also CHOL. * Arguments : const emxArray_real_T *Sigma * emxArray_real_T *T * double *p * Return Type : void */ static void cholcov_(const emxArray_real_T *Sigma, emxArray_real_T *T, double *p) { emxArray_real_T *D; emxArray_real_T *r3; int ixstart; int n; double ajj; int ix; boolean_T exitg4; emxArray_real_T *b_Sigma; int i5; int nmj; int iac; int i6; emxArray_boolean_T *negloc; boolean_T x; int b_n; int info; int colj; int j; boolean_T exitg3; int jj; int iy; int k; double c; int ia; emxArray_real_T *b_T; emxArray_real_T *c_Sigma; emxArray_creal_T *U; emxArray_creal_T *b_D; emxArray_real_T *b_U; emxArray_real_T *c_D; emxArray_real_T *d_D; emxArray_real_T *V; emxArray_int32_T *iidx; emxArray_real_T *d_Sigma; emxArray_creal_T *r4; unsigned int outsz[2]; emxArray_int32_T *iindx; unsigned int b_outsz; boolean_T exitg2; double apnd; double cdiff; emxArray_real_T *extremum; emxArray_real_T *c_U; boolean_T exitg1; int exponent; emxArray_boolean_T *b_x; emxArray_real_T *b; emxInit_real_T(&D, 1); emxInit_real_T(&r3, 1); /* Copyright 1993-2009 The MathWorks, Inc. */ /* Test for square, symmetric */ diag(Sigma, r3); b_abs(r3, D); ixstart = 1; n = D->size[0]; ajj = D->data[0]; if (D->size[0] > 1) { if (rtIsNaN(D->data[0])) { ix = 2; exitg4 = false; while ((!exitg4) && (ix <= n)) { ixstart = ix; if (!rtIsNaN(D->data[ix - 1])) { ajj = D->data[ix - 1]; exitg4 = true; } else { ix++; } } } if (ixstart < D->size[0]) { while (ixstart + 1 <= n) { if (D->data[ixstart] > ajj) { ajj = D->data[ixstart]; } ixstart++; } } } b_emxInit_real_T(&b_Sigma, 2); i5 = b_Sigma->size[0] * b_Sigma->size[1]; b_Sigma->size[0] = Sigma->size[0]; b_Sigma->size[1] = Sigma->size[1]; emxEnsureCapacity((emxArray__common *)b_Sigma, i5, (int)sizeof(double)); nmj = Sigma->size[1]; for (i5 = 0; i5 < nmj; i5++) { iac = Sigma->size[0]; for (i6 = 0; i6 < iac; i6++) { b_Sigma->data[i6 + b_Sigma->size[0] * i5] = Sigma->data[i6 + Sigma->size[0] * i5] - Sigma->data[i5 + Sigma->size[0] * i6]; } } emxInit_boolean_T(&negloc, 2); all(b_Sigma, negloc); x = b_all(negloc); emxFree_real_T(&b_Sigma); if ((double)x < 10.0 * eps(ajj)) { /* abs(all(all(Sigma - Sigma')))size[0] * T->size[1]; T->size[0] = Sigma->size[0]; T->size[1] = Sigma->size[1]; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); nmj = Sigma->size[0] * Sigma->size[1]; for (i5 = 0; i5 < nmj; i5++) { T->data[i5] = Sigma->data[i5]; } n = Sigma->size[1]; ixstart = 0; if (Sigma->size[1] == 0) { } else { b_n = Sigma->size[0]; info = -1; if (Sigma->size[0] == 0) { } else { colj = 0; j = 0; exitg3 = false; while ((!exitg3) && (j + 1 <= b_n)) { jj = colj + j; ajj = 0.0; if (j < 1) { } else { ix = colj; iy = colj; for (k = 1; k <= j; k++) { ajj += T->data[ix] * T->data[iy]; ix++; iy++; } } ajj = T->data[jj] - ajj; if (ajj > 0.0) { ajj = sqrt(ajj); T->data[jj] = ajj; if (j + 1 < b_n) { nmj = (b_n - j) - 2; ixstart = jj + b_n; jj = (colj + b_n) + 1; if ((j == 0) || (nmj + 1 == 0)) { } else { iy = ixstart; i5 = jj + n * nmj; for (iac = jj; iac <= i5; iac += n) { ix = colj + 1; c = 0.0; i6 = (iac + j) - 1; for (ia = iac; ia <= i6; ia++) { c += T->data[ia - 1] * T->data[ix - 1]; ix++; } T->data[iy] += -c; iy += n; } } ajj = 1.0 / ajj; i5 = (ixstart + b_n * nmj) + 1; while (ixstart + 1 <= i5) { T->data[ixstart] *= ajj; ixstart += b_n; } colj = jj - 1; } j++; } else { T->data[jj] = ajj; info = j; exitg3 = true; } } } ixstart = info + 1; if (info + 1 == 0) { jj = Sigma->size[1]; } else { jj = info; } for (j = 0; j + 1 <= jj; j++) { for (info = j + 1; info + 1 <= jj; info++) { T->data[info + T->size[0] * j] = 0.0; } } if (1 > jj) { nmj = 0; } else { nmj = jj; } if (1 > jj) { iac = 0; } else { iac = jj; } b_emxInit_real_T(&b_T, 2); i5 = b_T->size[0] * b_T->size[1]; b_T->size[0] = nmj; b_T->size[1] = iac; emxEnsureCapacity((emxArray__common *)b_T, i5, (int)sizeof(double)); for (i5 = 0; i5 < iac; i5++) { for (i6 = 0; i6 < nmj; i6++) { b_T->data[i6 + b_T->size[0] * i5] = T->data[i6 + T->size[0] * i5]; } } i5 = T->size[0] * T->size[1]; T->size[0] = b_T->size[0]; T->size[1] = b_T->size[1]; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); nmj = b_T->size[1]; for (i5 = 0; i5 < nmj; i5++) { iac = b_T->size[0]; for (i6 = 0; i6 < iac; i6++) { T->data[i6 + T->size[0] * i5] = b_T->data[i6 + b_T->size[0] * i5]; } } emxFree_real_T(&b_T); } *p = ixstart; if (ixstart > 0) { b_emxInit_real_T(&c_Sigma, 2); /* Test for positive definiteness */ /* Can get factors of the form Sigma==T'*T using the eigenvalue */ /* decomposition of a symmetric matrix, so long as the matrix */ /* is positive semi-definite. */ i5 = c_Sigma->size[0] * c_Sigma->size[1]; c_Sigma->size[0] = Sigma->size[0]; c_Sigma->size[1] = Sigma->size[1]; emxEnsureCapacity((emxArray__common *)c_Sigma, i5, (int)sizeof(double)); nmj = Sigma->size[1]; for (i5 = 0; i5 < nmj; i5++) { iac = Sigma->size[0]; for (i6 = 0; i6 < iac; i6++) { c_Sigma->data[i6 + c_Sigma->size[0] * i5] = (Sigma->data[i6 + Sigma->size[0] * i5] + Sigma->data[i5 + Sigma->size[0] * i6]) / 2.0; } } emxInit_creal_T(&U, 2); emxInit_creal_T(&b_D, 2); b_emxInit_real_T(&b_U, 2); eig(c_Sigma, U, b_D); /* Use real() to elemenate imaginary part - C always returns */ /* complex numbers when using eval(); zsebenik */ i5 = b_U->size[0] * b_U->size[1]; b_U->size[0] = U->size[0]; b_U->size[1] = U->size[1]; emxEnsureCapacity((emxArray__common *)b_U, i5, (int)sizeof(double)); nmj = U->size[0] * U->size[1]; emxFree_real_T(&c_Sigma); for (i5 = 0; i5 < nmj; i5++) { b_U->data[i5] = U->data[i5].re; } b_emxInit_real_T(&c_D, 2); i5 = c_D->size[0] * c_D->size[1]; c_D->size[0] = b_D->size[0]; c_D->size[1] = b_D->size[1]; emxEnsureCapacity((emxArray__common *)c_D, i5, (int)sizeof(double)); nmj = b_D->size[0] * b_D->size[1]; for (i5 = 0; i5 < nmj; i5++) { c_D->data[i5] = b_D->data[i5].re; } emxInit_real_T(&d_D, 1); diag(c_D, D); nmj = D->size[0]; i5 = d_D->size[0]; d_D->size[0] = nmj; emxEnsureCapacity((emxArray__common *)d_D, i5, (int)sizeof(double)); emxFree_real_T(&c_D); for (i5 = 0; i5 < nmj; i5++) { d_D->data[i5] = D->data[i5]; } b_emxInit_real_T(&V, 2); b_emxInit_int32_T(&iidx, 1); if (!issorted(d_D)) { b_emxInit_real_T(&d_Sigma, 2); i5 = d_Sigma->size[0] * d_Sigma->size[1]; d_Sigma->size[0] = Sigma->size[0]; d_Sigma->size[1] = Sigma->size[1]; emxEnsureCapacity((emxArray__common *)d_Sigma, i5, (int)sizeof(double)); nmj = Sigma->size[1]; for (i5 = 0; i5 < nmj; i5++) { iac = Sigma->size[0]; for (i6 = 0; i6 < iac; i6++) { d_Sigma->data[i6 + d_Sigma->size[0] * i5] = (Sigma->data[i6 + Sigma->size[0] * i5] + Sigma->data[i5 + Sigma->size[0] * i6]) / 2.0; } } eig(d_Sigma, U, b_D); i5 = V->size[0] * V->size[1]; V->size[0] = U->size[0]; V->size[1] = U->size[1]; emxEnsureCapacity((emxArray__common *)V, i5, (int)sizeof(double)); nmj = U->size[0] * U->size[1]; emxFree_real_T(&d_Sigma); for (i5 = 0; i5 < nmj; i5++) { V->data[i5] = U->data[i5].re; } b_emxInit_creal_T(&r4, 1); b_diag(b_D, r4); i5 = D->size[0]; D->size[0] = r4->size[0]; emxEnsureCapacity((emxArray__common *)D, i5, (int)sizeof(double)); nmj = r4->size[0]; for (i5 = 0; i5 < nmj; i5++) { D->data[i5] = r4->data[i5].re; } emxFree_creal_T(&r4); eml_sort(D, iidx); nmj = V->size[0]; i5 = b_U->size[0] * b_U->size[1]; b_U->size[0] = nmj; b_U->size[1] = iidx->size[0]; emxEnsureCapacity((emxArray__common *)b_U, i5, (int)sizeof(double)); iac = iidx->size[0]; for (i5 = 0; i5 < iac; i5++) { for (i6 = 0; i6 < nmj; i6++) { b_U->data[i6 + b_U->size[0] * i5] = V->data[i6 + V->size[0] * (iidx->data[i5] - 1)]; } } } emxFree_real_T(&d_D); emxFree_creal_T(&b_D); emxFree_creal_T(&U); /* Pick eigenvector direction so max abs coordinate is positive */ c_abs(b_U, V); for (i5 = 0; i5 < 2; i5++) { outsz[i5] = (unsigned int)V->size[i5]; } emxInit_int32_T(&iindx, 2); b_outsz = outsz[1]; i5 = iindx->size[0] * iindx->size[1]; iindx->size[0] = 1; emxEnsureCapacity((emxArray__common *)iindx, i5, (int)sizeof(int)); i5 = iindx->size[0] * iindx->size[1]; iindx->size[1] = (int)outsz[1]; emxEnsureCapacity((emxArray__common *)iindx, i5, (int)sizeof(int)); nmj = (int)b_outsz; for (i5 = 0; i5 < nmj; i5++) { iindx->data[i5] = 1; } n = V->size[0]; ix = 0; iy = -1; for (info = 1; info <= V->size[1]; info++) { ixstart = ix; jj = ix + n; ajj = V->data[ix]; iac = 1; if (n > 1) { nmj = 1; if (rtIsNaN(V->data[ix])) { b_n = ix + 1; exitg2 = false; while ((!exitg2) && (b_n + 1 <= jj)) { nmj++; ixstart = b_n; if (!rtIsNaN(V->data[b_n])) { ajj = V->data[b_n]; iac = nmj; exitg2 = true; } else { b_n++; } } } if (ixstart + 1 < jj) { for (b_n = ixstart + 1; b_n + 1 <= jj; b_n++) { nmj++; if (V->data[b_n] > ajj) { ajj = V->data[b_n]; iac = nmj; } } } } iy++; iindx->data[iy] = iac; ix += n; } ajj = ((double)Sigma->size[1] - 1.0) * (double)Sigma->size[0]; if ((Sigma->size[0] == 0) || (ajj < 0.0)) { n = -1; apnd = ajj; } else { c = floor(ajj / (double)Sigma->size[0] + 0.5); apnd = c * (double)Sigma->size[0]; cdiff = apnd - ajj; if (fabs(cdiff) < 4.4408920985006262E-16 * ajj) { c++; apnd = ajj; } else if (cdiff > 0.0) { apnd = (c - 1.0) * (double)Sigma->size[0]; } else { c++; } n = (int)c - 1; } b_emxInit_real_T(&extremum, 2); i5 = extremum->size[0] * extremum->size[1]; extremum->size[0] = 1; extremum->size[1] = n + 1; emxEnsureCapacity((emxArray__common *)extremum, i5, (int)sizeof(double)); if (n + 1 > 0) { extremum->data[0] = 0.0; if (n + 1 > 1) { extremum->data[n] = apnd; jj = n / 2; for (k = 1; k < jj; k++) { ajj = (double)k * (double)Sigma->size[0]; extremum->data[k] = ajj; extremum->data[n - k] = apnd - ajj; } if (jj << 1 == n) { extremum->data[jj] = apnd / 2.0; } else { ajj = (double)jj * (double)Sigma->size[0]; extremum->data[jj] = ajj; extremum->data[jj + 1] = apnd - ajj; } } } i5 = negloc->size[0] * negloc->size[1]; negloc->size[0] = 1; negloc->size[1] = iindx->size[1]; emxEnsureCapacity((emxArray__common *)negloc, i5, (int)sizeof(boolean_T)); nmj = iindx->size[0] * iindx->size[1]; for (i5 = 0; i5 < nmj; i5++) { negloc->data[i5] = (b_U->data[(int)((double)iindx->data[i5] + extremum->data[i5]) - 1] < 0.0); } emxFree_real_T(&extremum); jj = negloc->size[1] - 1; iac = 0; for (info = 0; info <= jj; info++) { if (negloc->data[info]) { iac++; } } i5 = iindx->size[0] * iindx->size[1]; iindx->size[0] = 1; iindx->size[1] = iac; emxEnsureCapacity((emxArray__common *)iindx, i5, (int)sizeof(int)); ixstart = 0; for (info = 0; info <= jj; info++) { if (negloc->data[info]) { iindx->data[ixstart] = info + 1; ixstart++; } } b_emxInit_real_T(&c_U, 2); jj = b_U->size[0]; i5 = c_U->size[0] * c_U->size[1]; c_U->size[0] = jj; c_U->size[1] = iindx->size[1]; emxEnsureCapacity((emxArray__common *)c_U, i5, (int)sizeof(double)); nmj = iindx->size[1]; for (i5 = 0; i5 < nmj; i5++) { for (i6 = 0; i6 < jj; i6++) { c_U->data[i6 + c_U->size[0] * i5] = -b_U->data[i6 + b_U->size[0] * (iindx->data[iindx->size[0] * i5] - 1)]; } } nmj = c_U->size[1]; for (i5 = 0; i5 < nmj; i5++) { iac = c_U->size[0]; for (i6 = 0; i6 < iac; i6++) { b_U->data[i6 + b_U->size[0] * (iindx->data[iindx->size[0] * i5] - 1)] = c_U->data[i6 + c_U->size[0] * i5]; } } emxFree_real_T(&c_U); emxFree_int32_T(&iindx); /* D = flipud(real(diag(D))); */ /* D = real(diag(D)); */ /* D = sort(real(diag(D))); */ ixstart = 1; n = D->size[0]; ajj = D->data[0]; if (D->size[0] > 1) { if (rtIsNaN(D->data[0])) { ix = 2; exitg1 = false; while ((!exitg1) && (ix <= n)) { ixstart = ix; if (!rtIsNaN(D->data[ix - 1])) { ajj = D->data[ix - 1]; exitg1 = true; } else { ix++; } } } if (ixstart < D->size[0]) { while (ixstart + 1 <= n) { if (D->data[ixstart] > ajj) { ajj = D->data[ixstart]; } ixstart++; } } } ajj = fabs(ajj); if ((!rtIsInf(ajj)) && (!rtIsNaN(ajj))) { if (ajj <= 2.2250738585072014E-308) { ajj = 4.94065645841247E-324; } else { frexp(ajj, &exponent); ajj = ldexp(1.0, exponent - 53); } } else { ajj = rtNaN; } ajj *= (double)D->size[0]; b_abs(D, r3); jj = r3->size[0] - 1; iac = 0; for (info = 0; info <= jj; info++) { if (r3->data[info] > ajj) { iac++; } } ixstart = 0; for (info = 0; info <= jj; info++) { if (r3->data[info] > ajj) { D->data[ixstart] = D->data[info]; ixstart++; } } b_emxInit_boolean_T(&b_x, 1); i5 = D->size[0]; D->size[0] = iac; emxEnsureCapacity((emxArray__common *)D, i5, (int)sizeof(double)); i5 = b_x->size[0]; b_x->size[0] = D->size[0]; emxEnsureCapacity((emxArray__common *)b_x, i5, (int)sizeof(boolean_T)); nmj = D->size[0]; for (i5 = 0; i5 < nmj; i5++) { b_x->data[i5] = (D->data[i5] < 0.0); } if (b_x->size[0] == 0) { *p = 0.0; } else { *p = b_x->data[0]; for (k = 2; k <= b_x->size[0]; k++) { *p += (double)b_x->data[k - 1]; } } emxFree_boolean_T(&b_x); /* number of negative eigenvalues */ if (*p == 0.0) { jj = r3->size[0] - 1; iac = 0; for (info = 0; info <= jj; info++) { if (r3->data[info] > ajj) { iac++; } } i5 = iidx->size[0]; iidx->size[0] = iac; emxEnsureCapacity((emxArray__common *)iidx, i5, (int)sizeof(int)); ixstart = 0; for (info = 0; info <= jj; info++) { if (r3->data[info] > ajj) { iidx->data[ixstart] = info + 1; ixstart++; } } d_sqrt(D); jj = D->size[0]; ixstart = D->size[0]; i5 = V->size[0] * V->size[1]; V->size[0] = jj; emxEnsureCapacity((emxArray__common *)V, i5, (int)sizeof(double)); i5 = V->size[0] * V->size[1]; V->size[1] = ixstart; emxEnsureCapacity((emxArray__common *)V, i5, (int)sizeof(double)); nmj = jj * ixstart; for (i5 = 0; i5 < nmj; i5++) { V->data[i5] = 0.0; } for (j = 0; j + 1 <= D->size[0]; j++) { V->data[j + V->size[0] * j] = D->data[j]; } b_emxInit_real_T(&b, 2); nmj = b_U->size[0]; i5 = b->size[0] * b->size[1]; b->size[0] = iidx->size[0]; b->size[1] = nmj; emxEnsureCapacity((emxArray__common *)b, i5, (int)sizeof(double)); for (i5 = 0; i5 < nmj; i5++) { iac = iidx->size[0]; for (i6 = 0; i6 < iac; i6++) { b->data[i6 + b->size[0] * i5] = b_U->data[i5 + b_U->size[0] * (iidx->data[i6] - 1)]; } } if ((V->size[1] == 1) || (b->size[0] == 1)) { i5 = T->size[0] * T->size[1]; T->size[0] = V->size[0]; T->size[1] = b->size[1]; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); nmj = V->size[0]; for (i5 = 0; i5 < nmj; i5++) { iac = b->size[1]; for (i6 = 0; i6 < iac; i6++) { T->data[i5 + T->size[0] * i6] = 0.0; ixstart = V->size[1]; for (jj = 0; jj < ixstart; jj++) { T->data[i5 + T->size[0] * i6] += V->data[i5 + V->size[0] * jj] * b->data[jj + b->size[0] * i6]; } } } } else { k = V->size[1]; outsz[0] = (unsigned int)V->size[0]; outsz[1] = (unsigned int)b->size[1]; colj = V->size[0]; i5 = T->size[0] * T->size[1]; T->size[0] = (int)outsz[0]; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); i5 = T->size[0] * T->size[1]; T->size[1] = (int)outsz[1]; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); nmj = (int)outsz[0] * (int)outsz[1]; for (i5 = 0; i5 < nmj; i5++) { T->data[i5] = 0.0; } if ((V->size[0] == 0) || (b->size[1] == 0)) { } else { ixstart = V->size[0] * (b->size[1] - 1); iac = 0; while ((colj > 0) && (iac <= ixstart)) { i5 = iac + colj; for (info = iac; info + 1 <= i5; info++) { T->data[info] = 0.0; } iac += colj; } nmj = 0; iac = 0; while ((colj > 0) && (iac <= ixstart)) { b_n = 0; i5 = nmj + k; for (jj = nmj; jj + 1 <= i5; jj++) { if (b->data[jj] != 0.0) { ia = b_n; i6 = iac + colj; for (info = iac; info + 1 <= i6; info++) { ia++; T->data[info] += b->data[jj] * V->data[ia - 1]; } } b_n += colj; } nmj += k; iac += colj; } } } emxFree_real_T(&b); } else { i5 = T->size[0] * T->size[1]; T->size[0] = 0; T->size[1] = 0; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); } emxFree_int32_T(&iidx); emxFree_real_T(&V); emxFree_real_T(&b_U); } } else { i5 = T->size[0] * T->size[1]; T->size[0] = 0; T->size[1] = 0; emxEnsureCapacity((emxArray__common *)T, i5, (int)sizeof(double)); *p = rtNaN; } emxFree_real_T(&r3); emxFree_real_T(&D); emxFree_boolean_T(&negloc); } /* * Arguments : const double x[20] * double y[20] * Return Type : void */ static void d_abs(const double x[20], double y[20]) { int k; for (k = 0; k < 20; k++) { y[k] = fabs(x[k]); } } /* * Arguments : emxArray_real_T *x * Return Type : void */ static void d_sqrt(emxArray_real_T *x) { int i14; int k; i14 = x->size[0]; for (k = 0; k < i14; k++) { x->data[k] = sqrt(x->data[k]); } } /* * Arguments : const emxArray_real_T *v * emxArray_real_T *d * Return Type : void */ static void diag(const emxArray_real_T *v, emxArray_real_T *d) { int j; int dlen; int stride; if ((v->size[0] == 1) && (v->size[1] == 1)) { j = d->size[0]; d->size[0] = 1; emxEnsureCapacity((emxArray__common *)d, j, (int)sizeof(double)); d->data[0] = v->data[0]; } else { if (0 < v->size[1]) { if (v->size[0] <= v->size[1]) { dlen = v->size[0]; } else { dlen = v->size[1]; } stride = v->size[0] + 1; } else { dlen = 0; stride = 0; } j = d->size[0]; d->size[0] = dlen; emxEnsureCapacity((emxArray__common *)d, j, (int)sizeof(double)); for (j = 0; j + 1 <= dlen; j++) { d->data[j] = v->data[j * stride]; } } } /* * Arguments : const double x[501] * double y[501] * Return Type : void */ static void e_abs(const double x[501], double y[501]) { int k; for (k = 0; k < 501; k++) { y[k] = fabs(x[k]); } } /* * Arguments : const emxArray_real_T *A * emxArray_creal_T *V * emxArray_creal_T *D * Return Type : void */ static void eig(const emxArray_real_T *A, emxArray_creal_T *V, emxArray_creal_T * D) { emxArray_creal_T *b_A; int kend; int j; emxArray_creal_T *c_A; emxArray_creal_T *alpha1; emxArray_creal_T *beta1; int n; int c; int coltop; double colnorm; double scale; double absxk; double t; double alpha1_re; double alpha1_im; emxInit_creal_T(&b_A, 2); kend = b_A->size[0] * b_A->size[1]; b_A->size[0] = A->size[0]; b_A->size[1] = A->size[1]; emxEnsureCapacity((emxArray__common *)b_A, kend, (int)sizeof(creal_T)); j = A->size[0] * A->size[1]; for (kend = 0; kend < j; kend++) { b_A->data[kend].re = A->data[kend]; b_A->data[kend].im = 0.0; } emxInit_creal_T(&c_A, 2); kend = c_A->size[0] * c_A->size[1]; c_A->size[0] = b_A->size[0]; c_A->size[1] = b_A->size[1]; emxEnsureCapacity((emxArray__common *)c_A, kend, (int)sizeof(creal_T)); j = b_A->size[0] * b_A->size[1]; for (kend = 0; kend < j; kend++) { c_A->data[kend] = b_A->data[kend]; } b_emxInit_creal_T(&alpha1, 1); b_emxInit_creal_T(&beta1, 1); eml_matlab_zggev(c_A, &j, alpha1, beta1, V); n = b_A->size[0]; emxFree_creal_T(&c_A); if (b_A->size[0] > 0) { c = (b_A->size[0] - 1) * b_A->size[0]; for (coltop = 1; coltop <= c + 1; coltop += n) { colnorm = 0.0; if (n == 1) { colnorm = rt_hypotd_snf(V->data[coltop - 1].re, V->data[coltop - 1].im); } else { scale = 2.2250738585072014E-308; kend = (coltop + n) - 1; for (j = coltop; j <= kend; j++) { absxk = fabs(V->data[j - 1].re); if (absxk > scale) { t = scale / absxk; colnorm = 1.0 + colnorm * t * t; scale = absxk; } else { t = absxk / scale; colnorm += t * t; } absxk = fabs(V->data[j - 1].im); if (absxk > scale) { t = scale / absxk; colnorm = 1.0 + colnorm * t * t; scale = absxk; } else { t = absxk / scale; colnorm += t * t; } } colnorm = scale * sqrt(colnorm); } kend = (coltop + n) - 1; for (j = coltop; j <= kend; j++) { absxk = V->data[j - 1].re; scale = V->data[j - 1].im; if (scale == 0.0) { V->data[j - 1].re = absxk / colnorm; V->data[j - 1].im = 0.0; } else if (absxk == 0.0) { V->data[j - 1].re = 0.0; V->data[j - 1].im = scale / colnorm; } else { V->data[j - 1].re = absxk / colnorm; V->data[j - 1].im = scale / colnorm; } } } } emxFree_creal_T(&b_A); j = alpha1->size[0]; kend = D->size[0] * D->size[1]; D->size[0] = j; emxEnsureCapacity((emxArray__common *)D, kend, (int)sizeof(creal_T)); j = alpha1->size[0]; kend = D->size[0] * D->size[1]; D->size[1] = j; emxEnsureCapacity((emxArray__common *)D, kend, (int)sizeof(creal_T)); j = alpha1->size[0] * alpha1->size[0]; for (kend = 0; kend < j; kend++) { D->data[kend].re = 0.0; D->data[kend].im = 0.0; } for (j = 0; j < alpha1->size[0]; j++) { alpha1_re = alpha1->data[j].re; alpha1_im = alpha1->data[j].im; absxk = beta1->data[j].re; t = beta1->data[j].im; if (t == 0.0) { if (alpha1_im == 0.0) { D->data[j + D->size[0] * j].re = alpha1_re / absxk; D->data[j + D->size[0] * j].im = 0.0; } else if (alpha1_re == 0.0) { D->data[j + D->size[0] * j].re = 0.0; D->data[j + D->size[0] * j].im = alpha1_im / absxk; } else { D->data[j + D->size[0] * j].re = alpha1_re / absxk; D->data[j + D->size[0] * j].im = alpha1_im / absxk; } } else if (absxk == 0.0) { if (alpha1_re == 0.0) { D->data[j + D->size[0] * j].re = alpha1_im / t; D->data[j + D->size[0] * j].im = 0.0; } else if (alpha1_im == 0.0) { D->data[j + D->size[0] * j].re = 0.0; D->data[j + D->size[0] * j].im = -(alpha1_re / t); } else { D->data[j + D->size[0] * j].re = alpha1_im / t; D->data[j + D->size[0] * j].im = -(alpha1_re / t); } } else { colnorm = fabs(absxk); scale = fabs(t); if (colnorm > scale) { scale = t / absxk; absxk += scale * t; D->data[j + D->size[0] * j].re = (alpha1_re + scale * alpha1_im) / absxk; D->data[j + D->size[0] * j].im = (alpha1_im - scale * alpha1_re) / absxk; } else if (scale == colnorm) { if (absxk > 0.0) { absxk = 0.5; } else { absxk = -0.5; } if (t > 0.0) { scale = 0.5; } else { scale = -0.5; } D->data[j + D->size[0] * j].re = (alpha1_re * absxk + alpha1_im * scale) / colnorm; D->data[j + D->size[0] * j].im = (alpha1_im * absxk - alpha1_re * scale) / colnorm; } else { scale = absxk / t; absxk = t + scale * absxk; D->data[j + D->size[0] * j].re = (scale * alpha1_re + alpha1_im) / absxk; D->data[j + D->size[0] * j].im = (scale * alpha1_im - alpha1_re) / absxk; } } } emxFree_creal_T(&beta1); emxFree_creal_T(&alpha1); } /* * Arguments : emxArray_creal_T *A * int *ilo * int *ihi * emxArray_int32_T *rscale * Return Type : void */ static void eml_matlab_zggbal(emxArray_creal_T *A, int *ilo, int *ihi, emxArray_int32_T *rscale) { int jj; int loop_ub; emxArray_creal_T *b_A; int32_T exitg2; int i; int j; boolean_T found; int ii; boolean_T exitg5; int nzcount; boolean_T exitg6; boolean_T c_A; boolean_T guard2 = false; double atmp_re; double atmp_im; int32_T exitg1; boolean_T exitg3; boolean_T exitg4; boolean_T guard1 = false; jj = rscale->size[0]; rscale->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)rscale, jj, (int)sizeof(int)); loop_ub = A->size[0]; for (jj = 0; jj < loop_ub; jj++) { rscale->data[jj] = 0; } *ilo = 1; *ihi = A->size[0]; if (A->size[0] <= 1) { *ihi = 1; rscale->data[0] = 1; } else { emxInit_creal_T(&b_A, 2); do { exitg2 = 0; i = 0; j = 0; found = false; ii = *ihi; exitg5 = false; while ((!exitg5) && (ii > 0)) { nzcount = 0; i = ii; j = *ihi; jj = 1; exitg6 = false; while ((!exitg6) && (jj <= *ihi)) { c_A = ((A->data[(ii + A->size[0] * (jj - 1)) - 1].re != 0.0) || (A->data[(ii + A->size[0] * (jj - 1)) - 1].im != 0.0)); guard2 = false; if (c_A || (ii == jj)) { if (nzcount == 0) { j = jj; nzcount = 1; guard2 = true; } else { nzcount = 2; exitg6 = true; } } else { guard2 = true; } if (guard2) { jj++; } } if (nzcount < 2) { found = true; exitg5 = true; } else { ii--; } } if (!found) { exitg2 = 2; } else { jj = b_A->size[0] * b_A->size[1]; b_A->size[0] = A->size[0]; b_A->size[1] = A->size[1]; emxEnsureCapacity((emxArray__common *)b_A, jj, (int)sizeof(creal_T)); loop_ub = A->size[0] * A->size[1]; for (jj = 0; jj < loop_ub; jj++) { b_A->data[jj] = A->data[jj]; } if (i != *ihi) { for (ii = 0; ii + 1 <= A->size[0]; ii++) { atmp_re = b_A->data[(i + b_A->size[0] * ii) - 1].re; atmp_im = b_A->data[(i + b_A->size[0] * ii) - 1].im; b_A->data[(i + b_A->size[0] * ii) - 1] = b_A->data[(*ihi + b_A-> size[0] * ii) - 1]; b_A->data[(*ihi + b_A->size[0] * ii) - 1].re = atmp_re; b_A->data[(*ihi + b_A->size[0] * ii) - 1].im = atmp_im; } } if (j != *ihi) { for (ii = 0; ii + 1 <= *ihi; ii++) { atmp_re = b_A->data[ii + b_A->size[0] * (j - 1)].re; atmp_im = b_A->data[ii + b_A->size[0] * (j - 1)].im; b_A->data[ii + b_A->size[0] * (j - 1)] = b_A->data[ii + b_A->size[0] * (*ihi - 1)]; b_A->data[ii + b_A->size[0] * (*ihi - 1)].re = atmp_re; b_A->data[ii + b_A->size[0] * (*ihi - 1)].im = atmp_im; } } jj = A->size[0] * A->size[1]; A->size[0] = b_A->size[0]; A->size[1] = b_A->size[1]; emxEnsureCapacity((emxArray__common *)A, jj, (int)sizeof(creal_T)); loop_ub = b_A->size[1]; for (jj = 0; jj < loop_ub; jj++) { ii = b_A->size[0]; for (nzcount = 0; nzcount < ii; nzcount++) { A->data[nzcount + A->size[0] * jj] = b_A->data[nzcount + b_A->size[0] * jj]; } } rscale->data[*ihi - 1] = j; (*ihi)--; if (*ihi == 1) { rscale->data[0] = 1; exitg2 = 1; } } } while (exitg2 == 0); if (exitg2 == 1) { } else { do { exitg1 = 0; i = 0; j = 0; found = false; jj = *ilo; exitg3 = false; while ((!exitg3) && (jj <= *ihi)) { nzcount = 0; i = *ihi; j = jj; ii = *ilo; exitg4 = false; while ((!exitg4) && (ii <= *ihi)) { c_A = ((A->data[(ii + A->size[0] * (jj - 1)) - 1].re != 0.0) || (A->data[(ii + A->size[0] * (jj - 1)) - 1].im != 0.0)); guard1 = false; if (c_A || (ii == jj)) { if (nzcount == 0) { i = ii; nzcount = 1; guard1 = true; } else { nzcount = 2; exitg4 = true; } } else { guard1 = true; } if (guard1) { ii++; } } if (nzcount < 2) { found = true; exitg3 = true; } else { jj++; } } if (!found) { exitg1 = 1; } else { jj = b_A->size[0] * b_A->size[1]; b_A->size[0] = A->size[0]; b_A->size[1] = A->size[1]; emxEnsureCapacity((emxArray__common *)b_A, jj, (int)sizeof(creal_T)); loop_ub = A->size[0] * A->size[1]; for (jj = 0; jj < loop_ub; jj++) { b_A->data[jj] = A->data[jj]; } if (i != *ilo) { for (ii = *ilo - 1; ii + 1 <= A->size[0]; ii++) { atmp_re = b_A->data[(i + b_A->size[0] * ii) - 1].re; atmp_im = b_A->data[(i + b_A->size[0] * ii) - 1].im; b_A->data[(i + b_A->size[0] * ii) - 1] = b_A->data[(*ilo + b_A->size[0] * ii) - 1]; b_A->data[(*ilo + b_A->size[0] * ii) - 1].re = atmp_re; b_A->data[(*ilo + b_A->size[0] * ii) - 1].im = atmp_im; } } if (j != *ilo) { for (ii = 0; ii + 1 <= *ihi; ii++) { atmp_re = b_A->data[ii + b_A->size[0] * (j - 1)].re; atmp_im = b_A->data[ii + b_A->size[0] * (j - 1)].im; b_A->data[ii + b_A->size[0] * (j - 1)] = b_A->data[ii + b_A->size [0] * (*ilo - 1)]; b_A->data[ii + b_A->size[0] * (*ilo - 1)].re = atmp_re; b_A->data[ii + b_A->size[0] * (*ilo - 1)].im = atmp_im; } } jj = A->size[0] * A->size[1]; A->size[0] = b_A->size[0]; A->size[1] = b_A->size[1]; emxEnsureCapacity((emxArray__common *)A, jj, (int)sizeof(creal_T)); loop_ub = b_A->size[1]; for (jj = 0; jj < loop_ub; jj++) { ii = b_A->size[0]; for (nzcount = 0; nzcount < ii; nzcount++) { A->data[nzcount + A->size[0] * jj] = b_A->data[nzcount + b_A-> size[0] * jj]; } } rscale->data[*ilo - 1] = j; (*ilo)++; if (*ilo == *ihi) { rscale->data[*ilo - 1] = *ilo; exitg1 = 1; } } } while (exitg1 == 0); } emxFree_creal_T(&b_A); } } /* * Arguments : emxArray_creal_T *A * int *info * emxArray_creal_T *alpha1 * emxArray_creal_T *beta1 * emxArray_creal_T *V * Return Type : void */ static void eml_matlab_zggev(emxArray_creal_T *A, int *info, emxArray_creal_T *alpha1, emxArray_creal_T *beta1, emxArray_creal_T *V) { int n; int m; int jrow; int jcol; double anrm; boolean_T exitg1; double absxk; boolean_T ilascl; double anrmto; double ctoc; boolean_T notdone; double cfrom1; double cto1; double stemp_im; emxArray_creal_T *b_A; emxArray_int32_T *rscale; emxArray_real_T *I; int ihi; int ilo; int b_n; creal_T c_A; creal_T d_A; creal_T tmp; double c; int j; double stemp_re; int i; *info = 0; n = A->size[0]; m = alpha1->size[0]; alpha1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)alpha1, m, (int)sizeof(creal_T)); jrow = A->size[0]; for (m = 0; m < jrow; m++) { alpha1->data[m].re = 0.0; alpha1->data[m].im = 0.0; } m = beta1->size[0]; beta1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)beta1, m, (int)sizeof(creal_T)); jrow = A->size[0]; for (m = 0; m < jrow; m++) { beta1->data[m].re = 0.0; beta1->data[m].im = 0.0; } jcol = A->size[0]; m = V->size[0] * V->size[1]; V->size[0] = jcol; emxEnsureCapacity((emxArray__common *)V, m, (int)sizeof(creal_T)); jcol = A->size[0]; m = V->size[0] * V->size[1]; V->size[1] = jcol; emxEnsureCapacity((emxArray__common *)V, m, (int)sizeof(creal_T)); jrow = A->size[0] * A->size[0]; for (m = 0; m < jrow; m++) { V->data[m].re = 0.0; V->data[m].im = 0.0; } if ((A->size[0] == 0) || (A->size[1] == 0)) { } else { anrm = 0.0; jcol = 0; exitg1 = false; while ((!exitg1) && (jcol <= A->size[0] * A->size[1] - 1)) { absxk = rt_hypotd_snf(A->data[jcol].re, A->data[jcol].im); if (rtIsNaN(absxk)) { anrm = rtNaN; exitg1 = true; } else { if (absxk > anrm) { anrm = absxk; } jcol++; } } if (!((!rtIsInf(anrm)) && (!rtIsNaN(anrm)))) { m = alpha1->size[0]; alpha1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)alpha1, m, (int)sizeof(creal_T)); jrow = A->size[0]; for (m = 0; m < jrow; m++) { alpha1->data[m].re = rtNaN; alpha1->data[m].im = 0.0; } m = beta1->size[0]; beta1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)beta1, m, (int)sizeof(creal_T)); jrow = A->size[0]; for (m = 0; m < jrow; m++) { beta1->data[m].re = rtNaN; beta1->data[m].im = 0.0; } jcol = A->size[0]; m = V->size[0] * V->size[1]; V->size[0] = jcol; emxEnsureCapacity((emxArray__common *)V, m, (int)sizeof(creal_T)); jcol = A->size[0]; m = V->size[0] * V->size[1]; V->size[1] = jcol; emxEnsureCapacity((emxArray__common *)V, m, (int)sizeof(creal_T)); jrow = A->size[0] * A->size[0]; for (m = 0; m < jrow; m++) { V->data[m].re = rtNaN; V->data[m].im = 0.0; } } else { ilascl = false; anrmto = anrm; if ((anrm > 0.0) && (anrm < 6.7178761075670888E-139)) { anrmto = 6.7178761075670888E-139; ilascl = true; } else { if (anrm > 1.4885657073574029E+138) { anrmto = 1.4885657073574029E+138; ilascl = true; } } if (ilascl) { absxk = anrm; ctoc = anrmto; notdone = true; while (notdone) { cfrom1 = absxk * 2.0041683600089728E-292; cto1 = ctoc / 4.9896007738368E+291; if ((cfrom1 > ctoc) && (ctoc != 0.0)) { stemp_im = 2.0041683600089728E-292; absxk = cfrom1; } else if (cto1 > absxk) { stemp_im = 4.9896007738368E+291; ctoc = cto1; } else { stemp_im = ctoc / absxk; notdone = false; } m = A->size[0] * A->size[1]; emxEnsureCapacity((emxArray__common *)A, m, (int)sizeof(creal_T)); jcol = A->size[0]; jrow = A->size[1]; jrow *= jcol; for (m = 0; m < jrow; m++) { A->data[m].re *= stemp_im; A->data[m].im *= stemp_im; } } } emxInit_creal_T(&b_A, 2); m = b_A->size[0] * b_A->size[1]; b_A->size[0] = A->size[0]; b_A->size[1] = A->size[1]; emxEnsureCapacity((emxArray__common *)b_A, m, (int)sizeof(creal_T)); jrow = A->size[0] * A->size[1]; for (m = 0; m < jrow; m++) { b_A->data[m] = A->data[m]; } b_emxInit_int32_T(&rscale, 1); b_emxInit_real_T(&I, 2); eml_matlab_zggbal(b_A, &ilo, &ihi, rscale); b_n = b_A->size[0]; jcol = b_A->size[0]; m = I->size[0] * I->size[1]; I->size[0] = jcol; emxEnsureCapacity((emxArray__common *)I, m, (int)sizeof(double)); jcol = b_A->size[0]; m = I->size[0] * I->size[1]; I->size[1] = jcol; emxEnsureCapacity((emxArray__common *)I, m, (int)sizeof(double)); jrow = b_A->size[0] * b_A->size[0]; for (m = 0; m < jrow; m++) { I->data[m] = 0.0; } if (b_A->size[0] > 0) { for (jcol = 0; jcol + 1 <= b_n; jcol++) { I->data[jcol + I->size[0] * jcol] = 1.0; } } m = V->size[0] * V->size[1]; V->size[0] = I->size[0]; V->size[1] = I->size[1]; emxEnsureCapacity((emxArray__common *)V, m, (int)sizeof(creal_T)); jrow = I->size[0] * I->size[1]; for (m = 0; m < jrow; m++) { V->data[m].re = I->data[m]; V->data[m].im = 0.0; } emxFree_real_T(&I); if ((b_A->size[0] <= 1) || (ihi < ilo + 2)) { } else { for (jcol = ilo - 1; jcol + 1 < ihi - 1; jcol++) { for (jrow = ihi - 1; jrow + 1 > jcol + 2; jrow--) { c_A = b_A->data[(jrow + b_A->size[0] * jcol) - 1]; d_A = b_A->data[jrow + b_A->size[0] * jcol]; eml_matlab_zlartg(c_A, d_A, &c, &tmp, &b_A->data[(jrow + b_A->size[0] * jcol) - 1]); b_A->data[jrow + b_A->size[0] * jcol].re = 0.0; b_A->data[jrow + b_A->size[0] * jcol].im = 0.0; for (j = jcol + 1; j + 1 <= ihi; j++) { absxk = tmp.re * b_A->data[jrow + b_A->size[0] * j].re - tmp.im * b_A->data[jrow + b_A->size[0] * j].im; ctoc = tmp.re * b_A->data[jrow + b_A->size[0] * j].im + tmp.im * b_A->data[jrow + b_A->size[0] * j].re; stemp_re = c * b_A->data[(jrow + b_A->size[0] * j) - 1].re + absxk; stemp_im = c * b_A->data[(jrow + b_A->size[0] * j) - 1].im + ctoc; absxk = b_A->data[(jrow + b_A->size[0] * j) - 1].re; ctoc = b_A->data[(jrow + b_A->size[0] * j) - 1].im; cfrom1 = b_A->data[(jrow + b_A->size[0] * j) - 1].im; cto1 = b_A->data[(jrow + b_A->size[0] * j) - 1].re; b_A->data[jrow + b_A->size[0] * j].re = c * b_A->data[jrow + b_A->size[0] * j].re - (tmp.re * absxk + tmp.im * ctoc); b_A->data[jrow + b_A->size[0] * j].im = c * b_A->data[jrow + b_A->size[0] * j].im - (tmp.re * cfrom1 - tmp.im * cto1); b_A->data[(jrow + b_A->size[0] * j) - 1].re = stemp_re; b_A->data[(jrow + b_A->size[0] * j) - 1].im = stemp_im; } tmp.re = -tmp.re; tmp.im = -tmp.im; for (i = ilo - 1; i + 1 <= ihi; i++) { absxk = tmp.re * b_A->data[i + b_A->size[0] * (jrow - 1)].re - tmp.im * b_A->data[i + b_A->size[0] * (jrow - 1)].im; ctoc = tmp.re * b_A->data[i + b_A->size[0] * (jrow - 1)].im + tmp.im * b_A->data[i + b_A->size[0] * (jrow - 1)].re; stemp_re = c * b_A->data[i + b_A->size[0] * jrow].re + absxk; stemp_im = c * b_A->data[i + b_A->size[0] * jrow].im + ctoc; absxk = b_A->data[i + b_A->size[0] * jrow].re; ctoc = b_A->data[i + b_A->size[0] * jrow].im; cfrom1 = b_A->data[i + b_A->size[0] * jrow].im; cto1 = b_A->data[i + b_A->size[0] * jrow].re; b_A->data[i + b_A->size[0] * (jrow - 1)].re = c * b_A->data[i + b_A->size[0] * (jrow - 1)].re - (tmp.re * absxk + tmp.im * ctoc); b_A->data[i + b_A->size[0] * (jrow - 1)].im = c * b_A->data[i + b_A->size[0] * (jrow - 1)].im - (tmp.re * cfrom1 - tmp.im * cto1); b_A->data[i + b_A->size[0] * jrow].re = stemp_re; b_A->data[i + b_A->size[0] * jrow].im = stemp_im; } for (i = 0; i + 1 <= b_n; i++) { absxk = tmp.re * V->data[i + V->size[0] * (jrow - 1)].re - tmp.im * V->data[i + V->size[0] * (jrow - 1)].im; ctoc = tmp.re * V->data[i + V->size[0] * (jrow - 1)].im + tmp.im * V->data[i + V->size[0] * (jrow - 1)].re; stemp_re = c * V->data[i + V->size[0] * jrow].re + absxk; stemp_im = c * V->data[i + V->size[0] * jrow].im + ctoc; absxk = V->data[i + V->size[0] * jrow].re; ctoc = V->data[i + V->size[0] * jrow].im; cfrom1 = V->data[i + V->size[0] * jrow].im; cto1 = V->data[i + V->size[0] * jrow].re; V->data[i + V->size[0] * (jrow - 1)].re = c * V->data[i + V->size [0] * (jrow - 1)].re - (tmp.re * absxk + tmp.im * ctoc); V->data[i + V->size[0] * (jrow - 1)].im = c * V->data[i + V->size [0] * (jrow - 1)].im - (tmp.re * cfrom1 - tmp.im * cto1); V->data[i + V->size[0] * jrow].re = stemp_re; V->data[i + V->size[0] * jrow].im = stemp_im; } } } } eml_matlab_zhgeqz(b_A, ilo, ihi, V, &jcol, alpha1, beta1); *info = jcol; if (jcol != 0) { } else { eml_matlab_ztgevc(b_A, V); b_n = V->size[0]; m = V->size[1]; if (ilo > 1) { for (i = ilo - 2; i + 1 >= 1; i--) { jcol = rscale->data[i] - 1; if (rscale->data[i] != i + 1) { for (j = 0; j + 1 <= m; j++) { tmp = V->data[i + V->size[0] * j]; V->data[i + V->size[0] * j] = V->data[jcol + V->size[0] * j]; V->data[jcol + V->size[0] * j] = tmp; } } } } if (ihi < b_n) { while (ihi + 1 <= b_n) { jcol = rscale->data[ihi] - 1; if (rscale->data[ihi] != ihi + 1) { for (j = 0; j + 1 <= m; j++) { tmp = V->data[ihi + V->size[0] * j]; V->data[ihi + V->size[0] * j] = V->data[jcol + V->size[0] * j]; V->data[jcol + V->size[0] * j] = tmp; } } ihi++; } } for (jcol = 0; jcol < n; jcol++) { absxk = fabs(V->data[V->size[0] * jcol].re) + fabs(V->data[V->size[0] * jcol].im); if (n > 1) { for (jrow = 1; jrow - 1 <= n - 2; jrow++) { ctoc = fabs(V->data[jrow + V->size[0] * jcol].re) + fabs(V-> data[jrow + V->size[0] * jcol].im); if (ctoc > absxk) { absxk = ctoc; } } } if (absxk >= 6.7178761075670888E-139) { absxk = 1.0 / absxk; for (jrow = 0; jrow < n; jrow++) { V->data[jrow + V->size[0] * jcol].re *= absxk; V->data[jrow + V->size[0] * jcol].im *= absxk; } } } if (ilascl) { notdone = true; while (notdone) { cfrom1 = anrmto * 2.0041683600089728E-292; cto1 = anrm / 4.9896007738368E+291; if ((cfrom1 > anrm) && (anrm != 0.0)) { stemp_im = 2.0041683600089728E-292; anrmto = cfrom1; } else if (cto1 > anrmto) { stemp_im = 4.9896007738368E+291; anrm = cto1; } else { stemp_im = anrm / anrmto; notdone = false; } m = alpha1->size[0]; emxEnsureCapacity((emxArray__common *)alpha1, m, (int)sizeof(creal_T)); jrow = alpha1->size[0]; for (m = 0; m < jrow; m++) { alpha1->data[m].re *= stemp_im; alpha1->data[m].im *= stemp_im; } } } } emxFree_int32_T(&rscale); emxFree_creal_T(&b_A); } } } /* * Arguments : emxArray_creal_T *A * int ilo * int ihi * emxArray_creal_T *Z * int *info * emxArray_creal_T *alpha1 * emxArray_creal_T *beta1 * Return Type : void */ static void eml_matlab_zhgeqz(emxArray_creal_T *A, int ilo, int ihi, emxArray_creal_T *Z, int *info, emxArray_creal_T *alpha1, emxArray_creal_T *beta1) { boolean_T b3; int n; int x; int j; double eshift_re; double eshift_im; creal_T ctemp; double rho_re; double rho_im; double anorm; double sumsq; boolean_T firstNonZero; int b_j; int jp1; double reAij; double imAij; double temp1; double temp2; double b_atol; double ascale; boolean_T failed; boolean_T guard1 = false; boolean_T guard2 = false; int ifirst; int istart; int ilast; int ilastm1; int ifrstm; int ilastm; int iiter; boolean_T goto60; boolean_T goto70; boolean_T goto90; int jiter; int32_T exitg1; boolean_T exitg3; int jm1; boolean_T b_guard1 = false; creal_T t1; creal_T d; double sigma2_im; boolean_T exitg2; creal_T b_A; creal_T c_A; *info = 0; b3 = !((Z->size[0] == 0) || (Z->size[1] == 0)); if ((A->size[0] == 1) && (A->size[1] == 1)) { ihi = 1; } n = A->size[0]; x = alpha1->size[0]; alpha1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)alpha1, x, (int)sizeof(creal_T)); j = A->size[0]; for (x = 0; x < j; x++) { alpha1->data[x].re = 0.0; alpha1->data[x].im = 0.0; } x = beta1->size[0]; beta1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)beta1, x, (int)sizeof(creal_T)); j = A->size[0]; for (x = 0; x < j; x++) { beta1->data[x].re = 1.0; beta1->data[x].im = 0.0; } eshift_re = 0.0; eshift_im = 0.0; ctemp.re = 0.0; ctemp.im = 0.0; rho_re = 0.0; rho_im = 0.0; anorm = 0.0; if (ilo > ihi) { } else { anorm = 0.0; sumsq = 0.0; firstNonZero = true; for (b_j = ilo; b_j <= ihi; b_j++) { x = b_j + 1; if (ihi < b_j + 1) { x = ihi; } for (jp1 = ilo; jp1 <= x; jp1++) { reAij = A->data[(jp1 + A->size[0] * (b_j - 1)) - 1].re; imAij = A->data[(jp1 + A->size[0] * (b_j - 1)) - 1].im; if (reAij != 0.0) { temp1 = fabs(reAij); if (firstNonZero) { sumsq = 1.0; anorm = temp1; firstNonZero = false; } else if (anorm < temp1) { temp2 = anorm / temp1; sumsq = 1.0 + sumsq * temp2 * temp2; anorm = temp1; } else { temp2 = temp1 / anorm; sumsq += temp2 * temp2; } } if (imAij != 0.0) { temp1 = fabs(imAij); if (firstNonZero) { sumsq = 1.0; anorm = temp1; firstNonZero = false; } else if (anorm < temp1) { temp2 = anorm / temp1; sumsq = 1.0 + sumsq * temp2 * temp2; anorm = temp1; } else { temp2 = temp1 / anorm; sumsq += temp2 * temp2; } } } } anorm *= sqrt(sumsq); } reAij = 2.2204460492503131E-16 * anorm; b_atol = 2.2250738585072014E-308; if (reAij > 2.2250738585072014E-308) { b_atol = reAij; } temp1 = 2.2250738585072014E-308; if (anorm > 2.2250738585072014E-308) { temp1 = anorm; } ascale = 1.0 / temp1; failed = true; for (b_j = ihi; b_j + 1 <= n; b_j++) { alpha1->data[b_j] = A->data[b_j + A->size[0] * b_j]; } guard1 = false; guard2 = false; if (ihi >= ilo) { ifirst = ilo; istart = ilo; ilast = ihi - 1; ilastm1 = ihi - 2; if (b3) { ifrstm = 1; ilastm = n; } else { ifrstm = ilo; ilastm = ihi; } iiter = 0; goto60 = false; goto70 = false; goto90 = false; jiter = 1; do { exitg1 = 0; if (jiter <= 30 * ((ihi - ilo) + 1)) { if (ilast + 1 == ilo) { goto60 = true; } else if (fabs(A->data[ilast + A->size[0] * ilastm1].re) + fabs(A-> data[ilast + A->size[0] * ilastm1].im) <= b_atol) { A->data[ilast + A->size[0] * ilastm1].re = 0.0; A->data[ilast + A->size[0] * ilastm1].im = 0.0; goto60 = true; } else { b_j = ilastm1; exitg3 = false; while ((!exitg3) && (b_j + 1 >= ilo)) { if (b_j + 1 == ilo) { firstNonZero = true; } else if (fabs(A->data[b_j + A->size[0] * (b_j - 1)].re) + fabs (A->data[b_j + A->size[0] * (b_j - 1)].im) <= b_atol) { A->data[b_j + A->size[0] * (b_j - 1)].re = 0.0; A->data[b_j + A->size[0] * (b_j - 1)].im = 0.0; firstNonZero = true; } else { firstNonZero = false; } if (firstNonZero) { ifirst = b_j + 1; goto70 = true; exitg3 = true; } else { b_j--; } } } if (goto60 || goto70) { firstNonZero = true; } else { firstNonZero = false; } if (!firstNonZero) { jp1 = alpha1->size[0]; x = alpha1->size[0]; alpha1->size[0] = jp1; emxEnsureCapacity((emxArray__common *)alpha1, x, (int)sizeof(creal_T)); for (x = 0; x < jp1; x++) { alpha1->data[x].re = rtNaN; alpha1->data[x].im = 0.0; } jp1 = beta1->size[0]; x = beta1->size[0]; beta1->size[0] = jp1; emxEnsureCapacity((emxArray__common *)beta1, x, (int)sizeof(creal_T)); for (x = 0; x < jp1; x++) { beta1->data[x].re = rtNaN; beta1->data[x].im = 0.0; } if (b3) { x = Z->size[0] * Z->size[1]; emxEnsureCapacity((emxArray__common *)Z, x, (int)sizeof(creal_T)); j = Z->size[1]; for (x = 0; x < j; x++) { jp1 = Z->size[0]; for (jm1 = 0; jm1 < jp1; jm1++) { Z->data[jm1 + Z->size[0] * x].re = rtNaN; Z->data[jm1 + Z->size[0] * x].im = 0.0; } } } *info = 1; exitg1 = 1; } else { b_guard1 = false; if (goto60) { goto60 = false; alpha1->data[ilast] = A->data[ilast + A->size[0] * ilast]; ilast = ilastm1; ilastm1--; if (ilast + 1 < ilo) { failed = false; guard2 = true; exitg1 = 1; } else { iiter = 0; eshift_re = 0.0; eshift_im = 0.0; if (!b3) { ilastm = ilast + 1; if (ifrstm > ilast + 1) { ifrstm = ilo; } } b_guard1 = true; } } else { if (goto70) { goto70 = false; iiter++; if (!b3) { ifrstm = ifirst; } if (iiter - iiter / 10 * 10 != 0) { reAij = -(A->data[ilast + A->size[0] * ilast].re - A-> data[ilastm1 + A->size[0] * ilastm1].re); temp1 = -(A->data[ilast + A->size[0] * ilast].im - A-> data[ilastm1 + A->size[0] * ilastm1].im); if (temp1 == 0.0) { t1.re = reAij / 2.0; t1.im = 0.0; } else if (reAij == 0.0) { t1.re = 0.0; t1.im = temp1 / 2.0; } else { t1.re = reAij / 2.0; t1.im = temp1 / 2.0; } anorm = A->data[ilastm1 + A->size[0] * ilast].re * A->data[ilast + A->size[0] * ilastm1].re - A->data[ilastm1 + A->size[0] * ilast].im * A->data[ilast + A->size[0] * ilastm1].im; reAij = A->data[ilastm1 + A->size[0] * ilast].re * A->data[ilast + A->size[0] * ilastm1].im + A->data[ilastm1 + A->size[0] * ilast].im * A->data[ilast + A->size[0] * ilastm1].re; d.re = (t1.re * t1.re - t1.im * t1.im) + anorm; d.im = (t1.re * t1.im + t1.im * t1.re) + reAij; c_sqrt(&d); rho_re = A->data[ilastm1 + A->size[0] * ilastm1].re - (t1.re - d.re); rho_im = A->data[ilastm1 + A->size[0] * ilastm1].im - (t1.im - d.im); imAij = A->data[ilastm1 + A->size[0] * ilastm1].re - (t1.re + d.re); sigma2_im = A->data[ilastm1 + A->size[0] * ilastm1].im - (t1.im + d.im); anorm = rho_re - A->data[ilast + A->size[0] * ilast].re; reAij = rho_im - A->data[ilast + A->size[0] * ilast].im; temp1 = imAij - A->data[ilast + A->size[0] * ilast].re; sumsq = sigma2_im - A->data[ilast + A->size[0] * ilast].im; if (rt_hypotd_snf(anorm, reAij) <= rt_hypotd_snf(temp1, sumsq)) { imAij = rho_re; sigma2_im = rho_im; rho_re = t1.re - d.re; rho_im = t1.im - d.im; } else { rho_re = t1.re + d.re; rho_im = t1.im + d.im; } } else { eshift_re += A->data[ilast + A->size[0] * ilastm1].re; eshift_im += A->data[ilast + A->size[0] * ilastm1].im; imAij = eshift_re; sigma2_im = eshift_im; } b_j = ilastm1; jp1 = ilastm1 + 1; exitg2 = false; while ((!exitg2) && (b_j + 1 > ifirst)) { istart = b_j + 1; ctemp.re = A->data[b_j + A->size[0] * b_j].re - imAij; ctemp.im = A->data[b_j + A->size[0] * b_j].im - sigma2_im; anorm = ascale * (fabs(ctemp.re) + fabs(ctemp.im)); temp2 = ascale * (fabs(A->data[jp1 + A->size[0] * b_j].re) + fabs(A->data[jp1 + A->size[0] * b_j].im)); reAij = anorm; if (temp2 > anorm) { reAij = temp2; } if ((reAij < 1.0) && (reAij != 0.0)) { anorm /= reAij; temp2 /= reAij; } if ((fabs(A->data[b_j + A->size[0] * (b_j - 1)].re) + fabs (A->data[b_j + A->size[0] * (b_j - 1)].im)) * temp2 <= anorm * b_atol) { goto90 = true; exitg2 = true; } else { jp1 = b_j; b_j--; } } if (!goto90) { istart = ifirst; if (ifirst == ilastm1 + 1) { ctemp.re = rho_re; ctemp.im = rho_im; } else { ctemp.re = A->data[(ifirst + A->size[0] * (ifirst - 1)) - 1]. re - imAij; ctemp.im = A->data[(ifirst + A->size[0] * (ifirst - 1)) - 1]. im - sigma2_im; } goto90 = true; } } if (goto90) { goto90 = false; b_A = A->data[istart + A->size[0] * (istart - 1)]; b_eml_matlab_zlartg(ctemp, b_A, &imAij, &t1); b_j = istart; jm1 = istart - 2; while (b_j < ilast + 1) { if (b_j > istart) { b_A = A->data[(b_j + A->size[0] * jm1) - 1]; c_A = A->data[b_j + A->size[0] * jm1]; eml_matlab_zlartg(b_A, c_A, &imAij, &t1, &A->data[(b_j + A->size[0] * jm1) - 1]); A->data[b_j + A->size[0] * jm1].re = 0.0; A->data[b_j + A->size[0] * jm1].im = 0.0; } for (j = b_j - 1; j + 1 <= ilastm; j++) { anorm = t1.re * A->data[b_j + A->size[0] * j].re - t1.im * A->data[b_j + A->size[0] * j].im; reAij = t1.re * A->data[b_j + A->size[0] * j].im + t1.im * A->data[b_j + A->size[0] * j].re; d.re = imAij * A->data[(b_j + A->size[0] * j) - 1].re + anorm; d.im = imAij * A->data[(b_j + A->size[0] * j) - 1].im + reAij; anorm = A->data[(b_j + A->size[0] * j) - 1].re; reAij = A->data[(b_j + A->size[0] * j) - 1].im; temp1 = A->data[(b_j + A->size[0] * j) - 1].im; sumsq = A->data[(b_j + A->size[0] * j) - 1].re; A->data[b_j + A->size[0] * j].re = imAij * A->data[b_j + A->size[0] * j].re - (t1.re * anorm + t1.im * reAij); A->data[b_j + A->size[0] * j].im = imAij * A->data[b_j + A->size[0] * j].im - (t1.re * temp1 - t1.im * sumsq); A->data[(b_j + A->size[0] * j) - 1] = d; } t1.re = -t1.re; t1.im = -t1.im; x = b_j; if (ilast + 1 < b_j + 2) { x = ilast - 1; } for (jp1 = ifrstm - 1; jp1 + 1 <= x + 2; jp1++) { anorm = t1.re * A->data[jp1 + A->size[0] * (b_j - 1)].re - t1.im * A->data[jp1 + A->size[0] * (b_j - 1)].im; reAij = t1.re * A->data[jp1 + A->size[0] * (b_j - 1)].im + t1.im * A->data[jp1 + A->size[0] * (b_j - 1)].re; d.re = imAij * A->data[jp1 + A->size[0] * b_j].re + anorm; d.im = imAij * A->data[jp1 + A->size[0] * b_j].im + reAij; anorm = A->data[jp1 + A->size[0] * b_j].re; reAij = A->data[jp1 + A->size[0] * b_j].im; temp1 = A->data[jp1 + A->size[0] * b_j].im; sumsq = A->data[jp1 + A->size[0] * b_j].re; A->data[jp1 + A->size[0] * (b_j - 1)].re = imAij * A->data[jp1 + A->size[0] * (b_j - 1)].re - (t1.re * anorm + t1.im * reAij); A->data[jp1 + A->size[0] * (b_j - 1)].im = imAij * A->data[jp1 + A->size[0] * (b_j - 1)].im - (t1.re * temp1 - t1.im * sumsq); A->data[jp1 + A->size[0] * b_j] = d; } if (b3) { for (jp1 = 0; jp1 + 1 <= n; jp1++) { anorm = t1.re * Z->data[jp1 + Z->size[0] * (b_j - 1)].re - t1.im * Z->data[jp1 + Z->size[0] * (b_j - 1)].im; reAij = t1.re * Z->data[jp1 + Z->size[0] * (b_j - 1)].im + t1.im * Z->data[jp1 + Z->size[0] * (b_j - 1)].re; d.re = imAij * Z->data[jp1 + Z->size[0] * b_j].re + anorm; d.im = imAij * Z->data[jp1 + Z->size[0] * b_j].im + reAij; anorm = Z->data[jp1 + Z->size[0] * b_j].re; reAij = Z->data[jp1 + Z->size[0] * b_j].im; temp1 = Z->data[jp1 + Z->size[0] * b_j].im; sumsq = Z->data[jp1 + Z->size[0] * b_j].re; Z->data[jp1 + Z->size[0] * (b_j - 1)].re = imAij * Z-> data[jp1 + Z->size[0] * (b_j - 1)].re - (t1.re * anorm + t1.im * reAij); Z->data[jp1 + Z->size[0] * (b_j - 1)].im = imAij * Z-> data[jp1 + Z->size[0] * (b_j - 1)].im - (t1.re * temp1 - t1.im * sumsq); Z->data[jp1 + Z->size[0] * b_j] = d; } } jm1 = b_j - 1; b_j++; } } b_guard1 = true; } if (b_guard1) { jiter++; } } } else { guard2 = true; exitg1 = 1; } } while (exitg1 == 0); } else { guard1 = true; } if (guard2) { if (failed) { *info = ilast + 1; for (jp1 = 0; jp1 + 1 <= ilast + 1; jp1++) { alpha1->data[jp1].re = rtNaN; alpha1->data[jp1].im = 0.0; beta1->data[jp1].re = rtNaN; beta1->data[jp1].im = 0.0; } if (b3) { x = Z->size[0] * Z->size[1]; emxEnsureCapacity((emxArray__common *)Z, x, (int)sizeof(creal_T)); j = Z->size[1]; for (x = 0; x < j; x++) { jp1 = Z->size[0]; for (jm1 = 0; jm1 < jp1; jm1++) { Z->data[jm1 + Z->size[0] * x].re = rtNaN; Z->data[jm1 + Z->size[0] * x].im = 0.0; } } } } else { guard1 = true; } } if (guard1) { for (b_j = 0; b_j + 1 < ilo; b_j++) { alpha1->data[b_j] = A->data[b_j + A->size[0] * b_j]; } } } /* * Arguments : const creal_T f * const creal_T g * double *cs * creal_T *sn * creal_T *r * Return Type : void */ static void eml_matlab_zlartg(const creal_T f, const creal_T g, double *cs, creal_T *sn, creal_T *r) { double scale; double f2s; double g2; double fs_re; double fs_im; double gs_re; double gs_im; int count; int rescaledir; boolean_T guard1 = false; double g2s; scale = fabs(f.re); f2s = fabs(f.im); if (f2s > scale) { scale = f2s; } f2s = fabs(g.re); g2 = fabs(g.im); if (g2 > f2s) { f2s = g2; } if (f2s > scale) { scale = f2s; } fs_re = f.re; fs_im = f.im; gs_re = g.re; gs_im = g.im; count = 0; rescaledir = 0; guard1 = false; if (scale >= 7.4428285367870146E+137) { do { count++; fs_re *= 1.3435752215134178E-138; fs_im *= 1.3435752215134178E-138; gs_re *= 1.3435752215134178E-138; gs_im *= 1.3435752215134178E-138; scale *= 1.3435752215134178E-138; } while (!(scale < 7.4428285367870146E+137)); rescaledir = 1; guard1 = true; } else if (scale <= 1.3435752215134178E-138) { if ((g.re == 0.0) && (g.im == 0.0)) { *cs = 1.0; sn->re = 0.0; sn->im = 0.0; *r = f; } else { do { count++; fs_re *= 7.4428285367870146E+137; fs_im *= 7.4428285367870146E+137; gs_re *= 7.4428285367870146E+137; gs_im *= 7.4428285367870146E+137; scale *= 7.4428285367870146E+137; } while (!(scale > 1.3435752215134178E-138)); rescaledir = -1; guard1 = true; } } else { guard1 = true; } if (guard1) { scale = fs_re * fs_re + fs_im * fs_im; g2 = gs_re * gs_re + gs_im * gs_im; f2s = g2; if (1.0 > g2) { f2s = 1.0; } if (scale <= f2s * 2.0041683600089728E-292) { if ((f.re == 0.0) && (f.im == 0.0)) { *cs = 0.0; r->re = rt_hypotd_snf(g.re, g.im); r->im = 0.0; f2s = rt_hypotd_snf(gs_re, gs_im); sn->re = gs_re / f2s; sn->im = -gs_im / f2s; } else { g2s = sqrt(g2); *cs = rt_hypotd_snf(fs_re, fs_im) / g2s; f2s = fabs(f.re); g2 = fabs(f.im); if (g2 > f2s) { f2s = g2; } if (f2s > 1.0) { f2s = rt_hypotd_snf(f.re, f.im); fs_re = f.re / f2s; fs_im = f.im / f2s; } else { g2 = 7.4428285367870146E+137 * f.re; scale = 7.4428285367870146E+137 * f.im; f2s = rt_hypotd_snf(g2, scale); fs_re = g2 / f2s; fs_im = scale / f2s; } gs_re /= g2s; gs_im = -gs_im / g2s; sn->re = fs_re * gs_re - fs_im * gs_im; sn->im = fs_re * gs_im + fs_im * gs_re; r->re = *cs * f.re + (sn->re * g.re - sn->im * g.im); r->im = *cs * f.im + (sn->re * g.im + sn->im * g.re); } } else { f2s = sqrt(1.0 + g2 / scale); r->re = f2s * fs_re; r->im = f2s * fs_im; *cs = 1.0 / f2s; f2s = scale + g2; g2 = r->re / f2s; f2s = r->im / f2s; sn->re = g2 * gs_re - f2s * -gs_im; sn->im = g2 * -gs_im + f2s * gs_re; if (rescaledir > 0) { for (rescaledir = 1; rescaledir <= count; rescaledir++) { r->re *= 7.4428285367870146E+137; r->im *= 7.4428285367870146E+137; } } else { if (rescaledir < 0) { for (rescaledir = 1; rescaledir <= count; rescaledir++) { r->re *= 1.3435752215134178E-138; r->im *= 1.3435752215134178E-138; } } } } } } /* * Arguments : const emxArray_creal_T *A * emxArray_creal_T *V * Return Type : void */ static void eml_matlab_ztgevc(const emxArray_creal_T *A, emxArray_creal_T *V) { emxArray_creal_T *work1; int n; int je; int j; emxArray_creal_T *work2; emxArray_real_T *rworka; double SMALL; double BIG; double BIGNUM; double anorm; int b_j; double y; double xmx; double ascale; int b_je; double temp; double scale; double salpha_re; double salpha_im; double acoeff; boolean_T b4; boolean_T b5; double acoefa; int jr; double dmin; double d_re; double d_im; double work1_im; b_emxInit_creal_T(&work1, 1); n = A->size[0] - 1; je = work1->size[0]; work1->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)work1, je, (int)sizeof(creal_T)); j = A->size[0]; for (je = 0; je < j; je++) { work1->data[je].re = 0.0; work1->data[je].im = 0.0; } b_emxInit_creal_T(&work2, 1); je = work2->size[0]; work2->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)work2, je, (int)sizeof(creal_T)); j = A->size[0]; for (je = 0; je < j; je++) { work2->data[je].re = 0.0; work2->data[je].im = 0.0; } emxInit_real_T(&rworka, 1); SMALL = 2.2250738585072014E-308 * (double)A->size[0] / 2.2204460492503131E-16; BIG = 1.0 / SMALL; BIGNUM = 1.0 / (2.2250738585072014E-308 * (double)A->size[0]); je = rworka->size[0]; rworka->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)rworka, je, (int)sizeof(double)); j = A->size[0]; for (je = 0; je < j; je++) { rworka->data[je] = 0.0; } anorm = fabs(A->data[0].re) + fabs(A->data[0].im); for (b_j = 1; b_j - 1 < n; b_j++) { for (je = 0; je < b_j; je++) { rworka->data[b_j] += fabs(A->data[je + A->size[0] * b_j].re) + fabs (A->data[je + A->size[0] * b_j].im); } y = rworka->data[b_j] + (fabs(A->data[b_j + A->size[0] * b_j].re) + fabs (A->data[b_j + A->size[0] * b_j].im)); if (y > anorm) { anorm = y; } } xmx = anorm; if (2.2250738585072014E-308 > anorm) { xmx = 2.2250738585072014E-308; } ascale = 1.0 / xmx; for (je = 0; je <= n; je++) { b_je = n - je; xmx = (fabs(A->data[b_je + A->size[0] * b_je].re) + fabs(A->data[b_je + A->size[0] * b_je].im)) * ascale; if (1.0 > xmx) { xmx = 1.0; } temp = 1.0 / xmx; xmx = temp * A->data[b_je + A->size[0] * b_je].re; scale = temp * A->data[b_je + A->size[0] * b_je].im; salpha_re = ascale * xmx; salpha_im = ascale * scale; acoeff = temp * ascale; if ((fabs(temp) >= 2.2250738585072014E-308) && (fabs(acoeff) < SMALL)) { b4 = true; } else { b4 = false; } if ((fabs(salpha_re) + fabs(salpha_im) >= 2.2250738585072014E-308) && (fabs (salpha_re) + fabs(salpha_im) < SMALL)) { b5 = true; } else { b5 = false; } scale = 1.0; if (b4) { xmx = anorm; if (BIG < anorm) { xmx = BIG; } scale = SMALL / fabs(temp) * xmx; } if (b5) { xmx = 1.0; if (BIG < 1.0) { xmx = BIG; } y = SMALL / (fabs(salpha_re) + fabs(salpha_im)) * xmx; if (y > scale) { scale = y; } } if (b4 || b5) { y = fabs(acoeff); xmx = fabs(salpha_re) + fabs(salpha_im); if (1.0 > y) { y = 1.0; } if (xmx > y) { y = xmx; } y = 1.0 / (2.2250738585072014E-308 * y); if (y < scale) { scale = y; } if (b4) { acoeff = ascale * (scale * temp); } else { acoeff *= scale; } if (b5) { salpha_re *= scale; salpha_im *= scale; } else { salpha_re *= scale; salpha_im *= scale; } } acoefa = fabs(acoeff); for (jr = 0; jr <= n; jr++) { work1->data[jr].re = 0.0; work1->data[jr].im = 0.0; } work1->data[b_je].re = 1.0; work1->data[b_je].im = 0.0; dmin = 2.2204460492503131E-16 * acoefa * anorm; y = 2.2204460492503131E-16 * (fabs(salpha_re) + fabs(salpha_im)); if (y > dmin) { dmin = y; } if (2.2250738585072014E-308 > dmin) { dmin = 2.2250738585072014E-308; } for (jr = 0; jr < b_je; jr++) { work1->data[jr].re = acoeff * A->data[jr + A->size[0] * b_je].re; work1->data[jr].im = acoeff * A->data[jr + A->size[0] * b_je].im; } work1->data[b_je].re = 1.0; work1->data[b_je].im = 0.0; for (b_j = 1; b_j - 1 < b_je; b_j++) { j = b_je - b_j; d_re = acoeff * A->data[j + A->size[0] * j].re - salpha_re; d_im = acoeff * A->data[j + A->size[0] * j].im - salpha_im; if (fabs(d_re) + fabs(d_im) <= dmin) { d_re = dmin; d_im = 0.0; } if ((fabs(d_re) + fabs(d_im) < 1.0) && (fabs(work1->data[j].re) + fabs (work1->data[j].im) >= BIGNUM * (fabs(d_re) + fabs(d_im)))) { temp = 1.0 / (fabs(work1->data[j].re) + fabs(work1->data[j].im)); for (jr = 0; jr <= b_je; jr++) { work1->data[jr].re *= temp; work1->data[jr].im *= temp; } } temp = -work1->data[j].re; work1_im = -work1->data[j].im; if (d_im == 0.0) { if (work1_im == 0.0) { work1->data[j].re = temp / d_re; work1->data[j].im = 0.0; } else if (temp == 0.0) { work1->data[j].re = 0.0; work1->data[j].im = work1_im / d_re; } else { work1->data[j].re = temp / d_re; work1->data[j].im = work1_im / d_re; } } else if (d_re == 0.0) { if (temp == 0.0) { work1->data[j].re = work1_im / d_im; work1->data[j].im = 0.0; } else if (work1_im == 0.0) { work1->data[j].re = 0.0; work1->data[j].im = -(temp / d_im); } else { work1->data[j].re = work1_im / d_im; work1->data[j].im = -(temp / d_im); } } else { y = fabs(d_re); xmx = fabs(d_im); if (y > xmx) { scale = d_im / d_re; xmx = d_re + scale * d_im; work1->data[j].re = (temp + scale * work1_im) / xmx; work1->data[j].im = (work1_im - scale * temp) / xmx; } else if (xmx == y) { if (d_re > 0.0) { scale = 0.5; } else { scale = -0.5; } if (d_im > 0.0) { xmx = 0.5; } else { xmx = -0.5; } work1->data[j].re = (temp * scale + work1_im * xmx) / y; work1->data[j].im = (work1_im * scale - temp * xmx) / y; } else { scale = d_re / d_im; xmx = d_im + scale * d_re; work1->data[j].re = (scale * temp + work1_im) / xmx; work1->data[j].im = (scale * work1_im - temp) / xmx; } } if (j + 1 > 1) { if (fabs(work1->data[j].re) + fabs(work1->data[j].im) > 1.0) { temp = 1.0 / (fabs(work1->data[j].re) + fabs(work1->data[j].im)); if (acoefa * rworka->data[j] >= BIGNUM * temp) { for (jr = 0; jr <= b_je; jr++) { work1->data[jr].re *= temp; work1->data[jr].im *= temp; } } } d_re = acoeff * work1->data[j].re; d_im = acoeff * work1->data[j].im; for (jr = 0; jr < j; jr++) { xmx = d_re * A->data[jr + A->size[0] * j].re - d_im * A->data[jr + A->size[0] * j].im; scale = d_re * A->data[jr + A->size[0] * j].im + d_im * A->data[jr + A->size[0] * j].re; work1->data[jr].re += xmx; work1->data[jr].im += scale; } } } for (jr = 0; jr <= n; jr++) { work2->data[jr].re = 0.0; work2->data[jr].im = 0.0; } for (j = 0; j <= b_je; j++) { for (jr = 0; jr <= n; jr++) { xmx = V->data[jr + V->size[0] * j].re * work1->data[j].re - V->data[jr + V->size[0] * j].im * work1->data[j].im; scale = V->data[jr + V->size[0] * j].re * work1->data[j].im + V->data[jr + V->size[0] * j].im * work1->data[j].re; work2->data[jr].re += xmx; work2->data[jr].im += scale; } } xmx = fabs(work2->data[0].re) + fabs(work2->data[0].im); if (n + 1 > 1) { for (jr = 1; jr - 1 < n; jr++) { y = fabs(work2->data[jr].re) + fabs(work2->data[jr].im); if (y > xmx) { xmx = y; } } } if (xmx > 2.2250738585072014E-308) { temp = 1.0 / xmx; for (jr = 0; jr <= n; jr++) { V->data[jr + V->size[0] * b_je].re = temp * work2->data[jr].re; V->data[jr + V->size[0] * b_je].im = temp * work2->data[jr].im; } } else { for (jr = 0; jr <= n; jr++) { V->data[jr + V->size[0] * b_je].re = 0.0; V->data[jr + V->size[0] * b_je].im = 0.0; } } } emxFree_real_T(&rworka); emxFree_creal_T(&work2); emxFree_creal_T(&work1); } /* * Arguments : emxArray_real_T *x * double idx * Return Type : void */ static void eml_null_assignment(emxArray_real_T *x, double idx) { int nrowx; int i; emxArray_real_T *b_x; nrowx = x->size[0] - 1; for (i = (int)idx; i <= nrowx; i++) { x->data[i - 1] = x->data[i]; } if (1 > nrowx) { nrowx = 0; } emxInit_real_T(&b_x, 1); i = b_x->size[0]; b_x->size[0] = nrowx; emxEnsureCapacity((emxArray__common *)b_x, i, (int)sizeof(double)); for (i = 0; i < nrowx; i++) { b_x->data[i] = x->data[i]; } i = x->size[0]; x->size[0] = b_x->size[0]; emxEnsureCapacity((emxArray__common *)x, i, (int)sizeof(double)); nrowx = b_x->size[0]; for (i = 0; i < nrowx; i++) { x->data[i] = b_x->data[i]; } emxFree_real_T(&b_x); } /* * Arguments : const emxArray_real_T *A * const emxArray_real_T *B * Return Type : double */ static double eml_qrsolve(const emxArray_real_T *A, const emxArray_real_T *B) { double Y; emxArray_real_T *b_A; int knt; int maxmn; int m; int mn; double atmp; double tau_data_idx_0; double xnorm; int rankR; emxArray_real_T *b_B; emxInit_real_T(&b_A, 1); knt = b_A->size[0]; b_A->size[0] = A->size[0]; emxEnsureCapacity((emxArray__common *)b_A, knt, (int)sizeof(double)); maxmn = A->size[0]; for (knt = 0; knt < maxmn; knt++) { b_A->data[knt] = A->data[knt]; } m = A->size[0] - 1; if (A->size[0] <= 1) { mn = A->size[0]; } else { mn = 1; } if (A->size[0] == 0) { } else { knt = 1; while (knt <= mn) { if (1 < m + 1) { atmp = b_A->data[0]; tau_data_idx_0 = 0.0; xnorm = eml_xnrm2(m, b_A); if (xnorm != 0.0) { xnorm = rt_hypotd_snf(b_A->data[0], xnorm); if (b_A->data[0] >= 0.0) { xnorm = -xnorm; } if (fabs(xnorm) < 1.0020841800044864E-292) { knt = 0; do { knt++; eml_xscal(m, 9.9792015476736E+291, b_A); xnorm *= 9.9792015476736E+291; atmp *= 9.9792015476736E+291; } while (!(fabs(xnorm) >= 1.0020841800044864E-292)); xnorm = eml_xnrm2(m, b_A); xnorm = rt_hypotd_snf(atmp, xnorm); if (atmp >= 0.0) { xnorm = -xnorm; } tau_data_idx_0 = (xnorm - atmp) / xnorm; eml_xscal(m, 1.0 / (atmp - xnorm), b_A); for (maxmn = 1; maxmn <= knt; maxmn++) { xnorm *= 1.0020841800044864E-292; } atmp = xnorm; } else { tau_data_idx_0 = (xnorm - b_A->data[0]) / xnorm; eml_xscal(m, 1.0 / (b_A->data[0] - xnorm), b_A); atmp = xnorm; } } } else { atmp = b_A->data[0]; tau_data_idx_0 = 0.0; } b_A->data[0] = atmp; knt = 2; } } rankR = 0; if (b_A->size[0] < 1) { knt = 0; maxmn = 1; } else { knt = 1; maxmn = b_A->size[0]; } if (knt > 0) { xnorm = (double)maxmn * fabs(b_A->data[0]) * 2.2204460492503131E-16; while ((rankR < 1) && (fabs(b_A->data[0]) >= xnorm)) { rankR = 1; } } emxInit_real_T(&b_B, 1); knt = b_B->size[0]; b_B->size[0] = B->size[0]; emxEnsureCapacity((emxArray__common *)b_B, knt, (int)sizeof(double)); maxmn = B->size[0]; for (knt = 0; knt < maxmn; knt++) { b_B->data[knt] = B->data[knt]; } m = b_A->size[0]; mn = !(b_A->size[0] < 1); Y = 0.0; maxmn = 1; while (maxmn <= mn) { if (tau_data_idx_0 != 0.0) { xnorm = b_B->data[0]; for (knt = 1; knt + 1 <= m; knt++) { xnorm += b_A->data[knt] * b_B->data[knt]; } xnorm *= tau_data_idx_0; if (xnorm != 0.0) { b_B->data[0] -= xnorm; for (knt = 1; knt + 1 <= m; knt++) { b_B->data[knt] -= b_A->data[knt] * xnorm; } } } maxmn = 2; } knt = 1; while (knt <= rankR) { Y = b_B->data[0]; knt = 2; } emxFree_real_T(&b_B); while (rankR > 0) { Y /= b_A->data[0]; rankR = 0; } emxFree_real_T(&b_A); return Y; } /* * Arguments : void * Return Type : void */ static void eml_rand_init(void) { method = 7U; } /* * Arguments : void * Return Type : void */ static void eml_rand_mcg16807_stateful_init(void) { state = 1144108930U; } /* * Arguments : void * Return Type : void */ static void eml_rand_shr3cong_stateful_init(void) { int i9; for (i9 = 0; i9 < 2; i9++) { b_state[i9] = 362436069U + 158852560U * i9; } } /* * Arguments : emxArray_real_T *x * emxArray_int32_T *idx * Return Type : void */ static void eml_sort(emxArray_real_T *x, emxArray_int32_T *idx) { int dim; int i13; emxArray_real_T *vwork; int j; int vstride; int k; emxArray_int32_T *iidx; dim = 2; if (x->size[0] != 1) { dim = 1; } if (dim <= 1) { i13 = x->size[0]; } else { i13 = 1; } emxInit_real_T(&vwork, 1); j = vwork->size[0]; vwork->size[0] = i13; emxEnsureCapacity((emxArray__common *)vwork, j, (int)sizeof(double)); vstride = x->size[0]; j = idx->size[0]; idx->size[0] = vstride; emxEnsureCapacity((emxArray__common *)idx, j, (int)sizeof(int)); vstride = 1; k = 1; while (k <= dim - 1) { vstride *= x->size[0]; k = 2; } j = 0; b_emxInit_int32_T(&iidx, 1); while (j + 1 <= vstride) { for (k = 0; k + 1 <= i13; k++) { vwork->data[k] = x->data[j + k * vstride]; } eml_sort_idx(vwork, iidx); for (k = 0; k + 1 <= i13; k++) { x->data[j + k * vstride] = vwork->data[k]; idx->data[j + k * vstride] = iidx->data[k]; } j++; } emxFree_int32_T(&iidx); emxFree_real_T(&vwork); } /* * Arguments : emxArray_real_T *x * emxArray_int32_T *idx * Return Type : void */ static void eml_sort_idx(emxArray_real_T *x, emxArray_int32_T *idx) { emxArray_real_T *b_x; int ib; int p; int m; int n; double x4[4]; int idx4[4]; emxArray_real_T *xwork; int nNaNs; int k; int wOffset; int i4; signed char perm[4]; int nNonNaN; int nBlocks; int iwork[256]; double b_xwork[256]; int bLen2; int nPairs; int32_T exitg1; emxInit_real_T(&b_x, 1); ib = x->size[0]; p = b_x->size[0]; b_x->size[0] = x->size[0]; emxEnsureCapacity((emxArray__common *)b_x, p, (int)sizeof(double)); m = x->size[0]; for (p = 0; p < m; p++) { b_x->data[p] = x->data[p]; } p = idx->size[0]; idx->size[0] = ib; emxEnsureCapacity((emxArray__common *)idx, p, (int)sizeof(int)); for (p = 0; p < ib; p++) { idx->data[p] = 0; } n = x->size[0]; for (m = 0; m < 4; m++) { x4[m] = 0.0; idx4[m] = 0; } emxInit_real_T(&xwork, 1); ib = x->size[0]; p = xwork->size[0]; xwork->size[0] = ib; emxEnsureCapacity((emxArray__common *)xwork, p, (int)sizeof(double)); nNaNs = 1; ib = 0; for (k = 0; k + 1 <= n; k++) { if (rtIsNaN(b_x->data[k])) { idx->data[n - nNaNs] = k + 1; xwork->data[n - nNaNs] = b_x->data[k]; nNaNs++; } else { ib++; idx4[ib - 1] = k + 1; x4[ib - 1] = b_x->data[k]; if (ib == 4) { ib = k - nNaNs; if (x4[0] <= x4[1]) { m = 1; p = 2; } else { m = 2; p = 1; } if (x4[2] <= x4[3]) { wOffset = 3; i4 = 4; } else { wOffset = 4; i4 = 3; } if (x4[m - 1] <= x4[wOffset - 1]) { if (x4[p - 1] <= x4[wOffset - 1]) { perm[0] = (signed char)m; perm[1] = (signed char)p; perm[2] = (signed char)wOffset; perm[3] = (signed char)i4; } else if (x4[p - 1] <= x4[i4 - 1]) { perm[0] = (signed char)m; perm[1] = (signed char)wOffset; perm[2] = (signed char)p; perm[3] = (signed char)i4; } else { perm[0] = (signed char)m; perm[1] = (signed char)wOffset; perm[2] = (signed char)i4; perm[3] = (signed char)p; } } else if (x4[m - 1] <= x4[i4 - 1]) { if (x4[p - 1] <= x4[i4 - 1]) { perm[0] = (signed char)wOffset; perm[1] = (signed char)m; perm[2] = (signed char)p; perm[3] = (signed char)i4; } else { perm[0] = (signed char)wOffset; perm[1] = (signed char)m; perm[2] = (signed char)i4; perm[3] = (signed char)p; } } else { perm[0] = (signed char)wOffset; perm[1] = (signed char)i4; perm[2] = (signed char)m; perm[3] = (signed char)p; } idx->data[ib - 2] = idx4[perm[0] - 1]; idx->data[ib - 1] = idx4[perm[1] - 1]; idx->data[ib] = idx4[perm[2] - 1]; idx->data[ib + 1] = idx4[perm[3] - 1]; b_x->data[ib - 2] = x4[perm[0] - 1]; b_x->data[ib - 1] = x4[perm[1] - 1]; b_x->data[ib] = x4[perm[2] - 1]; b_x->data[ib + 1] = x4[perm[3] - 1]; ib = 0; } } } wOffset = x->size[0] - nNaNs; if (ib > 0) { for (m = 0; m < 4; m++) { perm[m] = 0; } if (ib == 1) { perm[0] = 1; } else if (ib == 2) { if (x4[0] <= x4[1]) { perm[0] = 1; perm[1] = 2; } else { perm[0] = 2; perm[1] = 1; } } else if (x4[0] <= x4[1]) { if (x4[1] <= x4[2]) { perm[0] = 1; perm[1] = 2; perm[2] = 3; } else if (x4[0] <= x4[2]) { perm[0] = 1; perm[1] = 3; perm[2] = 2; } else { perm[0] = 3; perm[1] = 1; perm[2] = 2; } } else if (x4[0] <= x4[2]) { perm[0] = 2; perm[1] = 1; perm[2] = 3; } else if (x4[1] <= x4[2]) { perm[0] = 2; perm[1] = 3; perm[2] = 1; } else { perm[0] = 3; perm[1] = 2; perm[2] = 1; } for (k = 1; k <= ib; k++) { idx->data[(wOffset - ib) + k] = idx4[perm[k - 1] - 1]; b_x->data[(wOffset - ib) + k] = x4[perm[k - 1] - 1]; } } m = (nNaNs - 1) >> 1; for (k = 1; k <= m; k++) { p = idx->data[wOffset + k]; idx->data[wOffset + k] = idx->data[n - k]; idx->data[n - k] = p; b_x->data[wOffset + k] = xwork->data[n - k]; b_x->data[n - k] = xwork->data[wOffset + k]; } if (((nNaNs - 1) & 1) != 0) { b_x->data[(wOffset + m) + 1] = xwork->data[(wOffset + m) + 1]; } emxFree_real_T(&xwork); nNonNaN = (x->size[0] - nNaNs) + 1; m = 2; if (nNonNaN > 1) { if (x->size[0] >= 256) { nBlocks = nNonNaN >> 8; if (nBlocks > 0) { for (wOffset = 1; wOffset <= nBlocks; wOffset++) { i4 = ((wOffset - 1) << 8) - 1; for (nNaNs = 0; nNaNs < 6; nNaNs++) { n = 1 << (nNaNs + 2); bLen2 = n << 1; nPairs = 256 >> (nNaNs + 3); for (k = 1; k <= nPairs; k++) { m = i4 + (k - 1) * bLen2; for (ib = 1; ib <= bLen2; ib++) { iwork[ib - 1] = idx->data[m + ib]; b_xwork[ib - 1] = b_x->data[m + ib]; } p = 0; ib = n; do { exitg1 = 0; m++; if (b_xwork[p] <= b_xwork[ib]) { idx->data[m] = iwork[p]; b_x->data[m] = b_xwork[p]; if (p + 1 < n) { p++; } else { exitg1 = 1; } } else { idx->data[m] = iwork[ib]; b_x->data[m] = b_xwork[ib]; if (ib + 1 < bLen2) { ib++; } else { ib = m - p; while (p + 1 <= n) { idx->data[(ib + p) + 1] = iwork[p]; b_x->data[(ib + p) + 1] = b_xwork[p]; p++; } exitg1 = 1; } } } while (exitg1 == 0); } } } m = nBlocks << 8; ib = nNonNaN - m; if (ib > 0) { merge_block(idx, b_x, m, ib, 2); } m = 8; } } merge_block(idx, b_x, 0, nNonNaN, m); } p = x->size[0]; x->size[0] = b_x->size[0]; emxEnsureCapacity((emxArray__common *)x, p, (int)sizeof(double)); m = b_x->size[0]; for (p = 0; p < m; p++) { x->data[p] = b_x->data[p]; } emxFree_real_T(&b_x); } /* * Arguments : int n * const emxArray_real_T *x * Return Type : double */ static double eml_xnrm2(int n, const emxArray_real_T *x) { double y; double scale; int k; double absxk; double t; y = 0.0; if (n < 1) { } else if (n == 1) { y = fabs(x->data[1]); } else { scale = 2.2250738585072014E-308; for (k = 2; k <= n + 1; k++) { absxk = fabs(x->data[k - 1]); if (absxk > scale) { t = scale / absxk; y = 1.0 + y * t * t; scale = absxk; } else { t = absxk / scale; y += t * t; } } y = scale * sqrt(y); } return y; } /* * Arguments : int n * double a * emxArray_real_T *x * Return Type : void */ static void eml_xscal(int n, double a, emxArray_real_T *x) { int k; for (k = 1; k + 1 <= n + 1; k++) { x->data[k] *= a; } } /* * Arguments : emxArray__common *emxArray * int oldNumel * int elementSize * Return Type : void */ static void emxEnsureCapacity(emxArray__common *emxArray, int oldNumel, int elementSize) { int newNumel; int i; void *newData; newNumel = 1; for (i = 0; i < emxArray->numDimensions; i++) { newNumel *= emxArray->size[i]; } if (newNumel > emxArray->allocatedSize) { i = emxArray->allocatedSize; if (i < 16) { i = 16; } while (i < newNumel) { i <<= 1; } newData = calloc((unsigned int)i, (unsigned int)elementSize); if (emxArray->data != NULL) { memcpy(newData, emxArray->data, (unsigned int)(elementSize * oldNumel)); if (emxArray->canFreeData) { free(emxArray->data); } } emxArray->data = newData; emxArray->allocatedSize = i; emxArray->canFreeData = true; } } /* * Arguments : emxArray_boolean_T **pEmxArray * Return Type : void */ static void emxFree_boolean_T(emxArray_boolean_T **pEmxArray) { if (*pEmxArray != (emxArray_boolean_T *)NULL) { if (((*pEmxArray)->data != (boolean_T *)NULL) && (*pEmxArray)->canFreeData) { free((void *)(*pEmxArray)->data); } free((void *)(*pEmxArray)->size); free((void *)*pEmxArray); *pEmxArray = (emxArray_boolean_T *)NULL; } } /* * Arguments : emxArray_creal_T **pEmxArray * Return Type : void */ static void emxFree_creal_T(emxArray_creal_T **pEmxArray) { if (*pEmxArray != (emxArray_creal_T *)NULL) { if (((*pEmxArray)->data != (creal_T *)NULL) && (*pEmxArray)->canFreeData) { free((void *)(*pEmxArray)->data); } free((void *)(*pEmxArray)->size); free((void *)*pEmxArray); *pEmxArray = (emxArray_creal_T *)NULL; } } /* * Arguments : emxArray_int32_T **pEmxArray * Return Type : void */ static void emxFree_int32_T(emxArray_int32_T **pEmxArray) { if (*pEmxArray != (emxArray_int32_T *)NULL) { if (((*pEmxArray)->data != (int *)NULL) && (*pEmxArray)->canFreeData) { free((void *)(*pEmxArray)->data); } free((void *)(*pEmxArray)->size); free((void *)*pEmxArray); *pEmxArray = (emxArray_int32_T *)NULL; } } /* * Arguments : emxArray_real_T **pEmxArray * Return Type : void */ static void emxFree_real_T(emxArray_real_T **pEmxArray) { if (*pEmxArray != (emxArray_real_T *)NULL) { if (((*pEmxArray)->data != (double *)NULL) && (*pEmxArray)->canFreeData) { free((void *)(*pEmxArray)->data); } free((void *)(*pEmxArray)->size); free((void *)*pEmxArray); *pEmxArray = (emxArray_real_T *)NULL; } } /* * Arguments : emxArray_boolean_T **pEmxArray * int numDimensions * Return Type : void */ static void emxInit_boolean_T(emxArray_boolean_T **pEmxArray, int numDimensions) { emxArray_boolean_T *emxArray; int i; *pEmxArray = (emxArray_boolean_T *)malloc(sizeof(emxArray_boolean_T)); emxArray = *pEmxArray; emxArray->data = (boolean_T *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_creal_T **pEmxArray * int numDimensions * Return Type : void */ static void emxInit_creal_T(emxArray_creal_T **pEmxArray, int numDimensions) { emxArray_creal_T *emxArray; int i; *pEmxArray = (emxArray_creal_T *)malloc(sizeof(emxArray_creal_T)); emxArray = *pEmxArray; emxArray->data = (creal_T *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_int32_T **pEmxArray * int numDimensions * Return Type : void */ static void emxInit_int32_T(emxArray_int32_T **pEmxArray, int numDimensions) { emxArray_int32_T *emxArray; int i; *pEmxArray = (emxArray_int32_T *)malloc(sizeof(emxArray_int32_T)); emxArray = *pEmxArray; emxArray->data = (int *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : emxArray_real_T **pEmxArray * int numDimensions * Return Type : void */ static void emxInit_real_T(emxArray_real_T **pEmxArray, int numDimensions) { emxArray_real_T *emxArray; int i; *pEmxArray = (emxArray_real_T *)malloc(sizeof(emxArray_real_T)); emxArray = *pEmxArray; emxArray->data = (double *)NULL; emxArray->numDimensions = numDimensions; emxArray->size = (int *)malloc((unsigned int)(sizeof(int) * numDimensions)); emxArray->allocatedSize = 0; emxArray->canFreeData = true; for (i = 0; i < numDimensions; i++) { emxArray->size[i] = 0; } } /* * Arguments : double x * Return Type : double */ static double eps(double x) { double r; double absxk; int exponent; absxk = fabs(x); if ((!rtIsInf(absxk)) && (!rtIsNaN(absxk))) { if (absxk <= 2.2250738585072014E-308) { r = 4.94065645841247E-324; } else { frexp(absxk, &exponent); r = ldexp(1.0, exponent - 53); } } else { r = rtNaN; } return r; } /* * Arguments : const emxArray_boolean_T *x * emxArray_real_T *y * Return Type : void */ static void f_abs(const emxArray_boolean_T *x, emxArray_real_T *y) { unsigned int uv3[2]; int k; for (k = 0; k < 2; k++) { uv3[k] = (unsigned int)x->size[k]; } k = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = (int)uv3[1]; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); for (k = 0; k < x->size[1]; k++) { y->data[k] = x->data[k]; } } /* * Arguments : unsigned int mt[625] * unsigned int u[2] * Return Type : void */ static void genrand_uint32_vector(unsigned int mt[625], unsigned int u[2]) { int j; unsigned int mti; int kk; unsigned int y; unsigned int b_y; unsigned int c_y; unsigned int d_y; for (j = 0; j < 2; j++) { mti = mt[624] + 1U; if (mti >= 625U) { for (kk = 0; kk < 227; kk++) { y = (mt[kk] & 2147483648U) | (mt[1 + kk] & 2147483647U); if ((int)(y & 1U) == 0) { b_y = y >> 1U; } else { b_y = y >> 1U ^ 2567483615U; } mt[kk] = mt[397 + kk] ^ b_y; } for (kk = 0; kk < 396; kk++) { y = (mt[kk + 227] & 2147483648U) | (mt[228 + kk] & 2147483647U); if ((int)(y & 1U) == 0) { c_y = y >> 1U; } else { c_y = y >> 1U ^ 2567483615U; } mt[kk + 227] = mt[kk] ^ c_y; } y = (mt[623] & 2147483648U) | (mt[0] & 2147483647U); if ((int)(y & 1U) == 0) { d_y = y >> 1U; } else { d_y = y >> 1U ^ 2567483615U; } mt[623] = mt[396] ^ d_y; mti = 1U; } y = mt[(int)mti - 1]; mt[624] = mti; y ^= y >> 11U; y ^= y << 7U & 2636928640U; y ^= y << 15U & 4022730752U; y ^= y >> 18U; u[j] = y; } } /* * Arguments : unsigned int mt[625] * Return Type : double */ static double genrandu(unsigned int mt[625]) { double r; int32_T exitg1; unsigned int u[2]; boolean_T isvalid; int k; boolean_T exitg2; unsigned int b_r; /* ========================= COPYRIGHT NOTICE ============================ */ /* This is a uniform (0,1) pseudorandom number generator based on: */ /* */ /* A C-program for MT19937, with initialization improved 2002/1/26. */ /* Coded by Takuji Nishimura and Makoto Matsumoto. */ /* */ /* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, */ /* All rights reserved. */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* */ /* 1. Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* */ /* 2. Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer */ /* in the documentation and/or other materials provided with the */ /* distribution. */ /* */ /* 3. The names of its contributors may not be used to endorse or */ /* promote products derived from this software without specific */ /* prior written permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /* ============================= END ================================= */ do { exitg1 = 0; genrand_uint32_vector(mt, u); r = 1.1102230246251565E-16 * ((double)(u[0] >> 5U) * 6.7108864E+7 + (double) (u[1] >> 6U)); if (r == 0.0) { if ((mt[624] >= 1U) && (mt[624] < 625U)) { isvalid = true; } else { isvalid = false; } if (isvalid) { isvalid = false; k = 1; exitg2 = false; while ((!exitg2) && (k < 625)) { if (mt[k - 1] == 0U) { k++; } else { isvalid = true; exitg2 = true; } } } if (!isvalid) { b_r = 5489U; mt[0] = 5489U; for (k = 0; k < 623; k++) { b_r = (b_r ^ b_r >> 30U) * 1812433253U + (1 + k); mt[k + 1] = b_r; } mt[624] = 624U; } } else { exitg1 = 1; } } while (exitg1 == 0); return r; } /* * Arguments : const double varargin_1[15] * const double varargin_2[15] * double varargin_3 * Return Type : double */ static double interp1(const double varargin_1[15], const double varargin_2[15], double varargin_3) { double Vq; double y[15]; double x[15]; int low_i; int32_T exitg1; double r; int low_ip1; int high_i; int mid_i; for (low_i = 0; low_i < 15; low_i++) { y[low_i] = varargin_2[low_i]; x[low_i] = varargin_1[low_i]; } Vq = rtNaN; low_i = 1; do { exitg1 = 0; if (low_i < 16) { if (rtIsNaN(varargin_1[low_i - 1])) { exitg1 = 1; } else { low_i++; } } else { if (varargin_1[1] < varargin_1[0]) { for (low_i = 0; low_i < 7; low_i++) { r = x[low_i]; x[low_i] = x[14 - low_i]; x[14 - low_i] = r; } for (low_i = 0; low_i < 7; low_i++) { r = y[low_i]; y[low_i] = y[14 - low_i]; y[14 - low_i] = r; } } if (rtIsNaN(varargin_3) || (varargin_3 > x[14]) || (varargin_3 < x[0])) { } else { low_i = 1; low_ip1 = 2; high_i = 15; while (high_i > low_ip1) { mid_i = (low_i + high_i) >> 1; if (varargin_3 >= x[mid_i - 1]) { low_i = mid_i; low_ip1 = mid_i + 1; } else { high_i = mid_i; } } r = (varargin_3 - x[low_i - 1]) / (x[low_i] - x[low_i - 1]); if (r == 0.0) { Vq = y[low_i - 1]; } else if (r == 1.0) { Vq = y[low_i]; } else if (y[low_i - 1] == y[low_i]) { Vq = y[low_i - 1]; } else { Vq = (1.0 - r) * y[low_i - 1] + r * y[low_i]; } } exitg1 = 1; } } while (exitg1 == 0); return Vq; } /* * Arguments : const emxArray_real_T *x * emxArray_real_T *y * Return Type : void */ static void inv(const emxArray_real_T *x, emxArray_real_T *y) { int i3; int loop_ub; i3 = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)y, i3, (int)sizeof(double)); loop_ub = x->size[0] * x->size[1]; for (i3 = 0; i3 < loop_ub; i3++) { y->data[i3] = 0.0; } y->data[0] = 1.0; if ((y->size[1] == 0) || (!((int)y->data[0] != 0))) { } else { y->data[0] /= x->data[0]; } } /* * Arguments : const emxArray_real_T *varargin_1 * Return Type : boolean_T */ static boolean_T isequal(const emxArray_real_T *varargin_1) { boolean_T p; boolean_T b_p; int k; int32_T exitg1; p = false; b_p = false; k = 0; do { exitg1 = 0; if (k < 2) { if (varargin_1->size[k] != 0) { exitg1 = 1; } else { k++; } } else { b_p = true; exitg1 = 1; } } while (exitg1 == 0); if (!b_p) { } else { p = true; } return p; } /* * Arguments : const emxArray_real_T *x * Return Type : boolean_T */ static boolean_T issorted(const emxArray_real_T *x) { boolean_T y; int k; boolean_T exitg1; boolean_T p; y = true; if (x->size[0] == 0) { } else { k = 1; exitg1 = false; while ((!exitg1) && (k <= x->size[0] - 1)) { if ((x->data[k - 1] <= x->data[k]) || rtIsNaN(x->data[k])) { p = true; } else { p = false; } if (!p) { y = false; exitg1 = true; } else { k++; } } } return y; } /* * Arguments : double n1 * emxArray_real_T *y * Return Type : void */ static void linspace(double n1, emxArray_real_T *y) { double delta1; int i1; int k; if (n1 < 0.0) { n1 = 0.0; } delta1 = floor(n1); i1 = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = (int)delta1; emxEnsureCapacity((emxArray__common *)y, i1, (int)sizeof(double)); if ((int)delta1 >= 1) { y->data[(int)delta1 - 1] = 4.0; if (y->size[1] >= 2) { y->data[0] = 0.0; if (y->size[1] >= 3) { delta1 = 4.0 / ((double)y->size[1] - 1.0); i1 = y->size[1]; for (k = 0; k <= i1 - 3; k++) { y->data[1 + k] = (1.0 + (double)k) * delta1; } } } } } /* * Arguments : const emxArray_real_T *x * emxArray_real_T *y * Return Type : void */ static void mean(const emxArray_real_T *x, emxArray_real_T *y) { unsigned int sz[2]; int k; int ixstart; int ix; int iy; int i; double s; for (k = 0; k < 2; k++) { sz[k] = (unsigned int)x->size[k]; } k = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); if ((x->size[0] == 0) || (x->size[1] == 0)) { k = y->size[0] * y->size[1]; y->size[0] = 1; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); k = y->size[0] * y->size[1]; y->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); ixstart = (int)sz[1]; for (k = 0; k < ixstart; k++) { y->data[k] = 0.0; } } else { ix = 0; iy = -1; for (i = 1; i <= x->size[1]; i++) { ixstart = ix; ix++; s = x->data[ixstart]; for (k = 2; k <= x->size[0]; k++) { ix++; s += x->data[ix - 1]; } iy++; y->data[iy] = s; } } k = y->size[0] * y->size[1]; y->size[0] = 1; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); k = y->size[0]; ixstart = y->size[1]; ix = x->size[0]; ixstart *= k; for (k = 0; k < ixstart; k++) { y->data[k] /= (double)ix; } } /* * Arguments : emxArray_int32_T *idx * emxArray_real_T *x * int offset * int np * int nq * Return Type : void */ static void merge(emxArray_int32_T *idx, emxArray_real_T *x, int offset, int np, int nq) { emxArray_int32_T *iwork; emxArray_real_T *xwork; int n; int qend; int p; int iout; int32_T exitg1; b_emxInit_int32_T(&iwork, 1); emxInit_real_T(&xwork, 1); n = iwork->size[0]; iwork->size[0] = idx->size[0]; emxEnsureCapacity((emxArray__common *)iwork, n, (int)sizeof(int)); qend = x->size[0]; n = xwork->size[0]; xwork->size[0] = qend; emxEnsureCapacity((emxArray__common *)xwork, n, (int)sizeof(double)); if (nq == 0) { } else { n = np + nq; for (qend = 0; qend + 1 <= n; qend++) { iwork->data[qend] = idx->data[offset + qend]; xwork->data[qend] = x->data[offset + qend]; } p = 0; n = np; qend = np + nq; iout = offset - 1; do { exitg1 = 0; iout++; if (xwork->data[p] <= xwork->data[n]) { idx->data[iout] = iwork->data[p]; x->data[iout] = xwork->data[p]; if (p + 1 < np) { p++; } else { exitg1 = 1; } } else { idx->data[iout] = iwork->data[n]; x->data[iout] = xwork->data[n]; if (n + 1 < qend) { n++; } else { n = (iout - p) + 1; while (p + 1 <= np) { idx->data[n + p] = iwork->data[p]; x->data[n + p] = xwork->data[p]; p++; } exitg1 = 1; } } } while (exitg1 == 0); } emxFree_real_T(&xwork); emxFree_int32_T(&iwork); } /* * Arguments : emxArray_int32_T *idx * emxArray_real_T *x * int offset * int n * int preSortLevel * Return Type : void */ static void merge_block(emxArray_int32_T *idx, emxArray_real_T *x, int offset, int n, int preSortLevel) { int nPairs; int bLen; int tailOffset; int nTail; nPairs = n >> preSortLevel; bLen = 1 << preSortLevel; while (nPairs > 1) { if ((nPairs & 1) != 0) { nPairs--; tailOffset = bLen * nPairs; nTail = n - tailOffset; if (nTail > bLen) { merge(idx, x, offset + tailOffset, bLen, nTail - bLen); } } tailOffset = bLen << 1; nPairs >>= 1; for (nTail = 1; nTail <= nPairs; nTail++) { merge(idx, x, offset + (nTail - 1) * tailOffset, bLen, bLen); } bLen = tailOffset; } if (n > bLen) { merge(idx, x, offset, bLen, n - bLen); } } /* * Arguments : const emxArray_real_T *a * emxArray_real_T *c * Return Type : void */ static void mpower(const emxArray_real_T *a, emxArray_real_T *c) { int i2; double b_a; int loop_ub; i2 = c->size[0] * c->size[1]; c->size[0] = 1; c->size[1] = a->size[1]; emxEnsureCapacity((emxArray__common *)c, i2, (int)sizeof(double)); b_a = a->data[0]; loop_ub = a->size[0] * a->size[1]; for (i2 = 0; i2 < loop_ub; i2++) { c->data[i2] = b_a * a->data[i2]; } } /* * Arguments : emxArray_real_T *A * const emxArray_real_T *B * Return Type : void */ static void mrdivide(emxArray_real_T *A, const emxArray_real_T *B) { emxArray_real_T *b_B; emxArray_real_T *b_A; int i17; int loop_ub; double d2; emxInit_real_T(&b_B, 1); emxInit_real_T(&b_A, 1); if ((A->size[1] == 0) || (B->size[1] == 0)) { i17 = A->size[0] * A->size[1]; A->size[0] = 1; A->size[1] = 1; emxEnsureCapacity((emxArray__common *)A, i17, (int)sizeof(double)); A->data[0] = 0.0; } else if (1 == B->size[1]) { if (A->size[1] == 0) { } else { A->data[0] *= 1.0 / B->data[0]; } } else { i17 = b_B->size[0]; b_B->size[0] = B->size[1]; emxEnsureCapacity((emxArray__common *)b_B, i17, (int)sizeof(double)); loop_ub = B->size[1]; for (i17 = 0; i17 < loop_ub; i17++) { b_B->data[i17] = B->data[B->size[0] * i17]; } i17 = b_A->size[0]; b_A->size[0] = A->size[1]; emxEnsureCapacity((emxArray__common *)b_A, i17, (int)sizeof(double)); loop_ub = A->size[1]; for (i17 = 0; i17 < loop_ub; i17++) { b_A->data[i17] = A->data[A->size[0] * i17]; } d2 = eml_qrsolve(b_B, b_A); i17 = A->size[0] * A->size[1]; A->size[0] = 1; A->size[1] = 1; emxEnsureCapacity((emxArray__common *)A, i17, (int)sizeof(double)); A->data[0] = d2; } emxFree_real_T(&b_A); emxFree_real_T(&b_B); } /* * MVNRND Random vectors from the multivariate normal distribution. * R = MVNRND(MU,SIGMA) returns an N-by-D matrix R of random vectors * chosen from the multivariate normal distribution with mean vector MU, * and covariance matrix SIGMA. MU is an N-by-D matrix, and MVNRND * generates each row of R using the corresponding row of MU. SIGMA is a * D-by-D symmetric positive semi-definite matrix, or a D-by-D-by-N array. * If SIGMA is an array, MVNRND generates each row of R using the * corresponding page of SIGMA, i.e., MVNRND computes R(I,:) using MU(I,:) * and SIGMA(:,:,I). If the covariance matrix is diagonal, containing * variances along the diagonal and zero covariances off the diagonal, * SIGMA may also be specified as a 1-by-D matrix or a 1-by-D-by-N array, * containing just the diagonal. If MU is a 1-by-D vector, MVNRND * replicates it to match the trailing dimension of SIGMA. * * R = MVNRND(MU,SIGMA,N) returns a N-by-D matrix R of random vectors * chosen from the multivariate normal distribution with 1-by-D mean * vector MU, and D-by-D covariance matrix SIGMA. * * Example: * * mu = [1 -1]; Sigma = [.9 .4; .4 .3]; * r = mvnrnd(mu, Sigma, 500); * plot(r(:,1),r(:,2),'.'); * * See also MVTRND, MVNPDF, MVNCDF, NORMRND. * Arguments : const emxArray_real_T *mu * const emxArray_real_T *sigma * emxArray_real_T *r * Return Type : void */ static void mvnrnd_(const emxArray_real_T *mu, const emxArray_real_T *sigma, emxArray_real_T *r) { unsigned int sz[2]; int i4; boolean_T sigmaIsDiag; emxArray_real_T *t; emxArray_real_T *a; int ar; int k; int nb1; emxArray_real_T *r2; int ib; emxArray_real_T *bv; int cr; int ia; int bsub; int n; int bk; int br; emxArray_real_T *cv; double err; /* R = MVNRND(MU,SIGMA,N,T) supplies the Cholesky factor T of */ /* SIGMA, so that SIGMA(:,:,J) == T(:,:,J)'*T(:,:,J) if SIGMA is a 3D array or SIGMA */ /* == T'*T if SIGMA is a matrix. No error checking is done on T. */ /* */ /* [R,T] = MVNRND(...) returns the Cholesky factor T, so it can be */ /* re-used to make later calls more efficient, although there are greater */ /* efficiency gains when SIGMA can be specified as a diagonal instead. */ /* Copyright 1993-2011 The MathWorks, Inc. */ for (i4 = 0; i4 < 2; i4++) { sz[i4] = (unsigned int)sigma->size[i4]; } if (((int)sz[0] == 1) && ((int)sz[1] > 1)) { /* Just the diagonal of Sigma has been passed in. */ sigmaIsDiag = true; } else { sigmaIsDiag = false; } /* Special case: if mu is a column vector, then use sigma to try */ /* to interpret it as a row vector. */ /* if d == 1 && sz(1) == n */ /* mu = mu.'; */ /* [n,d] = size(mu); */ /* end */ /* Get size of data. */ /* cases not supplied */ /* Single covariance matrix */ /* Make sure sigma is the right size */ b_emxInit_real_T(&t, 2); b_emxInit_real_T(&a, 2); if (sigmaIsDiag) { /* Just the diagonal of sigma has been specified. */ /* if not(all(sigma>=0)) */ /* error(message('stats:mvnrnd:BadDiagSigma')); */ /* end */ i4 = t->size[0] * t->size[1]; t->size[0] = sigma->size[0]; t->size[1] = sigma->size[1]; emxEnsureCapacity((emxArray__common *)t, i4, (int)sizeof(double)); ar = sigma->size[0] * sigma->size[1]; for (i4 = 0; i4 < ar; i4++) { t->data[i4] = sigma->data[i4]; } i4 = sigma->size[0] * sigma->size[1]; for (k = 0; k < i4; k++) { t->data[k] = sqrt(t->data[k]); } randn(mu->size[1], a); nb1 = t->size[0]; if (a->size[1] <= t->size[1]) { ar = a->size[1]; } else { ar = t->size[1]; } b_emxInit_real_T(&r2, 2); i4 = r2->size[0] * r2->size[1]; r2->size[0] = t->size[0]; r2->size[1] = ar; emxEnsureCapacity((emxArray__common *)r2, i4, (int)sizeof(double)); ib = t->size[0]; if ((ib == 0) || (ar == 0)) { } else { emxInit_real_T(&bv, 1); cr = t->size[0]; i4 = bv->size[0]; bv->size[0] = cr; emxEnsureCapacity((emxArray__common *)bv, i4, (int)sizeof(double)); ia = 1; bsub = 1; n = 0; bk = -1; ib = t->size[0]; cr = t->size[0]; br = t->size[0]; i4 = cr * ar - br; cr = 0; emxInit_real_T(&cv, 1); while ((ib > 0) && (cr <= i4)) { for (k = 1; k <= nb1; k++) { bv->data[k - 1] = t->data[bk + k]; } err = a->data[n]; br = cv->size[0]; cv->size[0] = bv->size[0]; emxEnsureCapacity((emxArray__common *)cv, br, (int)sizeof(double)); ar = bv->size[0]; for (br = 0; br < ar; br++) { cv->data[br] = err * bv->data[br]; } for (k = 1; k <= ib; k++) { r2->data[(cr + k) - 1] = cv->data[k - 1]; } if (ia < a->size[1]) { n++; bk += nb1; bsub++; ia++; } else if (bsub < t->size[1]) { bk += nb1; bsub++; } else { ia = 1; bsub = 1; } cr += ib; } emxFree_real_T(&cv); emxFree_real_T(&bv); } i4 = r->size[0] * r->size[1]; r->size[0] = r2->size[0]; r->size[1] = r2->size[1]; emxEnsureCapacity((emxArray__common *)r, i4, (int)sizeof(double)); ar = r2->size[0] * r2->size[1]; for (i4 = 0; i4 < ar; i4++) { r->data[i4] = r2->data[i4] + mu->data[i4]; } emxFree_real_T(&r2); } else { /* Factor sigma using a function that will perform a Cholesky-like */ /* factorization as long as the sigma matrix is positive */ /* semi-definite (can have perfect correlation). Cholesky requires a */ /* positive definite matrix. sigma == T'*T */ cholcov_(sigma, t, &err); randn(t->size[0], a); if ((a->size[1] == 1) || (t->size[0] == 1)) { i4 = r->size[0] * r->size[1]; r->size[0] = 1; r->size[1] = t->size[1]; emxEnsureCapacity((emxArray__common *)r, i4, (int)sizeof(double)); ar = t->size[1]; for (i4 = 0; i4 < ar; i4++) { r->data[r->size[0] * i4] = 0.0; cr = a->size[1]; for (br = 0; br < cr; br++) { r->data[r->size[0] * i4] += a->data[a->size[0] * br] * t->data[br + t->size[0] * i4]; } } } else { k = a->size[1]; sz[1] = (unsigned int)t->size[1]; n = t->size[1] - 1; i4 = r->size[0] * r->size[1]; r->size[0] = 1; emxEnsureCapacity((emxArray__common *)r, i4, (int)sizeof(double)); i4 = r->size[0] * r->size[1]; r->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)r, i4, (int)sizeof(double)); ar = (int)sz[1]; for (i4 = 0; i4 < ar; i4++) { r->data[i4] = 0.0; } if (t->size[1] == 0) { } else { for (cr = 1; cr - 1 <= n; cr++) { for (bsub = cr; bsub <= cr; bsub++) { r->data[bsub - 1] = 0.0; } } br = 0; for (cr = 0; cr <= n; cr++) { ar = -1; i4 = br + k; for (ib = br; ib + 1 <= i4; ib++) { if (t->data[ib] != 0.0) { ia = ar; for (bsub = cr; bsub + 1 <= cr + 1; bsub++) { ia++; r->data[bsub] += t->data[ib] * a->data[ia]; } } ar++; } br += k; } } } i4 = r->size[0] * r->size[1]; r->size[0] = 1; emxEnsureCapacity((emxArray__common *)r, i4, (int)sizeof(double)); cr = r->size[0]; br = r->size[1]; ar = cr * br; for (i4 = 0; i4 < ar; i4++) { r->data[i4] += mu->data[i4]; } } emxFree_real_T(&a); emxFree_real_T(&t); /* Multiple covariance matrices */ } /* * 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. * Arguments : emxArray_real_T *x * emxArray_real_T *m * Return Type : void */ static void nanmean_(emxArray_real_T *x, emxArray_real_T *m) { emxArray_boolean_T *nans; int b_nans; int ixstart; emxArray_int32_T *r5; int ix; int i; unsigned int sz[2]; emxArray_real_T *n; int iy; double s; emxArray_real_T *y; emxInit_boolean_T(&nans, 2); /* Copyright 1993-2004 The MathWorks, Inc. */ /* Find NaNs and set them to zero */ b_nans = nans->size[0] * nans->size[1]; nans->size[0] = x->size[0]; nans->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)nans, b_nans, (int)sizeof(boolean_T)); ixstart = x->size[0] * x->size[1]; for (b_nans = 0; b_nans < ixstart; b_nans++) { nans->data[b_nans] = rtIsNaN(x->data[b_nans]); } b_emxInit_int32_T(&r5, 1); ix = nans->size[0] * nans->size[1] - 1; ixstart = 0; for (i = 0; i <= ix; i++) { if (nans->data[i]) { ixstart++; } } b_nans = r5->size[0]; r5->size[0] = ixstart; emxEnsureCapacity((emxArray__common *)r5, b_nans, (int)sizeof(int)); ixstart = 0; for (i = 0; i <= ix; i++) { if (nans->data[i]) { r5->data[ixstart] = i + 1; ixstart++; } } ixstart = r5->size[0]; for (b_nans = 0; b_nans < ixstart; b_nans++) { x->data[r5->data[b_nans] - 1] = 0.0; } emxFree_int32_T(&r5); /* Count up non-NaNs. */ b_nans = nans->size[0] * nans->size[1]; emxEnsureCapacity((emxArray__common *)nans, b_nans, (int)sizeof(boolean_T)); ixstart = nans->size[0]; b_nans = nans->size[1]; ixstart *= b_nans; for (b_nans = 0; b_nans < ixstart; b_nans++) { nans->data[b_nans] = !nans->data[b_nans]; } for (b_nans = 0; b_nans < 2; b_nans++) { sz[b_nans] = (unsigned int)nans->size[b_nans]; } b_emxInit_real_T(&n, 2); b_nans = n->size[0] * n->size[1]; n->size[0] = 1; n->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)n, b_nans, (int)sizeof(double)); if ((nans->size[0] == 0) || (nans->size[1] == 0)) { b_nans = n->size[0] * n->size[1]; n->size[0] = 1; emxEnsureCapacity((emxArray__common *)n, b_nans, (int)sizeof(double)); b_nans = n->size[0] * n->size[1]; n->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)n, b_nans, (int)sizeof(double)); ixstart = (int)sz[1]; for (b_nans = 0; b_nans < ixstart; b_nans++) { n->data[b_nans] = 0.0; } } else { ix = -1; iy = -1; for (i = 1; i <= nans->size[1]; i++) { ixstart = ix + 1; ix++; s = nans->data[ixstart]; for (b_nans = 2; b_nans <= nans->size[0]; b_nans++) { ix++; s += (double)nans->data[ix]; } iy++; n->data[iy] = s; } } emxFree_boolean_T(&nans); ix = n->size[1]; for (i = 0; i < ix; i++) { if (n->data[i] == 0.0) { n->data[i] = rtNaN; } } /* prevent divideByZero warnings */ /* Sum up non-NaNs, and divide by the number of non-NaNs. */ for (b_nans = 0; b_nans < 2; b_nans++) { sz[b_nans] = (unsigned int)x->size[b_nans]; } b_emxInit_real_T(&y, 2); b_nans = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)y, b_nans, (int)sizeof(double)); if ((x->size[0] == 0) || (x->size[1] == 0)) { b_nans = y->size[0] * y->size[1]; y->size[0] = 1; emxEnsureCapacity((emxArray__common *)y, b_nans, (int)sizeof(double)); b_nans = y->size[0] * y->size[1]; y->size[1] = (int)sz[1]; emxEnsureCapacity((emxArray__common *)y, b_nans, (int)sizeof(double)); ixstart = (int)sz[1]; for (b_nans = 0; b_nans < ixstart; b_nans++) { y->data[b_nans] = 0.0; } } else { ix = -1; iy = -1; for (i = 1; i <= x->size[1]; i++) { ixstart = ix + 1; ix++; s = x->data[ixstart]; for (b_nans = 2; b_nans <= x->size[0]; b_nans++) { ix++; s += x->data[ix]; } iy++; y->data[iy] = s; } } rdivide(y, n, m); emxFree_real_T(&y); emxFree_real_T(&n); } /* * Arguments : const emxArray_real_T *a * emxArray_real_T *y * Return Type : void */ static void power(const emxArray_real_T *a, emxArray_real_T *y) { unsigned int uv2[2]; int k; for (k = 0; k < 2; k++) { uv2[k] = (unsigned int)a->size[k]; } k = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = (int)uv2[1]; emxEnsureCapacity((emxArray__common *)y, k, (int)sizeof(double)); for (k = 0; k < (int)uv2[1]; k++) { y->data[k] = a->data[k] * a->data[k]; } } /* * Arguments : double varargin_2 * emxArray_real_T *r * Return Type : void */ static void randn(double varargin_2, emxArray_real_T *r) { int i; int k; unsigned int test1; unsigned int icng; unsigned int jsr; double b_r; double y; int ip1; static const double dv12[65] = { 0.340945, 0.4573146, 0.5397793, 0.6062427, 0.6631691, 0.7136975, 0.7596125, 0.8020356, 0.8417227, 0.8792102, 0.9148948, 0.9490791, 0.9820005, 1.0138492, 1.044781, 1.0749254, 1.1043917, 1.1332738, 1.161653, 1.189601, 1.2171815, 1.2444516, 1.2714635, 1.298265, 1.3249008, 1.3514125, 1.3778399, 1.4042211, 1.4305929, 1.4569915, 1.4834527, 1.5100122, 1.5367061, 1.5635712, 1.5906454, 1.617968, 1.6455802, 1.6735255, 1.7018503, 1.7306045, 1.7598422, 1.7896223, 1.8200099, 1.851077, 1.8829044, 1.9155831, 1.9492166, 1.9839239, 2.0198431, 2.0571356, 2.095993, 2.136645, 2.1793713, 2.2245175, 2.2725186, 2.3239338, 2.3795008, 2.4402218, 2.5075117, 2.5834658, 2.6713916, 2.7769942, 2.7769942, 2.7769942, 2.7769942 }; double x; double s; int32_T exitg1; unsigned int u32[2]; static const double dv13[257] = { 0.0, 0.215241895984875, 0.286174591792068, 0.335737519214422, 0.375121332878378, 0.408389134611989, 0.43751840220787, 0.46363433679088, 0.487443966139235, 0.50942332960209, 0.529909720661557, 0.549151702327164, 0.567338257053817, 0.584616766106378, 0.601104617755991, 0.61689699000775, 0.63207223638606, 0.646695714894993, 0.660822574244419, 0.674499822837293, 0.687767892795788, 0.700661841106814, 0.713212285190975, 0.725446140909999, 0.737387211434295, 0.749056662017815, 0.760473406430107, 0.771654424224568, 0.782615023307232, 0.793369058840623, 0.80392911698997, 0.814306670135215, 0.824512208752291, 0.834555354086381, 0.844444954909153, 0.854189171008163, 0.863795545553308, 0.87327106808886, 0.882622229585165, 0.891855070732941, 0.900975224461221, 0.909987953496718, 0.91889818364959, 0.927710533401999, 0.936429340286575, 0.945058684468165, 0.953602409881086, 0.96206414322304, 0.970447311064224, 0.978755155294224, 0.986990747099062, 0.99515699963509, 1.00325667954467, 1.01129241744, 1.01926671746548, 1.02718196603564, 1.03504043983344, 1.04284431314415, 1.05059566459093, 1.05829648333067, 1.06594867476212, 1.07355406579244, 1.0811144097034, 1.08863139065398, 1.09610662785202, 1.10354167942464, 1.11093804601357, 1.11829717411934, 1.12562045921553, 1.13290924865253, 1.14016484436815, 1.14738850542085, 1.15458145035993, 1.16174485944561, 1.16887987673083, 1.17598761201545, 1.18306914268269, 1.19012551542669, 1.19715774787944, 1.20416683014438, 1.2111537262437, 1.21811937548548, 1.22506469375653, 1.23199057474614, 1.23889789110569, 1.24578749554863, 1.2526602218949, 1.25951688606371, 1.26635828701823, 1.27318520766536, 1.27999841571382, 1.28679866449324, 1.29358669373695, 1.30036323033084, 1.30712898903073, 1.31388467315022, 1.32063097522106, 1.32736857762793, 1.33409815321936, 1.3408203658964, 1.34753587118059, 1.35424531676263, 1.36094934303328, 1.36764858359748, 1.37434366577317, 1.38103521107586, 1.38772383568998, 1.39441015092814, 1.40109476367925, 1.4077782768464, 1.41446128977547, 1.42114439867531, 1.42782819703026, 1.43451327600589, 1.44120022484872, 1.44788963128058, 1.45458208188841, 1.46127816251028, 1.46797845861808, 1.47468355569786, 1.48139403962819, 1.48811049705745, 1.49483351578049, 1.50156368511546, 1.50830159628131, 1.51504784277671, 1.521803020761, 1.52856772943771, 1.53534257144151, 1.542128153229, 1.54892508547417, 1.55573398346918, 1.56255546753104, 1.56939016341512, 1.57623870273591, 1.58310172339603, 1.58997987002419, 1.59687379442279, 1.60378415602609, 1.61071162236983, 1.61765686957301, 1.62462058283303, 1.63160345693487, 1.63860619677555, 1.64562951790478, 1.65267414708306, 1.65974082285818, 1.66683029616166, 1.67394333092612, 1.68108070472517, 1.68824320943719, 1.69543165193456, 1.70264685479992, 1.7098896570713, 1.71716091501782, 1.72446150294804, 1.73179231405296, 1.73915426128591, 1.74654827828172, 1.75397532031767, 1.76143636531891, 1.76893241491127, 1.77646449552452, 1.78403365954944, 1.79164098655216, 1.79928758454972, 1.80697459135082, 1.81470317596628, 1.82247454009388, 1.83028991968276, 1.83815058658281, 1.84605785028518, 1.8540130597602, 1.86201760539967, 1.87007292107127, 1.878180486293, 1.88634182853678, 1.8945585256707, 1.90283220855043, 1.91116456377125, 1.91955733659319, 1.92801233405266, 1.93653142827569, 1.94511656000868, 1.95376974238465, 1.96249306494436, 1.97128869793366, 1.98015889690048, 1.98910600761744, 1.99813247135842, 2.00724083056053, 2.0164337349062, 2.02571394786385, 2.03508435372962, 2.04454796521753, 2.05410793165065, 2.06376754781173, 2.07353026351874, 2.0833996939983, 2.09337963113879, 2.10347405571488, 2.11368715068665, 2.12402331568952, 2.13448718284602, 2.14508363404789, 2.15581781987674, 2.16669518035431, 2.17772146774029, 2.18890277162636, 2.20024554661128, 2.21175664288416, 2.22344334009251, 2.23531338492992, 2.24737503294739, 2.25963709517379, 2.27210899022838, 2.28480080272449, 2.29772334890286, 2.31088825060137, 2.32430801887113, 2.33799614879653, 2.35196722737914, 2.36623705671729, 2.38082279517208, 2.39574311978193, 2.41101841390112, 2.42667098493715, 2.44272531820036, 2.4592083743347, 2.47614993967052, 2.49358304127105, 2.51154444162669, 2.53007523215985, 2.54922155032478, 2.56903545268184, 2.58957598670829, 2.61091051848882, 2.63311639363158, 2.65628303757674, 2.68051464328574, 2.70593365612306, 2.73268535904401, 2.76094400527999, 2.79092117400193, 2.82287739682644, 2.85713873087322, 2.89412105361341, 2.93436686720889, 2.97860327988184, 3.02783779176959, 3.08352613200214, 3.147889289518, 3.2245750520478, 3.32024473383983, 3.44927829856143, 3.65415288536101, 3.91075795952492 }; static const double dv14[257] = { 1.0, 0.977101701267673, 0.959879091800108, 0.9451989534423, 0.932060075959231, 0.919991505039348, 0.908726440052131, 0.898095921898344, 0.887984660755834, 0.878309655808918, 0.869008688036857, 0.860033621196332, 0.851346258458678, 0.842915653112205, 0.834716292986884, 0.826726833946222, 0.818929191603703, 0.811307874312656, 0.803849483170964, 0.796542330422959, 0.789376143566025, 0.782341832654803, 0.775431304981187, 0.768637315798486, 0.761953346836795, 0.755373506507096, 0.748892447219157, 0.742505296340151, 0.736207598126863, 0.729995264561476, 0.72386453346863, 0.717811932630722, 0.711834248878248, 0.705928501332754, 0.700091918136512, 0.694321916126117, 0.688616083004672, 0.682972161644995, 0.677388036218774, 0.671861719897082, 0.66639134390875, 0.660975147776663, 0.655611470579697, 0.650298743110817, 0.645035480820822, 0.639820277453057, 0.634651799287624, 0.629528779924837, 0.624450015547027, 0.619414360605834, 0.614420723888914, 0.609468064925773, 0.604555390697468, 0.599681752619125, 0.594846243767987, 0.590047996332826, 0.585286179263371, 0.580559996100791, 0.575868682972354, 0.571211506735253, 0.566587763256165, 0.561996775814525, 0.557437893618766, 0.552910490425833, 0.548413963255266, 0.543947731190026, 0.539511234256952, 0.535103932380458, 0.530725304403662, 0.526374847171684, 0.522052074672322, 0.517756517229756, 0.513487720747327, 0.509245245995748, 0.505028667943468, 0.500837575126149, 0.49667156905249, 0.492530263643869, 0.488413284705458, 0.484320269426683, 0.480250865909047, 0.476204732719506, 0.47218153846773, 0.468180961405694, 0.464202689048174, 0.460246417812843, 0.456311852678716, 0.452398706861849, 0.448506701507203, 0.444635565395739, 0.440785034665804, 0.436954852547985, 0.433144769112652, 0.429354541029442, 0.425583931338022, 0.421832709229496, 0.418100649837848, 0.414387534040891, 0.410693148270188, 0.407017284329473, 0.403359739221114, 0.399720314980197, 0.396098818515832, 0.392495061459315, 0.388908860018789, 0.385340034840077, 0.381788410873393, 0.378253817245619, 0.374736087137891, 0.371235057668239, 0.367750569779032, 0.364282468129004, 0.360830600989648, 0.357394820145781, 0.353974980800077, 0.350570941481406, 0.347182563956794, 0.343809713146851, 0.340452257044522, 0.337110066637006, 0.333783015830718, 0.330470981379163, 0.327173842813601, 0.323891482376391, 0.320623784956905, 0.317370638029914, 0.314131931596337, 0.310907558126286, 0.307697412504292, 0.30450139197665, 0.301319396100803, 0.298151326696685, 0.294997087799962, 0.291856585617095, 0.288729728482183, 0.285616426815502, 0.282516593083708, 0.279430141761638, 0.276356989295668, 0.273297054068577, 0.270250256365875, 0.267216518343561, 0.264195763997261, 0.261187919132721, 0.258192911337619, 0.255210669954662, 0.252241126055942, 0.249284212418529, 0.246339863501264, 0.24340801542275, 0.240488605940501, 0.237581574431238, 0.23468686187233, 0.231804410824339, 0.228934165414681, 0.226076071322381, 0.223230075763918, 0.220396127480152, 0.217574176724331, 0.214764175251174, 0.211966076307031, 0.209179834621125, 0.206405406397881, 0.203642749310335, 0.200891822494657, 0.198152586545776, 0.195425003514135, 0.192709036903589, 0.190004651670465, 0.187311814223801, 0.1846304924268, 0.181960655599523, 0.179302274522848, 0.176655321443735, 0.174019770081839, 0.171395595637506, 0.168782774801212, 0.166181285764482, 0.163591108232366, 0.161012223437511, 0.158444614155925, 0.15588826472448, 0.153343161060263, 0.150809290681846, 0.148286642732575, 0.145775208005994, 0.143274978973514, 0.140785949814445, 0.138308116448551, 0.135841476571254, 0.133386029691669, 0.130941777173644, 0.12850872228, 0.126086870220186, 0.123676228201597, 0.12127680548479, 0.11888861344291, 0.116511665625611, 0.114145977827839, 0.111791568163838, 0.109448457146812, 0.107116667774684, 0.104796225622487, 0.102487158941935, 0.10018949876881, 0.0979032790388625, 0.095628536713009, 0.093365311912691, 0.0911136480663738, 0.0888735920682759, 0.0866451944505581, 0.0844285095703535, 0.082223595813203, 0.0800305158146631, 0.0778493367020961, 0.0756801303589272, 0.0735229737139814, 0.0713779490588905, 0.0692451443970068, 0.0671246538277886, 0.065016577971243, 0.0629210244377582, 0.06083810834954, 0.0587679529209339, 0.0567106901062031, 0.0546664613248891, 0.0526354182767924, 0.0506177238609479, 0.0486135532158687, 0.0466230949019305, 0.0446465522512946, 0.0426841449164746, 0.0407361106559411, 0.0388027074045262, 0.0368842156885674, 0.0349809414617162, 0.0330932194585786, 0.0312214171919203, 0.0293659397581334, 0.0275272356696031, 0.0257058040085489, 0.0239022033057959, 0.0221170627073089, 0.0203510962300445, 0.0186051212757247, 0.0168800831525432, 0.0151770883079353, 0.0134974506017399, 0.0118427578579079, 0.0102149714397015, 0.00861658276939875, 0.00705087547137324, 0.00552240329925101, 0.00403797259336304, 0.00260907274610216, 0.0012602859304986, 0.000477467764609386 }; if (method == 4U) { i = r->size[0] * r->size[1]; r->size[0] = 1; r->size[1] = (int)varargin_2; emxEnsureCapacity((emxArray__common *)r, i, (int)sizeof(double)); for (k = 0; k < (int)varargin_2; k++) { do { i = (int)(state / 127773U); test1 = 16807U * (state - i * 127773U); icng = 2836U * i; if (test1 < icng) { jsr = (test1 - icng) + 2147483647U; } else { jsr = test1 - icng; } i = (int)(jsr / 127773U); test1 = 16807U * (jsr - i * 127773U); icng = 2836U * i; if (test1 < icng) { state = (test1 - icng) + 2147483647U; } else { state = test1 - icng; } b_r = 2.0 * ((double)jsr * 4.6566128752457969E-10) - 1.0; y = 2.0 * ((double)state * 4.6566128752457969E-10) - 1.0; y = y * y + b_r * b_r; } while (!(y <= 1.0)); b_r *= sqrt(-2.0 * log(y) / y); r->data[k] = b_r; } } else if (method == 5U) { i = r->size[0] * r->size[1]; r->size[0] = 1; r->size[1] = (int)varargin_2; emxEnsureCapacity((emxArray__common *)r, i, (int)sizeof(double)); for (k = 0; k < (int)varargin_2; k++) { icng = 69069U * b_state[0] + 1234567U; jsr = b_state[1] ^ b_state[1] << 13; jsr ^= jsr >> 17; jsr ^= jsr << 5; test1 = icng + jsr; i = (int)((test1 & 63U) + 1U) - 1; ip1 = (int)((i + 1) + 1U) - 1; b_r = (double)(int)test1 * 4.6566128730773926E-10 * dv12[ip1]; if (fabs(b_r) <= dv12[i]) { } else { x = (fabs(b_r) - dv12[i]) / (dv12[ip1] - dv12[i]); icng = 69069U * icng + 1234567U; jsr ^= jsr << 13; jsr ^= jsr >> 17; jsr ^= jsr << 5; y = 0.5 + (double)(int)(icng + jsr) * 2.328306436538696E-10; s = x + y; if (s > 1.301198) { if (b_r < 0.0) { b_r = 0.4878992 * x - 0.4878992; } else { b_r = 0.4878992 - 0.4878992 * x; } } else if (s <= 0.9689279) { } else { x = 0.4878992 - 0.4878992 * x; if (y > 12.67706 - 12.37586 * exp(-0.5 * x * x)) { if (b_r < 0.0) { b_r = -x; } else { b_r = x; } } else if (exp(-0.5 * dv12[ip1] * dv12[ip1]) + y * 0.01958303 / dv12[ip1] <= exp(-0.5 * b_r * b_r)) { } else { do { icng = 69069U * icng + 1234567U; jsr ^= jsr << 13; jsr ^= jsr >> 17; jsr ^= jsr << 5; x = log(0.5 + (double)(int)(icng + jsr) * 2.328306436538696E-10) / 2.776994; icng = 69069U * icng + 1234567U; jsr ^= jsr << 13; jsr ^= jsr >> 17; jsr ^= jsr << 5; } while (!(-2.0 * log(0.5 + (double)(int)(icng + jsr) * 2.328306436538696E-10) > x * x)); if (b_r < 0.0) { b_r = x - 2.776994; } else { b_r = 2.776994 - x; } } } } b_state[0] = icng; b_state[1] = jsr; r->data[k] = b_r; } } else { i = r->size[0] * r->size[1]; r->size[0] = 1; r->size[1] = (int)varargin_2; emxEnsureCapacity((emxArray__common *)r, i, (int)sizeof(double)); for (k = 0; k < (int)varargin_2; k++) { do { exitg1 = 0; genrand_uint32_vector(c_state, u32); i = (int)((u32[1] >> 24U) + 1U); ip1 = (int)(i + 1U) - 1; b_r = (((double)(u32[0] >> 3U) * 1.6777216E+7 + (double)((int)u32[1] & 16777215)) * 2.2204460492503131E-16 - 1.0) * dv13[ip1]; if (fabs(b_r) <= dv13[i - 1]) { exitg1 = 1; } else if (i < 256) { y = genrandu(c_state); if (dv14[ip1] + y * (dv14[i - 1] - dv14[ip1]) < exp(-0.5 * b_r * b_r)) { exitg1 = 1; } } else { do { y = genrandu(c_state); x = log(y) * 0.273661237329758; y = genrandu(c_state); } while (!(-2.0 * log(y) > x * x)); if (b_r < 0.0) { b_r = x - 3.65415288536101; } else { b_r = 3.65415288536101 - x; } exitg1 = 1; } } while (exitg1 == 0); r->data[k] = b_r; } } } /* * Arguments : const emxArray_real_T *x * const emxArray_real_T *y * emxArray_real_T *z * Return Type : void */ static void rdivide(const emxArray_real_T *x, const emxArray_real_T *y, emxArray_real_T *z) { int i8; int loop_ub; i8 = z->size[0] * z->size[1]; z->size[0] = 1; z->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)z, i8, (int)sizeof(double)); loop_ub = x->size[0] * x->size[1]; for (i8 = 0; i8 < loop_ub; i8++) { z->data[i8] = x->data[i8] / y->data[i8]; } } /* * Arguments : const emxArray_real_T *a * double varargin_2 * emxArray_real_T *b * Return Type : void */ static void repmat(const emxArray_real_T *a, double varargin_2, emxArray_real_T * b) { int outsize_idx_0; int jtilecol; boolean_T p; int ibtile; int k; outsize_idx_0 = a->size[0]; jtilecol = b->size[0] * b->size[1]; b->size[0] = a->size[0]; b->size[1] = (int)varargin_2; emxEnsureCapacity((emxArray__common *)b, jtilecol, (int)sizeof(double)); if (!(a->size[0] == 0)) { if (outsize_idx_0 == 0) { p = true; } else if ((int)varargin_2 == 0) { p = true; } else { p = false; } if (!p) { outsize_idx_0 = a->size[0]; for (jtilecol = 1; jtilecol <= (int)varargin_2; jtilecol++) { ibtile = (jtilecol - 1) * outsize_idx_0; for (k = 0; k + 1 <= outsize_idx_0; k++) { b->data[ibtile + k] = a->data[k]; } } } } } /* * Arguments : double arg1 * Return Type : void */ static void rng(double arg1) { unsigned int seed; int r; int t; if (arg1 < 4.294967296E+9) { if (arg1 >= 0.0) { seed = (unsigned int)arg1; } else { seed = 0U; } } else if (arg1 >= 4.294967296E+9) { seed = MAX_uint32_T; } else { seed = 0U; } method = 4U; r = (int)(seed >> 16U); t = (int)(seed & 32768U); state = (unsigned int)r << 16U; state = seed - state; state -= t; state <<= 16U; state += t; state += r; if (state < 1U) { state = 1144108930U; } else { if (state > 2147483646U) { state = 2147483646U; } } } /* * Arguments : double u0 * double u1 * Return Type : double */ static double rt_hypotd_snf(double u0, double u1) { double y; double a; double b; a = fabs(u0); b = fabs(u1); if (a < b) { a /= b; y = b * sqrt(a * a + 1.0); } else if (a > b) { b /= a; y = a * sqrt(b * b + 1.0); } else if (rtIsNaN(b)) { y = b; } else { y = a * 1.4142135623730951; } return y; } /* * Arguments : double u0 * double u1 * Return Type : double */ static double rt_powd_snf(double u0, double u1) { double y; double d0; double d1; if (rtIsNaN(u0) || rtIsNaN(u1)) { y = rtNaN; } else { d0 = fabs(u0); d1 = fabs(u1); if (rtIsInf(u1)) { if (d0 == 1.0) { y = rtNaN; } else if (d0 > 1.0) { if (u1 > 0.0) { y = rtInf; } else { y = 0.0; } } else if (u1 > 0.0) { y = 0.0; } else { y = rtInf; } } else if (d1 == 0.0) { y = 1.0; } else if (d1 == 1.0) { if (u1 > 0.0) { y = u0; } else { y = 1.0 / u0; } } else if (u1 == 2.0) { y = u0 * u0; } else if ((u1 == 0.5) && (u0 >= 0.0)) { y = sqrt(u0); } else if ((u0 < 0.0) && (u1 > floor(u1))) { y = rtNaN; } else { y = pow(u0, u1); } } return y; } /* * Arguments : double u * Return Type : double */ static double rt_roundd_snf(double u) { double y; if (fabs(u) < 4.503599627370496E+15) { if (u >= 0.5) { y = floor(u + 0.5); } else if (u > -0.5) { y = u * 0.0; } else { y = ceil(u - 0.5); } } else { y = u; } return y; } /* * SKEWNESS Skewness. * S = SKEWNESS(X) returns the sample skewness of the values in X. For a * vector input, S is the third central moment of X, divided by the cube * of its standard deviation. For a matrix input, S is a row vector * containing the sample skewness of each column of X. For N-D arrays, * SKEWNESS operates along the first non-singleton dimension. * * SKEWNESS(X,0) adjusts the skewness for bias. SKEWNESS(X,1) is the same * as SKEWNESS(X), and does not adjust for bias. * * SKEWNESS(X,FLAG,DIM) takes the skewness along dimension DIM of X. * * SKEWNESS treats NaNs as missing values, and removes them. * * See also MEAN, MOMENT, STD, VAR, KURTOSIS. * Arguments : const emxArray_real_T *x * emxArray_real_T *s * Return Type : void */ static void skew(const emxArray_real_T *x, emxArray_real_T *s) { int itilerow; emxArray_real_T *b_x; int outsize_idx_1; emxArray_real_T *x0; emxArray_real_T *s2; int x_idx_0; int ibmat; boolean_T p; unsigned int uv1[2]; emxArray_real_T *y; emxArray_real_T *m3; emxArray_real_T *b_y; /* Copyright 1993-2004 The MathWorks, Inc. */ /* The output size for [] is a special case, handle it here. */ /* The output size for [] is a special case, handle it here. */ if (isequal(x)) { itilerow = s->size[0] * s->size[1]; s->size[0] = 1; s->size[1] = 1; emxEnsureCapacity((emxArray__common *)s, itilerow, (int)sizeof(double)); s->data[0] = rtNaN; } else { b_emxInit_real_T(&b_x, 2); /* Figure out which dimension nanmean will work along. */ /* dim = find(size(x) ~= 1, 1); */ /* Need to tile the output of nanmean to center X. */ /* tile = ones(1,2); */ /* tile(1) = size(x,1); */ /* Center X, compute its third and second moments, and compute the */ /* uncorrected skewness. */ itilerow = b_x->size[0] * b_x->size[1]; b_x->size[0] = x->size[0]; b_x->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)b_x, itilerow, (int)sizeof(double)); outsize_idx_1 = x->size[0] * x->size[1]; for (itilerow = 0; itilerow < outsize_idx_1; itilerow++) { b_x->data[itilerow] = x->data[itilerow]; } b_emxInit_real_T(&x0, 2); b_emxInit_real_T(&s2, 2); nanmean_(b_x, s2); x_idx_0 = x->size[0]; outsize_idx_1 = s2->size[1]; ibmat = x->size[0]; itilerow = x0->size[0] * x0->size[1]; x0->size[0] = ibmat; x0->size[1] = s2->size[1]; emxEnsureCapacity((emxArray__common *)x0, itilerow, (int)sizeof(double)); emxFree_real_T(&b_x); if (!(s2->size[1] == 0)) { if (x_idx_0 == 0) { p = true; } else if (outsize_idx_1 == 0) { p = true; } else { p = false; } if (!p) { x_idx_0 = x->size[0]; for (outsize_idx_1 = 0; outsize_idx_1 + 1 <= s2->size[1]; outsize_idx_1 ++) { ibmat = outsize_idx_1 * x_idx_0; for (itilerow = 1; itilerow <= x_idx_0; itilerow++) { x0->data[(ibmat + itilerow) - 1] = s2->data[outsize_idx_1]; } } } } itilerow = x0->size[0] * x0->size[1]; x0->size[0] = x->size[0]; x0->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)x0, itilerow, (int)sizeof(double)); outsize_idx_1 = x->size[0] * x->size[1]; for (itilerow = 0; itilerow < outsize_idx_1; itilerow++) { x0->data[itilerow] = x->data[itilerow] - x0->data[itilerow]; } for (itilerow = 0; itilerow < 2; itilerow++) { uv1[itilerow] = (unsigned int)x0->size[itilerow]; } b_emxInit_real_T(&y, 2); itilerow = y->size[0] * y->size[1]; y->size[0] = (int)uv1[0]; y->size[1] = (int)uv1[1]; emxEnsureCapacity((emxArray__common *)y, itilerow, (int)sizeof(double)); itilerow = (int)uv1[0] * (int)uv1[1]; for (outsize_idx_1 = 0; outsize_idx_1 < itilerow; outsize_idx_1++) { y->data[outsize_idx_1] = x0->data[outsize_idx_1] * x0->data[outsize_idx_1]; } nanmean_(y, s2); /* this is the biased variance estimator */ for (itilerow = 0; itilerow < 2; itilerow++) { uv1[itilerow] = (unsigned int)x0->size[itilerow]; } itilerow = y->size[0] * y->size[1]; y->size[0] = (int)uv1[0]; y->size[1] = (int)uv1[1]; emxEnsureCapacity((emxArray__common *)y, itilerow, (int)sizeof(double)); itilerow = (int)uv1[0] * (int)uv1[1]; for (outsize_idx_1 = 0; outsize_idx_1 < itilerow; outsize_idx_1++) { y->data[outsize_idx_1] = rt_powd_snf(x0->data[outsize_idx_1], 3.0); } emxFree_real_T(&x0); b_emxInit_real_T(&m3, 2); nanmean_(y, m3); emxFree_real_T(&y); for (itilerow = 0; itilerow < 2; itilerow++) { uv1[itilerow] = (unsigned int)s2->size[itilerow]; } b_emxInit_real_T(&b_y, 2); itilerow = b_y->size[0] * b_y->size[1]; b_y->size[0] = 1; b_y->size[1] = (int)uv1[1]; emxEnsureCapacity((emxArray__common *)b_y, itilerow, (int)sizeof(double)); for (outsize_idx_1 = 0; outsize_idx_1 < (int)uv1[1]; outsize_idx_1++) { b_y->data[outsize_idx_1] = rt_powd_snf(s2->data[outsize_idx_1], 1.5); } emxFree_real_T(&s2); rdivide(m3, b_y, s); /* Bias correct the skewness. */ emxFree_real_T(&b_y); emxFree_real_T(&m3); } } /* * Arguments : const emxArray_real_T *x * Return Type : double */ static double sum(const emxArray_real_T *x) { double y; int k; if (x->size[1] == 0) { y = 0.0; } else { y = x->data[0]; for (k = 2; k <= x->size[1]; k++) { y += x->data[k - 1]; } } return y; } /* * compileReplaceIncludes * Arguments : const emxArray_real_T *idRef * const emxArray_real_T *Sa_1 * const emxArray_real_T *Sa_2 * const emxArray_real_T *sVs30 * double nGM * double T1 * double T1dej * double ecSoilCode * double isScaled * double maxScale * double weight_mean * double weight_sd * double nLoop * double penalty * double seedValue * double M_bar * double R_bar * double eps_bar * double nX * double useVar * emxArray_real_T *finalRecords * emxArray_real_T *finalDirectios * emxArray_real_T *finalScaleFactors * emxArray_real_T *F_x * emxArray_real_T *F1_y1 * emxArray_real_T *F1_y1a * emxArray_real_T *F1_y2 * emxArray_real_T *F1_y3 * emxArray_real_T *F1_yn * emxArray_real_T *F2_y1 * emxArray_real_T *F3_y1 * emxArray_real_T *F3_y2 * double F4_x1[501] * emxArray_real_T *F4_y1 * emxArray_real_T *F5_y1 * emxArray_real_T *F6_y1 * emxArray_real_T *F7_y1 * double *errCode * Return Type : void */ void Select_Ground_Motions(const emxArray_real_T *idRef, const emxArray_real_T *Sa_1, const emxArray_real_T *Sa_2, const emxArray_real_T *sVs30, double nGM, double T1, double T1dej, double ecSoilCode, double isScaled, double maxScale, double weight_mean, double weight_sd, double nLoop, double penalty, double seedValue, double M_bar, double R_bar, double eps_bar, double nX, double useVar, emxArray_real_T *finalRecords, emxArray_real_T *finalDirectios, emxArray_real_T *finalScaleFactors, emxArray_real_T *F_x, emxArray_real_T *F1_y1, emxArray_real_T *F1_y1a, emxArray_real_T *F1_y2, emxArray_real_T *F1_y3, emxArray_real_T *F1_yn, emxArray_real_T *F2_y1, emxArray_real_T *F3_y1, emxArray_real_T *F3_y2, double F4_x1[501], emxArray_real_T *F4_y1, emxArray_real_T *F5_y1, emxArray_real_T *F6_y1, emxArray_real_T *F7_y1, double *errCode) { static const double dv0[501] = { 0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0, 1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.09, 1.1, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.2, 1.21, 1.22, 1.23, 1.24, 1.25, 1.26, 1.27, 1.28, 1.29, 1.3, 1.31, 1.32, 1.33, 1.34, 1.35, 1.36, 1.37, 1.38, 1.39, 1.4, 1.41, 1.42, 1.43, 1.44, 1.45, 1.46, 1.47, 1.48, 1.49, 1.5, 1.51, 1.52, 1.53, 1.54, 1.55, 1.56, 1.57, 1.58, 1.59, 1.6, 1.61, 1.62, 1.63, 1.64, 1.65, 1.66, 1.67, 1.68, 1.69, 1.7, 1.71, 1.72, 1.73, 1.74, 1.75, 1.76, 1.77, 1.78, 1.79, 1.8, 1.81, 1.82, 1.83, 1.84, 1.85, 1.86, 1.87, 1.88, 1.89, 1.9, 1.91, 1.92, 1.93, 1.94, 1.95, 1.96, 1.97, 1.98, 1.99, 2.0, 2.01, 2.02, 2.03, 2.04, 2.05, 2.06, 2.07, 2.08, 2.09, 2.1, 2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 2.17, 2.18, 2.19, 2.2, 2.21, 2.22, 2.23, 2.24, 2.25, 2.26, 2.27, 2.28, 2.29, 2.3, 2.31, 2.32, 2.33, 2.34, 2.35, 2.36, 2.37, 2.38, 2.39, 2.4, 2.41, 2.42, 2.43, 2.44, 2.45, 2.46, 2.47, 2.48, 2.49, 2.5, 2.51, 2.52, 2.53, 2.54, 2.55, 2.56, 2.57, 2.58, 2.59, 2.6, 2.61, 2.62, 2.63, 2.64, 2.65, 2.66, 2.67, 2.68, 2.69, 2.7, 2.71, 2.72, 2.73, 2.74, 2.75, 2.76, 2.77, 2.78, 2.79, 2.8, 2.81, 2.82, 2.83, 2.84, 2.85, 2.86, 2.87, 2.88, 2.89, 2.9, 2.91, 2.92, 2.93, 2.94, 2.95, 2.96, 2.97, 2.98, 2.99, 3.0, 3.02, 3.04, 3.06, 3.08, 3.1, 3.12, 3.14, 3.16, 3.18, 3.2, 3.22, 3.24, 3.26, 3.28, 3.3, 3.32, 3.34, 3.36, 3.38, 3.4, 3.42, 3.44, 3.46, 3.48, 3.5, 3.52, 3.54, 3.56, 3.58, 3.6, 3.62, 3.64, 3.66, 3.68, 3.7, 3.72, 3.74, 3.76, 3.78, 3.8, 3.82, 3.84, 3.86, 3.88, 3.9, 3.92, 3.94, 3.96, 3.98, 4.0, 4.02, 4.04, 4.06, 4.08, 4.1, 4.12, 4.14, 4.16, 4.18, 4.2, 4.22, 4.24, 4.26, 4.28, 4.3, 4.32, 4.34, 4.36, 4.38, 4.4, 4.42, 4.44, 4.46, 4.48, 4.5, 4.52, 4.54, 4.56, 4.58, 4.6, 4.62, 4.64, 4.66, 4.68, 4.7, 4.72, 4.74, 4.76, 4.78, 4.8, 4.82, 4.84, 4.86, 4.88, 4.9, 4.92, 4.94, 4.96, 4.98, 5.0, 5.05, 5.1, 5.15, 5.2, 5.25, 5.3, 5.35, 5.4, 5.45, 5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.85, 5.9, 5.95, 6.0, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45, 6.5, 6.55, 6.6, 6.65, 6.7, 6.75, 6.8, 6.85, 6.9, 6.95, 7.0, 7.05, 7.1, 7.15, 7.2, 7.25, 7.3, 7.35, 7.4, 7.45, 7.5, 7.55, 7.6, 7.65, 7.7, 7.75, 7.8, 7.85, 7.9, 7.95, 8.0, 8.05, 8.1, 8.15, 8.2, 8.25, 8.3, 8.35, 8.4, 8.45, 8.5, 8.55, 8.6, 8.65, 8.7, 8.75, 8.8, 8.85, 8.9, 8.95, 9.0, 9.05, 9.1, 9.15, 9.2, 9.25, 9.3, 9.35, 9.4, 9.45, 9.5, 9.55, 9.6, 9.65, 9.7, 9.75, 9.8, 9.85, 9.9, 9.95, 10.0 }; emxArray_real_T *recID; int i0; double mtmp; int loop_ub; emxArray_real_T *SaKnown; int ia; int ic; int absb; int apnd; int ndbl; int cdiff; emxArray_real_T *PerTgt_tmp; int k; emxArray_real_T *PerTgt_tmp2; emxArray_real_T *RSN; emxArray_real_T *soil_Vs30; emxArray_boolean_T *b_PerTgt_tmp; emxArray_int32_T *ii; emxArray_int32_T *b_ii; int i; emxArray_boolean_T *b_PerTgt_tmp2; emxArray_boolean_T *x; boolean_T exitg7; boolean_T guard4 = false; emxArray_real_T *posT1; emxArray_real_T *sa; double koefAtonacijsko_SD; double koefAtonacijsko_SC; double koefAtonacijsko_SB; double koefAtonacijsko_sigma; double koefAtonacijsko_bSD; double koefAtonacijsko_bSC; double koefAtonacijsko_bSB; double koefAtonacijsko_r0; double koefAtonacijsko_h0; double koefAtonacijsko_b4; double koefAtonacijsko_b3; double koefAtonacijsko_b2; double koefAtonacijsko_b1; emxArray_real_T *rho; emxArray_real_T *covReq; emxArray_real_T *var2; emxArray_real_T *varT; emxArray_real_T *sigma12; emxArray_real_T *b; emxArray_real_T *b_b; emxArray_real_T *c_b; emxArray_real_T *d_b; emxArray_real_T *y; emxArray_real_T *e_b; emxArray_real_T *c_PerTgt_tmp; emxArray_real_T *d_PerTgt_tmp; emxArray_real_T *e_PerTgt_tmp; emxArray_real_T *c_PerTgt_tmp2; int j; boolean_T exitg6; boolean_T guard3 = false; boolean_T exitg5; boolean_T guard2 = false; boolean_T exitg4; boolean_T guard1 = false; double a; double b_a; double c_a; double b_var2; double b_y[4]; emxArray_real_T *tempf; emxArray_real_T *recPer; emxArray_int32_T *r0; emxArray_real_T *d_a; emxArray_real_T *d_PerTgt_tmp2; emxArray_real_T *b_varT; emxArray_real_T *e_a; emxArray_real_T *b_sa; double devTotalSim[20]; double varargin_1[20]; boolean_T exitg3; double b_F4_x1[501]; double b_varargin_1[501]; boolean_T exitg2; emxArray_real_T *sampleBig; emxArray_boolean_T *r1; int nBig; emxArray_real_T *sampleSmall; emxArray_real_T *scaleFac; emxArray_boolean_T *b_recID; emxArray_real_T *b_sampleBig; emxArray_real_T *f_PerTgt_tmp; emxArray_boolean_T *c_varT; emxArray_real_T *c_sa; boolean_T exitg1; emxArray_boolean_T *c_recID; emxArray_boolean_T *d_recID; emxArray_real_T *e_PerTgt_tmp2; emxArray_real_T *d_varT; emxArray_boolean_T *e_varT; emxArray_boolean_T *f_varT; emxArray_boolean_T *b_recPer; emxArray_real_T *b_sampleSmall; emxArray_real_T *e_recID; emxArray_real_T *c_sampleSmall; emxArray_real_T *d_sa; emxArray_real_T *d_sampleSmall; emxArray_real_T *e_sampleSmall; boolean_T b_guard1 = false; double minID; double minDev; double devTotal; memcpy(&F4_x1[0], &dv0[0], 501U * sizeof(double)); emxInit_real_T(&recID, 1); *errCode = 0.0; /* finalRecords_tmp=0; */ i0 = finalDirectios->size[0]; finalDirectios->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalDirectios, i0, (int)sizeof(double)); finalDirectios->data[0] = 0.0; /* coder.varsize('notAllowed'); */ mtmp = rt_roundd_snf(nGM); i0 = recID->size[0]; recID->size[0] = (int)mtmp; emxEnsureCapacity((emxArray__common *)recID, i0, (int)sizeof(double)); loop_ub = (int)mtmp; for (i0 = 0; i0 < loop_ub; i0++) { recID->data[i0] = 0.0; } b_emxInit_real_T(&SaKnown, 2); /* This code is used to select conditional (structure- and site- specific) */ /* ground motions. The target means and covariances are obtained */ /* corresponding to a pre-defined target scenario earthquake, and are */ /* obtained based on the CMS method. The target means and variances can be */ /* modified by the user. The ground motion selection algorithm used here is */ /* based on a single arbitrary ground motion component (for two-dimensional */ /* structural models), instead of the geometric mean of two ground motion */ /* components (for three-dimensional structural models), as described in */ /* Jayaram et al. (2010). This is used to select ground motions for */ /* two-dimensional structural models, where a single ground motion component */ /* is required as an input for every time history analysis. */ /* */ /* Nirmal Jayaram, Ting Lin, Jack W. Baker */ /* Department of Civil and Environmental Engineering */ /* Stanford University */ /* Last Updated: 7 June 2010 */ /* */ /* Referenced manuscripts: */ /* */ /* N. Jayaram, T. Lin and and Baker, J. W. (2010). A computationally */ /* efficient ground-motion selection algorithm for matching a target */ /* response spectrum mean and variance, Earthquake Spectra, (in press). */ /* */ /* N. Jayaram and Baker, J. W. (2010). Ground-motion selection for PEER */ /* Transportation Systems Research Program, 7th CUEE and 5th ICEE Joint */ /* Conference, Tokyo, Japan. */ /* */ /* J. W. Baker and Jayaram, N. (2008). Correlation of spectral acceleration */ /* values from NGA ground motion models, Earthquake Spectra, 24 (1), 299-317 */ /* */ /* Baker, J.W. (2010). The Conditional Mean Spectrum: A tool for ground */ /* motion selection, ASCE Journal of Structural Engineering, (in press). */ /* */ /* % */ /* */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* */ /* OUTPUT VARIABLES */ /* finalRecords : Record numbers of selected records */ /* finalScaleFactors : Scale factors */ /* */ /* The final cell in this m file shows how to plot the selected spectra */ /* using this information. */ /* */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* % Load workspace containing ground-motion information. Here, the NGA */ /* database is used. Documentation of the NGA database workspace */ /* 'rec_selection_meta_data.mat' can be found at 'WorkspaceDocumentation.m'. */ /* For an alternate database, the minimum information to be provided */ /* includes the pseudo-acceleration spectra of the available, ground */ /* motions, periods at which the spectra are defined, and other information */ /* required to compute means and variances using ground-motion models. */ /* This cell can be modified by the user if desired. */ /* */ /* Variable definitions */ /* saKnown : (N*P matrix) */ /* This is a matrix of Sa values at different periods (P) for */ /* available ground-motion time histories (N). */ /* perKnown : The set of P periods. */ /* nGM : Number of ground motions to be selected */ /* T1 : Period at which spectra should be scaled and matched. */ /* Usually, the structure's fundamental period. */ /* isScaled : Should spectra be scaled before matching (1 -YES, 0-NO). */ /* maxScale : Maximum allowable scale factor. */ /* weights : [Weight for error in mean, Weight for error in standard */ /* deviation] e.g., [1.0,1.0] - equal weight for both errors. */ /* nLoop : This is a meta-variable of the algorithm. The greedy */ /* improvement technique does several passes over the available */ /* data set and tries to improve the selected records. This */ /* variable denotes the number of passes. Recommended value: 2. */ /* penalty : If a penalty needs to be applied to avoid selecting spectra */ /* that have spectral acceleration values beyond 3 sigma at any */ /* of the periods, set a value here. Use 0 otherwise. */ /* notAllowed: List of record numbers that should not be considered for */ /* selection. Use [] to consider all available records. This can */ /* be used to prevent certain magnitude-distance-Vs30 records */ /* from being selected, if desired. (see example below) */ /* checkCorr : If 1, this runs a code that compares the correlation */ /* structure of the selected ground motions to the correlations */ /* published by Baker and Jayaram (2008). */ /* seedValue : For repeatability. For a particular seedValue not equal to */ /* zero, the code will output the same set of ground motions. */ /* The set will change when the seedValue changes. If set to */ /* zero, the code randomizes the algorithm and different sets of */ /* ground motions (satisfying the target mean and variance) are */ /* generated each time. */ /* outputFile: File name of the output file */ /* */ /* If a database other than the NGA database is used, also define the */ /* following variables: */ /* */ /* magnitude : Magnitude of all the records */ /* distance_closest : Closest distance for all the records */ /* soil_Vs30 : Soil Vs30 values corresponding to all the records */ /* */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* User inputs begin here */ /* Information from the NGA database */ /* Each horizontal component of a recording from the same station in the NGA */ /* database is treated separately as an individual ground motion. */ i0 = SaKnown->size[0] * SaKnown->size[1]; SaKnown->size[0] = Sa_1->size[0] + Sa_2->size[0]; SaKnown->size[1] = Sa_1->size[1]; emxEnsureCapacity((emxArray__common *)SaKnown, i0, (int)sizeof(double)); loop_ub = Sa_1->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { ia = Sa_1->size[0]; for (ic = 0; ic < ia; ic++) { SaKnown->data[ic + SaKnown->size[0] * i0] = Sa_1->data[ic + Sa_1->size[0] * i0]; } } loop_ub = Sa_2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { ia = Sa_2->size[0]; for (ic = 0; ic < ia; ic++) { SaKnown->data[(ic + Sa_1->size[0]) + SaKnown->size[0] * i0] = Sa_2-> data[ic + Sa_2->size[0] * i0]; } } /* %% */ if (Sa_1->size[0] < 1) { absb = -1; apnd = 0; } else { ndbl = (int)floor(((double)Sa_1->size[0] - 1.0) + 0.5); apnd = ndbl + 1; cdiff = (ndbl - Sa_1->size[0]) + 1; absb = Sa_1->size[0]; if (fabs(cdiff) < 4.4408920985006262E-16 * (double)absb) { ndbl++; apnd = Sa_1->size[0]; } else if (cdiff > 0) { apnd = ndbl; } else { ndbl++; } absb = ndbl - 1; } b_emxInit_real_T(&PerTgt_tmp, 2); i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; PerTgt_tmp->size[1] = absb + 1; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); if (absb + 1 > 0) { PerTgt_tmp->data[0] = 1.0; if (absb + 1 > 1) { PerTgt_tmp->data[absb] = apnd; ndbl = absb / 2; for (k = 1; k < ndbl; k++) { PerTgt_tmp->data[k] = 1.0 + (double)k; PerTgt_tmp->data[absb - k] = apnd - k; } if (ndbl << 1 == absb) { PerTgt_tmp->data[ndbl] = (1.0 + (double)apnd) / 2.0; } else { PerTgt_tmp->data[ndbl] = 1.0 + (double)ndbl; PerTgt_tmp->data[ndbl + 1] = apnd - ndbl; } } } if (Sa_1->size[0] < 1) { absb = -1; apnd = 0; } else { ndbl = (int)floor(((double)Sa_1->size[0] - 1.0) + 0.5); apnd = ndbl + 1; cdiff = (ndbl - Sa_1->size[0]) + 1; absb = Sa_1->size[0]; if (fabs(cdiff) < 4.4408920985006262E-16 * (double)absb) { ndbl++; apnd = Sa_1->size[0]; } else if (cdiff > 0) { apnd = ndbl; } else { ndbl++; } absb = ndbl - 1; } b_emxInit_real_T(&PerTgt_tmp2, 2); i0 = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; PerTgt_tmp2->size[0] = 1; PerTgt_tmp2->size[1] = absb + 1; emxEnsureCapacity((emxArray__common *)PerTgt_tmp2, i0, (int)sizeof(double)); if (absb + 1 > 0) { PerTgt_tmp2->data[0] = 1.0; if (absb + 1 > 1) { PerTgt_tmp2->data[absb] = apnd; ndbl = absb / 2; for (k = 1; k < ndbl; k++) { PerTgt_tmp2->data[k] = 1.0 + (double)k; PerTgt_tmp2->data[absb - k] = apnd - k; } if (ndbl << 1 == absb) { PerTgt_tmp2->data[ndbl] = (1.0 + (double)apnd) / 2.0; } else { PerTgt_tmp2->data[ndbl] = 1.0 + (double)ndbl; PerTgt_tmp2->data[ndbl + 1] = apnd - ndbl; } } } emxInit_real_T(&RSN, 1); i0 = RSN->size[0]; RSN->size[0] = PerTgt_tmp->size[1] + PerTgt_tmp2->size[1]; emxEnsureCapacity((emxArray__common *)RSN, i0, (int)sizeof(double)); loop_ub = PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { RSN->data[i0] = PerTgt_tmp->data[PerTgt_tmp->size[0] * i0]; } loop_ub = PerTgt_tmp2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { RSN->data[i0 + PerTgt_tmp->size[1]] = PerTgt_tmp2->data[PerTgt_tmp2->size[0] * i0]; } emxInit_real_T(&soil_Vs30, 1); /* Filename = [Filename_1; Filename_2]; */ i0 = soil_Vs30->size[0]; soil_Vs30->size[0] = sVs30->size[0] + sVs30->size[0]; emxEnsureCapacity((emxArray__common *)soil_Vs30, i0, (int)sizeof(double)); loop_ub = sVs30->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { soil_Vs30->data[i0] = sVs30->data[i0]; } loop_ub = sVs30->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { soil_Vs30->data[i0 + sVs30->size[0]] = sVs30->data[i0]; } emxInit_boolean_T(&b_PerTgt_tmp, 2); /* mechanism = [mechanism; mechanism]; */ /* magnitude = [magnitude_; magnitude_]; */ /* lowest_usable_freq = [lowest_usable_freq; lowest_usable_freq]; */ /* distance_jb = [distance_jb; distance_jb]; */ /* distance_hyp = [distance_hyp; distance_hyp]; */ /* distance_epi = [distance_epi; distance_epi]; */ /* distance_closest = [distance_closest_; distance_closest_]; */ /* distance_campbell = [distance_campbell; distance_campbell]; */ /* %% */ /* nGM = 10; */ /* T1 = 2.63; */ /* isScaled = 1; */ /* maxScale = 4; */ /* nLoop = 2; */ /* penalty = 0; */ /* checkCorr = 1; */ /* seedValue = 1; */ /* outputFile = 'Output_File.dat'; */ /* NOTE: MORE user input required in the next cell */ /* if ecSoilCode==1 */ /* S1=0; % is there shallow alluvium */ /* S2=0; % is there deep alluvium */ /* coef=4; % 1-fault dist,raw coef; 2-fault dist,smooth coef 3-epicentral dist,raw coef; 4-epicentral dist,smooth coef */ /* elseif ecSoilCode==2 */ /* S1=0 % is there shallow alluvium */ /* S2=1 % is there deep alluvium */ /* coef=4 % 1-fault dist,raw coef; 2-fault dist,smooth coef 3-epicentral dist,raw coef; 4-epicentral dist,smooth coef */ /* elseif ecSoilCode==3 */ /* S1=1; % is there shallow alluvium */ /* S2=0; % is there deep alluvium */ /* coef=4; % 1-fault dist,raw coef; 2-fault dist,smooth coef 3-epicentral dist,raw coef; 4-epicentral dist,smooth coef */ /* else */ /* S1=0;% is there shallow alluvium */ /* S2=1; % is there deep alluvium */ /* coef=4; % 1-fault dist,raw coef; 2-fault dist,smooth coef 3-epicentral dist,raw coef; 4-epicentral dist,smooth coef */ /* end */ /* Limit records without acc. data. */ /* List of missing records: Usability testing of application programming */ /* interface for SAP2000, appendix B; Žiga Šebenik 2013 */ /* notAllowed = [notAllowed; 260; 930; 1171; 1298; 2136]; */ /* notAllowed = [notAllowed; 29; 168; 177; 267; 361; 365; 378; 473; 474; 475; 500; 599; 660; 805; 1635; 1753; 1774;]; */ /* notAllowed = [notAllowed; 43; 61; 78; 98; 104; 105; 106; 256; 275; 361; 390; 425; 436; 437; 438; 439; 442; 443; 444; 446; 496; 517; 530; 532; 651; 719; 720; 722; 723; 724; 725; 726; 727; 803; 822; 973; 1048; 1122; 1132; 1134; 1299; 1591; 1628; 1629; 1694; 1696; 1701; 1720; 1732; 3549; 3550; 3551]; */ /* Limiting the records to be considered using the `notAllowed' variable */ /* Using a different ground-motion database: */ /* MORE user input in the next cell */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* % Determination of target mean and covariances */ /* The Campbell and Bozorgnia (2008) ground-motion model is used in this */ /* code. The input variables defined below are the inputs required for this */ /* model. The user can change the ground-motion model as long as any */ /* additional information that may be required by the new model is provided. */ /* Please refer to Baker (2010) for details on the conditional mean spectrum */ /* method which is used for obtaining the target means and covariances in */ /* this example. Alternately, the details are summarized in Jayaram et al. */ /* (2010). */ /* The code provides the user an option to not match the target variance. */ /* This is done by setting the target variance to zero so that each selected */ /* response spectrum matches the target mean response spectrum. */ /* Variable definitions */ /* M_bar : Magnitude of the target scenario earthquake */ /* R_bar : Distance corresponding to the target scenario earthquake */ /* eps_bar : Epsilon value for the target scenario */ /* Vs30 : Average shear wave velocity in the top 30m of the soil, used */ /* to model local site effects (m/s) */ /* Ztor : Depth to the top of coseismic rupture (km) */ /* delta : Average dip of the rupture place (degree) */ /* lambda : Rake angle (degree) */ /* Zvs : Depth to the 2.5 km/s shear-wave velocity horizon (km) */ /* arb : 1 for arbitrary component sigma */ /* 0 for average component sigma */ /* PerTgt : Periods at which the target spectrum needs to be computed */ /* showPlots : 1 to display plots, 0 otherwise */ /* useVar : 0 to set target variance to zero, 1 to compute target */ /* variance using ground-motion model */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* User inputs begin here */ /* M_bar = 7; */ /* R_bar = 10; */ /* eps_bar = 2; */ /* Vs30 = 400; */ /* Ztor = 0; */ /* delta = 90; */ /* lambda = 180; */ /* Zvs = 2; */ /* arb = 1; % Arbitrary component */ linspace(nX, PerTgt_tmp); /* showPlots = 0; */ /* useVar = 1; */ /* Modify perTgt to include T1 */ i0 = b_PerTgt_tmp->size[0] * b_PerTgt_tmp->size[1]; b_PerTgt_tmp->size[0] = 1; b_PerTgt_tmp->size[1] = PerTgt_tmp->size[1]; emxEnsureCapacity((emxArray__common *)b_PerTgt_tmp, i0, (int)sizeof(boolean_T)); loop_ub = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { b_PerTgt_tmp->data[i0] = (PerTgt_tmp->data[i0] == T1); } emxInit_int32_T(&ii, 2); emxInit_int32_T(&b_ii, 2); if (!any(b_PerTgt_tmp)) { absb = PerTgt_tmp->size[1] - 1; ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp->data[i] < T1) { ndbl++; } } i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp->data[i] < T1) { ii->data[ndbl] = i + 1; ndbl++; } } absb = PerTgt_tmp->size[1] - 1; ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp->data[i] > T1) { ndbl++; } } i0 = b_ii->size[0] * b_ii->size[1]; b_ii->size[0] = 1; b_ii->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)b_ii, i0, (int)sizeof(int)); ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp->data[i] > T1) { b_ii->data[ndbl] = i + 1; ndbl++; } } i0 = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; PerTgt_tmp2->size[0] = 1; PerTgt_tmp2->size[1] = (ii->size[1] + b_ii->size[1]) + 1; emxEnsureCapacity((emxArray__common *)PerTgt_tmp2, i0, (int)sizeof(double)); loop_ub = ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp2->data[PerTgt_tmp2->size[0] * i0] = PerTgt_tmp->data[ii-> data[ii->size[0] * i0] - 1]; } PerTgt_tmp2->data[PerTgt_tmp2->size[0] * ii->size[1]] = T1; loop_ub = b_ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp2->data[PerTgt_tmp2->size[0] * ((i0 + ii->size[1]) + 1)] = PerTgt_tmp->data[b_ii->data[b_ii->size[0] * i0] - 1]; } } else { i0 = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; PerTgt_tmp2->size[0] = 1; PerTgt_tmp2->size[1] = PerTgt_tmp->size[1]; emxEnsureCapacity((emxArray__common *)PerTgt_tmp2, i0, (int)sizeof(double)); loop_ub = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp2->data[i0] = PerTgt_tmp->data[i0]; } } emxFree_boolean_T(&b_PerTgt_tmp); emxInit_boolean_T(&b_PerTgt_tmp2, 2); /* Modify perTgt to include T1dej */ i0 = b_PerTgt_tmp2->size[0] * b_PerTgt_tmp2->size[1]; b_PerTgt_tmp2->size[0] = 1; b_PerTgt_tmp2->size[1] = PerTgt_tmp2->size[1]; emxEnsureCapacity((emxArray__common *)b_PerTgt_tmp2, i0, (int)sizeof(boolean_T)); loop_ub = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { b_PerTgt_tmp2->data[i0] = (PerTgt_tmp2->data[i0] == T1dej); } if (!any(b_PerTgt_tmp2)) { absb = PerTgt_tmp2->size[1] - 1; ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp2->data[i] < T1dej) { ndbl++; } } i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp2->data[i] < T1dej) { ii->data[ndbl] = i + 1; ndbl++; } } absb = PerTgt_tmp2->size[1] - 1; ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp2->data[i] > T1dej) { ndbl++; } } i0 = b_ii->size[0] * b_ii->size[1]; b_ii->size[0] = 1; b_ii->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)b_ii, i0, (int)sizeof(int)); ndbl = 0; for (i = 0; i <= absb; i++) { if (PerTgt_tmp2->data[i] > T1dej) { b_ii->data[ndbl] = i + 1; ndbl++; } } i0 = F_x->size[0] * F_x->size[1]; F_x->size[0] = 1; F_x->size[1] = (ii->size[1] + b_ii->size[1]) + 1; emxEnsureCapacity((emxArray__common *)F_x, i0, (int)sizeof(double)); loop_ub = ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F_x->data[F_x->size[0] * i0] = PerTgt_tmp2->data[ii->data[ii->size[0] * i0] - 1]; } F_x->data[F_x->size[0] * ii->size[1]] = T1dej; loop_ub = b_ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F_x->data[F_x->size[0] * ((i0 + ii->size[1]) + 1)] = PerTgt_tmp2-> data[b_ii->data[b_ii->size[0] * i0] - 1]; } } else { i0 = F_x->size[0] * F_x->size[1]; F_x->size[0] = 1; F_x->size[1] = PerTgt_tmp2->size[1]; emxEnsureCapacity((emxArray__common *)F_x, i0, (int)sizeof(double)); loop_ub = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F_x->data[i0] = PerTgt_tmp2->data[i0]; } } emxFree_boolean_T(&b_PerTgt_tmp2); emxInit_boolean_T(&x, 2); /* Find position of T1 in PerTgt */ i0 = x->size[0] * x->size[1]; x->size[0] = 1; x->size[1] = F_x->size[1]; emxEnsureCapacity((emxArray__common *)x, i0, (int)sizeof(boolean_T)); loop_ub = F_x->size[0] * F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { x->data[i0] = (F_x->data[i0] == T1); } cdiff = x->size[1]; absb = 0; i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 1; exitg7 = false; while ((!exitg7) && (ndbl <= cdiff)) { guard4 = false; if (x->data[ndbl - 1]) { absb++; ii->data[absb - 1] = ndbl; if (absb >= cdiff) { exitg7 = true; } else { guard4 = true; } } else { guard4 = true; } if (guard4) { ndbl++; } } if (x->size[1] == 1) { if (absb == 0) { i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = 0; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); } } else { i0 = ii->size[0] * ii->size[1]; if (1 > absb) { ii->size[1] = 0; } else { ii->size[1] = absb; } emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); } b_emxInit_real_T(&posT1, 2); i0 = posT1->size[0] * posT1->size[1]; posT1->size[0] = 1; posT1->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)posT1, i0, (int)sizeof(double)); loop_ub = ii->size[0] * ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { posT1->data[i0] = ii->data[i0]; } b_emxInit_real_T(&sa, 2); /* Determine target spectra using ground-motion model (replace ground-motion */ /* model code if desired) */ /* sa = zeros(1,length(PerTgt)); */ /* sigma = zeros(1,length(PerTgt)); */ /* for i = 1:length(PerTgt) */ /* [temp1, temp2] = SP_1996(PerTgt(i), M_bar, R_bar, S1, S2, coef); */ /* sa(1,i)=temp1(1); */ /* sigma(1,i)=temp2(1); */ /* end */ i0 = sa->size[0] * sa->size[1]; sa->size[0] = 1; emxEnsureCapacity((emxArray__common *)sa, i0, (int)sizeof(double)); ndbl = F_x->size[1]; i0 = sa->size[0] * sa->size[1]; sa->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)sa, i0, (int)sizeof(double)); loop_ub = F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { sa->data[i0] = 0.0; } i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); ndbl = F_x->size[1]; i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); loop_ub = F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[i0] = 0.0; } for (i = 0; i < F_x->size[1]; i++) { /* [saSP(1,i) sigmaSP(1,i)] = SP_1996(PerTgt(i), M_mean, R_mean, S1, S2, coef); */ SP1996hor(F_x->data[i], ecSoilCode, &koefAtonacijsko_b1, &koefAtonacijsko_b2, &koefAtonacijsko_b3, &koefAtonacijsko_b4, &koefAtonacijsko_h0, &koefAtonacijsko_r0, &koefAtonacijsko_bSB, &koefAtonacijsko_bSC, &koefAtonacijsko_bSD, &koefAtonacijsko_sigma, &koefAtonacijsko_SB, &koefAtonacijsko_SC, &koefAtonacijsko_SD); AtonacijskoTip1(M_bar, R_bar, koefAtonacijsko_b1, koefAtonacijsko_b2, koefAtonacijsko_b3, koefAtonacijsko_b4, koefAtonacijsko_h0, koefAtonacijsko_r0, koefAtonacijsko_bSB, koefAtonacijsko_bSC, koefAtonacijsko_bSD, koefAtonacijsko_sigma, koefAtonacijsko_SB, koefAtonacijsko_SC, koefAtonacijsko_SD, &sa->data[sa->size[0] * i], &PerTgt_tmp->data [PerTgt_tmp->size[0] * i]); } b_emxInit_real_T(&rho, 2); b_exp(sa); /* User inputs end here */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* Use the CMS method to estimate target means and covariances */ /* (Log) Response Spectrum Mean: meanReq */ i0 = rho->size[0] * rho->size[1]; rho->size[0] = 1; emxEnsureCapacity((emxArray__common *)rho, i0, (int)sizeof(double)); ndbl = F_x->size[1]; i0 = rho->size[0] * rho->size[1]; rho->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)rho, i0, (int)sizeof(double)); loop_ub = F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { rho->data[i0] = 0.0; } for (i = 0; i < F_x->size[1]; i++) { rho->data[i] = baker_jayaram_correlation(F_x->data[i], T1); } b_log(sa); i0 = rho->size[0] * rho->size[1]; rho->size[0] = 1; rho->size[1] = PerTgt_tmp->size[1]; emxEnsureCapacity((emxArray__common *)rho, i0, (int)sizeof(double)); loop_ub = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { rho->data[i0] *= PerTgt_tmp->data[i0] * eps_bar; } b_emxInit_real_T(&covReq, 2); /* (Log) Response Spectrum Covariance: covReq */ ndbl = F_x->size[1]; i0 = covReq->size[0] * covReq->size[1]; covReq->size[0] = ndbl; emxEnsureCapacity((emxArray__common *)covReq, i0, (int)sizeof(double)); ndbl = F_x->size[1]; i0 = covReq->size[0] * covReq->size[1]; covReq->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)covReq, i0, (int)sizeof(double)); loop_ub = F_x->size[1] * F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { covReq->data[i0] = 0.0; } i = 0; b_emxInit_real_T(&var2, 2); b_emxInit_real_T(&varT, 2); b_emxInit_real_T(&sigma12, 2); b_emxInit_real_T(&b, 2); b_emxInit_real_T(&b_b, 2); b_emxInit_real_T(&c_b, 2); b_emxInit_real_T(&d_b, 2); b_emxInit_real_T(&y, 2); b_emxInit_real_T(&e_b, 2); b_emxInit_real_T(&c_PerTgt_tmp, 2); b_emxInit_real_T(&d_PerTgt_tmp, 2); b_emxInit_real_T(&e_PerTgt_tmp, 2); b_emxInit_real_T(&c_PerTgt_tmp2, 2); while (i <= F_x->size[1] - 1) { for (j = 0; j < F_x->size[1]; j++) { /* Periods */ /* Means and variances */ i0 = x->size[0] * x->size[1]; x->size[0] = 1; x->size[1] = F_x->size[1]; emxEnsureCapacity((emxArray__common *)x, i0, (int)sizeof(boolean_T)); mtmp = F_x->data[i]; loop_ub = F_x->size[0] * F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { x->data[i0] = (F_x->data[i0] == mtmp); } cdiff = x->size[1]; absb = 0; i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 1; exitg6 = false; while ((!exitg6) && (ndbl <= cdiff)) { guard3 = false; if (x->data[ndbl - 1]) { absb++; ii->data[absb - 1] = ndbl; if (absb >= cdiff) { exitg6 = true; } else { guard3 = true; } } else { guard3 = true; } if (guard3) { ndbl++; } } if (x->size[1] == 1) { if (absb == 0) { i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = 0; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); } } else { i0 = ii->size[0] * ii->size[1]; if (1 > absb) { ii->size[1] = 0; } else { ii->size[1] = absb; } emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); } i0 = x->size[0] * x->size[1]; x->size[0] = 1; x->size[1] = F_x->size[1]; emxEnsureCapacity((emxArray__common *)x, i0, (int)sizeof(boolean_T)); mtmp = F_x->data[j]; loop_ub = F_x->size[0] * F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { x->data[i0] = (F_x->data[i0] == mtmp); } cdiff = x->size[1]; absb = 0; i0 = b_ii->size[0] * b_ii->size[1]; b_ii->size[0] = 1; b_ii->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)b_ii, i0, (int)sizeof(int)); ndbl = 1; exitg5 = false; while ((!exitg5) && (ndbl <= cdiff)) { guard2 = false; if (x->data[ndbl - 1]) { absb++; b_ii->data[absb - 1] = ndbl; if (absb >= cdiff) { exitg5 = true; } else { guard2 = true; } } else { guard2 = true; } if (guard2) { ndbl++; } } if (x->size[1] == 1) { if (absb == 0) { i0 = b_ii->size[0] * b_ii->size[1]; b_ii->size[0] = 1; b_ii->size[1] = 0; emxEnsureCapacity((emxArray__common *)b_ii, i0, (int)sizeof(int)); } } else { i0 = b_ii->size[0] * b_ii->size[1]; if (1 > absb) { b_ii->size[1] = 0; } else { b_ii->size[1] = absb; } emxEnsureCapacity((emxArray__common *)b_ii, i0, (int)sizeof(int)); } i0 = e_PerTgt_tmp->size[0] * e_PerTgt_tmp->size[1]; e_PerTgt_tmp->size[0] = 1; e_PerTgt_tmp->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)e_PerTgt_tmp, i0, (int)sizeof(double)); loop_ub = ii->size[0] * ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { e_PerTgt_tmp->data[i0] = PerTgt_tmp->data[ii->data[i0] - 1]; } mpower(e_PerTgt_tmp, PerTgt_tmp2); i0 = d_PerTgt_tmp->size[0] * d_PerTgt_tmp->size[1]; d_PerTgt_tmp->size[0] = 1; d_PerTgt_tmp->size[1] = b_ii->size[1]; emxEnsureCapacity((emxArray__common *)d_PerTgt_tmp, i0, (int)sizeof(double)); loop_ub = b_ii->size[0] * b_ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_PerTgt_tmp->data[i0] = PerTgt_tmp->data[b_ii->data[i0] - 1]; } mpower(d_PerTgt_tmp, var2); i0 = x->size[0] * x->size[1]; x->size[0] = 1; x->size[1] = F_x->size[1]; emxEnsureCapacity((emxArray__common *)x, i0, (int)sizeof(boolean_T)); loop_ub = F_x->size[0] * F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { x->data[i0] = (F_x->data[i0] == T1); } cdiff = x->size[1]; absb = 0; i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = x->size[1]; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 1; exitg4 = false; while ((!exitg4) && (ndbl <= cdiff)) { guard1 = false; if (x->data[ndbl - 1]) { absb++; ii->data[absb - 1] = ndbl; if (absb >= cdiff) { exitg4 = true; } else { guard1 = true; } } else { guard1 = true; } if (guard1) { ndbl++; } } if (x->size[1] == 1) { if (absb == 0) { i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = 0; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); } } else { i0 = ii->size[0] * ii->size[1]; if (1 > absb) { ii->size[1] = 0; } else { ii->size[1] = absb; } emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); } i0 = c_PerTgt_tmp->size[0] * c_PerTgt_tmp->size[1]; c_PerTgt_tmp->size[0] = 1; c_PerTgt_tmp->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)c_PerTgt_tmp, i0, (int)sizeof(double)); loop_ub = ii->size[0] * ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_PerTgt_tmp->data[i0] = PerTgt_tmp->data[ii->data[i0] - 1]; } mpower(c_PerTgt_tmp, varT); a = baker_jayaram_correlation(F_x->data[i], F_x->data[j]); i0 = b->size[0] * b->size[1]; b->size[0] = 1; b->size[1] = var2->size[1]; emxEnsureCapacity((emxArray__common *)b, i0, (int)sizeof(double)); mtmp = PerTgt_tmp2->data[0]; loop_ub = var2->size[0] * var2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { b->data[i0] = mtmp * var2->data[i0]; } b_sqrt(b); b_a = baker_jayaram_correlation(F_x->data[i], F_x->data[j]); i0 = b_b->size[0] * b_b->size[1]; b_b->size[0] = 1; b_b->size[1] = var2->size[1]; emxEnsureCapacity((emxArray__common *)b_b, i0, (int)sizeof(double)); mtmp = PerTgt_tmp2->data[0]; loop_ub = var2->size[0] * var2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { b_b->data[i0] = mtmp * var2->data[i0]; } b_sqrt(b_b); c_a = baker_jayaram_correlation(F_x->data[i], T1); i0 = c_b->size[0] * c_b->size[1]; c_b->size[0] = 1; c_b->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)c_b, i0, (int)sizeof(double)); mtmp = PerTgt_tmp2->data[0]; loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_b->data[i0] = mtmp * varT->data[i0]; } b_sqrt(c_b); mtmp = baker_jayaram_correlation(T1, F_x->data[j]); i0 = d_b->size[0] * d_b->size[1]; d_b->size[0] = 1; d_b->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)d_b, i0, (int)sizeof(double)); b_var2 = var2->data[0]; loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_b->data[i0] = b_var2 * varT->data[i0]; } b_sqrt(d_b); i0 = sigma12->size[0] * sigma12->size[1]; sigma12->size[0] = 2; sigma12->size[1] = c_b->size[1]; emxEnsureCapacity((emxArray__common *)sigma12, i0, (int)sizeof(double)); loop_ub = c_b->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { sigma12->data[sigma12->size[0] * i0] = c_a * c_b->data[c_b->size[0] * i0]; } loop_ub = d_b->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { sigma12->data[1 + sigma12->size[0] * i0] = mtmp * d_b->data[d_b->size[0] * i0]; } inv(varT, c_b); i0 = y->size[0] * y->size[1]; y->size[0] = 2; y->size[1] = c_b->size[1]; emxEnsureCapacity((emxArray__common *)y, i0, (int)sizeof(double)); for (i0 = 0; i0 < 2; i0++) { loop_ub = c_b->size[1]; for (ic = 0; ic < loop_ub; ic++) { y->data[i0 + y->size[0] * ic] = sigma12->data[i0] * c_b->data [c_b->size[0] * ic]; } } i0 = e_b->size[0] * e_b->size[1]; e_b->size[0] = sigma12->size[1]; e_b->size[1] = 2; emxEnsureCapacity((emxArray__common *)e_b, i0, (int)sizeof(double)); for (i0 = 0; i0 < 2; i0++) { loop_ub = sigma12->size[1]; for (ic = 0; ic < loop_ub; ic++) { e_b->data[ic + e_b->size[0] * i0] = sigma12->data[i0 + sigma12->size[0] * ic]; } } if ((y->size[1] == 1) || (e_b->size[0] == 1)) { for (i0 = 0; i0 < 2; i0++) { for (ic = 0; ic < 2; ic++) { b_y[i0 + (ic << 1)] = 0.0; loop_ub = y->size[1]; for (apnd = 0; apnd < loop_ub; apnd++) { b_y[i0 + (ic << 1)] += y->data[i0 + y->size[0] * apnd] * e_b-> data[apnd + e_b->size[0] * ic]; } } } } else { k = y->size[1]; for (i0 = 0; i0 < 4; i0++) { b_y[i0] = 0.0; } for (ndbl = 0; ndbl < 4; ndbl += 2) { for (ic = ndbl; ic + 1 <= ndbl + 2; ic++) { b_y[ic] = 0.0; } } cdiff = 0; for (ndbl = 0; ndbl < 4; ndbl += 2) { absb = 0; i0 = cdiff + k; for (apnd = cdiff; apnd + 1 <= i0; apnd++) { if (e_b->data[apnd] != 0.0) { ia = absb; for (ic = ndbl; ic + 1 <= ndbl + 2; ic++) { ia++; b_y[ic] += e_b->data[apnd] * y->data[ia - 1]; } } absb += 2; } cdiff += k; } } i0 = c_PerTgt_tmp2->size[0] * c_PerTgt_tmp2->size[1]; c_PerTgt_tmp2->size[0] = 2; c_PerTgt_tmp2->size[1] = PerTgt_tmp2->size[1] + b->size[1]; emxEnsureCapacity((emxArray__common *)c_PerTgt_tmp2, i0, (int)sizeof (double)); loop_ub = PerTgt_tmp2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_PerTgt_tmp2->data[c_PerTgt_tmp2->size[0] * i0] = PerTgt_tmp2-> data[PerTgt_tmp2->size[0] * i0]; } loop_ub = b->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_PerTgt_tmp2->data[c_PerTgt_tmp2->size[0] * (i0 + PerTgt_tmp2->size[1])] = a * b->data[b->size[0] * i0]; } loop_ub = b_b->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_PerTgt_tmp2->data[1 + c_PerTgt_tmp2->size[0] * i0] = b_a * b_b-> data[b_b->size[0] * i0]; } loop_ub = var2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_PerTgt_tmp2->data[1 + c_PerTgt_tmp2->size[0] * (i0 + b_b->size[1])] = var2->data[var2->size[0] * i0]; } covReq->data[i + covReq->size[0] * j] = c_PerTgt_tmp2->data[2] - b_y[2]; if (useVar == 0.0) { covReq->data[i + covReq->size[0] * j] = 0.0; } } i++; } emxFree_real_T(&c_PerTgt_tmp2); emxFree_real_T(&e_PerTgt_tmp); emxFree_real_T(&d_PerTgt_tmp); emxFree_real_T(&c_PerTgt_tmp); emxFree_real_T(&e_b); emxFree_real_T(&y); emxFree_real_T(&d_b); emxFree_real_T(&c_b); emxFree_real_T(&b_b); emxFree_real_T(&b); emxFree_int32_T(&b_ii); emxFree_real_T(&sigma12); /* % Simulate response spectra using Monte Carlo Simulation */ /* 20 sets of response spectra are simulated and the best set (in terms of */ /* matching means, variances and skewness is chosen as the seed). The user */ /* can also optionally rerun this segment multiple times before deciding to */ /* proceed with the rest of the algorithm. It is to be noted, however, that */ /* the greedy improvement technique significantly improves the match between */ /* the means and the variances subsequently. */ /* Setting initial seed for simulation */ if (seedValue != 0.0) { rng(seedValue); } else{ srand(time(NULL)); int r__n__ = rand(); rng(r__n__); } c_emxInit_real_T(&tempf, 3); i0 = tempf->size[0] * tempf->size[1] * tempf->size[2]; tempf->size[0] = (int)nGM; emxEnsureCapacity((emxArray__common *)tempf, i0, (int)sizeof(double)); ndbl = F_x->size[1]; i0 = tempf->size[0] * tempf->size[1] * tempf->size[2]; tempf->size[1] = ndbl; tempf->size[2] = 20; emxEnsureCapacity((emxArray__common *)tempf, i0, (int)sizeof(double)); loop_ub = (int)nGM * F_x->size[1] * 20; for (i0 = 0; i0 < loop_ub; i0++) { tempf->data[i0] = 0.0; } emxInit_real_T(&recPer, 1); emxInit_int32_T(&r0, 2); b_emxInit_real_T(&d_a, 2); b_emxInit_real_T(&d_PerTgt_tmp2, 2); b_emxInit_real_T(&b_varT, 2); b_emxInit_real_T(&e_a, 2); b_emxInit_real_T(&b_sa, 2); for (j = 0; j < 20; j++) { for (i = 0; i < (int)nGM; i++) { i0 = b_sa->size[0] * b_sa->size[1]; b_sa->size[0] = 1; b_sa->size[1] = sa->size[1]; emxEnsureCapacity((emxArray__common *)b_sa, i0, (int)sizeof(double)); loop_ub = sa->size[0] * sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { b_sa->data[i0] = sa->data[i0] + rho->data[i0]; } mvnrnd_(b_sa, covReq, varT); b_exp(varT); loop_ub = varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { tempf->data[(i + tempf->size[0] * i0) + tempf->size[0] * tempf->size[1] * j] = varT->data[varT->size[0] * i0]; } } loop_ub = tempf->size[0]; ia = tempf->size[1]; i0 = d_a->size[0] * d_a->size[1]; d_a->size[0] = loop_ub; d_a->size[1] = ia; emxEnsureCapacity((emxArray__common *)d_a, i0, (int)sizeof(double)); for (i0 = 0; i0 < ia; i0++) { for (ic = 0; ic < loop_ub; ic++) { d_a->data[ic + d_a->size[0] * i0] = tempf->data[(ic + tempf->size[0] * i0) + tempf->size[0] * tempf->size[1] * j]; } } c_log(d_a); mean(d_a, varT); /* Round to 10 digits (to get the same results as in Matlab) and replace */ /* NaNs with 0; zsebenik */ loop_ub = tempf->size[0]; ia = tempf->size[1]; i0 = d_a->size[0] * d_a->size[1]; d_a->size[0] = loop_ub; d_a->size[1] = ia; emxEnsureCapacity((emxArray__common *)d_a, i0, (int)sizeof(double)); for (i0 = 0; i0 < ia; i0++) { for (ic = 0; ic < loop_ub; ic++) { d_a->data[ic + d_a->size[0] * i0] = tempf->data[(ic + tempf->size[0] * i0) + tempf->size[0] * tempf->size[1] * j]; } } c_log(d_a); i0 = d_a->size[0] * d_a->size[1]; emxEnsureCapacity((emxArray__common *)d_a, i0, (int)sizeof(double)); ndbl = d_a->size[0]; cdiff = d_a->size[1]; loop_ub = ndbl * cdiff; for (i0 = 0; i0 < loop_ub; i0++) { d_a->data[i0] *= 1.0E+10; } b_round(d_a); i0 = e_a->size[0] * e_a->size[1]; e_a->size[0] = d_a->size[0]; e_a->size[1] = d_a->size[1]; emxEnsureCapacity((emxArray__common *)e_a, i0, (int)sizeof(double)); loop_ub = d_a->size[0] * d_a->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { e_a->data[i0] = d_a->data[i0] / 1.0E+10; } skew(e_a, PerTgt_tmp); i0 = x->size[0] * x->size[1]; x->size[0] = 1; x->size[1] = PerTgt_tmp->size[1]; emxEnsureCapacity((emxArray__common *)x, i0, (int)sizeof(boolean_T)); loop_ub = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { x->data[i0] = rtIsNaN(PerTgt_tmp->data[i0]); } absb = x->size[1] - 1; ndbl = 0; for (i = 0; i <= absb; i++) { if (x->data[i]) { ndbl++; } } i0 = r0->size[0] * r0->size[1]; r0->size[0] = 1; r0->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)r0, i0, (int)sizeof(int)); ndbl = 0; for (i = 0; i <= absb; i++) { if (x->data[i]) { r0->data[ndbl] = i + 1; ndbl++; } } loop_ub = r0->size[0] * r0->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[r0->data[i0] - 1] = 0.0; } loop_ub = tempf->size[0]; ia = tempf->size[1]; i0 = d_a->size[0] * d_a->size[1]; d_a->size[0] = loop_ub; d_a->size[1] = ia; emxEnsureCapacity((emxArray__common *)d_a, i0, (int)sizeof(double)); for (i0 = 0; i0 < ia; i0++) { for (ic = 0; ic < loop_ub; ic++) { d_a->data[ic + d_a->size[0] * i0] = tempf->data[(ic + tempf->size[0] * i0) + tempf->size[0] * tempf->size[1] * j]; } } c_log(d_a); b_std(d_a, PerTgt_tmp2); diag(covReq, recPer); d_sqrt(recPer); i0 = var2->size[0] * var2->size[1]; var2->size[0] = 1; var2->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)var2, i0, (int)sizeof(double)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { var2->data[var2->size[0] * i0] = recPer->data[i0]; } i0 = b_varT->size[0] * b_varT->size[1]; b_varT->size[0] = 1; b_varT->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)b_varT, i0, (int)sizeof(double)); loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { b_varT->data[i0] = varT->data[i0] - (sa->data[i0] + rho->data[i0]); } power(b_varT, varT); i0 = d_PerTgt_tmp2->size[0] * d_PerTgt_tmp2->size[1]; d_PerTgt_tmp2->size[0] = 1; d_PerTgt_tmp2->size[1] = PerTgt_tmp2->size[1]; emxEnsureCapacity((emxArray__common *)d_PerTgt_tmp2, i0, (int)sizeof(double)); loop_ub = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_PerTgt_tmp2->data[i0] = PerTgt_tmp2->data[i0] - var2->data[i0]; } power(d_PerTgt_tmp2, PerTgt_tmp2); power(PerTgt_tmp, var2); devTotalSim[j] = (weight_mean * sum(varT) + weight_sd * sum(PerTgt_tmp2)) + 0.1 * (weight_mean + weight_sd) * sum(var2); } emxFree_real_T(&b_sa); emxFree_real_T(&e_a); emxFree_real_T(&b_varT); emxFree_real_T(&d_PerTgt_tmp2); emxFree_int32_T(&r0); d_abs(devTotalSim, varargin_1); ndbl = 1; mtmp = varargin_1[0]; apnd = 0; if (rtIsNaN(varargin_1[0])) { cdiff = 1; exitg3 = false; while ((!exitg3) && (cdiff + 1 < 21)) { ndbl = cdiff + 1; if (!rtIsNaN(varargin_1[cdiff])) { mtmp = varargin_1[cdiff]; apnd = cdiff; exitg3 = true; } else { cdiff++; } } } if (ndbl < 20) { while (ndbl + 1 < 21) { if (varargin_1[ndbl] < mtmp) { mtmp = varargin_1[ndbl]; apnd = ndbl; } ndbl++; } } loop_ub = tempf->size[0]; ia = tempf->size[1]; i0 = F1_yn->size[0] * F1_yn->size[1]; F1_yn->size[0] = loop_ub; F1_yn->size[1] = ia; emxEnsureCapacity((emxArray__common *)F1_yn, i0, (int)sizeof(double)); for (i0 = 0; i0 < ia; i0++) { for (ic = 0; ic < loop_ub; ic++) { F1_yn->data[ic + F1_yn->size[0] * i0] = tempf->data[(ic + tempf->size[0] * i0) + tempf->size[0] * tempf->size[1] * apnd]; } } /* if showPlots == 1 */ i0 = F1_y1->size[0] * F1_y1->size[1]; F1_y1->size[0] = 1; F1_y1->size[1] = sa->size[1]; emxEnsureCapacity((emxArray__common *)F1_y1, i0, (int)sizeof(double)); loop_ub = sa->size[0] * sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F1_y1->data[i0] = sa->data[i0] + rho->data[i0]; } b_exp(F1_y1); i0 = F1_y1a->size[0] * F1_y1a->size[1]; F1_y1a->size[0] = 1; F1_y1a->size[1] = sa->size[1]; emxEnsureCapacity((emxArray__common *)F1_y1a, i0, (int)sizeof(double)); loop_ub = sa->size[0] * sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F1_y1a->data[i0] = sa->data[i0] + rho->data[i0]; } diag(covReq, recPer); d_sqrt(recPer); i0 = F1_y2->size[0] * F1_y2->size[1]; F1_y2->size[0] = 1; F1_y2->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)F1_y2, i0, (int)sizeof(double)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { F1_y2->data[F1_y2->size[0] * i0] = recPer->data[i0]; } i0 = F1_y2->size[0] * F1_y2->size[1]; F1_y2->size[0] = 1; F1_y2->size[1] = sa->size[1]; emxEnsureCapacity((emxArray__common *)F1_y2, i0, (int)sizeof(double)); loop_ub = sa->size[0] * sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F1_y2->data[i0] = (sa->data[i0] + rho->data[i0]) + 1.96 * F1_y2->data[i0]; } b_exp(F1_y2); diag(covReq, recPer); d_sqrt(recPer); i0 = F1_y3->size[0] * F1_y3->size[1]; F1_y3->size[0] = 1; F1_y3->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)F1_y3, i0, (int)sizeof(double)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { F1_y3->data[F1_y3->size[0] * i0] = recPer->data[i0]; } i0 = F1_y3->size[0] * F1_y3->size[1]; F1_y3->size[0] = 1; F1_y3->size[1] = sa->size[1]; emxEnsureCapacity((emxArray__common *)F1_y3, i0, (int)sizeof(double)); loop_ub = sa->size[0] * sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { F1_y3->data[i0] = (sa->data[i0] + rho->data[i0]) - 1.96 * F1_y3->data[i0]; } b_exp(F1_y3); i0 = d_a->size[0] * d_a->size[1]; d_a->size[0] = F1_yn->size[0]; d_a->size[1] = F1_yn->size[1]; emxEnsureCapacity((emxArray__common *)d_a, i0, (int)sizeof(double)); loop_ub = F1_yn->size[0] * F1_yn->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_a->data[i0] = F1_yn->data[i0]; } c_log(d_a); mean(d_a, F2_y1); b_exp(F2_y1); diag(covReq, recPer); d_sqrt(recPer); i0 = F3_y1->size[0] * F3_y1->size[1]; F3_y1->size[0] = 1; F3_y1->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)F3_y1, i0, (int)sizeof(double)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { F3_y1->data[F3_y1->size[0] * i0] = recPer->data[i0]; } i0 = d_a->size[0] * d_a->size[1]; d_a->size[0] = F1_yn->size[0]; d_a->size[1] = F1_yn->size[1]; emxEnsureCapacity((emxArray__common *)d_a, i0, (int)sizeof(double)); loop_ub = F1_yn->size[0] * F1_yn->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_a->data[i0] = F1_yn->data[i0]; } c_log(d_a); b_std(d_a, F3_y2); /* */ /* % Plot simulated response spectra */ /* figure */ /* loglog(PerTgt, exp(meanReq), '-r', 'linewidth', 3) */ /* hold on */ /* loglog(PerTgt, exp(meanReq + 1.96*sqrt(diag(covReq))'), '--r', 'linewidth', 3) */ /* for i=1:nGM */ /* loglog(PerTgt,gm,'k'); */ /* end */ /* loglog(PerTgt, exp(meanReq - 1.96*sqrt(diag(covReq))'), '--r', 'linewidth', 3) */ /* axis([min(PerTgt) max(PerTgt) 1e-2 5]) */ /* xlabel('T (s)') */ /* ylabel('S_a (g)') */ /* legend('Median response spectrum','2.5 and 97.5 percentile response spectra','Response spectra of simulated ground motions') */ /* title('Response spectra of simulated ground motions') */ /* */ /* % Plot target and simulated means */ /* figure */ /* loglog(PerTgt,exp(meanReq)) */ /* hold on */ /* loglog(PerTgt,exp(mean(log(gm))),'--') */ /* axis([min(PerTgt) max(PerTgt) 1e-2 5]) */ /* xlabel('T (s)') */ /* ylabel('Median S_a (g)') */ /* legend('exp(Target mean lnS_a)','exp(Mean of simulated lnS_a)') */ /* title('Target and sample exponential logarithmic means (i.e., medians)') */ /* */ /* % Plot target and simulated standard deviations */ /* figure */ /* semilogx(PerTgt,sqrt(diag(covReq))') */ /* hold on */ /* semilogx(PerTgt,std(log(gm)),'--') */ /* axis([min(PerTgt) max(PerTgt) 0 1]) */ /* xlabel('T (s)') */ /* ylabel('Standard deviation of lnS_a') */ /* legend('Target standard deviation of lnS_a','Standard deviation of simulated lnS_a') */ /* title('Target and sample logarithmic standard deviations') */ /* */ /* end */ /* % Arrange the available spectra in a usable format and check for invalid */ /* input */ /* Match periods (known periods and periods for error computations) */ i0 = recPer->size[0]; recPer->size[0] = F_x->size[1]; emxEnsureCapacity((emxArray__common *)recPer, i0, (int)sizeof(double)); loop_ub = F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { recPer->data[i0] = 0.0; } for (i = 0; i < F_x->size[1]; i++) { mtmp = F_x->data[i]; for (i0 = 0; i0 < 501; i0++) { b_F4_x1[i0] = F4_x1[i0] - mtmp; } e_abs(b_F4_x1, b_varargin_1); ndbl = 1; mtmp = b_varargin_1[0]; apnd = 1; if (rtIsNaN(b_varargin_1[0])) { cdiff = 2; exitg2 = false; while ((!exitg2) && (cdiff < 502)) { ndbl = cdiff; if (!rtIsNaN(b_varargin_1[cdiff - 1])) { mtmp = b_varargin_1[cdiff - 1]; apnd = cdiff; exitg2 = true; } else { cdiff++; } } } if (ndbl < 501) { while (ndbl + 1 < 502) { if (b_varargin_1[ndbl] < mtmp) { mtmp = b_varargin_1[ndbl]; apnd = ndbl + 1; } ndbl++; } } recPer->data[i] = apnd; } b_emxInit_real_T(&sampleBig, 2); /* Check for invalid input */ loop_ub = SaKnown->size[0]; i0 = sampleBig->size[0] * sampleBig->size[1]; sampleBig->size[0] = loop_ub; sampleBig->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)sampleBig, i0, (int)sizeof(double)); ia = recPer->size[0]; for (i0 = 0; i0 < ia; i0++) { for (ic = 0; ic < loop_ub; ic++) { sampleBig->data[ic + sampleBig->size[0] * i0] = SaKnown->data[ic + SaKnown->size[0] * ((int)recPer->data[i0] - 1)]; } } emxInit_boolean_T(&r1, 2); i0 = r1->size[0] * r1->size[1]; r1->size[0] = sampleBig->size[0]; r1->size[1] = sampleBig->size[1]; emxEnsureCapacity((emxArray__common *)r1, i0, (int)sizeof(boolean_T)); loop_ub = sampleBig->size[0] * sampleBig->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { r1->data[i0] = rtIsNaN(sampleBig->data[i0]); } b_any(r1, x); emxFree_boolean_T(&r1); if (any(x)) { *errCode = 3390.0; /* 'NaNs found in input response spectra' */ i0 = finalRecords->size[0]; finalRecords->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalRecords, i0, (int)sizeof(double)); finalRecords->data[0] = 0.0; i0 = finalScaleFactors->size[0]; finalScaleFactors->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalScaleFactors, i0, (int)sizeof (double)); finalScaleFactors->data[0] = 0.0; i0 = F_x->size[0] * F_x->size[1]; F_x->size[0] = 1; F_x->size[1] = 1; emxEnsureCapacity((emxArray__common *)F_x, i0, (int)sizeof(double)); F_x->data[0] = 0.0; i0 = F1_y1->size[0] * F1_y1->size[1]; F1_y1->size[0] = 1; F1_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y1, i0, (int)sizeof(double)); F1_y1->data[0] = 0.0; i0 = F1_y1a->size[0] * F1_y1a->size[1]; F1_y1a->size[0] = 1; F1_y1a->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y1a, i0, (int)sizeof(double)); F1_y1a->data[0] = 0.0; i0 = F1_y2->size[0] * F1_y2->size[1]; F1_y2->size[0] = 1; F1_y2->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y2, i0, (int)sizeof(double)); F1_y2->data[0] = 0.0; i0 = F1_y3->size[0] * F1_y3->size[1]; F1_y3->size[0] = 1; F1_y3->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y3, i0, (int)sizeof(double)); F1_y3->data[0] = 0.0; i0 = F1_yn->size[0] * F1_yn->size[1]; F1_yn->size[0] = 1; F1_yn->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_yn, i0, (int)sizeof(double)); F1_yn->data[0] = 0.0; i0 = F2_y1->size[0] * F2_y1->size[1]; F2_y1->size[0] = 1; F2_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F2_y1, i0, (int)sizeof(double)); F2_y1->data[0] = 0.0; i0 = F3_y1->size[0] * F3_y1->size[1]; F3_y1->size[0] = 1; F3_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F3_y1, i0, (int)sizeof(double)); F3_y1->data[0] = 0.0; i0 = F3_y2->size[0] * F3_y2->size[1]; F3_y2->size[0] = 1; F3_y2->size[1] = 1; emxEnsureCapacity((emxArray__common *)F3_y2, i0, (int)sizeof(double)); F3_y2->data[0] = 0.0; i0 = F4_y1->size[0] * F4_y1->size[1]; F4_y1->size[0] = 1; F4_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F4_y1, i0, (int)sizeof(double)); F4_y1->data[0] = 0.0; i0 = F5_y1->size[0] * F5_y1->size[1]; F5_y1->size[0] = 1; F5_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F5_y1, i0, (int)sizeof(double)); F5_y1->data[0] = 0.0; i0 = F6_y1->size[0] * F6_y1->size[1]; F6_y1->size[0] = 1; F6_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F6_y1, i0, (int)sizeof(double)); F6_y1->data[0] = 0.0; i0 = F7_y1->size[0] * F7_y1->size[1]; F7_y1->size[0] = 1; F7_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F7_y1, i0, (int)sizeof(double)); F7_y1->data[0] = 0.0; } else { /* Processing available spectra */ c_log(sampleBig); nBig = sampleBig->size[0] - 1; /* % Find best matches to the simulated spectra from ground-motion database */ i0 = recPer->size[0]; recPer->size[0] = sampleBig->size[0]; emxEnsureCapacity((emxArray__common *)recPer, i0, (int)sizeof(double)); loop_ub = sampleBig->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { recPer->data[i0] = 0.0; } b_emxInit_real_T(&sampleSmall, 2); i0 = sampleSmall->size[0] * sampleSmall->size[1]; sampleSmall->size[0] = (int)nGM; emxEnsureCapacity((emxArray__common *)sampleSmall, i0, (int)sizeof(double)); ndbl = F_x->size[1]; i0 = sampleSmall->size[0] * sampleSmall->size[1]; sampleSmall->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)sampleSmall, i0, (int)sizeof(double)); loop_ub = (int)nGM * F_x->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { sampleSmall->data[i0] = 0.0; } i0 = finalScaleFactors->size[0]; finalScaleFactors->size[0] = (int)nGM; emxEnsureCapacity((emxArray__common *)finalScaleFactors, i0, (int)sizeof (double)); loop_ub = (int)nGM; for (i0 = 0; i0 < loop_ub; i0++) { finalScaleFactors->data[i0] = 1.0; } i = 0; emxInit_real_T(&scaleFac, 1); b_emxInit_boolean_T(&b_recID, 1); b_emxInit_real_T(&b_sampleBig, 2); b_emxInit_real_T(&f_PerTgt_tmp, 2); emxInit_boolean_T(&c_varT, 2); emxInit_real_T(&c_sa, 1); while (i <= (int)nGM - 1) { i0 = recPer->size[0]; recPer->size[0] = nBig + 1; emxEnsureCapacity((emxArray__common *)recPer, i0, (int)sizeof(double)); for (i0 = 0; i0 <= nBig; i0++) { recPer->data[i0] = 0.0; } i0 = scaleFac->size[0]; scaleFac->size[0] = nBig + 1; emxEnsureCapacity((emxArray__common *)scaleFac, i0, (int)sizeof(double)); for (i0 = 0; i0 <= nBig; i0++) { scaleFac->data[i0] = 1.0; } for (j = 0; j <= nBig; j++) { if (isScaled == 1.0) { i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = posT1->size[1]; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof(double)); loop_ub = posT1->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { varT->data[varT->size[0] * i0] = sampleBig->data[j + sampleBig-> size[0] * ((int)posT1->data[posT1->size[0] * i0] - 1)]; } b_exp(varT); i0 = c_varT->size[0] * c_varT->size[1]; c_varT->size[0] = 1; c_varT->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)c_varT, i0, (int)sizeof (boolean_T)); loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_varT->data[i0] = (varT->data[i0] == 0.0); } if (b_all(c_varT)) { scaleFac->data[j] = -1.0; recPer->data[j] = 1.0E+6; } else { absb = F_x->size[1] - 1; ndbl = 0; for (cdiff = 0; cdiff <= absb; cdiff++) { if (F_x->data[cdiff] == T1) { ndbl++; } } i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 0; for (cdiff = 0; cdiff <= absb; cdiff++) { if (F_x->data[cdiff] == T1) { ii->data[ndbl] = cdiff + 1; ndbl++; } } i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof(double)); i0 = c_sa->size[0]; c_sa->size[0] = sa->size[1]; emxEnsureCapacity((emxArray__common *)c_sa, i0, (int)sizeof(double)); loop_ub = sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { c_sa->data[i0] = sa->data[i0] + rho->data[i0]; } loop_ub = ii->size[0] * ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { varT->data[i0] = c_sa->data[ii->data[i0] - 1]; } b_exp(varT); i0 = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; PerTgt_tmp2->size[0] = 1; PerTgt_tmp2->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)PerTgt_tmp2, i0, (int)sizeof (double)); loop_ub = ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp2->data[PerTgt_tmp2->size[0] * i0] = sampleBig->data[j + sampleBig->size[0] * (ii->data[ii->size[0] * i0] - 1)]; } b_exp(PerTgt_tmp2); mrdivide(varT, PerTgt_tmp2); scaleFac->data[j] = varT->data[0]; if ((scaleFac->data[j] > maxScale) || (soil_Vs30->data[j] == -1.0)) { recPer->data[j] = 1.0E+6; } else { loop_ub = sampleBig->size[1]; i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; PerTgt_tmp->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof (double)); for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[PerTgt_tmp->size[0] * i0] = sampleBig->data[j + sampleBig->size[0] * i0]; } b_exp(PerTgt_tmp); i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof (double)); ndbl = PerTgt_tmp->size[0]; cdiff = PerTgt_tmp->size[1]; mtmp = scaleFac->data[j]; loop_ub = ndbl * cdiff; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[i0] *= mtmp; } b_log(PerTgt_tmp); loop_ub = tempf->size[1]; i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof(double)); for (i0 = 0; i0 < loop_ub; i0++) { varT->data[varT->size[0] * i0] = F1_yn->data[i + F1_yn->size[0] * i0]; } b_log(varT); i0 = f_PerTgt_tmp->size[0] * f_PerTgt_tmp->size[1]; f_PerTgt_tmp->size[0] = 1; f_PerTgt_tmp->size[1] = PerTgt_tmp->size[1]; emxEnsureCapacity((emxArray__common *)f_PerTgt_tmp, i0, (int) sizeof(double)); loop_ub = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { f_PerTgt_tmp->data[i0] = PerTgt_tmp->data[i0] - varT->data[i0]; } power(f_PerTgt_tmp, varT); recPer->data[j] = b_sum(varT); } } } else if (soil_Vs30->data[j] == -1.0) { recPer->data[j] = 1.0E+6; } else { loop_ub = tempf->size[1]; i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof(double)); for (i0 = 0; i0 < loop_ub; i0++) { varT->data[varT->size[0] * i0] = F1_yn->data[i + F1_yn->size[0] * i0]; } b_log(varT); loop_ub = sampleBig->size[1]; i0 = b_sampleBig->size[0] * b_sampleBig->size[1]; b_sampleBig->size[0] = 1; b_sampleBig->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)b_sampleBig, i0, (int)sizeof (double)); for (i0 = 0; i0 < loop_ub; i0++) { b_sampleBig->data[b_sampleBig->size[0] * i0] = sampleBig->data[j + sampleBig->size[0] * i0] - varT->data[varT->size[0] * i0]; } power(b_sampleBig, varT); recPer->data[j] = b_sum(varT); if (recPer->data[j] == rtInf) { recPer->data[j] = 1.0E+6; } } i0 = b_recID->size[0]; b_recID->size[0] = recID->size[0]; emxEnsureCapacity((emxArray__common *)b_recID, i0, (int)sizeof(boolean_T)); loop_ub = recID->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { b_recID->data[i0] = (recID->data[i0] == 1.0 + (double)j); } if (c_any(b_recID)) { recPer->data[j] = 1.0E+6; } } ndbl = 1; absb = recPer->size[0]; mtmp = recPer->data[0]; apnd = 1; if (recPer->size[0] > 1) { if (rtIsNaN(recPer->data[0])) { cdiff = 2; exitg1 = false; while ((!exitg1) && (cdiff <= absb)) { ndbl = cdiff; if (!rtIsNaN(recPer->data[cdiff - 1])) { mtmp = recPer->data[cdiff - 1]; apnd = cdiff; exitg1 = true; } else { cdiff++; } } } if (ndbl < recPer->size[0]) { while (ndbl + 1 <= absb) { if (recPer->data[ndbl] < mtmp) { mtmp = recPer->data[ndbl]; apnd = ndbl + 1; } ndbl++; } } } recID->data[i] = apnd; if (mtmp >= 1.0E+6) { *errCode = 3389.0; /* d'Warning: Possible problem with simulated spectrum. No good matches found' */ } if (isScaled == 1.0) { finalScaleFactors->data[i] = scaleFac->data[(int)recID->data[i] - 1]; } else { finalScaleFactors->data[i] = 1.0; } loop_ub = sampleBig->size[1]; ndbl = (int)recID->data[i]; i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; PerTgt_tmp->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[PerTgt_tmp->size[0] * i0] = sampleBig->data[(ndbl + sampleBig->size[0] * i0) - 1]; } b_exp(PerTgt_tmp); i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); ndbl = PerTgt_tmp->size[0]; cdiff = PerTgt_tmp->size[1]; mtmp = scaleFac->data[(int)recID->data[i] - 1]; loop_ub = ndbl * cdiff; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[i0] *= mtmp; } b_log(PerTgt_tmp); loop_ub = PerTgt_tmp->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { sampleSmall->data[i + sampleSmall->size[0] * i0] = PerTgt_tmp-> data[PerTgt_tmp->size[0] * i0]; } i++; } emxFree_real_T(&c_sa); emxFree_boolean_T(&c_varT); emxFree_real_T(&f_PerTgt_tmp); emxFree_real_T(&b_sampleBig); emxFree_boolean_T(&b_recID); b_emxInit_boolean_T(&c_recID, 1); i0 = c_recID->size[0]; c_recID->size[0] = recID->size[0]; emxEnsureCapacity((emxArray__common *)c_recID, i0, (int)sizeof(boolean_T)); loop_ub = recID->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { c_recID->data[i0] = (recID->data[i0] == 1.0); } b_emxInit_boolean_T(&d_recID, 1); b_emxInit_real_T(&e_PerTgt_tmp2, 2); b_emxInit_real_T(&d_varT, 2); emxInit_boolean_T(&e_varT, 2); emxInit_boolean_T(&f_varT, 2); b_emxInit_boolean_T(&b_recPer, 1); b_emxInit_real_T(&b_sampleSmall, 2); emxInit_real_T(&e_recID, 1); b_emxInit_real_T(&c_sampleSmall, 2); emxInit_real_T(&d_sa, 1); b_emxInit_real_T(&d_sampleSmall, 2); b_emxInit_real_T(&e_sampleSmall, 2); b_guard1 = false; if (c_all(c_recID)) { i0 = b_recPer->size[0]; b_recPer->size[0] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)b_recPer, i0, (int)sizeof(boolean_T)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { b_recPer->data[i0] = (recPer->data[i0] == 1.0E+6); } if (c_all(b_recPer)) { *errCode = 3391.0; /* 'Error: no match spectra found' */ i0 = finalRecords->size[0]; finalRecords->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalRecords, i0, (int)sizeof (double)); finalRecords->data[0] = 0.0; i0 = finalScaleFactors->size[0]; finalScaleFactors->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalScaleFactors, i0, (int)sizeof (double)); finalScaleFactors->data[0] = 0.0; i0 = F_x->size[0] * F_x->size[1]; F_x->size[0] = 1; F_x->size[1] = 1; emxEnsureCapacity((emxArray__common *)F_x, i0, (int)sizeof(double)); F_x->data[0] = 0.0; i0 = F1_y1->size[0] * F1_y1->size[1]; F1_y1->size[0] = 1; F1_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y1, i0, (int)sizeof(double)); F1_y1->data[0] = 0.0; i0 = F1_y1a->size[0] * F1_y1a->size[1]; F1_y1a->size[0] = 1; F1_y1a->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y1a, i0, (int)sizeof(double)); F1_y1a->data[0] = 0.0; i0 = F1_y2->size[0] * F1_y2->size[1]; F1_y2->size[0] = 1; F1_y2->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y2, i0, (int)sizeof(double)); F1_y2->data[0] = 0.0; i0 = F1_y3->size[0] * F1_y3->size[1]; F1_y3->size[0] = 1; F1_y3->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y3, i0, (int)sizeof(double)); F1_y3->data[0] = 0.0; i0 = F1_yn->size[0] * F1_yn->size[1]; F1_yn->size[0] = 1; F1_yn->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_yn, i0, (int)sizeof(double)); F1_yn->data[0] = 0.0; i0 = F2_y1->size[0] * F2_y1->size[1]; F2_y1->size[0] = 1; F2_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F2_y1, i0, (int)sizeof(double)); F2_y1->data[0] = 0.0; i0 = F3_y1->size[0] * F3_y1->size[1]; F3_y1->size[0] = 1; F3_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F3_y1, i0, (int)sizeof(double)); F3_y1->data[0] = 0.0; i0 = F3_y2->size[0] * F3_y2->size[1]; F3_y2->size[0] = 1; F3_y2->size[1] = 1; emxEnsureCapacity((emxArray__common *)F3_y2, i0, (int)sizeof(double)); F3_y2->data[0] = 0.0; i0 = F4_y1->size[0] * F4_y1->size[1]; F4_y1->size[0] = 1; F4_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F4_y1, i0, (int)sizeof(double)); F4_y1->data[0] = 0.0; i0 = F5_y1->size[0] * F5_y1->size[1]; F5_y1->size[0] = 1; F5_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F5_y1, i0, (int)sizeof(double)); F5_y1->data[0] = 0.0; i0 = F6_y1->size[0] * F6_y1->size[1]; F6_y1->size[0] = 1; F6_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F6_y1, i0, (int)sizeof(double)); F6_y1->data[0] = 0.0; i0 = F7_y1->size[0] * F7_y1->size[1]; F7_y1->size[0] = 1; F7_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F7_y1, i0, (int)sizeof(double)); F7_y1->data[0] = 0.0; } else { b_guard1 = true; } } else { b_guard1 = true; } if (b_guard1) { /* % Greedy subset modification procedure */ /* display('Please wait...This algorithm takes a few minutes depending on the number of records to be selected'); */ minID = rtNaN; diag(covReq, recPer); d_sqrt(recPer); i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; PerTgt_tmp->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[PerTgt_tmp->size[0] * i0] = recPer->data[i0]; } i0 = PerTgt_tmp->size[0] * PerTgt_tmp->size[1]; PerTgt_tmp->size[0] = 1; PerTgt_tmp->size[1] = sa->size[1]; emxEnsureCapacity((emxArray__common *)PerTgt_tmp, i0, (int)sizeof(double)); loop_ub = sa->size[0] * sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp->data[i0] = (sa->data[i0] + rho->data[i0]) + 3.0 * PerTgt_tmp->data[i0]; } b_exp(PerTgt_tmp); for (k = 0; k < (int)nLoop; k++) { /* Number of passes */ for (i = 0; i < (int)nGM; i++) { /* Selects nSelect ground motions */ double perOut; perOut=rt_roundd_snf(((((1.0 + (real_T)k) - 1.0) * nGM +(1.0 + (real_T)i)) - 1.0) / (nLoop * nGM) * 100.0); if(perOut<=0){perOut=perOut*-1;} fprintf(stdout, "\nStep 1: Selecting Ground Motions ... complete: %.2f%%...",perOut); fflush(stdout); /* display([num2str(round(((k-1)*nGM + i-1)/(nLoop*nGM)*100)) '% done']); */ minDev = 100000.0; b_eml_null_assignment(sampleSmall, 1.0 + (double)i); eml_null_assignment(recID, 1.0 + (double)i); /* Try to add a new spectra to the subset list */ i0 = scaleFac->size[0]; scaleFac->size[0] = nBig + 1; emxEnsureCapacity((emxArray__common *)scaleFac, i0, (int)sizeof(double)); for (i0 = 0; i0 <= nBig; i0++) { scaleFac->data[i0] = 0.0; } for (j = 0; j <= nBig; j++) { if (isScaled == 1.0) { i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = posT1->size[1]; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof(double)); loop_ub = posT1->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { varT->data[varT->size[0] * i0] = sampleBig->data[j + sampleBig->size[0] * ((int)posT1->data[posT1->size[0] * i0] - 1)]; } b_exp(varT); i0 = e_varT->size[0] * e_varT->size[1]; e_varT->size[0] = 1; e_varT->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)e_varT, i0, (int)sizeof (boolean_T)); loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { e_varT->data[i0] = (varT->data[i0] == 0.0); } if (b_all(e_varT)) { scaleFac->data[j] = 1.0E+6; } else { absb = F_x->size[1] - 1; ndbl = 0; for (cdiff = 0; cdiff <= absb; cdiff++) { if (F_x->data[cdiff] == T1) { ndbl++; } } i0 = ii->size[0] * ii->size[1]; ii->size[0] = 1; ii->size[1] = ndbl; emxEnsureCapacity((emxArray__common *)ii, i0, (int)sizeof(int)); ndbl = 0; for (cdiff = 0; cdiff <= absb; cdiff++) { if (F_x->data[cdiff] == T1) { ii->data[ndbl] = cdiff + 1; ndbl++; } } i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof (double)); i0 = d_sa->size[0]; d_sa->size[0] = sa->size[1]; emxEnsureCapacity((emxArray__common *)d_sa, i0, (int)sizeof (double)); loop_ub = sa->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_sa->data[i0] = sa->data[i0] + rho->data[i0]; } loop_ub = ii->size[0] * ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { varT->data[i0] = d_sa->data[ii->data[i0] - 1]; } b_exp(varT); i0 = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; PerTgt_tmp2->size[0] = 1; PerTgt_tmp2->size[1] = ii->size[1]; emxEnsureCapacity((emxArray__common *)PerTgt_tmp2, i0, (int) sizeof(double)); loop_ub = ii->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { PerTgt_tmp2->data[PerTgt_tmp2->size[0] * i0] = sampleBig-> data[j + sampleBig->size[0] * (ii->data[ii->size[0] * i0] - 1)]; } b_exp(PerTgt_tmp2); mrdivide(varT, PerTgt_tmp2); scaleFac->data[j] = varT->data[0]; } mtmp = log(scaleFac->data[j]); loop_ub = sampleBig->size[1] - 1; i0 = d_sampleSmall->size[0] * d_sampleSmall->size[1]; d_sampleSmall->size[0] = sampleSmall->size[0] + 1; d_sampleSmall->size[1] = sampleSmall->size[1]; emxEnsureCapacity((emxArray__common *)d_sampleSmall, i0, (int) sizeof(double)); ia = sampleSmall->size[1]; for (i0 = 0; i0 < ia; i0++) { ndbl = sampleSmall->size[0]; for (ic = 0; ic < ndbl; ic++) { d_sampleSmall->data[ic + d_sampleSmall->size[0] * i0] = sampleSmall->data[ic + sampleSmall->size[0] * i0]; } } for (i0 = 0; i0 <= loop_ub; i0++) { d_sampleSmall->data[sampleSmall->size[0] + d_sampleSmall->size[0] * i0] = sampleBig->data[j + sampleBig->size[0] * i0] + mtmp; } i0 = sampleSmall->size[0] * sampleSmall->size[1]; sampleSmall->size[0] = d_sampleSmall->size[0]; sampleSmall->size[1] = d_sampleSmall->size[1]; emxEnsureCapacity((emxArray__common *)sampleSmall, i0, (int)sizeof (double)); loop_ub = d_sampleSmall->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { ia = d_sampleSmall->size[0]; for (ic = 0; ic < ia; ic++) { sampleSmall->data[ic + sampleSmall->size[0] * i0] = d_sampleSmall->data[ic + d_sampleSmall->size[0] * i0]; } } } else { loop_ub = sampleBig->size[1] - 1; i0 = c_sampleSmall->size[0] * c_sampleSmall->size[1]; c_sampleSmall->size[0] = sampleSmall->size[0] + 1; c_sampleSmall->size[1] = sampleSmall->size[1]; emxEnsureCapacity((emxArray__common *)c_sampleSmall, i0, (int) sizeof(double)); ia = sampleSmall->size[1]; for (i0 = 0; i0 < ia; i0++) { ndbl = sampleSmall->size[0]; for (ic = 0; ic < ndbl; ic++) { c_sampleSmall->data[ic + c_sampleSmall->size[0] * i0] = sampleSmall->data[ic + sampleSmall->size[0] * i0]; } } for (i0 = 0; i0 <= loop_ub; i0++) { c_sampleSmall->data[sampleSmall->size[0] + c_sampleSmall->size[0] * i0] = sampleBig->data[j + sampleBig->size[0] * i0]; } i0 = sampleSmall->size[0] * sampleSmall->size[1]; sampleSmall->size[0] = c_sampleSmall->size[0]; sampleSmall->size[1] = c_sampleSmall->size[1]; emxEnsureCapacity((emxArray__common *)sampleSmall, i0, (int)sizeof (double)); loop_ub = c_sampleSmall->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { ia = c_sampleSmall->size[0]; for (ic = 0; ic < ia; ic++) { sampleSmall->data[ic + sampleSmall->size[0] * i0] = c_sampleSmall->data[ic + c_sampleSmall->size[0] * i0]; } } scaleFac->data[j] = 1.0; } /* Compute deviations from target */ mean(sampleSmall, varT); b_std(sampleSmall, PerTgt_tmp2); diag(covReq, recPer); d_sqrt(recPer); i0 = var2->size[0] * var2->size[1]; var2->size[0] = 1; var2->size[1] = recPer->size[0]; emxEnsureCapacity((emxArray__common *)var2, i0, (int)sizeof(double)); loop_ub = recPer->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { var2->data[var2->size[0] * i0] = recPer->data[i0]; } /* devTotal = weights(1) * sum(devMean.^2) + weights(2) * sum(devSig.^2)+ weights(3) * sum(devSkew.^2); */ i0 = d_varT->size[0] * d_varT->size[1]; d_varT->size[0] = 1; d_varT->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)d_varT, i0, (int)sizeof(double)); loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { d_varT->data[i0] = varT->data[i0] - (sa->data[i0] + rho->data[i0]); } power(d_varT, varT); i0 = e_PerTgt_tmp2->size[0] * e_PerTgt_tmp2->size[1]; e_PerTgt_tmp2->size[0] = 1; e_PerTgt_tmp2->size[1] = PerTgt_tmp2->size[1]; emxEnsureCapacity((emxArray__common *)e_PerTgt_tmp2, i0, (int)sizeof (double)); loop_ub = PerTgt_tmp2->size[0] * PerTgt_tmp2->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { e_PerTgt_tmp2->data[i0] = PerTgt_tmp2->data[i0] - var2->data[i0]; } power(e_PerTgt_tmp2, PerTgt_tmp2); devTotal = weight_mean * sum(varT) + weight_sd * sum(PerTgt_tmp2); /* Penalize bad spectra (set penalty to zero if this is not required) */ if (penalty != 0.0) { for (ndbl = 0; ndbl < sampleSmall->size[0]; ndbl++) { loop_ub = sampleSmall->size[1]; i0 = varT->size[0] * varT->size[1]; varT->size[0] = 1; varT->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)varT, i0, (int)sizeof (double)); for (i0 = 0; i0 < loop_ub; i0++) { varT->data[varT->size[0] * i0] = sampleSmall->data[ndbl + sampleSmall->size[0] * i0]; } b_exp(varT); i0 = f_varT->size[0] * f_varT->size[1]; f_varT->size[0] = 1; f_varT->size[1] = varT->size[1]; emxEnsureCapacity((emxArray__common *)f_varT, i0, (int)sizeof (boolean_T)); loop_ub = varT->size[0] * varT->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { f_varT->data[i0] = (varT->data[i0] > PerTgt_tmp->data[i0]); } f_abs(f_varT, varT); devTotal += b_sum(varT) * penalty; } } /* % Penalize bad spectra (set penalty to zero if this is not required) */ /* for m=1:size(sampleSmall,1) */ /* devTotal = devTotal + sum(abs(exp(sampleSmall(m,:))>exp(meanReq+3*sqrt(diag(covReq))')),2) * penalty; */ /* end */ if ((scaleFac->data[j] > maxScale) || (soil_Vs30->data[j] == -1.0)) { devTotal += 1.0E+6; } /* Should cause improvement and record should not be repeated */ if (devTotal < minDev) { i0 = d_recID->size[0]; d_recID->size[0] = recID->size[0]; emxEnsureCapacity((emxArray__common *)d_recID, i0, (int)sizeof (boolean_T)); loop_ub = recID->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { d_recID->data[i0] = (recID->data[i0] == 1.0 + (double)j); } if (!c_any(d_recID)) { minID = 1.0 + (double)j; minDev = devTotal; } } if (1 > sampleSmall->size[0] - 1) { loop_ub = 0; } else { loop_ub = sampleSmall->size[0] - 1; } absb = sampleSmall->size[1]; i0 = e_sampleSmall->size[0] * e_sampleSmall->size[1]; e_sampleSmall->size[0] = loop_ub; e_sampleSmall->size[1] = absb; emxEnsureCapacity((emxArray__common *)e_sampleSmall, i0, (int)sizeof (double)); for (i0 = 0; i0 < absb; i0++) { for (ic = 0; ic < loop_ub; ic++) { e_sampleSmall->data[ic + e_sampleSmall->size[0] * i0] = sampleSmall->data[ic + sampleSmall->size[0] * i0]; } } i0 = sampleSmall->size[0] * sampleSmall->size[1]; sampleSmall->size[0] = e_sampleSmall->size[0]; sampleSmall->size[1] = e_sampleSmall->size[1]; emxEnsureCapacity((emxArray__common *)sampleSmall, i0, (int)sizeof (double)); loop_ub = e_sampleSmall->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { ia = e_sampleSmall->size[0]; for (ic = 0; ic < ia; ic++) { sampleSmall->data[ic + sampleSmall->size[0] * i0] = e_sampleSmall->data[ic + e_sampleSmall->size[0] * i0]; } } } if (!rtIsNaN(minID)) { /* Add new element in the right slot */ if (isScaled == 1.0) { finalScaleFactors->data[i] = scaleFac->data[(int)minID - 1]; } else { finalScaleFactors->data[i] = 1.0; } if (1.0 > (1.0 + (double)i) - 1.0) { loop_ub = 0; } else { loop_ub = (int)((1.0 + (double)i) - 1.0); } if (1.0 + (double)i > sampleSmall->size[0]) { i0 = 1; ic = 0; } else { i0 = i + 1; ic = sampleSmall->size[0]; } mtmp = log(scaleFac->data[(int)minID - 1]); absb = sampleSmall->size[1]; ia = sampleBig->size[1] - 1; ndbl = sampleSmall->size[1] - 1; apnd = b_sampleSmall->size[0] * b_sampleSmall->size[1]; b_sampleSmall->size[0] = ((loop_ub + ic) - i0) + 2; b_sampleSmall->size[1] = absb; emxEnsureCapacity((emxArray__common *)b_sampleSmall, apnd, (int) sizeof(double)); for (apnd = 0; apnd < absb; apnd++) { for (cdiff = 0; cdiff < loop_ub; cdiff++) { b_sampleSmall->data[cdiff + b_sampleSmall->size[0] * apnd] = sampleSmall->data[cdiff + sampleSmall->size[0] * apnd]; } } for (apnd = 0; apnd <= ia; apnd++) { b_sampleSmall->data[loop_ub + b_sampleSmall->size[0] * apnd] = sampleBig->data[((int)minID + sampleBig->size[0] * apnd) - 1] + mtmp; } for (apnd = 0; apnd <= ndbl; apnd++) { ia = ic - i0; for (cdiff = 0; cdiff <= ia; cdiff++) { b_sampleSmall->data[((cdiff + loop_ub) + b_sampleSmall->size[0] * apnd) + 1] = sampleSmall->data[((i0 + cdiff) + sampleSmall->size[0] * apnd) - 1]; } } i0 = sampleSmall->size[0] * sampleSmall->size[1]; sampleSmall->size[0] = b_sampleSmall->size[0]; sampleSmall->size[1] = b_sampleSmall->size[1]; emxEnsureCapacity((emxArray__common *)sampleSmall, i0, (int)sizeof (double)); loop_ub = b_sampleSmall->size[1]; for (i0 = 0; i0 < loop_ub; i0++) { ia = b_sampleSmall->size[0]; for (ic = 0; ic < ia; ic++) { sampleSmall->data[ic + sampleSmall->size[0] * i0] = b_sampleSmall->data[ic + b_sampleSmall->size[0] * i0]; } } if (1.0 > (1.0 + (double)i) - 1.0) { loop_ub = 0; } else { loop_ub = (int)((1.0 + (double)i) - 1.0); } if (1.0 + (double)i > recID->size[0]) { i0 = 1; ic = 0; } else { i0 = i + 1; ic = recID->size[0]; } apnd = e_recID->size[0]; e_recID->size[0] = ((loop_ub + ic) - i0) + 2; emxEnsureCapacity((emxArray__common *)e_recID, apnd, (int)sizeof (double)); for (apnd = 0; apnd < loop_ub; apnd++) { e_recID->data[apnd] = recID->data[apnd]; } e_recID->data[loop_ub] = minID; ia = ic - i0; for (ic = 0; ic <= ia; ic++) { e_recID->data[(ic + loop_ub) + 1] = recID->data[(i0 + ic) - 1]; } i0 = recID->size[0]; recID->size[0] = e_recID->size[0]; emxEnsureCapacity((emxArray__common *)recID, i0, (int)sizeof(double)); loop_ub = e_recID->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { recID->data[i0] = e_recID->data[i0]; } } } } /* display('100% done'); */ printf("\nStep 1: Selecting Ground Motions ... complete: 100%%"); if (recID->size[0] == 0) { *errCode = 3391.0; /* 'Error: no match spectra found' */ i0 = finalRecords->size[0]; finalRecords->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalRecords, i0, (int)sizeof (double)); finalRecords->data[0] = 0.0; i0 = finalScaleFactors->size[0]; finalScaleFactors->size[0] = 1; emxEnsureCapacity((emxArray__common *)finalScaleFactors, i0, (int)sizeof (double)); finalScaleFactors->data[0] = 0.0; i0 = F_x->size[0] * F_x->size[1]; F_x->size[0] = 1; F_x->size[1] = 1; emxEnsureCapacity((emxArray__common *)F_x, i0, (int)sizeof(double)); F_x->data[0] = 0.0; i0 = F1_y1->size[0] * F1_y1->size[1]; F1_y1->size[0] = 1; F1_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y1, i0, (int)sizeof(double)); F1_y1->data[0] = 0.0; i0 = F1_y1a->size[0] * F1_y1a->size[1]; F1_y1a->size[0] = 1; F1_y1a->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y1a, i0, (int)sizeof(double)); F1_y1a->data[0] = 0.0; i0 = F1_y2->size[0] * F1_y2->size[1]; F1_y2->size[0] = 1; F1_y2->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y2, i0, (int)sizeof(double)); F1_y2->data[0] = 0.0; i0 = F1_y3->size[0] * F1_y3->size[1]; F1_y3->size[0] = 1; F1_y3->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_y3, i0, (int)sizeof(double)); F1_y3->data[0] = 0.0; i0 = F1_yn->size[0] * F1_yn->size[1]; F1_yn->size[0] = 1; F1_yn->size[1] = 1; emxEnsureCapacity((emxArray__common *)F1_yn, i0, (int)sizeof(double)); F1_yn->data[0] = 0.0; i0 = F2_y1->size[0] * F2_y1->size[1]; F2_y1->size[0] = 1; F2_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F2_y1, i0, (int)sizeof(double)); F2_y1->data[0] = 0.0; i0 = F3_y1->size[0] * F3_y1->size[1]; F3_y1->size[0] = 1; F3_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F3_y1, i0, (int)sizeof(double)); F3_y1->data[0] = 0.0; i0 = F3_y2->size[0] * F3_y2->size[1]; F3_y2->size[0] = 1; F3_y2->size[1] = 1; emxEnsureCapacity((emxArray__common *)F3_y2, i0, (int)sizeof(double)); F3_y2->data[0] = 0.0; i0 = F4_y1->size[0] * F4_y1->size[1]; F4_y1->size[0] = 1; F4_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F4_y1, i0, (int)sizeof(double)); F4_y1->data[0] = 0.0; i0 = F5_y1->size[0] * F5_y1->size[1]; F5_y1->size[0] = 1; F5_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F5_y1, i0, (int)sizeof(double)); F5_y1->data[0] = 0.0; i0 = F6_y1->size[0] * F6_y1->size[1]; F6_y1->size[0] = 1; F6_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F6_y1, i0, (int)sizeof(double)); F6_y1->data[0] = 0.0; i0 = F7_y1->size[0] * F7_y1->size[1]; F7_y1->size[0] = 1; F7_y1->size[1] = 1; emxEnsureCapacity((emxArray__common *)F7_y1, i0, (int)sizeof(double)); F7_y1->data[0] = 0.0; } else { /* Output information */ i0 = finalRecords->size[0]; finalRecords->size[0] = recID->size[0]; emxEnsureCapacity((emxArray__common *)finalRecords, i0, (int)sizeof (double)); loop_ub = recID->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { finalRecords->data[i0] = idRef->data[(int)RSN->data[(int)recID-> data[i0] - 1] - 1]; } i0 = finalDirectios->size[0]; finalDirectios->size[0] = recID->size[0]; emxEnsureCapacity((emxArray__common *)finalDirectios, i0, (int)sizeof (double)); loop_ub = recID->size[0]; for (i0 = 0; i0 < loop_ub; i0++) { finalDirectios->data[i0] = 1.0; } for (i = 0; i < recID->size[0]; i++) { if ((int)recID->data[i] > Sa_1->size[0]) { finalDirectios->data[i] = 2.0; } } /* % Spectra Plots */ repmat(finalScaleFactors, SaKnown->size[1], d_a); loop_ub = SaKnown->size[1]; i0 = F4_y1->size[0] * F4_y1->size[1]; F4_y1->size[0] = recID->size[0]; F4_y1->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)F4_y1, i0, (int)sizeof(double)); for (i0 = 0; i0 < loop_ub; i0++) { ia = recID->size[0]; for (ic = 0; ic < ia; ic++) { F4_y1->data[ic + F4_y1->size[0] * i0] = SaKnown->data[((int) recID->data[ic] + SaKnown->size[0] * i0) - 1] * d_a->data[ic + d_a->size[0] * i0]; } } loop_ub = sampleBig->size[1]; i0 = F5_y1->size[0] * F5_y1->size[1]; F5_y1->size[0] = recID->size[0]; F5_y1->size[1] = loop_ub; emxEnsureCapacity((emxArray__common *)F5_y1, i0, (int)sizeof(double)); for (i0 = 0; i0 < loop_ub; i0++) { ia = recID->size[0]; for (ic = 0; ic < ia; ic++) { F5_y1->data[ic + F5_y1->size[0] * i0] = sampleBig->data[((int) recID->data[ic] + sampleBig->size[0] * i0) - 1]; } } c_exp(F5_y1); repmat(finalScaleFactors, F_x->size[1], d_a); i0 = F5_y1->size[0] * F5_y1->size[1]; emxEnsureCapacity((emxArray__common *)F5_y1, i0, (int)sizeof(double)); ndbl = F5_y1->size[0]; cdiff = F5_y1->size[1]; loop_ub = ndbl * cdiff; for (i0 = 0; i0 < loop_ub; i0++) { F5_y1->data[i0] *= d_a->data[i0]; } mean(sampleSmall, F6_y1); b_exp(F6_y1); b_std(sampleSmall, F7_y1); } } emxFree_real_T(&e_sampleSmall); emxFree_real_T(&d_sampleSmall); emxFree_real_T(&d_sa); emxFree_real_T(&c_sampleSmall); emxFree_real_T(&e_recID); emxFree_real_T(&b_sampleSmall); emxFree_boolean_T(&c_recID); emxFree_boolean_T(&b_recPer); emxFree_boolean_T(&f_varT); emxFree_boolean_T(&e_varT); emxFree_real_T(&d_varT); emxFree_real_T(&e_PerTgt_tmp2); emxFree_boolean_T(&d_recID); emxFree_real_T(&scaleFac); emxFree_real_T(&sampleSmall); } emxFree_real_T(&d_a); emxFree_int32_T(&ii); emxFree_boolean_T(&x); emxFree_real_T(&sampleBig); emxFree_real_T(&recPer); emxFree_real_T(&tempf); emxFree_real_T(&varT); emxFree_real_T(&var2); emxFree_real_T(&covReq); emxFree_real_T(&rho); emxFree_real_T(&sa); emxFree_real_T(&posT1); emxFree_real_T(&PerTgt_tmp2); emxFree_real_T(&PerTgt_tmp); emxFree_real_T(&soil_Vs30); emxFree_real_T(&RSN); emxFree_real_T(&SaKnown); emxFree_real_T(&recID); /* if (showPlots) */ /* */ /* % Variables used here */ /* */ /* % SaKnown : As before, it contains the response spectra of all the */ /* % available ground motions (N*P matrix) - N ground motions, */ /* % P periods */ /* % sampleBig : Same as SaKnown, but is only defined at PerTgt, the */ /* % periods at which the target response spectrum properties */ /* % are computed */ /* % sampleSmall: The response spectra of the selected ground motions, */ /* % defined at PerTgt */ /* % meanReq : Target mean for the (log) response spectrum */ /* % covReq : Target covariance for the (log) response spectrum */ /* % */ /* */ /* */ /* % Plot at all periods */ /* figure */ /* loglog(PerTgt, exp(meanReq), 'b', 'linewidth', 3) */ /* hold on */ /* loglog(PerTgt, exp(meanReq + 1.96*sqrt(diag(covReq))'), '--b', 'linewidth', 3) */ /* loglog(perKnown,SaKnown(finalRecords,:).*repmat(finalScaleFactors,1,size(SaKnown,2)),'k'); */ /* loglog(PerTgt, exp(meanReq - 1.96*sqrt(diag(covReq))'), '--b', 'linewidth', 3) */ /* axis([min(PerTgt) max(PerTgt) 1e-2 5]) */ /* xlabel('T (s)'); */ /* ylabel('S_a (g)'); */ /* legend('Median response spectrum','2.5 and 97.5 percentile response spectra','Response spectra of selected ground motions'); */ /* title ('Response spectra of selected ground motions'); */ /* */ /* % Plot spectra only at periods where error is minimized */ /* figure */ /* loglog(PerTgt, exp(meanReq), 'b', 'linewidth', 3) */ /* hold on */ /* loglog(PerTgt, exp(meanReq + 1.96*sqrt(diag(covReq))'), '--b', 'linewidth', 3) */ /* loglog(PerTgt,exp(sampleBig(finalRecords,:)).*repmat(finalScaleFactors,1,length(PerTgt)),'color',[0.5 0.5 0.5],'linewidth',1) */ /* loglog(PerTgt, exp(meanReq - 1.96*sqrt(diag(covReq))'), '--b', 'linewidth', 3) */ /* axis([min(PerTgt) max(PerTgt) 1e-2 5]) */ /* xlabel('T (s)'); */ /* ylabel('S_a (g)'); */ /* legend('Median response spectrum','2.5 and 97.5 percentile response spectra','Response spectra of selected ground motions'); */ /* title ('Response spectra of selected ground motions at periods where error is minimized'); */ /* */ /* % Sample and target means */ /* figure */ /* loglog(PerTgt,exp(meanReq),'k','linewidth',1) */ /* hold on */ /* loglog(PerTgt,exp(mean(sampleSmall)),'b--','linewidth',1) */ /* axis([min(PerTgt) max(PerTgt) 1e-2 5]) */ /* xlabel('T (s)') */ /* ylabel('Median S_a (g)') */ /* legend('exp(Target mean lnS_a)','exp(Mean of selected lnS_a)') */ /* title('Target and sample exponential logarithmic means (i.e., medians)') */ /* */ /* % Sample and target standard deviations */ /* figure */ /* semilogx(PerTgt,sqrt(diag(covReq))','k','linewidth',1) */ /* hold on */ /* semilogx(PerTgt,std(sampleSmall),'b--','linewidth',1) */ /* axis([min(PerTgt) max(PerTgt) 0 1]) */ /* xlabel('T (s)') */ /* ylabel('Standard deviation of lnS_a') */ /* legend('Target standard deviation of lnS_a','Standard deviation of selected lnS_a') */ /* title('Target and sample logarithmic standard deviations') */ /* */ /* end */ /* % Output data to file (best viewed with textpad) */ /* fin = fopen(outputFile,'w'); */ /* fprintf(fin,'%s \t %s \t %s \t %s \n','Record Number','Scale Factor','File Name','URL'); % Title of relevant outputs */ /* for i = 1 : length(finalRecords) */ /* rec = finalRecords(i); */ /* url = ['http://peer.berkeley.edu/nga_files/ath/' Filename{rec}(1:end-3) 'AT2']; % URL of selected record */ /* fprintf(fin,'%d \t %6.2f \t %s \t %s \n',i,finalScaleFactors(i),Filename{rec},url); % Print relevant outputs */ /* end */ /* */ /* fclose(fin); */ } /* * Arguments : void * Return Type : void */ void Select_Ground_Motions_initialize(void) { rt_InitInfAndNaN(8U); eml_rand_init(); eml_rand_mcg16807_stateful_init(); eml_rand_shr3cong_stateful_init(); c_eml_rand_mt19937ar_stateful_i(); } /* * Arguments : void * Return Type : void */ void Select_Ground_Motions_terminate(void) { /* (no terminate code required) */ } /* * Arguments : int numDimensions * int *size * Return Type : emxArray_real_T * */ emxArray_real_T *emxCreateND_real_T(int numDimensions, int *size) { emxArray_real_T *emx; int numEl; int i; emxInit_real_T(&emx, numDimensions); numEl = 1; for (i = 0; i < numDimensions; i++) { numEl *= size[i]; emx->size[i] = size[i]; } emx->data = (double *)calloc((unsigned int)numEl, sizeof(double)); emx->numDimensions = numDimensions; emx->allocatedSize = numEl; return emx; } /* * Arguments : double *data * int numDimensions * int *size * Return Type : emxArray_real_T * */ emxArray_real_T *emxCreateWrapperND_real_T(double *data, int numDimensions, int * size) { emxArray_real_T *emx; int numEl; int i; emxInit_real_T(&emx, numDimensions); numEl = 1; for (i = 0; i < numDimensions; i++) { numEl *= size[i]; emx->size[i] = size[i]; } emx->data = data; emx->numDimensions = numDimensions; emx->allocatedSize = numEl; emx->canFreeData = false; return emx; } /* * Arguments : double *data * int rows * int cols * Return Type : emxArray_real_T * */ emxArray_real_T *emxCreateWrapper_real_T(double *data, int rows, int cols) { emxArray_real_T *emx; int size[2]; int numEl; int i; size[0] = rows; size[1] = cols; emxInit_real_T(&emx, 2); numEl = 1; for (i = 0; i < 2; i++) { numEl *= size[i]; emx->size[i] = size[i]; } emx->data = data; emx->numDimensions = 2; emx->allocatedSize = numEl; emx->canFreeData = false; return emx; } /* * Arguments : int rows * int cols * Return Type : emxArray_real_T * */ emxArray_real_T *emxCreate_real_T(int rows, int cols) { emxArray_real_T *emx; int size[2]; int numEl; int i; size[0] = rows; size[1] = cols; emxInit_real_T(&emx, 2); numEl = 1; for (i = 0; i < 2; i++) { numEl *= size[i]; emx->size[i] = size[i]; } emx->data = (double *)calloc((unsigned int)numEl, sizeof(double)); emx->numDimensions = 2; emx->allocatedSize = numEl; return emx; } /* * Arguments : emxArray_real_T *emxArray * Return Type : void */ void emxDestroyArray_real_T(emxArray_real_T *emxArray) { emxFree_real_T(&emxArray); } /* * Arguments : emxArray_real_T **pEmxArray * int numDimensions * Return Type : void */ void emxInitArray_real_T(emxArray_real_T **pEmxArray, int numDimensions) { emxInit_real_T(pEmxArray, numDimensions); } /* * File trailer for Select_Ground_Motions.c * * [EOF] */