# HG changeset patch # User jwe # Date 1155881213 0 # Node ID 5a3a716c257d2ced924ba5eea7a29676681d71bf # Parent 0c8ac963ae6928c4c9709e9c5a9ddefdfc03683b [project @ 2006-08-18 06:06:53 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2006-08-18 John W. Eaton + + * 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 * ls-mat5.cc (save_mat5_element_length): Correctly compute element diff --git a/src/load-save.cc b/src/load-save.cc --- a/src/load-save.cc +++ b/src/load-save.cc @@ -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\ diff --git a/src/load-save.h b/src/load-save.h --- a/src/load-save.h +++ b/src/load-save.h @@ -35,6 +35,7 @@ LS_ASCII, LS_BINARY, LS_MAT_ASCII, + LS_MAT_ASCII_LONG, LS_MAT_BINARY, LS_MAT5_BINARY, LS_MAT7_BINARY, diff --git a/src/ls-mat-ascii.cc b/src/ls-mat-ascii.cc --- a/src/ls-mat-ascii.cc +++ b/src/ls-mat-ascii.cc @@ -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++ *** diff --git a/src/ls-mat-ascii.h b/src/ls-mat-ascii.h --- a/src/ls-mat-ascii.h +++ b/src/ls-mat-ascii.h @@ -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 /*