/* nag_sparse_nsym_sort (f11zac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * */ #include #include #include #include int main(void) { double *a=0; Integer *icol=0; Integer *irow=0, *istr=0; Integer i, n, nnz; Nag_SparseNsym_Zeros zero; Nag_SparseNsym_Dups dup; Vprintf("nag_sparse_nsym_sort (f11zac) Example Program Results\n"); /* Skip heading in data file */ Vscanf(" %*[^\n]"); /* Read order of matrix and number of non-zero entries */ Vscanf("%ld%*[^\n]",&n); Vscanf("%ld%*[^\n]",&nnz); istr = NAG_ALLOC(n+1, Integer); a = NAG_ALLOC(nnz,double); irow = NAG_ALLOC(nnz,Integer); icol = NAG_ALLOC(nnz,Integer); if (!istr || !irow || !icol || !a) { Vprintf("Allocation failure\n"); return EXIT_FAILURE; } /* Read and output the original non-zero elements */ for (i = 1; i <= nnz; ++i) Vscanf("%lf%ld%ld%*[^\n]",&a[i-1], &irow[i-1], &icol[i-1]); Vprintf(" Original elements \n"); Vprintf(" nnz = %6ld\n",nnz); for (i = 1; i <= nnz; ++i) Vprintf(" %8ld%16.4e%8ld%8ld\n", i, a[i-1], irow[i-1],icol[i-1]); /* Reorder, sum duplicates and remove zeros */ dup = Nag_SparseNsym_SumDups; zero = Nag_SparseNsym_RemoveZeros; /* nag_sparse_nsym_sort (f11zac). * Sparse sort (nonsymmetric) */ nag_sparse_nsym_sort(n, &nnz, a, irow, icol, dup, zero, istr, NAGERR_DEFAULT); /* Output results */ Vprintf(" Reordered elements \n"); Vprintf(" nnz = %4ld\n",nnz); for (i = 1; i <= nnz; ++i) Vprintf(" %8ld%16.4e%8ld%8ld\n", i, a[i-1], irow[i-1],icol[i-1]); NAG_FREE(istr); NAG_FREE(irow); NAG_FREE(icol); NAG_FREE(a); return EXIT_SUCCESS; }