/* nag_sparse_nherm_sort (f11znc) Example Program. * * Copyright 2011, Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include int main(void) { /* Scalars */ Integer exit_status = 0; Integer i, n, nnz; /* Arrays */ char nag_enum_arg[40]; Integer *irow = 0, *icol = 0, *istr = 0; Complex *a = 0; /* NAG types */ NagError fail; Nag_SparseNsym_Dups dup; Nag_SparseNsym_Zeros zero; INIT_FAIL(fail); printf("nag_sparse_nherm_sort (f11znc) Example Program Results\n\n"); /* Skip heading in data file */ scanf("%*[^\n]"); /* Read order of matrix and number of non-zero entries */ scanf("%ld%*[^\n]", &n); scanf("%ld%*[^\n]", &nnz); /* Allocate memory */ if ( !(a = NAG_ALLOC(nnz, Complex)) || !(icol = NAG_ALLOC(nnz, Integer)) || !(irow = NAG_ALLOC(nnz, Integer)) || !(istr = NAG_ALLOC((n+1), Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Read and output the original non-zero elements */ for (i = 0; i < nnz; i++) scanf(" ( %lf , %lf ) %ld%ld%*[^\n]", &a[i].re, &a[i].im, &irow[i], &icol[i] ); /* Reorder, sum duplicates and remove zeros */ scanf("%s%*[^\n]", nag_enum_arg); /* Nag_SparseNsym_SumDups */ dup = (Nag_SparseNsym_Dups)nag_enum_name_to_value(nag_enum_arg); scanf("%s%*[^\n]", nag_enum_arg); /* Nag_SparseNsym_RemoveZeros */ zero = (Nag_SparseNsym_Zeros)nag_enum_name_to_value(nag_enum_arg); /* Output original */ printf("Original elements\n"); printf("%s%4ld\n", " n = ", n); printf("%s%4ld\n", " nnz = ", nnz); printf("%9s%14s%22s%9s\n","i","a","irow","icol"); for (i = 0; i < nnz; i++) printf("%9ld (%11.4e, %11.4e)%9ld%9ld\n", i, a[i].re, a[i].im, irow[i], icol[i]); /* nag_sparse_nherm_sort (f11znc). * Complex sparse non-Hermitian matrix reorder function. */ nag_sparse_nherm_sort(n, &nnz, a, irow, icol, dup, zero, istr, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_sparse_nherm_sort (f11znc)\n%s\n", fail.message); exit_status = 1; goto END; } /* Output results */ printf("\nReordered elements\n"); printf("%s%4ld\n", " nnz = ", nnz); printf("%9s%14s%22s%9s\n","i","a","irow","icol"); for (i = 0; i < nnz; i++) printf("%9ld (%11.4e, %11.4e)%9ld%9ld\n", i, a[i].re, a[i].im, irow[i], icol[i]); END: if (a) NAG_FREE(a); if (icol) NAG_FREE(icol); if (irow) NAG_FREE(irow); if (istr) NAG_FREE(istr); return exit_status; }