/* 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); Vprintf("nag_mv_z_scores (g03zac) Example Program Results\n\n"); /* Skip headings in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&n); Vscanf("%ld",&m); Vscanf("%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)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdx=m; tdz=nvar; } else { Vprintf("Invalid n or nvar.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&X(i,j)); } for (j = 0; j < m; ++j) Vscanf("%ld",&isx[j]); for (j = 0; j < m; ++j) Vscanf("%lf",&e[j]); for (j = 0; j < m; ++j) Vscanf("%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) { Vprintf("Error from nag_mv_z_scores (g03zac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\nStandardized Values\n\n"); for (i = 0; i < n; ++i) { for (j = 0; j < nvar; ++j) Vprintf("%8.3f",Z(i,j)); Vprintf("\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; }