⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guido.m

📁 MATLAB中读写、处理科学数据文件格式NETCDF的程序
💻 M
📖 第 1 页 / 共 2 页
字号:
 
% Version of 07-Feb-1998 09:45:56.
% Updated    14-Nov-2001 15:07:51.

if nargout > 0, theResult = []; end
if nargin < 1, help(mfilename), return, end

% Get current selections, recursively if needed.

if nargin < 2
	result = theInfo;
	theFields = fieldnames(result);
	isOkay = 1;
	for i = 1:length(theFields)
		[theValue, okay] = getinfo(theInfo, theFields{i});
		isOkay = isOkay & okay;
		switch class(theValue)
		case 'struct'
			[res, okay] = getinfo(theValue);
			isOkay = isOkay & okay;
			result = setfield(result, theFields{i}, res);
		otherwise
			result = setfield(result, theFields{i}, theValue);
		end
	end
	if nargout > 0
		theResult = result;
	else
		disp(result)
	end
	return
end

% Note: Matlab 6+ does not allow "getfield(a, 'b.c')",
%  unlike previous versions.  We need to parse the
%  'b.c' ourselves, then call "getfield(a, 'b', 'c')".

if ischar(theField) & any(theField == '.')
	theField = [theField '.'];
	f = find(theField == '.');
	theParts = cell(1, length(f));
	k = 0;
	for i = 1:length(f)
		theParts{i} = theField(k+1:f(i)-1);
		k = f(i);
	end
	theField = theParts;
elseif ~iscell(theField)
	theField = {theField};
end

theValue = [];

isOkay = 1;
% eval('theValue = getfield(theInfo, theField);', 'isOkay = 0;');
eval('theValue = getfield(theInfo, theField{:});', 'isOkay = 0;');

result = theValue;

if all(isOkay)
    switch class(theValue)
    case 'cell'
        if isequal(theValue{1}, 'checkbox') | ...
				isequal(theValue{1}, 'radiobutton')
			if length(theValue) < 2, theValue{2} = 0; end
            result = theValue{2};
        else
			if ~iscell(theValue{1}), theValue = {theValue{1}}; end
			if length(theValue) < 2, theValue{2} = 1; end
            result = theValue{1}{theValue{2}};
        end
    otherwise
        result = theValue;
    end
end

if nargout > 0
    theResult = result;
else
    disp(result)
end

% ---------- setinfo ----------%

function [theResult, isOkay] = setinfo(theInfo, theField, theValue)

% setinfo -- Set field value in an "Info" struct.
%  setinfo(theInfo, 'theField', theValue) updates
%   'theField' to theValue in theInfo, a struct
%   that is compatible with the "uigetinfo" function.
%   If 'theField' does not exist, it will be created
%   to receive theValue.
%  [theResult, isOkay] = ... returns isOkay = 0
%   if an error occurred; otherwise, non-zero.
%  setinfo(theInfo, 'theField') invokes "getinfo".
%  setinfo(theInfo) adjusts theInfo to canonical
%   form.
 
% 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 07-Feb-1998 09:45:56.
% Updated    14-Nov-2001 15:21:24.

if nargout > 0, theResult = []; end
if nargin < 1, help(mfilename), return, end

% Put all fields into canonical form.

if nargin < 2
	result = theInfo;
	theFields = fieldnames(result);
	isOkay = 1;
	for i = 1:length(theFields)
		theValue = getfield(result, theFields{i});
		switch class(theValue)
		case 'struct'
			[res, okay] = setinfo(theValue);
			isOkay = isOkay & okay;
			result = setfield(result, theFields{i}, res);
		case 'cell'
			if length(theValue) == 1 & ...
				(isequal(theValue{1}, 'radiobutton') | ...
				isequal(theValue{1}, 'checkbox'))
				theValue{2} = 0;
				result = setfield(result, theFields{i}, theValue);
			elseif length(theValue) == 1 & iscell(theValue{1})
				theValue{2} = 1;
				result = setfield(result, theFields{i}, theValue);
			elseif ~isequal(theValue{1}, 'radiobutton') & ...
					~isequal(theValue{1}, 'checkbox')
				theValue{1} = {theValue{1}};
				theValue{2} = 1;
			else
				theValue;
			end
		otherwise
		end
	end
	if nargout > 0, theResult = result; end
	return
end

[theVal, isOkay] = getinfo(theInfo, theField);

if nargin == 2
    if nargout > 0
        theResult = theVal;
    else
        disp(theVal)
    end
    return
end

if ischar(theField) & any(theField == '.')
	theField = [theField '.'];
	f = find(theField == '.');
	theParts = cell(1, length(f));
	k = 0;
	for i = 1:length(f)
		theParts{i} = theField(k+1:f(i)-1);
		k = f(i);
	end
	theField = theParts;
elseif ~iscell(theField)
	theField = {theField};
end

result = theInfo;

if ~all(isOkay)   % Create a new field.
    isOkay = 1;
% eval('result = setfield(theInfo, theField, theValue);', 'isOkay = 0;');
    eval('result = setfield(theInfo, theField{:}, theValue);', 'isOkay = 0;');
else   % Update an existing field.
	isokay = 1;
