/* nag_nag_2d_panel_sort (e02zac) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2004. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer exit_status, i, iadres, m, nadres, npoint, px, py; /* Arrays */ double *lamda = 0, *mu = 0, *x = 0, *y = 0; Integer *point = 0; /* Nag types */ NagError fail; exit_status = 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); fprintf(fpout, "nag_2d_panel_sort (e02zac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); while (fscanf(fpin, "%ld%*[^\n] ", &m) != EOF) { if (m > 0) { /* Allocate memory */ if (!(x = NAG_ALLOC(m, double)) || !(y = NAG_ALLOC(m, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid m.\n"); exit_status = 1; return exit_status; } fscanf(fpin, "%ld%ld%*[^\n] ", &px, &py); nadres = (px - 7) * (py - 7); npoint = m+nadres; if (px >= 8 && py >= 8) { /* Allocate memory */ if (!(lamda = NAG_ALLOC(px, double)) || !(mu = NAG_ALLOC(py, double)) || !(point = NAG_ALLOC(npoint, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid px or py.\n"); exit_status = 1; goto END; } /* Read data points and intercepts of panel sides */ for (i = 1; i <= m; ++i) { fscanf(fpin, "%lf%lf", &x[i - 1], &y[i - 1]); } fscanf(fpin, "%*[^\n] "); if (px > 8) { for (i = 5; i <= px - 4; ++i) { fscanf(fpin, "%lf", &lamda[i - 1]); } fscanf(fpin, "%*[^\n] "); } if (py > 8) { for (i = 5; i <= py - 4; ++i) { fscanf(fpin, "%lf", &mu[i - 1]); } fscanf(fpin, "%*[^\n] "); } /* Sort points into panel order */ /* nag_2d_panel_sort (e02zac). * Sort two-dimensional data into panels for fitting bicubic * splines */ nag_2d_panel_sort(px, py, lamda, mu, m, x, y, point, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_2d_panel_sort (e02zac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output points in panel order */ for (i = 1; i <= nadres; ++i) { fprintf(fpout, "\n%s%4ld\n\n", "Panel", i); iadres = m + i; while ((iadres = point[iadres - 1]) > 0) { fprintf(fpout, "%7.2f%7.2f\n", x[iadres - 1], y[iadres - 1]); } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (lamda) NAG_FREE(lamda); if (mu) NAG_FREE(mu); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (point) NAG_FREE(point); } return exit_status; }