📄 ncbevent.m
字号:
disp(theNCItem)
set(theProperties, 'String', theProps)
case 'extract'
if ~isempty(theNCItem), ncextract(theNCItem, 'ncx'), end
otherwise
end
case 'createfcn'
disp([' ## Not yet operational: ' theEvent])
case 'deletefcn'
assignin('base', 'nco', [])
assignin('base', 'nci', [])
assignin('base', 'ans', [])
close(self)
case 'menucallback'
theTag = get(gcbo, 'Tag');
s = abs(lower(theTag));
f = find((s >= abs('0') & s <= abs('9')) | ...
(s >= abs('a') & s <= abs('z')));
theTag = theTag(f);
set(gcbo, 'Tag', theTag);
switch lower(theTag)
case 'aboutncbrowser'
help ncbrowser
case 'netcdf'
theFile = 0;
[theFile, thePath] = uiputfile('unnamed.nc', 'Save New NetCDF As:');
if any(theFile)
theNCItem = netcdf([thePath theFile], 'clobber');
if ~isempty(theNCItem), theNCItem = close(theNCItem); end
end
case 'dimension'
thePrompts = {'Dimension Name', 'Dimension Size'};
theName = 'unnamedDimension';
theSize = '0';
theInfo = inputdlg(thePrompts, ...
'New NetCDF Dimension', [1], {theName, theSize});
if length(theInfo) > 1
theDimname = theInfo{1};
theDimsize = eval(theInfo{2});
if ~isempty(theDimname) & ~isempty(theDimsize)
% self(theDimname) = theDimsize;
% Note "self1" below. Why not "self"?
% self1 = ncsubsasgn(self, '()', theDimname, theDimsize);
self = ncsubsasgn(self, '()', theDimname, theDimsize);
ncbrefresh(self, super(self))
end
end
set(theProperties, 'String', theProps)
case 'variable'
if any(exist('listpick') == [2 3 6]) % M-, MEX-, or P-file.
thePrompt = {'Enter New Variable Name'};
theVarname = 'unnamedVariable';
theInfo = inputdlg(thePrompt, ...
'New NetCDF Variable', [1], {theVarname});
if length(theInfo) > 0 & ~isempty(theInfo{1})
theVarname = theInfo{1};
thePrompt = {['Select Dimensions For Variable "' theVarname '"']};
theDimnames = [];
theDimnames = feval('listpick', ncnames(dim(theNetCDF)), ...
thePrompt, 'New NetCDF Variable', 'multiple');
if iscell(theDimnames)
if strcmp(theTypename, '-'), theTypename = 'double'; end
theNetCDF{theVarname} = eval(['nc' lower(theTypename) '(theDimnames)']);
ncbrefresh(self, super(self));
end
end
set(theProperties, 'String', theProps)
end
case 'attribute'
theNCParent = theNCItem;
if isempty(theNCParent)
theNCParent = super(self);
theNCItem = theNCParent;
end
switch class(theNCParent)
case {'ncdim', 'ncatt'}
theNCParent = parent(theNCParent);
theNCItem = theNCParent;
end
switch class(theNCParent)
case {'ncbrowser'}
theNCParent = super(self);
theNCItem = theNCParent;
end
thePrompts = {'Attribute Name', 'Attribute Data'};
theName = '';
theData = '''''';
theInfo = inputdlg(thePrompts, ...
'New NetCDF Attribute', [1], {theName, theData});
if length(theInfo) > 1 & ~isempty(theInfo{1})
theName = theInfo{1};
theData = eval(theInfo{2});
if strcmp(theTypename, '-') | isstr(theData)
eval(['theNCParent.' theName ' = theData;'])
else
eval(['theNCParent.' theName ' = nc' lower(theTypename) '(theData);'])
end
ncbrefresh(self, theNCItem)
end
set(theProperties, 'String', theProps)
case 'open'
theNCItem = ncbrowser;
case 'save'
sync(theNetCDF)
case 'saveas' % Save-As, but do not open new file.
sync(theNetCDF)
theFile = 0;
[theFile, thePath] = uiputfile('unnamed.nc', 'Save NetCDF As');
if any(theFile)
theNewNetCDF = netcdf([thePath theFile], 'clobber');
if ~isempty(theNewNetCDF)
theNewNetCDF < super(self);
theNewNetCDF = close(theNewNetCDF);
if isempty(theNewNetCDF) & 0
theOldBrowser = self.itSelf;
theNewBrowser = ncbrowser([thePath theFile], 'write');
if ~isempty(theNewBrowser)
delete(theOldBrowser)
theNCItem = theNewBrowser;
end
end
end
end
case 'done'
delete(theFigure)
return
case 'undo'
disp([' ## Not yet operational: ' theEvent])
case 'cut'
disp([' ## Not yet operational: ' theEvent])
case 'copy'
if ~self.itIsClipboard
theClipboard = netcdf(ncbclipboard(self), 'clobber');
if ~isempty(theClipboard)
for i = 2:length(theDimnames)
d = theDimnames{i};
if d(1) == '*'
d(1) = '';
d = ncdim(d, theNetCDF);
theClipboard < d;
end
end
for i = 2:length(theVarnames)
v = theVarnames{i};
if v(1) == '*'
v(1) = '';
v = ncvar(v, theNetCDF);
d = dim(v);
for j = 1:length(d)
theClipboard < d{j};
end
theClipboard < v;
a = att(v);
for j = 1:length(a)
theClipboard < a{j};
end
% copy(ncvar(v, theNetCDF), theClipboard)
end
end
for i = 2:length(theAttnames)
a = theAttnames{i};
if a(1) == '*'
a(1) = '';
if theVarname(1) ~= '-'
theClipboard < ncatt(a, theNCVar);
else
theClipboard < ncatt(a, theNetCDF);
end
end
end
close(theClipboard)
end
end
case 'paste' % This copies structure, but not data.
if ~self.itIsClipboard
theClipboard = netcdf(ncbclipboard(self), 'nowrite');
if ~isempty(theClipboard)
theNetCDF < theClipboard;
ncbrefresh(self, super(self))
close(theClipboard)
end
end
case 'delete'
disp([' ## Not yet operational: ' theEvent])
case 'showclipboard'
isClipboard = self.itIsClipboard;
if ~self.itIsClipboard
theNCItem = ncbrowser(ncbclipboard(self), 'nowrite');
end
case 'selectall'
switch lower(class(theNCItem))
case 'ncdim'
theCount = 0;
for i = 2:length(theDimnames)
theCount = theCount + (theDimnames{i}(1) == '*');
end
for i = 2:length(theDimnames)
theDimPrefix = theDimnames{i}(1);
if theDimPrefix ~= '*' & theCount < length(theDimnames)-1
theDimnames{i} = ['*' theDimnames{i}];
elseif theDimPrefix == '*' & theCount == length(theDimnames)-1
theDimnames{i}(1) = '';
end
end
set(theDimensions, 'String', theDimnames, 'Value', theDimvalue)
case 'ncvar'
theCount = 0;
for i = 2:length(theVarnames)
theCount = theCount + (theVarnames{i}(1) == '*');
end
for i = 2:length(theVarnames)
theVarPrefix = theVarnames{i}(1);
if theVarPrefix ~= '*' & theCount < length(theVarnames)-1
theVarnames{i} = ['*' theVarnames{i}];
elseif theVarPrefix == '*' & theCount == length(theVarnames)-1
theVarnames{i}(1) = '';
end
end
set(theVariables, 'String', theVarnames, 'Value', theVarvalue)
case 'ncatt'
theCount = 0;
for i = 2:length(theAttnames)
theCount = theCount + (theAttnames{i}(1) == '*');
end
for i = 2:length(theAttnames)
theAttPrefix = theAttnames{i}(1);
if theAttPrefix ~= '*' & theCount < length(theAttnames)-1
theAttnames{i} = ['*' theAttnames{i}];
elseif theAttPrefix == '*' & theCount == length(theAttnames)-1
theAttnames{i}(1) = '';
end
end
set(theAttributes, 'String', theAttnames, 'Value', theAttvalue)
otherwise
end
case {'fillvalue', 'missingvalue', ...
'addoffset', 'scalefactor', ...
'units', ...
'fortranformat', 'cformat', ...
'epiccode', 'comment', ...
'genericname', 'longname', 'shortname'}
if isa(theNCItem, 'ncatt')
a = theNCItem;
theLabel = get(gcbo, 'Label');
result = name(a, theLabel);
if strcmp(theVarname, '-')
a = att(self);
else
% v = self{theVarname}; % <== Release 11 Trouble.
v = ncsubsref(self, '{}', {theVarname});
a = att(v);
end
theAttnames = [{'-'} ncnames(a)];
set(theAttributes, 'String', theAttnames);
end
case 'rename'
thePrompt = ['Rename NetCDF ' theConceptname ' "' ...
name(theNCItem) '" To:'];
theName = {name(theNCItem)};
theNewname = inputdlg(thePrompt, ...
'NetCDF Rename', 1, theName);
theNewname = theNewname{1};
if ~isempty(theNewname) & ~strcmp(theNewname, theName)
name(theNCItem, theNewname)
ncbrefresh(self, theNCItem)
end
set(theProperties, 'String', theProps)
case 'resize'
if isa(theNCItem, 'ncvar') | isa(theNCItem, 'ncdim')
theName = name(theNCItem);
theSize = ncsize(theNCItem);
sz = mat2str(theSize);
thePrompt = ['Resize NetCDF ' theConceptname ' "' ...
theName '" From ' mat2str(theSize) ' To:'];
theNewSize = inputdlg(thePrompt, ...
'NetCDF Resize', 1, {mat2str(theSize)});
if ~isempty(theNewSize)
theNewSize = eval(['[' theNewSize{1} ']'], '[]');
if isequal(size(theSize), size(theNewSize))
busy
result = resize(theNCItem, theNewSize);
idle
if ~isempty(result)
theNCItem = result;
self.netcdf = parent(theNCItem); % Very important.
ncbevent(self) % Re-catalog.
end
else
warndlg('Requested size is incompatible.', ...
'NCBrowser Warning')
end
end
end
set(theProperties, 'String', theProps)
case 'lowercase'
name(theNCItem, lower(name(theNCItem)))
ncbrefresh(self, theNCItem)
case 'uppercase'
name(theNCItem, upper(name(theNCItem)))
ncbrefresh(self, theNCItem)
case {'line', 'circles', 'dots', 'degrees', ...
'contour', 'image', 'listing', ...
'mesh', 'surf', 'pxline'}
switch ncclass(theNCItem)
case 'ncatt'
theNCItem = parent(theNCItem);
otherwise
end
switch ncclass(theNCItem)
case 'ncvar'
ncbgraph(self, theNCItem, lower(theTag))
otherwise
end
set(theProperties, 'String', theProps)
case 'showgraph'
ncbgraph(self)
otherwise
disp([theEvent ':' theTag])
end
idle(theFigure)
case 'refresh'
ncbrefresh(self, theNCItem)
set(theProperties, 'String', theProps)
otherwise
disp([' ## Unknown event: ' theEvent ':' theTag])
end
assignin('base', 'ncb', self)
assignin('base', 'nco', theNetCDF)
assignin('base', 'nci', theNCItem)
assignin('base', 'ans', theNCItem)
idle(theFigure)
if nargout > 0, theResult = theNCItem; end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -