/* nag_order_data (g10zac) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { Integer exit_status=0, i, *iwrk=0, n, nord; NagError fail; char weight[2]; double rss, *weights=0, *wtord=0, *wtptr, *x=0, *xord=0, *y=0, *yord=0; INIT_FAIL(fail); Vprintf("nag_order_data (g10zac) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld", &n); if (!(x = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double)) || !(weights = NAG_ALLOC(n, double)) || !(xord = NAG_ALLOC(n, double)) || !(yord = NAG_ALLOC(n, double)) || !(wtord = NAG_ALLOC(n, double)) || !(iwrk = NAG_ALLOC(n, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vscanf(" %s ", weight); for (i = 1; i <= n; ++i) Vscanf("%lf %lf", &x[i - 1], &y[i - 1]); if (*weight == 'W') wtptr = weights; else wtptr = 0; /* nag_order_data (g10zac). * Reorder data to give ordered distinct observations */ nag_order_data(n, x, y, wtptr, &nord, xord, yord, wtord, &rss, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_order_data (g10zac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print results */ Vprintf("\n"); Vprintf("%s%6ld\n", "Number of distinct observations = ", nord); Vprintf("%s%13.5f\n", "Residual sum of squares = ", rss); Vprintf("\n"); Vprintf(" %s\n", " X Y WEIGHTS"); for (i = 1; i <= nord; ++i) Vprintf(" %13.5f %13.5f %13.5f\n", xord[i - 1], yord[i - 1], wtord[i - 1]); END: if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (weights) NAG_FREE(weights); if (xord) NAG_FREE(xord); if (yord) NAG_FREE(yord); if (wtord) NAG_FREE(wtord); if (iwrk) NAG_FREE(iwrk); return exit_status; }