% eval('theVal = getfield(theInfo, theField);', 'isOkay = 0;');
	eval('theVal = getfield(theInfo, theField{:});', 'isOkay = 0;');
	if ~isOkay, theVal = []; end
    switch class(theVal)
	case 'cell'
        if isequal(theVal{1}, 'checkbox') | isequal(theVal{1}, 'radiobutton')
			% Do nothing.
		elseif ~iscell(theVal{1})
			theVal{1} = {theVal{1}};
			theVal{2} = 1;
		end
	end
    switch class(theVal)
    case 'cell'
        if isequal(theVal{1}, 'checkbox') | isequal(theVal{1}, 'radiobutton')
            theVal{2} = any(any(theValue));
        else
			switch class(theValue)
			case 'double'
				if theValue > 0 & theValue <= length(theVal{1})
					theVal{2} = theValue;
				end
			otherwise
            	flag = 0;
	            for i = 1:length(theVal{1})
	                if isequal(theVal{1}{i}, theValue)
	                    theVal{2} = i;
	                    flag = 1
	                end
	            end
	            if ~any(flag)   % Append.
	                theVal{1} = [theVal(:); {theValue}];
	                theVal{2} = length(theVal{1});
	            end
			end
% else
% theVal{1} = [{theValue}; theVal(:)];
        end
    otherwise
        theVal = theValue;
    end
    isOkay = 1;
% eval('result = setfield(theInfo, theField, theVal);', 'isOkay = 0;');
    eval('result = setfield(theInfo, theField{:}, theVal);', 'isOkay = 0;');
end

if nargout > 0
    theResult = result;
else
    disp(result)
end

% ---------- uilayout ----------%

function theResult = uilayout(theControls, theLayout, thePosition)

% 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 a simple vertical
%   arrangement of theControls.  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 (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-Dec-1999 06:03:57.

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;
   uilayout(theControls, theLayout, thePosition)
   set(theFrame, 'UserData', theControls)
   theStyles, theLayout, thePosition
   if nargout > 0, theResult = theFrame; end
   return
end

if nargin < 2, theLayout = (1:length(theControls)).'; end
if nargin < 3, thePosition = [0 0 1 1]; 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] ./ 100;
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;
   thePos = thePos .* thePosition([3 4 3 4]);
   thePos(1:2) = thePos(1:2) + thePosition(1:2);
   set(theControls(k), 'Position', thePos);
end

if nargout > 0, theResult = theControls; end

% ---------- hint ----------%

function theResult = hint(theText, theFigureName)

% hint -- Post a message.
%  hint('theText', 'theFigureName') posts 'theText' in the
%   figure named 'theFigureName', which will be created if
%   it does not already exist.  The text can be a string
%   separated by newlines, or a cell of strings.
%  hint('demo') demonstrates itself.
 
% 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 17-Dec-1999 11:31:03.
% Updated    04-Jan-2000 13:40:41.

if nargin < 1, theText = 'demo'; end

if isequal(theText, 'demo')
	hint(help(mfilename), 'Hint Hint')
	return
end

CR = char(13);
LF = char(10);
CRLF = [CR LF];

if nargout > 0, theResult = []; end
if nargin < 1
	help(mfilename)
	theText = help(mfilename);
	for i = 1:3
		theText = [theText theText];
	end
end
if nargin < 2, theFigureName = 'Help'; end

if min(size(theText)) == 1
	theText = theText(:).';
end

if ischar(theText) & size(theText, 1) == 1
	theText = strrep(theText, CRLF, CR);
	theText = strrep(theText, LF, CR);
	if theText(end) ~= CR, theText(end+1) = CR; end
	if theText(1) ~= CR, theText = [CR theText]; end
	f = find(theText == CR);
	if any(f)
		s = cell(length(f)-1, 1);
		for i = 1:length(f)-1
			if f(i)+1 < f(i+1)-1
				s{i} = theText(f(i)+1:f(i+1)-1);
			else
				s{i} = ' ';
			end
		end
		theText = s;
	end
end

theLineCount = size(theText, 1);

theFigure = findobj( ...
					'Type', 'figure', ...
					'Name', theFigureName, ...
					'Tag', [mfilename ' hint'] ...
					);
if isempty(theFigure)
	theFigures = findobj('Type', 'figure');
	if any(theFigures)
		thePosition = get(gcf, 'Position');
		left = thePosition(1);
		top = thePosition(2) + thePosition(4);
	end
	theFigure = figure( ...
					'Name', theFigureName, ...
					'Tag', mfilename, ...
					'Visible', 'off' ...
					);
	if any(theFigures)
		set(theFigure, 'Position', thePosition + [20 -20 0 0])
	end
end

delete(get(theFigure, 'Children'))

theColor = [9 9 9]/10;
theFontName = 'Courier';
if any(findstr(lower(computer), 'mac'))
	theFontName = 'Monaco';
end
theFontSize = 12;
theListBox = uicontrol( ...
				theFigure, ...
				'Style', 'listbox', ...
				'String', theText, ...
				'FontName', theFontName, ...
				'FontSize', theFontSize, ...
				'HorizontalAlignment', 'left', ...
				'BackgroundColor', theColor ...
				);

uilayout(theListBox, 1)

set(theFigure, 'Visible', 'on')
figure(theFigure)

if nargout > 0
	theResult = theFigure;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -