changeset 5956:cdef72fcd206

[project @ 2006-08-22 20:36:56 by jwe]
author jwe
date Tue, 22 Aug 2006 20:36:57 +0000
parents fc46f9c99028
children 370f785718be
files liboctave/CMatrix.cc liboctave/CMatrix.h liboctave/ChangeLog liboctave/dMatrix.cc liboctave/dMatrix.h src/ChangeLog src/ls-oct-ascii.cc src/ls-oct-ascii.h src/ov-base-int.cc src/ov-base-int.h src/ov-base-sparse.cc src/ov-base-sparse.h src/ov-base.cc src/ov-base.h src/ov-bool-mat.cc src/ov-bool-mat.h src/ov-bool.cc src/ov-bool.h src/ov-cell.cc src/ov-cell.h src/ov-complex.cc src/ov-complex.h src/ov-cx-mat.cc src/ov-cx-mat.h src/ov-fcn-handle.cc src/ov-fcn-handle.h src/ov-fcn-inline.cc src/ov-fcn-inline.h src/ov-list.cc src/ov-list.h src/ov-range.cc src/ov-range.h src/ov-re-mat.cc src/ov-re-mat.h src/ov-scalar.cc src/ov-scalar.h src/ov-str-mat.cc src/ov-str-mat.h src/ov-struct.cc src/ov-struct.h src/ov.h
diffstat 41 files changed, 236 insertions(+), 159 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CMatrix.cc
+++ b/liboctave/CMatrix.cc
@@ -3464,6 +3464,82 @@
 
 // i/o
 
+// Used when converting Inf to something that gnuplot can read.
+
+#ifndef OCT_RBV
+#define OCT_RBV DBL_MAX / 100.0
+#endif
+
+std::ostream&
+ComplexMatrix::save_ascii (std::ostream& os, bool& infnan_warned,
+			   int strip_nan_and_inf)
+{
+  if (strip_nan_and_inf)
+    {
+      octave_idx_type nr = rows ();
+      octave_idx_type nc = columns ();
+
+      for (octave_idx_type i = 0; i < nr; i++)
+	{
+	  if (strip_nan_and_inf)
+	    {
+	      for (octave_idx_type j = 0; j < nc; j++)
+		{
+		  Complex c = elem (i, j);
+
+		  if (xisnan (c))
+		    {
+		      if (strip_nan_and_inf == 1)
+			goto next_row;
+		      else if (strip_nan_and_inf == 2)
+			goto next_row_with_newline;
+		    }
+		}
+	    }
+
+	  for (octave_idx_type j = 0; j < nc; j++)
+	    {
+	      Complex c = elem (i, j);
+
+	      if (strip_nan_and_inf)
+		{
+		  double re = std::real (c);
+		  double im = std::imag (c);
+
+		  if (xisinf (re))
+		    re = re > 0 ? OCT_RBV : -OCT_RBV;
+
+		  if (xisinf (im))
+		    im = im > 0 ? OCT_RBV : -OCT_RBV;
+
+		  c = Complex (re, im);
+		}
+	      else if (! infnan_warned && (xisnan (c) || xisinf (c)))
+		{
+		  (*current_liboctave_warning_handler)
+		    ("save: Inf or NaN values may not be reloadable");
+
+		  infnan_warned = true;
+		}
+
+	      octave_write_complex (os, c);
+
+	      os << " ";
+	    }
+
+	next_row_with_newline:
+	  os << "\n";
+
+	next_row:
+	  continue;
+	}
+    }
+  else
+    os << *this;
+
+  return os;
+}
+
 std::ostream&
 operator << (std::ostream& os, const ComplexMatrix& a)
 {
--- a/liboctave/CMatrix.h
+++ b/liboctave/CMatrix.h
@@ -319,6 +319,9 @@
 
   // i/o
 
+  std::ostream& save_ascii (std::ostream& os, bool& infnan_warned,
+			    int strip_nan_and_inf);
+
   friend std::ostream& operator << (std::ostream& os, const ComplexMatrix& a);
   friend std::istream& operator >> (std::istream& is, ComplexMatrix& a);
 
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,5 +1,8 @@
 2006-08-22  John W. Eaton  <jwe@octave.org>
 
+	* CMatrix.cc (ComplexMatrix::save_ascii): New function.
+	* dMatrix.cc (Matrix::save_ascii): New function.
+
 	* mx-inlines.cc (MX_ND_CUMULATIVE_OP): Correctly detect empty arrays.
 	If array is empty, return value is same size as array.
 	(MX_ND_REDUCTION): Correctly detect empty arrays.
--- a/liboctave/dMatrix.cc
+++ b/liboctave/dMatrix.cc
@@ -2851,6 +2851,74 @@
   return result;
 }
 
