octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnuplot changes affects octave


From: John W. Eaton
Subject: gnuplot changes affects octave
Date: Tue, 22 Aug 2006 16:36:43 -0400

On  6-Aug-2006, Dmitri A. Sergatskov wrote:

| Recently gnuplot (version 4.1) changed the way it handles NaN and
| their meaning. That affects gplot.m and probably some other octave
| scripts.
| 
| E.g. consider the following data file (say "test1.dat")
| 
| # -- begin --
| 0 1
| 1 0
| NaN NaN       
| 1 2
| 2 1
| # -- end
| 
| In gnuplot 4.0
| plot "test1.dat" with line
| will produce two line segments; NaN are handled automatically.
| 
| In gnuplot 4.1 one needs to do first
| set datafile missing "NaN"
| (note that will *not* handle "nan" only "NaN)
| but than it will connect the segments between (1 0) and (1 2).
| 
| If one replaces line that has NaNs with an empty line, the connecting
| segment will not be there.

So are you saying that Octave should be scanning the data looking for
rows of NaNs and then converting those to empty lines in the data file
that it creates for gnuplot to plot?  This should work with both old
and new versions of gnuplot, correct?  If so, then how about the
following changes?  It seems a bit messy to just be using int values
for the strip_nan_and_inf parameter, but it works.

jwe


liboctave/ChangeLog:

2006-08-22  John W. Eaton  <address@hidden>
 
        * CMatrix.cc (ComplexMatrix::save_ascii): New function.
        * dMatrix.cc (Matrix::save_ascii): New function.


src/ChangeLog:

2006-08-22  John W. Eaton  <address@hidden>
 
        * 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.


Index: liboctave/CMatrix.cc
===================================================================
RCS file: /cvs/octave/liboctave/CMatrix.cc,v
retrieving revision 1.117
diff -u -u -r1.117 CMatrix.cc
--- liboctave/CMatrix.cc        3 May 2006 19:32:46 -0000       1.117
+++ liboctave/CMatrix.cc        22 Aug 2006 20:29:37 -0000
@@ -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)
 {
Index: liboctave/CMatrix.h
===================================================================
RCS file: /cvs/octave/liboctave/CMatrix.h,v
retrieving revision 1.57
diff -u -u -r1.57 CMatrix.h
--- liboctave/CMatrix.h 3 May 2006 19:32:46 -0000       1.57
+++ liboctave/CMatrix.h 22 Aug 2006 20:29:37 -0000
@@ -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);
 
Index: liboctave/dMatrix.cc
===================================================================
RCS file: /cvs/octave/liboctave/dMatrix.cc,v
retrieving revision 1.124
diff -u -u -r1.124 dMatrix.cc
--- liboctave/dMatrix.cc        18 Aug 2006 21:27:03 -0000      1.124
+++ liboctave/dMatrix.cc        22 Aug 2006 20:29:39 -0000
@@ -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)
 {
Index: liboctave/dMatrix.h
===================================================================
RCS file: /cvs/octave/liboctave/dMatrix.h,v
retrieving revision 1.64
diff -u -u -r1.64 dMatrix.h
--- liboctave/dMatrix.h 18 Aug 2006 21:27:03 -0000      1.64
+++ liboctave/dMatrix.h 22 Aug 2006 20:29:39 -0000
@@ -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);
 
