changeset 11419:a4822f3d1032

Fix for saving of single precision arrays to the matlab file format
author David Bateman <dbateman@free.fr>
date Tue, 28 Dec 2010 20:46:17 +0100
parents a140991387fb
children 466ba499eff5
files src/ChangeLog src/ls-mat5.cc
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Dec 28 07:42:34 2010 -0500
+++ b/src/ChangeLog	Tue Dec 28 20:46:17 2010 +0100
@@ -1,3 +1,9 @@
+2010-12-28  David Bateman  <dbateman@free.fr>
+
+	* ls-mat5.cc (save_mat5_array_length (const float*, octave_idx_type,
+        bool)): Take in to account the 4 bytes of padding for an odd number
+	of elements in single precision arrays.
+
 2010-12-27  Rik  <octave@nomad.inbox5.com>
 
 	* syscalls.cc (stat): Add additional calling form using file descriptor
--- a/src/ls-mat5.cc	Tue Dec 28 07:42:34 2010 -0500
+++ b/src/ls-mat5.cc	Tue Dec 28 20:46:17 2010 +0100
@@ -1314,7 +1314,7 @@
             FloatComplexNDArray ctmp (dims);
 
             for (octave_idx_type i = 0; i < n; i++)
-              ctmp(i) = Complex (re(i), im(i));
+              ctmp(i) = FloatComplex (re(i), im(i));
 
             tc = ctmp;
           }
@@ -1954,7 +1954,7 @@
 }
 
 int
-save_mat5_array_length (const float* val, octave_idx_type nel, bool)
+save_mat5_array_length (const float* /* val */, octave_idx_type nel, bool)
 {
   if (nel > 0)
     {
@@ -2002,7 +2002,8 @@
       //       size = 4;
       //   }
 
-      return 8 + nel * size;
+      // Round nel up to nearest even number of elements
+      return 8 + ((nel + 1) & ~0x1LL) * size;
     }
   else
     return 8;