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

📄 ncbevent.m

📁 MATLAB中读写、处理科学数据文件格式NETCDF的程序
💻 M
📖 第 1 页 / 共 2 页
字号:
function theResult = ncbevent(self, theEvent)

% NCBrowser/Event -- Event handler.
%  NCBrowser/Event(self, 'theEvent') handles 'theEvent'
%   sent to self, an NCBrowser object, by the "gcbo".
%   TheEvent is usually the name of the callback.  Each
%   time this routine is called, the NetCDF file object
%   (class "netcdf") is assigned to the command-line
%   variable "nco", and the selected NetCDF item is
%   assigned to "nci".   The "ncb" variable is the
%   current "ncbrowser" object.  The "ncx" variable
%   holds the most recently extracted data.
 
% 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 21-Apr-1997 09:23:56.
% Updated    27-Jul-2000 14:44:40.

if nargin < 1, help(mfilename), return, end
if nargin < 2, theEvent = 'Callback'; end

bluish = [0.25 1 1];
light_blue = [0.75 1 1];
yellow = [1 1 0];
yellowish = [1 1 0.5];
greenish = (bluish + yellow) ./ 2;
purplish = [0.75 0.75 1];

theFigure = self.itSelf;

busy(theFigure)

assignin('base', 'ncb', self)

% Get the current selections.

theGCBO = gcbo;
if isempty(theGCBO)
	theGCBO = findobj(theFigure, 'Type', 'uicontrol', ...
					'Style', 'pushbutton', 'Tag', 'Catalog');
end
theDimname = '';
theVarname = '';
theAttname = '';
theConceptname = '';
theTypename = '';
theNCItem = [];
theNCDim = [];
theNCVar = [];
theNCAtt = [];

theNetCDF = super(self);

f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', 'Dimensions');
theDimnames = get(f, 'String');
if ~iscell(theDimnames), theDimnames = {theDimnames}; end
theDimvalue = get(f, 'Value');
if any(theDimvalue)
   theDimname = theDimnames{theDimvalue};
   theDimPrefix = theDimname(1);
   if theDimPrefix == '*', theDimname(1) = ''; end   % Trouble with '*...'.
   if ~strcmp(theDimname, '-')
%		theNCDim = self(theDimname);
		theNCDim = ncsubsref(self, '()', {theDimname});
	end
end
theDimensions = f;

f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', 'Variables');
theVarnames = get(f, 'String');
if ~iscell(theVarnames), theVarnames = {theVarnames}; end
theVarvalue = get(f, 'Value');
if any(theVarvalue)
   theVarname = theVarnames{theVarvalue};
   theVarPrefix = theVarname(1);
   if theVarPrefix == '*', theVarname(1) = ''; end
   if ~strcmp(theVarname, '-')
%		theNCVar = self{theVarname};   % <== Release 11 Trouble.
		theNCVar = ncsubsref(self, '{}', {theVarname});
	end
end
theVariables = f;

f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', 'Attributes');
theAttnames = get(f, 'String');
if ~iscell(theAttnames), theAttnames = {theAttnames}; end
theAttvalue = get(f, 'Value');
if any(theAttvalue)
   theAttname = theAttnames{theAttvalue};
   theAttPrefix = theAttname(1);
   if theAttPrefix == '*', theAttname(1) = ''; end
   if strcmp(theVarname, '-') | isempty(theNCVar)
      theNCAtt = ncatt(theAttname, self);
     else
      theNCAtt = ncatt(theAttname, theNCVar);
   end
end
theAttributes = f;

f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', 'Properties');
theProps = get(f, 'String');
if theGCBO ~= f, set(f, 'String', '-'), end
theProperties = f;

f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', 'Concepts');
theNames = get(f, 'String');
if ~iscell(theNames), theNames = {theNames}; end
theValue = get(f, 'Value');
if any(theValue), theConceptname = theNames{theValue}; end
theConcepts = f;

f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', 'Types');
theNames = get(f, 'String');
if ~iscell(theNames), theNames = {theNames}; end
theValue = get(f, 'Value');
if any(theValue), theTypename = theNames{theValue}; end
theTypes = f;

