/* nag_tsa_resid_corr (g13asc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { double chi, df, objf, *par=0, *r=0, *rc=0, *res, s, *sd=0, siglev; double *x=0; Integer i, idf, j, m, *mr=0, narma, ni, npar, nres; Integer nx, nseries; Integer exit_status=0; Nag_ArimaOrder arimav; Nag_TransfOrder transfv; Nag_G13_Opt options; NagError fail; INIT_FAIL(fail); Vprintf("g13asc Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld%*[^\n]", &nx); if (!(x = NAG_ALLOC(nx, double)) || !(mr = NAG_ALLOC(7, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nx; ++i) Vscanf("%lf", &x[i - 1]); Vscanf("%*[^\n]"); for (i = 1; i <= 7; ++i) Vscanf("%ld", &mr[i - 1]); Vscanf("%*[^\n]"); npar = mr[0] + mr[2] + mr[3] + mr[5] + 1; if (!(par = NAG_ALLOC(npar, double)) || !(sd = NAG_ALLOC(npar, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= npar; ++i) par[i - 1] = 0.0; nseries = 1; arimav.p = mr[0]; arimav.d = mr[1]; arimav.q = mr[2]; arimav.bigp = mr[3] ; arimav.bigd = mr[4] ; arimav.bigq = mr[5] ; arimav.s = mr[6] ; g13bxc(&options); g13byc(nseries, &transfv, &fail); g13bec(&arimav, nseries, &transfv, par, npar, nx, x, nseries, sd, &s, &objf, &df, &options, &fail); nres = options.lenres; res = options.res; if (fail.code != NE_NOERROR) { Vprintf("Error from g13bec.\n%s\n", fail.message); exit_status = 1; goto END; } m = 10; if (!(r = NAG_ALLOC(m, double)) || !(rc = NAG_ALLOC(m*m, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } narma = mr[0] + mr[2] + mr[3] + mr[5]; g13asc(&arimav, nres, res, m, par, narma, r, rc, m, &chi, &idf, &siglev, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g13asc.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\nRESIDUAL AUTOCORRELATION FUNCTION"); Vprintf("\n---------------------------------\n\n"); for (j=0; j<=(m-1)/7; j++) { ni = MIN(7,m - j*7); Vprintf("LAG K "); for (i=0; i