/* nag_tsa_multi_inp_model_forecast (g13bjc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include #include static int ex1(void); static int ex2(void); int main(void) { Integer exit_status_ex1=0; Integer exit_status_ex2=0; /* Two examples are called, ex1() which uses the * default settings to solve the problem and * ex2() which solves the same problem with * some optional parameters set by the user. */ Vprintf("nag_tsa_multi_inp_model_forecast (g13bjc) Example Program " "Results\n"); Vscanf(" %*[^\n]"); /* Skip heading in data file */ exit_status_ex1 = ex1(); exit_status_ex2 = ex2(); return exit_status_ex1 == 0 && exit_status_ex2 == 0 ? 0 : 1; } #define PARX(I,J) parx[(I)*tdparx + J] #define XXY(I,J) xxy[(I)*tdxxy + J] #define MRX(I,J) mrx[(I)*tdmrx + J] static int ex1(void) { Integer exit_status=0, i, inser, j, ldparx, *mrx=0, n, nev, nfv, npara; Integer nseries, tdmrx, tdparx, tdxxy; NagError fail; Nag_ArimaOrder arimav; Nag_TransfOrder transfv; double *fsd=0, *fva=0, *para=0, *parx=0, *rmsxy=0, *xxy=0; INIT_FAIL(fail); Vprintf("\nnag_tsa_multi_inp_model_forecast (g13bjc) example 1: no option " "setting.\n\n"); /* Skip heading in data file */ Vscanf(" %*[^\n]"); Vscanf("%ld%ld%ld", &nev, &nfv, &nseries); if (nseries>0 && nseries >=1 && nev>0 && nfv>0) { /* * Allocate memory to the arrays in structure transfv containing * the transfer function model orders of the input series. */ /* nag_tsa_transf_orders (g13byc). * Allocates memory to transfer function model orders */ nag_tsa_transf_orders(nseries, &transfv, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_transf_orders (g13byc).\n%s\n", fail.message); exit_status = 1; goto END; } /* * Read the orders vector of the ARIMA model for the output noise * component into structure arimav. */ Vscanf("%ld%ld%ld%ld%ld" "%ld%ld", &arimav.p, &arimav.d, &arimav.q, &arimav.bigp, &arimav.bigd, &arimav.bigq, &arimav.s); /* * Read the transfer function model orders of the input series into * structure transfv. */ inser = nseries - 1; for (j=0; j=1) { if ( !( fsd = NAG_ALLOC(nfv, double)) || !( fva = NAG_ALLOC(nfv, double)) || !( para = NAG_ALLOC(npara, double)) || !( parx = NAG_ALLOC(ldparx*(nseries-1), double)) || !( rmsxy = NAG_ALLOC(nseries, double)) || !( xxy = NAG_ALLOC((nev+nfv)*nseries, double)) || !( mrx = NAG_ALLOC(7*(nseries-1), Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdmrx = nseries-1; tdparx = nseries-1; tdxxy = nseries; for (i=0; i0 && nev>0 && nfv>0) { /* * Set option variable to the desired value. */ options.cfixed = Nag_TRUE; /* * Allocate memory to the arrays in structure transfv containing * the transfer function model orders of the input series. */ /* nag_tsa_transf_orders (g13byc), see above. */ nag_tsa_transf_orders(nseries, &transfv, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_transf_orders (g13byc).\n%s\n", fail.message); exit_status = 1; goto END; } /* * Read the orders vector of the ARIMA model for the output noise * component into structure arimav. */ Vscanf("%ld%ld%ld%ld%ld" "%ld%ld", &arimav.p, &arimav.d, &arimav.q, &arimav.bigp, &arimav.bigd, &arimav.bigq, &arimav.s); /* * Read the transfer function model orders of the input series into * structure transfv. */ inser = nseries - 1; for (j=0; j=1) { if ( !( fsd = NAG_ALLOC(nfv, double)) || !( fva = NAG_ALLOC(nfv, double)) || !( para = NAG_ALLOC(npara, double)) || !( parx = NAG_ALLOC(ldparx*(nseries-1), double)) || !( rmsxy = NAG_ALLOC(nseries, double)) || !( xxy = NAG_ALLOC((nev+nfv)*(nseries), double)) || !( mrx = NAG_ALLOC(7*(nseries-1), Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdmrx = nseries-1; tdparx = nseries-1; tdxxy = nseries; for (i=0; i