/* nag_zwaxpby (f16ghc) 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, incw, incx, incy, n, wlen, xlen, ylen; Complex alpha, beta; /* Arrays */ Complex *w = 0, *x = 0, *y = 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_zwaxpby (f16ghc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Read number of elements */ fscanf(fpin, "%ld%*[^\n] ", &n); /* Read increments */ fscanf(fpin, "%ld%ld%ld%*[^\n] ", &incx, &incy, &incw); /* Read factors alpha and beta */ fscanf(fpin, " ( %lf , %lf ) ", &alpha.re, &alpha.im); fscanf(fpin, " ( %lf , %lf ) %*[^\n] ", &beta.re, &beta.im); wlen = MAX(1, 1 + (n - 1)*ABS(incw)); xlen = MAX(1, 1 + (n - 1)*ABS(incx)); ylen = MAX(1, 1 + (n - 1)*ABS(incy)); if (n > 0) { /* Allocate memory */ if (!(w = NAG_ALLOC(wlen, Complex)) || !(x = NAG_ALLOC(xlen, Complex)) || !(y = NAG_ALLOC(ylen, 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] "); /* Input vector y */ for (i = 0; i < ylen; i = i + incy) fscanf(fpin, " ( %lf , %lf ) ", &y[i].re, &y[i].im); fscanf(fpin, "%*[^\n] "); /* nag_zwaxpby (f16ghc). * Performs w := alpha*x + beta*y */ nag_zwaxpby(n, alpha, x, incx, beta, y, incy, w, incw, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_zwaxpby (f16ghc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print the result */ fprintf(fpout, "Result of the scaled vector addition is\n"); fprintf(fpout, "w = ( "); for (i = 0; i < wlen - 1; i = i + incw) fprintf(fpout, "(%9.4f,%9.4f), ", w[i].re, w[i].im); fprintf(fpout, "(%9.4f,%9.4f) )\n", w[wlen - 1].re, w[wlen - 1].im); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (w) NAG_FREE(w); if (x) NAG_FREE(x); if (y) NAG_FREE(y); return exit_status; }