Mercurial > hg > octave-nkf
diff src/pr-output.cc @ 4655:c8829691db47
[project @ 2003-11-24 21:24:37 by jwe]
author | jwe |
---|---|
date | Mon, 24 Nov 2003 21:24:37 +0000 |
parents | 0e28461651f2 |
children | 12b6fbd57436 |
line wrap: on
line diff
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -33,6 +33,7 @@ #include <iostream> #include <string> +#include "Array-util.h" #include "CMatrix.h" #include "Range.h" #include "cmd-edit.h" @@ -1527,6 +1528,8 @@ \ for (int i = 0; i < m; i++) \ { \ + OCTAVE_QUIT; \ + \ std::string nm = "ans"; \ \ if (m > 1) \ @@ -1978,6 +1981,97 @@ } } +void +octave_print_internal (std::ostream& os, const ArrayN<std::string>& nda, + bool pr_as_read_syntax, int extra_indent) +{ + // XXX FIXME XXX -- this mostly duplicates the code in the + // PRINT_ND_ARRAY macro. + + if (nda.is_empty ()) + print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); + else if (nda.length () == 1) + { + os << nda(0); + } + else + { + int ndims = nda.ndims (); + + dim_vector dims = nda.dims (); + + Array<int> ra_idx (ndims, 0); + + int m = 1; + + for (int i = 2; i < ndims; i++) + m *= dims(i); + + int nr = dims(0); + int nc = dims(1); + + for (int i = 0; i < m; i++) + { + std::string nm = "ans"; + + if (m > 1) + { + nm += "(:,:,"; + + OSSTREAM buf; + + for (int k = 2; k < ndims; k++) + { + buf << ra_idx(k) + 1; + + if (k < ndims - 1) + buf << ","; + else + buf << ")"; + } + + buf << OSSTREAM_ENDS; + + nm += OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); + } + + Array<idx_vector> idx (ndims); + + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + + for (int k = 2; k < ndims; k++) + idx(k) = idx_vector (ra_idx(k) + 1); + + Array2<std::string> page (nda.index (idx), nr, nc); + + // XXX FIXME XXX -- need to do some more work to put these + // in neatly aligned columns... + + int n_rows = page.rows (); + int n_cols = page.cols (); + + os << nm << " =\n\n"; + + for (int ii = 0; ii < n_rows; ii++) + { + for (int jj = 0; jj < n_cols; jj++) + os << " " << page(ii,jj); + + os << "\n"; + } + + if (i < m - 1) + os << "\n"; + + if (i < m) + increment_index (ra_idx, dims, 2); + } + } +} + extern void octave_print_internal (std::ostream&, const Cell&, bool, int, bool) {