Index: src/ls-oct-ascii.cc
===================================================================
RCS file: /cvs/octave/src/ls-oct-ascii.cc,v
retrieving revision 1.16
diff -u -u -r1.16 ls-oct-ascii.cc
--- src/ls-oct-ascii.cc 22 Aug 2006 05:13:42 -0000      1.16
+++ src/ls-oct-ascii.cc 22 Aug 2006 20:29:43 -0000
@@ -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?
Index: src/ls-oct-ascii.h
===================================================================
RCS file: /cvs/octave/src/ls-oct-ascii.h,v
retrieving revision 1.8
diff -u -u -r1.8 ls-oct-ascii.h
--- src/ls-oct-ascii.h  17 Apr 2006 05:05:16 -0000      1.8
+++ src/ls-oct-ascii.h  22 Aug 2006 20:29:43 -0000
@@ -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
Index: src/ov-base-int.cc
===================================================================
RCS file: /cvs/octave/src/ov-base-int.cc,v
retrieving revision 1.10
diff -u -u -r1.10 ov-base-int.cc
--- src/ov-base-int.cc  23 May 2006 06:05:14 -0000      1.10
+++ src/ov-base-int.cc  22 Aug 2006 20:29:43 -0000
@@ -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;
Index: src/ov-base-int.h
===================================================================
RCS file: /cvs/octave/src/ov-base-int.h,v
retrieving revision 1.5
diff -u -u -r1.5 ov-base-int.h
--- src/ov-base-int.h   13 Apr 2006 13:04:32 -0000      1.5
+++ src/ov-base-int.h   22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-base-sparse.cc
===================================================================
RCS file: /cvs/octave/src/ov-base-sparse.cc,v
retrieving revision 1.11
diff -u -u -r1.11 ov-base-sparse.cc
--- src/ov-base-sparse.cc       14 Jul 2006 20:29:35 -0000      1.11
+++ src/ov-base-sparse.cc       22 Aug 2006 20:29:43 -0000
@@ -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 ();
 
Index: src/ov-base-sparse.h
===================================================================
RCS file: /cvs/octave/src/ov-base-sparse.h,v
retrieving revision 1.13
diff -u -u -r1.13 ov-base-sparse.h
--- src/ov-base-sparse.h        22 Jul 2006 08:31:17 -0000      1.13
+++ src/ov-base-sparse.h        22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-base.cc
===================================================================
RCS file: /cvs/octave/src/ov-base.cc,v
retrieving revision 1.87
diff -u -u -r1.87 ov-base.cc
--- src/ov-base.cc      18 Aug 2006 21:27:04 -0000      1.87
+++ src/ov-base.cc      22 Aug 2006 20:29:43 -0000
@@ -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;
Index: src/ov-base.h
===================================================================
RCS file: /cvs/octave/src/ov-base.h,v
retrieving revision 1.97
diff -u -u -r1.97 ov-base.h
--- src/ov-base.h       18 Aug 2006 21:27:04 -0000      1.97
+++ src/ov-base.h       22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-bool-mat.cc
===================================================================
RCS file: /cvs/octave/src/ov-bool-mat.cc,v
retrieving revision 1.40
diff -u -u -r1.40 ov-bool-mat.cc
--- src/ov-bool-mat.cc  22 Jul 2006 08:31:17 -0000      1.40
+++ src/ov-bool-mat.cc  22 Aug 2006 20:29:43 -0000
@@ -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)
Index: src/ov-bool-mat.h
===================================================================
RCS file: /cvs/octave/src/ov-bool-mat.h,v
retrieving revision 1.45
diff -u -u -r1.45 ov-bool-mat.h
--- src/ov-bool-mat.h   18 Aug 2006 21:34:00 -0000      1.45
+++ src/ov-bool-mat.h   22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-bool.cc
===================================================================
RCS file: /cvs/octave/src/ov-bool.cc,v
retrieving revision 1.30
diff -u -u -r1.30 ov-bool.cc
--- src/ov-bool.cc      22 Jul 2006 08:31:17 -0000      1.30
+++ src/ov-bool.cc      22 Aug 2006 20:29:43 -0000
@@ -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 ();
 