+// Used when converting Inf to something that gnuplot can read.
+
+#ifndef OCT_RBV
+#define OCT_RBV DBL_MAX / 100.0
+#endif
+
+std::ostream&
+Matrix::save_ascii (std::ostream& os, bool& infnan_warned,
+		    int strip_nan_and_inf)
+{
+  if (strip_nan_and_inf)
+    {
+      octave_idx_type nr = rows ();
+      octave_idx_type nc = columns ();
+
+      for (octave_idx_type i = 0; i < nr; i++)
+	{
+	  if (strip_nan_and_inf)
+	    {
+	      for (octave_idx_type j = 0; j < nc; j++)
+		{
+		  double d = elem (i, j);
+
+		  if (xisnan (d))
+		    {
+		      if (strip_nan_and_inf == 1)
+			goto next_row;
+		      else if (strip_nan_and_inf == 2)
+			goto next_row_with_newline;
+		    }
+		}
+	    }
+
+	  for (octave_idx_type j = 0; j < nc; j++)
+	    {
+	      double d = elem (i, j);
+
+	      if (strip_nan_and_inf)
+		{
+		  if (xisinf (d))
+		    d = d > 0 ? OCT_RBV : -OCT_RBV;
+		}
+	      else if (! infnan_warned && (xisnan (d) || xisinf (d)))
+		{
+		  (*current_liboctave_warning_handler)
+		    ("save: Inf or NaN values may not be reloadable");
+
+		  infnan_warned = true;
+		}
+
+	      octave_write_double (os, d);
+
+	      os << " ";
+	    }
+
+	next_row_with_newline:
+	  os << "\n";
+
+	next_row:
+	  continue;
+	}
+    }
+  else
+    os << *this;
+
+  return os;
+}
+
 std::ostream&
 operator << (std::ostream& os, const Matrix& a)
 {
--- a/liboctave/dMatrix.h
+++ b/liboctave/dMatrix.h
@@ -274,6 +274,9 @@
 
   // i/o
 
+  std::ostream& save_ascii (std::ostream& os, bool& infnan_warned,
+			    int strip_nan_and_inf);
+
   friend std::ostream& operator << (std::ostream& os, const Matrix& a);
   friend std::istream& operator >> (std::istream& is, Matrix& a);
 
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,44 @@
 2006-08-22  John W. Eaton  <jwe@octave.org>
 
+	* ov.h (octave_value::save_ascii): strip_nan_and_inf is now int,
+	not bool.
+	* ov-base.h, ov-base.cc (octave_base_value::save_ascii): Likewise.
+	* ov-base-int.h, ov-base-int.cc	(octave_base_int_matrix<T>::save_ascii,
+	octave_base_int_scalar<T>::save_ascii, ): Likewise.
+	* ov-base-sparse.cc, ov-base-sparse.h
+	(octave_base_sparse<T>::save_ascii): Likewise.
+	* ov-bool-mat.cc, ov-bool-mat.h (octave_bool_matrix::save_ascii):
+	Likewise.
+	* ov-bool.cc, ov-bool.h (octave_bool::save_ascii): Likewise.
+	* ov-cell.cc, ov-cell.h (octave_cell::save_ascii): Likewise.
+	* ov-complex.cc, ov-complex.h (octave_complex::save_ascii): Likewise.
+	* ov-fcn-handle.cc, ov-fcn-handle.h (octave_fcn_handle::save_ascii):
+	Likewise.
+	* ov-fcn-inline.cc, ov-fcn-inline.h (octave_fcn_inline::save_ascii):
+	Likewise.
+	* ov-list.cc, ov-list.h (octave_list::save_ascii): Likewise.
+	* ov-range.cc, ov-range.h (octave_range::save_ascii): Likewise.
+	* ov-scalar.cc, ov-scalar.h (octave_scalar::save_ascii): Likewise.
+	* ov-str-mat.cc, ov-str-mat.h (octave_char_matrix_str::save_ascii):
+	Likewise.
+	* ov-struct.cc, ov-struct.h (octave_struct::save_ascii): Likewise.
+	* ov-re-mat.cc, ov-re-mat.cc (octave_matrix::save_ascii): Likewise.
+	* ov-cx-mat.cc, ov-cx-mat.cc (octave_complex_matrix::save_ascii): Likewise.
+
+	* ov-cx-mat.cc, ov-cx-mat.cc (octave_complex_matrix::save_ascii):
+	Don't strip Inf and NaN here.  Call ComplexMatrix::save_ascii to
+	do the real work.
+	* ov-re-mat.cc, ov-re-mat.cc (octave_matrix::save_ascii):
+	Don't strip Inf and NaN here.  Call Matrix::save_ascii to do the
+	real work.
+
+	* ov-re-mat.cc, ov-cx-mat.cc (strip_infnan): Delete.
+	* ls-oct-ascii.cc, ls-oct-ascii.h (save_ascii_data):
+	strip_nan_and_inf is now int, not bool.
+	(strip_infnan): Delete.
+	(save_ascii_data_for_plotting): Call save_ascii_data with
+	strip_nan_and_inf = 2.
+
 	* Makefile.in (INCLUDES): Remove matrix.h from the list.
 
 2006-08-22  David Bateman  <dbateman@free.fr>
--- a/src/ls-oct-ascii.cc
+++ b/src/ls-oct-ascii.cc
@@ -72,37 +72,6 @@
 
 // Functions for reading ascii data.
 
-static Matrix
-strip_infnan (const Matrix& m)
-{
-  octave_idx_type nr = m.rows ();
-  octave_idx_type nc = m.columns ();
-
-  Matrix retval (nr, nc);
-
-  octave_idx_type k = 0;
-  for (octave_idx_type i = 0; i < nr; i++)
-    {
-      for (octave_idx_type j = 0; j < nc; j++)
-	{
-	  double d = m (i, j);
-	  if (xisnan (d))
-	    goto next_row;
-	  else
-	    retval (k, j) = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d;
-	}
-      k++;
-
-    next_row:
-      continue;
-    }
-
-  if (k > 0)
-    retval.resize (k, nc);
-
-  return retval;
-}
-
 // Extract a KEYWORD and its value from stream IS, returning the
 // associated value in a new string.
 //
@@ -338,10 +307,12 @@
 // flag MARK_AS_GLOBAL on stream OS in the plain text format described
 // above for load_ascii_data.  If NAME is empty, the name: line is not
 // generated.  PRECISION specifies the number of decimal digits to print. 
-// If STRIP_NAN_AND_INF is TRUE, rows containing NaNs are deleted,
+// If STRIP_NAN_AND_INF is 1, rows containing NaNs are deleted,
 // and Infinite values are converted to +/-OCT_RBV (A Real Big Value,
 // but not so big that gnuplot can't handle it when trying to compute
-// axis ranges, etc.).
+// axis ranges, etc.).  If STRIP_NAN_AND_INF is 2, rows containing
+// NaNs are converted to blank lines in the output file and infinite
+// values are converted to +/-OCT_RBV.
 //
 // Assumes ranges and strings cannot contain Inf or NaN values.
 //
@@ -352,7 +323,7 @@
 bool
 save_ascii_data (std::ostream& os, const octave_value& val_arg,
 		 const std::string& name, bool& infnan_warned,
-		 bool strip_nan_and_inf, bool mark_as_global,
+		 int strip_nan_and_inf, bool mark_as_global,
 		 int precision)
 {
   bool success = true;
@@ -386,7 +357,7 @@
 {
   bool infnan_warned = true;
 
-  return save_ascii_data (os, t, name, infnan_warned, false, false, 0);
+  return save_ascii_data (os, t, name, infnan_warned, 2, false, 0);
 }
 
 // Maybe this should be a static function in tree-plot.cc?
--- a/src/ls-oct-ascii.h
+++ b/src/ls-oct-ascii.h
@@ -51,7 +51,7 @@
 extern bool
 save_ascii_data (std::ostream& os, const octave_value& val_arg,
 		 const std::string& name, bool& infnan_warned,
-		 bool strip_nan_and_inf, bool mark_as_global,
+		 int strip_nan_and_inf, bool mark_as_global,
 		 int precision);
 
 extern bool
--- a/src/ov-base-int.cc
+++ b/src/ov-base-int.cc
@@ -70,7 +70,7 @@
 
 template <class T>
 bool
-octave_base_int_matrix<T>::save_ascii (std::ostream& os, bool&, bool)
+octave_base_int_matrix<T>::save_ascii (std::ostream& os, bool&, int)
 {
   dim_vector d = this->dims ();
 
@@ -331,7 +331,7 @@
 
 template <class T>
 bool
-octave_base_int_scalar<T>::save_ascii (std::ostream& os, bool& , bool)
+octave_base_int_scalar<T>::save_ascii (std::ostream& os, bool& , int)
 {
   os << this->scalar << "\n";
   return true;
--- a/src/ov-base-int.h
+++ b/src/ov-base-int.h
@@ -68,7 +68,7 @@
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		   bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
@@ -109,7 +109,7 @@
 
   //  void decrement (void) { scalar -= 1; }
 
-  bool save_ascii (std::ostream& os, bool&, bool );
+  bool save_ascii (std::ostream& os, bool&, int);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-base-sparse.cc
+++ b/src/ov-base-sparse.cc
@@ -295,7 +295,7 @@
 
 template <class T>
 bool
-octave_base_sparse<T>::save_ascii (std::ostream& os, bool&, bool)
+octave_base_sparse<T>::save_ascii (std::ostream& os, bool&, int)
 {
   dim_vector dv = this->dims ();
 
--- a/src/ov-base-sparse.h
+++ b/src/ov-base-sparse.h
@@ -142,7 +142,7 @@
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-base.cc
+++ b/src/ov-base.cc
@@ -815,7 +815,7 @@
 }
 
 bool 
-octave_base_value::save_ascii (std::ostream&, bool&, bool)
+octave_base_value::save_ascii (std::ostream&, bool&, int)
 {
   gripe_wrong_type_arg ("octave_base_value::save_ascii()", type_name ());
   return false;
--- a/src/ov-base.h
+++ b/src/ov-base.h
@@ -415,7 +415,7 @@
   virtual void print_info (std::ostream& os, const std::string& prefix) const;
 
   virtual bool save_ascii (std::ostream& os, bool& infnan_warned,
-			   bool strip_nan_and_inf);
+			   int strip_nan_and_inf);
 
   virtual bool load_ascii (std::istream& is);
 
--- a/src/ov-bool-mat.cc
+++ b/src/ov-bool-mat.cc
@@ -150,7 +150,7 @@
 
 bool 
 octave_bool_matrix::save_ascii (std::ostream& os, bool& /* infnan_warned */,
-				bool /* strip_nan_and_inf */)
+				int /* strip_nan_and_inf */)
 {
   dim_vector d = dims ();
   if (d.length () > 2)
--- a/src/ov-bool-mat.h
+++ b/src/ov-bool-mat.h
@@ -165,7 +165,7 @@
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-bool.cc
+++ b/src/ov-bool.cc
@@ -134,7 +134,7 @@
 
 bool 
 octave_bool::save_ascii (std::ostream& os, bool& /* infnan_warned */,
-			 bool /* strip_nan_and_inf */)
+			 int /* strip_nan_and_inf */)
 {
   double d = double_value ();
 
--- a/src/ov-bool.h
+++ b/src/ov-bool.h
@@ -157,7 +157,7 @@
   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-cell.cc
+++ b/src/ov-cell.cc
@@ -434,7 +434,7 @@
 
 bool 
 octave_cell::save_ascii (std::ostream& os, bool& infnan_warned, 
-			       bool strip_nan_and_inf)
+			 int strip_nan_and_inf)
 {
   dim_vector d = dims ();
   if (d.length () > 2)
--- a/src/ov-cell.h
+++ b/src/ov-cell.h
@@ -114,7 +114,7 @@
 
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-complex.cc
+++ b/src/ov-complex.cc
@@ -177,7 +177,7 @@
 
 bool 
 octave_complex::save_ascii (std::ostream& os, bool& infnan_warned, 
-			    bool strip_nan_and_inf)
+			    int strip_nan_and_inf)
 {
   Complex c = complex_value ();
 
--- a/src/ov-complex.h
+++ b/src/ov-complex.h
@@ -117,7 +117,7 @@
   void decrement (void) { scalar -= 1.0; }
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-cx-mat.cc
+++ b/src/ov-cx-mat.cc
@@ -200,48 +200,9 @@
   return SparseComplexMatrix (matrix.matrix_value ());
 }
 
-static ComplexMatrix
-strip_infnan (const ComplexMatrix& m)
-{
-  octave_idx_type nr = m.rows ();
-  octave_idx_type nc = m.columns ();
-
-  ComplexMatrix retval (nr, nc);
-
-  octave_idx_type k = 0;
-  for (octave_idx_type i = 0; i < nr; i++)
-    {
-      for (octave_idx_type j = 0; j < nc; j++)
-	{
-	  Complex c = m (i, j);
-	  if (xisnan (c))
-	    goto next_row;
-	  else
-	    {
-	      double re = std::real (c);
-	      double im = std::imag (c);
-
-	      re = xisinf (re) ? (re > 0 ? OCT_RBV : -OCT_RBV) : re;
-	      im = xisinf (im) ? (im > 0 ? OCT_RBV : -OCT_RBV) : im;
-
-	      retval (k, j) = Complex (re, im);
-	    }
-	}
-      k++;
-
-    next_row:
-      continue;
-    }
-
-  if (k > 0)
-    retval.resize (k, nc);
-
-  return retval;
-}
-
 bool 
 octave_complex_matrix::save_ascii (std::ostream& os, bool& infnan_warned, 
-			       bool strip_nan_and_inf)
+				   int strip_nan_and_inf)
 {
   dim_vector d = dims ();
   if (d.length () > 2)
@@ -276,15 +237,7 @@
 
       ComplexMatrix tmp = 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;
+      tmp.save_ascii (os, infnan_warned, strip_nan_and_inf);
     }
 
   return true;
--- a/src/ov-cx-mat.h
+++ b/src/ov-cx-mat.h
@@ -121,7 +121,7 @@
   void decrement (void) { matrix -= Complex (1.0); }
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-fcn-handle.cc
+++ b/src/ov-fcn-handle.cc
@@ -144,7 +144,7 @@
 }
 
 bool
-octave_fcn_handle::save_ascii (std::ostream& os, bool&, bool)
+octave_fcn_handle::save_ascii (std::ostream& os, bool&, int)
 {
   os << nm << "\n";
 
--- a/src/ov-fcn-handle.h
+++ b/src/ov-fcn-handle.h
@@ -85,7 +85,7 @@
   std::string fcn_name (void) const { return nm; }
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-fcn-inline.cc
+++ b/src/ov-fcn-inline.cc
@@ -90,7 +90,7 @@
 }
 
 bool
-octave_fcn_inline::save_ascii (std::ostream& os, bool&, bool)
+octave_fcn_inline::save_ascii (std::ostream& os, bool&, int)
 {
   os << "# nargs: " <<  ifargs.length () << "\n";
   for (int i = 0; i < ifargs.length (); i++)
--- a/src/ov-fcn-inline.h
+++ b/src/ov-fcn-inline.h
@@ -66,7 +66,7 @@
   octave_value convert_to_str_internal (bool, bool, char) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-list.cc
+++ b/src/ov-list.cc
@@ -539,7 +539,7 @@
 
 bool 
 octave_list::save_ascii (std::ostream& os, bool& infnan_warned, 
-			   bool strip_nan_and_inf)
+			 int strip_nan_and_inf)
 {
   octave_value_list lst = list_value ();
   os << "# length: " << lst.length () << "\n";
--- a/src/ov-list.h
+++ b/src/ov-list.h
@@ -100,7 +100,7 @@
   bool print_name_tag (std::ostream& os, const std::string& name) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-range.cc
+++ b/src/ov-range.cc
@@ -286,7 +286,7 @@
 
 bool 
 octave_range::save_ascii (std::ostream& os, bool& /* infnan_warned */,
-			  bool /* strip_nan_and_inf */)
+			  int /* strip_nan_and_inf */)
 {
   Range r = range_value ();
   double base = r.base ();
--- a/src/ov-range.h
+++ b/src/ov-range.h
@@ -187,7 +187,7 @@
   bool print_name_tag (std::ostream& os, const std::string& name) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-re-mat.cc
+++ b/src/ov-re-mat.cc
@@ -254,40 +254,9 @@
   return retval;
 }
 
-static Matrix
-strip_infnan (const Matrix& m)
-{
-  octave_idx_type nr = m.rows ();
-  octave_idx_type nc = m.columns ();
-
-  Matrix retval (nr, nc);
-
-  octave_idx_type k = 0;
-  for (octave_idx_type i = 0; i < nr; i++)
-    {
-      for (octave_idx_type j = 0; j < nc; j++)
-	{
-	  double d = m (i, j);
-	  if (xisnan (d))
-	    goto next_row;
-	  else
-	    retval (k, j) = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d;
-	}
-      k++;
-
-    next_row:
-      continue;
-    }
-
-  if (k > 0)
-    retval.resize (k, nc);
-
-  return retval;
-}
-
 bool 
 octave_matrix::save_ascii (std::ostream& os, bool& infnan_warned, 
-			       bool strip_nan_and_inf)
+			   int strip_nan_and_inf)
 {
   dim_vector d = dims ();
   if (d.length () > 2)
@@ -322,15 +291,7 @@
 
       Matrix tmp = 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;
+      tmp.save_ascii (os, infnan_warned, strip_nan_and_inf);
     }
 
   return true;
