comparison libinterp/interpfcn/load-save.cc @ 16555:04fb96f4bea1

allow double-click in file browser to load data files * files-dock-widget.cc (files_dock_widget::display_directory): If file looks like Octave data file, load it instead of opening with editor. * ls-mat-ascii.h, ls-mat-ascii.cc (get_lines_and_columns): New option to supress error messages. New option to check for numeric values. (looks_like_mat_ascii_file): New function. * load-save.h load-save.cc (is_octave_data_file): New function. (get_file_format): Don't return LS_MAT_ASCII unless the file really looks like it is a numeric data file.
author John W. Eaton <jwe@octave.org>
date Tue, 23 Apr 2013 12:57:16 -0400
parents 302157614308
children b04ae15530fc
comparison
equal deleted inserted replaced
16554:03a28487fa9d 16555:04fb96f4bea1
240 file.clear (); 240 file.clear ();
241 file.seekg (0, std::ios::beg); 241 file.seekg (0, std::ios::beg);
242 242
243 int32_t mopt, nr, nc, imag, len; 243 int32_t mopt, nr, nc, imag, len;
244 244
245 int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len, 1); 245 int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len,
246 true);
246 247
247 if (! err) 248 if (! err)
248 retval = LS_MAT_BINARY; 249 retval = LS_MAT_BINARY;
249 else 250 else
250 { 251 {
275 return retval; 276 return retval;
276 } 277 }
277 278
278 static load_save_format 279 static load_save_format
279 get_file_format (const std::string& fname, const std::string& orig_fname, 280 get_file_format (const std::string& fname, const std::string& orig_fname,
280 bool &use_zlib) 281 bool &use_zlib, bool quiet = false)
281 { 282 {
282 load_save_format retval = LS_UNKNOWN; 283 load_save_format retval = LS_UNKNOWN;
283 284
284 #ifdef HAVE_HDF5 285 #ifdef HAVE_HDF5
285 // check this before we open the file 286 // check this before we open the file
307 gzfile.close (); 308 gzfile.close ();
308 } 309 }
309 } 310 }
310 #endif 311 #endif
311 312
312 if (retval == LS_UNKNOWN) 313 // FIXME -- looks_like_mat_ascii_file does not check to see
313 { 314 // whether the file contains numbers. It just skips comments and
314 // Try reading the file as numbers only, determining the 315 // checks for the same number of words on each line. We may need
315 // number of rows and columns from the data. We don't 316 // a better check here. The best way to do that might be just
316 // even bother to check to see if the first item in the 317 // to try to read the file and see if it works.
317 // file is a number, so that get_complete_line() can 318
318 // skip any comments that might appear at the top of the 319 if (retval == LS_UNKNOWN && looks_like_mat_ascii_file (fname))
319 // file. 320 retval = LS_MAT_ASCII;
320 321 }
321 retval = LS_MAT_ASCII; 322 else if (! quiet)
322 }
323 }
324 else
325 gripe_file_open ("load", orig_fname); 323 gripe_file_open ("load", orig_fname);
326 324
327 return retval; 325 return retval;
328 } 326 }
329 327
535 } 533 }
536 534
537 return fname; 535 return fname;
538 } 536 }
539 537
538 bool
539 is_octave_data_file (const std::string& fname)
540 {
541 bool use_zlib = false;
542 return get_file_format (fname, fname, use_zlib, true) != LS_UNKNOWN;
543 }
540 544
541 DEFUN (load, args, nargout, 545 DEFUN (load, args, nargout,
542 "-*- texinfo -*-\n\ 546 "-*- texinfo -*-\n\
543 @deftypefn {Command} {} load file\n\ 547 @deftypefn {Command} {} load file\n\
544 @deftypefnx {Command} {} load options file\n\ 548 @deftypefnx {Command} {} load options file\n\