comparison src/load-save.cc @ 3523:b80bbb43a1a9

[project @ 2000-02-02 10:25:52 by jwe]
author jwe
date Wed, 02 Feb 2000 10:26:25 +0000
parents d14c483b3c12
children 97cf542676e1
comparison
equal deleted inserted replaced
3522:bd422cf62f0c 3523:b80bbb43a1a9
61 // The number of decimal digits to use when writing ascii data. 61 // The number of decimal digits to use when writing ascii data.
62 static bool Vcrash_dumps_octave_core; 62 static bool Vcrash_dumps_octave_core;
63 63
64 // The default output format. May be one of "binary", "text", or 64 // The default output format. May be one of "binary", "text", or
65 // "mat-binary". 65 // "mat-binary".
66 static string Vdefault_save_format; 66 static std::string Vdefault_save_format;
67 67
68 // The number of decimal digits to use when writing ascii data. 68 // The number of decimal digits to use when writing ascii data.
69 static int Vsave_precision; 69 static int Vsave_precision;
70 70
71 // Used when converting Inf to something that gnuplot can read. 71 // Used when converting Inf to something that gnuplot can read.
97 97
98 return true; 98 return true;
99 } 99 }
100 100
101 static bool 101 static bool
102 valid_identifier (const string& s) 102 valid_identifier (const std::string& s)
103 { 103 {
104 return valid_identifier (s.c_str ()); 104 return valid_identifier (s.c_str ());
105 } 105 }
106 106
107 // XXX FIXME XXX -- shouldn't this be implemented in terms of other 107 // XXX FIXME XXX -- shouldn't this be implemented in terms of other
246 // Functions for reading ascii data. 246 // Functions for reading ascii data.
247 247
248 // Skip white space and comments on stream IS. 248 // Skip white space and comments on stream IS.
249 249
250 static void 250 static void
251 skip_comments (istream& is) 251 skip_comments (std::istream& is)
252 { 252 {
253 char c = '\0'; 253 char c = '\0';
254 while (is.get (c)) 254 while (is.get (c))
255 { 255 {
256 if (c == ' ' || c == '\t' || c == '\n') 256 if (c == ' ' || c == '\t' || c == '\n')
275 // Input should look something like: 275 // Input should look something like:
276 // 276 //
277 // #[ \t]*keyword[ \t]*:[ \t]*string-value[ \t]*\n 277 // #[ \t]*keyword[ \t]*:[ \t]*string-value[ \t]*\n
278 278
279 static char * 279 static char *
280 extract_keyword (istream& is, const char *keyword) 280 extract_keyword (std::istream& is, const char *keyword)
281 { 281 {
282 char *retval = 0; 282 char *retval = 0;
283 283
284 char c; 284 char c;
285 while (is.get (c)) 285 while (is.get (c))
286 { 286 {
287 if (c == '#') 287 if (c == '#')
288 { 288 {
289 ostrstream buf; 289 std::ostrstream buf;
290 290
291 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) 291 while (is.get (c) && (c == ' ' || c == '\t' || c == '#'))
292 ; // Skip whitespace and comment characters. 292 ; // Skip whitespace and comment characters.
293 293
294 if (isalpha (c)) 294 if (isalpha (c))
302 int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); 302 int match = (strncmp (tmp, keyword, strlen (keyword)) == 0);
303 delete [] tmp; 303 delete [] tmp;
304 304
305 if (match) 305 if (match)
306 { 306 {
307 ostrstream value; 307 std::ostrstream value;
308 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) 308 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
309 ; // Skip whitespace and the colon. 309 ; // Skip whitespace and the colon.
310 310
311 if (c != '\n') 311 if (c != '\n')
312 { 312 {
342 // Input should look something like: 342 // Input should look something like:
343 // 343 //
344 // [ \t]*keyword[ \t]*int-value.*\n 344 // [ \t]*keyword[ \t]*int-value.*\n
345 345
346 static bool 346 static bool
347 extract_keyword (istream& is, const char *keyword, int& value) 347 extract_keyword (std::istream& is, const char *keyword, int& value)
348 { 348 {
349 bool status = false; 349 bool status = false;
350 value = 0; 350 value = 0;
351 351
352 char c; 352 char c;
353 while (is.get (c)) 353 while (is.get (c))
354 { 354 {
355 if (c == '#') 355 if (c == '#')
356 { 356 {
357 ostrstream buf; 357 std::ostrstream buf;
358 358
359 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) 359 while (is.get (c) && (c == ' ' || c == '\t' || c == '#'))
360 ; // Skip whitespace and comment characters. 360 ; // Skip whitespace and comment characters.
361 361
362 if (isalpha (c)) 362 if (isalpha (c))
466 // 466 //
467 // XXX FIXME XXX -- this format is fairly rigid, and doesn't allow for 467 // XXX FIXME XXX -- this format is fairly rigid, and doesn't allow for
468 // arbitrary comments, etc. Someone should fix that. 468 // arbitrary comments, etc. Someone should fix that.
469 469
470 static char * 470 static char *
471 read_ascii_data (istream& is, const string& filename, bool& global, 471 read_ascii_data (std::istream& is, const std::string& filename, bool& global,
472 octave_value& tc, int count) 472 octave_value& tc, int count)
473 { 473 {
474 // Read name for this entry or break on EOF. 474 // Read name for this entry or break on EOF.
475 475
476 char *name = extract_keyword (is, "name"); 476 char *name = extract_keyword (is, "name");
737 // data string length 737 // data string length
738 // 738 //
739 // FILENAME is used for error messages. 739 // FILENAME is used for error messages.
740 740
741 static char * 741 static char *
742 read_binary_data (istream& is, bool swap, 742 read_binary_data (std::istream& is, bool swap,
743 oct_mach_info::float_format fmt, 743 oct_mach_info::float_format fmt,
744 const string& filename, bool& global, 744 const std::string& filename, bool& global,
745 octave_value& tc, char *&doc) 745 octave_value& tc, char *&doc)
746 { 746 {
747 char tmp = 0; 747 char tmp = 0;
748 748
749 FOUR_BYTE_INT name_len = 0; 749 FOUR_BYTE_INT name_len = 0;
944 944
945 return name; 945 return name;
946 } 946 }
947 947
948 static string 948 static string
949 get_mat_data_input_line (istream& is) 949 get_mat_data_input_line (std::istream& is)
950 { 950 {
951 string retval; 951 std::string retval;
952 952
953 bool have_data = false; 953 bool have_data = false;
954 954
955 do 955 do
956 { 956 {
984 984
985 return retval; 985 return retval;
986 } 986 }
987 987
988 static void 988 static void
989 get_lines_and_columns (istream& is, const string& filename, int& nr, int& nc) 989 get_lines_and_columns (std::istream& is, const std::string& filename, int& nr, int& nc)
990 { 990 {
991 streampos pos = is.tellg (); 991 streampos pos = is.tellg ();
992 992
993 int file_line_number = 0; 993 int file_line_number = 0;
994 994
995 nr = 0; 995 nr = 0;
996 nc = 0; 996 nc = 0;
997 997
998 while (is && ! error_state) 998 while (is && ! error_state)
999 { 999 {
1000 string buf = get_mat_data_input_line (is); 1000 std::string buf = get_mat_data_input_line (is);
1001 1001
1002 file_line_number++; 1002 file_line_number++;
1003 1003
1004 size_t beg = buf.find_first_not_of (" \t"); 1004 size_t beg = buf.find_first_not_of (" \t");
1005 1005
1049 // FILENAME is used for error messages. 1049 // FILENAME is used for error messages.
1050 // 1050 //
1051 // This format provides no way to tag the data as global. 1051 // This format provides no way to tag the data as global.
1052 1052
1053 static char * 1053 static char *
1054 read_mat_ascii_data (istream& is, const string& filename, 1054 read_mat_ascii_data (std::istream& is, const std::string& filename,
1055 octave_value& tc) 1055 octave_value& tc)
1056 { 1056 {
1057 char *name = 0; 1057 char *name = 0;
1058 1058
1059 string varname; 1059 std::string varname;
1060 1060
1061 size_t pos = filename.rfind ('/'); 1061 size_t pos = filename.rfind ('/');
1062 1062
1063 if (pos != NPOS) 1063 if (pos != NPOS)
1064 varname = filename.substr (pos+1); 1064 varname = filename.substr (pos+1);
1086 else 1086 else
1087 { 1087 {
1088 double d; 1088 double d;
1089 for (int i = 0; i < nr; i++) 1089 for (int i = 0; i < nr; i++)
1090 { 1090 {
1091 string buf = get_mat_data_input_line (is); 1091 std::string buf = get_mat_data_input_line (is);
1092 1092
1093 istrstream tmp_stream (buf.c_str ()); 1093 std::istrstream tmp_stream (buf.c_str ());
1094 1094
1095 for (int j = 0; j < nc; j++) 1095 for (int j = 0; j < nc; j++)
1096 { 1096 {
1097 tmp_stream >> d; 1097 tmp_stream >> d;
1098 1098
1136 // the bytes of each element before copying to DATA. FLT_FMT 1136 // the bytes of each element before copying to DATA. FLT_FMT
1137 // specifies the format of the data if we are reading floating point 1137 // specifies the format of the data if we are reading floating point
1138 // numbers. 1138 // numbers.
1139 1139
1140 static void 1140 static void
1141 read_mat_binary_data (istream& is, double *data, int precision, 1141 read_mat_binary_data (std::istream& is, double *data, int precision,
1142 int len, bool swap, 1142 int len, bool swap,
1143 oct_mach_info::float_format flt_fmt) 1143 oct_mach_info::float_format flt_fmt)
1144 { 1144 {
1145 switch (precision) 1145 switch (precision)
1146 { 1146 {
1172 break; 1172 break;
1173 } 1173 }
1174 } 1174 }
1175 1175
1176 static int 1176 static int
1177 read_mat_file_header (istream& is, bool& swap, FOUR_BYTE_INT& mopt, 1177 read_mat_file_header (std::istream& is, bool& swap, FOUR_BYTE_INT& mopt,
1178 FOUR_BYTE_INT& nr, FOUR_BYTE_INT& nc, 1178 FOUR_BYTE_INT& nr, FOUR_BYTE_INT& nc,
1179 FOUR_BYTE_INT& imag, FOUR_BYTE_INT& len, 1179 FOUR_BYTE_INT& imag, FOUR_BYTE_INT& len,
1180 int quiet = 0) 1180 int quiet = 0)
1181 { 1181 {
1182 swap = false; 1182 swap = false;
1321 // FILENAME is used for error messages. 1321 // FILENAME is used for error messages.
1322 // 1322 //
1323 // This format provides no way to tag the data as global. 1323 // This format provides no way to tag the data as global.
1324 1324
1325 static char * 1325 static char *
1326 read_mat_binary_data (istream& is, const string& filename, 1326 read_mat_binary_data (std::istream& is, const std::string& filename,
1327 octave_value& tc) 1327 octave_value& tc)
1328 { 1328 {
1329 // These are initialized here instead of closer to where they are 1329 // These are initialized here instead of closer to where they are
1330 // first used to avoid errors from gcc about goto crossing 1330 // first used to avoid errors from gcc about goto crossing
1331 // initialization of variable. 1331 // initialization of variable.
1445 1445
1446 // Return TRUE if NAME matches one of the given globbing PATTERNS. 1446 // Return TRUE if NAME matches one of the given globbing PATTERNS.
1447 1447
1448 static bool 1448 static bool
1449 matches_patterns (const string_vector& patterns, int pat_idx, 1449 matches_patterns (const string_vector& patterns, int pat_idx,
1450 int num_pat, const string& name) 1450 int num_pat, const std::string& name)
1451 { 1451 {
1452 for (int i = pat_idx; i < num_pat; i++) 1452 for (int i = pat_idx; i < num_pat; i++)
1453 { 1453 {
1454 glob_match pattern (patterns[i]); 1454 glob_match pattern (patterns[i]);
1455 1455
1458 } 1458 }
1459 return false; 1459 return false;
1460 } 1460 }
1461 1461
1462 static int 1462 static int
1463 read_binary_file_header (istream& is, bool& swap, 1463 read_binary_file_header (std::istream& is, bool& swap,
1464 oct_mach_info::float_format& flt_fmt, 1464 oct_mach_info::float_format& flt_fmt,
1465 bool quiet = false) 1465 bool quiet = false)
1466 { 1466 {
1467 int magic_len = 10; 1467 int magic_len = 10;
1468 char magic [magic_len+1]; 1468 char magic [magic_len+1];
1493 1493
1494 return 0; 1494 return 0;
1495 } 1495 }
1496 1496
1497 static load_save_format 1497 static load_save_format
1498 get_file_format (const string& fname, const string& orig_fname) 1498 get_file_format (const std::string& fname, const std::string& orig_fname)
1499 { 1499 {
1500 load_save_format retval = LS_UNKNOWN; 1500 load_save_format retval = LS_UNKNOWN;
1501 1501
1502 ifstream file (fname.c_str ()); 1502 std::ifstream file (fname.c_str ());
1503 1503
1504 if (! file) 1504 if (! file)
1505 { 1505 {
1506 error ("load: couldn't open input file `%s'", orig_fname.c_str ()); 1506 error ("load: couldn't open input file `%s'", orig_fname.c_str ());
1507 return retval; 1507 return retval;
1558 1558
1559 return retval; 1559 return retval;
1560 } 1560 }
1561 1561
1562 static octave_value_list 1562 static octave_value_list
1563 do_load (istream& stream, const string& orig_fname, bool force, 1563 do_load (std::istream& stream, const std::string& orig_fname, bool force,
1564 load_save_format format, oct_mach_info::float_format flt_fmt, 1564 load_save_format format, oct_mach_info::float_format flt_fmt,
1565 bool list_only, bool swap, bool verbose, const string_vector& argv, 1565 bool list_only, bool swap, bool verbose, const string_vector& argv,
1566 int argv_idx, int argc, int nargout) 1566 int argv_idx, int argc, int nargout)
1567 { 1567 {
1568 octave_value_list retval; 1568 octave_value_list retval;
1569 1569
1570 ostrstream output_buf; 1570 std::ostrstream output_buf;
1571 int count = 0; 1571 int count = 0;
1572 for (;;) 1572 for (;;)
1573 { 1573 {
1574 bool global = false; 1574 bool global = false;
1575 octave_value tc; 1575 octave_value tc;
1788 { 1788 {
1789 print_usage ("load"); 1789 print_usage ("load");
1790 return retval; 1790 return retval;
1791 } 1791 }
1792 1792
1793 string orig_fname = argv[i]; 1793 std::string orig_fname = argv[i];
1794 1794
1795 oct_mach_info::float_format flt_fmt = oct_mach_info::unknown; 1795 oct_mach_info::float_format flt_fmt = oct_mach_info::unknown;
1796 1796
1797 bool swap = false; 1797 bool swap = false;
1798 1798
1814 else 1814 else
1815 error ("load: must specify file format if reading from stdin"); 1815 error ("load: must specify file format if reading from stdin");
1816 } 1816 }
1817 else 1817 else
1818 { 1818 {
1819 string fname = file_ops::tilde_expand (argv[i]); 1819 std::string fname = file_ops::tilde_expand (argv[i]);
1820 1820
1821 if (format == LS_UNKNOWN) 1821 if (format == LS_UNKNOWN)
1822 format = get_file_format (fname, orig_fname); 1822 format = get_file_format (fname, orig_fname);
1823 1823
1824 if (format != LS_UNKNOWN) 1824 if (format != LS_UNKNOWN)
1827 1827
1828 unsigned mode = ios::in; 1828 unsigned mode = ios::in;
1829 if (format == LS_BINARY || format == LS_MAT_BINARY) 1829 if (format == LS_BINARY || format == LS_MAT_BINARY)
1830 mode |= ios::bin; 1830 mode |= ios::bin;
1831 1831
1832 ifstream file (fname.c_str (), mode); 1832 std::ifstream file (fname.c_str (), mode);
1833 1833
1834 if (file) 1834 if (file)
1835 { 1835 {
1836 if (format == LS_BINARY) 1836 if (format == LS_BINARY)
1837 { 1837 {
1858 } 1858 }
1859 1859
1860 // Return TRUE if PATTERN has any special globbing chars in it. 1860 // Return TRUE if PATTERN has any special globbing chars in it.
1861 1861
1862 static bool 1862 static bool
1863 glob_pattern_p (const string& pattern) 1863 glob_pattern_p (const std::string& pattern)
1864 { 1864 {
1865 int open = 0; 1865 int open = 0;
1866 1866
1867 int len = pattern.length (); 1867 int len = pattern.length ();
1868 1868
1924 // Save the data from TC along with the corresponding NAME, help 1924 // Save the data from TC along with the corresponding NAME, help
1925 // string DOC, and global flag MARK_AS_GLOBAL on stream OS in the 1925 // string DOC, and global flag MARK_AS_GLOBAL on stream OS in the
1926 // binary format described above for read_binary_data. 1926 // binary format described above for read_binary_data.
1927 1927
1928 static bool 1928 static bool
1929 save_binary_data (ostream& os, const octave_value& tc, 1929 save_binary_data (std::ostream& os, const octave_value& tc,
1930 const string& name, const string& doc, 1930 const std::string& name, const std::string& doc,
1931 bool mark_as_global, bool save_as_floats) 1931 bool mark_as_global, bool save_as_floats)
1932 { 1932 {
1933 FOUR_BYTE_INT name_len = name.length (); 1933 FOUR_BYTE_INT name_len = name.length ();
1934 1934
1935 os.write (&name_len, 4); 1935 os.write (&name_len, 4);
1954 charMatrix chm = tc.char_matrix_value (); 1954 charMatrix chm = tc.char_matrix_value ();
1955 for (int i = 0; i < nr; i++) 1955 for (int i = 0; i < nr; i++)
1956 { 1956 {
1957 FOUR_BYTE_INT len = chm.cols (); 1957 FOUR_BYTE_INT len = chm.cols ();
1958 os.write (&len, 4); 1958 os.write (&len, 4);
1959 string tstr = chm.row_as_string (i); 1959 std::string tstr = chm.row_as_string (i);
1960 const char *tmp = tstr.data (); 1960 const char *tmp = tstr.data ();
1961 os.write (tmp, len); 1961 os.write (tmp, len);
1962 } 1962 }
1963 } 1963 }
1964 else if (tc.is_range ()) 1964 else if (tc.is_range ())
2061 2061
2062 // Save the data from TC along with the corresponding NAME on stream OS 2062 // Save the data from TC along with the corresponding NAME on stream OS
2063 // in the MatLab binary format. 2063 // in the MatLab binary format.
2064 2064
2065 static bool 2065 static bool
2066 save_mat_binary_data (ostream& os, const octave_value& tc, 2066 save_mat_binary_data (std::ostream& os, const octave_value& tc,
2067 const string& name) 2067 const std::string& name)
2068 { 2068 {
2069 FOUR_BYTE_INT mopt = 0; 2069 FOUR_BYTE_INT mopt = 0;
2070 2070
2071 mopt += tc.is_string () ? 1 : 0; 2071 mopt += tc.is_string () ? 1 : 0;
2072 2072
2145 2145
2146 return os; 2146 return os;
2147 } 2147 }
2148 2148
2149 static void 2149 static void
2150 ascii_save_type (ostream& os, const char *type, bool mark_as_global) 2150 ascii_save_type (std::ostream& os, const char *type, bool mark_as_global)
2151 { 2151 {
2152 if (mark_as_global) 2152 if (mark_as_global)
2153 os << "# type: global "; 2153 os << "# type: global ";
2154 else 2154 else
2155 os << "# type: "; 2155 os << "# type: ";
2241 // Returns 1 for success and 0 for failure. 2241 // Returns 1 for success and 0 for failure.
2242 2242
2243 // XXX FIXME XXX -- should probably write the help string here too. 2243 // XXX FIXME XXX -- should probably write the help string here too.
2244 2244
2245 bool 2245 bool
2246 save_ascii_data (ostream& os, const octave_value& tc, 2246 save_ascii_data (std::ostream& os, const octave_value& tc,
2247 const string& name, bool strip_nan_and_inf, 2247 const std::string& name, bool strip_nan_and_inf,
2248 bool mark_as_global, int precision) 2248 bool mark_as_global, int precision)
2249 { 2249 {
2250 bool success = true; 2250 bool success = true;
2251 2251
2252 if (! precision) 2252 if (! precision)
2266 os << "# elements: " << elements << "\n"; 2266 os << "# elements: " << elements << "\n";
2267 for (int i = 0; i < elements; i++) 2267 for (int i = 0; i < elements; i++)
2268 { 2268 {
2269 int len = chm.cols (); 2269 int len = chm.cols ();
2270 os << "# length: " << len << "\n"; 2270 os << "# length: " << len << "\n";
2271 string tstr = chm.row_as_string (i); 2271 std::string tstr = chm.row_as_string (i);
2272 const char *tmp = tstr.data (); 2272 const char *tmp = tstr.data ();
2273 os.write (tmp, len); 2273 os.write (tmp, len);
2274 os << "\n"; 2274 os << "\n";
2275 } 2275 }
2276 } 2276 }
2365 } 2365 }
2366 2366
2367 // Save the info from sr on stream os in the format specified by fmt. 2367 // Save the info from sr on stream os in the format specified by fmt.
2368 2368
2369 static void 2369 static void
2370 do_save (ostream& os, symbol_record *sr, load_save_format fmt, 2370 do_save (std::ostream& os, symbol_record *sr, load_save_format fmt,
2371 int save_as_floats) 2371 int save_as_floats)
2372 { 2372 {
2373 if (! sr->is_variable ()) 2373 if (! sr->is_variable ())
2374 { 2374 {
2375 error ("save: can only save variables, not functions"); 2375 error ("save: can only save variables, not functions");
2376 return; 2376 return;
2377 } 2377 }
2378 2378
2379 string name = sr->name (); 2379 std::string name = sr->name ();
2380 string help = sr->help (); 2380 std::string help = sr->help ();
2381 int global = sr->is_linked_to_global (); 2381 int global = sr->is_linked_to_global ();
2382 2382
2383 octave_value tc = sr->def (); 2383 octave_value tc = sr->def ();
2384 2384
2385 if (tc.is_undefined ()) 2385 if (tc.is_undefined ())
2408 // Save variables with names matching PATTERN on stream OS in the 2408 // Save variables with names matching PATTERN on stream OS in the
2409 // format specified by FMT. If SAVE_BUILTINS is TRUE, also save 2409 // format specified by FMT. If SAVE_BUILTINS is TRUE, also save
2410 // builtin variables with names that match PATTERN. 2410 // builtin variables with names that match PATTERN.
2411 2411
2412 static int 2412 static int
2413 save_vars (ostream& os, const string& pattern, bool save_builtins, 2413 save_vars (std::ostream& os, const std::string& pattern, bool save_builtins,
2414 load_save_format fmt, int save_as_floats) 2414 load_save_format fmt, int save_as_floats)
2415 { 2415 {
2416 Array<symbol_record *> vars = curr_sym_tab->glob 2416 Array<symbol_record *> vars = curr_sym_tab->glob
2417 (pattern, symbol_record::USER_VARIABLE, SYMTAB_ALL_SCOPES); 2417 (pattern, symbol_record::USER_VARIABLE, SYMTAB_ALL_SCOPES);
2418 2418
2450 static load_save_format 2450 static load_save_format
2451 get_default_save_format (void) 2451 get_default_save_format (void)
2452 { 2452 {
2453 load_save_format retval = LS_ASCII; 2453 load_save_format retval = LS_ASCII;
2454 2454
2455 string fmt = Vdefault_save_format; 2455 std::string fmt = Vdefault_save_format;
2456 2456
2457 if (fmt == "binary") 2457 if (fmt == "binary")
2458 retval = LS_BINARY; 2458 retval = LS_BINARY;
2459 else if (fmt == "mat-binary" || fmt =="mat_binary") 2459 else if (fmt == "mat-binary" || fmt =="mat_binary")
2460 retval = LS_MAT_BINARY; 2460 retval = LS_MAT_BINARY;
2461 2461
2462 return retval; 2462 return retval;
2463 } 2463 }
2464 2464
2465 static void 2465 static void
2466 write_header (ostream& os, load_save_format format) 2466 write_header (std::ostream& os, load_save_format format)
2467 { 2467 {
2468 switch (format) 2468 switch (format)
2469 { 2469 {
2470 case LS_BINARY: 2470 case LS_BINARY:
2471 { 2471 {
2482 break; 2482 break;
2483 2483
2484 case LS_ASCII: 2484 case LS_ASCII:
2485 { 2485 {
2486 octave_gmtime now; 2486 octave_gmtime now;
2487 string time_string = now.asctime (); 2487 std::string time_string = now.asctime ();
2488 time_string = time_string.substr (0, time_string.length () - 1); 2488 time_string = time_string.substr (0, time_string.length () - 1);
2489 2489
2490 os << "# Created by Octave " OCTAVE_VERSION ", " 2490 os << "# Created by Octave " OCTAVE_VERSION ", "
2491 << time_string 2491 << time_string
2492 << " <" 2492 << " <"
2502 } 2502 }
2503 } 2503 }
2504 2504
2505 static void 2505 static void
2506 save_vars (const string_vector& argv, int argv_idx, int argc, 2506 save_vars (const string_vector& argv, int argv_idx, int argc,
2507 ostream& os, bool save_builtins, load_save_format fmt, 2507 std::ostream& os, bool save_builtins, load_save_format fmt,
2508 bool save_as_floats, bool write_header_info) 2508 bool save_as_floats, bool write_header_info)
2509 { 2509 {
2510 if (write_header_info) 2510 if (write_header_info)
2511 write_header (os, fmt); 2511 write_header (os, fmt);
2512 2512
2541 2541
2542 unsigned mode = ios::out|ios::trunc; 2542 unsigned mode = ios::out|ios::trunc;
2543 if (format == LS_BINARY || format == LS_MAT_BINARY) 2543 if (format == LS_BINARY || format == LS_MAT_BINARY)
2544 mode |= ios::bin; 2544 mode |= ios::bin;
2545 2545
2546 ofstream file (fname, mode); 2546 std::ofstream file (fname, mode);
2547 2547
2548 if (file) 2548 if (file)
2549 { 2549 {
2550 save_vars (string_vector (), 0, 0, file, false, format, false, true); 2550 save_vars (string_vector (), 0, 0, file, false, format, false, true);
2551 message (0, "save to `%s' complete", fname); 2551 message (0, "save to `%s' complete", fname);
2700 print_usage ("save"); 2700 print_usage ("save");
2701 return retval; 2701 return retval;
2702 } 2702 }
2703 else 2703 else
2704 { 2704 {
2705 string fname = file_ops::tilde_expand (argv[i]); 2705 std::string fname = file_ops::tilde_expand (argv[i]);
2706 2706
2707 i++; 2707 i++;
2708 2708
2709 unsigned mode = ios::out; 2709 unsigned mode = ios::out;
2710 if (format == LS_BINARY || format == LS_MAT_BINARY) 2710 if (format == LS_BINARY || format == LS_MAT_BINARY)
2711 mode |= ios::bin; 2711 mode |= ios::bin;
2712 2712
2713 mode |= append ? ios::ate : ios::trunc; 2713 mode |= append ? ios::ate : ios::trunc;
2714 2714
2715 ofstream file (fname.c_str (), mode); 2715 std::ofstream file (fname.c_str (), mode);
2716 2716
2717 if (file) 2717 if (file)
2718 { 2718 {
2719 bool write_header_info 2719 bool write_header_info
2720 = ((file.rdbuf ())->seekoff (0, ios::cur) == 0); 2720 = ((file.rdbuf ())->seekoff (0, ios::cur) == 0);
2737 // If TC is matrix, save it on stream OS in a format useful for 2737 // If TC is matrix, save it on stream OS in a format useful for
2738 // making a 3-dimensional plot with gnuplot. If PARAMETRIC is 2738 // making a 3-dimensional plot with gnuplot. If PARAMETRIC is
2739 // TRUE, assume a parametric 3-dimensional plot will be generated. 2739 // TRUE, assume a parametric 3-dimensional plot will be generated.
2740 2740
2741 bool 2741 bool
2742 save_three_d (ostream& os, const octave_value& tc, bool parametric) 2742 save_three_d (std::ostream& os, const octave_value& tc, bool parametric)
2743 { 2743 {
2744 bool fail = false; 2744 bool fail = false;
2745 2745
2746 int nr = tc.rows (); 2746 int nr = tc.rows ();
2747 int nc = tc.columns (); 2747 int nc = tc.columns ();
2804 static int 2804 static int
2805 default_save_format (void) 2805 default_save_format (void)
2806 { 2806 {
2807 int status = 0; 2807 int status = 0;
2808 2808
2809 string s = builtin_string_variable ("default_save_format"); 2809 std::string s = builtin_string_variable ("default_save_format");
2810 2810
2811 if (s.empty ()) 2811 if (s.empty ())
2812 { 2812 {
2813 gripe_invalid_value_specified ("default_save_format"); 2813 gripe_invalid_value_specified ("default_save_format");
2814 status = -1; 2814 status = -1;