/* nag_zsum (f16glc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 9, 2009. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer exit_status, i, incx, n, xlen; Complex sumval; /* Arrays */ Complex *x = 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_zsum (f16glc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Read the number of elements and the increment */ fscanf(fpin, "%ld%ld%*[^\n] ", &n, &incx); xlen = MAX(1, 1 + (n - 1)*ABS(incx)); if (n > 0) { /* Allocate memory */ if (!(x = NAG_ALLOC(xlen, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n\n"); exit_status = 1; goto END; } /* Input vector x */ for (i = 0; i < xlen; i = i + incx) fscanf(fpin, " ( %lf , %lf ) ", &x[i].re, &x[i].im); fscanf(fpin, "%*[^\n] "); /* nag_zsum (f16glc). * Sum elements of a vector of Complexes */ sumval = nag_zsum(n, x, incx, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_zsum (f16glc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print the result. */ fprintf(fpout, "Sum of elements of x is (%9.5f,%9.5f)\n", sumval.re, sumval.im); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); return exit_status; }