Index: src/ov-bool.h
===================================================================
RCS file: /cvs/octave/src/ov-bool.h,v
retrieving revision 1.36
diff -u -u -r1.36 ov-bool.h
--- src/ov-bool.h       18 Aug 2006 21:34:00 -0000      1.36
+++ src/ov-bool.h       22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-cell.cc
===================================================================
RCS file: /cvs/octave/src/ov-cell.cc,v
retrieving revision 1.70
diff -u -u -r1.70 ov-cell.cc
--- src/ov-cell.cc      14 Aug 2006 19:44:17 -0000      1.70
+++ src/ov-cell.cc      22 Aug 2006 20:29:43 -0000
@@ -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)
Index: src/ov-cell.h
===================================================================
RCS file: /cvs/octave/src/ov-cell.h,v
retrieving revision 1.32
diff -u -u -r1.32 ov-cell.h
--- src/ov-cell.h       22 Jul 2006 08:31:17 -0000      1.32
+++ src/ov-cell.h       22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-complex.cc
===================================================================
RCS file: /cvs/octave/src/ov-complex.cc,v
retrieving revision 1.37
diff -u -u -r1.37 ov-complex.cc
--- src/ov-complex.cc   22 Jul 2006 08:31:17 -0000      1.37
+++ src/ov-complex.cc   22 Aug 2006 20:29:43 -0000
@@ -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 ();
 
Index: src/ov-complex.h
===================================================================
RCS file: /cvs/octave/src/ov-complex.h,v
retrieving revision 1.37
diff -u -u -r1.37 ov-complex.h
--- src/ov-complex.h    22 Jul 2006 08:31:17 -0000      1.37
+++ src/ov-complex.h    22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-cx-mat.cc
===================================================================
RCS file: /cvs/octave/src/ov-cx-mat.cc,v
retrieving revision 1.53
diff -u -u -r1.53 ov-cx-mat.cc
--- src/ov-cx-mat.cc    22 Jul 2006 08:31:17 -0000      1.53
+++ src/ov-cx-mat.cc    22 Aug 2006 20:29:43 -0000
@@ -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;
Index: src/ov-cx-mat.h
===================================================================
RCS file: /cvs/octave/src/ov-cx-mat.h,v
retrieving revision 1.42
diff -u -u -r1.42 ov-cx-mat.h
--- src/ov-cx-mat.h     22 Jul 2006 08:31:17 -0000      1.42
+++ src/ov-cx-mat.h     22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-fcn-handle.cc
===================================================================
RCS file: /cvs/octave/src/ov-fcn-handle.cc,v
retrieving revision 1.30
diff -u -u -r1.30 ov-fcn-handle.cc
--- src/ov-fcn-handle.cc        21 Aug 2006 15:57:09 -0000      1.30
+++ src/ov-fcn-handle.cc        22 Aug 2006 20:29:43 -0000
@@ -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";
 
