comparison src/load-save.cc @ 4687:e95c86d48732

[project @ 2004-01-06 21:53:34 by jwe]
author jwe
date Tue, 06 Jan 2004 21:53:34 +0000
parents f6d6335c08f6
children bdc51b369a78
comparison
equal deleted inserted replaced
4686:c7ae43dfdea4 4687:e95c86d48732
373 } 373 }
374 374
375 octave_value 375 octave_value
376 do_load (std::istream& stream, const std::string& orig_fname, bool force, 376 do_load (std::istream& stream, const std::string& orig_fname, bool force,
377 load_save_format format, oct_mach_info::float_format flt_fmt, 377 load_save_format format, oct_mach_info::float_format flt_fmt,
378 bool list_only, bool swap, bool verbose, bool import, 378 bool list_only, bool swap, bool verbose,
379 const string_vector& argv, int argv_idx, int argc, int nargout) 379 const string_vector& argv, int argv_idx, int argc, int nargout)
380 { 380 {
381 octave_value retval; 381 octave_value retval;
382 382
383 Octave_map retstruct; 383 Octave_map retstruct;
413 name = read_mat_binary_data (stream, orig_fname, tc); 413 name = read_mat_binary_data (stream, orig_fname, tc);
414 break; 414 break;
415 415
416 #ifdef HAVE_HDF5 416 #ifdef HAVE_HDF5
417 case LS_HDF5: 417 case LS_HDF5:
418 name = read_hdf5_data (stream, orig_fname, 418 name = read_hdf5_data (stream, orig_fname, global, tc, doc);
419 global, tc, doc, import);
420 break; 419 break;
421 #endif /* HAVE_HDF5 */ 420 #endif /* HAVE_HDF5 */
422 421
423 case LS_MAT5_BINARY: 422 case LS_MAT5_BINARY:
424 name = read_mat5_binary_element (stream, orig_fname, swap, 423 name = read_mat5_binary_element (stream, orig_fname, swap,
584 @item -hdf5\n\ 583 @item -hdf5\n\
585 Force Octave to assume the file is in HDF5 format.\n\ 584 Force Octave to assume the file is in HDF5 format.\n\
586 (HDF5 is a free, portable binary format developed by the National\n\ 585 (HDF5 is a free, portable binary format developed by the National\n\
587 Center for Supercomputing Applications at the University of Illinois.)\n\ 586 Center for Supercomputing Applications at the University of Illinois.)\n\
588 Note that Octave can read HDF5 files not created by itself, but may\n\ 587 Note that Octave can read HDF5 files not created by itself, but may\n\
589 skip some datasets in formats that it cannot support. In particular,\n\ 588 skip some datasets in formats that it cannot support.\n"
590 it will skip datasets of data types that it does not recognize, with\n\
591 dimensionality > 2, or with names that aren't valid Octave identifiers\n\
592 See, however, the @samp{-import} option to ameliorate this somewhat.\n"
593 589
594 HAVE_HDF5_HELP_STRING 590 HAVE_HDF5_HELP_STRING
595 591
596 "\n\ 592 "\n\
597 @item -import\n\ 593 @item -import\n\
598 Make a stronger attempt to import foreign datasets. Currently, this means\n\ 594 The @samp{-import} is acceptted but ignored for backward compatiability.\n\
599 that for HDF5 files, invalid characters in names are converted to @samp{_},\n\ 595 Octave can now support multi-dimensional HDF data and automatically modifies\n\
600 and datasets with dimensionality > 2 are imported as lists of matrices (or\n\ 596 variable names if they are invalid Octave identifiers.\n\
601 lists of lists of matrices, or ...).\n\
602 \n\ 597 \n\
603 @end table\n\ 598 @end table\n\
604 @end deffn") 599 @end deffn")
605 { 600 {
606 octave_value_list retval; 601 octave_value_list retval;
619 load_save_format format = LS_UNKNOWN; 614 load_save_format format = LS_UNKNOWN;
620 615
621 bool force = false; 616 bool force = false;
622 bool list_only = false; 617 bool list_only = false;
623 bool verbose = false; 618 bool verbose = false;
624 bool import = false;
625 619
626 int i; 620 int i;
627 for (i = 1; i < argc; i++) 621 for (i = 1; i < argc; i++)
628 { 622 {
629 if (argv[i] == "-force" || argv[i] == "-f") 623 if (argv[i] == "-force" || argv[i] == "-f")
663 return retval; 657 return retval;
664 #endif /* ! HAVE_HDF5 */ 658 #endif /* ! HAVE_HDF5 */
665 } 659 }
666 else if (argv[i] == "-import" || argv[i] == "-i") 660 else if (argv[i] == "-import" || argv[i] == "-i")
667 { 661 {
668 import = true; 662 warning ("load: -import ignored");
669 } 663 }
670 else 664 else
671 break; 665 break;
672 } 666 }
673 667
698 // previous call, how do we fix up the state of std::cin so 692 // previous call, how do we fix up the state of std::cin so
699 // that we can get additional input? I'm afraid that we 693 // that we can get additional input? I'm afraid that we
700 // can't fix this using std::cin only. 694 // can't fix this using std::cin only.
701 695
702 retval = do_load (std::cin, orig_fname, force, format, flt_fmt, 696 retval = do_load (std::cin, orig_fname, force, format, flt_fmt,
703 list_only, swap, verbose, import, argv, i, argc, 697 list_only, swap, verbose, argv, i, argc,
704 nargout); 698 nargout);
705 } 699 }
706 else 700 else
707 error ("load: must specify file format if reading from stdin"); 701 error ("load: must specify file format if reading from stdin");
708 } 702 }
722 716
723 if (hdf5_file.file_id >= 0) 717 if (hdf5_file.file_id >= 0)
724 { 718 {
725 retval = do_load (hdf5_file, orig_fname, force, format, 719 retval = do_load (hdf5_file, orig_fname, force, format,
726 flt_fmt, list_only, swap, verbose, 720 flt_fmt, list_only, swap, verbose,
727 import, argv, i, argc, nargout); 721 argv, i, argc, nargout);
728 722
729 hdf5_file.close (); 723 hdf5_file.close ();
730 } 724 }
731 else 725 else
732 error ("load: couldn't open input file `%s'", 726 error ("load: couldn't open input file `%s'",
766 return retval; 760 return retval;
767 } 761 }
768 } 762 }
769 763
770 retval = do_load (file, orig_fname, force, format, 764 retval = do_load (file, orig_fname, force, format,
771 flt_fmt, list_only, swap, verbose, import, 765 flt_fmt, list_only, swap, verbose,
772 argv, i, argc, nargout); 766 argv, i, argc, nargout);
773 file.close (); 767 file.close ();
774 } 768 }
775 else 769 else
776 error ("load: couldn't open input file `%s'", 770 error ("load: couldn't open input file `%s'",
1268 { 1262 {
1269 i++; 1263 i++;
1270 1264
1271 #ifdef HAVE_HDF5 1265 #ifdef HAVE_HDF5
1272 if (format == LS_HDF5) 1266 if (format == LS_HDF5)
1273 error ("load: cannot write HDF5 format to stdout"); 1267 error ("save: cannot write HDF5 format to stdout");
1274 else 1268 else
1275 #endif /* HAVE_HDF5 */ 1269 #endif /* HAVE_HDF5 */
1276 // don't insert any commands here! the brace below must go 1270 // don't insert any commands here! the brace below must go
1277 // with the "else" above! 1271 // with the "else" above!
1278 { 1272 {
1308 #ifdef HAVE_HDF5 1302 #ifdef HAVE_HDF5
1309 if (format == LS_HDF5) 1303 if (format == LS_HDF5)
1310 { 1304 {
1311 hdf5_ofstream hdf5_file (fname.c_str ()); 1305 hdf5_ofstream hdf5_file (fname.c_str ());
1312 1306
1313 if (hdf5_file.file_id >= 0) { 1307 if (hdf5_file.file_id >= 0)
1314 save_vars (argv, i, argc, hdf5_file, save_builtins, format, 1308 {
1315 save_as_floats, true); 1309 save_vars (argv, i, argc, hdf5_file, save_builtins, format,
1316 1310 save_as_floats, true);
1317 hdf5_file.close (); 1311
1312 hdf5_file.close ();
1318 } 1313 }
1319 else 1314 else
1320 { 1315 {
1321 error ("save: couldn't open output file `%s'", fname.c_str ()); 1316 error ("save: couldn't open output file `%s'", fname.c_str ());
1322 return retval; 1317 return retval;