/* nag_durbin_watson_stat (g02fcc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double d, pdl, pdu; Integer exit_status, i, p, n; NagError fail; /* Arrays */ double *res = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); exit_status = 0; fprintf(fpout, "nag_durbin_watson_stat (g02fcc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &p); n = 10; /* Allocate memory */ if (!(res = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &res[i - 1]); fscanf(fpin, "%*[^\n] "); /* nag_durbin_watson_stat (g02fcc). * Computes Durbin-Watson test statistic */ nag_durbin_watson_stat(n, p, res, &d, &pdl, &pdu, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_durbin_watson_stat (g02fcc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " Durbin-Watson statistic %10.4f\n\n", d); fprintf(fpout, " Lower and upper bound %10.4f%10.4f\n", pdl, pdu); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (res) NAG_FREE(res); return exit_status; }