/* nag_tsa_multi_diff (g13dlc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, j, k, maxd, mind, n, nd, ik, nw, pdw, pddelta, pdz; NagError fail; /* Arrays */ double *delta = 0, *w = 0, *z = 0; Integer *id = 0, *tr=0; #define W(I,J) w[(J-1)*pdw + I - 1] #define DELTA(I,J) delta[(J-1)*pddelta + I - 1] #define Z(I,J) z[(J-1)*pdz + I - 1] INIT_FAIL(fail); exit_status = 0; Vprintf("nag_tsa_multi_diff (g13dlc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%*[^\n] ", &k, &n); if (k > 0 && n > 0) { ik = k; /* Allocate array id */ if ( !(id = NAG_ALLOC(k, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= k; ++i) Vscanf("%ld", &id[i-1]); Vscanf("%*[^\n] "); mind = 0; maxd = 0; for (i = 1; i <= k; ++i) { mind = MIN(mind, id[i-1]); maxd = MAX(maxd, id[i-1]); } if (mind >= 0) { /* Allocate arrays */ nw = n - maxd; if ( !(tr = NAG_ALLOC(k, Integer)) || !(delta = NAG_ALLOC(ik * maxd, double)) || !(w = NAG_ALLOC(ik * nw, double)) || !(z = NAG_ALLOC(ik * n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } pdw = ik; pddelta = ik; pdz = ik; for (i = 1; i <= k; ++i) { for (j = 1; j <= n; ++j) Vscanf("%lf", &Z(i,j)); Vscanf("%*[^\n] "); } for (i = 1; i <= k; ++i) Vscanf("%ld", &tr[i-1]); Vscanf("%*[^\n] "); if (maxd > 0) { for (i = 1; i <= k; ++i) { for (j = 1; j <= id[i-1]; ++j) Vscanf("%lf", &DELTA(i,j)); Vscanf("%*[^\n] "); } } /* nag_tsa_multi_diff (g13dlc). * Multivariate time series, differences and/or transforms */ nag_tsa_multi_diff(k, n, z, tr, id, delta, w, &nd, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_multi_diff (g13dlc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Transformed/Differenced series\n"); Vprintf(" ------------------------------\n"); for (i = 1; i <= k; ++i) { Vprintf("\n"); Vprintf(" Series %2ld\n", i); Vprintf(" -----------\n"); Vprintf("\n"); Vprintf(" Number of differenced values = %6ld\n", nd); Vprintf("\n"); for (j = 1; j <= nd; ++j) { Vprintf("%10.3f", W(i,j)); if (j % 8 == 0 || j == nd) Vprintf("\n"); } } } } END: if (tr) NAG_FREE(tr); if (delta) NAG_FREE(delta); if (w) NAG_FREE(w); if (z) NAG_FREE(z); if (id) NAG_FREE(id); return exit_status; }