Mercurial > octave
changeset 21758:ffad2baa90f7
maint: Use newlines to make code more readable.
line wrap: on
line diff
--- a/libinterp/corefcn/debug.cc Fri May 20 12:03:39 2016 -0700 +++ b/libinterp/corefcn/debug.cc Fri May 20 15:46:45 2016 -0700 @@ -437,12 +437,12 @@ %! dbstop in ls; %! dbstop help at 100; %! dbstop in ls 100; -%! dbstop help 200 if a==5; +%! dbstop help 201 if a==5; %! dbstop if error Octave:undefined-function; %! s = dbstatus; %! dbclear all; %! assert ({s.bkpt(:).name}, {"help", "help", "help>do_contents", "ls", "ls"}); -%! assert ([s.bkpt(:).line], [48, 100, 200, 58, 100]); +%! assert ([s.bkpt(:).line], [48, 100, 201, 58, 100]); %! assert (s.errs, {"Octave:undefined-function"}); */
--- a/scripts/@ftp/cd.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/@ftp/cd.m Fri May 20 15:46:45 2016 -0700 @@ -32,6 +32,7 @@ ## @end deftypefn function path = cd (f, path) + if (nargin != 1 && nargin != 2) print_usage (); endif @@ -39,7 +40,9 @@ if (nargin == 2) __ftp_cwd__ (f.curlhandle, path); endif + path = __ftp_pwd__ (f.curlhandle); + endfunction
--- a/scripts/@ftp/ftp.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/@ftp/ftp.m Fri May 20 15:46:45 2016 -0700 @@ -46,6 +46,7 @@ ## @end deftypefn function obj = ftp (host = "", username = "anonymous", password = "") + if (nargin == 1 && isa (host, "ftp")) obj = host; # Copy constructor else @@ -58,6 +59,7 @@ endif obj = class (p, "ftp"); endif + endfunction
--- a/scripts/@ftp/loadobj.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/@ftp/loadobj.m Fri May 20 15:46:45 2016 -0700 @@ -17,6 +17,7 @@ ## <http://www.gnu.org/licenses/>. function b = loadobj (a) + b = a; if (isfield (b, "jobject")) b = rmfield (b, "jobject"); @@ -32,6 +33,7 @@ warning ("@ftp/loadobj: can not change remote directory in loaded FTP object"); b = rmfield (b, "remotePwd"); endif + endfunction
--- a/scripts/audio/@audioplayer/set.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/audio/@audioplayer/set.m Fri May 20 15:46:45 2016 -0700 @@ -62,6 +62,7 @@ endfunction function setproperty (player, property, value) + switch (property) case "SampleRate" __player_set_fs__ (player, value); @@ -72,4 +73,6 @@ otherwise error ("audioplayer: no such property or the property specified is read-only"); endswitch + endfunction +
--- a/scripts/audio/@audioplayer/subsref.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/audio/@audioplayer/subsref.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,7 @@ ## @end deftypefn function value = subsref (player, idx) + if (nargin != 2) print_usage (); endif @@ -40,3 +41,4 @@ endif endfunction +
--- a/scripts/audio/@audiorecorder/subsasgn.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/audio/@audiorecorder/subsasgn.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,7 @@ ## @end deftypefn function value = subsasgn (recorder, idx, rhs) + if (nargin != 3) print_usage (); endif @@ -41,3 +42,4 @@ endif endfunction +
--- a/scripts/general/accumarray.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/accumarray.m Fri May 20 15:46:45 2016 -0700 @@ -370,6 +370,7 @@ A(subs) = vals; endif endif + endfunction
--- a/scripts/general/bitcmp.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/bitcmp.m Fri May 20 15:46:45 2016 -0700 @@ -71,6 +71,7 @@ mask = bitshift (bmax, k - amax); C = bitxor (bitand (A, mask), mask); endif + endfunction
--- a/scripts/general/celldisp.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/celldisp.m Fri May 20 15:46:45 2016 -0700 @@ -69,9 +69,11 @@ disp (""); endif endfor + endfunction function s = indices (dv, i) + if (sum (dv != 1) > 1) c = cell (size (dv)); [c{:}] = ind2sub (dv, i); @@ -80,6 +82,7 @@ else s = sprintf ("%i", i); endif + endfunction
--- a/scripts/general/common_size.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/common_size.m Fri May 20 15:46:45 2016 -0700 @@ -78,6 +78,7 @@ endif endif endif + endfunction
--- a/scripts/general/dblquad.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/dblquad.m Fri May 20 15:46:45 2016 -0700 @@ -65,6 +65,7 @@ q = feval (quadf, @(y) inner (y, f, xa, xb, tol, quadf, varargin{:}), ya, yb, tol); + endfunction function q = __dblquad_inner__ (y, f, xa, xb, tol, quadf, varargin)
--- a/scripts/general/del2.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/del2.m Fri May 20 15:46:45 2016 -0700 @@ -157,6 +157,7 @@ endfor D ./= nd; + endfunction
--- a/scripts/general/gradient.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/gradient.m Fri May 20 15:46:45 2016 -0700 @@ -84,6 +84,7 @@ endfunction function varargout = matrix_gradient (m, varargin) + transposed = false; if (isvector (m)) ## make a row vector. @@ -168,9 +169,11 @@ if (transposed) varargout{1} = varargout{1}.'; endif + endfunction function varargout = handle_gradient (f, p0, varargin) + ## Input checking p0_size = size (p0); @@ -218,6 +221,7 @@ varargout{d} = df_dx; endif endfor + endfunction
--- a/scripts/general/idivide.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/idivide.m Fri May 20 15:46:45 2016 -0700 @@ -66,6 +66,7 @@ ## @end deftypefn function z = idivide (x, y, op) + if (nargin < 2 || nargin > 3) print_usage (); elseif (nargin == 2) @@ -98,6 +99,7 @@ error ("idivide: unrecognized rounding type"); endif endif + endfunction
--- a/scripts/general/nthargout.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/nthargout.m Fri May 20 15:46:45 2016 -0700 @@ -67,6 +67,7 @@ ## Author: Jordi Gutiérrez Hermoso function out = nthargout (n, varargin) + if (nargin < 2) print_usage (); endif
--- a/scripts/general/polyarea.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/polyarea.m Fri May 20 15:46:45 2016 -0700 @@ -49,17 +49,19 @@ ## * optimization saving half the sums and multiplies function a = polyarea (x, y, dim) + if (nargin != 2 && nargin != 3) print_usage (); - elseif (size_equal (x, y)) - if (nargin == 2) - a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; - else - a = abs (sum (x .* (shift (y, -1, dim) - shift (y, 1, dim)), dim)) / 2; - endif - else + elseif (! size_equal (x, y)) error ("polyarea: X and Y must have the same shape"); endif + + if (nargin == 2) + a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; + else + a = abs (sum (x .* (shift (y, -1, dim) - shift (y, 1, dim)), dim)) / 2; + endif + endfunction
--- a/scripts/general/private/__splinen__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/private/__splinen__.m Fri May 20 15:46:45 2016 -0700 @@ -26,6 +26,7 @@ ## FIXME: Allow arbitrary grids.. function yi = __splinen__ (x, y, xi, extrapval, f) + ## ND isvector function. isvec = @(x) numel (x) == length (x); if (! iscell (x) || length (x) < ndims (y) || any (! cellfun (isvec, x)) @@ -46,5 +47,6 @@ endfor yi(idx) = extrapval; endif + endfunction
--- a/scripts/general/profexplore.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/profexplore.m Fri May 20 15:46:45 2016 -0700 @@ -134,5 +134,6 @@ endif endwhile + endfunction
--- a/scripts/general/quadgk.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/quadgk.m Fri May 20 15:46:45 2016 -0700 @@ -447,6 +447,7 @@ ## single BLAS call, rather than rows (sub) calls to the @times function. q = sum (y * weights15, 2) .* halfwidth; err = abs (sum (y(:,2:2:end) * weights7, 2) .* halfwidth - q); + endfunction function t = __quadgk_finite_waypoint__ (x, a, b)
--- a/scripts/general/quadv.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/quadv.m Fri May 20 15:46:45 2016 -0700 @@ -114,6 +114,7 @@ function [q, nfun, hmin] = simpsonstp (f, a, b, c, fa, fb, fc, q0, nfun, hmin, tol, trace, varargin) + if (nfun > 10_000) q = q0; else
--- a/scripts/general/structfun.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/structfun.m Fri May 20 15:46:45 2016 -0700 @@ -107,6 +107,7 @@ varargout = cellfun ("cell2struct", varargout, {fieldnames(S)}, {1}, ... uo_str, false); endif + endfunction
--- a/scripts/general/trapz.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/trapz.m Fri May 20 15:46:45 2016 -0700 @@ -122,6 +122,7 @@ z = 0.5 * sum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim); endif endif + endfunction
--- a/scripts/general/validateattributes.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/general/validateattributes.m Fri May 20 15:46:45 2016 -0700 @@ -330,6 +330,7 @@ error ("%s must be %s", err_ini, attr{idx-1}); endif endwhile + endfunction function retval = valid_arg_idx (arg)
--- a/scripts/geometry/dsearch.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/geometry/dsearch.m Fri May 20 15:46:45 2016 -0700 @@ -27,10 +27,13 @@ ## @end deftypefn function idx = dsearch (x, y, tri, xi, yi, s) + if (nargin < 5 || nargin > 6) print_usage (); endif + idx = __dsearchn__ ([x(:), y(:)], [xi(:), yi(:)]); + endfunction
--- a/scripts/geometry/dsearchn.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/geometry/dsearchn.m Fri May 20 15:46:45 2016 -0700 @@ -31,6 +31,7 @@ ## @end deftypefn function [idx, d] = dsearchn (x, tri, xi, outval) + if (nargin < 2 || nargin > 4) print_usage (); endif @@ -45,6 +46,7 @@ d(idx2) = outval; endif endif + endfunction
--- a/scripts/geometry/tsearchn.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/geometry/tsearchn.m Fri May 20 15:46:45 2016 -0700 @@ -31,6 +31,7 @@ ## @end deftypefn function [idx, p] = tsearchn (x, t, xi) + if (nargin != 3) print_usage (); endif @@ -56,6 +57,7 @@ p(ni(intri),:) = b(intri, :); ni(intri) = []; endfor + endfunction function Beta = cart2bary (T, P) @@ -84,6 +86,7 @@ [M, N] = size (P); Beta = (P - ones (M,1) * T(end,:)) / (T(1:end-1,:) - ones (N,1) * T(end,:)); Beta (:,end+1) = 1 - sum (Beta, 2); + endfunction
--- a/scripts/gui/waitbar.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/gui/waitbar.m Fri May 20 15:46:45 2016 -0700 @@ -161,6 +161,7 @@ endfunction function updatecancelbutton (hf, dummy, hax) + if (! strcmpi (get (hf, "__graphics_toolkit__"), "qt")) return endif @@ -199,6 +200,7 @@ set (hf, "position", fpos); set (hax, "position", apos, "units", units); endif + endfunction
--- a/scripts/help/__unimplemented__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/__unimplemented__.m Fri May 20 15:46:45 2016 -0700 @@ -526,6 +526,7 @@ endfunction function txt = check_package (fcn, name) + txt = sprintf ("the '%s' function belongs to the %s package from Octave Forge", fcn, name); @@ -542,6 +543,7 @@ ## the output of describe txt = sprintf ("%s which seems to not be installed in your system.", txt); endswitch + endfunction function list = missing_functions ()
--- a/scripts/help/doc_cache_create.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/doc_cache_create.m Fri May 20 15:46:45 2016 -0700 @@ -66,6 +66,7 @@ endfunction function [text, first_sentence, status] = handle_function (f, text, format) + first_sentence = ""; ## Skip internal functions starting with "__" if (strncmp (f, "__", 2)) @@ -93,9 +94,11 @@ ## Get first sentence of help text first_sentence = get_first_help_sentence (f); + endfunction function cache = create_cache (list) + cache = {}; ## For each function: @@ -117,6 +120,7 @@ cache(2, end) = text; cache(3, end) = first_sentence; endfor + endfunction function cache = gen_doc_cache_in_dir (directory) @@ -150,12 +154,14 @@ endfunction function cache = gen_builtin_cache () + operators = __operators__ (); keywords = __keywords__ (); builtins = __builtins__ (); list = {operators{:}, keywords{:}, builtins{:}}; cache = create_cache (list); + endfunction
--- a/scripts/help/get_first_help_sentence.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/get_first_help_sentence.m Fri May 20 15:46:45 2016 -0700 @@ -42,7 +42,7 @@ ## @end deftypefn function [text, status] = get_first_help_sentence (name, max_len = 80) - ## Check input + if (nargin < 1 || nargin > 2) print_usage (); endif @@ -77,6 +77,7 @@ if (nargout <= 1 && status != 0) warning ("get_first_help_sentence: couldn't run makeinfo on '%s'", name); endif + endfunction ## This function extracts the first sentence from a plain text help text @@ -140,6 +141,7 @@ ## Extract first line with plain text method. text = first_sentence_plain_text (help_text, max_len); + endfunction ## This function extracts the first sentence from a html help text.
--- a/scripts/help/help.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/help.m Fri May 20 15:46:45 2016 -0700 @@ -130,7 +130,6 @@ endfunction function retval = do_list_operators () - retval = sprintf ("*** operators:\n\n%s\n\n", list_in_columns (__operators__ ())); endfunction
--- a/scripts/help/lookfor.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/lookfor.m Fri May 20 15:46:45 2016 -0700 @@ -183,15 +183,18 @@ endfunction function [fcns, help_texts] = search_cache (str, cache_file, search_type) + load (cache_file); - if (! isempty (cache)) - t1 = strfind (lower (cache (1, :)), str); - t2 = strfind (lower (cache (search_type, :)), str); + + if (isempty (cache)) + fcns = help_texts = {}; + else + t1 = strfind (lower (cache(1, :)), str); + t2 = strfind (lower (cache(search_type, :)), str); cache_idx = find (! (cellfun ("isempty", t1) & cellfun ("isempty", t2))); fcns = cache(1, cache_idx); help_texts = cache(3, cache_idx); - else - fcns = help_texts = {}; endif + endfunction
--- a/scripts/help/print_usage.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/print_usage.m Fri May 20 15:46:45 2016 -0700 @@ -27,6 +27,7 @@ ## @end deftypefn function print_usage (name) + x = dbstack (); ## Handle input if (nargin == 0) @@ -100,6 +101,7 @@ endfunction function [retval, status] = get_usage_texinfo (help_text, max_len) + ## Lines ending with "@\n" are continuation lines, so they should be ## concatenated with the following line. help_text = strrep (help_text, "@\n", " "); @@ -127,6 +129,7 @@ ## Run makeinfo to generate plain text [retval, status] = __makeinfo__ (buffer, "plain text"); + endfunction function [retval, status] = get_usage_html (help_text, max_len)
--- a/scripts/help/private/__strip_html_tags__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/private/__strip_html_tags__.m Fri May 20 15:46:45 2016 -0700 @@ -25,6 +25,7 @@ ## function. function [text, status] = __strip_html_tags__ (html_text) + start = find (html_text == "<"); stop = find (html_text == ">"); if (length (start) == length (stop)) @@ -40,10 +41,12 @@ text = ""; status = 1; endif + endfunction ## This function removes end-lines (\n) that makes printing look bad function text = strip_superfluous_endlines (text) + ## Find groups of end-lines els = find (text == "\n"); dels = diff (els); @@ -78,5 +81,6 @@ ## Actually remove the elements text = text(keep); + endfunction
--- a/scripts/help/type.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/help/type.m Fri May 20 15:46:45 2016 -0700 @@ -124,6 +124,7 @@ text{n} = txt; endif endfor + endfunction
--- a/scripts/image/colormap.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/colormap.m Fri May 20 15:46:45 2016 -0700 @@ -60,6 +60,7 @@ ## Adapted-By: jwe function cmap = colormap (varargin) + mlock; # prevent map_list to be cleared by "clear all" persistent map_list = cell ();
--- a/scripts/image/cubehelix.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/cubehelix.m Fri May 20 15:46:45 2016 -0700 @@ -54,8 +54,8 @@ elseif (! isscalar (n)) error ("cubehelix: N must be a scalar"); endif + n = double (n); - if (n > 1) coeff = [ -0.14861 -0.29227 1.97294 1.78277 -0.90649 0.00000]; @@ -69,7 +69,6 @@ ## Clip values (only in case users have changed values of hue or gamma) map(map < 0) = 0; map(map > 1) = 1; - elseif (n > 0) map = [0, 0, 0]; else @@ -79,8 +78,8 @@ endfunction -## A better demo of this colormap would be a 3d plot in ntsc instead of -## rgb values. That would really show what this colormap is about. +## A better demo of this colormap would be a 3D plot in NTSC instead of +## RGB values. That would really show what this colormap is about. %!demo %! ## Show the 'cubehelix' colormap profile and as an image %! cmap = cubehelix (256); @@ -88,3 +87,4 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); +
--- a/scripts/image/im2double.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/im2double.m Fri May 20 15:46:45 2016 -0700 @@ -53,8 +53,13 @@ ## Author: Carnë Draug <carandraug@octave.org> function img = im2double (img, im_type) - ## "normal" (non-indexed) images - if (nargin () == 1) + + if (nargin < 1 || nargin > 2) + print_usage (); + endif + + if (nargin == 1) + ## "normal" (non-indexed) images switch (class (img)) case "uint8", img = double (img) / 255; case "uint16", img = double (img) / 65535; @@ -64,9 +69,8 @@ case "double", # do nothing otherwise, error ("im2double: IMG is of unsupported class \"%s\"", class (img)); endswitch - - ## indexed images - elseif (nargin () == 2) + else + ## indexed images if (! strcmpi (im_type, "indexed")) error ("im2double: second input argument must be the string \"indexed\""); elseif (any (isa (img, {"uint8", "uint16"}))) @@ -80,10 +84,8 @@ error (["im2double: if IMG is indexed, then it must be positive " ... "integer floating points, or unsigned integer class"]); endif + endif - else - print_usage (); - endif endfunction
--- a/scripts/image/imfinfo.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/imfinfo.m Fri May 20 15:46:45 2016 -0700 @@ -149,6 +149,7 @@ ## Author: Soren Hauberg <hauberg@gmail.com> function info = imfinfo (filename, varargin) + if (nargin < 1 || nargin > 2) print_usage (); elseif (! ischar (filename)) @@ -156,9 +157,12 @@ elseif (nargin > 1 && ! ischar (ext)) error ("imfinfo: EXT must be a string"); endif + info = imageIO ("imfinfo", @__imfinfo__, "info", filename, varargin{:}); + endfunction + ## This test is the same as the similar one in imread. imfinfo must check ## if file exists before calling __imfinfo_. This BIST test confirms this. %!testif HAVE_MAGICK
--- a/scripts/image/imformats.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/imformats.m Fri May 20 15:46:45 2016 -0700 @@ -71,6 +71,7 @@ ## Author: Carnë Draug <carandraug@octave.org> function varargout = imformats (arg1, arg2, arg3) + if (nargin > 3) print_usage (); endif @@ -138,6 +139,7 @@ else varargout{1} = formats; endif + endfunction function formats = default_formats () @@ -254,6 +256,7 @@ ## fills rest of format information by checking with GraphicsMagick formats = __magick_formats__ (formats); + endfunction function is_valid_format (format) @@ -264,21 +267,24 @@ if (! all (fields_mask)) error ("imformats: structure has missing field `%s'.", min_fields(! fields_mask){1}); endif + endfunction function match = find_ext_idx (formats, ext) - ## XXX: what should we do if there's more than one hit? - ## Should this function prevent the addition of - ## duplicated extensions? + ## FIXME: what should we do if there's more than one hit? + ## Should this function prevent the addition of + ## duplicated extensions? match = cellfun (@(x) any (strcmpi (x, ext)), {formats.ext}); endfunction function bool = isa_magick (coder, filename) + bool = false; try info = __magick_ping__ (filename, 1); bool = strcmp (coder, info.Format); end_try_catch + endfunction function pretty_print_formats (formats) @@ -315,6 +321,7 @@ endfunction + ## This must work, even without support for image IO %!test %! formats = imformats ();
--- a/scripts/image/imwrite.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/imwrite.m Fri May 20 15:46:45 2016 -0700 @@ -97,9 +97,11 @@ ## @end deftypefn function imwrite (varargin) + if (nargin < 2) print_usage (); endif + [filename, ext] = imwrite_filename (varargin{2:end}); fmt = imformats (ext); @@ -119,6 +121,7 @@ endfunction + ## Test input validation %!error imwrite () # Wrong # of args %!error imwrite (1) # Wrong # of args
--- a/scripts/image/ntsc2rgb.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/ntsc2rgb.m Fri May 20 15:46:45 2016 -0700 @@ -82,6 +82,7 @@ rgb(idx,:) = rgb(idx,:) ./ max (rgb(idx,:), [], 2); rgb = colorspace_conversion_revert (rgb, sz, is_im, is_nd); + endfunction
--- a/scripts/image/private/colorspace_conversion_revert.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/image/private/colorspace_conversion_revert.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## colorspace_conversion_input_check() function rv = colorspace_conversion_revert (rv, sz, is_im, is_nd) + if (is_im) if (is_nd) rv = reshape (rv, [sz(1:2) sz(4) sz(3)]); @@ -31,4 +32,6 @@ rv = reshape (rv, sz); endif endif + endfunction +
--- a/scripts/linear-algebra/logm.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/linear-algebra/logm.m Fri May 20 15:46:45 2016 -0700 @@ -133,6 +133,7 @@ ## LOG(EYE(SIZE(A))+A) using a partial fraction expansion. function s = logm_pade_pf (A, m) + [nodes, wts] = gauss_legendre (m); ## Convert from [-1,1] to [0,1]. nodes = (nodes+1)/2; @@ -143,6 +144,7 @@ for j = 1:m s += wts(j)*(A/(eye (n) + nodes(j)*A)); endfor + endfunction ###################################################################### @@ -155,11 +157,13 @@ ## rules, Math. Comp., 23(106):221-230, 1969. function [x, w] = gauss_legendre (n) + i = 1:n-1; v = i./sqrt ((2*i).^2-1); [V, D] = eig (diag (v, -1) + diag (v, 1)); x = diag (D); w = 2*(V(1,:)'.^2); + endfunction
--- a/scripts/linear-algebra/normest.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/linear-algebra/normest.m Fri May 20 15:46:45 2016 -0700 @@ -76,6 +76,7 @@ until (abs (n - n0) <= tol * n) rand ("state", v); # restore state of random number generator + endfunction
--- a/scripts/miscellaneous/fact.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/miscellaneous/fact.m Fri May 20 15:46:45 2016 -0700 @@ -268,6 +268,7 @@ endfunction function out = wordwrap (w) + ncol = terminal_size ()(2); wc = ostrsplit (w, " "); out = "\n"; @@ -284,6 +285,7 @@ i += 1; endwhile out = [out, "\n"]; + endfunction
--- a/scripts/miscellaneous/run.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/miscellaneous/run.m Fri May 20 15:46:45 2016 -0700 @@ -84,6 +84,7 @@ evalin ("caller", sprintf ("source ('%s');", script), "rethrow (lasterror ())"); endif + endfunction
--- a/scripts/miscellaneous/symvar.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/miscellaneous/symvar.m Fri May 20 15:46:45 2016 -0700 @@ -40,6 +40,7 @@ ## @end deftypefn function vars = symvar (str) + vars = argnames (inline (str)); ## Correct for auto-generated 'x' variable when no symvar was found. if (numel (vars) == 1 && strcmp (vars{1}, "x") && ! any (str == "x"))
--- a/scripts/miscellaneous/unpack.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/miscellaneous/unpack.m Fri May 20 15:46:45 2016 -0700 @@ -290,14 +290,14 @@ function files = __parse_gzip__ (output) ## Parse the output from gzip and gunzip returning the files - ## commpressed (or decompressed). + ## compressed (or decompressed). files = regexprep (output, '^.+ -- replaced with (.*)$', '$1'); endfunction function files = __parse_bzip2__ (output) ## Parse the output from bzip2 and bunzip2 returning the files - ## commpressed (or decompressed). + ## compressed (or decompressed). ## Strip leading blanks and .bz2 extension from filename files = regexprep (output, '^\s+(.*)\.bz2: .*', '$1');
--- a/scripts/optimization/fminunc.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/optimization/fminunc.m Fri May 20 15:46:45 2016 -0700 @@ -387,6 +387,7 @@ ## A helper function that evaluates a function and checks for bad results. function [fx, gx] = guarded_eval (fun, x) + if (nargout > 1) [fx, gx] = fun (x); else @@ -401,6 +402,7 @@ elseif (any (isinf (fx(:)))) error ("fminunc:isinf", "fminunc: Inf value encountered"); endif + endfunction @@ -437,6 +439,7 @@ ## FIXME: handle singularity, or leave it up to mldivide? function x = __doglegm__ (r, g, d, delta) + ## Get Gauss-Newton direction. b = r' \ g; x = r \ b; @@ -468,5 +471,6 @@ ## Form the appropriate convex combination. x = alpha * x + ((1-alpha) * min (snm, delta)) * s; endif + endfunction
--- a/scripts/optimization/fsolve.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/optimization/fsolve.m Fri May 20 15:46:45 2016 -0700 @@ -445,6 +445,7 @@ ## An assistant function that evaluates a function handle and checks for ## bad results. function [fx, jx] = guarded_eval (fun, x, complexeqn) + if (nargout > 1) [fx, jx] = fun (x); else @@ -461,13 +462,16 @@ elseif (any (isinf (fx(:)))) error ("fsolve:isinf", "fsolve: Inf value encountered"); endif + endfunction function [fx, jx] = make_fcn_jac (x, fcn, fjac) + fx = fcn (x); if (nargout == 2) jx = fjac (x); endif + endfunction @@ -587,6 +591,7 @@ ## FIXME: handle singularity, or leave it up to mldivide? function x = __dogleg__ (r, b, d, delta) + ## Get Gauss-Newton direction. x = r \ b; xn = norm (d .* x); @@ -617,5 +622,6 @@ ## Form the appropriate convex combination. x = alpha * x + ((1-alpha) * min (snm, delta)) * s; endif + endfunction
--- a/scripts/optimization/optimset.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/optimization/optimset.m Fri May 20 15:46:45 2016 -0700 @@ -115,7 +115,7 @@ function retval = optimset (varargin) - nargs = nargin (); + nargs = nargin; opts = __all_opts__ ();
--- a/scripts/optimization/private/__fdjac__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/optimization/private/__fdjac__.m Fri May 20 15:46:45 2016 -0700 @@ -22,6 +22,7 @@ ## @end deftypefn function fjac = __fdjac__ (fcn, x, fvec, typicalx, cdif, err = 0) + if (cdif) err = (max (eps, err)) ^ (1/3); h = typicalx*err; @@ -42,7 +43,6 @@ fjac(:,i) = (fcn (x1)(:) - fvec) / (x1(i) - x(i)); endfor endif + endfunction - -
--- a/scripts/optimization/sqp.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/optimization/sqp.m Fri May 20 15:46:45 2016 -0700 @@ -554,8 +554,7 @@ function [x_new, alpha, obj, globals] = ... - linesearch_L1 (x, p, obj_fun, obj_grd, ce_fun, ci_fun, lambda, ... - obj, globals) + linesearch_L1 (x, p, obj_fun, obj_grd, ce_fun, ci_fun, lambda, obj, globals) ## Choose parameters ##
--- a/scripts/pkg/private/build.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/build.m Fri May 20 15:46:45 2016 -0700 @@ -34,6 +34,7 @@ ## @end deftypefn function build (builddir, tarballs, verbose) + if (nargin != 3) print_usage (); endif @@ -83,4 +84,5 @@ chdir (init_wd); end_unwind_protect endfor + endfunction
--- a/scripts/pkg/private/configure_make.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/configure_make.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function configure_make (desc, packdir, verbose) + ## Perform ./configure, make, make install in "src". if (exist (fullfile (packdir, "src"), "dir")) src = fullfile (packdir, "src"); @@ -94,8 +95,8 @@ error ("pkg: error running `make' for the %s package.", desc.name); endif endif + endif - endif endfunction ## Executes a shell command. In the end it calls system() but in case of @@ -133,4 +134,6 @@ else [status, output] = system (cmd); endif + endfunction +
--- a/scripts/pkg/private/default_prefix.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/default_prefix.m Fri May 20 15:46:45 2016 -0700 @@ -22,6 +22,7 @@ ## @end deftypefn function [prefix, archprefix] = default_prefix (global_install, desc) + if (global_install) prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); if (nargin == 2) @@ -35,5 +36,6 @@ prefix = tilde_expand (fullfile ("~", "octave")); archprefix = prefix; endif + endfunction
--- a/scripts/pkg/private/describe.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/describe.m Fri May 20 15:46:45 2016 -0700 @@ -82,6 +82,7 @@ flag{i}, verbose); endfor endif + endfunction @@ -135,11 +136,13 @@ line = fgetl (fid); endwhile fclose (fid); + endfunction function print_package_description (pkg_name, pkg_ver, pkg_idx_struct, pkg_desc, status, verbose) + printf ("---\nPackage name:\n\t%s\n", pkg_name); printf ("Version:\n\t%s\n", pkg_ver); printf ("Short description:\n\t%s\n", pkg_desc); @@ -155,4 +158,5 @@ endif endfor endif + endfunction
--- a/scripts/pkg/private/dirempty.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/dirempty.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function emp = dirempty (nm, ign) + if (exist (nm, "dir")) if (nargin < 2) ign = {".", ".."}; @@ -47,5 +48,6 @@ else emp = true; endif + endfunction
--- a/scripts/pkg/private/get_description.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/get_description.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,7 @@ ## Parse the DESCRIPTION file. function desc = get_description (filename) + [fid, msg] = fopen (filename, "r"); if (fid == -1) error ("the DESCRIPTION file %s could not be read: %s", filename, msg); @@ -80,6 +81,7 @@ desc.depends = ""; endif desc.name = tolower (desc.name); + endfunction @@ -87,6 +89,7 @@ ## This function returns a cell of structures with the following fields: ## package, version, operator function deps_cell = fix_depends (depends) + deps = strtrim (ostrsplit (tolower (depends), ",")); deps_cell = cell (1, length (deps)); dep_pat = ... @@ -126,12 +129,13 @@ dep); endif endfor + endfunction function [valid] = is_valid_pkg_version_string (str) ## We are limiting ourselves to this set of characters because the - ## version will appear on the filepath. The portable character, according - ## to http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278 + ## version will appear on the filepath. The portable character, according to + ## http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278 ## is [A-Za-z0-9\.\_\-]. However, this is very limited. We specially ## want to support a "+" so we can support "pkgname-2.1.0+" during ## development. So we use Debian's character set for version strings
--- a/scripts/pkg/private/get_forge_download.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/get_forge_download.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,6 @@ function [url, local_file] = get_forge_download (name) [ver, url] = get_forge_pkg (name); - local_file = [name, "-", ver, ".tar.gz"]; + local_file = [name "-" ver ".tar.gz"]; endfunction
--- a/scripts/pkg/private/get_unsatisfied_deps.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/get_unsatisfied_deps.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function bad_deps = get_unsatisfied_deps (desc, installed_pkgs_lst) + bad_deps = {}; ## For each dependency. @@ -51,5 +52,6 @@ endif endif endfor + endfunction
--- a/scripts/pkg/private/getarch.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/getarch.m Fri May 20 15:46:45 2016 -0700 @@ -25,6 +25,7 @@ function arch = getarch () persistent _arch = [__octave_config_info__("canonical_host_type"), "-", ... __octave_config_info__("api_version")]; + arch = _arch; endfunction
--- a/scripts/pkg/private/install.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/install.m Fri May 20 15:46:45 2016 -0700 @@ -299,10 +299,12 @@ printf ("For information about changes from previous versions of the %s package, run 'news %s'.\n", desc.name, desc.name); endif + endfunction function pkg = extract_pkg (nm, pat) + fid = fopen (nm, "rt"); pkg = ""; if (fid >= 0) @@ -320,21 +322,25 @@ endif fclose (fid); endif + endfunction ## Make sure the package contains the essential files. function verify_directory (dir) + needed_files = {"COPYING", "DESCRIPTION"}; for f = needed_files if (! exist (fullfile (dir, f{1}), "file")) error ("package is missing file: %s", f{1}); endif endfor + endfunction function prepare_installation (desc, packdir) + ## Is there a pre_install to call? if (exist (fullfile (packdir, "pre_install.m"), "file")) wd = pwd (); @@ -358,10 +364,12 @@ msg); endif endif + endfunction function copy_built_files (desc, packdir, verbose) + src = fullfile (packdir, "src"); if (! exist (src, "dir")) return @@ -445,6 +453,7 @@ endif endif endif + endfunction @@ -469,10 +478,12 @@ break; endif endfor + endfunction function copy_files (desc, packdir, global_install) + ## Create the installation directory. if (! exist (desc.dir, "dir")) [status, output] = mkdir (desc.dir); @@ -589,10 +600,12 @@ if (exist (bindir, "dir") && ! dirempty (bindir)) [status, output] = copyfile (bindir, desc.dir); endif + endfunction function packinfo_copy_file (filename, requirement, packdir, packinfo, desc, octfiledir) + filepath = fullfile (packdir, filename); if (! exist (filepath, "file") && strcmpi (requirement, "optional")) ## do nothing, it's still OK @@ -604,6 +617,7 @@ error ("Couldn't copy %s file: %s", filename, output); endif endif + endfunction @@ -612,6 +626,7 @@ ## 'dir' is the 'inst' directory in temporary directory. ## 'index_file' is the name (including path) of resulting INDEX file. function write_index (desc, dir, index_file, global_install) + ## Get names of functions in dir [files, err, msg] = readdir (dir); if (err) @@ -672,10 +687,12 @@ fprintf (fid, "%s\n", categories{1}); fprintf (fid, " %s\n", functions{:}); fclose (fid); + endfunction function create_pkgadddel (desc, packdir, nm, global_install) + instpkg = fullfile (desc.dir, nm); instfid = fopen (instpkg, "at"); # append to support PKG_ADD at inst/ ## If it is exists, most of the PKG_* file should go into the @@ -738,19 +755,23 @@ endif endif endif + endfunction function archprefix = getarchprefix (desc, global_install) + if (global_install) [~, archprefix] = default_prefix (global_install, desc); else archprefix = desc.dir; endif + endfunction function finish_installation (desc, packdir, global_install) + ## Is there a post-install to call? if (exist (fullfile (packdir, "post_install.m"), "file")) wd = pwd (); @@ -765,12 +786,16 @@ rethrow (lasterror ()); end_try_catch endif + endfunction function generate_lookfor_cache (desc) + dirs = strtrim (ostrsplit (genpath (desc.dir), pathsep ())); for i = 1 : length (dirs) doc_cache_create (fullfile (dirs{i}, "doc-cache"), dirs{i}); endfor + endfunction +
--- a/scripts/pkg/private/installed_packages.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/installed_packages.m Fri May 20 15:46:45 2016 -0700 @@ -148,4 +148,5 @@ printf (format, cur_name, cur_loaded, cur_version, cur_dir); endfor endif + endfunction
--- a/scripts/pkg/private/list_forge_packages.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/list_forge_packages.m Fri May 20 15:46:45 2016 -0700 @@ -23,12 +23,14 @@ ## @end deftypefn function list = list_forge_packages () + [list, succ] = urlread ("http://packages.octave.org/list_packages.php"); - if (succ) - list = ostrsplit (list, " \n\t", true); - else + if (! succ) error ("pkg: could not read URL, please verify internet connection"); endif + + list = ostrsplit (list, " \n\t", true); + if (nargout == 0) page_screen_output (false, "local"); puts ("OctaveForge provides these packages:\n"); @@ -41,5 +43,6 @@ printf (" %s %s\n", list{i}, ver); endfor endif + endfunction
--- a/scripts/pkg/private/load_packages.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/load_packages.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function load_packages (files, handle_deps, local_list, global_list) + installed_pkgs_lst = installed_packages (local_list, global_list); num_packages = length (installed_pkgs_lst); @@ -49,5 +50,6 @@ ## Load the packages, but take care of the ordering of dependencies. load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true); + endfunction
--- a/scripts/pkg/private/load_packages_and_dependencies.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/load_packages_and_dependencies.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,7 @@ function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, global_install) + idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); dirs = {}; execpath = EXEC_PATH (); @@ -51,10 +52,12 @@ if (! strcmp (EXEC_PATH, execpath)) EXEC_PATH (execpath); endif + endfunction function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst) + for i = lidx if (isfield (installed_pkgs_lst{i}, "loaded") && installed_pkgs_lst{i}.loaded) @@ -86,4 +89,6 @@ endif endif endfor + endfunction +
--- a/scripts/pkg/private/rebuild.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/rebuild.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function descriptions = rebuild (prefix, archprefix, list, files, verbose) + if (isempty (files)) [dirlist, err, msg] = readdir (prefix); if (err) @@ -40,6 +41,7 @@ cd (wd); end_unwind_protect endif + descriptions = {}; for k = 1:length (dirlist) descfile = fullfile (prefix, dirlist{k}, "packinfo", "DESCRIPTION"); @@ -79,5 +81,6 @@ descriptions(dup) = []; endif endif + endfunction
--- a/scripts/pkg/private/save_order.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/save_order.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function newdesc = save_order (desc) + newdesc = {}; for i = 1 : length (desc) deps = desc{i}.depends; @@ -46,6 +47,7 @@ endif endif endfor + ## Eliminate the duplicates. idx = []; for i = 1 : length (newdesc) @@ -56,5 +58,6 @@ endfor endfor newdesc(idx) = []; + endfunction
--- a/scripts/pkg/private/uninstall.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/uninstall.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,7 @@ function uninstall (pkgnames, handle_deps, verbose, local_list, global_list, global_install) + ## Get the list of installed packages. [local_packages, global_packages] = installed_packages(local_list, global_list);
--- a/scripts/pkg/private/unload_packages.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/pkg/private/unload_packages.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ ## @end deftypefn function unload_packages (files, handle_deps, local_list, global_list) + installed_pkgs_lst = installed_packages (local_list, global_list); num_packages = length (installed_pkgs_lst); @@ -76,5 +77,6 @@ ## FIXME: We should also check if we need to remove items from EXEC_PATH. endif endfor + endfunction
--- a/scripts/plot/appearance/annotation.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/annotation.m Fri May 20 15:46:45 2016 -0700 @@ -529,6 +529,7 @@ endfunction function props = lineprops (varargin) + ## FIXME: Use "axesx(y)lim" instead of "linex(y)data" props = {"color", "color", [0 0 0], ... "linestyle", "linelinestyle", "-", ... @@ -538,6 +539,7 @@ if (strcmp (varargin, "names")) props = props(1:3:end); endif + endfunction function col = basecolors () @@ -546,13 +548,13 @@ endfunction function linemenu (hui, hpar) + hm = uimenu ("parent", hui, "label", "Line"); ## Color vals = basecolors (); addbasemenu (hm, hpar, "Color", vals); - ## Linestyle vals = set (hpar, "linestyle"); addbasemenu (hm, hpar, "Linestyle", vals); @@ -560,18 +562,22 @@ ## Linewidth vals = [0.5 1 1.5 2]; addbasemenu (hm, hpar, "Linewidth", vals); + endfunction function props = arrowprops (varargin) + props = {"headlength", "data", 10, ... "headstyle", "radio", "diamond|ellipse|none|plain|rectangle|vback1|{vback2}|vback3", ... "headwidth", "data", 10}; if (strcmp (varargin, "names")) props = props(1:3:end); endif + endfunction function arrowmenu (hui, hpar) + hm = uimenu ("parent", hui, "label", "Arrowhead"); ## Headlength/width @@ -582,9 +588,11 @@ ## Headstyle vals = set (hpar, "headstyle"); addbasemenu (hm, hpar, "Headstyle", vals); + endfunction function props = dblarrowprops (varargin) + props = {"head1length", "data", 10, ... "head1style", "radio", "diamond|ellipse|none|plain|rectangle|vback1|{vback2}|vback3", ... "head1width", "data", 10, ... @@ -594,9 +602,11 @@ if (strcmp (varargin, "names")) props = props(1:3:end); endif + endfunction function dblarrowmenu (hui, hpar) + hm1 = uimenu ("parent", hui, "label", "Arrowhead #1"); hm2 = uimenu ("parent", hui, "label", "Arrowhead #2"); @@ -611,9 +621,11 @@ vals = set (hpar, "head1style"); addbasemenu (hm1, hpar, "head1style", vals, "Headstyle"); addbasemenu (hm2, hpar, "head2style", vals, "Headstyle"); + endfunction function props = textprops (varargin) + props = {"fontangle", "textfontangle", "normal", ... "fontname", "textfontname", "Helvetica", ... "fontsize", "textfontsize", 10, ... @@ -632,9 +644,11 @@ if (strcmp (varargin, "names")) props = props(1:3:end); endif + endfunction function stringdlg (hpar, prop) + def = get (hpar, prop); if (iscell (def)) prompt = arrayfun (@(n) sprintf ("Line #%d:", n), 1:numel (def), @@ -649,9 +663,11 @@ if (! isempty (cstr)) set (hpar, prop, cstr); endif + endfunction function textmenu (hui, hpar) + hm = uimenu ("parent", hui, "label", "Text"); ## String; @@ -694,6 +710,7 @@ endfunction function props = textboxprops (varargin) + props = {"backgroundcolor", "patchfacecolor", "none", ... "color", "textcolor", [0 0 0], ... "edgecolor", "patchedgecolor", [0 0 0], ... @@ -714,9 +731,11 @@ if (strcmp (varargin, "names")) props = props(1:3:end); endif + endfunction function textboxmenu (hui, hpar) + ## Text properties hm1 = uimenu ("parent", hui, "label", "Text"); @@ -771,9 +790,11 @@ prop = "linewidth"; vals = 0.5:.5:2; addbasemenu (hm2, hpar, prop, vals, "Line Width"); + endfunction function props = rectprops (varargin) + props = {"edgecolor", "patchedgecolor", "k", ... "facealpha", "patchfacealpha", 1, ... "facecolor", "patchfacecolor", "none", ... @@ -782,9 +803,11 @@ if (strcmp (varargin, "names")) props = props(1:3:end); endif + endfunction function rectmenu (hui, hpar) + prop = "facecolor"; vals = basecolors (); addbasemenu (hui, hpar, prop, vals, "Face Color"); @@ -797,6 +820,7 @@ prop = "linewidth"; vals = 0.5:.5:2; addbasemenu (hui, hpar, prop, vals, "Line Width"); + endfunction function addbaseprops (h, proptable) @@ -805,6 +829,7 @@ endfunction function addbasemenu (hm, hpar, pname, vals, mainlabel = "" ) + if (isempty (mainlabel)) mainlabel = pname; endif @@ -825,11 +850,14 @@ fcn = @() set (hpar, pname, val); htmp(ii) = uimenu (h, "label", label, "callback", fcn); endfor + handle_check (hpar, {}, htmp, pname, is_numeric); addlistener (hpar, pname, {@handle_check, htmp, pname, is_numeric}); + endfunction function handle_check (h, dummy, hmenus, prop, is_numeric) + vals = get (hmenus, "label"); current = get (h, prop); if (is_numeric) @@ -839,9 +867,11 @@ idx = strcmp (vals, current); set (hmenus(idx), "checked", "on"); set (hmenus(! idx), "checked", "off"); + endfunction function update_position (h1, dummy, h, force = false) + if (! force) pos = convertposition (h, getappdata (h, "__former_units__"), get (h, "units")); @@ -852,11 +882,12 @@ set (h, "position", [0 0 .5 .5], "position", get (h, "position")); endif + endfunction - function update_line (h, dummy, prop, hli) persistent recursive = false; + if (! recursive) switch (prop) case "color" @@ -914,9 +945,11 @@ endswitch endif + endfunction function [x, y] = arrowcoordinates (h, nar = []) + pos = getnormpos (h); ppos = norm2pts (h, pos(3:4).'); ang = angle (complex (ppos(1), ppos(2))); @@ -979,6 +1012,7 @@ x = XY(1,:).'; y = XY(2,:).'; + endfunction function update_arrow (h, dummy, prop, hpa = []) @@ -1000,6 +1034,7 @@ endswitch endif endfor + endfunction function update_text (h, dummy, prop, hte) @@ -1024,6 +1059,7 @@ endif endswitch endif + endfunction function update_textbox (h, dummy, prop, htb) @@ -1204,11 +1240,11 @@ endfunction function [x, y] = pos2ell (pos) + a = pos(3)/2; b = pos(4)/2; - ## Arbitrarily use 100 points - ## when it is spread over + ## Arbitrarily use 100 points when it is spread over ang = linspace (0, 2*pi, 100); x = a * cos (ang); @@ -1216,6 +1252,7 @@ x += pos(1) + a; y += pos(2) + b; + endfunction function update_rect (h, dummy, prop, hre, typ) @@ -1236,10 +1273,11 @@ set (hre, prop, get (h, prop)); endswitch endif + endfunction -## FIXME: the additionnal regular axes is necessary for fltk to draw the +## FIXME: the additional regular axes is necessary for fltk to draw the ## annotation axes. %!demo %! clf; axes ('visible', 'off');
--- a/scripts/plot/appearance/datetick.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/datetick.m Fri May 20 15:46:45 2016 -0700 @@ -271,12 +271,13 @@ [ax "lim"], [min(ticks), max(ticks)]); endif endif + endfunction function [a, b] = __magform__ (x) + if (x == 0) - a = 0; - b = 0; + a = b = 0; else l = log10 (abs (x)); r = rem (l, 1); @@ -290,6 +291,7 @@ a = -a; endif endif + endfunction ## A translation from Tom Holoryd's python code at @@ -317,6 +319,8 @@ else x = 10; endif + sep = x * 10 .^ b; + endfunction
--- a/scripts/plot/appearance/legend.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/legend.m Fri May 20 15:46:45 2016 -0700 @@ -1104,6 +1104,7 @@ endfunction function updatelegendtext (h, ~) + kids = get (h, "children"); htext = []; for i = 1:numel (kids) @@ -1118,9 +1119,11 @@ ec = get (h, "edgecolor"); set (h, "xcolor", ec, "ycolor", ec); + endfunction function hideshowlegend (h, ~, ca, pos1, pos2) + isvisible = strcmp (get (h, "visible"), "off"); if (! isvisible) kids = get (h, "children"); @@ -1146,6 +1149,7 @@ end_unwind_protect endif endfor + endfunction function deletelegend1 (h, ~, hlegend) @@ -1157,6 +1161,7 @@ endfunction function deletelegend2 (h, ~, ca, pos, outpos, t1, hplots) + for i = 1 : numel (ca) if (isaxes (ca(i)) && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")) @@ -1172,10 +1177,12 @@ endif endif endfor + if (ishandle (t1)) set (t1, "deletefcn", ""); delete (t1); endif + for i = 1 : numel (hplots) if (ishandle (hplots(i)) && strcmp (get (hplots(i), "type"), "line")) dellistener (hplots(i), "color"); @@ -1188,6 +1195,7 @@ dellistener (hplots(i), "displayname"); endif endfor + endfunction function updateline (h, ~, hlegend, linelength, update_name) @@ -1245,6 +1253,7 @@ "userdata", h, "parent", hlegend); endif endif + endfunction
--- a/scripts/plot/appearance/whitebg.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/whitebg.m Fri May 20 15:46:45 2016 -0700 @@ -38,6 +38,7 @@ ## @end deftypefn function whitebg (varargin) + h = 0; color = NaN; @@ -133,8 +134,7 @@ endif endfor else - ## FIXME - ## Is this the right thing to do in this case? + ## FIXME: Is this the right thing to do in this case? set (findall (fig, "type", "axes"), "color", color); if (isroot) defs = get (0, "default"); @@ -144,6 +144,7 @@ endif endif endif + endfunction
--- a/scripts/plot/appearance/xlim.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/xlim.m Fri May 20 15:46:45 2016 -0700 @@ -43,11 +43,13 @@ ## @end deftypefn function retval = xlim (varargin) + ret = __axis_limits__ ("xlim", varargin{:}); if (! isempty (ret)) retval = ret; endif + endfunction
--- a/scripts/plot/appearance/ylim.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/ylim.m Fri May 20 15:46:45 2016 -0700 @@ -43,11 +43,13 @@ ## @end deftypefn function retval = ylim (varargin) + ret = __axis_limits__ ("ylim", varargin{:}); if (! isempty (ret)) retval = ret; endif + endfunction
--- a/scripts/plot/appearance/zlim.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/appearance/zlim.m Fri May 20 15:46:45 2016 -0700 @@ -43,11 +43,13 @@ ## @end deftypefn function retval = zlim (varargin) + ret = __axis_limits__ ("zlim", varargin{:}); if (! isempty (ret)) retval = ret; endif + endfunction
--- a/scripts/plot/draw/area.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/area.m Fri May 20 15:46:45 2016 -0700 @@ -187,11 +187,13 @@ endfunction function update_props (h, d) + kids = get (h, "children"); set (kids, "edgecolor", get (h, "edgecolor"), "facecolor", get (h, "facecolor"), "linestyle", get (h, "linestyle"), "linewidth", get (h, "linewidth")); + endfunction function move_baseline (h, d) @@ -217,9 +219,11 @@ recursion = false; end_unwind_protect endif + endfunction function update_data (h, d) + hlist = get (h, "areagroup"); bv = get (h, "basevalue"); for i = 1 : length (hlist) @@ -237,6 +241,7 @@ y0 = y1; endfor + endfunction
--- a/scripts/plot/draw/colorbar.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/colorbar.m Fri May 20 15:46:45 2016 -0700 @@ -254,8 +254,8 @@ endfunction function deletecolorbar (h, d, hc, orig_props) - ## Don't delete the colorbar and reset the axis size if the - ## parent figure is being deleted. + ## Don't delete the colorbar and reset the axis size + ## if the parent figure is being deleted. if (isaxes (hc) && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))) if (strcmp (get (hc, "beingdeleted"), "off")) @@ -272,9 +272,11 @@ set (ax, "units", units); endif endif + endfunction function resetaxis (cax, d, ax, orig_props) + if (isaxes (ax)) ## FIXME: Probably don't want to delete everyone's listeners on colormap. dellistener (ancestor (ax, "figure"), "colormap"); @@ -292,9 +294,11 @@ "activepositionproperty", orig_props.activepositionproperty); set (ax, "units", units); endif + endfunction function update_colorbar_clim (hax, d, hi, vert) + if (isaxes (hax) && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))) clen = rows (get (ancestor (hax, "figure"), "colormap")); @@ -312,6 +316,7 @@ set (hiax, "xlim", cext); endif endif + endfunction function update_colorbar_cmap (hf, d, hi, vert, init_sz) @@ -331,9 +336,11 @@ update_colorbar_clim (get (hi, "parent"), d, hi, vert); endif endif + endfunction function update_colorbar_axis (h, d, cax, orig_props) + if (isaxes (cax) && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off"))) loc = get (cax, "location"); @@ -363,6 +370,7 @@ endif endif + endfunction function [pos, cpos, vertical, mirr] = __position_colorbox__ (cbox, obj, cf)
--- a/scripts/plot/draw/fill.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/fill.m Fri May 20 15:46:45 2016 -0700 @@ -146,6 +146,7 @@ endfunction function retval = iscolorspec (arg) + retval = false; if (ischar (arg)) persistent colors = {"y", "yellow", "r", "red", "m", "magenta", ... @@ -159,6 +160,7 @@ ## Let patch worry about the multple different input formats. retval = true; endif + endfunction
--- a/scripts/plot/draw/isocolors.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/isocolors.m Fri May 20 15:46:45 2016 -0700 @@ -100,6 +100,7 @@ ## Author: Martin Helm <martin@mhelm.de> function varargout = isocolors (varargin) + calc_rgb = false; switch (nargin) case 2 @@ -135,6 +136,7 @@ otherwise print_usage (); endswitch + if (isnumeric (vp) && columns (vp) == 3) pa = []; v = vp; @@ -144,6 +146,7 @@ else error ("isocolors: last argument is not a vertex list or patch handle"); endif + if (calc_rgb) new_col = zeros (rows (v), 3); new_col(:,1) = __interp_cube__ (x, y, z, R, v, "values" ); @@ -152,6 +155,8 @@ else new_col = __interp_cube__ (x, y, z, c, v, "values" ); endif + + ## FIXME: No reason to actually error out if an extra argout is used. switch (nargout) case 0 if (! isempty (pa)) @@ -162,6 +167,7 @@ otherwise print_usage (); endswitch + endfunction
--- a/scripts/plot/draw/isonormals.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/isonormals.m Fri May 20 15:46:45 2016 -0700 @@ -98,6 +98,7 @@ ## Author: Martin Helm <martin@mhelm.de> function varargout = isonormals (varargin) + na = nargin; negate = false; if (ischar (varargin{nargin})) @@ -108,6 +109,7 @@ error ("isonormals: Unknown option '%s'", varargin{nargin}); endif endif + switch (na) case 2 c = varargin{1}; @@ -124,6 +126,7 @@ otherwise print_usage (); endswitch + if (isnumeric (vp) && columns (vp) == 3) pa = []; v = vp; @@ -133,11 +136,13 @@ else error ("isonormals: Last argument is not a vertex list or a patch handle"); endif + if (negate) normals = -__interp_cube__ (x, y, z, c, v, "normals"); else normals = __interp_cube__ (x, y, z, c, v, "normals"); endif + switch (nargout) case 0 if (! isempty (pa)) @@ -148,6 +153,7 @@ otherwise print_usage (); endswitch + endfunction
--- a/scripts/plot/draw/plotmatrix.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/plotmatrix.m Fri May 20 15:46:45 2016 -0700 @@ -114,6 +114,7 @@ function plotmatrixdelete (h, d, ax) + for i = 1 : numel (ax) hc = ax(i); if (isaxes (hc) && strcmpi (get (hc, "beingdeleted"), "off")) @@ -124,9 +125,11 @@ endif endif endfor + endfunction function [h, ax, p, pax] = __plotmatrix__ (bigax, varargin) + have_line_spec = false; have_hist = false; parent = get (bigax, "parent"); @@ -198,5 +201,6 @@ endif endfor endfor + endfunction
--- a/scripts/plot/draw/plotyy.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/plotyy.m Fri May 20 15:46:45 2016 -0700 @@ -191,6 +191,7 @@ else error ("plotyy.m: This shouldn't happen. File a bug report."); endif + endfunction function deleteplotyy (h, ~, ax2, t2) @@ -204,6 +205,7 @@ function update_nextplot (h, ~, ax2) persistent recursion = false; + if (! recursion) unwind_protect recursion = true; @@ -212,6 +214,7 @@ recursion = false; end_unwind_protect endif + endfunction function update_position (h, ~, ax2) @@ -252,9 +255,11 @@ recursion = false; end_unwind_protect endif + endfunction function color = getcolor (ax) + obj = get (ax); if (isfield (obj, "color")) color = obj.color; @@ -265,6 +270,7 @@ else color = [0, 0, 0]; endif + endfunction
--- a/scripts/plot/draw/polar.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/polar.m Fri May 20 15:46:45 2016 -0700 @@ -158,9 +158,9 @@ ## FIXME: workaround: calculate r(ho)tick from xtick ## It would be better to just calculate the values, ## but that code is deep in the C++ for the plot engines. - savexlim = get (hax, "xlim"); - saveylim = get (hax, "ylim"); + saved_lims = get (hax, {"xlim", "ylim"}); set (hax, "xlim", [-maxr maxr], "ylim", [-maxr maxr]); + xtick = get (hax, "xtick"); minidx = find (xtick > 0, 1); maxidx = find (xtick >= maxr, 1); @@ -171,7 +171,9 @@ rtick = xtick(minidx:end); rtick(end+1) = xtick(end) + diff (xtick(end-1:end)); endif - set (hax, "xlim", savexlim, "ylim", saveylim); + + set (hax, {"xlim", "ylim"}, saved_lims); + endfunction function retval = __plr1__ (h, theta, fmt) @@ -194,6 +196,7 @@ if (ndims (theta) > 2 || ndims (rho) > 2) error ("polar: THETA and RHO must be 2-D objects"); endif + theta = real (theta); rho = real (rho); @@ -310,6 +313,7 @@ unwind_protect_cleanup set (0, "showhiddenhandles", shh); end_unwind_protect + endfunction function __update_polar_grid__ (hax, ~, hg)
--- a/scripts/plot/draw/private/__bar__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__bar__.m Fri May 20 15:46:45 2016 -0700 @@ -342,6 +342,7 @@ endfunction function update_xlim (h, ~) + kids = get (h, "children"); xlim = get (h, "xlim"); @@ -353,9 +354,11 @@ endif endif endfor + endfunction function update_baseline (h, ~) + visible = get (h, "visible"); ydata = get (h, "ydata")(1); @@ -369,6 +372,7 @@ break; endif endfor + endfunction function show_baseline (h, ~, prop = "") @@ -394,6 +398,7 @@ recursion = false; end_unwind_protect endif + endfunction function move_baseline (h, ~) @@ -414,6 +419,7 @@ recursion = false; end_unwind_protect endif + endfunction function update_props (h, ~) @@ -459,6 +465,7 @@ recursion = false; end_unwind_protect endif + endfunction function update_group (h, ~) @@ -481,5 +488,6 @@ recursion = false; end_unwind_protect endif + endfunction
--- a/scripts/plot/draw/private/__contour__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__contour__.m Fri May 20 15:46:45 2016 -0700 @@ -22,6 +22,7 @@ ## @end deftypefn function [c, hg] = __contour__ (varargin) + ax = varargin{1}; zlevel = varargin{2}; filled = "off"; @@ -206,6 +207,7 @@ endfunction function add_patch_children (hg) + c = get (hg, "contourmatrix"); lev = get (hg, "levellist"); fill = get (hg, "fill"); @@ -379,6 +381,7 @@ endfunction function update_zlevel (h, ~) + z = get (h, "zlevel"); zmode = get (h, "zlevelmode"); kids = get (h, "children"); @@ -396,15 +399,18 @@ set (kids(i), "zdata", z .* ones (size (get (kids(i), "xdata")))); endfor endswitch + endfunction function update_line (h, ~) + lc = get (h, "linecolor"); if (strcmp (lc, "auto")) lc = "flat"; endif set (findobj (h, "type", "patch"), "edgecolor", lc, "linewidth", get (h, "linewidth"), "linestyle", get (h, "linestyle")); + endfunction function update_data (h, ~, prop = "") @@ -540,9 +546,11 @@ recursive = false; endif + endfunction function lvl_eps = get_lvl_eps (lev) + ## FIXME: is this the right thing to do for this tolerance? Should ## it be an absolute or relative tolerance, or switch from one to the ## other depending on the value of lev? @@ -556,5 +564,6 @@ lvl_eps = tmp / 1000.0; endif endif + endfunction
--- a/scripts/plot/draw/private/__errplot__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__errplot__.m Fri May 20 15:46:45 2016 -0700 @@ -283,6 +283,7 @@ function [xdata, ydata] = errorbar_data (xdata, ydata, ldata, udata, xldata, xudata, ifmt, xscale, yscale) + if (strcmp (xscale, "linear")) dx = 0.01 * (max (xdata(:)) - min (xdata(:))); if (dx == 0) @@ -317,6 +318,7 @@ ylo = ydata/ry; yhi = ydata*ry; endif + nans = NaN + xdata(:); # fast way to do NaN (size (xdata(:))) if (strcmp (ifmt, "yerr")) xdata = [xdata, xdata, nans, ... @@ -365,6 +367,7 @@ endfunction function update_props (hg, ~, hl) + set (hl, "color", get (hg, "color"), "linewidth", get (hg, "linewidth")); set (hl(2), "linestyle", get (hg, "linestyle"), @@ -372,6 +375,7 @@ "markeredgecolor", get (hg, "markeredgecolor"), "markerfacecolor", get (hg, "markerfacecolor"), "markersize", get (hg, "markersize")); + endfunction function update_data (hg, ~, hl)
--- a/scripts/plot/draw/private/__interp_cube__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__interp_cube__.m Fri May 20 15:46:45 2016 -0700 @@ -24,6 +24,7 @@ ## @end deftypefn function [Vxyz, idx, frac] = __interp_cube__ (x, y, z, val, v, req = "values" ) + if (isnumeric (x) && ndims (x) == 3 && isnumeric (y) && ndims (y) == 3 && isnumeric (z) && ndims (z) == 3 && size_equal (x, y, z, val)) x = squeeze (x(1,:,1))(:); @@ -36,6 +37,7 @@ else error ("__interp_cube__: X, Y, Z have wrong dimensions"); endif + if (size (val) != [length(x), length(y), length(z)]) error ("__interp_cube__: VAL has wrong dimensions"); endif @@ -43,8 +45,9 @@ error ( "V has to be Nx3 matrix"); endif ##if (! ischar (req)) - ## error ('__interp_cube__: Invalid request parameter use "values", "normals" or "normals8"'); + ## error ('__interp_cube__: Invalid request parameter use "values", "normals" or "normals8"'); ##endif + if (isempty (v)) Vxyz = idx = frac = []; return; @@ -99,9 +102,11 @@ otherwise error ('__interp_cube__: Invalid request type "%s", use "values", "normals" or "normals8"', req); endswitch + endfunction function [Vxyz, idx, frac] = interp_cube_trilin (x, y, z, val, v) + [idx, frac] = cube_idx (x(:), y(:), z(:), v); sval = size (val); i000 = sub2ind (sval, idx(:, 1), idx(:, 2), idx(:, 3)); @@ -124,9 +129,11 @@ val( i101 ) .* Bx .* (1 .- By) .* Bz .+ ... val( i110 ) .* Bx .* By .* (1 .- Bz) .+ ... val( i111 ) .* Bx .* By .* Bz; + endfunction function [Dx, Dy, Dz, idx, frac] = interp_cube_trilin_grad (x, y, z, val, v) + [idx, frac] = cube_idx (x(:), y(:), z(:), v); sval = size (val); i000 = sub2ind (sval, idx(:, 1), idx(:, 2), idx(:, 3)); @@ -167,9 +174,11 @@ val( i101 ) .* Bx .* (1 .- By) .+ ... val( i110 ) .* Bx .* By .* -1 .+ ... val( i111 ) .* Bx .* By; + endfunction function [idx, frac] = cube_idx (x, y, z, v) + idx = zeros (size (v)); frac = zeros (size (v)); idx(:, 2) = lookup (x(2:end-1), v(:, 1)) + 1; @@ -181,5 +190,6 @@ idx(:, 3) = lookup (z(2:end-1), v(:, 3)) + 1; frac(:, 3) = (v(:, 3) - z(idx(:, 3))) ... ./ (z(idx(:, 3)+1) - z(idx(:, 3))); + endfunction
--- a/scripts/plot/draw/private/__marching_cube__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__marching_cube__.m Fri May 20 15:46:45 2016 -0700 @@ -204,10 +204,11 @@ endif endif endfor + endfunction -function p = vertex_interp (isolevel,p1x, p1y, p1z,... - p2x, p2y, p2z,valp1,valp2, col1, col2) +function p = vertex_interp (isolevel, p1x, p1y, p1z, ... + p2x, p2y, p2z,valp1,valp2, col1, col2) if (nargin == 9) p = zeros (length (p1x), 3); @@ -216,7 +217,7 @@ else error ("__marching_cube__: wrong number of arguments"); endif - mu = zeros (length (p1x), 1); + id = abs (valp1-valp2) < (10*eps) .* (abs (valp1) .+ abs (valp2)); if (any (id)) p(id, 1:3) = [ p1x(id), p1y(id), p1z(id) ]; @@ -224,6 +225,8 @@ p(id, 4) = col1(id); endif endif + + mu = zeros (length (p1x), 1); nid = ! id; if (any (nid)) mu(nid) = (isolevel - valp1(nid)) ./ (valp2(nid) - valp1(nid)); @@ -234,9 +237,11 @@ p(nid, 4) = col1(nid) + mu(nid) .* (col2(nid) - col1(nid)); endif endif + endfunction function [edge_table, tri_table] = init_mc () + edge_table = [ 0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, ... 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, ... @@ -528,5 +533,6 @@ 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ] + 1; + endfunction
--- a/scripts/plot/draw/private/__patch__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__patch__.m Fri May 20 15:46:45 2016 -0700 @@ -181,4 +181,6 @@ if (! failed) h = __go_patch__ (p, args{:}); endif + endfunction +
--- a/scripts/plot/draw/private/__pie__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__pie__.m Fri May 20 15:46:45 2016 -0700 @@ -151,6 +151,7 @@ elseif (strcmp (caller, "pie")) axis ([-1.5, 1.5, -1.5, 1.5], "square", "off"); endif + endfunction function update_text_pos (all_handles) @@ -197,5 +198,6 @@ endif endfor endif + endfunction
--- a/scripts/plot/draw/private/__plt__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__plt__.m Fri May 20 15:46:45 2016 -0700 @@ -157,7 +157,8 @@ endfunction -function [hlgnd, tlgnd, setlgnd] = __plt_key__ (h, options, hlgnd, tlgnd, setlgnd) +function [hlgnd, tlgnd, setlgnd] = __plt_key__ (h, options, + hlgnd, tlgnd, setlgnd) n = numel (h); if (numel (options) == 1) options = repmat (options(:), n, 1); @@ -171,6 +172,7 @@ setlgnd = true; endif endfor + endfunction function retval = __plt1__ (h, x1, options, properties = {})
--- a/scripts/plot/draw/private/__quiver__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__quiver__.m Fri May 20 15:46:45 2016 -0700 @@ -411,6 +411,7 @@ endfunction function update_props (h, ~) + kids = get (h, "children"); set (kids([3 2]), {"color", "linestyle", "linewidth"}, @@ -418,5 +419,6 @@ set (kids(2), "visible", get (h, "showarrowhead")); set (kids(1), {"color", "marker", "markerfacecolor", "markersize"}, get (h, {"color", "marker", "markerfacecolor", "markersize"})); + endfunction
--- a/scripts/plot/draw/private/__scatter__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__scatter__.m Fri May 20 15:46:45 2016 -0700 @@ -284,6 +284,7 @@ endfunction function render_size_color (hg, vert, s, c, marker, filled, isflat) + if (isscalar (s)) x = vert(:,1); y = vert(:,2); @@ -342,9 +343,11 @@ marker, filled, isflat); endfor endif + endfunction function update_props (h, d) + lw = get (h, "linewidth"); m = get (h, "marker"); fc = get (h, "markerfacecolor"); @@ -353,10 +356,12 @@ set (kids, "linewidth", lw, "marker", m, "markerfacecolor", fc, "markeredgecolor", ec); + endfunction ## FIXME: This callback routine doesn't handle the case where N > 100. function update_data (h, d) + x = get (h, "xdata"); y = get (h, "ydata"); z = get (h, "zdata");
--- a/scripts/plot/draw/private/__stem__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/private/__stem__.m Fri May 20 15:46:45 2016 -0700 @@ -350,6 +350,7 @@ endfunction function update_xlim (h, ~) + kids = get (h, "children"); xlim = get (h, "xlim"); @@ -361,9 +362,11 @@ endif endif endfor + endfunction function update_baseline (h, ~, src) + visible = get (h, "visible"); if (src == 0) basevalue = get (h, "basevalue"); @@ -385,9 +388,11 @@ endif endif endfor + endfunction function show_baseline (h, ~, hg = []) + if (isempty (hg)) set (get (h, "baseline"), "visible", get (h, "showbaseline")); else @@ -397,9 +402,11 @@ set (get (h, "baseline"), "visible", "on"); endif endif + endfunction function move_baseline (h, ~) + b0 = get (h, "basevalue"); bl = get (h, "baseline"); @@ -411,9 +418,11 @@ ny = length (yt); yt = [b0 * ones(1, ny); yt; NaN(1, ny)](:); set (kids(2), "ydata", yt); + endfunction function update_props (h, ~) + kids = get (h, "children"); set (kids(2), "color", get (h, "color"), "linestyle", get (h, "linestyle"), @@ -422,9 +431,11 @@ "marker", get (h, "marker"), "markerfacecolor", get (h, "markerfacecolor"), "markersize", get (h, "markersize")); + endfunction function update_data (h, ~) + x = get (h, "xdata"); y = get (h, "ydata"); z = get (h, "zdata"); @@ -457,5 +468,6 @@ kids = get (h, "children"); set (kids(2), "xdata", xt, "ydata", yt, "zdata", zt); set (kids(1), "xdata", x, "ydata", y, "zdata", z); + endfunction
--- a/scripts/plot/draw/rectangle.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/rectangle.m Fri May 20 15:46:45 2016 -0700 @@ -80,6 +80,7 @@ if (nargout > 0) h = htmp; endif + endfunction function hg = __rectangle__ (hax, varargin) @@ -175,6 +176,7 @@ addlistener (hg, "linewidth", @update_props); addlistener (hg, "linestyle", @update_props); addlistener (hg, "facecolor", @update_props); + endfunction function update_data (h, ~) @@ -221,13 +223,13 @@ recursion = false; end_unwind_protect endif + endfunction function update_props (h, ~) kids = get (h, "children"); set (kids, {"edgecolor", "linewidth", "linestyle", "facecolor"}, get (h, {"edgecolor", "linewidth", "linestyle", "facecolor"})); - endfunction
--- a/scripts/plot/draw/stairs.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/draw/stairs.m Fri May 20 15:46:45 2016 -0700 @@ -245,6 +245,7 @@ endfunction function update_data (h, ~) + x = get (h, "xdata"); y = get (h, "ydata"); @@ -269,6 +270,7 @@ ys(ridx) = y(2:nr); set (get (h, "children"), "xdata", xs, "ydata", ys); + endfunction
--- a/scripts/plot/util/__actual_axis_position__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/__actual_axis_position__.m Fri May 20 15:46:45 2016 -0700 @@ -82,6 +82,7 @@ else pos = axis_obj.position; endif + endfunction
--- a/scripts/plot/util/__gnuplot_drawnow__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/__gnuplot_drawnow__.m Fri May 20 15:46:45 2016 -0700 @@ -351,6 +351,7 @@ endfunction function term = gnuplot_default_term (plot_stream) + term = lower (getenv ("GNUTERM")); ## If not specified, guess the terminal type. if (isempty (term) || ! __gnuplot_has_terminal__ (term, plot_stream)) @@ -366,6 +367,7 @@ term = "dumb"; endif endif + endfunction function [term, opts] = gnuplot_trim_term (string) @@ -398,7 +400,9 @@ endfunction function retval = have_non_legend_axes (h) + retval = false; + all_axes = findall (h, "type", "axes"); if (! isempty (all_axes)) n_all_axes = numel (all_axes); @@ -409,6 +413,7 @@ retval = (n_all_axes - n_legend_axes) > 1; endif endif + endfunction
--- a/scripts/plot/util/axes.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/axes.m Fri May 20 15:46:45 2016 -0700 @@ -96,6 +96,7 @@ endfunction function restack_axes (h, cf) + show = get (0, "showhiddenhandles"); set (0, "showhiddenhandles", "on"); unwind_protect @@ -106,4 +107,6 @@ unwind_protect_cleanup set (0, "showhiddenhandles", show); end_unwind_protect + endfunction +
--- a/scripts/plot/util/findobj.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/findobj.m Fri May 20 15:46:45 2016 -0700 @@ -284,6 +284,7 @@ h = h(match); h = h(:); + endfunction
--- a/scripts/plot/util/ginput.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/ginput.m Fri May 20 15:46:45 2016 -0700 @@ -136,6 +136,7 @@ endfunction function ginput_keypressfcn (~, evt) + point = get (gca (), "currentpoint"); if (strcmp (evt.Key, "return")) ## Enter key stops ginput. @@ -146,6 +147,7 @@ ginput_accumulator (1, point(1,1), point(1,2), uint8 (character(1))); endif endif + endfunction function ginput_closerequestfcn (hfig, ~, orig_closerequestfcn)
--- a/scripts/plot/util/hdl2struct.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/hdl2struct.m Fri May 20 15:46:45 2016 -0700 @@ -117,14 +117,13 @@ endfunction function hdlist = getspecial (h) - obj = get (h); + ## return handles to special children - fields = fieldnames (obj); hdlist = []; - regkids = get ( h, "children"); + regkids = get (h, "children"); set (0, "showhiddenhandles", "on"); - allkids = get ( h, "children"); + allkids = get (h, "children"); set (0, "showhiddenhandles", "off"); speckids = arrayfun (@(x) ! any (x == regkids), allkids); hdlist = allkids (find (speckids)); @@ -133,8 +132,9 @@ endfunction function prpstr = getprops (h) + obj = get (h); - ## get usefull properties rejecting readonly, children, handles ... + ## get useful properties rejecting readonly, children, handles ... fields = fieldnames (obj); hdlist = [];
--- a/scripts/plot/util/im2frame.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/im2frame.m Fri May 20 15:46:45 2016 -0700 @@ -64,6 +64,7 @@ endif frame = struct ("cdata", x, "colormap", map); + endfunction
--- a/scripts/plot/util/ishghandle.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/ishghandle.m Fri May 20 15:46:45 2016 -0700 @@ -26,8 +26,8 @@ ## @end deftypefn function retval = ishghandle (h) - ## This function is just included for compatibility as Octave has - ## no simulink equivalent. + ## This function is just included for compatibility as + ## Octave has no simulink equivalent. retval = ishandle (h); endfunction
--- a/scripts/plot/util/isprop.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/isprop.m Fri May 20 15:46:45 2016 -0700 @@ -49,6 +49,7 @@ res(i) = true; end_try_catch endfor + endfunction
--- a/scripts/plot/util/linkprop.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/linkprop.m Fri May 20 15:46:45 2016 -0700 @@ -102,6 +102,7 @@ recursion = false; end_unwind_protect endif + endfunction function delete_linkprop (hlist, prop)
--- a/scripts/plot/util/pan.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/pan.m Fri May 20 15:46:45 2016 -0700 @@ -106,14 +106,16 @@ endfunction function update_mouse_mode (hfig, arg) + if (strcmp (arg, "off")) set (hfig, "__mouse_mode__", "none"); else - ## FIXME: Is there a better way other than calling these - ## functions to set the other mouse mode Enable fields to - ## "off"? + ## FIXME: Is there a better way other than calling these functions + ## to set the other mouse mode Enable fields to "off"? rotate3d ("off"); zoom ("off"); set (hfig, "__mouse_mode__", "pan"); endif + endfunction +
--- a/scripts/plot/util/print.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/print.m Fri May 20 15:46:45 2016 -0700 @@ -688,12 +688,15 @@ if (opts.debug) fprintf ("epstool command: '%s'\n", cmd); endif + endfunction function cmd = fig2dev (opts, devopt) + if (nargin < 2) devopt = opts.devopt; endif + dos_shell = (ispc () && ! isunix ()); if (! isempty (opts.fig2dev_binary)) if (dos_shell) @@ -708,14 +711,17 @@ if (opts.debug) fprintf ("fig2dev command: '%s'\n", cmd); endif + endfunction function latex_standalone (opts) + n = find (opts.name == ".", 1, "last"); if (! isempty (n)) opts.name = opts.name(1:n-1); endif latexfile = [opts.name ".tex"]; + switch (opts.devopt) case {"pdflatexstandalone"} packages = "\\usepackage{graphicx,color}"; @@ -727,6 +733,7 @@ packages = "\\usepackage{epsfig,color}"; graphicsfile = [opts.name "-inc.eps"]; endswitch + papersize = sprintf ("\\usepackage[papersize={%.2fbp,%.2fbp},text={%.2fbp,%.2fbp}]{geometry}", fix (opts.canvas_size), fix (opts.canvas_size)); prepend = {"\\documentclass{minimal}"; @@ -735,6 +742,7 @@ "\\begin{document}"; "\\centering"}; postpend = {"\\end{document}"}; + fid = fopen (latexfile, "r"); if (fid >= 0) latex = fscanf (fid, "%c", Inf); @@ -750,6 +758,7 @@ error ("print:erroropeningfile", "print.m: error opening file '%s'", latexfile); endif + fid = fopen (latexfile, "w"); if (fid >= 0) fprintf (fid, "%s\n", prepend{:}); @@ -764,12 +773,15 @@ error ("print:erroropeningfile", "print.m: error opening file '%s'", latexfile); endif + endfunction function cmd = lpr (opts) + if (nargin < 2) devopt = opts.devopt; endif + if (! isempty (opts.lpr_binary)) cmd = opts.lpr_binary; if (! isempty (opts.lpr_options)) @@ -784,12 +796,15 @@ if (opts.debug) fprintf ("lpr command: '%s'\n", cmd); endif + endfunction function cmd = pstoedit (opts, devopt) + if (nargin < 2) devopt = opts.devopt; endif + dos_shell = (ispc () && ! isunix ()); if (! isempty (opts.pstoedit_binary)) if (dos_shell) @@ -804,5 +819,6 @@ if (opts.debug) fprintf ("pstoedit command: '%s'\n", cmd); endif + endfunction
--- a/scripts/plot/util/printd.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/printd.m Fri May 20 15:46:45 2016 -0700 @@ -80,6 +80,7 @@ fclose (pf); delete (tempf); pr_out = sprintf ("%s file %s written\n", opt, filename); + endfunction
--- a/scripts/plot/util/private/__add_default_menu__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/private/__add_default_menu__.m Fri May 20 15:46:45 2016 -0700 @@ -60,6 +60,7 @@ endfunction + function save_cb (h, e) [hcbo, hfig] = gcbo (); lbl = get (hcbo, "label"); @@ -75,6 +76,7 @@ endif endfunction + function __save_as__ (caller) [filename, filedir] = uiputfile ({"*.pdf;*.ps;*.gif;*.png;*.jpg", "Supported Graphic Formats"}, @@ -96,6 +98,7 @@ hax = findobj (fig, "type", "axes", "-not", "tag", "legend"); endfunction + function grid_cb (h, e) hax = __get_axes__ (h); id = get (h, "tag"); @@ -108,12 +111,14 @@ drawnow (); endfunction + function autoscale_cb (h, e) hax = __get_axes__ (h); arrayfun (@(h) axis (h, "auto"), hax); drawnow (); endfunction + function guimode_cb (h, e) [hax, fig] = __get_axes__ (h); id = get (h, "tag"); @@ -135,3 +140,4 @@ arrayfun (@(h) set (h, "mousewheelzoom", 0.0), hax); endswitch endfunction +
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m Fri May 20 15:46:45 2016 -0700 @@ -1701,6 +1701,7 @@ endfunction function x = flip (x) + if (rows (x) == 1) x = fliplr (x); elseif (columns (x) == 1 || ischar (x)) @@ -1708,6 +1709,7 @@ else x = flipud (fliplr (x)); endif + endfunction function spacing_spec = create_spacingspec (f, s, gp_term) @@ -1726,14 +1728,17 @@ endfunction function fontspec = create_fontspec (f, s, gp_term) + if (isempty (f) || strcmp (f, "*") || strcmp (gp_term, "tikz")) fontspec = sprintf ("font \",%d\"", s); else fontspec = sprintf ("font \"%s,%d\"", f, s); endif + endfunction function idx = do_border_2d (obj, plot_stream, idx) + fprintf (plot_stream, "set border 0\n"); if (strcmp (obj.box, "on") || strcmp (obj.xaxislocation, "bottom")) @@ -1771,6 +1776,7 @@ fprintf (plot_stream, "from graph %d,%d,%d ", from); fprintf (plot_stream, "to graph %d,%d,%d\n", to); endfunction + endfunction function [style, ltidx] = do_linestyle_command (obj, linecolor, idx, @@ -1928,6 +1934,7 @@ endfunction function [lt] = gnuplot_linetype (obj) + if (isfield (obj, "linestyle")) if (__gnuplot_has_feature__ ("dashtype")) opt = "dashtype"; @@ -1970,9 +1977,11 @@ else lt = ""; endif + endfunction function [pt, pt2, obj] = gnuplot_pointtype (obj) + if (isfield (obj, "marker")) switch (obj.marker) case "+" @@ -2031,10 +2040,10 @@ else pt = pt2 = ""; endif + endfunction function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) - ## DATA is already transposed. ## Convert NA elements to normal NaN values because fprintf writes @@ -2144,6 +2153,7 @@ obj.zticklabel, obj.zcolor, "z", plot_stream, true, "border", obj.tickdir, ticklength, fontname, fontspec, obj.ticklabelinterpreter, obj.zscale, obj.zsgn, gnuplot_term); + endfunction function do_tics_1 (ticmode, tics, mtics, labelmode, labels, color, ax, @@ -2225,9 +2235,11 @@ else fprintf (plot_stream, "unset m%stics;\n", ax); endif + endfunction function ticklabel = ticklabel_to_cell (ticklabel) + if (ischar (ticklabel)) ticklabel = cellstr (ticklabel); elseif (iscellstr (ticklabel)) @@ -2235,6 +2247,7 @@ else error ("__gnuplot_draw_axes__: unsupported type of ticklabel"); endif + endfunction function colorspec = get_text_colorspec (color) @@ -2242,11 +2255,13 @@ endfunction function [f, s, fnt, it, bld] = get_fontname_and_size (t) + if (isempty (t.fontname) || strcmp (t.fontname, "*")) fnt = ""; else fnt = t.fontname; endif + f = fnt; it = false; bld = false; @@ -2267,15 +2282,16 @@ f = [f "-italic"]; it = true; endif + if (isempty (t.fontsize)) s = 10; else s = t.fontsize; endif + endfunction function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld) - persistent warned_latex = false; if (strcmp (fld, "string")) @@ -2324,6 +2340,7 @@ endif endif endif + endfunction function str = __tex2enhanced__ (str, fnt, it, bld) @@ -2502,11 +2519,13 @@ endfunction function l = length_string (s) + l = length (s) - length (strfind (s,'{')) - length (strfind (s,'}')); m = regexp (s, '/([\w-]+|[\w-]+=\d+)', 'matches'); if (! isempty (m)) l -= sum (cellfun ("length", m)); endif + endfunction function sym = __setup_sym_table__ () @@ -2625,6 +2644,7 @@ endfunction function retval = __do_enhanced_option__ (enhanced, obj) + retval = ""; if (enhanced) if (strcmpi (obj.interpreter, "none")) @@ -2633,18 +2653,24 @@ retval = "enhanced"; endif endif + endfunction function maybe_do_xtick_mirror (plot_stream, axis_obj) + if (! isempty(axis_obj.xtick)) fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n", axis_obj.tickdir); endif + endfunction function maybe_do_x2tick_mirror (plot_stream, axis_obj) + if (! isempty(axis_obj.xtick)) fprintf (plot_stream, "unset xtics; set x2tics %s nomirror\n", axis_obj.tickdir); endif + endfunction +
--- a/scripts/plot/util/private/__gnuplot_open_stream__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/private/__gnuplot_open_stream__.m Fri May 20 15:46:45 2016 -0700 @@ -25,7 +25,9 @@ ## Created: 2009-04-11 function plot_stream = __gnuplot_open_stream__ (npipes, h) + [prog, args] = gnuplot_binary (); + if (npipes > 1) [plot_stream(1), plot_stream(2), pid] = popen2 (prog, args{:}); if (pid < 0) @@ -39,8 +41,10 @@ error ("__gnuplot_open_stream__: failed to open connection to gnuplot"); endif endif + if (nargin > 1) set (h, "__plot_stream__", plot_stream); endif + endfunction
--- a/scripts/plot/util/private/__gnuplot_print__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/private/__gnuplot_print__.m Fri May 20 15:46:45 2016 -0700 @@ -198,7 +198,9 @@ endfunction + function eps_drawnow (opts, epsfile, gp_opts) + [h, fontsize] = get_figure_text_objs (opts); unwind_protect fontsize_2x = cellfun (@times, {2}, fontsize, "uniformoutput", false); @@ -207,9 +209,12 @@ unwind_protect_cleanup set (h, {"fontsize"}, fontsize); end_unwind_protect + endfunction + function local_drawnow (term, file, opts) + set (0, "currentfigure", opts.figure); if (isempty (opts.debug_file) || ! opts.debug) drawnow (term, file); @@ -219,8 +224,10 @@ if (opts.debug) fprintf ("Expanded gnuplot terminal = '%s'\n", term); endif + endfunction + function f = font_spec (opts, varargin) for n = 1:2:numel (varargin) opts.(varargin{n}) = varargin{n+1}; @@ -326,9 +333,12 @@ f = sprintf ("fontsize %d", opts.fontsize); endif endswitch + endfunction + function [h, fontsize] = get_figure_text_objs (opts) + h = findall (opts.figure, "-property", "fontsize"); hp = get (h, "parent"); if (iscell (hp)) @@ -348,5 +358,6 @@ case 1 fontsize = {fontsize}; endswitch + endfunction
--- a/scripts/plot/util/private/__print_parse_opts__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/private/__print_parse_opts__.m Fri May 20 15:46:45 2016 -0700 @@ -452,6 +452,7 @@ %! assert (opts.figure, 5); function cmd = __quote_path__ (cmd) + if (! isempty (cmd)) is_quoted = all (cmd([1, end]) == "'"); if (! is_quoted) @@ -464,8 +465,10 @@ endif endif endif + endfunction + function gs = __ghostscript_binary__ () persistent ghostscript_binary = "" @@ -609,6 +612,7 @@ endfunction function value = convert2points (value, units) + switch (units) case "inches" value *= 72; @@ -618,6 +622,7 @@ error ("print:customnormalized", "print.m: papersize=='<custom>' and paperunits='normalized' may not be combined"); endswitch + endfunction function device_list = gs_device_list ();
--- a/scripts/plot/util/refreshdata.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/refreshdata.m Fri May 20 15:46:45 2016 -0700 @@ -101,6 +101,7 @@ set (h(i), pdname, val); endfor endfor + endfunction
--- a/scripts/plot/util/rotate3d.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/rotate3d.m Fri May 20 15:46:45 2016 -0700 @@ -95,6 +95,7 @@ endfunction function update_mouse_mode (hfig, arg) + if (strcmp (arg, "off")) set (hfig, "__mouse_mode__", "none"); else @@ -105,4 +106,6 @@ zoom ("off"); set (hfig, "__mouse_mode__", "rotate"); endif + endfunction +
--- a/scripts/plot/util/struct2hdl.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/struct2hdl.m Fri May 20 15:46:45 2016 -0700 @@ -177,8 +177,9 @@ endfunction function [h, sout] = createaxes (s, p, par) - ## regular axes + if (! any (strcmpi (s.properties.tag, {"colorbar", "legend"}))) + ## regular axes propval = {"position", s.properties.position}; hid = {"autopos_tag", "looseinset"}; for ii = 1:numel (hid) @@ -283,7 +284,9 @@ error ("hdl2struct: didn't find an object"); endif endif + sout = s; + endfunction function h = createline (s, par) @@ -292,6 +295,7 @@ endfunction function [h, sout] = createpatch (s, par) + prp.faces = s.properties.faces; prp.vertices = s.properties.vertices; prp.facevertexcdata = s.properties.facevertexcdata; @@ -305,6 +309,7 @@ s.properties = rmfield (s.properties, {"xdata", "ydata", "zdata", "cdata"}); addmissingprops (h, s.properties); sout = s; + endfunction function h = createtext (s, par) @@ -357,11 +362,14 @@ addmissingprops (h, s.properties); s.special = []; endif + sout = s; pout = p; + endfunction function [h, sout, pout] = createhg_hilev (s, p, par) + fields = s.properties; if (isfield (fields, "contourmatrix")) ## contours @@ -547,11 +555,14 @@ addmissingprops (h, s.properties); s.special = []; # children will be treated as normal children endif + sout = s; pout = p; + endfunction function setprops (s, h, p, hilev) + if (! any (strcmpi (s.properties.tag, {"colorbar", "legend"}))) specs = s.children(s.special); if (isempty (specs)) @@ -624,14 +635,17 @@ endfunction function out = valcomp (x, hdls) + if (isfloat (x) && isscalar (x)) out = any (x == hdls); else out = 0; endif + endfunction function addmissingprops (h, props) + hid = {"autopos_tag", "looseinset"}; oldfields = fieldnames (props); curfields = fieldnames (get (h)); @@ -643,6 +657,7 @@ addproperty (prop, h, "any"); endif endfor + endfunction
--- a/scripts/plot/util/subplot.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/subplot.m Fri May 20 15:46:45 2016 -0700 @@ -368,6 +368,7 @@ function subplot_align (h, d, rmupdate = false) persistent updating = false; + if (! updating) if (rmupdate) ## The "position" property has been changed from outside this routine.
--- a/scripts/plot/util/zoom.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/plot/util/zoom.m Fri May 20 15:46:45 2016 -0700 @@ -163,16 +163,17 @@ endfunction function update_mouse_mode (hfig, arg) + if (strcmp (arg, "off")) set (hfig, "__mouse_mode__", "none"); else - ## FIXME: Is there a better way other than calling these - ## functions to set the other mouse mode Enable fields to - ## "off"? + ## FIXME: Is there a better way other than calling these functions + ## to set the other mouse mode Enable fields to "off"? pan ("off"); rotate3d ("off"); set (hfig, "__mouse_mode__", "zoom"); endif + endfunction
--- a/scripts/polynomial/polyout.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/polynomial/polyout.m Fri May 20 15:46:45 2016 -0700 @@ -89,6 +89,7 @@ endfunction function str = coeff (c) + if (imag (c)) if (real (c)) str = sprintf ("(%s)", num2str (c, 5)); @@ -98,6 +99,7 @@ else str = num2str (c, 5); endif + endfunction
--- a/scripts/polynomial/ppder.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/polynomial/ppder.m Fri May 20 15:46:45 2016 -0700 @@ -49,6 +49,7 @@ endif ppd = mkpp (x, pd, d); + endfunction
--- a/scripts/polynomial/ppint.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/polynomial/ppint.m Fri May 20 15:46:45 2016 -0700 @@ -26,6 +26,7 @@ ## @end deftypefn function ppi = ppint (pp, c) + if (nargin < 1 || nargin > 2) print_usage (); endif
--- a/scripts/polynomial/ppjumps.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/polynomial/ppjumps.m Fri May 20 15:46:45 2016 -0700 @@ -26,6 +26,7 @@ ## @end deftypefn function jumps = ppjumps (pp) + if (nargin != 1) print_usage (); endif @@ -56,6 +57,7 @@ rlim = shiftdim (ppval (pp, x(2:end-1)), nd - 1); jumps = shiftdim (rlim - llim, 1); + endfunction
--- a/scripts/polynomial/splinefit.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/polynomial/splinefit.m Fri May 20 15:46:45 2016 -0700 @@ -94,6 +94,7 @@ ## @end deftypefn function pp = splinefit (x, y, breaks, varargin) + if (nargin > 3) n = cellfun ("isclass", varargin, "char"); varargin(n) = lower (varargin(n)); @@ -105,6 +106,7 @@ else props = struct (); endif + fields = fieldnames (props); for f = 1:numel (fields) if (! any (strcmp (fields{f}, @@ -113,6 +115,7 @@ "unrecognized property '%s'", fields{f}); endif endfor + args = {}; if (isfield (props, "periodic") && props.periodic) args{end+1} = "p"; @@ -142,7 +145,9 @@ elseif (! isnumeric (breaks) || ! isvector (breaks)) print_usage (); endif + pp = __splinefit__ (x, y, breaks, args{:}); + endfunction
--- a/scripts/signal/detrend.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/signal/detrend.m Fri May 20 15:46:45 2016 -0700 @@ -38,7 +38,7 @@ ## Adapted-By: jwe function y = detrend (x, p = 1) - ## Check input + if (nargin > 0 && isreal (x) && ndims (x) <= 2) ## Check p if (ischar (p) && strcmpi (p, "constant"))
--- a/scripts/signal/filter2.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/signal/filter2.m Fri May 20 15:46:45 2016 -0700 @@ -55,5 +55,6 @@ [nr, nc] = size (b); y = conv2 (x, b(nr:-1:1, nc:-1:1), shape); + endfunction
--- a/scripts/sparse/bicgstab.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/bicgstab.m Fri May 20 15:46:45 2016 -0700 @@ -72,133 +72,131 @@ function [x, flag, relres, iter, resvec] = bicgstab (A, b, tol, maxit, M1, M2, x0) - if (nargin >= 2 && nargin <= 7 && isvector (full (b))) + if (nargin < 2 || nargin > 7 || ! isvector (full (b))) + print_usage (); + endif + + if (ischar (A)) + A = str2func (A); + elseif (isnumeric(A) && issquare (A)) + Ax = @(x) A * x; + elseif (isa (A, "function_handle")) + Ax = @(x) feval (A, x); + else + error ("bicgstab: A must be a square matrix or function"); + endif - if (ischar (A)) - A = str2func (A); - elseif (isnumeric(A) && issquare (A)) - Ax = @(x) A * x; - elseif (isa (A, "function_handle")) - Ax = @(x) feval (A, x); - else - error ("bicgstab: A must be a square matrix or function"); - endif + if (nargin < 3 || isempty (tol)) + tol = 1e-6; + endif + + if (nargin < 4 || isempty (maxit)) + maxit = min (rows (b), 20); + endif - if (nargin < 3 || isempty (tol)) - tol = 1e-6; - endif - - if (nargin < 4 || isempty (maxit)) - maxit = min (rows (b), 20); - endif + if (nargin < 5 || isempty (M1)) + M1m1x = @(x) x; + elseif (ischar (M1)) + M1m1x = str2func (M1); + elseif (isnumeric(M1) && ismatrix (M1)) + M1m1x = @(x) M1 \ x; + elseif (isa (M1, "function_handle")) + M1m1x = @(x) feval (M1, x); + else + error ("bicgstab: preconditioner M1 must be a function or matrix"); + endif - if (nargin < 5 || isempty (M1)) - M1m1x = @(x) x; - elseif (ischar (M1)) - M1m1x = str2func (M1); - elseif (isnumeric(M1) && ismatrix (M1)) - M1m1x = @(x) M1 \ x; - elseif (isa (M1, "function_handle")) - M1m1x = @(x) feval (M1, x); - else - error ("bicgstab: preconditioner M1 must be a function or matrix"); - endif + if (nargin < 6 || isempty (M2)) + M2m1x = @(x) x; + elseif (ischar (M2)) + M2m1x = str2func (M2); + elseif (isnumeric(M2) && ismatrix (M2)) + M2m1x = @(x) M2 \ x; + elseif (isa (M2, "function_handle")) + M2m1x = @(x) feval (M2, x); + else + error ("bicgstab: preconditioner M2 must be a function or matrix"); + endif + + precon = @(x) M2m1x (M1m1x (x)); + + if (nargin < 7 || isempty (x0)) + x0 = zeros (size (b)); + endif - if (nargin < 6 || isempty (M2)) - M2m1x = @(x) x; - elseif (ischar (M2)) - M2m1x = str2func (M2); - elseif (isnumeric(M2) && ismatrix (M2)) - M2m1x = @(x) M2 \ x; - elseif (isa (M2, "function_handle")) - M2m1x = @(x) feval (M2, x); - else - error ("bicgstab: preconditioner M2 must be a function or matrix"); - endif + ## specifies initial estimate x0 + if (nargin < 7) + x = zeros (rows (b), 1); + else + x = x0; + endif + + norm_b = norm (b); + + res = b - Ax (x); + rr = res; - precon = @(x) M2m1x (M1m1x (x)); + ## Vector of the residual norms for each iteration. + resvec = norm (res) / norm_b; - if (nargin < 7 || isempty (x0)) - x0 = zeros (size (b)); - endif + ## Default behavior we don't reach tolerance tol within maxit iterations. + flag = 1; - ## specifies initial estimate x0 - if (nargin < 7) - x = zeros (rows (b), 1); + for iter = 1:maxit + rho_1 = rr' * res; + + if (iter == 1) + p = res; else - x = x0; + beta = (rho_1 / rho_2) * (alpha / omega); + p = res + beta * (p - omega * v); endif - norm_b = norm (b); - - res = b - Ax (x); - rr = res; + phat = precon (p); - ## Vector of the residual norms for each iteration. - resvec = norm (res) / norm_b; + v = Ax (phat); + alpha = rho_1 / (rr' * v); + s = res - alpha * v; - ## Default behavior we don't reach tolerance tol within maxit iterations. - flag = 1; - - for iter = 1:maxit - rho_1 = rr' * res; + shat = precon (s); - if (iter == 1) - p = res; - else - beta = (rho_1 / rho_2) * (alpha / omega); - p = res + beta * (p - omega * v); - endif - - phat = precon (p); + t = Ax (shat); + omega = (s' * t) / (t' * t); + x += alpha * phat + omega * shat; + res = s - omega * t; + rho_2 = rho_1; - v = Ax (phat); - alpha = rho_1 / (rr' * v); - s = res - alpha * v; - - shat = precon (s); - - t = Ax (shat); - omega = (s' * t) / (t' * t); - x += alpha * phat + omega * shat; - res = s - omega * t; - rho_2 = rho_1; + relres = norm (res) / norm_b; + resvec = [resvec; relres]; - relres = norm (res) / norm_b; - resvec = [resvec; relres]; - - if (relres <= tol) - ## We reach tolerance tol within maxit iterations. - flag = 0; - break; - elseif (resvec(end) == resvec(end - 1)) - ## The method stagnates. - flag = 3; - break; - endif - endfor + if (relres <= tol) + ## We reach tolerance tol within maxit iterations. + flag = 0; + break; + elseif (resvec(end) == resvec(end - 1)) + ## The method stagnates. + flag = 3; + break; + endif + endfor - if (nargout < 2) - if (flag == 0) - printf ("bicgstab converged at iteration %i ", iter); - printf ("to a solution with relative residual %e\n", relres); - elseif (flag == 3) - printf ("bicgstab stopped at iteration %i ", iter); - printf ("without converging to the desired tolerance %e\n", tol); - printf ("because the method stagnated.\n"); - printf ("The iterate returned (number %i) ", iter); - printf ("has relative residual %e\n", relres); - else - printf ("bicgstab stopped at iteration %i ", iter); - printf ("without converging to the desired toleranc %e\n", tol); - printf ("because the maximum number of iterations was reached.\n"); - printf ("The iterate returned (number %i) ", iter); - printf ("has relative residual %e\n", relres); - endif + if (nargout < 2) + if (flag == 0) + printf ("bicgstab converged at iteration %i ", iter); + printf ("to a solution with relative residual %e\n", relres); + elseif (flag == 3) + printf ("bicgstab stopped at iteration %i ", iter); + printf ("without converging to the desired tolerance %e\n", tol); + printf ("because the method stagnated.\n"); + printf ("The iterate returned (number %i) ", iter); + printf ("has relative residual %e\n", relres); + else + printf ("bicgstab stopped at iteration %i ", iter); + printf ("without converging to the desired toleranc %e\n", tol); + printf ("because the maximum number of iterations was reached.\n"); + printf ("The iterate returned (number %i) ", iter); + printf ("has relative residual %e\n", relres); endif - - else - print_usage (); endif endfunction @@ -249,3 +247,4 @@ %! b = A * [1; 1]; %! [x, flag, relres, iter, resvec] = bicgstab (A, b); %! assert (x, [1; 1], 1e-6); +
--- a/scripts/sparse/colperm.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/colperm.m Fri May 20 15:46:45 2016 -0700 @@ -35,6 +35,7 @@ [i, j] = find (s); idx = find (diff ([j; Inf]) != 0); - [dummy, p] = sort (idx - [0; idx(1:(end-1))]); + [~, p] = sort (idx - [0; idx(1:(end-1))]); + endfunction
--- a/scripts/sparse/etreeplot.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/etreeplot.m Fri May 20 15:46:45 2016 -0700 @@ -34,5 +34,6 @@ endif treeplot (etree (A+A'), varargin{:}); + endfunction
--- a/scripts/sparse/pcg.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/pcg.m Fri May 20 15:46:45 2016 -0700 @@ -385,6 +385,7 @@ warning ("pcg: matrix not positive definite?\n"); endif endif + endfunction
--- a/scripts/sparse/qmr.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/qmr.m Fri May 20 15:46:45 2016 -0700 @@ -263,6 +263,7 @@ else print usage(); endif + endfunction
--- a/scripts/sparse/spaugment.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/spaugment.m Fri May 20 15:46:45 2016 -0700 @@ -75,6 +75,7 @@ ## @end deftypefn function s = spaugment (A, c) + if (nargin < 2) if (issparse (A)) c = max (max (abs (A))) / 1000; @@ -91,6 +92,7 @@ [m, n] = size (A); s = [ c * speye(m, m), A; A', sparse(n, n)]; + endfunction
--- a/scripts/sparse/speye.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/speye.m Fri May 20 15:46:45 2016 -0700 @@ -32,6 +32,7 @@ ## @end deftypefn function s = speye (m, n) + if (nargin == 1) if (isvector (m) && length (m) == 2) n = m(2); @@ -49,6 +50,7 @@ lo = min ([m, n]); s = sparse (1:lo, 1:lo, 1, m, n); + endfunction
--- a/scripts/sparse/treelayout.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/sparse/treelayout.m Fri May 20 15:46:45 2016 -0700 @@ -30,178 +30,181 @@ ## @seealso{etreeplot, gplot, treeplot} ## @end deftypefn -function [x_coordinate, y_coordinate, height, s] = treelayout (tree, permutation) +function [x_coordinate, y_coordinate, height, s] = ... + treelayout (tree, permutation) + if (nargin < 1 || nargin > 2 || nargout > 4) print_usage (); elseif (! isvector (tree) || rows (tree) != 1 || ! isnumeric (tree) || any (tree > length (tree)) || any (tree < 0)) error ("treelayout: the first input argument must be a vector of predecessors"); - else - ## Make it a row vector. - tree = tree(:)'; + endif + + ## Make it a row vector. + tree = tree(:)'; + + ## The count of nodes of the graph. + num_nodes = length (tree); + ## The number of children. + num_children = zeros (1, num_nodes + 1); - ## The count of nodes of the graph. - num_nodes = length (tree); - ## The number of children. - num_children = zeros (1, num_nodes + 1); + ## Checking vector of predecessors. + for i = 1 : num_nodes + if (tree(i) < i) + ## This part of graph was checked before. + continue; + endif - ## Checking vector of predecessors. - for i = 1 : num_nodes - if (tree(i) < i) + ## Try to find cicle in this part of graph using modified Floyd's + ## cycle-finding algorithm. + tortoise = tree(i); + hare = tree(tortoise); + + while (tortoise != hare) + ## End after finding a cicle or reaching a checked part of graph. + + if (hare < i) ## This part of graph was checked before. - continue; + break endif - ## Try to find cicle in this part of graph using modified Floyd's - ## cycle-finding algorithm. - tortoise = tree(i); - hare = tree(tortoise); - - while (tortoise != hare) - ## End after finding a cicle or reaching a checked part of graph. - - if (hare < i) - ## This part of graph was checked before. - break - endif - - tortoise = tree(tortoise); - ## Hare will move faster than tortoise so in cicle hare must - ## reach tortoise. - hare = tree(tree(hare)); - - endwhile - - if (tortoise == hare) - ## If hare reach tortoise we found circle. - error ("treelayout: vector of predecessors has bad format"); - endif + tortoise = tree(tortoise); + ## Hare will move faster than tortoise so in cicle hare must + ## reach tortoise. + hare = tree(tree(hare)); - endfor - ## Vector of predecessors has right format. - - for i = 1:num_nodes - ## vec_of_child is helping vector which is used to speed up the - ## choice of descendant nodes. - - num_children(tree(i)+1) = num_children(tree(i)+1) + 1; - endfor + endwhile - pos = 1; - start = zeros (1, num_nodes+1); - xhelp = zeros (1, num_nodes+1); - stop = zeros (1, num_nodes+1); - for i = 1 : num_nodes + 1 - start(i) = pos; - xhelp(i) = pos; - pos += num_children(i); - stop(i) = pos; - endfor - - if (nargin == 1) - for i = 1:num_nodes - vec_of_child(xhelp(tree(i)+1)) = i; - xhelp(tree(i)+1) = xhelp(tree(i)+1) + 1; - endfor - else - vec_of_child = permutation; + if (tortoise == hare) + ## If hare reach tortoise we found circle. + error ("treelayout: vector of predecessors has bad format"); endif - ## The number of "parent" (actual) node (it's descendants will be - ## browse in the next iteration). - par_number = 0; + endfor + ## Vector of predecessors has right format. + + for i = 1:num_nodes + ## vec_of_child is helping vector which is used to speed up the + ## choice of descendant nodes. + + num_children(tree(i)+1) = num_children(tree(i)+1) + 1; + endfor + + pos = 1; + start = zeros (1, num_nodes+1); + xhelp = zeros (1, num_nodes+1); + stop = zeros (1, num_nodes+1); + for i = 1 : num_nodes + 1 + start(i) = pos; + xhelp(i) = pos; + pos += num_children(i); + stop(i) = pos; + endfor - ## The x-coordinate of the left most descendant of "parent node" - ## this value is increased in each leaf. - left_most = 0; + if (nargin == 1) + for i = 1:num_nodes + vec_of_child(xhelp(tree(i)+1)) = i; + xhelp(tree(i)+1) = xhelp(tree(i)+1) + 1; + endfor + else + vec_of_child = permutation; + endif - ## The level of "parent" node (root level is num_nodes). - level = num_nodes; + ## The number of "parent" (actual) node (it's descendants will be + ## browse in the next iteration). + par_number = 0; - ## num_nodes - max_ht is the height of this graph. - max_ht = num_nodes; + ## The x-coordinate of the left most descendant of "parent node" + ## this value is increased in each leaf. + left_most = 0; + + ## The level of "parent" node (root level is num_nodes). + level = num_nodes; + + ## num_nodes - max_ht is the height of this graph. + max_ht = num_nodes; - ## Main stack - each item consists of two numbers - the number of - ## node and the number it's of parent node on the top of stack - ## there is "parent node". - stk = [-1, 0]; + ## Main stack - each item consists of two numbers - the number of + ## node and the number it's of parent node on the top of stack + ## there is "parent node". + stk = [-1, 0]; + + ## Number of vertices s in the top-level separator. + s = 0; + ## Flag which says if we are in top level separator. + top_level = 1; + ## The top of the stack. + while (par_number != -1) + if (start(par_number+1) < stop(par_number+1)) + idx = vec_of_child(start(par_number+1) : stop(par_number+1) - 1); + else + idx = zeros (1, 0); + endif + + ## Add to idx the vector of parent descendants. + stk = [stk; [idx', ones(fliplr(size(idx))) * par_number]]; - ## Number of vertices s in the top-level separator. - s = 0; - ## Flag which says if we are in top level separator. - top_level = 1; - ## The top of the stack. - while (par_number != -1) - if (start(par_number+1) < stop(par_number+1)) - idx = vec_of_child(start(par_number+1) : stop(par_number+1) - 1); - else - idx = zeros (1, 0); + ## We are in top level separator when we have one child and the + ## flag is 1 + if (columns (idx) == 1 && top_level == 1) + s += 1; + else + ## We aren't in top level separator now. + top_level = 0; + endif + ## If there is not any descendant of "parent node": + if (stk(end,2) != par_number) + left_most += 1; + x_coordinate_r(par_number) = left_most; + max_ht = min (max_ht, level); + if (length (stk) > 1 && find ((shift (stk,1) - stk) == 0) > 1 + && stk(end,2) != stk(end-1,2)) + ## Return to the nearest branching the position to return + ## position is the position on the stack, where should be + ## started further search (there are two nodes which has the + ## same parent node). + + position = (find ((shift (stk(:,2), 1) - stk(:,2)) == 0))(end) + 1; + par_number_vec = stk(position:end,2); + + ## The vector of removed nodes (the content of stack form + ## position to end). + + level += length (par_number_vec); + + ## The level have to be decreased. + + x_coordinate_r(par_number_vec) = left_most; + stk(position:end,:) = []; endif - ## Add to idx the vector of parent descendants. - stk = [stk; [idx', ones(fliplr(size(idx))) * par_number]]; - - ## We are in top level separator when we have one child and the - ## flag is 1 - if (columns (idx) == 1 && top_level == 1) - s += 1; - else - ## We aren't in top level separator now. - top_level = 0; - endif - ## If there is not any descendant of "parent node": - if (stk(end,2) != par_number) - left_most += 1; - x_coordinate_r(par_number) = left_most; - max_ht = min (max_ht, level); - if (length (stk) > 1 && find ((shift (stk,1) - stk) == 0) > 1 - && stk(end,2) != stk(end-1,2)) - ## Return to the nearest branching the position to return - ## position is the position on the stack, where should be - ## started further search (there are two nodes which has the - ## same parent node). - - position = (find ((shift (stk(:,2), 1) - stk(:,2)) == 0))(end) + 1; - par_number_vec = stk(position:end,2); + ## Remove the next node from "searched branch". - ## The vector of removed nodes (the content of stack form - ## position to end). - - level += length (par_number_vec); - - ## The level have to be decreased. - - x_coordinate_r(par_number_vec) = left_most; - stk(position:end,:) = []; - endif - - ## Remove the next node from "searched branch". - - stk(end,:) = []; - ## Choose new "parent node". - par_number = stk(end,1); - ## If there is another branch start to search it. - if (par_number != -1) - y_coordinate(par_number) = level; - x_coordinate_l(par_number) = left_most + 1; - endif - else - - ## There were descendants of "parent nod" choose the last of - ## them and go on through it. - level -= 1; - par_number = stk(end,1); + stk(end,:) = []; + ## Choose new "parent node". + par_number = stk(end,1); + ## If there is another branch start to search it. + if (par_number != -1) y_coordinate(par_number) = level; x_coordinate_l(par_number) = left_most + 1; endif - endwhile + else - ## Calculate the x coordinates (the known values are the position - ## of most left and most right descendants). - x_coordinate = (x_coordinate_l + x_coordinate_r) / 2; + ## There were descendants of "parent nod" choose the last of + ## them and go on through it. + level -= 1; + par_number = stk(end,1); + y_coordinate(par_number) = level; + x_coordinate_l(par_number) = left_most + 1; + endif + endwhile - height = num_nodes - max_ht - 1; - endif + ## Calculate the x coordinates (the known values are the position + ## of most left and most right descendants). + x_coordinate = (x_coordinate_l + x_coordinate_r) / 2; + + height = num_nodes - max_ht - 1; + endfunction
--- a/scripts/specfun/expint.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/specfun/expint.m Fri May 20 15:46:45 2016 -0700 @@ -152,6 +152,7 @@ endif; endif endfor + endfunction
--- a/scripts/specfun/isprime.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/specfun/isprime.m Fri May 20 15:46:45 2016 -0700 @@ -131,6 +131,7 @@ endfunction function t = isgaussianprime (z) + ## Assume prime unless proven otherwise t = true (size (z)); @@ -149,6 +150,7 @@ zidx = ! (xidx | yidx); # Skip entries that were already evaluated zabs = x(zidx).^2 + y(zidx).^2; t(zidx) &= isprime (zabs); + endfunction
--- a/scripts/statistics/base/lscov.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/statistics/base/lscov.m Fri May 20 15:46:45 2016 -0700 @@ -111,6 +111,7 @@ endfor endif endif + endfunction
--- a/scripts/statistics/base/mode.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/statistics/base/mode.m Fri May 20 15:46:45 2016 -0700 @@ -103,6 +103,7 @@ c{i} = xs(t2(:, i) == f(i), i); m(i) = c{i}(1); endfor + endfunction
--- a/scripts/statistics/distributions/binoinv.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/statistics/distributions/binoinv.m Fri May 20 15:46:45 2016 -0700 @@ -79,6 +79,7 @@ ## Compute CDF in batches of doubling size until CDF > x, or answer > 500 ## Return the locations of unfinished cases in k. function [m, k] = scalar_binoinv (x, n, p) + k = 1:length (x); m = zeros (size (x)); prev_limit = 0; @@ -104,6 +105,7 @@ ## Return the locations of unfinished cases in k. ## Calculates CDF by summing PDF, which is faster than calls to binocdf. function [m, k] = vector_binoinv (x, n, p) + k = 1:length(x); m = zeros (size (x)); prev_limit = 0; @@ -135,6 +137,7 @@ ## but care must be taken to handle both scalar and vector n, p. Bookkeeping ## may cost more than the extra computations. function m = bin_search_binoinv (x, n, p) + k = 1:length (x); lower = zeros (size (x)); limit = 500; # lower bound on point at which prev phase finished @@ -155,6 +158,7 @@ endfor m = ceil (lower); m(x > binocdf (m(:), n, p)) += 1; # fix off-by-one errors from binary search + endfunction
--- a/scripts/statistics/distributions/nbininv.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/statistics/distributions/nbininv.m Fri May 20 15:46:45 2016 -0700 @@ -83,6 +83,7 @@ ## Compute CDF in batches of doubling size until CDF > x, or answer > 500. ## Return the locations of unfinished cases in k. function [m, k] = scalar_nbininv (x, n, p) + k = 1:length (x); m = zeros (size (x)); prev_limit = 0; @@ -107,6 +108,7 @@ ## but care must be taken to handle both scalar and vector n,p. Bookkeeping ## may cost more than the extra computations. function m = bin_search_nbininv (x, n, p) + k = 1:length (x); lower = zeros (size (x)); limit = 1;
--- a/scripts/statistics/distributions/poissinv.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/statistics/distributions/poissinv.m Fri May 20 15:46:45 2016 -0700 @@ -105,6 +105,7 @@ ## http://www.gnu.org/licenses/gpl.html function inv = analytic_approx (x, lambda) + s = norminv (x, 0, 1) ./ sqrt (lambda); k = (s > -0.6833501) & (s < 1.777993); ## use polynomial approximations in central region
--- a/scripts/testfun/__have_feature__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/__have_feature__.m Fri May 20 15:46:45 2016 -0700 @@ -22,11 +22,13 @@ ## @end deftypefn function retval = __have_feature__ (feature) + if (strncmp (feature, "ENABLE_", 7)) features = __octave_config_info__ (); else features = __octave_config_info__ ("build_features"); endif + if (iscellstr (feature)) retval = (all (isfield (features, feature)) && cellfun (@(x) features.(x), feature)); @@ -35,6 +37,7 @@ else retval = false; endif + endfunction
--- a/scripts/testfun/__printf_assert__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/__printf_assert__.m Fri May 20 15:46:45 2016 -0700 @@ -23,7 +23,9 @@ function __printf_assert__ (varargin) global _assert_printf = ""; + _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); + endfunction
--- a/scripts/testfun/__prog_output_assert__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/__prog_output_assert__.m Fri May 20 15:46:45 2016 -0700 @@ -23,6 +23,7 @@ function ret = __prog_output_assert__ (str) global _assert_printf = ""; + if (isempty (_assert_printf)) ret = isempty (str); elseif (_assert_printf(end) == "\n") @@ -30,7 +31,9 @@ else ret = strcmp (_assert_printf, str); endif + _assert_printf = ""; + endfunction
--- a/scripts/testfun/__run_test_suite__.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/__run_test_suite__.m Fri May 20 15:46:45 2016 -0700 @@ -134,6 +134,7 @@ endfunction function print_pass_fail (p, n, xf, sk) + if ((n + sk) > 0) printf (" PASS %4d/%-4d", p, n); nfail = n - p - xf; @@ -148,43 +149,48 @@ endif endif puts ("\n"); + endfunction function retval = has_functions (f) + n = length (f); if (n > 3 && strcmpi (f((end-2):end), ".cc")) fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char")'; - fclose (fid); - retval = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\>', - 'lineanchors', 'once')); - else + if (fid < 0) error ("__run_test_suite__: fopen failed: %s", f); endif + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\>', + 'lineanchors', 'once')); elseif (n > 2 && strcmpi (f((end-1):end), ".m")) retval = true; else retval = false; endif + endfunction function retval = has_tests (f) + fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char")'; - fclose (fid); - retval = ! isempty (regexp (str, - '^%!(assert|error|fail|test|xtest|warning)', - 'lineanchors', 'once')); - else + if (fid < 0) error ("__run_test_suite__: fopen failed: %s", f); endif + + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str, + '^%!(assert|error|fail|test|xtest|warning)', + 'lineanchors', 'once')); + endfunction function [dp, dn, dxf, dsk] = run_test_dir (fid, d); global files_with_tests; global files_with_no_tests; + lst = dir (d); dp = dn = dxf = dsk = 0; for i = 1:length (lst) @@ -198,6 +204,7 @@ dsk += sk; endif endfor + saved_dir = pwd (); unwind_protect cd (d); @@ -223,6 +230,7 @@ unwind_protect_cleanup cd (saved_dir); end_unwind_protect + endfunction function [dp, dn, dxf, dsk] = run_test_script (fid, d); @@ -230,6 +238,7 @@ global files_with_no_tests; global topsrcdir; global topbuilddir; + lst = dir (d); dp = dn = dxf = dsk = 0; for i = 1:length (lst) @@ -242,6 +251,7 @@ dsk += sk; endif endfor + for i = 1:length (lst) nm = lst(i).name; ## Ignore hidden files @@ -274,6 +284,7 @@ endif endfor ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); + endfunction function n = num_elts_matching_pattern (lst, pat)
--- a/scripts/testfun/demo.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/demo.m Fri May 20 15:46:45 2016 -0700 @@ -152,8 +152,9 @@ endfunction function clear_figures () - ## Prevent proliferation of figure windows. If any figure windows - ## exist, close all but one and clear the one remaining. + + ## Prevent proliferation of figure windows. If any figure windows exist, + ## close all but one and clear the one remaining. figs = __go_figure_handles__ (); if (! isempty (figs)) if (numel (figs) > 1) @@ -163,8 +164,10 @@ endif clf ("reset"); endif + endfunction + %!demo %! t = 0:0.01:2*pi; %! x = sin (t);
--- a/scripts/testfun/private/compare_plot_demos.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/private/compare_plot_demos.m Fri May 20 15:46:45 2016 -0700 @@ -108,6 +108,7 @@ unwind_protect_cleanup rmpath (cwd); end_unwind_protect + if (! strcmp (arg.toolkits, "matlab")) ## Generate the html comparison of the images html_compare_plot_demos (arg.toolkits); @@ -116,5 +117,6 @@ printf ('\nNow run %s in Matlab.\nAfter this run html_compare_plot_demos,\n', arg.fcn_file); printf ('for example html_compare_plot_demos ({"fltk", "gnuplot", "matlab"}), to create the html page.\n'); endif + endfunction
--- a/scripts/testfun/private/dump_demos.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/private/dump_demos.m Fri May 20 15:46:45 2016 -0700 @@ -95,9 +95,11 @@ ## Close script fclose (fid); + endfunction function dump_all_demos (directory, fid, fmt) + dirinfo = dir (fullfile (directory, "*.m")); flist = {dirinfo.name}; ## Remove uigetdir, uigetfile, uiputfile, etc. @@ -147,9 +149,11 @@ endfor endfor fprintf (fid, "close all\n"); + endfunction function retval = get_demos (fcn) + [code, idx] = test (fcn, "grabdemo"); num_demos = length (idx) - 1; retval = cell (1, num_demos); @@ -157,9 +161,11 @@ for k = 1:num_demos retval{k} = oct2mat (code(idx(k):idx(k+1)-1)); endfor + endfunction function code = oct2mat (code) + ## Simple hacks to make things Matlab compatible code = strrep (code, "%!", "%%"); code = strrep (code, "!", "~"); @@ -183,5 +189,6 @@ ## Fix up sombrero which now has default argument in Octave code = strrep (code, "sombrero ()", "sombrero (41)"); + endfunction
--- a/scripts/testfun/rundemos.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/rundemos.m Fri May 20 15:46:45 2016 -0700 @@ -62,6 +62,7 @@ endfunction function run_all_demos (directory, do_class_dirs) + flist = readdir (directory); dirs = {}; for i = 1:numel (flist) @@ -94,17 +95,20 @@ run_all_demos (d, false); endfor endif + endfunction function retval = has_demos (f) + fid = fopen (f); if (f < 0) error ("rundemos: fopen failed: %s", f); - else - str = fread (fid, "*char").'; - fclose (fid); - retval = ! isempty (regexp (str, '^%!demo', 'lineanchors', 'once')); endif + + str = fread (fid, "*char").'; + fclose (fid); + retval = ! isempty (regexp (str, '^%!demo', 'lineanchors', 'once')); + endfunction
--- a/scripts/testfun/runtests.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/runtests.m Fri May 20 15:46:45 2016 -0700 @@ -62,6 +62,7 @@ endfunction function run_all_tests (directory, do_class_dirs) + flist = readdir (directory); dirs = {}; no_tests = {}; @@ -99,40 +100,45 @@ run_all_tests (d, false); endfor endif + endfunction function retval = has_functions (f) + n = length (f); if (n > 3 && strcmpi (f((end-2):end), ".cc")) fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char")'; - fclose (fid); - retval = ! isempty (regexp (str,'^(?:DEFUN|DEFUN_DLD|DEFUNX)\>', - 'lineanchors', 'once')); - else + if (fid < 0) error ("runtests: fopen failed: %s", f); endif + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str,'^(?:DEFUN|DEFUN_DLD|DEFUNX)\>', + 'lineanchors', 'once')); elseif (n > 2 && strcmpi (f((end-1):end), ".m")) retval = true; else retval = false; endif + endfunction function retval = has_tests (f) + fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char").'; - fclose (fid); - retval = ! isempty (regexp (str, '^%!(?:test|xtest|assert|error|warning)', - 'lineanchors', 'once')); - else + if (fid < 0) error ("runtests: fopen failed: %s", f); endif + + str = fread (fid, "*char").'; + fclose (fid); + retval = ! isempty (regexp (str, '^%!(?:test|xtest|assert|error|warning)', + 'lineanchors', 'once')); + endfunction function print_pass_fail (n, p, xf) + if (n > 0) printf (" PASS %4d/%-4d", p, n); nfail = n - p; @@ -145,6 +151,7 @@ endif endif puts ("\n"); + endfunction function print_test_file_name (nm)
--- a/scripts/testfun/test.m Fri May 20 12:03:39 2016 -0700 +++ b/scripts/testfun/test.m Fri May 20 15:46:45 2016 -0700 @@ -689,6 +689,7 @@ ## Find [start,end] of fn in 'function [a,b] = fn'. function pos = function_name (def) + pos = []; ## Find the end of the name. @@ -708,11 +709,13 @@ ## Return the end points of the name. pos = [left, right]; + endfunction ## Strip <pattern> from '<pattern> code'. ## Also handles 'id=ID code' function [pattern, id, rest] = getpattern (str) + pattern = "."; id = []; rest = str; @@ -726,6 +729,7 @@ elseif (strncmp (str, "id=", 3)) [id, rest] = strtok (str(4:end)); endif + endfunction ## Strip '.*prefix:' from '.*prefix: msg\n' and strip trailing blanks.