Mercurial > hg > octave-shane
changeset 10735:d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 30 Jun 2010 15:52:57 +0200 |
parents | 551913ba1f85 |
children | 14af8004945d |
files | src/ChangeLog src/ov-range.cc |
diffstat | 2 files changed, 41 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2010-06-30 Jaroslav Hajek <highegg@gmail.com> + + * ov-range.cc (octave_range::save_ascii): Save length rather than + limit when inc is zero. Adjust comment. + (octave_range::save_binary, octave_range::save_hdf5): Ditto. + (octave_range::load_ascii): Assume limit is length when increment is + zero. + (octave_range::load_binary, octave_range::load_hdf5): Ditto. + + 2010-06-25 John W. Eaton <jwe@octave.org> * graphics.cc (reset_default_properties): New static function.
--- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -402,11 +402,19 @@ double base = r.base (); double limit = r.limit (); double inc = r.inc (); + octave_idx_type len = r.nelem (); - os << "# base, limit, increment\n"; + if (inc != 0) + os << "# base, limit, increment\n"; + else + os << "# base, length, increment\n"; + octave_write_double (os, base); os << " "; - octave_write_double (os, limit); + if (inc != 0) + octave_write_double (os, limit); + else + os << len; os << " "; octave_write_double (os, inc); os << "\n"; @@ -420,7 +428,8 @@ // # base, limit, range comment added by save (). skip_comments (is); - is >> range; + double base, limit, inc; + is >> base >> limit >> inc; if (!is) { @@ -428,6 +437,11 @@ return false; } + if (inc != 0) + range = Range (base, limit, inc); + else + range = Range (base, inc, static_cast<octave_idx_type> (limit)); + return true; } @@ -440,6 +454,9 @@ double bas = r.base (); double lim = r.limit (); double inc = r.inc (); + if (inc == 0) + lim = r.nelem (); + os.write (reinterpret_cast<char *> (&bas), 8); os.write (reinterpret_cast<char *> (&lim), 8); os.write (reinterpret_cast<char *> (&inc), 8); @@ -467,8 +484,11 @@ return false; if (swap) swap_bytes<8> (&inc); - Range r (bas, lim, inc); - range = r; + if (inc != 0) + range = Range (bas, lim, inc); + else + range = Range (bas, inc, static_cast<octave_idx_type> (lim)); + return true; } @@ -525,7 +545,7 @@ Range r = range_value (); double range_vals[3]; range_vals[0] = r.base (); - range_vals[1] = r.limit (); + range_vals[1] = r.inc () != 0 ? r.limit () : r.nelem (); range_vals[2] = r.inc (); retval = H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, @@ -575,8 +595,11 @@ rangevals) >= 0) { retval = true; - Range r (rangevals[0], rangevals[1], rangevals[2]); - range = r; + if (rangevals[2] != 0) + range = Range (rangevals[0], rangevals[1], rangevals[2]); + else + range = Range (rangevals[0], rangevals[2], + static_cast<octave_idx_type> (rangevals[1])); } H5Tclose (range_type);