NAG Library Manual, Mark 27.3
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_correg_linregm_stat_durbwat (g02fcc) Example Program.
 *
 * Copyright 2021 Numerical Algorithms Group.
 *
 * Mark 27.3, 2021.
 */

#include <nag.h>
#include <stdio.h>

int main(void) {
  /* Scalars */
  double d, pdl, pdu;
  Integer exit_status, i, p, n;
  NagError fail;

  /* Arrays */
  double *res = 0;

  INIT_FAIL(fail);

  exit_status = 0;
  printf("nag_correg_linregm_stat_durbwat (g02fcc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "%*[^\n] ", &p);
  n = 10;

  /* Allocate memory */
  if (!(res = NAG_ALLOC(n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  for (i = 1; i <= n; ++i)
    scanf("%lf", &res[i - 1]);
  scanf("%*[^\n] ");

  /* nag_correg_linregm_stat_durbwat (g02fcc).
   * Computes Durbin-Watson test statistic
   */
  nag_correg_linregm_stat_durbwat(n, p, res, &d, &pdl, &pdu, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_correg_linregm_stat_durbwat (g02fcc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  printf("\n");
  printf(" Durbin-Watson statistic %10.4f\n\n", d);
  printf(" Lower and upper bound %10.4f%10.4f\n", pdl, pdu);
END:
  NAG_FREE(res);
  return exit_status;
}