changeset 6188:160958073cde

[project @ 2006-11-29 18:55:47 by jwe]
author jwe
date Wed, 29 Nov 2006 18:55:48 +0000
parents 2a8922007c12
children 0d23b0c0ce1a
files src/ChangeLog src/DLD-FUNCTIONS/fftw_wisdom.cc src/mex.cc
diffstat 3 files changed, 47 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Nov 29 02:00:00 2006 +0000
+++ b/src/ChangeLog	Wed Nov 29 18:55:48 2006 +0000
@@ -1,3 +1,8 @@
+2006-11-29  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/fftw_wisdom.cc (Ffftw_wisdom): Look in load-path
+	if reading wisdom file, but not if writing.
+
 2006-11-28  John W. Eaton  <jwe@octave.org>
 
 	* mex.cc (mxArray_struct::get_field_by_number):
--- a/src/DLD-FUNCTIONS/fftw_wisdom.cc	Wed Nov 29 02:00:00 2006 +0000
+++ b/src/DLD-FUNCTIONS/fftw_wisdom.cc	Wed Nov 29 18:55:48 2006 +0000
@@ -31,6 +31,8 @@
 
 #include <sstream>
 
+#include "file-stat.h"
+
 #include "defaults.h"
 #include "defun-dld.h"
 #include "error.h"
@@ -110,37 +112,56 @@
 	    overwrite = true;
 	}
 
-      std::string str = args(0).string_value ();
-      std::string wisdom = octave_env::make_absolute
-	(load_path::find_file (str), octave_env::getcwd ());
+      std::string name = args(0).string_value ();
+
+      std::string wisdom = file_ops::tilde_expand (name);
+
+      if (! (overwrite || octave_env::absolute_pathname (wisdom)))
+	{
+	  file_stat fs (wisdom);
+
+	  if (! fs.exists ())
+	    {
+	      std::string tmp = octave_env::make_absolute
+		(load_path::find_file (wisdom), octave_env::getcwd ());
 
-      // FIXME -- should probably protect FILE* resources with
-      // auto_ptr or similar...
+	      if (! tmp.empty ())
+		{
+		  warning_with_id ("Octave:fftw-wisdom-file-in-path",
+				   "fftw_wisdom: file found in load path");
+		  wisdom = tmp;
+		}
+	    }
+	}
 
-      if (wisdom.empty () || overwrite)
+      if (overwrite)
 	{
-	  if (str.empty ())
-	    error ("fftw_wisdom: can not save to file");
+	  FILE *ofile = fopen (wisdom.c_str (), "wb");
+
+	  if (! ofile)
+	    error ("fftw_wisdom: unable to open file `%s' for writing",
+		   wisdom.c_str());
 	  else
 	    {
-	      FILE *ofile = fopen (str.c_str (), "wb");
-	      if (! ofile)
-		error ("fftw_wisdom: can not save to file %s", str.c_str());
-	      else
-		{
-		  fftw_export_wisdom_to_file (ofile);
-		  fclose (ofile);
-		}
+	      fftw_export_wisdom_to_file (ofile);
+	      fclose (ofile);
 	    }
 	}
       else
 	{
 	  FILE *ifile = fopen (wisdom.c_str (), "r");
-	  if (! fftw_import_wisdom_from_file (ifile))
-	    error ("fftw_wisdom: can not import wisdom from file"); 
-	  fclose (ifile);
+
+	  if (! ifile)
+	    error ("fftw_wisdom: unable to open file `%s' for reading",
+		   wisdom.c_str ());
+	  else
+	    {
+	      if (! fftw_import_wisdom_from_file (ifile))
+		error ("fftw_wisdom: can not import wisdom from file"); 
+
+	      fclose (ifile);
+	    }
 	}
-
     } 
   else 
     {
--- a/src/mex.cc	Wed Nov 29 02:00:00 2006 +0000
+++ b/src/mex.cc	Wed Nov 29 18:55:48 2006 +0000
@@ -1661,7 +1661,7 @@
   mxArray *get_field_by_number (int index, int key_num) const
   {
     return key_num >= 0 && key_num < nfields
-      ? : data[nfields * index + key_num] : 0;
+      ? data[nfields * index + key_num] : 0;
   }
 
   void set_field_by_number (int index, int key_num, mxArray *val);