if ~isempty(theNCDim), theNCItem = theNCDim; end
if ~isempty(theNCVar), theNCItem = theNCVar; end
if ~isempty(theNCAtt), theNCItem = theNCAtt; end

if any(theGCBO == [theDimensions theVariables theAttributes])
   set([theDimensions theVariables theAttributes], ...
         'BackgroundColor', light_blue)
end

theValue = [];
if strcmp(get(theGCBO, 'Type'), 'uicontrol')
   theValue = get(theGCBO, 'Value');
   theOldValue = get(theGCBO, 'UserData');
end
theOldGCBO = self.itsGCBO;
theTag = get(theGCBO, 'Tag');

% Process the event.

switch lower(theEvent)
case 'buttondownfcn'
   disp([' ## Not yet operational: ' theEvent])
case 'callback'
   switch lower(theTag)
   case 'dimensions'
      self.itsGCBO = theDimensions;
      set(theFigure, 'UserData', self)
      if strcmp(theDimname, '-')
         set(theDimensions, 'Value', theOldValue)
         idle(theFigure), return
      end
      set(theDimensions, 'UserData', theValue)
%		d = self(theDimname);   % Trouble with '*...' names.
		d = ncsubsref(self, '()', {theDimname});
      theProps = mat2str(ncsize(d));
      v = var(d);
      a = att(self);
      if theDimPrefix == '*', theDimPrefix = ''; else, theDimPrefix = '*'; end
      theDimnames{theDimvalue} = [theDimPrefix theDimname];
      theVarnames = [{'-'} ncnames(v)];
      theAttnames = [{'-'} ncnames(a)];
      set(theDimensions, 'BackgroundColor', yellowish);
      set(theDimensions, 'String', theDimnames, 'Value', theDimvalue);
      set(theVariables, 'String', theVarnames, 'Value', 1);
      set(theAttributes, 'String', theAttnames, 'Value', 1);
      set(theProperties, 'String', theProps)
      theTypenames = get(theTypes, 'String');
      theType = datatype(d);
      for i = 1:length(theTypenames)
         set(theTypes, 'Value', i)
         if strcmp(lower(theTypenames{i}), theType)
            set(theTypes, 'UserData', i)
            break
         end
      end
      theConceptnames = get(theConcepts, 'String');
      theName = 'dimension';
      theRecdim = recdim(self);
      if ~isempty(theRecdim) & dimid(theRecdim) == dimid(d)
         theName = 'record dimension';
      end
      for i = 1:length(theConceptnames)
         set(theConcepts, 'Value', i);
         if strcmp(lower(theConceptnames{i}), theName)
            set(theConcepts, 'UserData', i)
            break
         end
      end
   case 'variables'
      self.itsGCBO = theVariables;
      set(theFigure, 'UserData', self)
      if strcmp(theVarname, '-')
         set(theVariables, 'Value', theOldValue)
         idle(theFigure), return
      end
      set(theVariables, 'UserData', theValue)
%		v = self{theVarname};   % <== Release 11 Trouble.
		v = ncsubsref(self, '{}', {theVarname});
      theProps = mat2str(ncsize(v));
      d = dim(v);
      a = att(v);
      theDimnames = [{'-'} ncnames(d)];
      if theVarPrefix == '*', theVarPrefix = ''; else, theVarPrefix = '*'; end
      theVarnames{theVarvalue} = [theVarPrefix theVarname];
      theAttnames = [{'-'} ncnames(a)];
      set(theDimensions, 'String', theDimnames, 'Value', 1);
      set(theVariables, 'String', theVarnames, 'Value', theVarvalue);
      set(theVariables, 'BackgroundColor', yellowish);
      set(theAttributes, 'String', theAttnames, 'Value', 1);
      set(theProperties, 'String', theProps)
      theTypenames = get(theTypes, 'String');
      theType = datatype(v);
      for i = 1:length(theTypenames)
         set(theTypes, 'Value', i)
         if strcmp(lower(theTypenames{i}), theType)
            set(theTypes, 'UserData', i)
            break
         end
      end
      theConceptnames = get(theConcepts, 'String');
      theName = 'variable';
      if iscoord(v), theName = 'coordinate variable'; end
      for i = 1:length(theConceptnames)
         set(theConcepts, 'Value', i);
         if strcmp(lower(theConceptnames{i}), theName)
            set(theConcepts, 'UserData', i)
            break
         end
      end
   case 'attributes'
      self.itsGCBO = theAttributes;
      set(theFigure, 'UserData', self)
      if strcmp(theAttname, '-')
         set(theAttributes, 'Value', theOldValue)
         idle(theFigure), return
      end
      if theAttPrefix == '*', theAttPrefix = ''; else, theAttPrefix = '*'; end
      theAttnames{theAttvalue} = [theAttPrefix theAttname];
      set(theAttributes, 'String', theAttnames, 'Value', theAttvalue)
      set(theAttributes, 'UserData', theValue)
      if strcmp(theVarname, '-')
         v = [];
         a = ncatt(theAttname, self);
      else
