/* nag_tsa_cross_corr (g13bcc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ double r0xy, r0yx, statxy, statyx, sxy, syx; Integer exit_status, i, nl, nxy; NagError fail; /* Arrays */ double *rxy = 0, *ryx = 0, *x = 0, *y = 0; INIT_FAIL(fail); exit_status = 0; Vprintf("g13bcc Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read series length and number of lags */ Vscanf("%ld%ld%*[^\n] ", &nxy, &nl); /* Allocate memory */ if ( !(rxy = NAG_ALLOC(nl, double)) || !(ryx = NAG_ALLOC(nl, double)) || !(x = NAG_ALLOC(nxy, double)) || !(y = NAG_ALLOC(nxy, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Read series */ for (i = 1; i <= nxy; ++i) Vscanf("%lf", &x[i-1]); Vscanf("%*[^\n] "); for (i = 1; i <= nxy; ++i) Vscanf("%lf", &y[i-1]); Vscanf("%*[^\n] "); /* Call routine to calculate cross correlations between X and Y */ g13bcc(x, y, nxy, nl, &sxy, &r0xy, rxy, &statxy, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g13bcc, 1st call.\n%s\n", fail.message); exit_status = 1; goto END; } /* Call routine to calculate cross correlations between Y and X */ g13bcc(y, x, nxy, nl, &syx, &r0yx, ryx, &statyx, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g13bcc, 2nd call.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Between Between\n"); Vprintf(" X and Y Y and X\n"); Vprintf("\n"); Vprintf("Standard deviation ratio%10.4f%15.4f\n", sxy, syx); Vprintf("\n"); Vprintf("Cross correlation at lag\n"); Vprintf(" 0"); Vprintf("%10.4f%15.4f\n", r0xy, r0yx); for (i = 1; i <= nl; ++i) Vprintf(" %4ld%10.4f%15.4f\n", i, rxy[i-1], ryx[i-1]); Vprintf("\n"); Vprintf("Test statistic %10.4f%15.4f\n", statxy, statyx); END: if (rxy) NAG_FREE(rxy); if (ryx) NAG_FREE(ryx); if (x) NAG_FREE(x); if (y) NAG_FREE(y); return exit_status; }