changeset 5938:5a3a716c257d

[project @ 2006-08-18 06:06:53 by jwe]
author jwe
date Fri, 18 Aug 2006 06:06:53 +0000
parents 0c8ac963ae69
children 2e86e3601e0f
files src/ChangeLog src/load-save.cc src/load-save.h src/ls-mat-ascii.cc src/ls-mat-ascii.h
diffstat 5 files changed, 54 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Aug 18 00:58:08 2006 +0000
+++ b/src/ChangeLog	Fri Aug 18 06:06:53 2006 +0000
@@ -1,3 +1,11 @@
+2006-08-18  John W. Eaton  <jwe@octave.org>
+
+	* load-save.h (enum load_save_format): New element, LS_MAT_ASCII_LONG.
+	* load-save.cc (Fload, Fsave): Make -ascii Matlab compatible.
+	(do_save): Handle LS_MAT_ASCII.
+	* ls-mat-ascii.cc (save_mat_ascii_data): New function.
+	* ls-mat-ascii.h: Provide decl.
+
 2006-08-17  John W. Eaton  <jwe@octave.org>
 
 	* ls-mat5.cc (save_mat5_element_length): Correctly compute element
--- a/src/load-save.cc	Fri Aug 18 00:58:08 2006 +0000
+++ b/src/load-save.cc	Fri Aug 18 06:06:53 2006 +0000
@@ -649,12 +649,10 @@
 the same name as those found in the file.\n\
 \n\
 @item -ascii\n\
-Force Octave to assume the file is in Octave's text format.\n\
-\n\
-@strong{WARNING: the meaning of this option will change in a future\n\
-version of Octave to be compatible with @sc{Matlab}.  To keep the\n\
-meaning of your code the same across this change, use the @code{-text}\n\
-option instead.}\n\
+Force Octave to assume the file contains columns of numbers in text format\n\
+without any header or other information.  Data in the file will be loaded\n\
+as a single numeric matrix with the name of the variable derived from the\n\
+name of the file.\n\
 \n\
 @item -binary\n\
 Force Octave to assume the file is in Octave's binary format.\n\
@@ -732,12 +730,7 @@
 	}
       else if (argv[i] == "-ascii" || argv[i] == "-a")
 	{
-	  warning ("the meaning of this option will change in a future");
-	  warning ("version of Octave to be compatible with Matlab.");
-	  warning ("To keep the meaning of your code the same across");
-	  warning ("this change, use the -text option instead.");
-
-	  format = LS_ASCII;
+	  format = LS_MAT_ASCII;
 	}
       else if (argv[i] == "-binary" || argv[i] == "-b")
 	{
@@ -1007,6 +1000,12 @@
       save_binary_data (os, tc, name, help, global, save_as_floats);
       break;
 
+    case LS_MAT_ASCII:
+    case LS_MAT_ASCII_LONG:
+      if (! save_mat_ascii_data (os, tc, fmt == LS_MAT_ASCII ? 8 : 16))
+	warning ("save: unable to save %s in ASCII format", name.c_str ());
+      break;
+
     case LS_MAT_BINARY:
       save_mat_binary_data (os, tc, name);
       break;
@@ -1096,12 +1095,7 @@
 	}
       else if (argv[i] == "-ascii" || argv[i] == "-a")
 	{
-	  warning ("the meaning of this option will change in a future");
-	  warning ("version of Octave to be compatible with Matlab.");
-	  warning ("To keep the meaning of your code the same across");
-	  warning ("this change, use the -text option instead.");
-
-	  format = LS_ASCII;
+	  format = LS_MAT_ASCII;
 	}
       else if (argv[i] == "-text" || argv[i] == "-t")
 	{
@@ -1461,12 +1455,7 @@
 \n\
 @table @code\n\
 @item -ascii\n\
-Save the data in Octave's text data format.\n\
-\n\
-@strong{WARNING: the meaning of this option will change in a future\n\
-version of Octave to be compatible with @sc{Matlab}.  To keep the\n\
-meaning of your code the same across this change, use the @code{-text}\n\
-option instead.}\n\
+Save a single matrix in a text file.\n\
 \n\
 @item -binary\n\
 Save the data in Octave's binary data format.\n\
--- a/src/load-save.h	Fri Aug 18 00:58:08 2006 +0000
+++ b/src/load-save.h	Fri Aug 18 06:06:53 2006 +0000
@@ -35,6 +35,7 @@
     LS_ASCII,
     LS_BINARY,
     LS_MAT_ASCII,
+    LS_MAT_ASCII_LONG,
     LS_MAT_BINARY,
     LS_MAT5_BINARY,
     LS_MAT7_BINARY,
--- a/src/ls-mat-ascii.cc	Fri Aug 18 00:58:08 2006 +0000
+++ b/src/ls-mat-ascii.cc	Fri Aug 18 06:06:53 2006 +0000
@@ -328,6 +328,34 @@
   return retval;
 }
 
+bool
+save_mat_ascii_data (std::ostream& os, const octave_value& val,
+		     int precision)
+{
+  bool success = true;
+
+  long old_precision = os.precision ();
+  os.precision (precision);
+
+  if (val.is_complex_type ())
+    warning ("save: omitting imaginary part for ASCII file");
+
+  Matrix m = val.matrix_value (true);
+
+  if (error_state)
+    {
+      success = false;
+
+      error_state = 0;
+    }
+  else
+    os << m;
+
+  os.precision (old_precision);
+
+  return (os && success);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/ls-mat-ascii.h	Fri Aug 18 00:58:08 2006 +0000
+++ b/src/ls-mat-ascii.h	Fri Aug 18 06:06:53 2006 +0000
@@ -28,6 +28,10 @@
 read_mat_ascii_data (std::istream& is, const std::string& filename,
 		     octave_value& tc);
 
+extern bool
+save_mat_ascii_data (std::ostream& os, const octave_value& val_arg,
+		     int precision);
+
 #endif
 
 /*