comparison src/load-save.cc @ 5089:3db2b2762491

[project @ 2004-12-03 04:06:05 by jwe]
author jwe
date Fri, 03 Dec 2004 04:06:05 +0000
parents a9f67193e3a0
children 741618f692d7
comparison
equal deleted inserted replaced
5088:7830f271a53f 5089:3db2b2762491
303 303
304 static load_save_format 304 static load_save_format
305 get_file_format (const std::string& fname, const std::string& orig_fname) 305 get_file_format (const std::string& fname, const std::string& orig_fname)
306 { 306 {
307 load_save_format retval = LS_UNKNOWN; 307 load_save_format retval = LS_UNKNOWN;
308
309 // If the file doesn't exist do nothing
310 std::ifstream file_exist (fname.c_str ());
311 if (file_exist)
312 file_exist.close ();
313 else
314 {
315 error ("load: nonexistent file `%s'", fname.c_str ());
316 return LS_UNKNOWN;
317 }
318 308
319 #ifdef HAVE_HDF5 309 #ifdef HAVE_HDF5
320 // check this before we open the file 310 // check this before we open the file
321 if (H5Fis_hdf5 (fname.c_str ()) > 0) 311 if (H5Fis_hdf5 (fname.c_str ()) > 0)
322 return LS_HDF5; 312 return LS_HDF5;
722 } 712 }
723 else 713 else
724 { 714 {
725 std::string fname = file_ops::tilde_expand (argv[i]); 715 std::string fname = file_ops::tilde_expand (argv[i]);
726 716
717 // Check if file exists, if it doesn't then also check with a
718 // .mat extension
719 std::ifstream file_exist (fname.c_str ());
720 if (file_exist)
721 file_exist.close ();
722 else
723 {
724 fname.append (".mat");
725 std::ifstream file_mat_exist (fname.c_str ());
726 if (file_mat_exist)
727 file_mat_exist.close ();
728 else
729 {
730 error ("load: nonexistent file: `%s'", orig_fname.c_str ());
731 return retval;
732 }
733 }
734
727 if (format == LS_UNKNOWN) 735 if (format == LS_UNKNOWN)
728 format = get_file_format (fname, orig_fname); 736 format = get_file_format (fname, orig_fname);
729 737
730 #ifdef HAVE_HDF5 738 #ifdef HAVE_HDF5
731 if (format == LS_HDF5) 739 if (format == LS_HDF5)
732 { 740 {
733 i++; 741 i++;
734 742
735 // If the file doesn't exist do nothing 743 hdf5_ifstream hdf5_file (fname.c_str ());
736 std::ifstream file (fname.c_str (), std::ios::in); 744
737 if (file) 745 if (hdf5_file.file_id >= 0)
738 { 746 {
739 file.close (); 747 retval = do_load (hdf5_file, orig_fname, force, format,
740 748 flt_fmt, list_only, swap, verbose,
741 hdf5_ifstream hdf5_file (fname.c_str ()); 749 argv, i, argc, nargout);
742 750
743 if (hdf5_file.file_id >= 0) 751 hdf5_file.close ();
744 {
745 retval = do_load (hdf5_file, orig_fname, force, format,
746 flt_fmt, list_only, swap, verbose,
747 argv, i, argc, nargout);
748
749 hdf5_file.close ();
750 }
751 else
752 error ("load: couldn't open input file `%s'",
753 orig_fname.c_str ());
754 } 752 }
755 else 753 else
756 error ("load: nonexistent file `%s'", orig_fname.c_str ()); 754 error ("load: couldn't open input file `%s'",
755 orig_fname.c_str ());
757 } 756 }
758 else 757 else
759 #endif /* HAVE_HDF5 */ 758 #endif /* HAVE_HDF5 */
760 // don't insert any statements here; the "else" above has to 759 // don't insert any statements here; the "else" above has to
761 // go with the "if" below!!!!! 760 // go with the "if" below!!!!!
801 } 800 }
802 else 801 else
803 error ("load: couldn't open input file `%s'", 802 error ("load: couldn't open input file `%s'",
804 orig_fname.c_str ()); 803 orig_fname.c_str ());
805 } 804 }
806 else
807 error ("load: nonexistent file: `%s'", orig_fname.c_str ());
808 } 805 }
809 806
810 return retval; 807 return retval;
811 } 808 }
812 809