/* nag_damin_val (f16jrc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 9, 2009. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, incx, k, n, xlen; double r; /* Arrays */ double *x = 0; /* Nag Types */ NagError fail; exit_status = 0; INIT_FAIL(fail); printf("nag_damin_val (f16jrc) Example Program Results\n\n"); /* Skip heading in data file */ scanf("%*[^\n] "); /* Read the number of elements and the increment */ scanf("%ld%ld%*[^\n] ", &n, &incx); xlen = MAX(1, 1 + (n - 1)*ABS(incx)); if (n > 0) { /* Allocate memory */ if (!(x = NAG_ALLOC(xlen, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid n\n"); exit_status = 1; goto END; } /* Input vector x */ for (i = 0; i < xlen; i = i + incx) scanf("%lf", &x[i]); scanf("%*[^\n] "); /* nag_damin_val (f16jrc). * Get absolutely minimum value (r) and location of that value (k) * of double array */ nag_damin_val(n, x, incx, &k, &r, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_damin_val (f16jrc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print the absolutely minimum value */ printf("Absolutely minimum element of x is %12.5f\n", r); /* Print its location */ printf("Index of absolutely minimum element of x is %3ld\n", k); END: if (x) NAG_FREE(x); return exit_status; }