/* nag_tsa_spectrum_bivar_cov (g13ccc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ double pxy; Integer exit_status, i, ic, ii, ish, iw, kc, lf, mw, nc, ng, nxy, nxyg; /* Arrays */ double *cxy = 0, *cyx = 0, *xg = 0, *yg = 0; Complex *g = 0; NagMeanOrTrend mtxy; NagError fail; INIT_FAIL(fail); exit_status = 0; Vprintf("g13ccc Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%ld%*[^\n] ", &nxy, &nc, &ic); if (nxy > 0 && nc > 0) { /* Set parameters for call to g13ccc */ /* Mean correction and 10 percent taper */ mtxy = Nag_Mean; pxy = 0.1; /* Parzen window and zero covariance at lag 35 */ iw = 4; mw = 35; /* Alignment shift of 3, 50 covariances to be calculated */ ish = 3; kc = 350; lf = 80; if (ic == 0) nxyg = MAX(kc, lf); else nxyg = lf; /* Allocate arrays xg, yg, cxy and cyx */ if ( !(xg = NAG_ALLOC(nxyg, double)) || !(yg = NAG_ALLOC(nxyg, double)) || !(cxy = NAG_ALLOC(nc, double)) || !(cyx = NAG_ALLOC(nc, double)) || !(g = NAG_ALLOC((lf/2)+1, Complex))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } if (ic == 0) { for (i = 1; i <= nxy; ++i) Vscanf("%lf", &xg[i-1]); Vscanf("%*[^\n] "); for (i = 1; i <= nxy; ++i) Vscanf("%lf", &yg[i-1]); Vscanf("%*[^\n] "); } else { for (i = 1; i <= nc; ++i) Vscanf("%lf", &cxy[i-1]); Vscanf("%*[^\n] "); for (i = 1; i <= nc; ++i) Vscanf("%lf", &cyx[i-1]); Vscanf("%*[^\n] "); } g13ccc(nxy, mtxy, pxy, iw, mw, ish, ic, nc, cxy, cyx, kc, lf, xg, yg, g, &ng, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g13ccc.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Returned cross covariances\n"); Vprintf("\n"); Vprintf(" Lag XY YX Lag XY YX Lag XY YX\n"); for (i = 1; i <= nc; i += 3) { for (ii = i; ii <= MIN(i+2, nc); ++ii) Vprintf("%4ld%9.4f%9.4f ", ii-1, cxy[ii-1], cyx[ii-1]); Vprintf("\n"); } Vprintf("\n"); Vprintf(" Returned sample spectrum\n"); Vprintf("\n"); Vprintf(" Real Imaginary Real Imaginary " " Real Imaginary\n"); Vprintf(" Lag part part Lag part part Lag" " part part\n"); for (i = 1; i <= ng; i += 3) { for (ii = i; ii <= MIN(i+2, ng); ++ii) Vprintf("%4ld%9.4f%9.4f ", ii-1, g[ii-1].re, g[ii-1].im); Vprintf("\n"); } } END: if (cxy) NAG_FREE(cxy); if (cyx) NAG_FREE(cyx); if (xg) NAG_FREE(xg); if (yg) NAG_FREE(yg); if (g) NAG_FREE(g); return exit_status; }