Mercurial > hg > octave-lojdl
changeset 3738:f20c30fa3a8d
[project @ 2000-11-17 20:10:22 by jwe]
author | jwe |
---|---|
date | Fri, 17 Nov 2000 20:10:23 +0000 |
parents | b736f8b8f0a1 |
children | 85027c5aedc2 |
files | src/ChangeLog src/load-save.cc src/load-save.h src/pt-plot.cc |
diffstat | 4 files changed, 68 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2000-11-17 John W. Eaton <jwe@bevo.che.wisc.edu> + + * load-save.cc (save_ascii_data_for_plotting): New function. + * pt-plot.cc (save_in_tmp_file): Use it instead of save_ascii_data. + + * load-save.cc (save_ascii_data): Warn if saving Inf or NaN values. + New arg, infnan_warned. Use it to warn just once per set. + Now static. + (do_save): New arg, infnan_warned. Pass to save_ascii_data. + (save_vars): Initialize infnan_warned here, pass to do_save. + 2000-11-16 Paul Kienzle <pkienzle@kienzle.powernet.co.uk> * file-io.cc (Ffprintf): If no file id parameter, don't return
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -4448,10 +4448,11 @@ // XXX FIXME XXX -- should probably write the help string here too. -bool +static bool save_ascii_data (std::ostream& os, const octave_value& tc, - const std::string& name, bool strip_nan_and_inf, - bool mark_as_global, int precision) + const std::string& name, bool& infnan_warned, + bool strip_nan_and_inf, bool mark_as_global, + int precision) { bool success = true; @@ -4494,6 +4495,7 @@ ascii_save_type (os, "scalar", mark_as_global); double d = tc.double_value (); + if (strip_nan_and_inf) { if (xisnan (d)) @@ -4508,17 +4510,32 @@ } } else - os << d << "\n"; + { + if (! infnan_warned && (xisnan (d) || xisinf (d))) + { + warning ("save: Inf or NaN values may not be reloadable"); + infnan_warned = true; + } + + os << d << "\n"; + } } else if (tc.is_real_matrix ()) { ascii_save_type (os, "matrix", mark_as_global); + os << "# rows: " << tc.rows () << "\n" << "# columns: " << tc.columns () << "\n"; Matrix tmp = tc.matrix_value (); + if (strip_nan_and_inf) tmp = strip_infnan (tmp); + else if (! infnan_warned && tmp.any_element_is_inf_or_nan ()) + { + warning ("save: Inf or NaN values may not be reloadable"); + infnan_warned = true; + } os << tmp; } @@ -4527,6 +4544,7 @@ ascii_save_type (os, "complex scalar", mark_as_global); Complex c = tc.complex_value (); + if (strip_nan_and_inf) { if (xisnan (c)) @@ -4548,17 +4566,32 @@ } } else - os << c << "\n"; + { + if (! infnan_warned && (xisnan (c) || xisinf (c))) + { + warning ("save: Inf or NaN values may not be reloadable"); + infnan_warned = true; + } + + os << c << "\n"; + } } else if (tc.is_complex_matrix ()) { ascii_save_type (os, "complex matrix", mark_as_global); + os << "# rows: " << tc.rows () << "\n" << "# columns: " << tc.columns () << "\n"; ComplexMatrix tmp = tc.complex_matrix_value (); + if (strip_nan_and_inf) tmp = strip_infnan (tmp); + else if (! infnan_warned && tmp.any_element_is_inf_or_nan ()) + { + warning ("save: Inf or NaN values may not be reloadable"); + infnan_warned = true; + } os << tmp; } @@ -4570,11 +4603,20 @@ return (os && success); } +bool +save_ascii_data_for_plotting (std::ostream& os, const octave_value& t, + const std::string& name) +{ + bool infnan_warned = true; + + save_ascii_data (os, t, name, infnan_warned, true, false, 0); +} + // Save the info from sr on stream os in the format specified by fmt. static void do_save (std::ostream& os, symbol_record *sr, load_save_format fmt, - int save_as_floats) + int save_as_floats, bool& infnan_warned) { if (! sr->is_variable ()) { @@ -4594,7 +4636,7 @@ switch (fmt) { case LS_ASCII: - save_ascii_data (os, tc, name, false, global); + save_ascii_data (os, tc, name, infnan_warned, false, global, 0); break; case LS_BINARY: @@ -4634,9 +4676,11 @@ int saved = vars.length (); + bool infnan_warned = false; + for (int i = 0; i < saved; i++) { - do_save (os, vars (i), fmt, save_as_floats); + do_save (os, vars (i), fmt, save_as_floats, infnan_warned); if (error_state) break; @@ -4653,7 +4697,7 @@ for (int i = 0; i < count; i++) { - do_save (os, vars (i), fmt, save_as_floats); + do_save (os, vars (i), fmt, save_as_floats, infnan_warned); if (error_state) break;
--- a/src/load-save.h +++ b/src/load-save.h @@ -29,11 +29,9 @@ class octave_value; -extern bool save_ascii_data (std::ostream& os, const octave_value& t, - const std::string& name = std::string (), - bool strip_nan_and_inf = false, - bool mark_as_global = false, - int precision = 0); +extern bool +save_ascii_data_for_plotting (std::ostream& os, const octave_value& t, + const std::string& name = std::string ()); extern bool save_three_d (std::ostream& os, const octave_value& t, bool parametric = false);