Mercurial > hg > octave-terminal
changeset 4914:1c0442da75fd
[project @ 2004-07-23 16:55:13 by jwe]
author | jwe |
---|---|
date | Fri, 23 Jul 2004 16:55:13 +0000 |
parents | c8368716bab3 |
children | c638c144d4da |
files | scripts/general/num2str.m scripts/image/imshow.m scripts/plot/figure.m src/ChangeLog src/pt-loop.cc src/symtab.cc src/symtab.h |
diffstat | 7 files changed, 139 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/num2str.m +++ b/scripts/general/num2str.m @@ -50,7 +50,7 @@ ## Setup a suitable format string if (isnumeric (x) && round (x) == x && abs (x) < 1e10) dgt1 = ceil (log10 (max (max (abs (real (x(:)))), - max (abs (imag (x(:))))))) + 1; + max (abs (imag (x(:))))))) + 1; dgt2 = dgt1 - (min (real (x(:))) >= 0); fmt = sprintf("%%%dd%%+-%ddi ", dgt2, dgt1); elseif (isscalar (x)) @@ -61,27 +61,27 @@ endif ## Manipulate the complex value to have real values in the odd - ## columns and imaginary values in the even columns + ## columns and imaginary values in the even columns. sz = size (x); - nc = sz (2); + nc = sz(2); nd = ndims (x); - perm = fix ([1 : 0.5 : nc + 0.5]); - perm (2 : 2 : 2*nc) = perm(2 : 2 : 2*nc) + nc; + perm = fix ([1:0.5:nc+0.5]); + perm(2:2:2*nc) = perm(2:2:2*nc) + nc; idx = cell (); for i = 1:nd idx {i} = 1:sz(i); endfor - idx {2} = perm; + idx{2} = perm; x = horzcat (real(x), imag(x)); - x = x (idx{:}); + x = x(idx{:}); - fmt = strcat (deblank(repmat (fmt, 1, nc)), "\n"); - tmp = sprintf (fmt, permute (x, [2, 1, 3 : nd])); + fmt = strcat (deblank (repmat (fmt, 1, nc)), "\n"); + tmp = sprintf (fmt, permute (x, [2, 1, 3:nd])); ## Put the "i"'s where they are supposed to be. while (true) tmp2 = strrep (tmp, " i\n", "i\n"); - if (length(tmp) == length(tmp2)) + if (length (tmp) == length (tmp2)) break; else tmp = tmp2; @@ -107,12 +107,12 @@ endif else if (isnumeric (x) && round (x) == x && abs (x) < 1e10) - if (max(abs(x(:))) == 0) + if (max (abs (x(:))) == 0) dgt = 1; else - dgt = floor(log10(max(abs(x(:))))) + (min (real (x(:))) < 0) + 1; + dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 1; endif - fmt = sprintf("%%%dd ",dgt); + fmt = sprintf ("%%%dd ", dgt); elseif (isscalar (x)) fmt = "%.4g"; else @@ -120,7 +120,8 @@ endif endif fmt = strcat (deblank (repmat (fmt, 1, columns (x))), "\n"); - tmp = sprintf (fmt, permute (x, [2, 1, 3 : ndims(x)])); + nd = ndims (x); + tmp = sprintf (fmt, permute (x, [2, 1, 3:nd])); tmp(length (tmp)) = ""; retval = split (tmp, "\n"); endif
--- a/scripts/image/imshow.m +++ b/scripts/image/imshow.m @@ -69,8 +69,8 @@ if (mvars != 3) I = varargin{1}; if (iscomplex (I)) - warning ("imshow: displaying real part of complex image"); - I = real (I); + warning ("imshow: displaying real part of complex image"); + I = real (I); endif if (max (I(:)) <= 1) ## image in [0-1]; scale to [0-255] @@ -109,9 +109,9 @@ endif if (max (tmp(:)) > 1) ## Normalise to [0-1]. - r = r/255; - g = g/255; - b = b/255; + r = r / 255; + g = g / 255; + b = b / 255; endif [I, M] = rgb2ind (r, g, b); endif
--- a/scripts/plot/figure.m +++ b/scripts/plot/figure.m @@ -21,7 +21,7 @@ ## @deftypefn {Function File} {} figure (@var{n}) ## Set the current plot window to plot window @var{n}. This function ## currently requires X11 and a version of gnuplot that supports multiple -## frames. If @var{N} is not specified, the next available window +## frames. If @var{n} is not specified, the next available window ## number is chosen. ## @end deftypefn
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-07-23 John W. Eaton <jwe@octave.org> + + * symtab.cc (whos_parameter): Move decl here, from symtab.h. + 2004-07-23 Oyvind Kristiansen <oyvinkri@stud.ntnu.no> * symtab.cc (symbol_record::subsymbols_list): New method.
--- a/src/pt-loop.cc +++ b/src/pt-loop.cc @@ -246,7 +246,7 @@ { \ int ndims = dv.length (); \ Array<idx_vector> idx; \ - int steps = dv.numel () / dv (0); \ + int steps = dv.numel () / dv (0); \ idx.resize (ndims, idx_vector (1)); \ idx (0) = idx_vector (':'); \ \ @@ -254,7 +254,7 @@ { \ MAYBE_DO_BREAKPOINT; \ \ - octave_value val (arg.index(idx)); \ + octave_value val (arg.index(idx)); \ \ bool quit = false; \ \ @@ -266,11 +266,11 @@ \ for (int j = 1; j < ndims; j++) \ { \ - idx(j) = idx_vector (idx(j)(0) + 2); \ - if (idx(j)(0) < dv(j)) \ + idx(j) = idx_vector (idx(j)(0) + 2); \ + if (idx(j)(0) < dv(j)) \ break; \ else \ - idx(j) = idx_vector (1); \ + idx(j) = idx_vector (1); \ } \ } \ } \
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -31,6 +31,7 @@ #include <cassert> #include <cctype> #include <climits> +#include <cstdio> #include <iomanip> #include <fstream> @@ -51,7 +52,6 @@ #include "lo-mappers.h" #include "parse.h" -#include <stdio.h> unsigned long int symbol_table::symtab_count = 0; @@ -201,9 +201,6 @@ // Individual records in a symbol table. -// XXX FIXME XXX -- there are lots of places below where we should -// probably be temporarily ignoring interrupts. - void symbol_record::rename (const std::string& new_name) { @@ -419,24 +416,27 @@ } } +// Calculate how much space needs to be reserved for the first part of +// the dimensions string. For example, +// +// mat is a 12x3 matrix +// ^^ => 2 columns + int -symbol_record::dimensions_string_req_first_space (int print_dims) const +symbol_record::dimensions_string_req_first_space (int print_dims) const { - // This method calculates how much space needs to be reserved for the - // first part of the dimensions string. - // Example: mat is a 12x3 matrix - // ^^ => 2 columns long dim = 0; int first_param_space = 0; - // Calculating dimensions + // Calculating dimensions. + std::string dim_str = ""; std::stringstream ss; dim_vector dimensions; if (is_variable ()) { - if (is_matrix_type ()) + if (is_matrix_type ()) { dimensions = dims (); dim = dimensions.length (); @@ -445,23 +445,26 @@ first_param_space = (first_param_space >= 1 ? first_param_space : 1); - // Preparing dimension string + // Preparing dimension string. + if ((dim <= print_dims || print_dims < 0) && print_dims != 0) { - // Dimensions string must be printed like this: 2x3x4x2 + // Dimensions string must be printed like this: 2x3x4x2. + if (dim == 0 || dim == 1) - first_param_space = 1; // First parameter is 1 + first_param_space = 1; // First parameter is 1. else { ss << dimensions (0); - + dim_str = ss.str (); first_param_space = dim_str.length (); } } - else + else { - // Printing dimension string as: a-D + // Printing dimension string as: a-D. + ss << dim; dim_str = ss.str (); @@ -471,14 +474,15 @@ return first_param_space; } +// Calculate how much space needs to be reserved for the the +// dimensions string. For example, +// +// mat is a 12x3 matrix +// ^^^^ => 4 columns + int symbol_record::dimensions_string_req_total_space (int print_dims) const { - // This method calculates how much space needs to be reserved for the - // the dimensions string. - // Example: mat is a 12x3 matrix - // ^^^^ => 4 columns - std::string dim_str = ""; std::stringstream ss; @@ -488,56 +492,62 @@ return dim_str.length (); } +// Make the dimensions-string. For example: mat is a 2x3 matrix. +// ^^^ + std::string -symbol_record::make_dimensions_string (int print_dims) const +symbol_record::make_dimensions_string (int print_dims) const { - // This method makes the dimensions-string, which is a string that tells - // how large a object is, dimensionally. - // Example: mat is a 2x3 matrix - // ^^^ - long dim = 0; - // Calculating dimensions + // Calculating dimensions. + std::string dim_str = ""; std::stringstream ss; dim_vector dimensions; if (is_variable ()) { - if (is_matrix_type ()) + if (is_matrix_type ()) { dimensions = dims (); dim = dimensions.length (); } } - // Preparing dimension string + // Preparing dimension string. + if ((dim <= print_dims || print_dims < 0) && print_dims != 0) { // Only printing the dimension string as: axbxc... + if (dim == 0) ss << "1x1"; else { - for (int i = 0; i < dim; i++) + for (int i = 0; i < dim; i++) { if (i == 0) { if (dim == 1) - // Looks like this is not going to happen in Octave, but ... - ss << "1x" << dimensions (i); + { + // Looks like this is not going to happen in + // Octave, but ... + + ss << "1x" << dimensions (i); + } else ss << dimensions (i); } - else if (i < dim && dim != 1) + else if (i < dim && dim != 1) ss << "x" << dimensions (i); } } } - else + else { - // Printing dimension string as: a-D + // Printing dimension string as: a-D. + ss << dim << "-D"; } @@ -546,11 +556,12 @@ return dim_str; } +// Print a line of information on a given symbol. + void symbol_record::print_symbol_info_line (std::ostream& os, std::list<whos_parameter>& params) const { - // This method prints a line of information on a given symbol std::list<whos_parameter>::iterator i = params.begin (); while (i != params.end ()) { @@ -558,35 +569,40 @@ if (param.command != '\0') { - // Do the actual printing + // Do the actual printing. + switch (param.modifier) { case 'l': - os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); + os << std::setiosflags (std::ios::left) + << std::setw (param.parameter_length); break; case 'r': - os << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); + os << std::setiosflags (std::ios::right) + << std::setw (param.parameter_length); break; case 'c': if (param.command == 's') { - int front = param.first_parameter_length - - dimensions_string_req_first_space (param.dimensions); - int back = param.parameter_length - - dimensions_string_req_total_space (param.dimensions) - - front; + int front = param.first_parameter_length + - dimensions_string_req_first_space (param.dimensions); + int back = param.parameter_length + - dimensions_string_req_total_space (param.dimensions) + - front; front = (front > 0) ? front : 0; back = (back > 0) ? back : 0; - os << std::setiosflags (std::ios::left) + os << std::setiosflags (std::ios::left) << std::setw (front) - << "" << std::resetiosflags (std::ios::left) + << "" + << std::resetiosflags (std::ios::left) << make_dimensions_string (param.dimensions) << std::setiosflags (std::ios::left) << std::setw (back) - << "" << std::resetiosflags (std::ios::left); + << "" + << std::resetiosflags (std::ios::left); } else { @@ -596,7 +612,9 @@ break; default: - error ("whos_line_format: modifier `%c' unknown", param.modifier); + error ("whos_line_format: modifier `%c' unknown", + param.modifier); + os << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); } @@ -636,8 +654,8 @@ case 't': os << type_name (); break; - - default: + + default: error ("whos_line_format: command `%c' unknown", param.command); } @@ -1090,9 +1108,9 @@ symbol_record *sym_ptr = new symbol_record (); octave_value value; int parse_status; - + value = eval_string (var_name, true, parse_status); - + sym_ptr->define (value); sym_ptr->rename (var_name); subsymbols(count++) = sym_ptr; @@ -1212,7 +1230,7 @@ break; case 'c': - if (param.command != 's') + if (param.command != 's') { os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); @@ -1229,7 +1247,7 @@ if (param.command == 's' && param.modifier == 'c') { int a, b; - + if (param.modifier == 'c') { a = param.first_parameter_length - param.balance; @@ -1345,8 +1363,8 @@ param.command = '\0'; if (Vwhos_line_format[idx] == '%') - { - bool _error = false; + { + bool error_encountered = false; param.modifier = 'r'; param.parameter_length = 0; param.dimensions = 8; @@ -1365,18 +1383,21 @@ error ("parameter without ; in whos_line_format"); idx += cmd.length (); - + + // XXX FIXME XXX -- use iostream functions instead of sscanf! + if (cmd.find_first_of ("crl") != 1) items = sscanf (cmd.c_str (), "%c%c:%d:%d:%d:%d;", &garbage, ¶m.command, &a, &b, &c, &balance); else items = sscanf (cmd.c_str (), "%c%c%c:%d:%d:%d:%d;", - &garbage, ¶m.modifier, ¶m.command, &a, &b, &c, &balance) - 1; - + &garbage, ¶m.modifier, ¶m.command, + &a, &b, &c, &balance) - 1; + if (items < 2) { error ("whos_line_format: parameter structure without command in whos_line_format"); - _error = true; + error_encountered = true; } // Insert data into parameter @@ -1392,7 +1413,7 @@ { error ("whos_line_format: '%c' is not a command", param.command); - _error = true; + error_encountered = true; } if (param.command == 's') @@ -1403,7 +1424,7 @@ // recalculated for each Size-command int j, first = 0, rest = 0, total = 0; param.dimensions = c; - + for (j = 0; j < len; j++) { int first1 = symbols(j)->dimensions_string_req_first_space (param.dimensions); @@ -1435,7 +1456,7 @@ { error ("whos_line_format: modifier 'c' not available for command '%c'", param.command); - _error = true; + error_encountered = true; } // What happens if whos_line_format contains negative numbers @@ -1445,12 +1466,12 @@ param.first_parameter_length); param.parameter_length = ((a < 0) ? 0 : (param.parameter_length < - param_length (pos_s)) ? + param_length (pos_s)) ? param_length (pos_s) : param.parameter_length); // Parameter will not be pushed into parameter list if ... - if (! _error) + if (! error_encountered) params.push_back (param); } else @@ -1479,23 +1500,24 @@ std::ostream& os, bool show_verbose, unsigned type, unsigned scope) { - // This method prints information for sets of symbols, but only one set - // at a time (like, for instance: all variables, og all - // built-in-functions) + // This method prints information for sets of symbols, but only one + // set at a time (like, for instance: all variables, or all + // built-in-functions). - // This method invokes print_symbol_info_line to print info on every symbol + // This method invokes print_symbol_info_line to print info on every + // symbol. int status = 0; if (show_verbose) { - // XXX FIXME XXX Should separate argv to lists with and without dots - Array<symbol_record *> _symbols = symbol_list (argv, type, scope); - Array<symbol_record *> _subsymbols = subsymbol_list (argv, type, scope); + // XXX FIXME XXX Should separate argv to lists with and without dots. + Array<symbol_record *> xsymbols = symbol_list (argv, type, scope); + Array<symbol_record *> xsubsymbols = subsymbol_list (argv, type, scope); - int sym_len = _symbols.length (), subsym_len = _subsymbols.length (), + int sym_len = xsymbols.length (), subsym_len = xsubsymbols.length (), len = sym_len + subsym_len; - + Array<symbol_record *> symbols (len); if (len > 0) @@ -1503,12 +1525,12 @@ int bytes = 0, elements = 0, i; std::list<whos_parameter> params; - // Joining symbolic tables + // Joining symbolic tables. for (i = 0; i < sym_len; i++) - symbols(i) = _symbols(i); + symbols(i) = xsymbols(i); for (i = 0; i < subsym_len; i++) - symbols(i+sym_len) = _subsymbols(i); + symbols(i+sym_len) = xsubsymbols(i); os << "\n" << header << "\n\n"; @@ -1527,7 +1549,7 @@ bytes += symbols(j)->byte_size (); } - os << "\nTotal is " << elements + os << "\nTotal is " << elements << " element" << ((elements > 1) ? "s" : "") << " using " << bytes << " byte" << ((bytes > 1) ? "s" : "") << "\n"; @@ -1539,7 +1561,7 @@ string_vector symbols = name_list (argv, 1, type, scope); if (! symbols.empty ()) - { + { os << "\n" << header << "\n\n"; symbols.list_in_columns (os);
--- a/src/symtab.h +++ b/src/symtab.h @@ -48,8 +48,12 @@ struct whos_parameter { - char command, modifier; - int parameter_length, first_parameter_length, dimensions, balance; + char command; + char modifier; + int parameter_length; + int first_parameter_length; + int dimensions; + int balance; std::string text; std::string line; };