%			v = self{theVarname};   % <== Release 11 Trouble.
			v = ncsubsref(self, '{}', {theVarname});
         a = ncatt(theAttname, v);
      end
      theProps = mat2str(a(:));
      set(theAttributes, 'BackgroundColor', yellowish);
      set(theProperties, 'String', theProps)
      theTypenames = get(theTypes, 'String');
      theType = datatype(a);
      for i = 1:length(theTypenames)
         set(theTypes, 'Value', i)
         if strcmp(lower(theTypenames{i}), theType)
            set(theTypes, 'UserData', i)
            break
         end
      end
      theConceptnames = get(theConcepts, 'String');
      theName = 'attribute';
      if isempty(v), theName = 'global attribute'; end
      for i = 1:length(theConceptnames)
         set(theConcepts, 'Value', i);
         if strcmp(lower(theConceptnames{i}), theName)
            set(theConcepts, 'UserData', i)
            break
         end
      end
   case 'concepts'
      if strcmp(theConceptname, '-')
         set(theConcepts, 'Value', get(theConcepts, 'UserData'))
         idle(theFigure), return
      end
      set(theConcepts, 'UserData', theValue)
   case 'types'
      if strcmp(theTypename, '-')
         set(theTypes, 'Value', get(theTypes, 'UserData'))
         idle(theFigure), return
      end
      set(theTypes, 'UserData', theValue)
   case 'properties'
      ncb = self;
      nco = theNetCDF;
      nci = theNCItem;
      ans = theNCItem;
      theStatement = strrep(theProps, '>> ', '');
      f = findstr(theStatement, ' <==');
      if any(f)
         theStatement(f(1):length(theStatement)) = '';
      end
      if ~any(theStatement == '=')
         result = eval(theStatement, '''## ERROR ##''');
      else
         result = [];
         evalin('base', [theStatement ';'], '''## ERROR ##''');
      end
      if isequal(result, '## ERROR ##')
         result = [theStatement ' <== Unable to evaluate.'];
      end
      switch class(result)
      case {'double', 'char'}
         result = ['>> ' mat2str(result)];
      otherwise
         disp(result)
         result = [theStatement ' <== See command window.'];
      end
      set(theProperties, 'String', result)
      idle(theFigure)
      return
   case 'catalog'
      d = dim(self);
      v = var(self);
      a = att(self);
      theDimnames = [{'-'} ncnames(d)];
      theVarnames = [{'-'} ncnames(v)];
      theAttnames = [{'-'} ncnames(a)];
      set(theDimensions, 'String', theDimnames, 'Value', 1, 'UserData', 1);
      set(theVariables, 'String', theVarnames, 'Value', 1, 'UserData', 1);
      set(theAttributes, 'String', theAttnames, 'Value', 1, 'UserData', 1);
      theSize = ncsize(super(self));
      set(theProperties, 'String', mat2str(theSize(1:3)))
      set(theConcepts, 'Value', 1, 'UserData', 1);
      set(theTypes, 'Value', 1, 'UserData', 1);
      self.itsGCBO = [];
      set(theFigure, 'UserData', self)
      theNCItem = theNetCDF;
      assignin('base', 'nci', theNCItem)
      assignin('base', 'ans', theNCItem)
   case {'listing', 'plot'}
      ncbgraph(self, theNCItem, lower(theTag))
      set(theProperties, 'String', theProps)
   case 'info'
      if isempty(theNCItem), theNCItem = theNetCDF; end

⌨️ 快捷键说明

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