octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2.9.15 --> 3.0


From: John Swensen
Subject: Re: 2.9.15 --> 3.0
Date: Sun, 07 Oct 2007 21:29:53 -0400
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

John W. Eaton wrote:
OK, I have the following items for 2.9.15, then bug fixes only until
3.0 (really, I mean it this time :-):

  * GPLv3
  * diag should preserve class/type
  * filename completion (if possible)
  * verify that the new residue works (could use some tests)
  * improve residue doc string
  * interp2 bug
  * num2str bug
  * any other pending bug reports?

Is there anything else?

jwe

Here are 2 patches to fix the num2str bug. One is the num2str fixes and the other adds the strtrim() function. The strtrim() function is almost a complete copy of the deblank() function. Let me know if you want any other changes.
John Swensen
--- /dev/null   2007-10-07 21:02:22.000000000 -0400
+++ scripts/strings/strtrim.m   2007-10-07 20:12:22.000000000 -0400
@@ -0,0 +1,52 @@
+## Copyright (C) 1996 Kurt Hornik
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+## -*- texinfo -*- @deftypefn {Function File} {} deblank (@var{s})
+## Remove leading and trailing blanks and nulls from @var{s}.  If
+## @var{s} is a matrix, @var{deblank} trims each row to the length of
+## longest string.  If @var{s} is a cell array, operate recursively on
+## each element of the cell array. @end deftypefn
+
+## Author: John Swensen <address@hidden>
+## Adapted-From: deblank() by Kurt Hornik <address@hidden>
+
+function s = strtrim (s)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  if (ischar (s))
+
+    k = find (! isspace (s) & s != "\0");
+    if (isempty (s) || isempty (k))
+      s = "";
+    else
+      s = s(:,ceil (min (k) / rows (s)):ceil (max (k) / rows (s)));
+    endif
+
+  elseif (iscell(s))
+
+    s = cellfun (@strtrim, s, "UniformOutput", false);
+
+  else
+    error ("strtrim: expecting string argument");
+  endif
+
+endfunction
Index: scripts/general/num2str.m
===================================================================
RCS file: /cvs/octave/scripts/general/num2str.m,v
retrieving revision 1.30
diff -u -r1.30 num2str.m
--- scripts/general/num2str.m   20 Apr 2007 18:16:08 -0000      1.30
+++ scripts/general/num2str.m   8 Oct 2007 01:03:07 -0000
@@ -56,11 +56,16 @@
        dgt1 = ceil (log10 (max (max (abs (real (x(:)))),
                                 max (abs (imag (x(:))))))) + 1;
        dgt2 = dgt1 - (min (real (x(:))) >= 0);
-       fmt = sprintf("%%%dd%%+-%ddi  ", dgt2, dgt1);
+       
+       if( length( abs(x) == x ) > 0 )
+         fmt = sprintf("%%%dg%%+-%dgi  ", dgt2, dgt1);
+       else
+         fmt = sprintf("%%%dd%%+-%ddi  ", dgt2, dgt1);
+       endif
       elseif (isscalar (x))
-       fmt = "%.4g%-+.4gi";
+       fmt = "%.6g%-+.6gi";
       else
-       fmt = "%11.4g%-+11.4gi";
+       fmt = "%11.6g%-+11.6gi";
       endif
     endif
 
@@ -101,7 +106,7 @@
     endwhile
 
     tmp(length (tmp)) = "";
-    retval = split (tmp, "\n");
+    retval = strtrim( split (tmp, "\n") );
   else
     if (nargin == 2)
       if (ischar (arg))
@@ -120,18 +125,22 @@
        else
          dgt = floor (log10 (max (abs(x(:))))) + (min (real (x(:))) < 0) + 1;
        endif
-       fmt = sprintf ("%%%dd  ", dgt);
+       if( length( abs(x) == x ) > 0 )
+         fmt = sprintf ("%%%dg  ", dgt);
+       else
+         fmt = sprintf ("%%%dd  ", dgt);
+       endif
       elseif (isscalar (x))
-       fmt = "%.4g";
+       fmt = "%11.5g";
       else
-       fmt = "%11.4g";
+       fmt = "%11.5g";
       endif
     endif
     fmt = strcat (deblank (repmat (fmt, 1, columns (x))), "\n");
     nd = ndims (x);
     tmp = sprintf (fmt, permute (x, [2, 1, 3:nd]));
     tmp(length (tmp)) = "";
-    retval = split (tmp, "\n");
+    retval = strtrim( split (tmp, "\n") );
   endif
 
 endfunction

reply via email to

[Prev in Thread] Current Thread [Next in Thread]