Mercurial > hg > octave-max
changeset 5347:679cc8fec408
[project @ 2005-05-11 16:34:11 by jwe]
author | jwe |
---|---|
date | Wed, 11 May 2005 16:34:11 +0000 |
parents | a103c41e68b2 |
children | b3ba123faec8 |
files | liboctave/Range.h scripts/ChangeLog scripts/plot/polar.m src/pt-colon.cc src/pt-colon.h test/ChangeLog test/config/unix.exp |
diffstat | 7 files changed, 109 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Range.h +++ b/liboctave/Range.h @@ -33,7 +33,7 @@ public: Range (void) - : rng_base (-1), rng_limit (-1), rng_inc (-1), rng_nelem (-1), cache () { } + : rng_base (0), rng_limit (0), rng_inc (0), rng_nelem (0), cache (1, 0) { } Range (const Range& r) : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc),
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2005-05-11 John W. Eaton <jwe@octave.org> + + * plot/polar.m: Don't call __pltopt__ here. + 2005-05-02 John W. Eaton <jwe@octave.org> * mkdoc: Print header message.
--- a/scripts/plot/polar.m +++ b/scripts/plot/polar.m @@ -40,16 +40,13 @@ __gnuplot_raw__ ("set nopolar;\n"); if (nargin == 3) - if (isstr (fmt)) - fmt = __pltopt__ ("polar", fmt); - else + if (! isstr (fmt)) error ("polar: third argument must be a string"); endif __plr2__ (x1, x2, fmt); elseif (nargin == 2) if (isstr (x2)) - fmt = __pltopt__ ("polar", x2); - __plr1__ (x1, fmt); + __plr1__ (x1, x2); else fmt = ""; __plr2__ (x1, x2, fmt);
--- a/src/pt-colon.cc +++ b/src/pt-colon.cc @@ -82,6 +82,73 @@ } octave_value +tree_colon_expression::make_range (const Matrix& m_base, + const Matrix& m_limit, + const Matrix& m_increment, + bool result_is_str, bool dq_str) const +{ + octave_value retval; + + bool base_empty = m_base.is_empty (); + bool limit_empty = m_limit.is_empty (); + bool increment_empty = m_increment.is_empty (); + + if ((base_empty || m_base.numel () == 1) + && (limit_empty || m_limit.numel () == 1) + && (increment_empty || m_increment.numel () == 1)) + { + if (base_empty || limit_empty || increment_empty) + retval = Range (); + else + { + retval = Range (m_base(0), m_limit(0), m_increment(0)); + + if (result_is_str) + retval = retval.convert_to_str (false, true, dq_str ? '"' : '\''); + } + } + else + eval_error ("colon expression values must be scalars or empty matrices"); + + return retval; +} + +octave_value +tree_colon_expression::make_range (const octave_value& ov_base, + const octave_value& ov_limit, + const octave_value& ov_increment) const +{ + octave_value retval; + + bool result_is_str = (ov_base.is_string () && ov_limit.is_string ()); + bool dq_str = (ov_base.is_dq_string () || ov_limit.is_dq_string ()); + + Matrix m_base = ov_base.matrix_value (true); + + if (error_state) + eval_error ("invalid base value in colon expression"); + else + { + Matrix m_limit = ov_limit.matrix_value (true); + + if (error_state) + eval_error ("invalid limit value in colon expression"); + else + { + Matrix m_increment = ov_increment.matrix_value (true); + + if (error_state) + eval_error ("invalid increment value in colon expression"); + else + retval = make_range (m_base, m_limit, m_increment, + result_is_str, dq_str); + } + } + + return retval; +} + +octave_value tree_colon_expression::rvalue (void) { octave_value retval; @@ -91,72 +158,38 @@ if (error_state || ! op_base || ! op_limit) return retval; - octave_value tmp = op_base->rvalue (); - - if (error_state || tmp.is_undefined ()) - { - eval_error ("invalid value in colon expression"); - return retval; - } - - double xbase = tmp.double_value (); + octave_value ov_base = op_base->rvalue (); - if (error_state) - { - eval_error ("colon expression elements must be scalars"); - return retval; - } - - tmp = op_limit->rvalue (); - - if (error_state || tmp.is_undefined ()) - { - eval_error ("invalid value in colon expression"); - return retval; - } - - double xlimit = tmp.double_value (); - - if (error_state) + if (error_state || ov_base.is_undefined ()) + eval_error ("invalid base value in colon expression"); + else { - eval_error ("colon expression elements must be scalars"); - return retval; - } - - double xinc = 1.0; + octave_value ov_limit = op_limit->rvalue (); - if (op_increment) - { - tmp = op_increment->rvalue (); - - if (error_state || tmp.is_undefined ()) + if (error_state || ov_limit.is_undefined ()) + eval_error ("invalid limit value in colon expression"); + else { - eval_error ("invalid value in colon expression"); - return retval; - } + octave_value ov_increment = 1.0; - xinc = tmp.double_value (); + if (op_increment) + { + ov_increment = op_increment->rvalue (); - if (error_state) - { - eval_error ("colon expression elements must be scalars"); - return retval; + if (error_state || ov_increment.is_undefined ()) + eval_error ("invalid increment value in colon expression"); + } + + if (! error_state) + retval = make_range (ov_base, ov_limit, ov_increment); } } - retval = octave_value (xbase, xlimit, xinc); - - if (error_state) - { - retval = octave_value (); - eval_error (); - } - return retval; } void -tree_colon_expression::eval_error (const std::string& s) +tree_colon_expression::eval_error (const std::string& s) const { if (! s.empty ()) ::error ("%s", s.c_str ());
--- a/src/pt-colon.h +++ b/src/pt-colon.h @@ -75,7 +75,7 @@ octave_value_list rvalue (int nargout); - void eval_error (const std::string& s = std::string ()); + void eval_error (const std::string& s = std::string ()) const; tree_expression *base (void) { return op_base; } @@ -97,6 +97,14 @@ bool save_base; + octave_value + make_range (const Matrix& m_base, const Matrix& m_limit, + const Matrix& m_increment, bool result_is_str) const; + + octave_value + make_range (const octave_value& ov_base, const octave_value& ov_limit, + const octave_value& ov_increment) const; + // No copying! tree_colon_expression (const tree_colon_expression&);
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2005-05-11 John W. Eaton <jwe@octave.org> + + * config/unix.exp: Start Octave with -H. + 2002-10-31 John W. Eaton <jwe@bevo.che.wisc.edu> * octave.test/arith/prod-4.m, octave.test/arith/sum-4.m:
--- a/test/config/unix.exp +++ b/test/config/unix.exp @@ -81,7 +81,7 @@ # the timeout period at a minute for the real tests. set timeout 60 - spawn $OCTAVE -f -q $OSPATH + spawn $OCTAVE -f -q -H $OSPATH set timeout 5 expect { @@ -132,8 +132,8 @@ # Can't seem to get 2>&1 to work without using /bin/sh -c ""... - send_log "EXEC: $OCTAVE -f -q $OSPATH $src_file\n" - catch "exec /bin/sh -c \"$OCTAVE -f -q $OSPATH $src_file 2>&1\"" oct_output + send_log "EXEC: $OCTAVE -f -q -H $OSPATH $src_file\n" + catch "exec /bin/sh -c \"$OCTAVE -f -q -H $OSPATH $src_file 2>&1\"" oct_output } # do_test -- run a test given by the file $src_code.