% Installer: "snackbar_install.m" % Created: 30-Apr-2003 11:35:50. function bund_driver % bund_driver -- Driver for "bund" bundles. % bund_driver (no arguments) contains Matlab commands % to inflate the instructions and files that are % encoded into the "bund_data" function of this package. % Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 14-Jun-2001 10:54:16. % Updated 06-Feb-2003 14:36:58. help(mfilename) v = version; isVersion6 = (v(1) == '6'); BINARY_TAG = '?'; CR = char(13); LF = char(10); comp = upper(computer); if any(findstr(comp, 'PCWIN')) % Windows. NL = [CR LF]; elseif any(findstr(comp, 'MAC')) % Macintosh. NL = CR; else % Unix. NL = LF; end c = zeros(1, 256); c(abs('0'):abs('9')) = 0:9; c(abs('a'):abs('f')) = 10:15; disp([' ']) disp([' ## This installer is ready to expand its contents,']) disp([' ## starting in the present directory: "' pwd '"']) disp([' ## To abort, execute an interruption now.']) disp([' ## Otherwise, to continue, press any key.']) disp([' ']) try pause catch disp([' ## Installation interrupted.']) disp([' ']) return end % eval('pause', 'disp(''Installation interrupted.''), return') tic w = which(mfilename); fin = fopen(w, 'r'); if fin < 0, return, end found = ~~0; while ~found s = fgetl(fin); if isequal(s, -1) fclose(fin); return end s = strrep(s, LF, ''); % Not necessary? s = strrep(s, CR, ''); % Not necessary? if isequal(s, 'function bund_data') found = ~~1; end end fout = -1; done = ~~0; while ~done s = fgetl(fin); if isequal(s, -1) fclose(fin); return end s = strrep(s, LF, ''); % Not necessary? s = strrep(s, CR, ''); % Not necessary? if length(s) > 0 if s(1) ~= '%' f = findstr(s, 'bund_setdir'); if any(f) theDir = eval(strrep(s, 'bund_setdir', '')); [status, msg] = mkdir(theDir); switch status case 1 if isVersion6 & any(msg) disp([' ## Directory exists: "' theDir '"']) else disp([' ## Directory created: "' theDir '"']) end case 2 disp([' ## Directory exists: "' theDir '"']) otherwise error([' ## Error while making new directory.']) end try cd(theDir) catch error([' ## Unable to go to directory: "' theDir '"']) end % eval('cd(theDir)', ... % 'disp(theDir), error('' ## Unable to go to directory.'')') else % try % eval(s); % catch % error([' ## Unable to evaluate: "' s '"']) % end eval(s, ... 'disp(s), error(''Unable to evaluate statement.'')') end elseif length(s) > 1 & s(2) == BINARY_TAG hx = double(s(3:end)); % Assume hex data. bin = 16*c(hx(1:2:end)) + c(hx(2:2:end)); fwrite(fout, bin, 'uchar'); else fprintf(fout, '%s', s(2:end)); fprintf(fout, NL); end end end fclose(fin); disp([' ## Elapsed time: ' num2str(fix(10*toc)/10) ' s.']) function bund_data bund_setdir('snackbar') disp(' ## Installing: "end.m" (text)') fout = fopen('end.m', 'w'); %function theResult = end(self, k, n) % %% generic/end -- Evaluate "end" as an index. %% end(self, k, n) returns the value of "end" %% that has been used as the k-th index in %% a list of n indices, on behalf of "self", %% a "generic" object. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 21-Apr-1999 08:50:46. % %if nargin < 1, help(mfilename), return, end % %s = size(self); % %if k == 1 & n == 1 % result = prod(s); %elseif k <= length(s) % result = s(k); %else % result = 0; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "again.m" (text)') fout = fopen('again.m', 'w'); %function theResult = again(varargin) % %% again -- Button for "Again" actions. %% again('theCallback') adds an "Again" pushbutton %% to the current figure, to evaluate 'theCallback' %% when pressed. The button handle is returned. %% again('s1', 's2', ...) joins the string-arguments %% with blank-separators to form the actual %% callback. Use the words 'comma' and 'semicolon' %% to invoke those separators. %% h = again (no argument) returns the handle of %% the existing "Again" pushbutton. %% again('demo') demonstrates itself by plotting %% random numbers each time the button is pressed. %% %% Note: this code needs some work to prevent %% run-away recursions when it is called from %% another routine as part of a demo. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Feb-2000 23:41:04. %% Updated 21-Jun-2002 14:36:42. % %% Process the callback. % %if any(gcbo) % oldPointer = get(gcbf, 'Pointer'); % try % set(gcbf, 'Pointer', 'watch') % drawnow % eval(get(gcbo, 'Tag')) % catch % disp(' ') % disp('An error has occurred:') % disp(lasterr) % end % set(gcbf, 'Pointer', oldPointer) % return %end % %% Return the existing handle. % %props = {'Style', 'pushbutton', 'String', 'Again', ... % 'Position', [20 10 60 20]}; %h = findobj(gcf, props{:}); %if any(h) & nargin < 1 & nargout > 0 % theResult = h; % return %end % %% Create or update the button. % %if nargin < 1, varargin{1} = 'demo'; help(mfilename), end % %theCallback = ''; %for i = 1:length(varargin) % if i > 1, theCallback = [theCallback ' ']; end % switch varargin{i} % case {'then', 'comma'} % varargin{i} = ','; % case 'semicolon' % varargin{i} = ';'; % end % theCallback = [theCallback varargin{i}]; %end % %if isequal(theCallback, 'demo') % theCallback = 'n=ceil(50*rand(1,1))+1;plot(fft(eye(n,n)),''-o''),axis equal'; % eval(theCallback) %end % %if isempty(h) & ~isempty(theCallback) % h = uicontrol(props{:}); % set(h, 'Callback', mfilename, 'Tag', theCallback, ... % 'ToolTipString', theCallback) %elseif ~isempty(theCallback) % set(h, 'Callback', mfilename, 'Tag', theCallback, ... % 'ToolTipString', theCallback) %end % %figure(gcf) % %if nargout > 0, theResult = h; end fclose(fout); disp(' ## Installing: "allequal.m" (text)') fout = fopen('allequal.m', 'w'); %function theResult = allequal(x, varargin) % %% allequal -- Is first argument same as any other? %% allequal(x, var1, var2, ...) returns TRUE (~~1) %% if all the arguments are equal, in the sense %% of the NANEQUAL function; otherwise, it returns %% FALSE (~~0). %% %% Also see: ANYEQUAL, NANEQUAL. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Mar-2002 11:17:11. %% Updated 20-Mar-2002 11:17:11. % %if nargin < 2, help(mfilename), return, end % %result = ~~1; % %for i = 1:length(varargin) % if ~nanequal(x, varargin{i}) % result = ~~0; % break % end %end % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "anyequal.m" (text)') fout = fopen('anyequal.m', 'w'); %function theResult = anyequal(x, varargin) % %% anyequal -- Is first argument same as any other? %% anyequal(x, var1, var2, ...) returns TRUE (~~1) %% if x is equal to any of the other arguments, %% in the sense of the NANEQUAL function; otherwise, %% it returns FALSE (~~0). %% %% Also see: ALLEQUAL, NANEQUAL. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Mar-2002 11:17:11. %% Updated 20-Mar-2002 11:17:11. % %if nargin < 2, help(mfilename), return, end % %result = ~~0; % %for i = 1:length(varargin) % if nanequal(x, varargin{i}) % result = ~~1; % break % end %end % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "arrowsafe.m" (text)') fout = fopen('arrowsafe.m', 'w'); %function [x, y] = arrowsafe(x0, y0, theLength, theAngle, theHeadSize) % %% arrowsafe -- Intelligent, oriented arrows. %% arrowsafe('demo') demonstrates itself with arrows centered %% on the origin, each one-unit long. %% arrowsafe(N) demonstrates itself with N arrows. %% arrowsafe(x0, y0, theLength, theAngle, theHeadSize) draws %% arrows that start at (x0, y0), with theLength (in y-axis units), %% theAngle (degrees, counter-clockwise from +x), and theHeadSize %% (in y-axis units). The variables should be the same size, but %% any can be a scalar, just so long as the x0 and/or y0 array is %% the full size. The "ResizeFcn" of the figure is set to update %% the arrows automatically. The "Tag" is the mfilename. %% h = arrowsafe(...) draws the arrows and returns the handle. %% [x, y] = arrowsafe(...) returns the (x, y) data for the %% arrows, one column per arrow, but does not draw them. %% arrowsafe (no argument) redraws existing arrows. This is %% useful whenever the window is resized or the x or y limits %% change. (Recall that printing causes the "ResizeFcn" to %% be called twice.) %% %% Note: this routine leaves the axes in "manual" mode. Use %% "axis auto" to revert to automatic axis limits. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jan-2000 14:22:59. %% Updated 20-Feb-2002 16:22:49. % %RCF = 180 / pi; % %% Resize. % %if nargin < 1 % oldGCA = gca; % h = findobj(gcf, 'Type', 'line', 'Tag', mfilename); % for i = 1:length(h) % p = get(h(i), 'Parent'); % axes(p) % u = get(h(i), 'UserData'); % [xx, yy] = feval(mfilename, u(:, 1), u(:, 2), ... % u(:, 3), u(:, 4), u(:, 5)); % set(h(i), 'XData', xx(:), 'YData', yy(:)); % end % axes(oldGCA) % return %end % %% Demonstration. % %if nargin == 1 % if isequal(x0, 'demo') % help(mfilename) % x0 = 16; % elseif ischar(x0) % x0 = eval(x0); % end % theName = [mfilename ' demo']; % f = findobj('Type', 'figure', 'Name', theName); % if ~any(f) % f = figure('Name', theName); % end % figure(max(f)) % delete(get(f, 'Children')) % n = max(1, round(x0)); % offset = 0; % x0 = zeros(1, n) + offset; % ang = linspace(0, 360, length(x0)+1); % ang(end) = []; % h = feval(mfilename, x0, 0, 1, ang); % set(gca, 'Xlim', [-n n], 'YLim', [-2 2]) % feval(mfilename) % set(gcf, 'WindowButtonDownFcn', ... % ['if zoomsafe(''down''), ' mfilename ', end']) % if nargout > 0, x = h; end % return %end % %% Initialize. % %if nargin > 1 % if nargout == 2, x = []; y = []; end % if length(x0) == 1 % x0 = x0 * ones(size(y0)); % elseif length(y0) == 1 % y0 = y0 * ones(size(x0)); % end % x0 = reshape(x0, [1 prod(size(x0))]); % y0 = reshape(y0, size(x0)); % if nargin < 3, theLength = 1; end % if nargin < 4, theAngle = 0; end % if nargin < 5, theHeadSize = 0.1 .* theLength; end % if length(theLength) == 1 % theLength = theLength * ones(size(x0)); % end % if length(theAngle) == 1 % theAngle = theAngle * ones(size(x0)); % end % if length(theHeadSize) == 1 % theHeadSize = theHeadSize * ones(size(x0)); % end % % theLength = reshape(theLength, size(x0)); % theAngle = reshape(theAngle, size(x0)); % theHeadSize = reshape(theHeadSize, size(x0)); % % axes(gca) % oldUnits = get(gca, 'Units'); % set(gca, 'Units', 'pixels') % thePosition = get(gca, 'Position'); % set(gca, 'Units', oldUnits) % theWidth = thePosition(3); % pixels. % theHeight = thePosition(4); % pixels. % % axis('manual') % dx = diff(get(gca, 'XLim')); % dy = diff(get(gca, 'YLim')); % dydx = dy / dx; % Not used. % dxdp = dx / theWidth; % sci/pixel. % dydp = dy / theHeight; % sci/pixel. % scale = dxdp / dydp; %% <== Scale-factor. % % xa = [-10; -20; 0; -20; -10]/20; % Arrowhead. % ya = [0; 10; 0; -10; 0]/20; % % m = length(xa); % n = prod(size(x0)); % repeats = [m 1]; % % ang = repmat(theAngle, repeats); % len = repmat(theLength, repeats); % head = repmat(theHeadSize, repeats); % % xa = repmat(xa, [1 n]); % ya = repmat(ya, [1 n]); % % xa = xa .* head; % ya = ya .* head; % % xa = xa + len; % % za = xa + sqrt(-1) * ya; % % za = [zeros(1, n); za]; % % ang = repmat(theAngle, [size(za, 1) 1]); % len = repmat(theLength, [size(za, 1) 1]); % head = repmat(theHeadSize, [size(za, 1) 1]); % xx0 = repmat(x0, [size(za, 1) 1]); % yy0 = repmat(y0, [size(za, 1) 1]); % % za = exp(sqrt(-1) * ang / RCF) .* za; % xx = real(za); % yy = imag(za); % % nans = zeros(1, n) + NaN; % % xx = [xx; nans]; % yy = [yy; nans]; % % zz = xx + sqrt(-1) .* yy; % % xx0 = repmat(x0, [size(zz, 1) 1]); % yy0 = repmat(y0, [size(zz, 1) 1]); % % xx = xx0 + real(zz) * scale; % <== Scaling. % yy = yy0 + imag(zz); % % parameters = [x0(:) y0(:) theLength(:) theAngle(:) theHeadSize(:)]; % % if nargout < 2 % h = line(xx(:), yy(:), ... % 'Tag', mfilename, ... % 'UserData', parameters); % if nargout > 1, x = h; end % elseif nargout == 2 % x = xx; % y = yy; % end % set(gcf, 'ResizeFcn', mfilename) % % if nargout == 1, x = h; end %end fclose(fout); disp(' ## Installing: "ascii.m" (text)') fout = fopen('ascii.m', 'w'); %function ascii % %% ascii -- Display Ascii Character Table. %% ascii (no argument) displays the Ascii Character Table %% in the current font. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Sep-1997 16:21:23. % %a = zeros(256, 4) + abs(' '); %a(:, 4) = (0:255).'; %a = setstr(a); % %% Control characters. % %a( 0+1, 2:4) = 'NUL'; %a( 1+1, 2:4) = 'SOH'; %a( 2+1, 2:4) = 'STX'; %a( 3+1, 2:4) = 'ETX'; %a( 4+1, 2:4) = 'EOT'; %a( 5+1, 2:4) = 'ENQ'; %a( 6+1, 2:4) = 'ACK'; %a( 7+1, 2:4) = 'BEL'; %a( 8+1, 2:4) = ' BS'; %a( 9+1, 2:4) = ' HT'; %a( 10+1, 2:4) = ' LF'; %a( 11+1, 2:4) = ' VT'; %a( 12+1, 2:4) = ' FF'; %a( 13+1, 2:4) = ' CR'; %a( 14+1, 2:4) = ' SO'; %a( 15+1, 2:4) = ' SI'; %a( 16+1, 2:4) = 'DLE'; %a( 17+1, 2:4) = 'DC1'; %a( 18+1, 2:4) = 'DC2'; %a( 19+1, 2:4) = 'DC3'; %a( 20+1, 2:4) = 'DC4'; %a( 21+1, 2:4) = 'NAK'; %a( 22+1, 2:4) = 'SYN'; %a( 23+1, 2:4) = 'ETB'; %a( 24+1, 2:4) = 'CAN'; %a( 25+1, 2:4) = ' EM'; %a( 26+1, 2:4) = 'SUB'; %a( 27+1, 2:4) = 'ESC'; %a( 28+1, 2:4) = ' FS'; %a( 29+1, 2:4) = ' GS'; %a( 30+1, 2:4) = ' RS'; %a( 31+1, 2:4) = ' US'; % %% Other named characters. % %a( 32+1, 2:4) = ' SP'; %a(127+1, 2:4) = 'DEL'; % %% Reshape. % %a = reshape(a.', prod(size(a))/16, 16).'; % %% Display. % %disp(' ') %disp(' ## Ascii Character Table') %disp(' ') %disp(a) %disp(' ') fclose(fout); disp(' ## Installing: "assign.m" (text)') fout = fopen('assign.m', 'w'); %function assign(theName, theValue) % %% assign -- Assign a value to a name. %% assign('theName', theValue) assigns theValue %% to 'theName' in the caller's workspace. It %% avoids the need to construct an explicit %% assignment statement to be eval-ed. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 28-May-1998 00:43:58. % %if nargin < 2, help(mfilename), return, end % %% The following scheme permits the assignment %% of items that have complicated subscripts, %% such as "a{1}(2).b{3}.c = pi". % %hasAns = (evalin('caller', 'exist(''ans'', ''var'')') == 1); %if hasAns % ans = evalin('caller', 'ans'); % Save. %end %assignin('caller', 'ans', theValue) %evalin('caller', [theName ' = ans;']) %evalin('caller', 'clear(''ans'')') %if hasAns % assignin('caller', 'ans', ans) % Restore. %end fclose(fout); disp(' ## Installing: "at.m" (text)') fout = fopen('at.m', 'w'); %function theResult = at(theFile, theOffset) % %% at -- Switch to the folder of a given file. %% at('theFunction') switches to the folder of %% 'theFunction', as determined by the "which" %% function. %% at('theFunction', theOffset) performs as above, %% then marches into higher directories by the %% amount of theOffset, which must be a negative %% integer. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Feb-2000 22:21:09. %% Updated 22-Apr-2003 09:19:37. % %if nargout > 0, theResult = []; end % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theOffset = 0; end %if ischar(theOffset), theOffset = eval(theOffset); end % %w = which(theFile); % %if isempty(w) % w = which([theFile '/' theFile]); % if isempty(w) % disp([' ## No such file: ' theFile]) % return % end %elseif isequal(w, 'built-in') % disp([' ## ' theFile ' is built-in. Try "at ' theFile '.m".']) % return %end % %[thePath, theName, theExtension, theVersion] = fileparts(w); % %if any(thePath) % cd(thePath) % if theOffset < 0 % for i = 1:fix(abs(theOffset)) % cd .. % end % end %end % %if nargout > 0 % theResult = pwd; %else % disp([' ## ' pwd]) %end fclose(fout); disp(' ## Installing: "basic_english.m" (text)') fout = fopen('basic_english.m', 'w'); %function theWordList = basic_english % %% basic_english (no argument) returns the alphabetized %% "Basic English" word-list of Charles Kay Ogden, from %% the Basic English web-site "http://www.basiceng.com". %% The result is a cell-array of 850 words. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 08-Mar-2002 11:56:44. %% Updated 08-Mar-2002 12:03:40. % %% Original Ogden sequence. % %wordlist = { % %'come' 'get' 'give' 'go' 'keep' 'let' 'make' 'put' 'seem' 'take' % 'be' 'do' 'have' 'say' 'see' 'send' 'may' 'will' 'about' 'across' % 'after' 'against' 'among' 'at' 'before' 'between' 'by' 'down' 'from' 'in' % 'off' 'on' 'over' 'through' 'to' 'under' 'up' 'with' 'as' 'for' % 'of' 'till' 'than' 'a' 'the' 'all' 'any' 'every' 'no' 'other' % 'some' 'such' 'that' 'this' 'I' 'he' 'you' 'who' 'and' 'because' % 'but' 'or' 'if' 'though' 'while' 'how' 'when' 'where' 'why' 'again' % 'ever' 'far' 'forward' 'here' 'near' 'now' 'out' 'still' 'then' 'there' % 'together' 'well' 'almost' 'enough' 'even' 'little' 'much' 'not' 'only' 'quite' % 'so' 'very' 'tomorrow' 'yesterday' 'north' 'south' 'east' 'west' 'please' 'yes' % 'account' 'act' 'addition' 'adjustment' 'advertisement' 'agreement' 'air' 'amount' 'amusement' 'animal' % 'answer' 'apparatus' 'approval' 'argument' 'art' 'attack' 'attempt' 'attention' 'attraction' 'authority' % 'back' 'balance' 'base' 'behavior' 'belief' 'birth' 'bit' 'bite' 'blood' 'blow' % 'body' 'brass' 'bread' 'breath' 'brother' 'building' 'burn' 'burst' 'business' 'butter' % 'canvas' 'care' 'cause' 'chalk' 'chance' 'change' 'cloth' 'coal' 'color' 'comfort' % 'committee' 'company' 'comparison' 'competition' 'condition' 'connection' 'control' 'cook' 'copper' 'copy' % 'cork' 'cotton' 'cough' 'country' 'cover' 'crack' 'credit' 'crime' 'crush' 'cry' % 'current' 'curve' 'damage' 'danger' 'daughter' 'day' 'death' 'debt' 'decision' 'degree' % 'design' 'desire' 'destruction' 'detail' 'development' 'digestion' 'direction' 'discovery' 'discussion' 'disease' % 'disgust' 'distance' 'distribution' 'division' 'doubt' 'drink' 'driving' 'dust' 'earth' 'edge' % 'education' 'effect' 'end' 'error' 'event' 'example' 'exchange' 'existence' 'expansion' 'experience' % 'expert' 'fact' 'fall' 'family' 'father' 'fear' 'feeling' 'fiction' 'field' 'fight' % 'fire' 'flame' 'flight' 'flower' 'fold' 'food' 'force' 'form' 'friend' 'front' % 'fruit' 'glass' 'gold' 'government' 'grain' 'grass' 'grip' 'group' 'growth' 'guide' % 'harbor' 'harmony' 'hate' 'hearing' 'heat' 'help' 'history' 'hole' 'hope' 'hour' % 'humor' 'ice' 'idea' 'impulse' 'increase' 'industry' 'ink' 'insect' 'instrument' 'insurance' % 'interest' 'invention' 'iron' 'jelly' 'join' 'journey' 'judge' 'jump' 'kick' 'kiss' % 'knowledge' 'land' 'language' 'laugh' 'law' 'lead' 'learning' 'leather' 'letter' 'level' % 'lift' 'light' 'limit' 'linen' 'liquid' 'list' 'look' 'loss' 'love' 'machine' % 'man' 'manager' 'mark' 'market' 'mass' 'meal' 'measure' 'meat' 'meeting' 'memory' % 'metal' 'middle' 'milk' 'mind' 'mine' 'minute' 'mist' 'money' 'month' 'morning' % 'mother' 'motion' 'mountain' 'move' 'music' 'name' 'nation' 'need' 'news' 'night' % 'noise' 'note' 'number' 'observation' 'offer' 'oil' 'operation' 'opinion' 'order' 'organization' % 'ornament' 'owner' 'page' 'pain' 'paint' 'paper' 'part' 'paste' 'payment' 'peace' % 'person' 'place' 'plant' 'play' 'pleasure' 'point' 'poison' 'polish' 'porter' 'position' % 'powder' 'power' 'price' 'print' 'process' 'produce' 'profit' 'property' 'prose' 'protest' % 'pull' 'punishment' 'purpose' 'push' 'quality' 'question' 'rain' 'range' 'rate' 'ray' % 'reaction' 'reading' 'reason' 'record' 'regret' 'relation' 'religion' 'representative' 'request' 'respect' % 'rest' 'reward' 'rhythm' 'rice' 'river' 'road' 'roll' 'room' 'rub' 'rule' % 'run' 'salt' 'sand' 'scale' 'science' 'sea' 'seat' 'secretary' 'selection' 'self' % 'sense' 'servant' 'sex' 'shade' 'shake' 'shame' 'shock' 'side' 'sign' 'silk' % 'silver' 'sister' 'size' 'sky' 'sleep' 'slip' 'slope' 'smash' 'smell' 'smile' % 'smoke' 'sneeze' 'snow' 'soap' 'society' 'son' 'song' 'sort' 'sound' 'soup' % 'space' 'stage' 'start' 'statement' 'steam' 'steel' 'step' 'stitch' 'stone' 'stop' % 'story' 'stretch' 'structure' 'substance' 'sugar' 'suggestion' 'summer' 'support' 'surprise' 'swim' % 'system' 'talk' 'taste' 'tax' 'teaching' 'tendency' 'test' 'theory' 'thing' 'thought' % 'thunder' 'time' 'tin' 'top' 'touch' 'trade' 'transport' 'trick' 'trouble' 'turn' % 'twist' 'unit' 'use' 'value' 'verse' 'vessel' 'view' 'voice' 'walk' 'war' % 'wash' 'waste' 'water' 'wave' 'wax' 'way' 'weather' 'week' 'weight' 'wind' % 'wine' 'winter' 'woman' 'wood' 'wool' 'word' 'work' 'wound' 'writing' 'year' % 'angle' 'ant' 'apple' 'arch' 'arm' 'army' 'baby' 'bag' 'ball' 'band' % 'basin' 'basket' 'bath' 'bed' 'bee' 'bell' 'berry' 'bird' 'blade' 'board' % 'boat' 'bone' 'book' 'boot' 'bottle' 'box' 'boy' 'brain' 'brake' 'branch' % 'brick' 'bridge' 'brush' 'bucket' 'bulb' 'button' 'cake' 'camera' 'card' 'cart' % 'carriage' 'cat' 'chain' 'cheese' 'chest' 'chin' 'church' 'circle' 'clock' 'cloud' % 'coat' 'collar' 'comb' 'cord' 'cow' 'cup' 'curtain' 'cushion' 'dog' 'door' % 'drain' 'drawer' 'dress' 'drop' 'ear' 'egg' 'engine' 'eye' 'face' 'farm' % 'feather' 'finger' 'fish' 'flag' 'floor' 'fly' 'foot' 'fork' 'fowl' 'frame' % 'garden' 'girl' 'glove' 'goat' 'gun' 'hair' 'hammer' 'hand' 'hat' 'head' % 'heart' 'hook' 'horn' 'horse' 'hospital' 'house' 'island' 'jewel' 'kettle' 'key' % 'knee' 'knife' 'knot' 'leaf' 'leg' 'library' 'line' 'lip' 'lock' 'map' % 'match' 'monkey' 'moon' 'mouth' 'muscle' 'nail' 'neck' 'needle' 'nerve' 'net' % 'nose' 'nut' 'office' 'orange' 'oven' 'parcel' 'pen' 'pencil' 'picture' 'pig' % 'pin' 'pipe' 'plane' 'plate' 'plough/plow' 'pocket' 'pot' 'potato' 'prison' 'pump' % 'rail' 'rat' 'receipt' 'ring' 'rod' 'roof' 'root' 'sail' 'school' 'scissors' % 'screw' 'seed' 'sheep' 'shelf' 'ship' 'shirt' 'shoe' 'skin' 'skirt' 'snake' % 'sock' 'spade' 'sponge' 'spoon' 'spring' 'square' 'stamp' 'star' 'station' 'stem' % 'stick' 'stocking' 'stomach' 'store' 'street' 'sun' 'table' 'tail' 'thread' 'throat' % 'thumb' 'ticket' 'toe' 'tongue' 'tooth' 'town' 'train' 'tray' 'tree' 'trousers' % 'umbrella' 'wall' 'watch' 'wheel' 'whip' 'whistle' 'window' 'wing' 'wire' 'worm' % 'able' 'acid' 'angry' 'automatic' 'beautiful' 'black' 'boiling' 'bright' 'broken' 'brown' % 'cheap' 'chemical' 'chief' 'clean' 'clear' 'common' 'complex' 'conscious' 'cut' 'deep' % 'dependent' 'early' 'elastic' 'electric' 'equal' 'fat' 'fertile' 'first' 'fixed' 'flat' % 'free' 'frequent' 'full' 'general' 'good' 'great' 'grey/gray' 'hanging' 'happy' 'hard' % 'healthy' 'high' 'hollow' 'important' 'kind' 'like' 'living' 'long' 'male' 'married' % 'material' 'medical' 'military' 'natural' 'necessary' 'new' 'normal' 'open' 'parallel' 'past' % 'physical' 'political' 'poor' 'possible' 'present' 'private' 'probable' 'quick' 'quiet' 'ready' % 'red' 'regular' 'responsible' 'right' 'round' 'same' 'second' 'separate' 'serious' 'sharp' % 'smooth' 'sticky' 'stiff' 'straight' 'strong' 'sudden' 'sweet' 'tall' 'thick' 'tight' % 'tired' 'true' 'violent' 'waiting' 'warm' 'wet' 'wide' 'wise' 'yellow' 'young' % 'awake' 'bad' 'bent' 'bitter' 'blue' 'certain' 'cold' 'complete' 'cruel' 'dark' % 'dead' 'dear' 'delicate' 'different' 'dirty' 'dry' 'false' 'feeble' 'female' 'foolish' % 'future' 'green' 'ill' 'last' 'late' 'left' 'loose' 'loud' 'low' 'mixed' % 'narrow' 'old' 'opposite' 'public' 'rough' 'sad' 'safe' 'secret' 'short' 'shut' % 'simple' 'slow' 'small' 'soft' 'solid' 'special' 'strange' 'thin' 'white' 'wrong' %}; % %wordlist = sort(wordlist(:)); % %if nargout > 0 % theWordList = wordlist; %else % assignin('caller', 'ans', wordlist) %end fclose(fout); disp(' ## Installing: "begets.m" (text)') fout = fopen('begets.m', 'w'); %function msg = Begets(fcn,nin,a,b,c,d,e,f,g,h,i,j) % %% Begets -- Message showing the result of a function. %% Begets('fcn',nin,a,b,...) creates a message that %% shows the function 'fcn' with its input and %% output values. The number of input arguments %% is nin. The argument list a,b,... is organized %% into nin input values, followed immediately by %% the output values. Thus, begets('sqrt', 1, 4, 2) %% results in the message "sqrt(4) ==> 2". % %% Uses: var2str. % %% Copyright (C) 1991 Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if nargin < 1 % help(mfilename) % disp(' Some examples:') % x = (1:4).'; % begets('mean', 1, x, mean(x)); % x = (2:4).^2; % begets('sqrt', 1, x, sqrt(x)); % x = [1 2; 3 4]; [m, n] = size(x); % begets('size', 1, x, [m n]); % begets('size', 1, x, m, n); % x = [1 2; 2 1]; [v, d] = eig(x); % begets('eig', 1, x, v, d) % begets('1/0', 0, inf) % begets('inf.*0', 0, inf.*0) % x = abs('hello'); % begets('setstr', 1, x, setstr(x)) % x = 'hello'; % begets('abs', 1, x, abs(x)) % return %end % %% FCN(...) Input argument list. % %s = ''; %s = [fcn]; %if nin > 0, s = [s '(']; end %arg = 'a'; %for ii = 1:nin; % s = [s var2str(eval(arg))]; % if ii < nin, s = [s ', ']; end % arg = setstr(arg + 1); %end %if nin > 0, s = [s ')']; end % %% [...] Output argument list. % %t = ''; %nout = nargin - nin - 2; %if nout > 1, t = ['[']; end %for ii = 1:nout % t = [t var2str(eval(arg))]; % if ii < nout, t = [t ', ']; end % arg = setstr(arg + 1); %end %if nout > 1, t = [t ']']; end % %% Message. % %% u = [t ' = ' s]; %u = [s ' ==> ' t]; % %if nargout > 0, msg = u; else, disp([' ' u]); end fclose(fout); disp(' ## Installing: "bgtext.m" (text)') fout = fopen('bgtext.m', 'w'); %function handle = bgtext(x, y, z, string, color, varargin) % %% bgtext -- Text with background color. %% bgtext(x, y, 'string', color, ...) draws the text with %% the given patch color in the background. The "ResizeFcn" %% of the figure is set to resize the patches automatically. %% The default color is light-gray. Except for the added %% "color" argument, the syntax is the same as for "text". %% bgtext(x, y, z, 'string', color, ...) for 3-d text position. %% bgtext(theFigure) resizes the background patches to fit the %% extents of the "bgtext" objects in theFigure (default = gcf). %% bgtext('demo', N) demonstrates itself for N random locations %% (default = 2), in a random color. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Aug-1999 14:26:10. %% Updated 31-Aug-1999 16:23:27. % %DEFAULT_COLOR = [9 9 9]/10; % %if nargin < 1, x = gcf; end % %% Demonstration. % %if isequal(x, 'demo') % n = 2; % if nargin > 1 % if isstr(y), y = eval(y); end % n = y; % end % x = rand(n, 1); % y = rand(size(x)); % string = 'Hello World'; % color = 0.5 * (1 + rand(1, 3)); % color = color / max(color); % set(gca, 'XLim', [-0.5 1.5], 'YLim', [-0.5 1.5]) % bgtext(x, y, string, color) % set(gcf, 'Name', [mfilename ' demo']) % zoomsafe % figure(gcf) % return %end % %% Resize background patch sizes. % %if nargin < 2 & ishandle(x) & isequal(get(x, 'Type'), 'figure') % h = x; % f = findobj(h, 'Type', 'text', 'Tag', mfilename); % for i = 1:length(f) % t = f(i); % p = get(t, 'UserData'); % ax = get(t, 'Parent'); % xdir = get(ax, 'XDir'); % ydir = get(ax, 'YDir'); % if ishandle(p) % switch get(p, 'Type') % case 'patch' % extent = get(t, 'Extent'); % x0 = extent(1); y0 = extent(2); % width = extent(3); height = extent(4); % xp = x0 + [0 width width 0]; % yp = y0 + [0 0 height height]; % switch xdir % case 'reverse' % xp = xp - (max(xp) - min(xp)); % otherwise % end % switch ydir % case 'reverse' % yp = yp - (max(yp) - min(yp)); % otherwise % end % set(p, 'XData', xp, 'YData', yp) % otherwise % end % end % end % return %end % %% Normal processing. % %is3d = ~isstr(z); % %if ~is3d % if nargin > 4 % varargin = [{color} varargin]; % else % varargin = {}; % end % if nargin > 3 % color = string; % else % color = DEFAULT_COLOR; % end % string = z; %else % if nargin < 5 % color = DEFAULT_COLOR; % end %end % %wasHold = ishold; %hold on % %% Measure temporary text (invisible). % %if ~is3d % t = text(x, y, string); %else % t = text(x, y, z, string); %end % %ax = get(t(1), 'Parent'); %xdir = get(ax, 'XDir'); %ydir = get(ax, 'YDir'); % %if ~isempty(varargin), set(t, varargin{:}), end %set(t, 'Visible', 'off') % %extent = zeros(length(t), 4); %for i = 1:length(t) % extent(i, :) = get(t(i), 'Extent'); %end % %% Delete temporary text. % %delete(t) % %% Create patches. % %p = zeros(length(t), 1); %for i = 1:length(t) % x0 = extent(i, 1); y0 = extent(i, 2); % width = extent(i, 3); height = extent(i, 4); % xp = x0 + [0 width width 0]; % yp = y0 + [0 0 height height]; % switch xdir % case 'reverse' % xp = xp - (max(xp) - min(xp)); % otherwise % end % switch ydir % case 'reverse' % yp = yp - (max(yp) - min(yp)); % otherwise % end % p(i) = patch(xp, yp, color); %end %set(p, 'EdgeColor', 'none', 'Tag', mfilename) % %% Superimpose new text. % %if ~is3d % t = text(x, y, string); %else % t = text(x, y, z, string); %end % %if ~wasHold, hold off, end % %if ~isempty(varargin), set(t, varargin{:}), end % %for i = 1:length(t) % set(t(i), 'UserData', p(i), 'Tag', mfilename) %end % %% Set the "ResizeFcn" callback. % %set(gcf, 'ResizeFcn', [mfilename]) % %% Return. % %if nargout > 0, handle = t; end fclose(fout); disp(' ## Installing: "blinksafe.m" (text)') fout = fopen('blinksafe.m', 'w'); %function vis = blinksafe(varargin) % %% blinksafe -- Toggle data points in (x, y, z) plot. %% blinksafe('demo') demonstrates itself, using random (x, y) %% data plotted with EraseMode = 'xor'. %% blinksafe('on') enables blinking, in which a mouse click %% on a plotted (x, y, z) point makes the point invisible %% and marks the site with a distinctive dot. The z-value %% at that point is set to NaN, and its original value is %% remembered for later restoration. The proximity of the %% click to a point is determined in the (x, y) plane only. %% blinksafe(h) turns blinking on for just the lines specified %% by the handles h. %% blinksafe('off') turns blinking off and removes the markers. %% Points invisible at this stage will remain invisible, %% since the corresponding z values will now be NaN. %% blinksafe('clear') restores all the plotted data to visibility. %% vis = blinksafe(h) returns the visibility-vector (1 = visible; %% 0 = not visible) for the line whose handle is h. %% %% Also see: marksafe. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jan-2000 09:44:58. %% Updated 02-Feb-2000 23:45:50. % %BLINKER_TAG = ['_' mfilename '_']; %BLINKER_MARKER = '*'; %BLINKER_SIZE = get(0, 'DefaultLineMarkerSize'); %BLINKER_COLOR = [1 0 0]; %BLINKER_BUTTONDOWNFCN = mfilename; % %% Demonstration. % %if nargin > 0 & isequal(varargin{1}, 'demo') % help(mfilename) % x = linspace(0, 1, 101); % y = sin(3*pi*x); % noise = 2*(rand(size(x)) - 0.5); % noise(abs(noise) < 0.95) = 0; % h = plot(x, y+noise, '-o', ... % 'MarkerSize', 4, 'EraseMode', 'xor'); % eval(mfilename) % if exist('zoomsafe', 'file') == 2 % eval('zoomsafe') % end % set(gcf, 'Name', [mfilename ' demo']) % if nargout > 0, vis = h; end % return %end % %% Get visibility of a line. %% Requires a handle and an output variable. % %if nargout > 0 & nargin > 0 % vis = []; % h = varargin{1}; % if ischar(h), h = eval(h); end % if ishandle(h) % if isequal(get(h, 'Type'), 'line') % if ~isequal(get(h, 'Tag'), BLINKER_TAG) % vis = isfinite(get(h, 'ZData')); % end % end % end % return %end % %% Actions: on, off, clear. % %if nargin > 0 & isempty(gcbo) % if ischar(varargin{1}) % theAction = varargin{1}; % switch theAction % case 'on' % varargin = {}; % case 'off' % h = findobj(gcf, 'Tag', BLINKER_TAG); % if any(h), delete(h), end % return % case 'clear' % h = findobj(gcf, 'Tag', BLINKER_TAG); % if any(h) % for i = 1:length(h) % u = get(h(i), 'UserData'); % z = get(u.handle, 'ZData'); % z(u.index) = u.z; % set(u.handle, 'ZData', z) % end % delete(h) % end % return % otherwise % disp([' ## No such action: "' theAction '"']) % return % end % end %end % %% Initialize. % %if isempty(gcbo) % if isempty(varargin) % h = findobj(gcf, 'Type', 'line'); % varargin{1} = h; % end % h = varargin{1}; % set(h, 'ButtonDownFcn', BLINKER_BUTTONDOWNFCN) % for i = 1:length(h) % z = get(h(i), 'ZData'); % if isempty(z) % x = get(h(i), 'XData'); % z = zeros(size(x)); % set(h(i), 'ZData', z); % end % end % return %end % %% Process a click. If clicking on the data, make %% the closest data point invisible. If clicking %% on a "blinker", restore the visibility of the %% corresponding point. % %if isempty(varargin), varargin{1} = 'ButtonDownFcn'; end % %if length(varargin) > 0 & ischar(varargin{1}) % theEvent = varargin{1}; % switch lower(theEvent) % case 'buttondownfcn' % switch get(gcbo, 'Tag') % case '_blinksafe_' % Restore visibility; delete the blinker. % u = get(gcbo, 'UserData'); % z = get(u.handle, 'ZData'); % z(u.index) = u.z; % set(u.handle, 'ZData', z); % delete(gcbo) % otherwise % Make invisible; create a blinker. % p = get(gca, 'CurrentPoint'); % x0 = p(1, 1); % y0 = p(1, 2); % x = get(gcbo, 'XData'); % y = get(gcbo, 'YData'); % % dx = diff(get(gca, 'XLim')); % Scale to pixels. % dy = diff(get(gca, 'YLim')); % theOldUnits = get(gca, 'Units'); % set(gca, 'Units', 'pixels'); % thePosition = get(gca, 'Position'); % theWidth = thePosition(3); % theHeight = thePosition(4); % dx = dx / theWidth; % dy = dy / theHeight; % set(gca, 'Units', theOldUnits) % % d = abs((x*dy+sqrt(-1)*y*dx - (x0*dy+sqrt(-1)*y0*dx))); % % index = find(d == min(d)); % if any(index) % index = index(1); % z = get(gcbo, 'ZData'); % if isempty(z), z = zeros(size(x)); end % if isfinite(z(index)) & 0 % u.handle = gcbo; % u.index = index; % u.z = z(index); % theMarker = get(gcbo, 'Marker'); % if isequal(theMarker, BLINKER_MARKER) % BLINKER_MARKER = 'o'; % end % h = line(x(index), y(index),... % 'Marker', BLINKER_MARKER, ... % 'MarkerSize', BLINKER_SIZE, ... % 'MarkerFaceColor', 'none', ... % 'MarkerEdgeColor', BLINKER_COLOR, ... % 'EraseMode', 'xor', ... % 'ButtonDownFcn', BLINKER_BUTTONDOWNFCN, ... % 'UserData', u, ... % 'Tag', BLINKER_TAG); % z(index) = nan; % set(gcbo, 'ZData', z) % else % h = make_blinker(gcbo, index); % end % end % end % otherwise % disp(['## No such event: ' theEvent]) % end %end % %% ---------- make_blinker ---------- % % %function theResult = make_blinker(h, index) % %% make_blinker -- Create a blinker. %% make_blinker(h, index) places a blinker %% on line h at the given index. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Jan-2000 14:11:55. %% Updated 18-Jan-2000 14:11:55. % %BLINKER_TAG = ['_' mfilename '_']; %BLINKER_MARKER = '*'; %BLINKER_SIZE = get(0, 'DefaultLineMarkerSize'); %BLINKER_COLOR = [1 0 0]; %BLINKER_BUTTONDOWNFCN = mfilename; % %result = zeros(size(h)); % %for i = 1:length(h) % x = get(h(i), 'XData'); % y = get(h(i), 'YData'); % z = get(h(i), 'ZData'); % if isempty(z) % z = zeros(size(x)); % end % theMarker = get(h(i), 'Marker'); % if isequal(theMarker, BLINKER_MARKER) % BLINKER_MARKER = 'o'; % end % if ~isequal(get(gcbo, 'Marker'), 'none') % BLINKER_SIZE = 2 + get(gcbo, 'MarkerSize'); % end % % if isfinite(z(index)) % u.handle = h(i); % u.index = index; % u.z = z(index); % result(i) = line(x(index), y(index),... % 'Marker', BLINKER_MARKER, ... % 'MarkerSize', BLINKER_SIZE, ... % 'MarkerFaceColor', 'none', ... % 'MarkerEdgeColor', BLINKER_COLOR, ... % 'EraseMode', 'xor', ... % 'ButtonDownFcn', BLINKER_BUTTONDOWNFCN, ... % 'UserData', u, ... % 'Tag', BLINKER_TAG); % z(index) = nan; % set(h(i), 'ZData', z) % end %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "bringtofront.m" (text)') fout = fopen('bringtofront.m', 'w'); %function bringtofront(varargin) % %% bringtofront -- Lift graphical objects. %% bringtofront(theHandles, ...) brings theHandles %% to the front, one-by-one, in the order listed. %% Any number of handles can be mentioned, either %% as matrices or scalars. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 15-Apr-1999 19:40:12. %% Updated 12-Mar-2002 12:09:59. % %if nargin < 1, help(mfilename), return, end % %for j = 1:prod(size(varargin)) % theHandles = varargin{j}; % if ischar(theHandles), theHandles = evalin('caller', theHandles); end % for i = 1:prod(size(theHandles)) % if ishandle(theHandles(i)) % theType = get(theHandles(i), 'Type'); % theParent = get(theHandles(i), 'Parent'); % theParentType = get(theParent, 'Type'); % theChildren = get(theParent, 'Children'); % theChildren(theChildren == theHandles(i)) = []; % theChildren = [theHandles(i); theChildren(:)]; % set(theParent, 'Children', theChildren) % switch theType % case {'figure', 'axes'} % feval(theType, theHandles(i)) % otherwise % end % switch theParentType % case 'figure' % set(theParent, 'CurrentObject', theHandles(i)) % otherwise % end % end % end %end fclose(fout); disp(' ## Installing: "busy.m" (text)') fout = fopen('busy.m', 'w'); %function Busy(theFigure) % %% Busy -- Set the watch-cursor. %% Busy(theFigure) sets the watch-cursor in theFigure. %% The companion routine is "Idle". % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if ~any(findobj('Type', 'figure')), return, end % %if nargin < 1 % theFigure = gcf; %end % %set(theFigure, 'Pointer', 'watch'); fclose(fout); disp(' ## Installing: "calls.m" (text)') fout = fopen('calls.m', 'w'); %function [varargout] = calls(theFcn, varargin) % %% calls -- List of function calls. %% calls('demo') demonstrates itself by listing the %% routines that would be called by "bessel(2, 1)". %% [...] = calls('theFcn', ...) executes 'theFcn' with %% the given arguments, then displays the list of M %% and Mex routines that were called, according to the %% Matlab "which" function. The list of full-path names %% is also placed in the caller's "ans". If the list is %% empty, then all the calls were made to "built-in" %% functions. %% %% NOTE: When using this routine to assist a bundling %% procedure, be sure not to include files whose %% respective copyrights would be violated. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Apr-2000 09:11:50. %% Updated 11-Jan-2001 10:17:36. % %if nargout > 0, varargout = cell(1, nargout); end % %if nargin < 1, help(mfilename), theFcn = 'demo'; end % %if isequal(theFcn, 'demo') % calls('bessel', 2, 1) % return %end % %clear functions %clear mex % %if nargout > 0 % if nargin > 1 % [varargout{:}] = feval(theFcn, varargin{:}); % else % [varargout{:}] = feval(theFcn); % end %else % if nargin > 1 % feval(theFcn, varargin{:}); % else % feval(theFcn); % end %end % %[theCalled, theMexCalled] = inmem; %isMex = ones(length(theCalled)+length(theMexCalled), 1); %isMex(1:length(theCalled)) = 0; %theCalled = [theCalled; theMexCalled]; %[theCalled, indices] = sort(theCalled); %isMex = isMex(indices); % %theNames = theCalled; % %for i = 1:length(theCalled) % theCalled{i} = which(theCalled{i}); %end % %w = which(mfilename); %for i = length(theCalled):-1:1 % if isequal(w, theCalled{i}) % theCalled(i) = []; % theNames(i) = []; % break % end %end % %if isempty(theCalled) % theCalled = ' (none)'; %end % %assignin('caller', 'ans', theCalled) % %nmax = 0; %for i = 1:length(theNames) % nmax = max(nmax, length(theNames{i})); %end % %blank = char(zeros(1, nmax) + abs(' ')); %for i = 1:length(theNames) % temp = blank; % if isMex(i) % temp = [temp ' Mex ']; % else % temp = [temp ' M ']; % end % temp(1:length(theNames{i})) = theNames{i}; % theCalled{i} = [temp ' ' theCalled{i}]; %end % %disp(' ') %disp([' ## M-files and Mex-files called by "' theFcn '":']) %disp(' ') %disp(theCalled) % %clear functions fclose(fout); disp(' ## Installing: "crossings.m" (text)') fout = fopen('crossings.m', 'w'); %function theResult = crossings(z1, z2, varargin) % %% crossings -- Index where a polyline crosses a line. %% crossings(N) demonstrates itself with N polyline %% points, where N defaults to 10. %% crossings(z1, z2) returns decimal-indices in polyline %% z1 where line-segment z2 (both complex) crosses it. %% Zero represents segments that do not cross. %% crossings(x1, y1, x2, y2) is an alternative syntax. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jul-2000 09:05:48. %% Updated 30-Sep-2002 16:00:42. % %if nargin < 1, help(mfilename), z1 = 'demo'; end % %if isequal(z1, 'demo'), z1 = 10; end %if ischar(z1), z1 = eval(z1); end % %if length(z1) == 1 % n = z1; % z1 = sort(rand(1, n)) + sqrt(-1)*rand(1, n); % z2 = rand(1, 2) + sqrt(-1)*rand(1, 2); % hold off % plot(real(z1), imag(z1), 'g', ... % real(z2), imag(z2), 'r') % tic % result = feval(mfilename, z1, z2); % disp([' ## Elapsed time: ' int2str(round(toc)) ' s']) % if any(result) % zi = interp1(1:length(z1), z1, result(result ~= 0)); % hold on % plot(real(zi), imag(zi), 'bo') % end % hold off % title([mfilename ' ' int2str(n)]) % figure(gcf) % try, zoomsafe, catch, end % if nargout > 0 % theResult = result; % else % crossing_indices = result(result ~= 0) % end % return %end % %if nargin > 3 % z1 = z1 + sqrt(-1)*z2; % z2 = varargin{1} + sqrt(-1)*varargin{2}; %end % %if length(z2) > 2 % temp = z1; z1 = z2; z2 = temp; %end % %% *** The following note not yet correct. *** %% NOTE: This routine can be vectorized by using %% "tensor_sol" to compute all the crossings (roots) at %% once. The problem to be solved is A = [x1 1; x2 1] %% and b = [y1; y2], where each of the entries extends %% into the third dimension, one element per line segment. %% Call "tensor_sol(A, b, 2, 1)". % %z1 = z1(:); %z2 = z2(:); % %result = zeros(length(z1)-1, 1); % %for i = 1:length(z1)-1 % z0 = z1(i); % zd = diff(z1(i:i+1)); % z = (z2 - z0) / zd; % if any(imag(z) >= 0) & any(imag(z) <= 0) % p = polyfit(real(z), imag(z), 1); % root = -p(2) / p(1); % if root >= 0 & root <= 1 % result(i) = root + i; % end % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "dateaxis.m" (text)') fout = fopen('dateaxis.m', 'w'); %function dateaxis(theTickAxis, theDateFormat, theBias) % %% dateaxis -- Resizeable "datetick" function. %% dateaxis('theTickAxis', theDateFormat, theBias) converts %% the labels of 'theTickAxis' {'x' | 'y' | 'z'} to dates %% in theDateFormat (see "help datestr") and makes the %% affected axis resizeable. The Matlab "datenum" or %% "datestr" that corresponds to zero can be entered as %% theBias. More than one axis can be labeled with dates %% by stringing 'theTickAxis' codes together, as in 'xy'. %% The input defaults are 'x', 2, and 0, respectively. %% dateaxis('demo') demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-May-1998 11:03:32. % %if nargin < 1, theTickAxis = 'x'; end % %% Demonstration. % %if isequal(theTickAxis, 'demo') % help(mfilename) % theNow = now; % t = -50:10:50; % theTitle = 'Original'; theXLabel = 'x'; theYLabel = 'y'; % for i = 1:2 % subplot(2, 1, i) % plot([0 -50; 0 0], [-50 0; 0 0], 'r-', t, t, '-o') % axis(55 * [-1 1 -1 1]) % text(+5, 0, 'now') % title(theTitle), xlabel(theXLabel), ylabel(theYLabel) % theTitle = ['dateaxis(''x'', 2, now)']; % theXLabel = 'Date'; theYLabel = 'Day Number'; % end % set(gcf, 'Name', 'DateAxis Demo') % dateaxis('x', 2, theNow) % figure(gcf) % return %end % %% Defaults. % %if nargin < 2, theDateFormat = 2; end %if nargin < 3, theBias = 0; end %if isstr(theBias), theBias = datenum(theBias); end % %% Process each 'tick-axis' code. % %for k = 1:length(theTickAxis) % %% Revert to "auto" tick-labels temporarily. % % switch upper(theTickAxis(k)) % case {'X', 'Y', 'Z'} % set(gca, [theTickAxis(k) 'TickMode'], 'auto') % set(gca, [theTickAxis(k) 'TickLabelMode'], 'auto') % otherwise % help(mfilename) % error([' ## Unknown Tick-Axis Designation: ' theTickAxis(k) '.']); % end % %% Convert ticks to date-strings. % % theTicks = get(gca, [theTickAxis(k) 'Tick']); % theTickLabels = cell(size(theTicks)); % for i = 1:length(theTicks) % theTicklabels{i} = ''; % if rem(i, 2) % if nargin < 2 % theTickLabels{i} = datestr(theTicks(i)+theBias); % else % theTickLabels{i} = datestr(theTicks(i)+theBias, theDateFormat); % end % end % end % set(gca, [theTickAxis(k) 'Tick'], theTicks, ... % [theTickAxis(k) 'TickLabel'], theTickLabels) %end % %% Make resizeable if called directly. % %if isempty(gcbo) % if nargin < 2 % theResizeFcn = ['dateaxis(''' theTickAxis ''');']; % elseif ischar(theDateFormat) % theResizeFcn = ['dateaxis(''' theTickAxis ''', ''' theDateFormat ''', ' num2str(theBias) ');']; % else % theResizeFcn = ['dateaxis(''' theTickAxis ''', ' int2str(theDateFormat) ', ' num2str(theBias) ');']; % end % set(get(gca, 'Parent'), 'ResizeFcn', theResizeFcn) %end fclose(fout); disp(' ## Installing: "datenum2julian.m" (text)') fout = fopen('datenum2julian.m', 'w'); %function theJulian = datenum2julian(theDateNum) % %% datenum2julian -- Convert Julian Day to Matlab datenum. %% datenum2julian(theDateNum) converts theDayNum (Matlab %% datenum) to its equivalent Julian day. The Julian %% day is referenced to midnight, not noon. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Oct-1998 15:49:22. % %if nargin < 1, help(mfilename), return, end % %t0 = datenum(1968, 5, 23) - 2440000; % May 23, 1968. % %result = theDateNum - t0; % %if nargout > 0 % theJulian = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "deg2dms.m" (text)') fout = fopen('deg2dms.m', 'w'); %function dms=deg2dms(deg) % %%DEG2DMS Converts angles from degrees to deg:min:sec vector format %% %% dms = DEG2DM(deg) converts angles from degrees to deg:min:sec vector %% format. %% %% See also DMS2DEG, DEG2RAD, MAT2DMS, DMS2MAT, ANGLEDIM, ANGL2STR % %% Copyright 1996-2002 Systems Planning and Analysis, Inc. and The MathWorks, Inc. %% Written by: E. Byrns, E. Brown %% $Revision: 1.10 $ $Date: 2002/03/20 21:24:58 $ % % %if nargin==0 % error('Incorrect number of arguments') %elseif ~isreal(deg) % warning('Imaginary parts of complex ANGLE argument ignored') % deg = real(deg); %end % %% Test for empty inputs % %if isempty(deg); dms = []; return; end % %% Construct a sign vector which has +1 when deg >= 0 and -1 when deg < 0. % %signvec = sign(deg); %signvec = signvec + (signvec == 0); % Enforce +1 when deg == 0 % %% Compute the degrees, minutes and seconds % % %deg = abs(deg); % Work in absolute value. Signvec will set sign later %d = fix(deg); % Degrees %ms = 60*(deg - d); % Minutes and seconds %m = fix(ms); % Minutes %s = 60*(ms - m); % Seconds % %% Determine where to store the sign of the angle. It should be %% associated with the largest nonzero component of d:m:s. % %dsign = signvec .* (d~=0); % Associate with degrees %msign = signvec .* (d==0 & m~=0); % Assoicate with minutes (d = 0) %ssign = signvec .* (d==0 & m==0 & s~=0); % Associate with seconds (d = m = 0) % %% In the application of signs below, the comparison with 0 is used so that %% the sign vector contains only +1 and -1. Any zero occurances causes %% data to be lost when the sign has been applied to a higher component %% of d:m:s. % %d = ((dsign==0) + dsign).*d; % Apply signs to the degrees %m = ((msign==0) + msign).*m; % Apply signs to minutes %s = ((ssign==0) + ssign).*s; % Apply signs to seconds % %dms = mat2dms(d,m,s); % Construct the dms vector for output % % fclose(fout); disp(' ## Installing: "demonstrate.m" (text)') fout = fopen('demonstrate.m', 'w'); %function theResult = demonstrate(varargin) % %% demonstrate -- Evaluate and display a command. %% demonstrate ... or demonstrate('...') evaluates %% the concatenated argument(s) as a single command %% and returns or displays a single string showing %% the answer adjacent to the command itself. %% demonstrate (no argument) shows help and %% demonstrates several commands. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Aug-1998 09:12:02. % %if nargin < 1 & nargout < 1 % help(mfilename) % demonstrate datestr(now) % demonstrate sqrt(2) % demonstrate min(2, 3) % demonstrate 2 * 3 % oldWarning = warning; % warning off % demonstrate [-1 0 1] / 0 % warning(oldWarning) % return %end % %theCommand = ''; %for i = 1:length(varargin) % if i > 1, theCommand = [theCommand ' ']; end % theCommand = [theCommand varargin{i}]; %end % %okay = 1; %theAnswer = []; %lasterr('') %theAnswer = evalin('caller', theCommand, '[]'); %if ~isempty(lasterr), theAnswer = ['Error: ' lasterr]; end % %result = [theCommand ' ==> ' mat2str(theAnswer)]; % %if nargout > 0 % theResult = result; %else % disp([' ' result]) %end fclose(fout); disp(' ## Installing: "describe.m" (text)') fout = fopen('describe.m', 'w'); %function status = describe(theItem, howMuch) % %% describe -- Explanation of an item. %% describe('theFunction') shows help for 'theFunction'. %% describe(theObject) describes theObject itself, but not %% its inherited parts. %% describe(theObject, 'full') describes theObject fully. %% describe(theNonObject, ...) describes theNonObject. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, describe('describe'), return, end %if nargin < 2, howMuch = ''; end % %theName = inputname(1); % %if isstr(theItem) % help(theItem) % elseif isobject(theItem) % disp(' ') % if ~isempty(theName) % disp([' ## Name: ' theName]) % end % if isobject(theItem) % disp([' ## Public Class: ' class(theItem)]) % s = super(theItem); % while isobject(s) % disp([' ## Public SuperClass: ' class(s)]) % s = super(s); % end % disp([' ## Protected Methods:']) % theMethods = methods(class(theItem)); % for i = 1:length(theMethods) % if strcmp(class(theItem), theMethods{i}) % disp([' ' class(theItem) '/' theMethods{i} '() // Constructor']) % else % disp([' ' class(theItem) '/' theMethods{i} '()']) % end % end % disp([' ## Private Fields:']), disp(struct(theItem)) % if strcmp(lower(howMuch), 'full') % if isobject(super(theItem)) % disp([' ## Inherited by ' class(theItem) ':']) % describe(super(theItem), 'full') % theItem = super(theItem); % end % end % end % else % disp([' ## Name: ' theName]) % disp([' ## Class: ' class(theItem)]) % disp([' ## Value:']) % disp(theItem) %end fclose(fout); disp(' ## Installing: "dhms.m" (text)') fout = fopen('dhms.m', 'w'); %function theResult = dhms(theArg) % %% dhms -- Convert to/from dhms time-string format. %% dhms('theTimeString') converts 'theTimeString' of %% the form '1d2h3m4s' to decimal days. Multiply %% the result by 86400 to get decimal seconds. %% dhms(theDecimalDays) converts theDecimalDays into a %% time-string of the format '1d2h3m4s', rounded to the %% nearest second. %% dhms (no argument) demonstrates itself. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 16-Oct-1998 18:09:35. % %if nargin < 1, theArg = 'demo'; end % %if isequal(theArg, 'demo') % help(mfilename) % format long % theTimeString = '9d23h59m59s' % theDecimalDays = dhms2d(theTimeString) % theTimeString = d2dhms(theDecimalDays) % format short % return %end % %switch class(theArg) %case 'double' % result = d2dhms(theArg); %case 'char' % result = dhms2d(theArg); %otherwise % help(mfilename) % warning([' ## Invalid argument type: ' class(theArg)]) % result = []; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end % % %function theResult = d2dhms(theDecimalDays) % %% d2dhms -- Convert decimal days to '1d2h3m4s' time-string. %% d2dhms(theDecimalDays) converts theDecimalDays into a %% time-string of the format '1d2h3m4s', rounded to the %% nearest second. %% d2dhms (no argument) demonstrates itself. %% %% Also see: dhms2d. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Oct-1998 08:16:05. % %if nargin < 1 % help(mfilename) % theDecimalDays = 'demo'; %end % %if isequal(theDecimalDays, 'demo') % theDecimalDays = dhms2d('9d23h59m59s') % theTimeString = d2dhms(theDecimalDays) % return %end % %t = theDecimalDays; % %d = fix(t); %t = rem(t, 1) * 24; %h = fix(t); %t = rem(t, 1) * 60; %m = fix(t); %t = rem(t, 1) * 60; %s = round(t); % %result = ''; %if any(d), result = [result int2str(d) 'd']; end %if any(h), result = [result int2str(h) 'h']; end %if any(m), result = [result int2str(m) 'm']; end %if any(s), result = [result int2str(s) 's']; end % %if isempty(result), result = '0s'; end % %if nargout > 0 % theResult = result; %else % disp(result) %end % % %function theResult = dhms2d(theTimeString) % %% dhms2d -- Convert dhms time-string to decimal days. %% dhms('theTimeString') converts 'theTimeString' of %% the form '1d2h3m4s' to decimal days. Multiply %% the result by 86400 to get decimal seconds. %% dhms2d (no argument) demonstrates itself. %% %% Also see: d2dhms. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-Oct-1998 21:19:25. % %if nargin < 1 % help(mfilename) % theTimeString = 'demo'; %end % %if isequal(theTimeString, 'demo') % theTimeString = '9d23h59m60s' % theDecimalDays = dhms2d(theTimeString) % return %end % %t = lower(theTimeString); % %flag = 0; % %if any(t == 's') % t = strrep(t, 's', '*1'); % flag = 1; %end % %if any(t == 'm') % if flag % t = strrep(t, 'm', '*60+'); % else % t = strrep(t, 'm', '*60'); % end % flag = 1; %end % %if any(t == 'h') % if flag % t = strrep(t, 'h', '*3600+'); % else % t = strrep(t, 'h', '*3600'); % end % flag = 1; %end % %if any(t == 'd') % if flag % t = strrep(t, 'd', '*86400+'); % else % t = strrep(t, 'd', '*86400'); % end %end % %result = eval(t) / 86400; % %if nargout > 0 % theResult = result; %else % disp(result) %end % fclose(fout); disp(' ## Installing: "dirinfo.m" (text)') fout = fopen('dirinfo.m', 'w'); %function result = dirinfo % %% dirinfo -- Information about current-directory. %% dirinfo (no argument) returns information about %% the current-directory: number of files, directories, %% and bytes. The tally works recursively through all %% the embedded directories. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Sep-2001 15:15:24. %% Updated 25-Sep-2001 15:20:54. % %files = 0; %dirs = 0; %bytes = 0; % %d = dir; % %for i = 1:length(d) % if d(i).isdir % cd(d(i).name) % y = feval(mfilename); % files = files + y.files; % dirs = dirs + 1; % bytes = bytes + y.bytes; % cd .. % else % files = files + 1; % bytes = bytes + d(i).bytes; % end %end % %x.files = files; %x.dirs = dirs; %x.bytes = bytes; % %if nargout > 0 % result = x; %else % disp(x) %end fclose(fout); disp(' ## Installing: "doubleclick.m" (text)') fout = fopen('doubleclick.m', 'w'); %function theResult = doubleclick(double_click_time) % %% doubleclick -- Trap for double-clicks. %% doubleclick(double_click_time) returns TRUE if a click %% is detected while "doubleclick" itself is executing; %% otherwise, FALSE. Call "doubleclick" at the top %% of a "WindowButtonDown" or "ButtonDown" callback. %% The 'Interruptible' property of the callback-object %% must be 'on'. Default double_click_time is 0.5 sec. %% A valid double-click causes two values to be returned %% in succession: first, a logical(1), then []. The %% latter can be ignored; it represents the first click %% that initiated the process. For a valid single-click, %% only logical(0) is returned. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Jul-1998 09:47:16. %% Updated 04-Sep-2001 02:42:01. % %persistent CLICK_COUNT % Use "persistent in Matlab 5.2+. % %% Increase the following if the %% double-click-time seems too short. % %if nargin < 1, double_click_time = 1/2; end % %DOUBLE_CLICK_TIME = double_click_time; % Seconds. % %if isempty(CLICK_COUNT), CLICK_COUNT = 0; end % %CLICK_COUNT = CLICK_COUNT + 1; % %if CLICK_COUNT == 1 % tic % while isequal(CLICK_COUNT, 1) & toc < DOUBLE_CLICK_TIME, end %end % %drawnow % Process the event-cue. % %% Note: %% Despite the "drawnow" seen above, Matlab does not %% update the "SelectionType" in timely fashion, so %% it cannot be used to trap a double-click properly. % %result = (CLICK_COUNT > 1); % %CLICK_COUNT = []; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ezgrid.m" (text)') fout = fopen('ezgrid.m', 'w'); %function [xi, yi, zi] = ezgrid(x, y, z, nx, ny, doPlot) % %% ezgrid -- Easy GRIDDATA scheme. %% ezgrid('demo') calls "ezgrid(200)". %% ezgrid(N) demonstrates itself with N points (default = 200). %% [xi, yi, zi] = ezgrid(x, y, z, nx, ny, doPlot) grids the z(x, y) %% data, returning ny-by-nx arrays zi(xi, yi). A contour plot %% is shown if "doPlot" evaluates to TRUE. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Apr-2002 11:54:05. %% Updated 02-Apr-2002 12:08:33. % %if nargin < 1, help(mfilename), x = 'demo'; end %if isequal(x, 'demo'), x = 200; end %if ischar(x), x = eval(x); end % %% Demonstration. % %if length(x) == 1 % n = ceil(x); % m = ceil(sqrt(x)); % x = rand(n, 1); % y = rand(n, 1); % z = rand(n, 1); % feval(mfilename, x, y, z, m, m, 1) % return %end % %if nargin < 3, nx = 21; end %if nargin < 4, ny = nx; end %if nargin < 5, doPlot = ~~0; end % %x = x(:); %y = y(:); %z = z(:); % %% Remove (x, y) minima to assist GRIDDATA/QHULL. % %xmin = min(x); %ymin = min(y); % %x = x - xmin; %y = y - ymin; % %% Margin for the grid. % %dx = max(x)/(nx-1); %dy = max(y)/(ny-1); % %% Generate the MESHGRID. % %xlin = linspace(min(x)-dx/2, max(x)+dx/2, nx); %ylin = linspace(min(y)-dy/2, max(y)+dy/2, ny); % %[xxi, yyi] = meshgrid(xlin, ylin); % %% Call GRIDDATA. % %zzi = griddata(x, y, z, xxi, yyi); % %% Restore the minima. % %xxi = xxi + xmin; %yyi = yyi + ymin; % %% Automatic plot. % %if ~~doPlot(:) % figure(gcf) % hold off % contour(xxi, yyi, zzi) % hold on % x = x + xmin; % y = y + ymin; % marker = 'ro'; % if length(x) > 200, marker = 'r+'; end % if length(x) > 1000, marker = 'r.'; end % plot(x, y, marker) % hold off % title([mfilename '(' int2str(length(x)) ')']) % xlabel x % ylabel y % try % zoomsafe on % catch % disp([' ## ZOOMSAFE not available.']) % end %end % %% Output. % %if nargout > 0 % xi = xxi; yi = yyi; zi = zzi; %end fclose(fout); disp(' ## Installing: "fcat.m" (text)') fout = fopen('fcat.m', 'w'); %function theBytesOut = fcat(theInput, theOutput) % %% fcat -- Concatenate files. %% fcat('theInput', 'theOutput') concatenates all files %% encompassed by "dir('theInput')" to 'theOutput' file. %% The output file is created if it does not already %% exist. The number of bytes output is returned. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Jul-2000 15:09:05. %% Updated 19-Jul-2000 15:29:15. % %if nargout > 0, theBytesOut = 0; end % %if nargin < 2, help(mfilename), return, end % %if ischar(theInput) % theInput = dir(theInput); %end % %if isempty(theInput) % disp([' ## ' mfilename ' -- No inputs exist.']) % return %end % %fout = fopen(theOutput, 'a'); % %if fout < 0 % disp([' ## ' mfilename ' -- No such output file: ' theOutput]) % return %end % %bytes_out = 0; % %for i = 1:length(theInput) % w = which(theInput(i).name); % fin = fopen(w, 'r'); % if fin >= 0 % theBytes = fread(fin); % fclose(fin); % if ~isempty(theBytes) % c = fwrite(fout, theBytes); % bytes_out = bytes_out + c; % end % end %end % %fclose(fout); % %if nargout > 0, theBytesOut = bytes_out; end fclose(fout); disp(' ## Installing: "fcomment.m" (text)') fout = fopen('fcomment.m', 'w'); %function status = fcomment(infile, outfile) % %% fcomment -- Convert text file for "load" compatibility. %% fcomment('infile', 'outfile') converts the "infile" to the %% "outfile" by prepending each comment-line with '%' and %% passing all other lines intact. The "uigetfile" and %% "uiputfile" dialogs are invoked if areguments are not %% provided. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 09-Nov-1998 05:37:45. %% Updated 04-Aug-1999 11:16:48. % %if nargin < 1 % help(mfilename) % [theFile, thePath] = uigetfile('*.*', 'Select A File:'); % if ~any(theFile), return, end % infile = [thePath theFile]; %end % %theSuggested = infile; %i = find(theSuggested == filesep); %if any(i), theSuggested(1:i(length(i))) = []; end %i = find(theSuggested == '.'); %if any(i), theSuggested(i(length(i)):length(theSuggested)) = []; end %theSuggested = [theSuggested '.out']; % %if nargin < 2 % [theFile, thePath] = uiputfile(theSuggested, 'Save File As:'); % if ~any(theFile), return, end % outfile = [thePath theFile]; %end % %f = fopen(infile, 'r'); %if f < 0, return; end %g = fopen(outfile, 'w'); %if g < 0, fclose(f); return, end % %while (1) % s = fgets(f); %disp(s) % if isequal(s, -1), break; end % t = upper(s); % if any(t) & any(t >= 'A' & t ~= 'E' & t <= 'Z') % s = ['% ' s]; % end % fwrite(g, s); %end % %fclose(f); %fclose(g); fclose(fout); disp(' ## Installing: "fig2jpeg.m" (text)') fout = fopen('fig2jpeg.m', 'w'); %function theOutputInfo = fig2jpeg(theFilename, theFigure, theQuality) % %% fig2jpeg -- Save a visible figure in JPEG format. %% fig2jpeg('theFilename', theFigure, theQuality) saves theFigure %% (must exist and be visible; default = gcf) to 'theFilename' %% (default = 'unnamed.jpg'), with theQuality (default = 100). %% If no filename is given, the Matlab "uiputfile" dialog is %% invoked. If an output argument is provided, the "imfinfo" %% string is returned. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 03-Jan-2000 17:35:28. %% Updated 04-Jan-2000 14:03:25. % %if nargout > 0, theOutputInfo = []; end % %if ~any(findobj('Type', 'figure', 'Visible', 'on')) % disp(' ## No visible figures.') % return %end % %if nargin < 1 % [f, p] = uiputfile('unnamed.jpg', 'Save Figure As JPEG:'); % if ~any(f) % help(mfilename) % return % end % if p(end) ~= filesep, p(end+1) = filesep; end % theFilename = [p f]; %end %if nargin < 2, theFigure = gcf; end %if nargin < 3, theQuality = 100; end % %theOldFigure = gcf; % %figure(theFigure) %[x, map] = getframe(theFigure); %imwrite(x, map, theFilename, 'jpg', 'Quality', theQuality) % %figure(theOldFigure) % %if nargout > 0 % theOutputInfo = imfinfo(theFilename); %end fclose(fout); disp(' ## Installing: "filepick_install.m" (text)') fout = fopen('filepick_install.m', 'w'); %% Installer: "filepick_install.m" %% Created: 15-Aug-2001 11:19:32. % %function bund_driver % %% bund_driver -- Driver for "bund" bundles. %% bund_driver (no arguments) contains Matlab commands %% to inflate the instructions and files that are %% encoded into the "bund_data" function of this package. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Jun-2001 10:54:16. %% Updated 03-Aug-2001 13:43:17. % %help(mfilename) % %BINARY_TAG = '?'; % %CR = char(13); %LF = char(10); % %comp = upper(computer); %if any(findstr(comp, 'PCWIN')) % Windows. % NL = [CR LF]; %elseif any(findstr(comp, 'MAC2')) % Macintosh. % NL = CR; %else % Unix. % NL = LF; %end % %c = zeros(1, 256); %c(abs('0'):abs('9')) = 0:9; %c(abs('a'):abs('f')) = 10:15; % %disp([' ']) %disp([' ## This installer is ready to expand its contents,']) %disp([' ## starting in the present directory: "' pwd '"']) %disp([' ## To abort, execute an interruption now.']) %disp([' ## Otherwise, to continue, press any key.']) %disp([' ']) % %try % pause %catch % disp([' ## Installation interrupted.']) % disp([' ']) % return %end % %tic % %w = which(mfilename); % %fin = fopen(w, 'r'); %if fin < 0, return, end % %found = ~~0; %while ~found % s = fgetl(fin); % if isequal(s, -1) % fclose(fin); % return % end % s = strrep(s, LF, ''); % Not necessary? % s = strrep(s, CR, ''); % Not necessary? % if isequal(s, 'function bund_data') % found = ~~1; % end %end % %fout = -1; % %done = ~~0; %while ~done % s = fgetl(fin); % if isequal(s, -1) % fclose(fin); % return % end % if length(s) > 0 % if s(1) ~= '%' % f = findstr(s, 'bund_setdir'); % if any(f) % theDir = eval(strrep(s, 'bund_setdir', '')); % status = mkdir(theDir); % switch status % case 1 % disp([' ## Directory created: "' theDir '"']) % case 2 % disp([' ## Directory exists: "' theDir '"']) % otherwise % error([' ## Error while making new directory.']) % end % % try % cd(theDir) % catch % error([' ## Unable to go to directory: "' theDir '"']) % end % else % try % eval(s); % catch % error([' ## Unable to evaluate: "' s '"']) % end % end % elseif length(s) > 1 & s(2) == BINARY_TAG % hx = double(s(3:end)); % Assume hex data. % bin = 16*c(hx(1:2:end)) + c(hx(2:2:end)); % fwrite(fout, bin, 'uchar'); % else % fprintf(fout, '%s', s(2:end)); % fprintf(fout, NL); % end % end %end % %fclose(fin); % %disp([' ## Elapsed time: ' num2str(fix(10*toc)/10) ' s.']) % %function bund_data %bund_setdir('filepick') %bund_setdir('@filepick') % %disp(' ## Installing: "event.m" (text)') %fout = fopen('event.m', 'w'); %%function theResult = Event(self, theMode) %% %%% filepick/event -- Event handler. %%% Event(self) handles mouse events associated %%% with self, a "filepick" object. %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 13-Jun-2001 15:21:01. %%% Updated 14-Jun-2001 15:49:21. %% %%if nargin < 1, help(mfilename), return, end %%if nargin < 2, theMode = 'normal'; end %% %%theFigure = self.itSelf; %% %%theDirectory = findobj(theFigure, 'Tag', 'Directory'); %%theSource = findobj(theFigure, 'Tag', 'Source'); %%theDestination = findobj(theFigure, 'Tag', 'Destination'); %%theOkay = findobj(theFigure, 'Tag', 'Okay'); %% %%theSourceString = get(theSource, 'String'); %%theDestinationString = get(theDestination, 'String'); %% %%theDirectoryString = get(theDirectory, 'String'); %%theDirectoryValue = get(theDirectory, 'Value'); %% %%theTag = get(gcbo, 'Tag'); %%theValue = get(gcbo, 'Value'); %%theOldValue = get(gcbo, 'UserData'); %% %%% Update the GUI. %% %%switch theMode %%case 'update' %% filterspec = self.itsFilterSpec; %% p = pwd; %% if p(end) ~= filesep, p(end+1) = filesep; end %% f = find(p == filesep); %% theDirectoryString = cell(length(f), 1); %% k = 0; %% for i = 1:length(f) %% theDirectoryString{i} = p(k+1:f(i)-1); %% k = f(i); %% end %% set(theDirectory, 'String', theDirectoryString, ... %% 'Value', length(theDirectoryString)) %% theTag = ''; %% files = dir; %% theSourceString = cell(length(files), 1); %% for i = length(files):-1:1 %% name = files(i).name; %% theSourceString{i} = name; %% if files(i).isdir %% name = ['<' name '>']; %% theSourceString{i} = name; %% elseif ~isempty(filterspec) %% okay = ~~0; %% for j = 1:length(filterspec) %% f = findstr1(name, filterspec{j}); %% if any(f), okay = ~~1; break, end %% end %% if ~okay, theSourceString(i) = []; end %% end %% end %% if isempty(theSourceString) %% theSourceString = {'(no files)'}; %% end %% set(theSource, 'String', theSourceString, 'Value', 1, 'UserData', files) %% return %%otherwise %%end %% %%% Process mouse action. %% %%switch lower(theTag) %%case 'directory' %% k = length(theDirectoryString) - theDirectoryValue; %% for i = 1:k, cd .., end %% event(self, 'update') %% return %%case 'source' % Not correct. %% name = theSourceString{theValue}; %% if name(1) == '<' & name(end) == '>' % Directory. %% name = name(2:end-1); %% cd(name) %% event(self, 'update') %% return %% elseif ~isequal(name, '(no files)') %% theSrc = theSource; %% theDst = theDestination; %% theTag = 'Move'; %% end %%case 'destination' %% theSrc = theDestination; %% theDst = theSource; %% theTag = 'Move'; %%otherwise %%end %% %%% Transfer a string. %% %%switch lower(theTag) %%case 'move' %% theSrcList = get(theSrc, 'String'); %% theDstList = get(theDst, 'String'); %% theSrcValue = get(theSrc, 'Value'); %% theDstValue = get(theDst, 'Value'); %% s = theSrcList{theSrcValue}; %% d = theDirectoryString; %% p = ''; %% for i = 1:length(d) %% p = [p d{i} filesep]; %% end %% s = [p s]; %% switch lower(theMode) %% case 'unique' %% theDstList = [theDstList; {s}]; %% theSrcList(theSrcValue) = []; %% theSrcValue = min(theSrcValue, length(theSrcList)); %% theDstValue = length(theDstList); %% case 'multiple' %% if theDst == theDestination %% theDstList = [theDstList; {s}]; %% theDstValue = length(theDstList); %% elseif theDst == theSource %% theSrcList(theSrcValue) = []; %% theSrcValue = min(theSrcValue, length(theSrcList)); %% end %% otherwise %% end %% set(theSrc, 'String', theSrcList, 'UserData', theSrcValue) %% set(theDst, 'String', theDstList, 'UserData', theDstValue) %% if length(theSrcList) > 0, set(theSrc, 'Value', theSrcValue), end %% if length(theDstList) > 0, set(theDst, 'Value', theDstValue), end %% set(theOkay, 'UserData', get(theDestination, 'String')) %%case {'cancel', 'okay'} %% set(theFigure, 'UserData', []) %%otherwise %%end %fclose(fout); % %disp(' ## Installing: "filepick.m" (text)') %fout = fopen('filepick.m', 'w'); %%function [p, f] = filepick(theFilterSpec, theDialogTitle, x, y, varargin) %% %%% filepick/filepick -- Pick one or more files. %%% filepick(filterSpec, dialogTitle, x, y) presents a dialog for %%% selecting one or more files, the full-path names of which are %%% returned in a cell-array. To remove an unwanted selection, %%% click on it. In the directories are marked by <...> triangular %%% brackets. If "Cancel" is chosen, the result will be empty. %%% Several file-filters can be specified as a compact comma-separated %%% list, or as a cell-array of the individual filters, as in: %%% '*.dat,*.nc', or {'*.dat, '*.nc'}. %%% [p, f] = filepick(...) returns the paths and filenames in separate %%% cell-arrays. %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 13-Jun-2001 15:21:01. %%% Updated 14-Jun-2001 15:56:23. %% %%if nargin < 1, theFilterSpec = ''; end %%if nargin < 2, theDialogTitle = 'File Picker'; end %% %%theName = theDialogTitle; %%theMode = 'multiple'; %% %%thePrompt{1} = {'<== Select Files By Single Click ==>'}; %%thePrompt{2} = 'Directory'; %%thePrompt{3} = 'Selected'; %% %%theDirectory = pwd; %%cd(theDirectory) %% %%oldPWD = pwd; %% %%files = dir; %%theSourceList = cell(length(files), 1); %%for i = 1:length(files) %% theSourceList{i} = files(i).name; %%end %% %%theSourceList = [theSourceList(:)]; %%theDestinationList = cell(0, 1); %% %%if nargout > 1, theResult = cell(0, 1); end %% %%theFigure = figure('Name', theName, 'NumberTitle', 'off', ... %% 'WindowStyle', 'modal', 'Visible', 'off', 'Resize', 'off'); %%thePosition = get(theFigure, 'Position'); %%thePosition(2) = thePosition(2) + 0.10 .* thePosition(4); %%thePosition(3) = 0.5 .* thePosition(3); %%thePosition(4) = 0.80 .* thePosition(4); %% %%thePosition(3) = thePosition(3) * 2; %% %%if nargin > 2, thePosition(1) = x; end %%if nargin > 3, thePosition(2) = y; end %% %%set(theFigure, 'Position', thePosition) %% %%fs = theFilterSpec; %%if ~iscell(fs) %% if any(fs) %% if fs(end) ~= ',', fs(end+1) = ','; end %% f = find(fs == ','); %% theFilterSpec = cell(1, length(f)); %% k = 0; %% for i = 1:length(f) %% theFilterSpec{i} = fs(k+1:f(i)-1); %% k = f(i); %% end %% else %% theFilterSpec = []; %% end %%end %% %%theStruct.itSelf = theFigure; %%theStruct.itsFilterSpec = theFilterSpec; %%self = class(theStruct, 'filepick'); %%set(theFigure, 'UserData', self) %% %%if isempty(self), return, end %% %%theFrame = uicontrol('Style', 'frame', 'Visible', 'on', ... %% 'Units', 'normalized', 'Position', [0 0 1 1], ... %% 'BackgroundColor', [0.5 1 1]); %% %%theControls = zeros(7, 1); %%theControls(1) = uicontrol('Style', 'text', 'Tag', 'Label', ... %% 'String', thePrompt{1}, 'HorizontalAlignment', 'center'); %%theControls(2) = uicontrol('Style', 'text', 'Tag', 'Label', ... %% 'String', thePrompt{2}, 'HorizontalAlignment', 'center'); %%theControls(3) = uicontrol('Style', 'text', 'Tag', 'Label', ... %% 'String', thePrompt{3}, 'HorizontalAlignment', 'center'); %%theControls(4) = uicontrol('Style', 'listbox', 'Tag', 'Source', ... %% 'String', theSourceList); %%theControls(5) = uicontrol('Style', 'listbox', 'Tag', 'Destination', ... %% 'String', theDestinationList); %%theControls(6) = uicontrol('Style', 'pushbutton', 'Tag', 'Cancel', ... %% 'String', 'Cancel', 'UserData', []); %%theControls(7) = uicontrol('Style', 'pushbutton', 'Tag', 'Okay', ... %% 'String', 'Okay', 'UserData', theDestinationList); %% %%p = pwd; %%if(p(end) ~= filesep), p(end+1) = filesep; end %%f = find(p == filesep); %%d = cell(length(f), 1); %%k = 0; %%for i = 1:length(d) %% d{i} = p(k+1:f(i)-1); %% k = f(i); %%end %% %%theControls(8) = uicontrol('Style', 'popupmenu', 'Tag', 'Directory', ... %% 'String', d, 'Value', length(d), 'UserData', []); %% %%xx = Inf; %% %%theLayout = [ ... %% 10 10 10 10 10 10 10 10 10 %% 20 20 20 30 30 30 30 30 30 %% 80 80 80 xx xx xx xx xx xx %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% xx 60 60 xx xx xx 70 70 xx]; %% %%uilayout(theControls, theLayout, [2 2 96 92]./100) %%set(theFrame, 'UserData', theControls) %% %%theCallback = ['event(get(gcf, ''UserData''), ''' theMode ''')']; %%set(theControls(4:8), 'Callback', theCallback) %%set(theControls(1:3), 'BackgroundColor', [0.5 1 1]); %% %%if any(findstr(computer, 'MAC')) %% set(theControls(4:5), 'FontName', 'Monaco', ... %% 'FontSize', 12, ... %% 'FontAngle', 'normal', ... %% 'FontWeight', 'normal') %%end %% %%if length(varargin) > 0 %% set(theControls(4:5), varargin{:}) %%end %% %%event(self, 'update') %% %%set(theFigure, 'Visible', 'on') %%waitfor(theFigure, 'UserData', []) %% %%result = get(gco, 'UserData'); %% %%cd(oldPWD) %% %%delete(theFigure) %% %%if nargout < 2 %% p = result; %%else %% p = cell(size(result)); %% f = cell(size(result)); %% for i = 1:length(result) %% [p{i}, f{i}] = fileparts(result{i}); %% end %%end %fclose(fout); % %disp(' ## Installing: "version.m" (text)') %fout = fopen('version.m', 'w'); %%function version(self) %% %%% Version of 31-May-2001 15:27:27. %% %%helpdlg(help(mfilename), 'listpick') %fclose(fout); %cd ('..') % %disp(' ## Installing: "uilayout.m" (text)') %fout = fopen('uilayout.m', 'w'); %%function theResult = uilayout(theControls, theLayout, ... %% thePosition, theMargin) %% %%% uilayout -- Layout for ui controls. %%% uilayout(theControls, theLayout) positions theControls %%% according to theLayout, an array whose entries, taken %%% in sorted order, define the rectangular extents occupied %%% by each control. TheLayout defaults to the shape of %%% theControls array. A one-percent margin is %%% imposed between controls. To define a layout region %%% containing no control, use Inf. %%% uilayout(..., thePosition) confines the controls to the %%% given normalized position of the figure. This syntax %%% is useful for embedding controls within a frame. %%% uilayout(....., theMargin) allows the default margin %%% of 0.01 (normalized units) between controls to be %%% set to another value. %%% uilayout (no argument) demonstrates itself. %% %%% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 18-Apr-1997 08:07:54. %%% Updated 27-Jan-2000 23:05:13. %% %%if nargin < 1, theControls = 'demo'; help(mfilename), end %% %%if strcmp(theControls, 'demo') %% theLayout = [1 2; %% 3 4; %% 5 Inf; %% 5 6; %% 5 Inf; %% 7 8; %% 9 10; %% 11 12; %% 13 14]; %% [m, n] = size(theLayout); %% thePos = get(0, 'DefaultUIControlPosition'); %% theSize = [n+2 m+2] .* thePos(3:4); %% theFigure = figure('Name', 'UILayout', ... %% 'NumberTitle', 'off', ... %% 'Resize', 'off', ... %% 'Units', 'pixels'); %% thePos = get(theFigure, 'Position'); %% theTop = thePos(2) + thePos(4); %% thePos = thePos .* [1 1 0 0] + [0 0 theSize]; %% thePos(2) = theTop - (thePos(2) + thePos(4)); %% set(theFigure, 'Position', thePos); %% theFrame = uicontrol('Style', 'frame', ... %% 'Units', 'normalized', ... %% 'Position', [0 0 1 1], ... %% 'BackgroundColor', [0.5 1 1]); %% theStyles = {'checkbox'; 'text'; ... %% 'edit'; 'text'; ... %% 'listbox'; 'text'; ... %% 'popupmenu'; 'text'; ... %% 'pushbutton'; 'text'; ... %% 'radiobutton'; 'text'; ... %% 'text'; 'text'}; %% theStrings = {'Anchovies?', '<-- CheckBox --', ... %% 'Hello World!', '<-- Edit --', ... %% {'Now', 'Is', 'The' 'Time' 'For' 'All' 'Good', ... %% 'Men', 'To', 'Come' 'To' 'The' 'Aid' 'Of', ... %% 'Their' 'Country'}, ... %% '<-- ListBox --', ... %% {'Cheetah', 'Leopard', 'Lion', 'Tiger', 'Wildcat'}, ... %% '<-- PopupMenu --', ... %% 'Okay', '<-- PushButton --', ... %% 'Cream?', '<-- RadioButton --', ... %% 'UILayout', '<-- Text --'}; %% theControls = zeros(size(theStyles)); %% for i = 1:length(theStyles) %% theControls(i) = uicontrol('Style', theStyles{i}, ... %% 'String', theStrings{i}, ... %% 'Callback', ... %% 'disp(int2str(get(gcbo, ''Value'')))'); %% end %% set(theControls(1:2:length(theControls)), 'BackGroundColor', [1 1 0.5]) %% set(theControls(2:2:length(theControls)), 'BackGroundColor', [0.5 1 1]) %% thePosition = [1 1 98 98] ./ 100; %% feval(mfilename, theControls, theLayout, thePosition) %% set(theFrame, 'UserData', theControls) %% theStyles, theLayout, thePosition %% if nargout > 0, theResult = theFrame; end %% return %%end %% %%if nargin < 2 %% theLayout = zeros(size(theControls)); %% theLayout(:) = 1:prod(size(theControls)); %%end %%if nargin < 3, thePosition = [0 0 1 1]; end %%if nargin < 4, theMargin = 1/100; end %% %%a = theLayout(:); %%a = a(finite(a)); %%a = sort(a); %%a(diff(a) == 0) = []; %% %%b = zeros(size(theLayout)); %% %%for k = 1:length(a) %% b(theLayout == a(k)) = k; %%end %% %%[m, n] = size(theLayout); %% %%set(theControls, 'Units', 'Normalized') %%theMargin = [1 1 -2 -2] * theMargin; %%for k = 1:min(length(theControls), length(a)) %% [i, j] = find(b == k); %% xmin = (min(j) - 1) ./ n; %% xmax = max(j) ./ n; %% ymin = 1 - max(i) ./ m; %% ymax = 1 - (min(i) - 1) ./ m; %% thePos = [xmin ymin (xmax-xmin) (ymax-ymin)] + theMargin; %%if (1) %% thePos = thePos .* thePosition([3 4 3 4]); %% thePos(1:2) = thePos(1:2) + thePosition(1:2); %%end %% set(theControls(k), 'Position', thePos); %%end %% %%if nargout > 0, theResult = theControls; end %fclose(fout); %cd ('..') fclose(fout); disp(' ## Installing: "findobjs.m" (text)') fout = fopen('findobjs.m', 'w'); %function theResult = findobjs(varargin) % %% findobjs -- Smart "findobj" with relational operators. %% findobjs(...) returns handles in the same fashion %% as "findobj", with the added feature of allowing %% a relational-operator to be appended to each %% property-name, as in "findobjs('Type~=', 'line')". %% The "~=" relationship is processed with the %% Matlab "isequal" function; all others rely on %% "feval('operator', ...)". Handles that do not %% possess the given property-names are ignored, %% as are illegal operators. %% findobj('demo') demonstrates itself. %% %% Also see: "help findobj". % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 10-Dec-1999 11:26:09. %% Updated 10-Dec-1999 14:42:23. % %if nargout > 0, theResult = []; end % %if nargin < 1, varargin = {}; end %if isempty(varargin), varargin = {'demo'}; end % %% Demonstration. % %if isequal(varargin{1}, 'demo') % disp(' ') % disp(' ## findobjs demo') % delete(get(gcf, 'Children')) % set(gcf, 'Name', 'findobjs demo') % disp(' ') % s = 'plot(0:10, rand(1, 11), ''o-'')'; % disp([' ## ' s]) % eval(s) % disp(' ') % figure(gcf) % s = 'findobjs(0)'; % disp([' ## ' s]) % eval(s) % disp(' ') % s = 'findobjs(0, ''Type~='', ''axes'', ''Type~='', ''line'')'; % disp([' ## ' s]) % eval(s) % disp(' ') % return %end % %% Get the starting handle. % %theHandle = 0; %if ~ischar(varargin{1}) & ishandle(varargin{1}) % theHandle = varargin{1}; % varargin(1) = []; %end % %% Parse the relational operators, setting %% "==" to the empty-string ''. % %s = []; %for i = 2:2:length(varargin) % k = i/2; % name = lower(varargin{i-1}); % relop = name(name < 'a' | name > 'z'); % if isequal(relop, '=='), relop = ''; end % name = name(name >= 'a' & name <= 'z'); % value = varargin{i}; % s(k).name = name; % s(k).value = value; % s(k).relop = relop; %end % %% Separate the equalities from the others. % %t = s; %for i = length(s):-1:1 % if isempty(s(i).relop) % s(i) = []; % Equality. % else % t(i) = []; % Other. % end %end % %% Get the handles for the equalities, or %% everything if no equalities are given. % %u = []; %for i = 1:length(t) % u{end+1} = t(i).name; % u{end+1} = t(i).value; %end %if isempty(u) % result = findobj(theHandle); %else % result = findobj(theHandle, u{:}); %end % %% Isolate the relational subset, if any. % %if length(s) > 0 % for k = length(result):-1:1 % okay = 0; % try % for i = 1:length(s) % try % val = get(result(k), s(i).name); % catch % break % end % value = s(i).value; % relop = s(i).relop; % % switch relop % case '~=' % okay = ~isequal(val, value); % otherwise % try % okay = feval(relop, val, value); % catch % end % end % % if ~okay, break, end % end % catch % end % if ~all(okay(:)) % result(k) = []; % end % end %end % %% Done. % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) % if isempty(result) % disp(' Empty matrix: 0-by-1') % else % for i = 1:length(result) % disp([' ## ' num2str(result(i), 16) ': ' get(result(i), 'Type')]) % end % end %end fclose(fout); disp(' ## Installing: "findpt.m" (text)') fout = fopen('findpt.m', 'w'); %function [theResult, theIndex, x, y, z] = findpt(theLine, x, y, z) % %% findpt -- Find the current point. %% findpt(theLine) installs "findpt" in theLine (a handle) if called %% directly, rather than as the result of a callback. In this case, %% theLine defaults to all the lines in the current figure. During %% mouse-down and mouse-move, the (x, y, z) location of the nearest %% actual point on the original mouse-down line is displayed near %% the mouse, in the figure-name, and in the Matlab command window. %% Note: A simple down/up mouse-click (no dragging) causes the tag %% to remain on the plot. It can be erased by clicking on it. %% [theLine, theIndex, x, y, z] = findpt(theLine, x, y, z) returns the %% actual point on theLine [default = gcbo], that is nearest (x, y, z) %% [default = present mouse position]. The returned values are packed %% into a single vector if only one output argument is provided. The %% output (x, y, z) are the actual coordinates of the point. If no %% output arguments are given, the (x, y) result is displayed on the %% plot and in the figure-name while the mouse is down. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Updated 06-Jul-1998 10:02:02. % %% N.B. -- The following globals are needed %% for persistence, not for global access. % %global theFigureName %global theFigureNumberTitle %global theLineHandle %global theTextHandle %global theMarkerHandle %global mouseDidMove % %DIGITS = 6; % %if nargin < 1, theLine = gcbo; end % %% If not a callback, install "findpt" %% in all the lines in the figure. % %if isempty(gcbo) % if isempty(theLine) % theLine = findobj(gcf, 'Type', 'line'); % end % if any(theLine) % set(theLine, 'ButtonDownFcn', mfilename) % end % return %end % %if nargin == 1 % switch theLine % case 0 % Mouse up. % if any(theTextHandle) % if any(mouseDidMove) % delete(theTextHandle) % delete(theMarkerHandle) % mouseDidMove = 0; % end % set(gcf, 'Name', theFigureName, 'NumberTitle', theFigureNumberTitle) % theLineHandle = []; % theTextHandle = []; % theMarkerHandle = []; % set(gcf, 'Name', theFigureName, ... % 'NumberTitle', theFigureNumberTitle, ... % 'WindowButtonMotionFcn', '', ... % 'WindowButtonUpFcn', '') % theFigureName = ''; % theFigureNumberTitle = ''; % return % end %case -1 % Mouse move. % a = theFigureName; % b = theFigureNumberTitle; % mouseDidMove = 1; % delete(theTextHandle) % delete(theMarkerHandle) % findpt(theLineHandle) % theFigureName = a; % theFigureNumberTitle = b; % return % otherwise % end %end % %switch get(theLine, 'Type') %case 'line' %otherwise % if nargout > 0, theResult = []; end % return %end % %if nargin < 2 % theCurrentPoint = mean(get(gca, 'CurrentPoint')); % Assume "view(2)". % x = theCurrentPoint(1); % y = theCurrentPoint(2); % z = theCurrentPoint(3); %end % %theXRange = diff(get(gca, 'XLim')); %theYRange = diff(get(gca, 'YLim')); %theZRange = diff(get(gca, 'ZLim')); %theZRange = 1; % Assume "view(2)". % %theXData = get(theLine, 'XData'); %theYData = get(theLine, 'YData'); %theZData = get(theLine, 'ZData'); %emptyZ = 0; %if isempty(theZData) % emptyZ = 1; % theZData = zeros(size(theXData)); %end % %theZTemp = theZData .* 0; % Assume "view(2)". % %dx = (theXData - x) .* theYRange .* theZRange; %dy = (theYData - y) .* theXRange .* theZRange; %dz = (theZTemp - z) .* theXRange .* theYRange; % %dd = dx.^2 + dy.^2 + dz.^2; % %theIndex = find(dd == min(dd)); %if any(theIndex), theIndex = theIndex(1); end % %x = theXData(theIndex); %y = theYData(theIndex); %z = theZData(theIndex); % %result = [theLine, theIndex, x, y, z]; % %% N.B. We need to display the z-value (see below) %% if there is any z-data in the line. % %if nargout > 1 % theResult = theLine; %elseif nargout == 1 % theResult = result; %else % assignin('base', 'ans', result) % theString = [num2str(x, DIGITS) ', ' num2str(y, DIGITS)]; % if ~emptyZ % theString = [theString ', ' num2str(z, DIGITS)]; % end % if (1), disp(theString), end % theString = ['<' theString '>']; % theFigureName = get(gcf, 'Name'); % theFigureNumberTitle = get(gcf, 'NumberTitle'); % set(gcf, 'Name', theString, 'NumberTitle', 'off') % theMarker = get(theLine, 'Marker'); % theColor = get(theLine, 'Color'); % switch theMarker % case 'o' % theMarker = '*'; % otherwise % theMarker = 'o'; % end % theLineHandle = theLine; % theMarkerHandle = line(x, y, ... % 'Marker', theMarker, ... % 'EraseMode', 'xor'); % theTextHandle = text(x, y, theString, ... % 'Tag', mfilename, 'EraseMode', 'xor', ... % 'HorizontalAlignment', 'right', ... % 'VerticalAlignment', 'bottom'); % theButtonDownFcn = 'delete(get(gcbo, ''UserData''))'; % h = [theMarkerHandle; theTextHandle]; % set(h, 'UserData', h, 'ButtonDownFcn', theButtonDownFcn) % set(gcf, 'WindowButtonMotionFcn', 'findpt(-1)') % set(gcf, 'WindowButtonUpFcn', 'findpt(0)') %end fclose(fout); disp(' ## Installing: "findstr1.m" (text)') fout = fopen('findstr1.m', 'w'); %function theResult = findstr1(theText, theString) % %% findstr1 -- Find string, using * wildcard. %% findstr('demo') demonstrates itself. %% findstr1('theText', 'theString') searches 'theText' %% for all examples of 'theString', which may include %% one or more asterisks '*' as wildcards, representing %% zero or more characters. The sought-after string may %% also contain escaped characters, preceeded by backslash %% '\', and followed by one of '\bfnrt'. The routine %% returns or displays the indices of the starts of all %% qualifying strings. Not case-sensitive. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Jan-2000 15:13:15. %% Updated 14-Jun-2001 05:35:04. % %% To do: %% %% 1. Need ? wildcard for single character. %% 2. Need $ for end of line. % %if nargout > 0, theResult = []; end % %if nargin < 1, theText = 'demo'; end % %if nargin < 2 & isequal(theText, 'demo') % help(mfilename) % theCommand = [mfilename '(''abracadabra'', ''a*b*a'')']; % disp(theCommand) % disp(mat2str(eval(theCommand))) % return %end % %if size(theText, 2) == 1, theText = theText.'; end %if size(theString, 2) == 1, theString = theString.'; end % %result = []; % %special = '\bfnrt'; %for i = 1:length(special) % s = ['\' special(i)]; % theString = strrep(theString, s, sprintf(s)); %end % %f = find(theString(1:end-1) == '*'); %if any(length(f) > 1) % theString(f(diff(f) == 1)) = ''; %end % %f = find(theString ~= '*'); %if any(f) % theString = theString(f(1):f(end)); %end % %theString = ['*' theString '*']; %stars = find(theString == '*'); % %if all(theString == '*') % result = 1:length(theText); % stars = []; %end % %len = 0; % %for i = 1:length(stars)-1 % s = theString(stars(i)+1:stars(i+1)-1); % len = len + length(s); % f = findstr(theText, s); % if isempty(f) % result = []; % elseif i == 1 % result = f; % elseif any(result) % okay = find(result+len <= max(f)+length(s)); % Careful. % result = result(okay); % end % if isempty(result), break, end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "fixnl.m" (text)') fout = fopen('fixnl.m', 'w'); %function theResult = fixnl(theInputFile, theOutputFile, oldNL, newNL) % %% fixnl -- Fix newline characters. %% fixnl('theInputFile', 'theOutputFile') repairs the %% newline characters in the text file named 'theInputFile' %% and places the result in 'theOutputFile'. If no input %% file is given, the get/put file dialogs are used. %% The name of the output file is returned. The routine %% assumes that the input file uses either CR or LF or %% [CR LF], and that the output file is to conform to %% the current computer's standard newline scheme, namely %% Macintosh = CR, Unix = LF, and PCWIN = [CR LF], where %% CR = char(13); LF = char(10). %% fixnl('theInputFile', 'theOutputFile', 'oldNL', 'newNL') %% uses the given NL strings, rather than the standard ones. %% For example, users may need to convert [CR CR LF] %% to [CR LF], perhaps due to a mistaken translation %% of a file during an Internet transfer. %% fixnl('oldNL', 'newNL') invokes the get/put dialogs %% to get the filenames. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 24-Apr-1997 14:40:37. %% Updated 01-Nov-2002 15:13:52. % %% Get input file. % %if nargin < 1, theInputFile = ''; end %if nargin < 2, theOutputFile = ''; end % %% Default behavior. Use the get/put dialogs. % %if nargin < 1 % while (1) % result = fixnl('', ''); % if isempty(result) % if nargout > 0, theResult = result; end % return % end % end %end % %% User-defined behavior. Use the get/put dialogs. % %if nargin == 2 & ... % any(theInputFile < char(32)) & ... % any(theOutputFile < char(32)) % oldNL = theInputFile; % newNL = theOutputFile; % while (1) % result = fixnl('', '', oldNL, newNL); % if isempty(result) % if nargout > 0, theResult = result; end % return % end % end %end % %% Normal behavior. % %result = ''; % %if isempty(theInputFile) % theInputFilename = 0; % thePrompt = 'Select File To Convert:'; % [theInputFilename, thePathname] = uigetfile('*', thePrompt); % if ~any(theInputFilename) % if nargout > 0, theResult = result; end % return % end % theInputFile = [thePathname theInputFilename]; % else % theInputFilename = theInputFile; %end % %% Get output file. % %if isempty(theOutputFile) % theOutputFile = 0; % theOutputFilename = theInputFilename; % thePrompt = 'Save Converted File As:'; % [theOutputFilename, thePathname] = ... % uiputfile(theInputFilename, thePrompt); % if ~any(theOutputFilename) % if nargout > 0, theResult = result; end % return % end % theOutputFile = [thePathname theOutputFilename]; % else % theOutputFilename = theOutputFile; %end % %if strcmp(theOutputFile, '.') % theOutputFile = theInputFile; %end % %% Read input file. % %fp = fopen(theInputFile, 'r'); %s = setstr(fread(fp).'); %fclose(fp); % %% Save to temporary file if overwriting. % %if strcmp(lower(theOutputFile), lower(theInputFile)) % theSavedFile = [theInputFile '.saved']; % fp = fopen(theSavedFile, 'w'); % theCount = fwrite(fp, s); % fclose(fp); % if theCount ~= length(s) % disp(' ## Unable to save a copy of the input file.') % if nargout > 0, theResult = result; end % return % end %end % %CR = setstr(13); % Carriage-return. %LF = setstr(10); % Line-feed. %CRLF = [CR LF]; % PC and Vax style. % %if nargin < 4 % c = computer; % if findstr(computer, 'MAC') % Macintosh. % NL = CR; % elseif findstr(computer, 'PCWIN') % PC. % NL = CRLF; % elseif findstr(computer, 'VMS') % Vax VMS. % NL = CRLF; % else % Unix. % NL = LF; % end % % f = find(s == LF); % g = find(s == CR); % if any(f) & any(g) & isequal(g+1, f) % s(f) = ''; % end % % f = find(s == LF); % s(f) = CR; % % if ~isequal(NL, CR) % s = strrep(s, CR, NL); % end %else % s = strrep(s, oldNL, newNL); %end % %% Save to output file. % %fp = fopen([theOutputFile], 'w'); %theCount = fwrite(fp, s); %fclose(fp); % %% Delete temporary file. % %result = theOutputFile; % %if strcmp(lower(theOutputFile), lower(theInputFile)) % if theCount == length(s) % delete(theSavedFile) % else % result = ''; % disp(' ## Error during "fixnl" output.') % disp([' ## Original data are in "' theSavedFile '"']) % end %end % %disp([' ## Newlines fixed -- ' theInputFilename ' ==> ' theOutputFilename]) % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "fpeval.m" (text)') fout = fopen('fpeval.m', 'w'); %function [varargout] = fpeval(theFcn, varargin) % %% fpeval -- FEVAL by full-path name. %% [...] = fpeval('theFcn', ...) performs FEVAL with %% 'theFcn' function, given by its full-path name, %% exclusive of extension. Use this routine to %% execute functions that lie outside the Matlab %% path, including those hidden in "private" %% areas. %% [...] = fpeval({theFcnParts}, ...) will use the %% Matlab "fullfile" function to construct theFcn %% from a list of its part-names. For example, %% {matlabroot, 'toolbox', 'signal', 'private', %% 'chi2conf'} will reach the private chi-square %% confidence routine in the "signal" toolbox. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Nov-1998 09:43:22. % %if nargin < 1, help(mfilename), return, end % %if iscell(theFcn) % theFcn = fullfile(theFcn{:}); %end % %% Separate directory and function names. % %originalFcn = theFcn; % %thePWD = pwd; %theDir = ''; %f = find(theFcn == filesep); %if any(f) % theDir = theFcn(1:f(end)); % theFcn(1:f(end)) = ''; %end % %% Trim extension, if any. % %f = find(theFcn == '.'); %if any(f), theFcn(f(1):end) = ''; end % %% Change directory, then execute. % %try % if ~isempty(theDir), cd(theDir), end % if nargout > 0 % varargout = cell(1, nargout); % [varargout{:}] = feval(theFcn, varargin{:}); % else % feval(theFcn, varargin{:}); % end %catch % disp([' ## ' mfilename ' -- An error occurred while attempting:']) % disp([' ## "' originalFcn '"']) % disp([' ## ' lasterr]) %end % %% Restore directory, no matter what. % %if ~isempty(theDir), cd(thePWD), end fclose(fout); disp(' ## Installing: "fps.m" (text)') fout = fopen('fps.m', 'w'); %function u = fps(p, isSlope, dx, dy) % %% fps -- Fast Poisson solver with boundary values. %% fps(p) solves laplacian(u) = p for u, assuming the %% boundary values are given along the perimeter of %% p and the laplacians are given in the interior. %% fps(p, isSlope) solves using the perimeter of p %% as values of slope, if isSlope is logically TRUE. %% fps(p, isSlope, dx, dy) uses sample intervals dx %% and dy. Defaults = 1 and 1, respectively. %% fps([m n]) demonstrates itself with an n-by-n array %% (default = [20 20]), with an off-center spike. %% Note: for the speediest Fourier transform, use a p %% whose size is a composite of small factors, then %% add 2, such as 33. %% %% Also see: fpt. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Reference: Press, et al., Numerical Recipes, %% Cambridge University Press, 1986 and later. % %% Version of 23-Oct-1998 09:02:58. %% Updated 15-May-2002 11:11:40. % %if nargin < 1, help(mfilename), p = 'demo'; end %if nargin < 2, isSlope = 0; end %if nargin < 3, dx = 1; end %if nargin < 4, dy = 1; end % %if ischar(isSlope), isSlope = eval(isSlope); end %isSlope == any(isSlope(:)); % %if isequal(p, 'demo'), p = 20; end %if ischar(p), p = eval(p); end %if length(p) == 1 % if nargin < 2 % p(2) = p; % else % p(2) = isSlope; % end %end % %if length(p) == 2 % theSize = max(p, 4); % p = zeros(theSize); % [m, n] = size(p); % p(ceil(m/3), ceil(n/3)) = 1; % feval(mfilename, p, isSlope, dx, dy); % return %end % %if nargout < 1, tic; end % %% Fold the boundary into source terms. % %if ~isSlope % theFactor = -1; % Boundary-value scheme. %else % theFactor = +2; % Boundary-slope scheme. %end % %q = p; %for i = 1:2 % q = q.'; % q(2:end-1, 2:end-3:end-1) = ... % q(2:end-1, 2:end-3:end-1) + ... % theFactor * q(2:end-1, 1:end-1:end); %end % %% Extract the interior. % %q = q(2:end-1, 2:end-1); % %% Symmetry: odd if 'value'; even if 'slope'. % %if ~isSlope % theSign = -1; % Odd-symmetry, sine-transform scheme. %else % theSign = +1; % Even-symmetry, cosine-transform scheme. %end % %[m, n] = size(q); %q = [zeros(m, 1) q zeros(m, 1) theSign*fliplr(q)]; %q = [zeros(1, 2*n+2); q; zeros(1, 2*n+2); theSign*flipud(q)]; % %% Fast Poisson Transform. The array q is now twice the size %% of the original p, minus two elements in each direction. %% Thus, to invoke a power-of-two Fourier transform, use %% sizes that themselves are a power-of-two plus one. % %res = fpt(q, 0, dx, dy); % %% Retain relevant piece. % %if ~isSlope % result = p; % result(2:end-1, 2:end-1) = res(2:m+1, 2:n+1); %else % result = res(1:m+2, 1:n+2); %end % %% Output or plot solution. % %if nargout > 0 % u = result; %else % disp([' ## Elapsed time: ' num2str(toc) ' s.']) % subplot(2, 2, 1), surf(p), axis tight % title('Laplacian Data'), xlabel('x'), ylabel('y'), zlabel('p') % subplot(2, 2, 2), surf(result), axis tight % title('Poisson Solution'), xlabel('x'), ylabel('y'), zlabel('u') % subplot(2, 2, 3), plot(p), axis tight % xlabel('x'), ylabel('p') % subplot(2, 2, 4), plot(result), axis tight % xlabel('x'), ylabel('u') % figure(gcf) % [m, n] = size(p); % set(gcf, 'Name',[mfilename ' ' int2str(m) ' ' int2str(n)]) % error_norm = norm(4*del2(result(2:end-1, 2:end-1))-p(2:end-1, 2:end-1)); % disp([' ## Error norm: ' num2str(error_norm)]) %end fclose(fout); disp(' ## Installing: "fpt.m" (text)') fout = fopen('fpt.m', 'w'); %function u = fpt(p, doInverse, dx, dy) % %% fpt -- Fast Poisson transform. %% fpt(p) solves laplacian(u) = p, for matrix u, %% assuming periodic boundary conditions. %% fpt(p, doInverse) performs the inverse-transform %% if "doInverse" is logically TRUE. Default = %% FALSE. %% fpt(p, doInverse, dx, dy) uses sample intervals %% dx and dy. Defaults = 1 and 1, respectively. %% %% Also see: fps, fft2, ifft2. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Reference: Press, et al., Numerical Recipes, %% Cambridge University Press, 1986 and later. % %% Version of 23-Oct-1998 09:02:58. %% Updated 10-Feb-2000 20:51:38. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, doInverse = 0; end %if nargin < 3, dx = 1; end %if nargin < 4, dy = 1; end % %% Compute Fourier weights. % %[m, n] = size(p); % %i = (0:m-1).' * ones(1, n); %j = ones(m, 1) * (0:n-1); % %% The simple formula for unit sample intervals is: % %% weights = 2 * (cos(2*pi*i/m) + cos(2*pi*j/n) - 2); % %% We modify it with the actual dx and dy values, %% where dx runs horizontally and dy runs vertically. % %dx2 = dx*dx; %dy2 = dy*dy; %weights = 2 * (cos(2*pi*i/m)/dy2 + cos(2*pi*j/n)/dx2 - 1/dy2 - 1/dx2); %weights(1, 1) = 1; % %% Solve. % %if ~any(doInverse) % u = ifft2(fft2(p) ./ weights); %else % u = ifft2(fft2(p) .* weights); %end % %if isreal(p), u = real(u); end fclose(fout); disp(' ## Installing: "frot13.m" (text)') fout = fopen('frot13.m', 'w'); %function theResult = frot13(theSource, theDestination) % %% frot13 -- ROT13 applied to a file. %% frot13('demo') risks suicide by operating on itself %% twice in succession. %% frot13('theSource', 'theDestination') performs ROT13 %% on the contents of the 'theSource' file and saves the %% result as the 'theDestination' file, which defaults %% to the name of the source-file. If either filename %% contains a '*' wildcard, the appropriate UIGETFILE/ %% UIPUTFILE dialog is invoked. Additionally, if the %% source filename contains a wildcard, the procedure %% is applied repeatedly until the UIGETFILE dialog %% is cancelled. ROT13 is its own inverse. %% frot13 (no argument) same as frot13('*'). % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Apr-2000 07:47:15. %% Updated 26-Apr-2000 08:26:35. % %if nargout > 0, theResult = 0; end %if nargin < 1, theSource = '*'; help(mfilename), end % %if isequal(theSource, 'demo') % fp = fopen(which(mfilename), 'r'); % before = fread(fp); % fclose(fp); % mlock % for i = 1:2 % disp([' ## ' upper(mfilename) ' Demo Round No. ' int2str(i)]) % feval(mfilename, which(mfilename)) % end % munlock % fp = fopen(which(mfilename), 'r'); % after = fread(fp); % fclose(fp); % if isequal(before, after) % disp([' ## ' upper(mfilename) ' Demo Successful.']) % else % disp([' ## ' upper(mfilename) ' Demo NOT Successful.']) % end % return %end % %if any(theSource == '*') % theFilter = theSource; % theFile = -1; % while any(theFile) % [theFile, thePath] = uigetfile(theFilter, 'Select File For ROT13'); % if ~any(theFile), status = -1; return, end % if thePath(end) ~= filesep, thePath(end+1) = filesep; end % theSource = [thePath theFile]; % if nargin < 2 % result = feval(mfilename, theSource); % else % result = feval(mfilename, theSource, theDestination); % end % end % if nargout > 0, theResult = result; end % return %end % %if nargin < 2 % theDestination = theSource; %elseif any(theDestination == '*') % theFilter = theDestination; % [theFile, thePath] = uiputfile(theFilter, 'Save ROT13 File As') % if ~any(theFile) % if nargout > 0, theResult = -1; end % return % end % if thePath(end) ~= filesep, thePath(end+1) = filesep; end % theDestination = [thePath theFile]; %end % %result = -1; % %fp = fopen(theSource, 'r'); %if fp >= 0 % s = fread(fp); % result = fclose(fp); %end % %r = rot13(s); % %result = -1; % %fp = fopen(theDestination, 'w'); %if fp >= 0 % fwrite(fp, r); % result = fclose(fp); %end % %if nargout > 0, theResult = result; end % % %% ---------- rot13 ---------- % % %function theResult = rot13(theString) % %% rot13 -- Apply "rot13" 13-letter shift to a string. %% rot13('theString') rotates the alphabetic characters %% in theString by 13 characters. Thus, the string %% 'aAnN' goes to 'nNaA'. Non-alphabetic characters %% are not affected. This routine is its own inverse. %% ROT13 is a lightweight encryption scheme used by %% Internet news-groups to obscure text that might %% be considered offensive to some readers. %% rot13 (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Feb-1998 17:18:21. % %if nargin < 1 % help(mfilename) % before = 'Hello World'; % after = rot13(before); % again = rot13(after); % disp([' ## ROT13: ' before ' ==> ' after ' ==> ' again]) % return %end % %s = theString; % %f = find((s >= 'A' & s <= 'M') | (s >= 'a' & s <= 'm')); %g = find((s >= 'N' & s <= 'Z') | (s >= 'n' & s <= 'z')); % %s(f) = s(f) + 13; %s(g) = s(g) - 13; % %if nargout > 0 % theResult = s; %else % disp(s) %end fclose(fout); disp(' ## Installing: "fsearch.m" (text)') fout = fopen('fsearch.m', 'w'); %function fsearch(theString, varargin) % %% fsearch -- String search in files. %% fsearch (no argument) demonstrates itself by %% searching for the word "demo" in its own %% M-file. %% fsearch('theString') searches recursively by invoking %% fsearch('theString', '*', '-r'). %% fsearch('theString', 'file1', 'file2', ...) searches %% just the given files, as interpreted by the Matlab %% "which" function. Names wildcarded with asterisks (*) %% are interpreted by the Matlab "dir" and "which" functions. %% fsearch(..., 'option1', option2', ...) applies the given %% options (must be at end of argument list). %% Options: '-r' as final argument causes recursive %% search, starting at the current directory. %% Also see help on: dir, findstr, which % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Jan-2000 11:27:57. %% Updated 14-Apr-2003 16:19:38. % %% Note: we need to address the "." and ".." problem %% that arises during recursive calls to this function. %% My "dirsafe" function is only part of the solution. % %persistent LEVEL %persistent FOUND % %if nargin < 1 % help(mfilename) % s = 'fsearch(''demo'', ''fsearch.m'')'; % disp(s) % eval(s) % return %end %if nargin < 2, varargin = {'*', '-r'}; end % %if isempty(LEVEL), LEVEL = 0; end %if isempty(FOUND), FOUND = ~~0; end % %CR = char(13); %LF = char(10); %CRLF = [CR LF]; % %isRecursive = ~~0; %if isequal(varargin{end}, '-r') % isRecursive = ~~1; % varargin(end) = []; % if isempty(varargin), varargin = {'*'}; end %end % %for k = 1:length(varargin) % theFiles = varargin{k}; % isWildcard = any(theFiles == '*'); % if isWildcard % d = dirsafe(theFiles); % Need to be careful here. % f = []; % for i = 1:length(d) % if ~d(i).isdir % f{end+1} = d(i).name; % elseif isRecursive % end % end % theFiles = f; % else % theFiles = varargin(k); % end % for j = 1:length(theFiles) % theFileName = theFiles{j}; % if any(theFileName) % theFilePath = which(theFileName); % fp = fopen(theFileName, 'r'); % if fp >= 0 % t = char(fread(fp)).'; % fclose(fp); % t = strrep(t, CRLF, CR); % t = strrep(t, LF, CR); % t(end+1) = CR; % t = [CR t]; % s = lower(t); % theStr = lower(theString); % if any(theStr == '*') % theStr = [theStr '*' CR]; % How to restrict this? % end % pos = findstr1(s, theStr); % Note "findstr1". % if any(pos) % eol = findstr1(s, CR); % before = eol(1:end-1); % after = eol(2:end); % thePrecision = ceil(log10(max(after))); % prev = 0; % for i = 1:length(pos) % f = find(pos(i) > eol(1:end-1) & ... % pos(i) < eol(2:end)); % if any(f) & f > prev % prev = f; % FOUND = ~~1; % theLine = int2str(f); % while length(theLine) < thePrecision % theLine = [' ' theLine]; % end % theText = t(before(f)+1:after(f)-1); % f = find(theText > ' '); % if any(f), theText = theText(f(1):f(end)); end % disp([' ## File "' theFilePath '"; Line ' theLine ' ## ' theText]) % end % end % end % else % disp([' ## Unable to open: ' theFileName]) % end % end % end % if isRecursive % d = dirsafe; % for i = 1:length(d) % if d(i).isdir % thePWD = pwd; % LEVEL = LEVEL+1; % try % cd(d(i).name) % feval(mfilename, theString, varargin{k}, '-r') % catch % disp([' ## Error while processing:']) % disp(theFiles(:)) % end % cd(thePWD) % LEVEL = LEVEL-1; % end % end % end %end % %if LEVEL <= 0 % if ~FOUND, disp([' ## None found.']), end % LEVEL = []; % FOUND = []; %end % % %% ---------- findstr1 ---------- % % % %function theDir = dirsafe(varargin) % %% dirsafe -- DIR which ignores "." and ".." %% dirsafe(...) calls "dir", then removes references %% to the "." and ".." directories, if any. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Sep-2002 16:26:23. %% Updated 18-Sep-2002 16:26:23. % %if nargin < 1 % d = dir; %else % d = dir(varargin{:}); %end % %for i = length(d):-1:1 % if d(i).isdir & all(d(i).name == '.') % d(i) = []; % end %end % %if nargout > 0 % theDir = d; %else % assignin('caller', 'ans', d) % disp(d) %end % % %% ---------- findstr1 ---------- % % % %function theResult = findstr1(theText, theString) % %% findstr1 -- Find string, using * wildcard. %% findstr('demo') demonstrates itself. %% findstr1('theText', 'theString') searches 'theText' %% for all examples of 'theString', which may include %% one or more asterisks '*' as wildcards, representing %% zero or more characters. The sought-after string may %% also contain escaped characters, preceeded by backslash %% '\', and followed by one of '\bfnrt'. The routine %% returns or displays the indices of the starts of all %% qualifying strings. Not case-sensitive. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Jan-2000 15:13:15. %% Updated 04-Jan-2000 21:34:49. % %if nargout > 0, theResult = []; end % %if nargin < 1, theText = 'demo'; end % %if nargin < 2 & isequal(theText, 'demo') % help(mfilename) % theCommand = [mfilename '(''abracadabra'', ''a*b*a'')']; % disp(theCommand) % disp(mat2str(eval(theCommand))) % return %end % %if size(theText, 2) == 1, theText = theText.'; end %if size(theString, 2) == 1, theString = theString.'; end % %special = '\bfnrt'; %for i = 1:length(special) % s = ['\' special(i)]; % theString = strrep(theString, s, sprintf(s)); %end % %while any(findstr(theString, '**')) % theString = strrep(theString, '**', '*'); %end % %f = find(theString ~= '*'); %if any(f) % theString = theString(f(1):f(end)); %end % %theString = ['*' theString '*']; %stars = find(theString == '*'); % %result = []; %len = 0; % %for i = 1:length(stars)-1 % s = theString(stars(i)+1:stars(i+1)-1); % len = len + length(s); % f = findstr(theText, s); % if isempty(f) % result = []; % elseif i == 1 % result = f; % elseif any(result) % okay = find(result+len <= max(f)+length(s)); % Careful. % result = result(okay); % end % if isempty(result), break, end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "genetic.m" (text)') fout = fopen('genetic.m', 'w'); %function [theResult, theFinalCost, theInitialCost] = ... % genetic(theFcn, theParameters, theOptions, empty, varargin) % %% genetic -- Genetic optimization driver. %% genetic('demo') demonstrates itself with 10 parameters. %% genetic(N) demonstrates itself with N parameters (default = 10). %% The procedure combines random vectors genetically, thereby %% redistributing their elements, in hopes of reducing the %% standard-deviation of each vector. The procedure uses %% 3*N parents, 30*N children, 100 iterations, and 0.0001 %% tolerance. %% genetic('theFcn', theParameters, theOptions, [], varargin) minimizes %% theFcn cost-function, using theParameters, a two-column array %% of [xmin xmax], the permitted ranges. TheOptions vector is: %% [#-of-parents; #-of-children; maximum-iterations; maximum-cost]. %% The cost-function will be called repeatedly, using all of the %% evolving parameters at once, followed by the "varargin" arguments, %% if any, until halted by reaching the maximum number of iterations %% or by falling below maximum-cost. (The probabilistic genetic %% actions take place in the "breed" function.) The Fcn input %% is one array, whose columns represent individual solutions, %% plus any additional arguments specified by "varargin". % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 29-Mar-2001 17:08:53. %% Updated 14-Jun-2001 07:26:58. % %if nargin < 1 % help(mfilename) % theFcn = 'demo'; %end % %if isequal(theFcn, 'demo') % theFcn = 10; %end % %if nargin < 2 & ischar(theFcn) % theFcn = eval(theFcn); %end % %if ~ischar(theFcn) % nParameters = theFcn(1); % nParents = 3*nParameters; % nChildren = 10*nParents; % if length(theFcn) > 1 % nParents = theFcn(2); % end % if length(theFcn) > 2 % nChildren = theFcn(3); % end % theFcn = 'std'; % theParameters = zeros(nParameters, 2); % theParameters(:, 2) = 1; % theMaximumIterations = 100; % theMaximumCost = 1e-4; % theOptions = [nParents; nChildren; theMaximumIterations; theMaximumCost]; % tic % [result, theFinalCost, theInitialCost] = ... % feval(mfilename, theFcn, theParameters, theOptions); % t = toc; % disp([' ## Elapsed time: ' num2str(ceil(10*t)/10) ' s.']) % hold off % plot(1:length(theFinalCost), theFinalCost, '-bo', ... % 1:length(theInitialCost), theInitialCost, '-ro') % xlabel('Index') % ylabel('Standard-deviation') % legend final initial % set(gca, 'XLim', [0 length(theFinalCost)+1]) % set(gcf, 'Name', ['Genetic ' int2str(nParameters)]) % return %end % %nParents = theOptions(1); %nChildren = theOptions(2); %theMaximumIterations = theOptions(3); %theMaximumCost = theOptions(4); % %[m, n] = size(theParameters); %nParameters = m; % %sz = [1 nParents+nChildren]; %xmin = repmat(theParameters(:, 1), sz); %xmax = repmat(theParameters(:, 2), sz); %xdif = xmax - xmin; % %xmin_p = xmin(:, 1:nParents); %xdif_p = xmax(:, 1:nParents) - xmin(:, 1:nParents); %xmin_c = xmin(:, 1:nChildren); %xdif_c = xmax(:, 1:nChildren) - xmin(:, 1:nChildren); % %xval = rand(nParameters, nParents) .* xdif_p + ... % xmin_p; % %% Evaluate the parents. % %if isempty(varargin) % theInitialCost = feval(theFcn, xval); %else % theInitialCost = feval(theFcn, xval, varargin{:}); %end % %% Breed many generations by genetic-crossover %% of the parameter-vectors. Once debugged, %% we will add a small amount of genetic-drift, %% to the mix, plus an even smaller amount of %% gross genetic-mutation. % %% Need to trap invalid costs, such as NaN or negative. % %iter = 0; %cost = theInitialCost; % %while iter < theMaximumIterations & all(cost > theMaximumCost) % if iter > 0 & rem(iter, 100) == 0 % disp([' ## iter: ' int2str(iter)]) % cost % end % iter = iter+1; % xval = (xval(:, 1:nParents) - xmin(:, 1:nParents)) ./ ... % xdif(:, 1:nParents); % xnew = breed(xval, nChildren); % if (0) % xnew = drift(xnew); % xnew = mutate(xnew); % end % xnew = xnew .* xdif(:, 1:nChildren) + ... % xmin(:, 1:nChildren); % if isempty(varargin) % newCost = feval(theFcn, xnew); % else % newCost = feval(theFcn, xnew, varargin{:}); % end % %% hello %% xnew %% newCost % %% We need to compute a fitness, then use %% it as the probability of survival. % %% hello % cost = [cost newCost]; % xval = [xval xnew]; % % fitness = exp(-cost); % cumulative = cumsum(fitness); % cumulative = cumulative ./ cumulative(end); % Normalize. % cumulative(end) = 1; % % index = zeros(size(cumulative)); % %% The following features a "while" loop that %% protects the search-scheme, until we discover %% how to make it bullet-proof. We want "f" never %% to be empty. % % okay = ~~0; % while ~okay % okay = ~~1; % r = sort(rand(size(cumulative))); % for i = 1:length(r) % f = find(r(i) <= cumulative); % Very slow: 40% % if isempty(f) % okay = ~~0; % break % else % index(i) = f(1); % end % end % end %% hello %% index % f = find(diff(index) == 0); % if any(f) % index(f) = []; % end % %% hello %% index %% cost % % cost = cost(index); % xval = xval(:, index); % % % hello % [cost, index] = sort(cost); % % xval = xval(:, index); % xval = xval(:, 1:nParents); % cost = cost(1:nParents); %end % %if nargout > 0 % theResult = xval; % theFinalCost = cost; %else % result = xval % cost %end % % %% ---------- breed ---------- % % % %function progeny = breed(parents, nChildren) % %% breed -- Parents breed children. %% breed(parents, nChildren) breds nChildren from %% the given parents. % %DRIFT_PROB = 1e-4; % See the "drift" function below. %DRIFT_AMOUNT = 1e-4; % See the "drift" function below. %MUTATE_PROB = 1e-4; % See the "mutate" function below. % %[m, n] = size(parents); %progeny = zeros(m, nChildren); %for i = 1:2:nChildren % k = floor(rand(1, 2) .* n + 1); % progeny(:, [i i+1]) = crossover(parents(:, k)); % Slow: 10% %end %progeny = drift(progeny, DRIFT_PROB, DRIFT_AMOUNT); %progeny = mutate(progeny, MUTATE_PROB); % % %% ---------- crossover ---------- % % % %function y = crossover(x) % %% crossover -- Genetic crossover. %% crossover(x) combines the two columns of x %% by genetic crossover. % %[m, n] = size(x); % %i = (rand(m, 1) < 0.5); %j = ~i; % %y = zeros(size(x)); %y(:, 1) = x(:, 1) .* i + x(:, 2) .* j; % Slow: 8% %y(:, 2) = x(:, 1) .* j + x(:, 2) .* i; % Slow: 8% % % %% ---------- drift ---------- % % % %function y = drift(x, prob, amount) % %% drift -- Genetic drift by small amounts. %% drift(x, prob, amount) adds genetic-drift %% to the columns of x, by the given small %% probability, in the given amount. % %if nargin < 2, prob = 1e-4; end %if nargin < 3, amount = 1e-4; end % %r = rand(size(x)); %s = 2 * (rand(size(x)) - 0.5); %y = x; %y(r < prob) = y(r < prob) + s(r < prob) .* amount; %y = max(min(y, 1), 0); % % %% ---------- mutate ---------- % % % %function y = mutate(x, prob) % %% mutate -- Genetic mutation by small probabilities. %% mutate(x, prob) mutates the columns of x by the %% given small probability. % %if nargin < 2, prob = 1e-4; end % %r = rand(size(x)); %s = rand(size(x)); %y = x; %y(r < prob) = s(r < prob); fclose(fout); disp(' ## Installing: "geo_simplify.m" (text)') fout = fopen('geo_simplify.m', 'w'); %function [olon, olat] = geo_simplify(lon, lat, frac, nmin) % %% geo_simplify -- NaN-aware driver for geo_simp. %% [olon, olat] = geo_simplify(lon, lat, frac, nmin) calls %% geo_simp independently for each of the NaN-separated %% segments of the (lon, lat) data. The concatenated results %% are returned as (olon, olat). The proportion to be kept %% in the result is given by frac (default = 0.5), a decimal %% fraction between 0 and 1. Nmin (default = 4) specifies %% the smallest segment of the result that will be retained. %% [out] = ... returns the result as one array of [olon olat]. %% geo_simplify(N) demonstrates itself for N points (default = 24), %% containing a NaN in the middle. The result preserves about %% one-third of the original points. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 08-Feb-1999 15:57:00. %% Updated 09-Feb-1999 10:44:56. %% Updated 11-Feb-1999 14:12:56. % %if nargin < 1, help(mfilename), lon = 'demo'; end % %if isequal(lon, 'demo'), lon = 24; end % %if ischar(lon), lon = eval(lon); end % %if length(lon) == 1 % n = lon; % lon = (1:n).'; % lat = cumsum(rand(size(lon))-0.5) .* 10; % lat(ceil(n/2)) = NaN; % frac = 1/3; % nmin = 1; % tic % [lon1, lat1] = geo_simplify(lon, lat, frac); % toc % plot(lon1, lat1, '-*', lon, lat, 'o') % xlabel('lon (degrees)'), ylabel('lat (degrees)') % title('geo\_simplify') % axis equal % set(gcf, 'Name', 'geo_simplify') % figure(gcf) % return %end % %if nargin < 3, frac = 0.5; end %if nargin < 4, nmin = 4; end % %f = find(~isfinite(lon) | ~isfinite(lat)); %f = [0; f; length(lon)+1]; % %lon1 = []; %lat1 = []; %for k = 2:length(f) % i = f(k-1)+1; % j = f(k)-1; % count = j - i + 1; % if count >= nmin % [lo, la] = geo_simp(lon(i:j), lat(i:j), frac); % if length(lo) >= nmin % lon1 = [lon1; lo; NaN]; % lat1 = [lat1; la; NaN]; % end % end %end % %if nargout == 1 % olon = [lon1 lat1]; %elseif nargout > 1 % olon = lon1; % olat = lat1; %else % disp([lon1 lat1]); %end % %function [olon, olat] = geo_simp(lon, lat, nmax, tolerance) % %% geo_simp -- Simplify a (lon, lat) contour. %% [olon, olat] = geo_simp(lon, lat, nmax, tolerance) %% simplifies the (lon, lat) contour, returning nmax points %% if (nmax > 0), or those points that are more significant %% than the given tolerance. The gs_sort() routine is used, %% in which the deviation, not the curvature, is the key %% principle. NaNs are ignored. Nmax may be specified as %% a decimal fraction (0...1), or as an integer > 1. %% [out] = geo_simplity(...) returns [olon olat] in one array. %% geo_simplify(nPoints) demonstrates itself with nPoints %% (random); default = 24. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-Jul-1998 06:40:26. %% Revised 04-Sep-1998 15:29:19. % %% Reference: Douglas, D.H. and T.K. Peucker, Algorithms for %% the reduction of the number of points required to represent %% a digitized line of (sic?) its caricature, Can. Cartogr., %% 10, 112-122, 1973. We have adopted a similar scheme for %% selecting "significant" points. Unlike the D-P algorithm, %% we sort all the points first, then isolate those that satisfy %% our criteria for tolerance or total number of points retained. % %if nargin < 1, help(mfilename), lon = 'demo'; end % %if isequal(lon, 'demo'), lon = 24; end % %if ischar(lon), lon = eval(lon); end % %if length(lon) == 1 % n = lon; % lon = 1:n; % lat = cumsum(rand(size(lon))-0.5) .* 10; % lat(ceil(n/2)) = NaN; % nmax = fix((n+2) ./ 3); % tolerance = 0; % tic % [lon1, lat1] = geo_simp(lon, lat, nmax, tolerance); % toc % plot(lon1, lat1, '-*', lon, lat, 'o') % xlabel('lon (degrees)'), ylabel('lat (degrees)') % title('geo\_simp') % axis equal % set(gcf, 'Name', 'geo_simp') % figure(gcf) % return %end % %if nargin < 3, nmax = length(lon); end %if nargin < 4 % tolerance = 0; % if nmax == 0, nmax = length(lon); end %end % %if nmax > 0 & nmax <= 1 % nmax = round(nmax*length(lon)); %end % %RCF = 180 ./ pi; %x = cos(lat/RCF).*cos(lon/RCF); %y = cos(lat/RCF).*sin(lon/RCF); %z = sin(lat/RCF); % %% Save NaNs. % %xx = x(:); %yy = y(:); %zz = z(:); % %i = find(isfinite(xx) & isfinite(yy) & isfinite(zz)); %j = find(~isfinite(xx) | ~isfinite(yy) | ~isfinite(zz)); %if any(i), xx = xx(i); yy = yy(i); zz = zz(i); end % %% Sort. % %[ind, dev] = gs_sort(xx, yy, zz);