/* nag_tsa_diff (g13aac) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer exit_status, i, d, ds, s, nx, nxd; NagError fail; /* Arrays */ double *x = 0, *xd = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); exit_status = 0; fprintf(fpout, "nag_tsa_diff (g13aac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%ld%ld%ld%*[^\n] ", &nx, &d, &ds, &s); if (nx > 0) { /* Allocate memory */ if (!(x = NAG_ALLOC(nx, double)) || !(xd = NAG_ALLOC(nx, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nx; ++i) fscanf(fpin, "%lf", &x[i-1]); fscanf(fpin, "%*[^\n] "); fprintf(fpout, "\n"); fprintf(fpout, "Non-seasonal differencing of order %ld " "and seasonal differencing\nof order %ld " "with seasonality %ld are applied\n", d, ds, s); /* nag_tsa_diff (g13aac). * Univariate time series, seasonal and non-seasonal * differencing */ nag_tsa_diff(x, nx, d, ds, s, xd, &nxd, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_tsa_diff (g13aac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, "The output array holds %2ld values, of which the " "first %2ld are differenced values\n\n", nx, nxd); for (i = 1; i <= nx; ++i) { fprintf(fpout, "%10.1f", xd[i-1]); if (i % 5 == 0 || i == nx) fprintf(fpout, "\n"); } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (xd) NAG_FREE(xd); return exit_status; }