Index: src/ov-fcn-handle.h
===================================================================
RCS file: /cvs/octave/src/ov-fcn-handle.h,v
retrieving revision 1.20
diff -u -u -r1.20 ov-fcn-handle.h
--- src/ov-fcn-handle.h 13 Apr 2006 13:04:33 -0000      1.20
+++ src/ov-fcn-handle.h 22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-fcn-inline.cc
===================================================================
RCS file: /cvs/octave/src/ov-fcn-inline.cc,v
retrieving revision 1.26
diff -u -u -r1.26 ov-fcn-inline.cc
--- src/ov-fcn-inline.cc        23 May 2006 06:05:14 -0000      1.26
+++ src/ov-fcn-inline.cc        22 Aug 2006 20:29:43 -0000
@@ -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++)
Index: src/ov-fcn-inline.h
===================================================================
RCS file: /cvs/octave/src/ov-fcn-inline.h,v
retrieving revision 1.9
diff -u -u -r1.9 ov-fcn-inline.h
--- src/ov-fcn-inline.h 13 Apr 2006 13:04:33 -0000      1.9
+++ src/ov-fcn-inline.h 22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-list.cc
===================================================================
RCS file: /cvs/octave/src/ov-list.cc,v
retrieving revision 1.54
diff -u -u -r1.54 ov-list.cc
--- src/ov-list.cc      14 Jul 2006 20:29:35 -0000      1.54
+++ src/ov-list.cc      22 Aug 2006 20:29:43 -0000
@@ -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";
Index: src/ov-list.h
===================================================================
RCS file: /cvs/octave/src/ov-list.h,v
retrieving revision 1.29
diff -u -u -r1.29 ov-list.h
--- src/ov-list.h       14 Jul 2006 20:29:35 -0000      1.29
+++ src/ov-list.h       22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-range.cc
===================================================================
RCS file: /cvs/octave/src/ov-range.cc,v
retrieving revision 1.50
diff -u -u -r1.50 ov-range.cc
--- src/ov-range.cc     22 Jul 2006 08:31:17 -0000      1.50
+++ src/ov-range.cc     22 Aug 2006 20:29:43 -0000
@@ -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 ();
Index: src/ov-range.h
===================================================================
RCS file: /cvs/octave/src/ov-range.h,v
retrieving revision 1.57
diff -u -u -r1.57 ov-range.h
--- src/ov-range.h      18 Aug 2006 21:27:04 -0000      1.57
+++ src/ov-range.h      22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-re-mat.cc
===================================================================
RCS file: /cvs/octave/src/ov-re-mat.cc,v
retrieving revision 1.64
diff -u -u -r1.64 ov-re-mat.cc
--- src/ov-re-mat.cc    18 Aug 2006 21:27:04 -0000      1.64
+++ src/ov-re-mat.cc    22 Aug 2006 20:29:43 -0000
@@ -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;
Index: src/ov-re-mat.h
===================================================================
RCS file: /cvs/octave/src/ov-re-mat.h,v
retrieving revision 1.55
diff -u -u -r1.55 ov-re-mat.h
--- src/ov-re-mat.h     18 Aug 2006 21:27:04 -0000      1.55
+++ src/ov-re-mat.h     22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-scalar.cc
===================================================================
RCS file: /cvs/octave/src/ov-scalar.cc,v
retrieving revision 1.36
diff -u -u -r1.36 ov-scalar.cc
--- src/ov-scalar.cc    22 Jul 2006 08:31:17 -0000      1.36
+++ src/ov-scalar.cc    22 Aug 2006 20:29:43 -0000
@@ -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 ();
 
Index: src/ov-scalar.h
===================================================================
RCS file: /cvs/octave/src/ov-scalar.h,v
retrieving revision 1.47
diff -u -u -r1.47 ov-scalar.h
--- src/ov-scalar.h     18 Aug 2006 21:27:04 -0000      1.47
+++ src/ov-scalar.h     22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-str-mat.cc
===================================================================
RCS file: /cvs/octave/src/ov-str-mat.cc,v
retrieving revision 1.64
diff -u -u -r1.64 ov-str-mat.cc
--- src/ov-str-mat.cc   14 Jul 2006 20:29:35 -0000      1.64
+++ src/ov-str-mat.cc   22 Aug 2006 20:29:43 -0000
@@ -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)
Index: src/ov-str-mat.h
===================================================================
RCS file: /cvs/octave/src/ov-str-mat.h,v
retrieving revision 1.47
diff -u -u -r1.47 ov-str-mat.h
--- src/ov-str-mat.h    15 Jul 2006 13:00:43 -0000      1.47
+++ src/ov-str-mat.h    22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov-struct.cc
===================================================================
RCS file: /cvs/octave/src/ov-struct.cc,v
retrieving revision 1.75
diff -u -u -r1.75 ov-struct.cc
--- src/ov-struct.cc    22 Jul 2006 08:31:17 -0000      1.75
+++ src/ov-struct.cc    22 Aug 2006 20:29:43 -0000
@@ -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";
Index: src/ov-struct.h
===================================================================
RCS file: /cvs/octave/src/ov-struct.h,v
retrieving revision 1.37
diff -u -u -r1.37 ov-struct.h
--- src/ov-struct.h     22 Jul 2006 08:31:17 -0000      1.37
+++ src/ov-struct.h     22 Aug 2006 20:29:43 -0000
@@ -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);
 
Index: src/ov.h
===================================================================
RCS file: /cvs/octave/src/ov.h,v
retrieving revision 1.148
diff -u -u -r1.148 ov.h
--- src/ov.h    18 Aug 2006 21:27:04 -0000      1.148
+++ src/ov.h    22 Aug 2006 20:29:44 -0000
@@ -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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]