/* nag_mv_z_scores (g03zac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 8 revised, 2004. * */ #include #include #include #include #define X(I, J) x[(I) *tdx + J] #define Z(I, J) z[(I) *tdz + J] int main(void) { Integer exit_status = 0, i, *isx = 0, j, m, n, nvar, tdx, tdz; NagError fail; double *e = 0, *s = 0, *x = 0, *z = 0; INIT_FAIL(fail); printf("nag_mv_z_scores (g03zac) Example Program Results\n\n"); /* Skip headings in data file */ scanf("%*[^\n]"); scanf("%ld", &n); scanf("%ld", &m); scanf("%ld", &nvar); if (n >= 1 && nvar >= 1 && m >= nvar) { if (!(e = NAG_ALLOC(m, double)) || !(s = NAG_ALLOC(m, double)) || !(x = NAG_ALLOC((n)*(m), double)) || !(z = NAG_ALLOC((n)*(nvar), double)) || !(isx = NAG_ALLOC(m, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } tdx = m; tdz = nvar; } else { printf("Invalid n or nvar.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) scanf("%lf", &X(i, j)); } for (j = 0; j < m; ++j) scanf("%ld", &isx[j]); for (j = 0; j < m; ++j) scanf("%lf", &e[j]); for (j = 0; j < m; ++j) scanf("%lf", &s[j]); /* nag_mv_z_scores (g03zac). * Standardize values of a data matrix */ nag_mv_z_scores(n, m, x, tdx, nvar, isx, s, e, z, tdz, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_mv_z_scores (g03zac).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\nStandardized Values\n\n"); for (i = 0; i < n; ++i) { for (j = 0; j < nvar; ++j) printf("%8.3f", Z(i, j)); printf("\n"); } END: if (e) NAG_FREE(e); if (s) NAG_FREE(s); if (x) NAG_FREE(x); if (z) NAG_FREE(z); if (isx) NAG_FREE(isx); return exit_status; }