/* nag_tsa_spectrum_univar_cov (g13cac) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. * Mark 7b revised, 2004. */ #include #include #include #include int main(void) { /* Scalars */ double px; Integer exit_status, i, ic, iw, kc, lf, mtx, mw, nc, ng, nx, nxg; NagError fail; /* Arrays */ double *c = 0, *xg = 0; double stats[4]; INIT_FAIL(fail); exit_status = 0; Vprintf("nag_tsa_spectrum_univar_cov (g13cac) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%*[^\n] ", &nx, &nc); if (nx > 0 && nc > 0) { mtx = 1; px = 0.1; iw = 4; mw = 100; ic = 0; kc = 360; lf = 200; if (ic == 0) nxg = MAX(kc, lf); else nxg = lf; /* Allocate memory */ if ( !(c = NAG_ALLOC(nc, double)) || !(xg = NAG_ALLOC(nxg, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nx; ++i) Vscanf("%lf", &xg[i-1]); Vscanf("%*[^\n] "); /* nag_tsa_spectrum_univar_cov (g13cac). * Univariate time series, smoothed sample spectrum using * rectangular, Bartlett, Tukey or Parzen lag window */ nag_tsa_spectrum_univar_cov(nx, mtx, px, iw, mw, ic, nc, c, kc, lf, Nag_Unlogged, nxg, xg, &ng, stats, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_spectrum_univar_cov (g13cac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("Covariances\n"); for (i = 1; i <= nc; ++i) { Vprintf("%11.4f", c[i-1]); if (i % 6 == 0 || i == nc) Vprintf("\n"); } Vprintf("\n"); Vprintf("Degrees of freedom =%4.1f Bandwidth =%7.4f\n", stats[0], stats[3]); Vprintf("\n"); Vprintf("95 percent confidence limits - Lower =%7.4f " "Upper =%7.4f\n", stats[1], stats[2]); Vprintf("\n"); Vprintf(" Spectrum Spectrum Spectrum" " Spectrum\n"); Vprintf(" estimate estimate estimate" " estimate\n"); for (i = 1; i <= ng; ++i) { Vprintf("%4ld%10.4f", i, xg[i-1]); if (i % 4 == 0 || i == ng) Vprintf("\n"); } } END: if (c) NAG_FREE(c); if (xg) NAG_FREE(xg); return exit_status; }