--- a/src/ov-re-mat.h
+++ b/src/ov-re-mat.h
@@ -156,7 +156,7 @@
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-scalar.cc
+++ b/src/ov-scalar.cc
@@ -157,7 +157,7 @@
 
 bool 
 octave_scalar::save_ascii (std::ostream& os, bool& infnan_warned, 
-			   bool strip_nan_and_inf)
+			   int strip_nan_and_inf)
 {
   double d = double_value ();
 
--- a/src/ov-scalar.h
+++ b/src/ov-scalar.h
@@ -187,7 +187,7 @@
   void decrement (void) { --scalar; }
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		 bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-str-mat.cc
+++ b/src/ov-str-mat.cc
@@ -271,7 +271,7 @@
 bool 
 octave_char_matrix_str::save_ascii (std::ostream& os,
 				    bool& /* infnan_warned */, 
-				    bool /* strip_nan_and_inf */)
+				    int /* strip_nan_and_inf */)
 {
   dim_vector d = dims ();
   if (d.length () > 2)
--- a/src/ov-str-mat.h
+++ b/src/ov-str-mat.h
@@ -130,7 +130,7 @@
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		   bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov-struct.cc
+++ b/src/ov-struct.cc
@@ -1017,7 +1017,7 @@
 
 bool
 octave_struct::save_ascii (std::ostream& os, bool& infnan_warned, 
-			   bool strip_nan_and_inf)
+			   int strip_nan_and_inf)
 {
   Octave_map m = map_value ();
   os << "# length: " << m.length () << "\n";
--- a/src/ov-struct.h
+++ b/src/ov-struct.h
@@ -118,7 +118,7 @@
   bool print_name_tag (std::ostream& os, const std::string& name) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-		   bool strip_nan_and_inf);
+		   int strip_nan_and_inf);
 
   bool load_ascii (std::istream& is);
 
--- a/src/ov.h
+++ b/src/ov.h
@@ -779,7 +779,7 @@
 			   const std::string& prefix = std::string ()) const;
 
   bool save_ascii (std::ostream& os, bool& infnan_warned,
-			   bool strip_nan_and_inf) 
+		   int strip_nan_and_inf) 
     { return rep->save_ascii (os, infnan_warned, strip_nan_and_inf); }
 
   bool load_ascii (std::istream& is)