/* nag_sparse_sym_sort (f11zbc) 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_SparseSym_Zeros zero; Nag_SparseSym_Dups dup; Vprintf("f11zbc 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_SparseSym_SumDups; zero = Nag_SparseSym_RemoveZeros; f11zbc(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; }