% Installer: "netcdf_install.m" % Created: 30-Apr-2003 11:16:19. 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('netcdf') bund_setdir('@listpick') disp(' ## Installing: "event.m" (text)') fout = fopen('event.m', 'w'); %function theResult = Event(self, theMode) % %% ListMove/Event -- Event handler. %% Event(self) handles mouse events associated %% with self, a "listpick" object. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theMode = 'normal'; end % %theFigure = self.itSelf; % %theSource = findobj(theFigure, 'Tag', 'Source'); %theDestination = findobj(theFigure, 'Tag', 'Destination'); %theOkay = findobj(theFigure, 'Tag', 'Okay'); % %theSourceString = get(theSource, 'String'); %theDestinationString = get(theDestination, 'String'); % %theTag = get(gcbo, 'Tag'); %theValue = get(gcbo, 'Value'); %theOldValue = get(gcbo, 'UserData'); % %switch lower(theTag) %case {'source', 'destination'} % if theValue == 1 & 0 % set(gcbo, 'Value', theOldValue) % return % end %otherwise %end % %switch lower(theTag) %case 'source' % theSrc = theSource; % theDst = theDestination; % theTag = 'Move'; %case 'destination' % theSrc = theDestination; % theDst = theSource; % theTag = 'Move'; %otherwise %end % %switch lower(theTag) %case 'move' % theSrcList = get(theSrc, 'String'); % theDstList = get(theDst, 'String'); % theSrcValue = get(theSrc, 'Value'); % theDstValue = get(theDst, 'Value'); % s = theSrcList{theSrcValue}; % 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: "listpick.m" (text)') fout = fopen('listpick.m', 'w'); %function theResult = ListPick(theSourceList, thePrompt, ... % theName, theMode, varargin) % %% ListPick/ListPick -- Move items from one listbox to another. %% ListPick({theSourceList}, 'thePrompt', 'theName', 'theMode') creates %% a modal dialog with {theSourceList} strings in a listbox, whose items %% can be moved to and from the adjacent listbox by clicking on them. %% The "Okay" button causes the destination list to be returned. %% Otherwise, the empty-list is returned. 'ThePrompt' appears at the %% top of the dialog, and 'theName' is the dialog's figure name. %% 'TheMode' is 'unique' (default) or 'multiple'. In 'unique' mode, %% the clicked item moves from one list to the other, whereas in 'multiple' %% mode, the SourceList remains intact and only copies of its items move %% to and from the destination list. %% ListPick (no argument) demonstrates itself. % %% N.B. Multiple-selections in a listbox can be enabled by setting %% the "Max" property to the maximum number of selections allowed. %% Do not try to set "Value" to 0. If the "String" is set to an %% empty cell array, leave the "Value" as is. %% %% N.B. With an "edit" control, use the "Max" property to specify %% the number of allowed lines, separated by newlines. % %if nargin < 1, help(mfilename), theSourceList = 'demo'; end % %if isstr(theSourceList) & strcmp(theSourceList, 'demo') % theSourceList = {'fum'; 'fi'; 'fee'; 'fo'}; % thePrompt = 'Rearrange' ; % theMode = 'Unique'; % theName = ['ListPick -- ' theMode]; % theList = listpick(theSourceList, thePrompt, theName, theMode) % theNotes = {'do', 'do_', 're', 'mi', 'mi_', 'fa', 'fa_', 'so', 'la', 'la_', 'ti', 'ti_', ... % 'Do', 'Do_', 'Re', 'Mi', 'Mi_', 'Fa', 'Fa_', 'So', 'La', 'La_', 'Ti', 'Ti_', ... % 'DO', 'DO_', 'RE', 'MI', 'MI_', 'FA', 'FA_', 'SO', 'LA', 'LA_', 'TI', 'TI_', ... % 'rest'}; % theSourceList = theNotes; % thePrompt = 'Compose Music' ; % theMode = 'Multiple'; % theName = ['ListPick -- ' theMode]; % theSampleRate = 8192; % t = 2 .* pi .* (0:theSampleRate/2) ./ theSampleRate; % theFundamental = 220; % A below middle-C (264 Hz). % theFrequencies = theFundamental .* (2 .^ (1/12)) .^ (0:length(theNotes)-1); % theFrequencies(length(theFrequencies)) = 0; %% Frequencies from John Pierce's book. % theFrequencies = [220.00, 233.08, 246.94, 261.63, 277.18, 293.66, ... % 311.13, 329.63, 349.23, 369.99, 392.00, 415.30].'; % theFrequencies = theFrequencies * [1 2 4]; % theFrequencies = [theFrequencies(:).', 0]; %% % theSounds = []; % for i = 1:length(theNotes) % theSounds = setfield(theSounds, theNotes{i}, theFrequencies(i)); % end % theSounds; % thePlayedNotes = listpick(theSourceList, thePrompt, theName, theMode) % for i = 1:length(thePlayedNotes) % f = getfield(theSounds, thePlayedNotes{i}); % sound(sin(f .* t), theSampleRate) % end % return %end % %if nargin < 2, thePrompt = '<== Pick Items ==>'; end %if nargin < 3, theName = ''; end %if nargin < 4, theMode = 'unique'; end % %% N.B. We should use the prompt as follows: %% {thePrompt, from_label, to_label}. % %if ~iscell(thePrompt), thePrompt = {thePrompt}; end %if length(thePrompt) < 2, thePrompt{2} = 'From'; end %if length(thePrompt) < 3, thePrompt{3} = 'To'; 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); %set(theFigure, 'Position', thePosition) % %theStruct.itSelf = theFigure; %self = class(theStruct, 'listpick'); %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}); %theControls(2) = uicontrol('Style', 'text', 'Tag', 'Label', ... % 'String', thePrompt{2}); %theControls(3) = uicontrol('Style', 'text', 'Tag', 'Label', ... % 'String', thePrompt{3}); %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); % %theLayout = [ 10 10 10 10 10 10 10 10 % 20 20 20 20 30 30 30 30 % 40 40 40 40 50 50 50 50 % 40 40 40 40 50 50 50 50 % 40 40 40 40 50 50 50 50 % 40 40 40 40 50 50 50 50 % 40 40 40 40 50 50 50 50 % 40 40 40 40 50 50 50 50 % Inf 60 60 Inf Inf 70 70 Inf]; % %uilayout(theControls, theLayout, [2 2 96 92]./100) %set(theFrame, 'UserData', theControls) % %theCallback = ['event(get(gcf, ''UserData''), ''' theMode ''')']; %set(theControls(4:7), '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 % %set(theFigure, 'Visible', 'on') %waitfor(theFigure, 'UserData', []) % %result = get(gco, 'UserData'); % %delete(theFigure) % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 25-Mar-2003 11:36:42. % %helpdlg(help(mfilename), 'listpick') fclose(fout); cd ('..') bund_setdir('@ncatt') disp(' ## Installing: "copy.m" (text)') fout = fopen('copy.m', 'w'); %function theResult = copy(self, theDestination) % %% ncatt/copy -- Copy a NetCDF attribute. %% copy(self, theDestination) copys the NetCDF attribute %% associated with self, an ncatt object, to the location %% associated with theDestination, a netcdf or ncvar object. %% If successful, the new ncatt object is returned; otherwise, %% the empty-matrix [] 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 07-Aug-1997 15:43:32. % %if nargin < 2, help(mfilename), return, end % %result = []; % %switch ncclass(theDestination) %case 'netcdf' % result = ncatt(name(self), datatype(self), self(:), theDestination); %case 'ncvar' % result = ncatt(name(self), datatype(self), self(:), theDestination); %case 'ncatt' % switch ncclass(self) % case 'ncatt' % theDestination(:) = self(:); % result = theDestination; % case {'double', 'char'} % theDestination(:) = self; % result = theDestination; % otherwise % end %otherwise %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "datatype.m" (text)') fout = fopen('datatype.m', 'w'); %function theResult = datatype(self) % %% ncatt/datatype -- Numeric type of an ncatt object. %% datatype(self) returns the numeric type of self, %% an "ncatt" object. % %% 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-Aug-1997 09:42:59. % %if nargin < 1, help(mfilename), return, end % %result = ''; % %theTypes = {'byte', 'char', 'short', 'long', 'float', 'double'}; % %theNCid = ncid(self); % %if theNCid >= 0 % theVarid = varid(self); % theAttname = name(self); % [theType, theLen, status] = ncmex('attinq', theNCid, theVarid, theAttname); % if status >= 0 & ~isstr(theType) % theType = theTypes{theType}; % end %else % theType = self.itsAtttype; %end % %result = theType; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "delete.m" (text)') fout = fopen('delete.m', 'w'); %function theResult = delete(varargin) % %% ncatt/delete -- Delete a NetCDF attribute. %% delete(self) deletes the NetCDF attribute associated %% with self, an "ncatt" object, and returns [] if %% successful. Otherwise, it returns self. %% delete(att1, att2, ...) deletes the given attributes %% and the results in a list. % %% 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-Aug-1997 15:43:32. % %if nargin < 1, help(mfilename), return, end % %% If not all arguments are "ncatt" objects, %% let the the "netcdf" parent inherit. % %if nargin > 1 % all_ncatt = 1; % for i = 1:length(varargin) % switch ncclass(varargin{i}) % case 'ncatt' % otherwise % all_ncatt = 0; break % end % end % if ~all_ncatt % self = varargin{1}; % theParent = parent(parent(self)); % result = delete(theParent, varargin{:}); % if nargout > 0, theResult = result; end % return % end %end % %self = varargin; %status = zeros(size(varargin)); % %for i = 1:length(varargin) % theAtt = varargin{i}; % status(i) = ncmex('attdel', ncid(theAtt), varid(theAtt), name(theAtt)); % if status(i) < 0 % theParent = parent(parent(theAtt)); % theParent = redef(theParent); % if ~isempty(theParent) % status(i) = ncmex('attdel', ncid(theAtt), varid(theAtt), name(theAtt)); % end % end % if status(i) > 0, self{i} = []; end %end % %if length(varargin) == 1, self = self{1}; end % %if all(status >= 0) % result = []; % else % result = self; %end % %if nargout > 0 % theResult = result; %end fclose(fout); disp(' ## Installing: "dim.m" (text)') fout = fopen('dim.m', 'w'); %function theResult = dim(self) % %% ncatt/dim -- Dimensions associated with attributes of the same name. %% dim(self) returns a list of the ncdim objects that are %% associated with variables that have an attribute with the %% same name as self, an ncatt object. % %% 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-Aug-1997 15:43:32. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end % %[ndims, nvars, ngatts, recdim, status] = ... % ncmex('inquire', ncid(self)); %if status < 0, return, end % %result = cell(0, 0); %for i = 1:nvars % varid = i - 1; % [varname, vartype, varndims, vardims, varnatts, status] = ... % ncmex('varinq', ncid(self), varid); % if status >= 0 % nc = ncitem('', ncid(self)); % v = ncvar(varname, nc); % a = att(v); % for j = 1:length(a) % if strcmp(name(a{j}), name(self)) % result = [result dim(v)]; % break % end % end % end %end % %if nargout > 0 % theResult = result; % else % for i = 1:length(result) % disp(name(result{i})) % end %end fclose(fout); disp(' ## Installing: "gt.m" (text)') fout = fopen('gt.m', 'w'); %function theResult = gt(self, other) % %% gt -- Greater-than operator; redirection operator. %% gt(self, other) returns the arithmetic greater-than %% comparison of self with other, for self, an ncatt %% object, and other, an ncatt, double, or char. %% gt(self, other) redirects self, an ncatt object, %% into other, a netcdf or ncvar object. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch class(other) % case {'netcdf', 'ncvar'} % result = copy(self, other); % case 'ncatt' % a = self(:); % b = other(:); % if isequal(size(a), size(b)) | length(b) == 1 % result = (a > b); % end % case {'double', 'char'} % a = self(:); % b = other; % if isequal(size(a), size(b)) | length(b) == 1 % result = (a > b); % end % otherwise % warning(' ## Incompatible arguments.') %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "isglobal.m" (text)') fout = fopen('isglobal.m', 'w'); %function theResult = isglobal(self) % %% ncatt/isglobal -- Is this a global atttribute? %% isglobal(self) returns TRUE (1) if self, an %% ncatt object, represents a global attribute. % %% 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 15-May-1997 11:57:05. % %if nargin < 1, help(mfilename), return, end % %result = (varid(self) < 0); % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "lt.m" (text)') fout = fopen('lt.m', 'w'); %function theResult = lt(self, other) % %% ncatt/lt -- Redirection operator. %% lt(self, other) redirects the contents of other, %% an ncatt, double, or char object, into self, %% an ncatt object. % %% 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-Aug-1997 15:43:32. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch class(other) % case 'ncatt' % result = copy(other, self); % a = self(:); % b = other(:); % if isequal(size(a), size(b)) | length(b) == 1 % result = (a > b); % end % case {'double', 'char'} % a = self(:); % b = other; % if isequal(size(a), size(b)) | length(b) == 1 % result = (a > b); % end % otherwise % warning(' ## Incompatible arguments.') %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "ncatt.m" (text)') fout = fopen('ncatt.m', 'w'); %function self = ncatt(theAttname, theAtttype, theAttvalue, theParent) % %% ncatt/ncatt -- Constructor for ncatt class. %% ncatt(theAttname, theAtttype, theAttvalue, theParent) allocates %% an ncatt object with theAttname, theAtttype, and theAttvalue in %% theParent, a netcdf or an ncvar object. The redirection syntax %% is theParent < ncatt(theAttname, theAtttype, theAttvalue). %% The result is assigned silently to 'ans" if no output %% argument is given. %% ncatt(theAttname, theAttvalue, theParent) uses the class of %% theAttvalue as theAtttype ('char' or 'double'). %% ncatt(theAttname, theParent) returns an ncatt object corresponding %% to the attribute of theAttname in theParent. %% ncatt (no argument) returns a raw "ncatt" object. %% %% N.B. To put/get the conventional '_FillValue' attribute of a variable, %% use 'FillValue_'. % %% 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-Aug-1997 15:45:48. %% Revised 19-Mar-1998 09:37:02. % %if nargin < 1 & nargout < 1, help(mfilename), return, end % %% Basic structure. % %theStruct.itsAtttype = ''; %theStruct.itsAttvalue = ''; % %% Raw object. % %if nargin < 1 & nargout > 0 % self = class(theStruct, 'ncatt', ncitem); % return %end % %if strcmp(theAttname, 'FillValue_'), theAttname = '_FillValue'; end % %if nargin == 2 % theParent = theAtttype; % theNCid = ncid(theParent); % theVarid = varid(theParent); % theAttnum = 0; % [theAtttype, theAttlen, status] = ... % ncmex('attinq', theNCid, theVarid, theAttname); % if status >= 0 % theStruct.itsAtttype = ''; % theStruct.itsAttvalue = ''; % theItem = ncitem(theAttname, theNCid, -1, theVarid, theAttnum); % result = class(theStruct, 'ncatt', theItem); % else % result = []; % end % if nargout > 0 % self = result; % else % ncans(result) % end % return %end % %if nargin == 3 % switch ncclass(theAttvalue) % case {'netcdf', 'ncvar'} % theParent = theAttvalue; % theAttvalue = theAtttype; % theAtttype = ncclass(theAttvalue); % if isa(theParent, 'ncvar') % switch theAttname % case {'_FillValue'} % theAtttype = datatype(theParent); % case {'scale_factor', 'add_offset'} % otherwise % end % end % result = ncatt(theAttname, theAtttype, theAttvalue, theParent); % if nargout > 0 % self = result; % else % ncans(result) % end % return % otherwise % end %end % %if strcmp(theAtttype, 'int'), theAtttype = 'long'; end % %status = 0; %if nargin < 4 % theNCid = -1; % theVarid = -1; % theAttnum = -1; %else % theNCid = ncid(theParent); % theVarid = varid(theParent); % theAttnum = 0; % if isa(theParent, 'ncvar') % switch theAttname % case {'_FillValue'} % theAtttype = datatype(theParent); % case {'scale_factor', 'add_offset'} % otherwise % end % end % if isstr(theAttvalue) % theAttvalue = strrep(theAttvalue, '\0', setstr(0)); % end % theTempname = theAttname; % if (1) % theTempname(:) = '-'; % Is this necessary any longer? % end % status = 0; % [theType, theLen, theStatus] = ... % ncmex('attinq', theNCid, theVarid, theAttname); % if theStatus >= 0 & ~strcmp(theAttname, theTempname) % status = ncmex('attrename', theNCid, theVarid, ... % theAttname, theTempname); % end % if status >= 0 % status = ncmex('attput', theNCid, theVarid, ... % theTempname, theAtttype, -1, theAttvalue); % end % if status < 0 % theNetCDF = redef(parent(theParent)); % if ~isempty(theNetCDF), status = 0; end % if status >= 0 % status = ncmex('attput', theNCid, theVarid, ... % theTempname, theAtttype, -1, theAttvalue); % end % end % if status >= 0 & ~strcmp(theAttname, theTempname) % status = ncmex('attrename', theNCid, theVarid, ... % theTempname, theAttname); % end %end % %if status >= 0 % theStruct.itsAtttype = theAtttype; % theStruct.itsAttvalue = theAttvalue; % result = class(theStruct, 'ncatt', ... % ncitem(theAttname, theNCid, -1, theVarid, theAttnum)); %else % result = []; %end % %if nargout > 0 % self = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "subsasgn.m" (text)') fout = fopen('subsasgn.m', 'w'); %function theResult = subsasgn(self, theStruct, other) % %% ncatt/subsasgn -- Overloaded "()" operator. %% subsref(self, theStruct) processes the subscripting %% operator () for self, an "ncatt" object referenced on %% the lefthand side of an assignment, as in self(i:j) %% = other, self(i:j:k) = other, or self(:) = other. % %% See also: ncatt/subsref. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % Never happens. % result = other; % if nargout > 1 % theResult = result; % else % disp(result) % end % return %end % %result = []; % %if isa(other, 'ncitem'), other = other(:); end % %theNetCDF = parent(parent(self)); %theNCid = ncid(self); %theVarid = varid(self); %theAttname = name(self); %if strcmp(theAttname, 'FillValue') % theAttname = '_Fillvalue'; % theAtttype = datatype(ncvar('', theNCid, -1, theVarid)); % [ignore, theAttlen, status] = ... % ncmex('attinq', theNCid, theVarid, theAttname); %else % [theAtttype, theAttlen, status] = ... % ncmex('attinq', theNCid, theVarid, theAttname); %end %if status < 0, theAtttype = class(other); end % %theAttvalue = self(:); %if isstr(theAttvalue) % Undo escaped-zeros, if any. % theAttvalue = strrep(theAttvalue, '\0', setstr(0)); %end % %theDatatype = datatype(self); %theTypelen = ncmex('typelen', theDatatype); %isUnsigned = unsigned(self); % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %if isa(theSubs, 'cell'), theSubs = theSubs{1}; end % %switch theType %case '()' % if isempty(other) & length(theSubs) == 1 & strcmp(theSubs{1}, ':') % result = delete(self); % Delete. % if nargout > 0 % theResult = result; % else % disp(result) % end % return % end %otherwise %end % %switch theType %case '()' % Attribute data: self(...) % switch theSubs % case ':' % if isstr(other), other = strrep(other, '\0', setstr(0)); end % theAttvalue = other; % otherwise % if isstr(other), other = strrep(other, '\0', setstr(0)); end % theAttvalue(theSubs) = other; % end % if isstr(theAttvalue) % theAttvalue = strrep(theAttvalue, '\0', setstr(0)); % end % if isUnsigned & prod(ncsize(self)) > 0 % nBits = 8*theTypelen; % i = (theAttvalue >= 2^(nBits-1)); % theAttvalue(i) = theAttvalue(i) - 2^nBits; % end % status = ... % ncmex('attput', theNCid, theVarid, theAttname, ... % theAtttype, -1, theAttvalue); % if status < 0 % theNetCDF = redef(theNetCDF); % status = ... % ncmex('attput', theNCid, theVarid, theAttname, ... % theAtttype, -1, theAttvalue); % end % result = self; %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(theResult) %end fclose(fout); disp(' ## Installing: "subsref.m" (text)') fout = fopen('subsref.m', 'w'); %function theResult = subsref(self, theStruct) % %% ncatt/subsref -- Overloaded "{}", ".", and "()" operators. %% subsref(self, theStruct) processes the subscripting %% operator () for self, an "ncatt" object referenced on %% the righthand side of an assignment, such as in %% result = self(...). % %% Also see: ncatt/subsasgn. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % result = self; % if nargout > 0 % theResult = result; % else % disp(theResult) % end % return %end % %result = []; % %theNCid = ncid(self); %theVarid = varid(self); %theAttname = name(self); %theDatatype = datatype(self); %theTypelen = ncmex('typelen', theDatatype); %isUnsigned = unsigned(self); % %if length(theStruct) == 1 % s = theStruct; % theType = s(1).type; % theSubs = s(1).subs; % s(1) = []; % if theNCid >= 0 % [result, status] = ... % ncmex('attget', theNCid, theVarid, theAttname); % if status >= 0 & isstr(result) % result = strrep(result, setstr(0), '\0'); % end % else % result = self.itsAttvalue; % end % switch theType % case '()' % Attribute data: self(...) % if isa(theSubs, 'cell'), theSubs = theSubs{1}; end % switch class(theSubs) % case 'char' % switch theSubs % case ':' % otherwise % warning(' ## Illegal syntax.') % end % case 'double' % result = result(theSubs); % otherwise % warning([' ## Illegal syntax: "' theSubs '"']) % end % if isUnsigned & prod(size(result)) > 0 % result(result < 0) = 2^(8*theTypelen) + result(result < 0); % end % otherwise % warning(' ## Illegal syntax.') % end %else % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(theResult) %end fclose(fout); disp(' ## Installing: "var.m" (text)') fout = fopen('var.m', 'w'); %function theResult = var(self) % %% ncatt/var -- Variables associated with attributes of the same name. %% var(self) returns a list of the ncvar objects that have an %% attribute with the same name as self, an ncatt object. % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end % %[ndims, nvars, ngatts, recdim, status] = ... % ncmex('inquire', ncid(self)); %if status < 0, return, end % %count = 0; %result = cell(0, 0); %for i = 1:nvars % varid = i - 1; % [varname, vartype, varndims, vardims, varnatts, status] = ... % ncmex('varinq', ncid(self), varid); % if status >= 0 % nc = ncitem('', ncid(self)); % v = ncvar(varname, nc); % a = att(ncvar(varname, nc)); % for j = 1:length(a) % if strcmp(name(a{j}), name(self)) % count = count + 1; % result{count} = v; % break % end % end % end %end % %if nargout > 0 % theResult = result; % else % for i = 1:length(result) % disp(name(result{i})) % end %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'ncatt') fclose(fout); cd ('..') bund_setdir('@ncbrowser') disp(' ## Installing: "disp.m" (text)') fout = fopen('disp.m', 'w'); %function disp(self) % %% disp -- Display self. %% disp(self) displays self, an "ncbrowser" object. % %% 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-May-1997 13:39:24. % %if nargin < 1, help(mfilename), return, end % %disp(struct(self)) fclose(fout); disp(' ## Installing: "display.m" (text)') fout = fopen('display.m', 'w'); %function display(self) % %% display -- Display an ncbrowser object. %% display(self) displays self, an ncbrowser object. % %% 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-May-1997 13:43:20. % %if nargin < 1, help(mfilename), return, end % %theName = inputname(1); %disp(' '), disp([theName ' =']), disp(' ') %disp(self) fclose(fout); disp(' ## Installing: "ncbclipboard.m" (text)') fout = fopen('ncbclipboard.m', 'w'); %function theResult = NCBClipboard(self) % %% NCBrowser/NCBClipboard -- NetCDF Browser clipboard file name. %% NCBClipboard(self) returns the full-path name of %% the NetCDF Browser clipboard file. % %% 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 08-May-1997 10:54:11. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = ''; end % %w = which(mfilename); %if any(w) % w(length(w)) = ''; % w = [w 'nc']; %end % %if nargout > 0 % theResult = w; % else % disp(w) %end fclose(fout); disp(' ## Installing: "ncbevent.m" (text)') fout = fopen('ncbevent.m', 'w'); %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 % 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 fclose(fout); disp(' ## Installing: "ncbgraph.m" (text)') fout = fopen('ncbgraph.m', 'w'); %function theResult = NCBGraph(self, theNCItem, theKind) % %% NCBGraph -- Graph data from the NetCDF browser. %% NCBGraph(self, theNCItem, 'theKind') plots the data associated %% with theNCItem selected in self, an "ncbrowser" object, using %% 'theKind' of graphical function: 'plot' (default), 'contour', %% 'image', 'list', 'mesh', or 'surf'. % %% 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-Apr-1997 15:51:05. %% Updated 01-Jan-2000 09:13:08. % %if nargin < 1, help(mfilename), return, end %if nargin < 3, theKind = 'plot'; end % %% Activate the figure. % %theFigure = findobj('Type', 'figure', ... % 'Name', 'NetCDF Browser Graph'); % %switch lower(theKind) %case 'listing' %otherwise % if isempty(theFigure) % theFigure = figure('Name', 'NetCDF Browser Graph', 'Visible', 'off'); % thePos = get(theFigure, 'Position'); % thePos = thePos + thePos([3:4 3:4]) .* [1 1 -2 -2] ./ 10; % set(theFigure, 'Position', thePos, 'Visible', 'on') % end %end % %switch lower(theKind) %case 'listing' %otherwise % figure(theFigure(1)), axes(gca) %end % %if nargin < 2, return, end % %switch ncclass(theNCItem) %case 'ncvar' %case 'ncatt' % theNCItem = parent(theNCItem); % switch ncclass(theNCItem) % case 'ncvar' % otherwise % return % end %otherwise % return %end % %% Plot. % %switch lower(theKind) %case 'line' % result = plot(theNCItem, '-'); %case 'circles' % result = plot(theNCItem, 'o'); %case 'dots' % result = plot(theNCItem, '.'); %case 'degrees' % Very crude at present. % if exist('modplot', 'file') == 2 % y = theNCItem(:); % x = (1:length(y)).'; % result = feval('modplot', x, y, 360); % xlabel('Index Number') % ylabel(labelsafe(name(theNCItem))) % end %case 'contour' % result = contour(theNCItem); %case 'image' % result = image(theNCItem); %case 'listing' % result = listing(theNCItem); % if nargout > 0, theResult = result; end % return %case 'mesh' % result = mesh(theNCItem); %case 'surf' % result = surf(theNCItem); %case 'pxline' % if exist('pxline', 'file') == 2 % h = plot(theNCItem); % x = get(h, 'XData'); y = get(h, 'YData'); c = get(h, 'Color'); % delete(h) % if isa(x, 'cell') % temp = zeros(length(x{1}), length(x)); % for j = 1:length(x) % temp(:, j) = x{j}(:); % end % x = temp; % end % if isa(y, 'cell') % temp = zeros(length(y{1}), length(y)); % for j = 1:length(y) % temp(:, j) = y{j}(:); % end % y = temp; % end % if isa(c, 'cell'), c = c{1}; end % feval('pxline', x(:), y(:), 'Color', c) % end % result = []; %otherwise % result = []; %end % %% Set the title. % %theTitle = name(super(self)); %if length(theTitle) > 0 % f = find(theTitle == filesep); % if any(f) % theTitle(1:f(length(f))) = ''; % end %end %title(labelsafe(theTitle)) % %% Make visible and zoomable. % %set([gcf gca], 'Visible', 'on') % %switch lower(theKind) %case 'pxline' % eval('zoomsafe', ';') %otherwise % eval('zoomsafe', ';') %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "ncbmenu.m" (text)') fout = fopen('ncbmenu.m', 'w'); %function theResult = NCBMenu(self) % %% NCBMenu -- Menus for NCBrowser. %% NCBMenu(self) creates the menus for self, %% an NCBrowser. % %% 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 11:09:13. % %if nargin < 1, help(mfilename), return, end % %theFigure = self.itSelf; % %% The following uses string-matrices, because %% the Matlab makemenu() function has not been %% upgraded for Matlab-5 cell-arrays. % %theLabels = str2mat( ... % '', ... % '>About NCBrowser', ... % '>-', ... % '>New', ... % '>>NetCDF...', ... % '>>-', ... % '>>Dimension...', ... % '>>Variable...', ... % '>>Attribute...', ... % '>Open...', ... % '>-', ... % '>Save', ... % '>Save As...', ... % '>-', ... % '>Done', ... % '', ... % '>Undo', ... % '>-', ... % '>Cut', ... % '>Copy', ... % '>Paste', ... % '>Delete', ... % '>-', ... % '>Select All', ... % '>-', ... % '>Show Clipboard', ... % '', ... % '>Conventions', ... % '>>_FillValue', ... % '>>missing_value', ... % '>>-', ... % '>>scale_factor', ... % '>>add_offset', ... % '>>-', ... % '>>units', ... % '>>-', ... % '>>minimum_value', ... % '>>maximum_value', ... % '>>valid_range', ... % '>>-', ... % '>>C_format', ... % '>>FORTRAN_format', ... % '>>-', ... % '>>title', ... % '>>history', ... % '>>comment', ... % '>>-', ... % '>>description', ... % '>>generic_name', ... % '>>long_name', ... % '>>short_name', ... % '>>-', ... % '>>epic_code', ... % '>-', ... % '>Rename...', ... % '>-', ... % '>Lowercase', ... % '>Uppercase', ... % '>-', ... % '>Resize...', ... % '', ... % '>Line', ... % '>Circles', ... % '>Dots', ... % '>-', ... % '>Degrees', ... % '>-', ... % '>Contour', ... % '>Image', ... % '>Mesh', ... % '>Surf', ... % '>-', ... % '>PXLine', ... % '>-', ... % '>Show Graph' ... % ); % %theCallback = 'ncbevent(''MenuCallback'')'; %theCalls = str2mat( ... % '', ... % NetCDF. % theCallback, ... % About NCBrowser. % '', ... % theCallback, ... % New % theCallback, ... % NetCDF... % '', ... % theCallback, ... % Dimension. % theCallback, ... % Variable. % theCallback, ... % Attribute. % theCallback, ... % Open... % '', ... % theCallback, ... % Save. % theCallback, ... % Save As... % '', ... % theCallback, ... % Done. % '', ... % Edit % '', ... % Undo. % '', ... % '', ... % Cut. % theCallback, ... % Copy. % theCallback, ... % Paste. % '', ... % Clear. % '', ... % theCallback, ... % Select All. % '', ... % theCallback, ... % Show Clipboard. % '', ... % Rename. % '', ... % Conventions. % theCallback, ... % _FillValue. % theCallback, ... % missing_value. % '', ... % theCallback, ... % scale_factor. % theCallback, ... % add_offset. % '', ... % theCallback, ... % units. % '', ... % theCallback, ... % minimum_value. % theCallback, ... % minimum_value. % theCallback, ... % valid_range. % '', ... % theCallback, ... % C_format. % theCallback, ... % FORTRAN_format. % '', ... % theCallback, ... % title. % theCallback, ... % history. % theCallback, ... % comment. % '', ... % theCallback, ... % description. % theCallback, ... % generic_name. % theCallback, ... % short_name. % theCallback, ... % long_name. % '', ... % theCallback, ... % epic_code. % '', ... % theCallback, ... % Rename... % '', ... % theCallback, ... % Lowercase... % theCallback, ... % Uppercase... % '', ... % theCallback, ... % Resize... % '', ... % Graph. % theCallback, ... % Line. % theCallback, ... % Circles. % theCallback, ... % Dots. % '', ... % theCallback, ... % Mod. % '', ... % theCallback, ... % Contour. % theCallback, ... % Image. % theCallback, ... % Mesh. % theCallback, ... % Surf. % '', ... % theCallback, ... % PXLine. % '', ... % theCallback ... % Show Graph. % ); % %theTags = theLabels; % %theMenus = makemenu(theFigure, theLabels, theCalls, theTags); % %% Disabled menus. % %f = findobj(theFigure, 'Type', 'uimenu'); %for i = length(f):-1:1 % theSubMenus = get(f(i), 'Children'); % if isempty(theSubMenus) % theCall = get(f(i), 'Callback'); % if isempty(theCall) | all(theCall == ' ') % set(f(i), 'Enable', 'off') % end % end %end % %if nargout > 0, theResult = theMenus; end fclose(fout); disp(' ## Installing: "ncbplot.m" (text)') fout = fopen('ncbplot.m', 'w'); %function theResult = NCBPlot(self, theNCItem) % %% NCBPlot -- Plot data via the NetCDF browser. %% NCBPlot(self, theNCItem) plots the data associated %% with theNCItem selected in self, an "ncbrowser" %% object. % %% 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-Apr-1997 15:51:05. % %if nargin < 2, help(mfilename), return, end % %% Activate the figure. % %theFigure = findobj('Type', 'figure', ... % 'Name', 'NetCDF Browser Graph'); % %if isempty(theFigure) % theFigure = figure('Name', 'NetCDF Browser Graph', 'Visible', 'off'); % thePos = get(theFigure, 'Position'); % thePos = thePos + thePos([3:4 3:4]) .* [1 1 -2 -2] ./ 10; % set(theFigure, 'Position', thePos, 'Visible', 'on') %end % %figure(theFigure(1)), axes(gca) % %% Plot. % %result = plot(theNCItem); % %% Make visible. % %set([gcf gca], 'Visible', 'on') % %if nargout > 0, theResult = result; end % %if nargout > 0 % theResult = theHandles; %end fclose(fout); disp(' ## Installing: "ncbrefresh.m" (text)') fout = fopen('ncbrefresh.m', 'w'); %function theResult = NCBRefresh(self, theNCItem) % %% NCBRefresh -- Refresh NCBrowser entries. %% NCBRefresh(self, theNCItem) refreshes the NCBrowser, %% assuming the NCItem is the selected item. % %% 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 16:13:42. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theNCItem = []; end % %if isempty(theNCItem), theNCItem = super(self); end % %h = self.itSelf; % %theDimensions = findobj(h, 'Type', 'uicontrol', ... % 'Style', 'listbox', ... % 'Tag', 'Dimensions'); % %theVariables = findobj(h, 'Type', 'uicontrol', ... % 'Style', 'listbox', ... % 'Tag', 'Variables'); % %theAttributes = findobj(h, 'Type', 'uicontrol', ... % 'Style', 'listbox', ... % 'Tag', 'Attributes'); % %theDimvalue = get(theDimensions, 'Value'); %theVarvalue = get(theVariables, 'Value'); %theAttvalue = get(theAttributes, 'Value'); % %theDimnames = ncnames(dim(self)); %theVarnames = ncnames(var(self)); %theAttnames = ncnames(att(self)); % %theName = name(theNCItem); % %switch lower(class(theNCItem)) %case 'netcdf' %case 'ncdim' %theVarnames = ncnames(var(theNCItem)); %case 'ncvar' %theDimnames = ncnames(dim(theNCItem)); %theAttnames = ncnames(att(theNCItem)); %case 'ncatt' %theAttnames = ncnames(att(parent(theNCItem))); %otherwise %end % %theDimnames = [{'-'} theDimnames]; %theVarnames = [{'-'} theVarnames]; %theAttnames = [{'-'} theAttnames]; % %switch lower(class(theNCItem)) %case 'netcdf' %case 'ncdim' % theDimnames{theDimvalue} = ['*' theDimnames{theDimvalue}]; %case 'ncvar' % theVarnames{theVarvalue} = ['*' theVarnames{theVarvalue}]; %case 'ncatt' % theAttnames{theAttvalue} = ['*' theAttnames{theAttvalue}]; %otherwise %end % %set(theDimensions, 'String', theDimnames, 'Value', theDimvalue) %set(theVariables, 'String', theVarnames, 'Value', theVarvalue) %set(theAttributes, 'String', theAttnames, 'Value', theAttvalue) % %if nargout > 0, theResult = theNCItem; end fclose(fout); disp(' ## Installing: "ncbrowser.m" (text)') fout = fopen('ncbrowser.m', 'w'); %function self = NCBrowser(theNetCDFFile, thePermission) % %% NCBrowser/NCBBrowser -- NetCDF Browser. %% NCBBrowser'(theNetCDFFile', 'thePermission') creates a %% browser for 'theNetCDFFile', opened with 'thePermission' %% (default = 'nowrite'). The "uigetfile" dialog is used if %% no file or wildcard is given. The "netcdf" object is %% assigned to the variable "nco" in the "base" workspace, %% and the "nci" variable will subsequently hold the currently %% selected NetCDF item. The "ncb" variable is always the current %% "ncbrowser" object. The "ncbrowser" is assigned silently to %% "ans" if no output argument is given. Files are opened with %% 'nowrite' permission by default. %% NCBrowser('thePermission') opens the selected file with %% 'thePermission', either 'nowrite' or 'write'. Files are %% opened with 'nowrite' permission by default. %% %% Menus: %% Menu %% New >>> %% NetCDF... -- New NetCDF file via "uiputfile" dialog. %% Dimension... -- New NetCDF dimension via dialog. %% Variable... -- New NetCDF variable via dialogs. %% Attribute... -- New NetCDF attribute via dialog. %% Open... -- Open NetCDF file via "uigetfile" dialog. %% Save -- Synchronize the NetCDF file. %% Save As... -- Save NetCDF file via "uiputfile" dialog. %% Done -- Close NetCDF file and delete the browser. %% Menu %% Undo -- Not used. %% Cut -- Not used. %% Copy -- Copy current NetCDF selection(s) to clipboard. %% Paste -- Paste clipboard contents to current NetCDF file. %% Delete -- Not used. %% Select All -- Select all items of the selected kind. %% Show Clipboard -- Show clipboard in new NetCDF browser. %% Menu %% Conventions >>> -- Rename to various NetCDF conventions. %% Rename... -- Rename current selection via dialog. %% Uppercase -- Rename current selection to all uppercase. %% Lowercase -- Rename current selection to all lowercase. %% Menu %% Line -- Line-graph of selected variable (EPIC-aware). %% Circles -- Graph with "o" symbols only. %% Dots -- Graph with "." symbols only. %% Degrees -- Line-graph with mod-180 pen-up. %% Contour -- Default contour plot of 2-d data. %% Image -- Image of 2-d data. %% Mesh -- Mesh plot of 2-d data. %% Surf -- Surface plot of 2-d data. %% PXLine -- Experimental interactive line plot. %% Show Graph -- Bring graph window to front. %% %% Buttons: %% Catalog -- Show full catalog of NetCDF file. %% Info -- Display information about selected item. %% Listing -- Display contents of selected variable. %% Extract -- Dialog for extracting data from selection. %% %% Workspace Aliases: %% ncb -- The "ncbrowser" object. %% nco -- The "netcdf" object. %% nci -- The selected object. %% ncx -- The 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 18-Apr-1997 15:33:51. %% Updated 11-Jan-2002 05:57:21. % %disp(' ## NCBrowser is a work-in-progress.') %disp(' ## Not all menu items are implemented.') %disp(' ## See "help ncbrowser".') % %bluish = [0.25 1 1]; %light_blue = [0.75 1 1]; %yellowish = [1 1 0.25]; %yellowish = [1 1 0.5]; %reddish = [1 0.5 0.5]; %greenish = [0.5 1 0.5]; % %if nargin < 1, theNetCDFFile = ''; end %if nargout > 0, theResult = []; end % %if isa(theNetCDFFile, 'netcdf') % theNetCDFFile = name(theNetCDFFile); %end % %if nargin < 2 % switch theNetCDFFile % case {'nowrite', 'write'} % thePermission = theNetCDFFile; % theNetCDFFile = ''; % otherwise % thePermission = 'nowrite'; % end %end % %% Can use shorthand "r" or "w" if three arguments. % %switch thePermission %case 'w' % thePermission = 'write'; %case 'r' % thePermission = 'nowrite'; %end % %if isempty(theNetCDFFile), theNetCDFFile = '*'; end % %if isstr(theNetCDFFile) & any(theNetCDFFile == '*') % theFile = 0; % [theFile, thePath] = ... % uigetfile(theNetCDFFile, 'Select NetCDF File:'); % if ~any(theFile), return, end % theNetCDFFile = [thePath theFile]; % elseif isstr(theNetCDFFile) % theNetCDFFile = which(theNetCDFFile); %end % %x = inf; % %theLayout = [ 99 99 99 99 99 99 99 99 99 % Title. % 1 1 1 2 2 2 3 3 3 % Labels. % 4 4 4 5 5 5 6 6 6 % 4 4 4 5 5 5 6 6 6 % 4 4 4 5 5 5 6 6 6 % 4 4 4 5 5 5 6 6 6 % 4 4 4 5 5 5 6 6 6 % 4 4 4 5 5 5 6 6 6 % 7 7 7 7 7 7 7 7 7 % Edit. % 8 8 8 9 9 x x x x; % 10 10 11 11 x 12 12 13 13]; % Catalog, info, listing, extract. % %theStyles = {'text'; 'text'; 'text'; % 'listbox'; 'listbox'; 'listbox'; % 'edit'; % 'popupmenu'; 'popupmenu'; % 'pushbutton'; 'pushbutton'; 'pushbutton'; 'pushbutton'; % 'text'}; % %theStrings = {'Dimensions'; 'Variables'; 'Attributes'; % 'Dimensions'; 'Variables'; 'Attributes'; % 'Properties'; % {'-'; 'Dimension'; 'Record Dimension'; '-'; % 'Variable'; 'Coordinate Variable'; '-'; % 'Attribute'; 'Global Attribute'}; % {'-'; 'Double'; 'Float'; '-'; 'Long'; 'Short'; % '-'; 'Char'; 'Byte'}; % 'Catalog'; 'Info'; 'Listing'; 'Extract'; % 'NetCDF File'}; % %theTags = {'DimLabel'; 'VarLabel'; 'AttLabel'; % 'Dimensions'; 'Variables'; 'Attributes'; % 'Properties'; 'Concepts'; 'Types'; % 'Catalog'; 'Info'; 'Listing'; 'Extract'; % 'Filename'}; % %theFigure = figure('Name', 'NetCDF Browser', ... % 'Color', bluish, 'Visible', 'off', ... % 'DeleteFcn', 'ncbevent(''DeleteFcn'')'); % %switch thePermission %case 'nowrite' % set(theFigure, 'Name', [get(gcf, 'Name') ' -- Read Only']) %otherwise % set(theFigure, 'Name', [get(gcf, 'Name') ' -- Read/Write']) %end % %theFrame = uicontrol('Style', 'frame', ... % 'Units', 'normalized', ... % 'Position', [0 0 1 1], ... % 'Tag', 'Frame', ... % 'BackgroundColor', [0.25 1 1]); % %theControls = zeros(length(theStyles), 1); % %theFontSize = get(0, 'DefaultUIControlFontSize'); %theFontWeight = get(0, 'DefaultUIControlFontWeight'); % %theFontWeight = 'bold'; % %for i = 1:length(theStyles) % theControls(i) = uicontrol('Style', theStyles{i}, ... % 'String', theStrings{i}, ... % 'FontSize', theFontSize, ... % 'FontWeight', theFontWeight, ... % 'Tag', theTags{i}, ... % 'Callback', 'ncbevent(''Callback'')'); %end % %thePosition = [2 2 96 96] ./ 100; % %uilayout(theControls, theLayout, thePosition) % %theStruct.itSelf = theFigure; %theStruct.itsGCBO = []; %theStruct.itIsClipboard = []; %switch class(theNetCDFFile) %case 'char' % theNetCDF = netcdf(theNetCDFFile, thePermission); % isClipboard = 0; %case 'netcdf' % theNetCDF = theNetCDFFile; % isClipboard = 1; %otherwise %end %if ~isempty(theNetCDF) % result = class(theStruct, 'ncbrowser', theNetCDF); % result.itIsClipboard = isClipboard; % set(theFigure, 'UserData', result) % else % delete(theFigure) % result = []; % if nargout > 0 % self = result; % else % assignin('base', 'ans', result) % end % return %end % %ncbmenu(result) %set(theFigure, 'MenuBar', 'none') % %theDims = dim(theNetCDF); %theVars = var(theNetCDF); %theAtts = att(theNetCDF); % %theDimnames = [{'-'} ncnames(theDims)]; %theVarnames = [{'-'} ncnames(theVars)]; %theAttnames = [{'-'} ncnames(theAtts)]; % %set(theControls(4), 'String', theDimnames) %set(theControls(5), 'String', theVarnames) %set(theControls(6), 'String', theAttnames) %theSize = ncsize(super(result)); %set(theControls(7), 'String', mat2str(theSize(1:3))) %set(theControls(14), 'String', theNetCDFFile); % %set(theControls([4 5 6 8 9]), 'Value', 1, 'UserData', 1) % %set(theControls(7), 'HorizontalAlignment', 'left') % %set(theControls([1:3 13]), 'BackgroundColor', bluish); %set(theControls([4 5 6]), 'BackgroundColor', light_blue); %set(theControls([7 8 9]), 'BackgroundColor', yellowish); %set(theControls(10:13), 'BackgroundColor', yellowish); % %set(theFigure, 'Visible', 'on') % %assignin('base', 'ncb', result) %assignin('base', 'nco', theNetCDF) %assignin('base', 'nci', theNetCDF) %assignin('base', 'ncx', []) % %if nargout > 0 % self = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'ncbrowser') fclose(fout); cd ('..') bund_setdir('@ncdim') disp(' ## Installing: "att.m" (text)') fout = fopen('att.m', 'w'); %function theResult = att(self) % %% ncdim/att -- Attributes of variables associated with a NetCDF dimension. %% att(self) returns a list of the ncvar objects that use the dimension %% associated with self, an ncdim object. % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %result = cell(0, 0); % %v = var(self); %for i = 1:length(v) % result = [result att(v{i})]; %end % %if nargout > 0 % theResult = result; % else % for i = 1:length(result) % disp(name(result{i})) % end %end fclose(fout); disp(' ## Installing: "copy.m" (text)') fout = fopen('copy.m', 'w'); %function theResult = copy(self, theDestination) % %% ncdim/copy -- Copy a NetCDF dimension. %% copy(self, theDestination) copys the NetCDF dimension %% associated with self, an ncdim object, to theDestination, %% a netcdf object. If successful, the new ncdim object is %% returned; otherwise, the empty-matrix [] 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 07-Aug-1997 15:45:48. %% Updated 30-Apr-2001 09:27:03. % %if nargin < 2, help(mfilename), return, end % %switch ncclass(theDestination) %case 'netcdf' % theSize = ncsize(self); % if isrecdim(self), theSize = 0; end % result = ncdim(name(self), theSize, theDestination); %otherwise % result = []; %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "gt.m" (text)') fout = fopen('gt.m', 'w'); %function theResult = gt(self, theDestination) % %% ncdim/gt -- Pipe self into a netcdf item. %% gt(self, theDestination) pipes self, an ncdim %% object, into theDestination, an netcdf object. % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch class(theDestination) % case 'netcdf' % result = []; % [ndims, nvars, ngatts, recdim, status] = ncmex('inquire', ncid(self)); % if dimid(self) == recdim % end % if isempty(result) % result = copy(self, theDestination); % end % otherwise % warning(' ## Illegal operation.') %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "iscoord.m" (text)') fout = fopen('iscoord.m', 'w'); %function theResult = iscoord(self) % %% ncdim/iscoord -- Is self a coordinate-dimension? %% iscoord(self) returns TRUE (non-zero) if self has the %% same name as a variable; else, it returns FALSE (0). % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %theName = name(self); %result = (ncmex('varid', ncid(self), name(self)) >= 0); % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "isrecdim.m" (text)') fout = fopen('isrecdim.m', 'w'); %function theResult = isrecdim(self) % %% ncdim/isrecdim -- Is self a coordinate-dimension? %% isrecdim(self) returns TRUE (non-zero) if self is %% the record-dimension; else, it returns FALSE (0). % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %result = 0; %theRecdim = recdim(parent(self)); %if ~isempty(theRecdim) % if dimid(self) == dimid(theRecdim) % result = 1; % end %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "ncdim.m" (text)') fout = fopen('ncdim.m', 'w'); %function self = ncdim(theDimname, theDimsize, theNetcdf) % %% ncdim/ncdim -- Constructor for ncdim class. %% ncdim(theDimname, theDimsize, theNetcdf) defines a new ncdim %% object with theDimname and theDimsize in theNetcdf, a netcdf %% object. The equivalent redirection syntax is %% theNetcdf < ncdim(theDimname, theDimsize). The result is %% assigned silently to 'ans" if no output argument is given. %% ncdim(theDimname, theNetcdf) returns a new ncdim object %% corresponding to theDimname in theNetcdf, a netcdf or %% ncvar object. %% ncdim (no argument) returns a raw "ncdim" object. % %% 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-Aug-1997 15:45:48. % %if nargin < 1 & nargout < 1, help(mfilename), return, end % %if nargout > 0, self = []; end % %% Basic structure. % %theStruct.itsDimsize = []; % %% Raw object. % %if nargin < 1 & nargout > 0 % self = class(theStruct, 'ncdim', ncitem); % return %end % %if nargin == 2 & ... % (isa(theDimsize, 'netcdf') | isa(theDimsize, 'ncvar')) % result = []; % theNetcdf = theDimsize; % theNCid = ncid(theNetcdf); % theDimsize = -1; % switch class(theDimname) % case 'char' % [theDimid, status] = ncmex('dimid', theNCid, theDimname); % case 'double' % theDimid = theDimname - 1; % status = 0; % otherwise % status = -1; % ncillegal % end % if status >= 0 % [theDimname, theDimsize, status] = ncmex('diminq', theNCid, theDimid); % if status >= 0 % theStruct.itsDimsize = theDimsize; % result = class(theStruct, 'ncdim', ncitem(theDimname, theNCid, theDimid)); % end % end % if nargout > 0 % self = result; % else % ncans(result) % end % return %end % %theNCid = -1; %if nargin > 2, theNCid = ncid(theNetcdf); end % %if ~finite(theDimsize), theDimsize = 0; end % %status = 0; % %theDimid = -1; %if theNCid ~= -1 % switch class(theDimname) % case 'char' % [theDimid, status] = ncmex('dimid', theNCid, theDimname); % otherwise % status = -1; % warning(' ## Illegal syntax.') % end % if status < 0 % theTempname = theDimname; % theTempname(:) = '-'; % [theDimid, status] = ncmex('dimdef', theNCid, theTempname, theDimsize); % if status < 0 % status = ncmex('redef', theNCid); % if status >= 0 % [theDimid, status] = ... % ncmex('dimdef', theNCid, theTempname, theDimsize); % end % end % if status >= 0 % status = ncmex('dimrename', theNCid, theDimid, theDimname); % end % end % if status >= 0 % [theDimname, theDimsize, status] = ncmex('diminq', theNCid, theDimid); % end %end % %if status >= 0 % theStruct.itsDimsize = theDimsize; % result = class(theStruct, 'ncdim', ncitem(theDimname, theNCid, theDimid)); %else % result = []; %end % %if nargout > 0 % self = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "resize.m" (text)') fout = fopen('resize.m', 'w'); %function theResult = resize(self, newSize) % %% ncdim/resize -- Resize dimension. %% resize(self, newSize) resizes the length of self, %% an "ncdim" object. The newSize is a positive %% integer. The new self is returned. % %% 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 03-Nov-1998 08:52:22. %% Updated 03-Mar-2003 16:15:48. % %if nargin < 1, help(mfilename), return, end %if nargout > 0, theResult = self; end % %% The following is almost identical to "ncvar/resize". % %% Check for no-change. % %if isequal(ncsize(self), newSize) % result = self; % if nargout > 0 % theResult = result; % else % ncans(result) % end % return %end % %theItemName = name(self); % %% Check for writeability. % %f = parent(self); %thePermission = permission(f); %theSrcName = name(f); % %if isequal(thePermission, 'nowrite') % disp([' ## NetCDF source file must be writeable.']) % return %end % %% Check request. % %if ~isrecdim(self) & newSize <= 0 % disp([' ## Dimension "' name(self) '" size requires positive integer.']) % return %end % %% Create temporary file. % %g = []; % %i = 0; %while isempty(g) % i = i + 1; % theTmpName = ['tmp_' int2str(i) '.nc']; % if exist(theTmpName, 'file') ~= 2 % g = netcdf(theTmpName, 'noclobber'); % end %end % %theTmpName = name(g); % %% Copy the affected dimension first. % %d = {self}; %for i = 1:length(d) % if isrecdim(d{i}) % g(name(d{i})) = 0; % else % g(name(d{i})) = newSize(i); % end %end % %% Copy other dimensions. % %d = dim(f); %for i = 1:length(d) % if isrecdim(d{i}) % g(name(d{i})) = 0; % else % g(name(d{i})) = ncsize(d{i}); % end %end % %% Copy global attributes. % %a = att(f); %for i = 1:length(a) % copy(a{i}, g) %end % %% Copy variable definitions and attributes. % %v = var(f); %for i = 1:length(v) % copy(v{i}, g, 0, 1) %end % %% Copy variable data as minimal rectangular array. %% Note that the "()" operator is out-of-context %% inside this method, so we have to build our own %% calls to "ncvar/subsref" and "ncvar/subsasgn". %% It might be easier for us to use "virtual" %% variables instead, which could be transferred %% with the more intelligent "ncvar/copy" method. % %v = var(f); %w = var(g); % %for i = 1:length(v) % sv = ncsize(v{i}); % sw = ncsize(w{i}); % if ~isempty(sw) % d = dim(w{i}); % if isrecdim(d{1}) % if sw(1) == 0 % if isequal(name(d{1}), theItemName) % sw(1) = newSize; % else % sw(1) = sv(1); % end % end % end % end % theMinimalSize = min(sv, sw); % if prod(theMinimalSize) > 0 % if isequal(sv, sw) % copy(v{i}, g, 1) % else % theIndices = cell(size(theMinimalSize)); % for j = 1:length(theIndices) % theIndices{j} = 1:theMinimalSize(j); % end % theStruct.type = '()'; % theStruct.subs = theIndices; % theData = subsref(v{i}, theStruct); % w{i} = subsasgn(w{i}, theStruct, theData); % end % end %end % %% Close both files. % %f = close(f); %g = close(g); % %% Delete old file. % %delete(theSrcName) % %% Rename new file to old file name. % %fcopy(theTmpName, theSrcName) %delete(theTmpName) % %% Open the new file. % %g = netcdf(theSrcName, thePermission); % %% Return the resized dimension. % %result = g(theItemName); % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "subsasgn.m" (text)') fout = fopen('subsasgn.m', 'w'); %function theResult = subsasgn(self, theStruct, other) % %% ncdim/subsasgn -- Overloaded "()" operator. %% subsref(self, theStruct) processes the subscripting %% operator () for self, an "ncdim" object referenced %% on the left-hand side of an assignment, as in %% "self(:) = other". If "other" is [] (empty-matrix), %% the dimension and all its associated variables are %% deleted. If "other" is a scalar, the dimension is %% resized to that value. % %% Also see: ncdim/subsref. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % Never happens. % result = other; % if nargout > 1 % theResult = result; % else % disp(result) % end % return %end % %result = []; % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; %if ~isa(theSubs, 'cell'), theSubs = {theSubs}; end % %switch theType %case '()' % if length(theSubs) == 1 & strcmp(theSubs{1}, ':') % if isempty(other) % result = delete(self); % Delete. % elseif isa(other, 'double') & length(other) == 1 % result = resize(self, other); % Resize. % end % end %otherwise %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "subsindex.m" (text)') fout = fopen('subsindex.m', 'w'); %function theResult = subsindex(self) % %% ncdim/subsindex -- Value of an ncdim object as an index. %% subsindex(self) returns the set of zero-based indices %% equivalent to the value of self, an "ncdim" object. %% The result is [(1:self(:)) - 1], corresponding %% to the full span of the dimensional length. %% %% Also see: ncvar/subsindex. % %% 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-Aug-1997 15:45:48. % %result = (1:self(:)) - 1; % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "subsref.m" (text)') fout = fopen('subsref.m', 'w'); %function theResult = subsref(self, theStruct) % %% ncdim/subsref -- Overloaded "{}", ".", and "()" operators. %% subsref(self, theStruct) processes the subscripting %% operator () for self, an "ncdim" object referenced on %% the righthand side of an assignment, specifically %% the single case of result = self(:), which returns %% the value of the dimension. % %% Also see: ncdim/subsasgn. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % result = self; % if nargout > 0 % theResult = result; % else % disp(theResult) % end % return %end % %result = []; % %theNCid = ncid(self); %theDimid = dimid(self); %[ignore, theSize] = ncmex('diminq', theNCid, theDimid); % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %if isa(theSubs, 'cell'), theSubs = theSubs{1}; end % %switch theType %case '()' % Attribute data: self(...) % switch theSubs % case ':' % result = theSize; % otherwise % warning([' ## Illegal syntax: "' theSubs '"']) % end %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(theResult) %end fclose(fout); disp(' ## Installing: "var.m" (text)') fout = fopen('var.m', 'w'); %function theResult = var(self) % %% ncdim/var -- Variables associated with a NetCDF dimension. %% var(self) returns a list of the ncvar objects that use %% the dimension associated with self, an ncdim object. % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end % %[ndims, nvars, ngatts, recdim, status] = ... % ncmex('inquire', ncid(self)); %if status < 0, return, end % %count = 0; %result = cell(0, 0); %for i = 1:nvars % varid = i - 1; % [varname, vartype, varndims, vardims, varnatts, status] = ... % ncmex('varinq', ncid(self), varid); % if status >= 0 % for j = 1:length(vardims) % if vardims(j) == dimid(self) % nc = ncitem('', ncid(self)); % v = ncvar(varname, nc); % count = count + 1; % result{count} = v; % break % end % end % end %end % %if nargout > 0 % theResult = result; % else % for i = 1:length(result) % disp(name(result{i})) % end %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'ncdim') fclose(fout); cd ('..') bund_setdir('@ncitem') disp(' ## Installing: "and.m" (text)') fout = fopen('and.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "attnum.m" (text)') fout = fopen('attnum.m', 'w'); %function theResult = attnum(self, theAttnum) % %% ncitem/attnum -- Attribute number of an ncitem. %% attnum(self) returns the attribute number of self, %% an "ncitem" object. %% attnum(self, theAttnum) sets the attnum of self %% to theAttnum and returns self. % %% 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-Aug-1997 09:34:31. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 % result = self.itsAttnum; %else % self.itsAttnum = theAttnum; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "autonan.m" (text)') fout = fopen('autonan.m', 'w'); %function theResult = autonan(self, theAutoNaNFlag) % %% ncitem/autonan -- Set/get auto-NaN flag. %% autonan(self) returns the auto-NaN flag of self. %% When TRUE, ncvar objects will convert their fill-value %% elements to NaNs on reading, and convert NaNs back to %% the fill-value on writing to the file. %% autonan(self, theAutoNaNFlag) sets the auto-NaN flag %% and returns self. % %% 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 18-Dec-1998 09:52:41. %% Updated 09-Aug-1999 16:18:10. % %if nargin < 1, help(mfilename), return, end % %if nargin == 1 % result = ~~self.itIsAutoNaNing; %else % self.itIsAutoNaNing = ~~theAutoNaNFlag; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "autoscale.m" (text)') fout = fopen('autoscale.m', 'w'); %function theResult = autoscale(self, theAutoscale) % %% ncitem/autoscale -- Auto-scale flag of an ncitem. %% autoscale(self) returns the auto-scale flag of self, %% an ncitem object. %% autoscale(self, theAutoscale) sets the auto-scale flag %% to theAutoscale and returns self. % %% 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-Aug-1997 09:42:01. %% Updated 09-Aug-1999 16:18:59. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 % result = ~~self.itIsAutoscaling; %else % self.itIsAutoscaling = ~~theAutoscale; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "colon.m" (text)') fout = fopen('colon.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "ctranspose.m" (text)') fout = fopen('ctranspose.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "datatype.m" (text)') fout = fopen('datatype.m', 'w'); %function theResult = datatype(self) % %% ncitem/datatype -- Numeric type of an ncitem object. %% datatype(self) returns the numeric type of %% self, an object derived from the ncitem class. % %% 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-Aug-1997 09:42:59. % %if nargin < 1, help(mfilename), return, end % %result = ''; % %theTypes = {'byte', 'char', 'short', 'long', 'float', 'double'}; % %theNCid = ncid(self); % %theClass = ncclass(self); %switch theClass %case 'ncdim' % theType = 'long'; % status = 0; %case 'ncvar' % if theNCid >= 0 % theVarid = varid(self); % [theName, theType, theNdims, theDimids, theNatts, status] = ... % ncmex('varinq', theNCid, theVarid); % else % s = struct(self); % theType = s.itsVartype; % status = 0; % end %case 'ncatt' % if theNCid >= 0 % theVarid = varid(self); % theAttname = name(self); % [theType, theLen, status] = ... % ncmex('attinq', theNCid, theVarid, theAttname); % else % s = struct(self); % theType = s.itsVartype; % status = 0; % end %otherwise % theType = 'unknown'; % status = -1; % warning(' ## Illegal syntax.') %end % %if status >= 0 & ~isstr(theType) % theType = theTypes{theType}; %end % %result = theType; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "delete.m" (text)') fout = fopen('delete.m', 'w'); %function theResult = delete(varargin) % %% ncitem/delete -- Delete one or more NetCDF items. %% delete(item1, item2, ...) deletes the items, all "ncitem" %% objects that must be associated with the same NetCDF file. % %% 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 13-Aug-1997 16:50:10. % %if nargin < 1, help(mfilename), return, end % %theParent = parent(parent(varargin{1})); % %result = delete(theParent, varargin{:}); % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "desc.m" (text)') fout = fopen('desc.m', 'w'); %function status = desc(theItem, howMuch) % %% ncitem/desc -- Description of a NetCDF object. %% desc('theFunction') shows help for 'theFunction'. %% desc(theObject) describes theObject itself, but not %% its inherited parts. %% desc(theObject, 'full') describes theObject fully. %% desc(theNonObject, ...) describes theNonObject. %% %% Also see: ncitem/disp, ncitem/display. % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 09:43:31. % %if nargin < 1, help(mfilename), 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: "dimid.m" (text)') fout = fopen('dimid.m', 'w'); %function theResult = dimid(self, theDimid) % %% ncitem/dimid -- Dimid of an ncitem. %% dimid(self) returns the dimension of of self, %% an "ncitem" object. %% dimid(self, theDimid) sets the dimension id %% of self to theDimid and returns self. % %% 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-Aug-1997 09:44:27. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 % result = self.itsDimid; %else % self.itsDimid = theDimid; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "disp.m" (text)') fout = fopen('disp.m', 'w'); %function disp(self) % %% ncitem/disp -- Display the contents of an ncitem object. %% disp(self) displays the contents of self, an object %% derived from the ncitem class. %% %% Also see: ncitem/display, ncitem/desc. % %% 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-Aug-1997 09:44:53. % %if nargin < 1, help(mfilename), return, end % %theClass = ncclass(self); %switch theClass %case {'ncitem'} % disp(struct(self)) %case 'netcdf' % self = ncregister(self); % s = ncsize(self); % t.NetCDF_File = name(self); % t.nDimensions = s(1); % t.nVariables = s(2); % t.nGlobalAttributes = s(3); % t.RecordDimension = ''; % t.nRecords = 0; % if ~isempty(recdim(self)) % t.RecordDimension = name(recdim(self)); % t.nRecords = ncsize(recdim(self)); % end % t.Permission = permission(self); % t.DefineMode = mode(self); % t.FillMode = setfill(self); % t.MaxNameLen = fatnames(self); % disp(t) %case {'ncdim'} % t.NetCDF_Dimension = name(self); % t.itsLength = ncsize(self); % disp(t) %case {'ncvar'} % t.NetCDF_Variable = name(self); % t.itsType = datatype(self); % theOrientation = orient(self); % theAutoscale = autoscale(self); % theAutonan = autonan(self); % isUnsigned = unsigned(self); % IsQuick = quick(self); % d = dim(self); % if ~isempty(d), d = d(abs(theOrientation)); end % t.itsDimensions = ''; % for i = 1:length(d) % if i > 1, t.itsDimensions = [t.itsDimensions ', ']; end % t.itsDimensions = [t.itsDimensions name(d{i})]; % end % t.itsLengths = ncsize(self); % t.itsOrientation = theOrientation; %% t.itsSubset = subset(self); %% t.itsOffset = offset(self); %% t.itsOrigin = origin(self); % t.itsVars = var(self); % [theSrcsubs, theDstsubs] = subs(self); % t.itsSrcsubs = theSrcsubs; % t.itsDstsubs = theDstsubs; % t.nAttributes = length(att(self)); % t.itIsAutoscaling = theAutoscale; % t.itIsAutoNaNing = theAutonan; % t.itIsUnsigned = isUnsigned; % t.itIsQuick = IsQuick; % disp(t) %case {'ncatt'} % t.NetCDF_Attribute = name(self); % t.itsType = datatype(self); % t.itsLength = ncsize(self); % t.itIsUnsigned = unsigned(self); % disp(t) %case {'ncrec'} % disp(self(:)) %otherwise % warning(' ## Illegal syntax.') %end fclose(fout); disp(' ## Installing: "display.m" (text)') fout = fopen('display.m', 'w'); %function display(self) % %% ncitem/display -- Display an ncitem object. %% display(self) displays self, an ncitem object. %% %% Also see: ncitem/disp, ncitem/desc. % %% 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-Aug-1997 09:44:53. % %if nargin < 1, help(mfilename), return, end % %theName = inputname(1); %disp(' '), disp([theName ' =']), disp(' ') %disp(self) fclose(fout); disp(' ## Installing: "double.m" (text)') fout = fopen('double.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "end.m" (text)') fout = fopen('end.m', 'w'); %function theResult = end(self, k, n) % %% ncitem/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", %% an "ncitem" 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 24-Aug-1999 08:46:58. %% Updated 24-Aug-1999 08:46:58. % %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: "eq.m" (text)') fout = fopen('eq.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "feval.m" (text)') fout = fopen('feval.m', 'w'); %function varargout = feval(varargin) % %% ncitem/feval -- feval() for an ncitem object. %% [...] = feval('theFcn', ...) applies 'theFcn' function to the %% argument list. All "ncitem" arguments are dereferenced to %% their corresponding numerical contents. The stored NetCDF %% contents themselves are not affected. % %% 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-Aug-1997 09:48:11. % %if nargin < 1, help(mfilename), return, end % %% De-reference the ncitem data. % %for i = 2:length(varargin) % switch ncclass(varargin{i}) % case {'ncdim', 'ncvar', 'ncatt', 'ncrec'} % varargin{i} = varargin{i}(:); % Whole data. % otherwise % end %end % %% Allocate output objects. % %varargout = cell(1, min(nargout, 1)); %for i = 1:length(varargout), varargout{i} = []; end % %% Evaluate the function. % %theFcn = varargin{1}; %trystr = 'varargout{:} = feval(varargin{:});'; %catchstr = ['disp('' ## ' mfilename ' failure while trying: ' ... % theFcn '(...)'')']; %eval(trystr, catchstr); fclose(fout); disp(' ## Installing: "ge.m" (text)') fout = fopen('ge.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "gt.m" (text)') fout = fopen('gt.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "horzcat.m" (text)') fout = fopen('horzcat.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "id.m" (text)') fout = fopen('id.m', 'w'); %function theResult = id(self) % %% ncitem/id -- The access id of a NetCDF object. %% id(self) returns the access id for self, %% a netcdf, ncdim, ncvar, or ncatt object. % %% 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-Aug-1997 09:48:59. % %if nargin < 1, help(mfilename), return, end % %switch class(self) %case 'netcdf' % result = ncid(self); %case 'ncdim' % result = dimid(self); %case 'ncvar' % result = varid(self); %case 'ncatt' % result = attnum(self); %otherwise %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "iscoord.m" (text)') fout = fopen('iscoord.m', 'w'); %function theResult = iscoord(self) % %% ncitem/iscoord -- Is self related to a coordinate-variable? %% iscoord(self) returns TRUE (non-zero) if self has the %% same name as a dimension; else, it returns FALSE (0). % %% 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-Aug-1997 09:49:26. % %if nargin < 1, help(mfilename), return, end % %theName = name(self); % %theClass = ncclass(self); %switch theClass %case 'ncdim' % result = (ncmex('varid', ncid(self), name(self)) >= 0); %case 'ncvar' % result = (ncmex('dimid', ncid(self), name(self)) >= 0); %case 'ncatt' % result = (ncmex('varid', ncid(self), name(self)) >= 0) & ... % (ncmex('dimid', ncid(self), name(self)) >= 0); %otherwise % result = 0; %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "isequal.m" (text)') fout = fopen('isequal.m', 'w'); %function theResult = isequal(self, other) % %% ncitem/isequal -- Are two ncitems the same? %% isequal(self, other) returns TRUE (1) if self %% and other represent the same NetCDF entity. %% Otherwise, it returns FALSE (0). %% %% Also see: ncitem/eq, ncitem/ne. % %% 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-Aug-1997 09:50:19. % %if nargin < 2, help(mfilename), return, end % %result = 0; % %if isequal(class(self), class(other)) & ... % isequal(name(self), name(other)) & ... % isequal(ncid(self), ncid(other)) & ... % isequal(dimid(self), dimid(other)) & ... % isequal(varid(self), varid(other)) & ... % isequal(attnum(self), attnum(other)) % result = 1; %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "ldivide.m" (text)') fout = fopen('ldivide.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "le.m" (text)') fout = fopen('le.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "length.m" (text)') fout = fopen('length.m', 'w'); %function theResult = length(self) % %% ncitem/length -- Length of an "ncitem" object. %% length(self) returns max(size(self)). % %% 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-Dec-1998 10:04:23. % %result = max(size(self)); % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "listing.m" (text)') fout = fopen('listing.m', 'w'); %function theResult = listing(self) % %% ncitem/listing -- Listing of value. %% listing(self) lists the value of self, %% an object derived from "ncitem". % %% 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-Aug-1997 09:51:07. % %if nargin < 1, help(mfilename), return, end % %theNameOfSelf = name(self); %if strcmp(theNameOfSelf, '_FillValue') % theNameOfSelf = 'FillValue_'; %end %x = self(:); % %disp(' '), disp(' ') %disp([theNameOfSelf ' =']), disp(' ') %disp(x) % %if nargout > 0 % theResult = x; %end fclose(fout); disp(' ## Installing: "lt.m" (text)') fout = fopen('lt.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "mdivide.m" (text)') fout = fopen('mdivide.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "minus.m" (text)') fout = fopen('minus.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "mldivide.m" (text)') fout = fopen('mldivide.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "mode.m" (text)') fout = fopen('mode.m', 'w'); %function theResult = mode(self) % %% ncitem/mode -- Define/data mode. %% mode(self) returns the "define/data" mode of %% the "netcdf" object associated with self, %% an object derived from "ncitem". % %% 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 11-Aug-1997 10:43:29. % %if nargin < 1, help(mfilename), return, end % %theParent = mode(parent(parent(self))); % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "mpower.m" (text)') fout = fopen('mpower.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "mrdivide.m" (text)') fout = fopen('mrdivide.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "mtimes.m" (text)') fout = fopen('mtimes.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "name.m" (text)') fout = fopen('name.m', 'w'); %function theResult = name(self, theNewName) % %% ncitem/name -- Name of the NetCDF item. %% name(self) returns the name of self, an ncitem object. %% name(self, theNewName) renames self to theNewName and %% returns self. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 09:51:50. % %if nargin < 1, help(mfilename), return, end % %result = ''; % %if nargin > 1 % if ncid(self) >= 0 % switch ncclass(self) % case {'ncdim', 'ncvar', 'ncatt'} % self = rename(self, theNewName); % if isa(self, 'ncatt'), self.itsName = theNewName; end % otherwise % warning(' ## Illegal syntax.') % end % else % self.itsName = theNewName; % end %end % %result = self.itsName; % %if ~isempty(self) & ncid(self) >= 0 % switch ncclass(self) % case 'netcdf' % self = ncregister(self); % result = self.itsName; % status = 0; % case 'ncdim' % if dimid(self) >= 0 % [theDimname, theDimsize, status] = ... % ncmex('diminq', ncid(self), dimid(self)); % if status >= 0, result = theDimname; end % end % case 'ncvar' % if varid(self) >= 0 % [theVarname, theVartype, theVarndims, theVardims, ... % theVarnatts, status] = ... % ncmex('varinq', ncid(self), varid(self)); % if status >= 0, result = theVarname; end % end % case 'ncatt' % if attnum(self) >= 0 % theAttname = self.itsName; % [theAtttype, theAttlen, status] = ... % ncmex('attinq', ncid(self), varid(self), theAttname); % if status >= 0, result = theAttname; end % end % case 'ncitem' % result = ''; % if ncid(self) >= 0 % if dimid(self) >= 0 % [theDimname, theDimsize, status] = ... % ncmex('diminq', ncid(self), dimid(self)); % if status >= 0, result = theDimname; end % elseif varid(self) >= 0 & attnum(self) < 0 % [theVarname, theVartype, theVarndims, theVardims, ... % theVarnatts, status] = ... % ncmex('varinq', ncid(self), varid(self)); % if status >= 0, result = theVarname; end % elseif attnum(self) >= 0 % theAttname = self.itsName; % [theAtttype, theAttlen, status] = ... % ncmex('attinq', ncid(self), varid(self), theAttname); % if status >= 0, result = theAttname; end % else % result = self.itsName; % end % end % otherwise % warning([' ## Illegal operation.']) % end %end % %self.itsName = result; % %if nargin > 1, result = self; end % %if nargout > 0 % theResult = result; % elseif nargin < 2 % disp(result) %end fclose(fout); disp(' ## Installing: "ncclass.m" (text)') fout = fopen('ncclass.m', 'w'); %function theResult = ncclass(self) % %% ncitem/ncclass -- NetCDF class of a derived object. %% ncclass(self) returns the NetCDF class of self, %% an object derived from ncitem. Unrecognized %% classes are returned as they are. % %% 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 15-May-1997 11:27:21. % %if nargin < 1, help(mfilename), return, end % %theNCClass = class(self); %theNCClasses = {'netcdf', 'ncdim', 'ncvar', 'ncatt', 'ncrec', 'ncitem'}; %for i = 1:length(theNCClasses) % if isa(self, theNCClasses{i}) % theNCClass = theNCClasses{i}; % break; % end %end % %if nargout > 0 % theResult = theNCClass; % else % disp(theNCClass) %end fclose(fout); disp(' ## Installing: "ncid.m" (text)') fout = fopen('ncid.m', 'w'); %function theResult = ncid(self, theNCid) % %% ncitem/ncid -- Id of the owner of an ncitem object. %% ncid(self) returns the ncid of the "netcdf" %% object that owns self, an "ncitem" object. %% ncid(self, theNCid) sets the ncid of self to theNCid %% and returns self. % %% 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-Aug-1997 09:53:00. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 % result = self.itsNCid; %elseif nargin == 2 % self.itsNCid = theNCid; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ncitem.m" (text)') fout = fopen('ncitem.m', 'w'); %function self = ncitem(theName, theNCid, ... % theDimid, theVarid, theAttnum, ... % theRecnum, theRecdimid, theAutoscale, ... % isUnsigned, isQuick, theMaxNameLen) % %% ncitem/ncitem -- Constructor for ncitem class. %% ncitem('theName', theNCid, theDimid, theVarid, ... %% theAttnum, theRecnum, theRecdimid, theAutoscale, ... %% isUnsigned, isQuick, theMaxNameLen) allocates a %% container for the given information about a NetCDF %% item. It serves as a header class for derived NetCDF %% classes, including netcdf, ncdim, ncvar, ncatt, ncrec, %% and ncslice. The result is assigned silently to "ans" %% if no output argument is given. % %% Copyright (C) 1996 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-1999 15:04:36. %% Updated 09-Aug-1999 16:19:27. %% Touched 22-Mar-2000 09:36:07. Autoscale/autonan proposal. % %if nargin < 1 & nargout < 1 % help(mfilename) % return %end % %if nargin < 1, theName = ''; end %if nargin < 2, theNCid = -1; end %if nargin < 3, theDimid = -1; end %if nargin < 4, theVarid= -1; end %if nargin < 5, theAttnum = -1; end %if nargin < 6, theRecnum = -1; end %if nargin < 7, theRecdimid = -1; end %if nargin < 8, theAutoscale = 0; end % ZYDECO Proposal: default = 1. %if nargin < 9, theAutoNaN = 0; end % ZYDECO Proposal: default = 1. %if nargin < 10, isUnsigned = 0; end %if nargin < 11, isQuick = 0; end %if nargin < 12, theMaxNameLen = 0; end % %if (1) % theStruct = struct( ... % 'itsName', theName, ... % 'itsNCid', theNCid, ... % 'itsDimid', theDimid, ... % 'itsVarid', theVarid, ... % 'itsAttnum', theAttnum, ... % 'itsRecnum', theRecnum, ... % 'itsRecdimid', theRecdimid, ... % 'itIsAutoscaling', theAutoscale, ... % 'itIsAutoNaNing', theAutoNaN, ... % 'itIsUnsigned', isUnsigned, ... % 'itIsQuick', isQuick, ... % 'itsMaxNameLen', theMaxNameLen ... % ); %else % theStruct.itsName = theName; % theStruct.itsNCid = theNCid; % theStruct.itsDimid = theDimid; % theStruct.itsVarid = theVarid; % theStruct.itsAttnum = theAttnum; % theStruct.itsRecnum = theRecnum; % theStruct.itsRecdimid = theRecdimid; % theStruct.itIsAutoscaling = theAutoscale; % theStruct.itIsAutoNaNing = theAutoNaN; % theStruct.itIsUnsigned = isUnsigned; % theStruct.itIsQuick = isQuick; % theStruct.itsMaxNameLen = theMaxNameLen; %end % %result = class(theStruct, 'ncitem'); % %if nargout > 0 % self = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "ncsize.m" (text)') fout = fopen('ncsize.m', 'w'); %function [theResult, nvars, ngatts, recdim] = ncsize(self, index) % %% ncitem/ncsize -- Sizes (dimensions) of an "ncitem" object. %% ncsize(self) returns the size of self, an object derived %% from the "ncitem" class. Depending on the class of self, %% this will be either its dimension-length, variable-size, %% or attribute-length. N.B. The "ncsize" vector may have %% have only one component, unlike a Matlab "size" vector, %% which always has more than one. Use "size" to get the %% Matlab analog. If self is a "netcdf" object, the returned %% value is [ndims nvars ngatts recdimid]. Optionally, four %% separate output variables can be requested. %% ncsize(self, index) returns the ncsize-component %% at the given index. %% %% Also see: ncitem/size, ncitem/name, ncitem/datatype. % %% 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 13-Oct-1998 10:54:34. %% Updated 19-Jul-1999 10:59:21. % %if nargin < 1, help(mfilename), return, end % %result = []; % %theNCid = ncid(self); % %theClass = ncclass(self); %switch theClass %case 'ncitem' % theSize = []; % status = 0; %case 'netcdf' % [ndims, nvars, ngatts, recdim, status] = ... % ncmex('ncinquire', theNCid); % if nargout > 1 % theSize = ndims; % else % theSize = [ndims nvars ngatts recdim]; % end %case 'ncdim' % theSize = []; % theDimid = dimid(self); % if theDimid >= 0 % [theDimname, theSize, status] = ... % ncmex('diminq', theNCid, theDimid); % end %case 'ncatt' % theSize = []; % theVarid = varid(self); % if theVarid >= -1 % theAttname = name(self); % [theType, theSize, status] = ... % ncmex('attinq', theNCid, theVarid, theAttname); % end %case 'ncvar' % Overloaded by ncvar/ncsize. % theSize = []; % theVarid = varid(self); % if theVarid >= 0 % [theVarname, theVartype, theVarndims, ... % theVardimids, theVarnatts, status] = ... % ncmex('varinq', theNCid, theVarid); % if status >= 0 % theSize = -ones(1, length(theVardimids)); % for i = 1:length(theVardimids) % [theDimname, theSize(i), status] = ... % ncmex('diminq', theNCid, theVardimids(i)); % if status < 0, break, end % end % end % end %otherwise % theSize = []; % status = -1; % warning(' ## Illegal syntax.') %end % %result = theSize; %if nargin > 1 & index <= length(result) % result = result(index); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ncsubsasgn.m" (text)') fout = fopen('ncsubsasgn.m', 'w'); %function theResult = ncsubsasgn(self, varargin) % %% ncitem/ncsubsasgn -- Dispatch subsasgn() call. %% ncsubsasgn(self, type1, subs1, ..., other) dispatches %% a call to the subsasgn() function for self, an "ncitem" %% object, using the sequence of "types" and "subs" to %% prepare the required "struct". The final argument must %% be the right-side argument. Multi-dimensional subscripts %% must be embedded in a cell. % %% 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-Mar-1998 22:45:05. % %if nargin < 1, help(mfilename), return, end % %if length(varargin) < 3 | rem(length(varargin), 2) == 0 % error(' ## Requires even number of type/subs pairs.') %end % %% The substruct() function is new in v.5.2. %% Do not use here. % %k = 0; %for i = 2:2:length(varargin) % k = k+1; % theType = varargin{i-1}; % theSubs = varargin{i}; % if ~iscell(theSubs), theSubs = {theSubs}; end % theStruct(k).type = theType; % theStruct(k).subs = theSubs; %end % %other = varargin{length(varargin)}; % %theResult = subsasgn(self, theStruct, other); fclose(fout); disp(' ## Installing: "ncsubsref.m" (text)') fout = fopen('ncsubsref.m', 'w'); %function theResult = ncsubsref(self, varargin) % %% ncitem/ncsubsref -- Dispatch subsref() call. %% ncsubsref(self, type1, subs1, type2, subs2, ...) %% dispatches a call to the subsref() function for self, %% an "ncitem" object, using the sequence of "types" %% and "subs" to prepare the required "struct". %% Multi-dimensional subscripts must be embedded %% in a cell. % %% 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-Mar-1998 22:45:05. % %if nargin < 1, help(mfilename), return, end % %if length(varargin) < 2 | rem(length(varargin), 2) == 1 % error(' ## Requires even number of type/subs pairs.') %end % %% The substruct() function is new in v.5.2. %% Do not use here. % %k = 0; %for i = 2:2:length(varargin) % k = k+1; % theType = varargin{i-1}; % theSubs = varargin{i}; % if ~iscell(theSubs), theSubs = {theSubs}; end % theStruct(k).type = theType; % theStruct(k).subs = theSubs; %end % %theResult = subsref(self, theStruct); fclose(fout); disp(' ## Installing: "ne.m" (text)') fout = fopen('ne.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "not.m" (text)') fout = fopen('not.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "op.m" (text)') fout = fopen('op.m', 'w'); %function varargout = op(varargin) % %% op -- Apply a function or operator. %% op(self, other, ...) applies the operator or function %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "options.m" (text)') fout = fopen('options.m', 'w'); %function theResult = options(self, theOptions) % %% ncitem/options -- Set netcdf options. %% options(self, theOptions) sets theOptions in the %% current netcdf interface and returns the original %% option settings. %% options(self) returns the current netcdf options. % %% 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-Aug-1997 09:54:12. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % result = ncmex('setopts'); % else % result = ncmex('setopts', theOptions); %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "or.m" (text)') fout = fopen('or.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "parent.m" (text)') fout = fopen('parent.m', 'w'); %function theResult = parent(self) % %% ncitem/parent -- Parent of a NetCDF item. %% parent(self) returns the parent-object %% of self, an "ncitem" object. Non-global %% attributes return an "ncvar"; all others %% return a "netcdf". The parent of a "netcdf" %% is 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-Apr-1997 09:17:30. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0 % theResult = []; %end % %theNCid = ncid(self); %if theNCid < 0, return, end % %theNetCDF = netcdf(theNCid); % %switch ncclass(self) %case 'ncatt' % if varid(self) >= 0 % theParent = ncvar(ncitem('', ncid(self), -1, varid(self))); % else % theParent = ncregister(theNetCDF); % end %otherwise % theParent = ncregister(theNetCDF); %end % %if nargout > 0 % theResult = theParent; %else % theParent %end fclose(fout); disp(' ## Installing: "permission.m" (text)') fout = fopen('permission.m', 'w'); %function theResult = permission(self) % %% ncitem/permission -- Create/open of a netcdf file. %% permission(self) returns the "create/open" permission %% of the "netcdf" object associated with self, %% an object derived from "ncitem". % %% 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 11-Aug-1997 10:43:29. % %if nargin < 1, help(mfilename), return, end % %theParent = permission(parent(parent(self))); % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "plus.m" (text)') fout = fopen('plus.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "power.m" (text)') fout = fopen('power.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "quick.m" (text)') fout = fopen('quick.m', 'w'); %function theResult = quick(self, theQuickFlag) % %% ncitem/quick -- Set/Get "quick" flag. %% quick(self) returns the "quick" flag of self, %% an "ncitem" object. When TRUE, the flag forces %% faster, vanilla-flavored I/O for variables. %% See help on "ncvar/subsref" and "ncvar/subsasgn". %% quick(self, theQuickFlag) sets the "quick" flag %% to theQuickFlag. % %% 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 19-Jul-1999 15:10:58. %% Updated 19-Jul-1999 16:34:07. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % result = self.itIsQuick; %else % result = self; % result.itIsQuick = ~~theQuickFlag; %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "rdivide.m" (text)') fout = fopen('rdivide.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "recdim.m" (text)') fout = fopen('recdim.m', 'w'); %function theResult = recdim(self, theRecdim) % %% ncitem/recdim -- Record-dimension of an ncitem. %% recdim(self) returns an "ncdim" object corresponding %% to the current record-dimension (actual or artificial) %% of self, a "netcdf" or "ncvar" object. %% recdim(self, theRecdim) sets the recdimid field %% of self to the id of theRecdim and returns self. %% TheRecdim may be given as a dimension name, a %% dimension id, or an "ncdim" object. This usage %% allows an artificial record-dimension to be set. % %% Version of 07-Aug-1997 09:59:52. %% Updated 05-Oct-1999 17:59:09. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if isa(self, 'netcdf') | isa(self, 'ncvar') % if nargin < 2 % if ncid(self) >= 0 % theRecdimid = recdimid(self); % status = 0; % if theRecdimid < 0 % [ndims, nvars, ngatts, theRecdimid, status] = ... % ncmex('inquire', ncid(self)); % end % if status >= 0 % [theName, theLength, status] = ... % ncmex('diminq', ncid(self), theRecdimid); % if status >= 0 % self = recdimid(self, theRecdimid); % if (0) % Matlab 5.3 trouble below! % result = self(theName); % else % theStruct.type = '()'; % theStruct.subs = {theName}; % result = subsref(self, theStruct); % end % end % end % end % elseif isa(theRecdim, 'ncdim') % theRecdimid = dimid(theRecdim); % result = recdim(self, theRecdimid); % elseif isa(theRecdim, 'double') % if ~isempty(theRecdim) % theRecdimid = theRecdim; % else % theRecdimid = -1; % end % result = recdimid(self, theRecdimid); % elseif isa(theRecdim, 'char') % if ~isempty(theRecdim) % theRecdimname = theRecdim; % if (0) % Matlab 5.3 trouble below! % theRecdimid = dimid(self(theRecdimname)); % else % theStruct.type = '()'; % theStruct.subs = {theRecdimname}; % theRecdimid = dimid(subsref(self, theStruct)); % end % else % theRecdimid = -1; % end % result = recdim(self, theRecdimid); % end % if isa(result, 'netcdf') % ncregister(result) % result = ncregister(result); % end %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "recdimid.m" (text)') fout = fopen('recdimid.m', 'w'); %function theResult = recdimid(self, theRecdimid) % %% ncitem/recdimid -- Recdimid of an ncitem. %% recdimid(self) returns the record-dimension id %% of self, an "ncitem" object. %% recdimid(self, theRecdimid) sets the record-dimension %% id of self to theRecdimid and returns self. % %% 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-Aug-1997 09:44:27. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin < 2 % result = self.itsRecdimid; %else % self.itsRecdimid = theRecdimid; % result = self; % if isa(result, 'netcdf') % ncregister(result) % result = ncregister(result); % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "recnum.m" (text)') fout = fopen('recnum.m', 'w'); %function theResult = recnum(self, theRecnum) % %% ncitem/recnum -- Record number of an ncitem. %% recnum(self) returns the current record number %% of self, an ncitem object. %% recnum(self, theRecnum) sets the recnum to theRecnum %% and returns self. % %% Version of 07-Aug-1997 09:59:52. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 % result = self.itsRecnum; %else % self.itsRecnum = theRecnum; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "rename.m" (text)') fout = fopen('rename.m', 'w'); %function theResult = rename(self, theNewName) % %% ncitem/rename -- Rename a NetCDF entity. %% rename(self, theNewName) renames the NetCDF entity %% associated with self, an object derived from the %% ncitem class, to theNewName. The updated self is %% returned. %% %% Also see: ncitem/name. %% %% THIS IS A PRIVATE FUNCTION: Do not call this function %% directly; use name(self, theNewName) instead. % %% 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-Aug-1997 10:00:41. % %if nargin < 2, help(mfilename), return, end % %result = []; % %theNCid = ncid(self); % %switch class(self) %case {'ncdim'} % theDimid = dimid(self); % status = ncmex('dimrename', theNCid, theDimid, theNewName); % if status < 0 % status = ncmex('redef', theNCid); % if status >= 0 % status = ncmex('dimrename', theNCid, theDimid, theNewName); % status = ncmex('endef', theNCid); % end % end %case {'ncvar'} % theVarid = varid(self); % status = ncmex('varrename', theNCid, theVarid, theNewName); % if status < 0 % status = ncmex('redef', theNCid); % if status >= 0 % status = ncmex('varrename', theNCid, theVarid, theNewName); % status = ncmex('endef', theNCid); % end % end %case {'ncatt'} % theVarid = varid(self); % theAttname = name(self); % status = ncmex('attrename', theNCid, theVarid, theAttname, theNewName); % if status < 0 % status = ncmex('redef', theNCid); % if status >= 0 % status = ncmex('attrename', theNCid, theVarid, theAttname, theNewName); % status = ncmex('endef', theNCid); % end % end %otherwise % status = -1; % warning(' ## Illegal syntax.') %end % %if status >= 0, self.itsName = theNewName; end % %result = self; % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "size.m" (text)') fout = fopen('size.m', 'w'); %function [varargout] = size(self, index) % %% ncitem/size -- Sizes (dimensions) of an "ncitem" object. %% size(self) returns the size of self, an object derived %% from the "ncitem" class. Depending on the class of self, %% this will be either its dimension-length, variable-size, %% or attribute-length. *** NOTE: Starting January 1, 1999, %% the size-vector will contain at least two elements, in %% keeping with the Matlab convention. Use "ncsize" to get %% the old form of the size-vector. *** %% If self is a "netcdf" object, the returned value is %% [ndims nvars ngatts recdimid]. Optionally, four separate %% output variables can be requested. %% size(self, index) returns the size-component at the %% given index. The result is 1 if the index exceeds %% the length of the conventional size-vector. %% %% Also see: ncitem/ncsize, ncitem/name, ncitem/datatype. % %% 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-Aug-1997 10:00:59. %% Updated 10-Oct-2001 11:55:24. % %if nargin < 1, help(mfilename), return, end % %% Composite variables. The destination subscripts %% are contained in a cell of cells, one cell for %% each participating variable. The effective %% size is the maximum subscript in each direction. % %switch class(self) %case 'ncvar' % theVars = var(self); % if ~isempty(theVars) % [theSrcsubs, theDstsubs] = subs(self); % theSize = 0; % for j = 1:length(theVars) % s = theDstsubs{j}; % for i = 1:length(s) % theSize(i) = max(theSize(i), max(s{i})); % end % end % while length(theSize) < 2 % theSize = [theSize 1]; % end % if nargout > 0 % varargout{1} = theSize; % else % disp(theSize) % end % return % end %end % %% Conventional NetCDF items. % %vout = cell(1, max(nargout, 1)); % %[vout{:}] = ncsize(self); % %switch class(self) %case 'netcdf' % if nargin > 1 & nargout < 2 % result = vout{1}; % if index > 0 & index <= length(result) % result = result(index); % else % result = []; % end % vout{1} = result; % end %otherwise % result = vout{1}; % while length(result) < 2, result = [result 1]; end % if nargin > 1 % if length(result) < index % result = 1; % elseif index > 0 % result = result(index); % else % result = []; % end % end % vout{1} = result; %end % %if nargout > 0 % varargout = vout; %else % disp(vout{1}) %end fclose(fout); disp(' ## Installing: "subsasgn.m" (text)') fout = fopen('subsasgn.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "subsindex.m" (text)') fout = fopen('subsindex.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "subsref.m" (text)') fout = fopen('subsref.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "times.m" (text)') fout = fopen('times.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "transpose.m" (text)') fout = fopen('transpose.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "uigetatt.m" (text)') fout = fopen('uigetatt.m', 'w'); %function theResult = uigetatt(self) % %% ncitem/uigetatt -- Get a NetCDF attribute via dialog. %% uigetatt(self) returns one attribute associated with self, %% an "ncitem" object, selected from a list-dialog. The %% returned value is an "ncatt" object, or the empty-matrix %% [] if no variable is selected. % %% 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 01-Dec-1997 13:20:58. % %if nargin < 1, help(mfilename), return, end % %result = []; % %theParent = parent(parent(self)); %theFilename = name(theParent); %f = find(theFilename == filesep); %if any(f) % theFilename(1:f(length(f))) = ''; %end % %theAtts = att(self); %theAttnames = ncnames(theAtts); %if ~isempty(theAttnames) % thePrompt = {'Select Attribute From', 'NetCDF File', ['"' theFilename '"']}; % theSelection = listdlg('ListString', theAttnames, ... % 'SelectionMode', 'single', ... % 'PromptString', thePrompt); % if any(theSelection) % result = theAtts{theSelection}; % end %else % disp(' ## No attributes available.') %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "uigetdim.m" (text)') fout = fopen('uigetdim.m', 'w'); %function theResult = uigetdim(self) % %% ncitem/uigetdim -- Get a NetCDF dimension via dialog. %% uigetdim(self) returns one dimension associated with %% self, an "ncitem" object, selected from a list-dialog. %% The returned item is an "ncdim" object, or the %% empty-matrix [] if no dimension is selected. % %% 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 01-Dec-1997 13:20:58. % %if nargin < 1, help(mfilename), return, end % %result = []; % %theParent = parent(parent(self)); %theFilename = name(theParent); %f = find(theFilename == filesep); %if any(f) % theFilename(1:f(length(f))) = ''; %end % %theDims = dim(self); %theDimnames = ncnames(theDims); %if ~isempty(theDimnames) % thePrompt = {'Select Dimension From', 'NetCDF File', ['"' theFilename '"']}; % theSelection = listdlg('ListString', theDimnames, ... % 'SelectionMode', 'single', ... % 'PromptString', thePrompt); % if any(theSelection) % result = theDims{theSelection}; % end %else % disp(' ## No dimensions available.') %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "uigetvar.m" (text)') fout = fopen('uigetvar.m', 'w'); %function theResult = uigetvar(self) % %% ncitem/uigetvar -- Get a NetCDF variable via dialog. %% uigetvar(self) returns one variable from the NetCDF file %% associated with self, an "ncitem" object, selected from %% a list-dialog. The returned item is an "ncvar" object, %% or the empty-matrix [] if no variable is selected. % %% 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 01-Dec-1997 13:20:58. % %if nargin < 1, help(mfilename), return, end % %result = []; % %theParent = parent(parent(self)); %theFilename = name(theParent); %f = find(theFilename == filesep); %if any(f) % theFilename(1:f(length(f))) = ''; %end % %theVars = var(self); %theVarnames = ncnames(theVars); %if ~isempty(theVarnames) % thePrompt = {'Select Variable From', 'NetCDF File', ['"' theFilename '"']}; % theSelection = listdlg('ListString', theVarnames, ... % 'SelectionMode', 'single', ... % 'PromptString', thePrompt); % if any(theSelection) % result = theVars{theSelection}; % end %else % disp(' ## No variables available.') %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "uint8.m" (text)') fout = fopen('uint8.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "uminus.m" (text)') fout = fopen('uminus.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "unsigned.m" (text)') fout = fopen('unsigned.m', 'w'); %function theResult = unsigned(self, isUnsigned) % %% ncitem/unsigned -- Set/get unsigned flag. %% unsigned(self) returns TRUE if the "unsigned" flag %% has been set to interpret NetCDF signed integer data %% as unsigned. This flag does not affect the contents %% of the NetCDF file itself. Only bytes, shorts, and %% longs are allowed to be unsigned. %% unsigned(self, isUnsigned) sets the "unsigned" flag %% according to the "isUnsigned" argument: 1 or 0. % %% 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-Nov-1998 12:51:36. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % result = self.itIsUnsigned; %else % if isa(self, 'ncvar') | isa(self, 'ncatt') % switch datatype(self) % case {'byte', 'short', 'long'} % isUnsigned = ~~isUnsigned; % otherwise % isUnsigned = ~~0; % end % self.itIsUnsigned = isUnsigned; % end % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "uplus.m" (text)') fout = fopen('uplus.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); disp(' ## Installing: "varid.m" (text)') fout = fopen('varid.m', 'w'); %function theResult = varid(self, theVarid) % %% ncitem/varid -- Variable id of an ncitem. %% varid(self) returns the variable id of self, %% an "ncitem" object. %% varid(self, theVarid) sets the varid of self %% to theVarid and returns self. % %% 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-Aug-1997 11:17:56. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 % result = self.itsVarid; %else % self.itsVarid = theVarid; % result = self; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'ncitem') fclose(fout); disp(' ## Installing: "vertcat.m" (text)') fout = fopen('vertcat.m', 'w'); %function [varargout] = fcn(varargin) % %% fcn -- Apply a function or operator. %% fcn(self, other, ...) applies the function or operator %% derived from the name of this M-file to the arguments. %% the "self" argument is an "ncitem". % %% 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-Aug-1997 11:46:29. % %fcn = mfilename; %f = find(fcn == '/'); %if any(f), fcn(1:f(length(f))) = ''; end % %varargin = [{fcn} varargin]; %varargout = cell(1, nargout); % %[varargout{:}] = feval(varargin{:}); fclose(fout); cd ('..') bund_setdir('@ncrec') disp(' ## Installing: "gt.m" (text)') fout = fopen('gt.m', 'w'); %function theResult = gt(self, theNetcdf) % %% ncrec/gt -- Pipe self into a netcdf object. %% gt(self, theItem) pipes self, an ncrec object, %% into theNetcdf, a netcdf object. % %% 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-Aug-1997 15:55:19. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch class(theNetcdf) % case 'netcdf' % result = rec(theNetcdf, recnum(self), self(:)); % otherwise % warning(' ## Illegal operation.') %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "ncrec.m" (text)') fout = fopen('ncrec.m', 'w'); %function self = ncrec(theNetcdf, theAutoscaleflag) % %% ncrec/ncrec -- Constructor for ncrec class. %% ncrec(theNetcdf, theAutoscaleflag) allocates a new ncrec %% object for the current record-variables associated with %% theNetcdf, a netcdf object. The result is assigned %% silently to "ans" if no output argument is given. % %% 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-Aug-1997 15:55:19. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, self = []; end % %if nargin < 2, theAutoscaleflag = 0; end % %theRecdim = recdim(theNetcdf); %if ~isempty(theRecdim) % theRecdimid = dimid(theRecdim); %else % if nargout < 1, ncans(self), end % return %end % %theVars = var(theNetcdf); %for i = length(theVars):-1:1 % theDims = dim(theVars{i}); % if length(theDims) < 1 | ... % dimid(theDims{1}) ~= theRecdimid % theVars(i) = []; % else % theVars{i} = autoscale(theVars{i}, theAutoscaleflag); % end %end % %theStruct.itsVars = theVars; % %theNCid = ncid(theNetcdf); % %result = class(theStruct, 'ncrec', ncitem('', theNCid)); % %if nargout > 0 % self = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "size.m" (text)') fout = fopen('size.m', 'w'); %function theResult = size(self) % %% ncrec/size -- Size (dimensions) of an ncrec object. %% size(self) returns the size (dimensions) of %% self, an ncrec object. % %% 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-Aug-1997 16:01:38. % %% (N.B. We will want to %% return a cell-list of sizes, I think.) % %DEADLINE = '01-Jan-1999'; % %if nargin < 1, help(mfilename), return, end % %theNCid = ncid(self); %[theSize] = ncmex('recinq', theNCid); % %if length(theSize) < 2 & now > datenum(DEADLINE) % theSize = [theSize 1]; %end % %if nargout > 0 % theResult = theSize; %else % disp(theSize) %end fclose(fout); disp(' ## Installing: "subsasgn.m" (text)') fout = fopen('subsasgn.m', 'w'); %function theResult = subsasgn(self, theStruct, other) % %% ncrec/subsasgn -- Overloaded assignment for ncrec. %% subsasgn(self, theStruct, other) processes the %% subscripted assignment for self, an "ncrec" object. %% The self is returned. The only allowed syntax %% is self(theRecindices) = theRecs, for an array %% of record-structures. % %% Also see: ncrec/subsref. % %% 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-Aug-1997 16:01:38. % %if nargin < 3, help(mfilename), return, end % %result = []; % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %if isa(theSubs, 'cell'), theSubs = theSubs{1}; end % %% N.B. Should be expanded to "self(...).field(...)" syntax. %% The ncrec/subsref method already complies. % %switch theType %case '()' % theRecindices = theSubs; % theVars = self.itsVars; % if isa(other, 'cell'), other = other{1}; end % theRecs = other; % theFields = fieldnames(theRecs); % for k = 1:length(theVars) % for j = 1:length(theRecindices) % if theRecindices(j) > 0 % for i = 1:length(theFields) % if strcmp(name(theVars{k}), theFields{i}) % a = ['theVars{k}(' int2str(theRecindices(j)) ', :)' ... % ' = theRecs(' int2str(j) ').' theFields{i} ';']; % eval(a); % end % end % end % end % end % result = self; %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "subsref.m" (text)') fout = fopen('subsref.m', 'w'); %function theResult = subsref(self, theStruct) % %% ncrec/subsref -- Overloaded subscriting for ncrec. %% subsref(self, theStruct) processes subscript references to self, %% an "ncrec" object. The basic syntax is self(theRecindex), which %% returns the record-data struct corresponding to theRecindex. If %% theRecindex == 0, the struct contains all zeros, for use as a %% template. The syntax can be extended with a valid field name %% and indices, as in "self(10).field(1:20, 2:2:30)". % %% Also see: ncatt/subsasgn. % %% 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-Aug-1997 16:01:38. % %if nargin < 1, help(mfilename), return, end % %result = []; % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %if isa(theSubs, 'cell'), theSubs = theSubs{1}; end % %switch theType %case '()' % theRecindex = theSubs; % theVars = self.itsVars; % theVarData = cell(1, length(theVars)); % theVarName = cell(1, length(theVars)); % for i = 1:length(theVars) % theVarName{i} = name(theVars{i}); % if theRecindex > 0 % theVarData{i} = theVars{i}(theRecindex, :); % else % theSize = ncsize(theVars{i}); % if length(theSize) == 1, theSize = [theSize 1]; end % if length(theSize) == 2, theSize = [theSize 1]; end % theVarData{i} = zeros(theSize(2:length(theSize))); % end % end % result = cell2struct(theVarData, theVarName, 2); % for i = 1:length(s) % if ~iscell(s(i).subs), s(i).subs = {s(i).subs}; end % end % switch length(s) % case 0 % case 1 % result = getfield(result, s(1).subs) % case 2 % result = getfield(result, {1}, s(1).subs, s(2).subs) % otherwise % warning([' ## Illegal syntax: Too many substripts.']) % end %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'ncrec') fclose(fout); cd ('..') bund_setdir('@ncvar') disp(' ## Installing: "addoffset.m" (text)') fout = fopen('addoffset.m', 'w'); %function theResult = addoffset(self, theNewAddoffset) % %% ncvar/addoffset -- "add_offset" attribute value. %% addoffset(self) returns the "add_offset" attribute %% value of self, an "ncvar" object, or 0 if no such %% attribute exists. %% addoffset(self, theNewAddoffset) changes the add-offset %% of self, an "ncvar" object, to theNewAddoffset. % %% 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 22-Dec-1998 10:04:05. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % result = 0; % theAtt = ncatt('add_offset', self); % if ~isempty(theAtt), result = theAtt(:); end % else % theVartype = datatype(self); % theAtttype = theVartype; % theAtt = ncatt('add_offset', theAtttype, theNewAddoffset, self); % result = theAtt; %end % %if nargout > 0 % theResult = result; % elseif nargin < 2 % disp(result) %end fclose(fout); disp(' ## Installing: "att.m" (text)') fout = fopen('att.m', 'w'); %function theResult = att(self, theAttname) % %% ncvar/att -- Attributes of an ncvar object. %% att(self, 'theAttname') returns the ncatt object %% whose name is theAttname, associated with self, %% an ncvar object. %% att(self) returns the cell-list of ncatt objects %% associated with self, an ncvar object. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin == 1 & ncid(self) >= 0 % [theVarname, theVartype, theVarndims, theVardims, theVarnatts] = ... % ncmex('varinq', ncid(self), varid(self)); % result = cell(1, theVarnatts); % for i = 1:theVarnatts % theAttnum = i-1; % theAttname = ncmex('attname', ncid(self), varid(self), theAttnum); % result{i} = ncatt(theAttname, self); % end % elseif ncid(self) >= 0 % result = ncatt(theAttname, self); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "browse.m" (text)') fout = fopen('browse.m', 'w'); %function theResult = browse(varargin) % %% ncvar/browse -- Interactive plot of NetCDF variable. %% browse(z, 'thePen') plots NetCDF variable z as %% an interactive "pxline", using 'thePen'. The syntax %% is the same as the "ncvar/plot" function. % %% 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-Apr-1997 09:44:36. %% Updated 01-Jan-2000 09:59:35. % %if nargin < 1, help(mfilename), return, end % %varargout = cell(1, 1); %[varargout{:}] = plot(varargin{:}); %h = varargout{1}; %if exist('pxline', 'file') == 2 % result = pxline(h); %end %delete(h); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "contour.m" (text)') fout = fopen('contour.m', 'w'); %function theResult = contour(varargin) % %% ncvar/contour -- Contour a NetCDF variable. %% contour(z, 'thePen') meshes NetCDF variable z, %% an "ncvar" object, using 'thePen'. If z is z(x), %% for coordinate variable x, then the function is %% called recursively as NCMesh(x, z, 'thePen'). %% For z(x, y), the recursive call is NCMesh(x, y, %% z, 'thePen'). The x, y, and z axes are labeled %% with the names and units of the corresponding %% variables. The title is set to the name of %% the z variable. % %% 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-Apr-1997 09:44:36. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end %result = []; % %% Isolate the pen. % %thePen = '-'; %if isstr(varargin{length(varargin)}) % thePen = varargin{length(varargin)}; % varargin(length(varargin)) = []; %end % %x = []; y = []; z = []; % %theXLabel = 'Index Number'; %theYLabel = 'Index Number'; %theZLabel = 'Value'; % %if length(varargin) == 1 % z = varargin{1}; % theNetCDF = parent(z); % theSize = size(z); % theDims = dim(z); % if length(theDims) < 1, return, end % if length(theSize) > 0 % x = ncvar(name(theDims{1}), theNetCDF); % if isempty(x), x = (1:theSize(1)).'; end % end % if length(theSize) > 1 % y = ncvar(name(theDims{2}), theNetCDF); % if isempty(y), y = (1:theSize(2)).'; end % end % if ~isempty(y) % result = contour(x, y, z, thePen); % end % elseif length(varargin) > 1 % x = varargin{1}; % z = varargin{2}; % if length(varargin) > 2 % y = varargin{2}; % z = varargin{3}; % end % if isa(x, 'ncvar') % theXLabel = name(x); % a = ncatt('units', x); % theXUnits = a(:); % if ~isempty(theXUnits), theXLabel = [theXLabel ' ' theXUnits]; end % x = x(:); % end % if isa(y, 'ncvar') % theYLabel = name(y); % a = ncatt('units', y); % theYUnits = a(:); % if ~isempty(theYUnits), theYLabel = [theYLabel ' ' theYUnits]; end % y = y(:); % end % theZLabel = name(z); % a = ncatt('units', z); % theZUnits = a(:); % if ~isempty(theZUnits), theZLabel = [theZLabel ' ' theZUnits]; end % axes(gca) % if length(varargin) > 2 % result = contour3(x, y, z(:), thePen); % xlabel(labelsafe(theXLabel)) % ylabel(labelsafe(theYLabel)) % zlabel(labelsafe(theZLabel)) % end % theTitle = name(z); % title(labelsafe(theTitle)) %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "copy.m" (text)') fout = fopen('copy.m', 'w'); %function theResult = copy(self, theDestination, ... % copyData, copyAttributes, copyDimensions) % %% ncvar/copy -- Copy a NetCDF variable, including data and attributes. %% copy(self, theDestination, copyData, copyAttributes) copies the NetCDF %% variable associated with self, an "ncvar" object, to the location %% associated with theDestination, a "netcdf" or "ncvar" object. If %% successful, the new "ncvar" object is returned; otherwise, the empty- %% matrix [] is returned. The default behavior is NOT to copy data and %% attributes, unless otherwise directed with non-zero "copyData" and/or %% "copyAttributes". %% %% To copy several variables without rewriting theDestination file %% unnecessarily, call this routine once for each variable, using %% copyData = 0 and copyAttributes = 1. Then call it again for the %% same variables, using copyData = 1 and copyAttributes = 0. %% %% Small computers may require limits on memory usage during copying. %% If copyData > 1, it specifies the maximum number of data elements to %% transfer per NetCDF call. For copyData = 1, the number is 16*1024 %% elements. Use "inf" to transfer all the data in one call. %% %% copy(self, theDestination, copyData, copyAttributes, copyDimensions) %% for copyDimensions = 0 fulfills the copying request only if the %% corresponding dimensions already exist in theDestination NetCDF %% file. The default is copyDimensions = 1, which copies the %% corresponding dimensions automatically as needed. % %% 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 14-May-1997 10:56:35. %% Revised 05-Sep-1997 22:42:02. %% Revised 24-Mar-1998 17:38:36. For Matlab 5.2. % %% Arguments. % %if nargin < 2, help(mfilename), return, end %if nargin < 3, copyData = 0; end %if nargin < 4, copyAttributes = 0; end %if nargin < 5, copyDimensions = 1; end %if nargout > 0, theResult = []; end % %% Dimensions. % %switch ncclass(theDestination) %case 'netcdf' % switch ncclass(self) % case 'ncvar' % if isempty(theDestination{name(self)}) % d = dim(self); % for i = 1:length(d) % if ~copyDimensions % status = theDestination(name(d{i})); % else % status = (theDestination < d{i}); % end % if isempty(status), return, end % end % end % otherwise % end %case 'ncvar' %otherwise % warning(' ## Incompatible arguments.') %end % %% Variable definition. % %switch ncclass(theDestination) %case 'netcdf' % switch ncclass(self) % case 'ncvar' % v = theDestination{name(self)}; % if isempty(v) % v = ncvar(name(self), datatype(self), ncnames(dim(self)), theDestination); % if isempty(v), return, end % end % otherwise % end %case 'ncvar' % v = theDestination; %otherwise % warning(' ## Incompatible arguments.') %end % %% Copy attributes. % %if copyAttributes % switch ncclass(self) % case 'ncvar' % a = att(self); % for i = 1:length(a) % status = (v < a{i}); % if isempty(status), return, end % end % otherwise % end %end % %% Copy data. % %MAX_CHUNK = 16 * 1024; % 16 K values = 128 K bytes. % %if copyData > 1, MAX_CHUNK = copyData; end % %if copyData % theClass = ncclass(self); % switch theClass % case {'ncvar', 'double', 'char', 'uint8'} % d = dim(v); % theSize = size(v); % if isempty(d) % kmax = 1; % elseif isrecdim(d{1}) % theSize = ncsize(self); % kmax = prod(theSize); % else % kmax = min(prod(theSize), prod(size(self))); % end % [s, c] = ncind2sub(theSize, 1, min(MAX_CHUNK, kmax)); % if length(c) > 0, MAX_CHUNK = c(1); end % k = 0;; % while k < kmax; % kstep = min(MAX_CHUNK, kmax-k); % [s, c] = ncind2sub(theSize, k+1, kstep); % [m, n] = size(s); % switch theClass % case 'ncvar' % for i = 1:m % t = s(i, :); %% v(t{:}) = self(t{:}); % "()" out-of-context here. % theSubs.type = '()'; % theSubs.subs = t; % temp = subsref(self, theSubs); % v = subsasgn(v, theSubs, temp); % end % otherwise % for i = 1:m % t = s(i, :); %% v(t{:}) = self(k+1:k+kstep); % Here too. % theSubs.type = '()'; % theSubs.subs = t; % temp = self(k+1:k+kstep); % v = subsasgn(v, theSubs, temp); % end % end % k = k + kstep; % end % otherwise % warning(' ## Incompatible arguments.') % end %end % %% Return. % %if nargout > 0, theResult = v; end fclose(fout); disp(' ## Installing: "datatype.m" (text)') fout = fopen('datatype.m', 'w'); %function theResult = datatype(self, theNewDatatype) % %% ncvar/datatype -- Numeric type of an ncatt object. %% datatype(self) returns the numeric type of self, %% an "ncvar" object. The allowed datatypes are: %% {'byte', 'char', 'short', 'long', 'float', 'double'}. %% datatype(self, 'theNewDatatype') changes the datatype %% of self to 'theNewDatatype'. The NetCDF file itself %% must be writeable. The function will also reset the %% datatype of the associated "_FillValue" (if any) to %% the same new type. The new self 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 07-Aug-1997 09:42:59. % %if nargin < 1, help(mfilename), return, end % %result = ''; % %theTypes = {'byte', 'char', 'short', 'long', 'float', 'double'}; % %theNCid = ncid(self); % %% Get the existing datatype. % %if theNCid >= 0 % theVarid = varid(self); % [theName, theType, theNdims, theDimids, theNatts, status] = ... % ncmex('varinq', theNCid, theVarid); % if status >= 0 & ~isstr(theType) % theType = theTypes{theType}; % end %else % theType = self.itsVartype; %end % %result = theType; % %% Change the datatype. % %if nargin > 1 % theNetCDF = parent(self); % switch lower(permission(theNetCDF)) % case {'nowrite'} % disp([' ## No "' mfilename '" action taken; ' ... % 'file "' name(theNetCDF) '" permission is "nowrite".']) % if nargout > 0 % theResult = self; % else % disp(self) % end % return % end % theVarname = name(self); % theTempname = theVarname; % theTempname(:) = '_'; % self = name(self, theTempname); % theDimnames = ncnames(dim(self)); % theNetCDF{theVarname} = feval(['nc' theNewDatatype], theDimnames{:}); % theVar = theNetCDF{theVarname}; % theAtts = att(self); % for i = 1:length(theAtts) % copy(theAtts{i}, theVar) % end % if ~isempty(fillval(self)) % fillval(theVar, fillval(self)); % end % theData = self(:); % if ~isempty(theData) % theVar(:) = theData; % end % theChangedNetCDF = delete(self); % result = theChangedNetCDF{theVarname}; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "dim.m" (text)') fout = fopen('dim.m', 'w'); %function theResult = dim(self, theDimname) % %% ncvar/dim -- Dimensions of an ncvar object. %% dim(self, 'theDimname') returns the ncdim object %% whose name is theDimname, associated with self, %% an ncvar object. %% dim(self) returns the cell-list of ncdim objects %% associated with self, an "ncvar" object. % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin < 2 & ncid(self) >= 0 % [theVarname, theVartype, theVarndims, theVardimids, theVarnatts, status] = ... % ncmex('varinq', ncid(self), varid(self)); % result = cell(1, theVarndims); % for i = 1:theVarndims % theDimid = theVardimids(i); % [theDimname, theDimsize, status] = ... % ncmex('diminq', ncid(self), theDimid); % result{i} = ncdim(theDimname, self); % end %elseif nargin > 1 % result = ncdim(theDimname, self); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "fillval.m" (text)') fout = fopen('fillval.m', 'w'); %function theResult = fillval(self, theNewFillValue) % %% ncvar/fillval -- Get or set _FillValue of a netcdf variable. %% fillval(self) returns the value of the _FillValue %% attribute of self, an ncvar object. %% fillval(self, theNewFillValue) sets the _FillValue %% attribute of self, an ncvar object, to theNewFillValue. %% The type of the fill value is set to the type of the %% netcdf variable. The resulting ncatt object 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 07-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % theAtt = ncatt('_FillValue', self); % result = theAtt(:); % else % theVartype = datatype(self); % theAtttype = theVartype; % theAtt = ncatt('_FillValue', theAtttype, theNewFillValue, self); % result = theAtt; %end % %if nargout > 0 % theResult = result; % elseif nargin < 2 % disp(result) %end fclose(fout); disp(' ## Installing: "foo.nc.copy" (binary)') fout = fopen('foo.nc.copy', 'w'); %?43444601000000000000000a000000070000000474696d6500 %?000000000000036c6174000000000a000000036c6f6e000000 %?00050000000c656c61707365645f74696d6500000064000000 %?0c686f7273655f6e756d626572000000050000000d612e646f %?747465642e6e616d65000000000000160000000d612d646173 %?6865642d6e616d65000000000000160000000c000000050000 %?000b4465736372697074696f6e00000000020000000a546573 %?742066696c652e000000000006417574686f72000000000002 %?0000001e44722e20436861726c657320522e2044656e68616d %?2c205a594445434f2e00000000000743726561746564000000 %?00020000001430342d4f63742d323030312031323a30303a35 %?350000000d612e646f747465642e6e616d6500000000000002 %?0000001e6120646f7474656420676c6f62616c206174747269 %?62757465206e616d6500000000000d612d6461736865642d6e %?616d65000000000000020000001e612064617368656420676c %?6f62616c20617474726962757465206e616d6500000000000b %?0000000c0000000474696d6500000001000000000000000c00 %?00000100000005756e69747300000000000002000000077365 %?636f6e6473000000000400000004000018bc000000036c6174 %?0000000001000000010000000c000000040000000a5f46696c %?6c56616c756500000000000400000001fffffc190000000c73 %?63616c655f666163746f720000000400000001000000010000 %?000a6164645f6f666673657400000000000400000001000000 %?0000000005756e697473000000000000020000000d64656772 %?6565735f6e6f72746800000000000004000000280000057c00 %?0000036c6f6e0000000001000000020000000c000000010000 %?0005756e697473000000000000020000000c64656772656573 %?5f656173740000000400000014000005a40000000c656c6170 %?7365645f74696d6500000001000000030000000c0000000100 %?000005756e697473000000000000020000000a666f72746e69 %?6768747300000000000600000320000005b80000000c686f72 %?73655f6e756d62657200000001000000040000000000000000 %?0000000400000014000008d800000005737065656400000000 %?00000200000003000000040000000c0000000100000005756e %?69747300000000000002000000126675726c6f6e67732f666f %?72746e6967687400000000000600000fa0000008ec00000001 %?7a000000000000030000000000000001000000020000000c00 %?00000200000005756e69747300000000000002000000066d65 %?7465727300000000000b76616c69645f72616e676500000000 %?050000000200000000459c400000000004000000c8000018c0 %?00000001740000000000000300000000000000010000000200 %?0000000000000000000004000000c800001988000000017000 %?0000000000030000000000000001000000020000000c000000 %?010000000a5f46696c6c56616c756500000000000400000001 %?ffffffff00000004000000c800001a50000000027268000000 %?0000030000000000000001000000020000000c000000010000 %?000a5f46696c6c56616c756500000000000400000001ffffff %?ff00000004000000c800001b180000000d612e646f74746564 %?2e6e616d6500000000000001000000050000000c0000000100 %?00000d612e646f747465642e6e616d65000000000000020000 %?00206120646f74746564207661726961626c65206174747269 %?62757465206e616d6500000002000000180000188c0000000d %?612d6461736865642d6e616d65000000000000010000000600 %?00000c000000010000000d612d6461736865642d6e616d6500 %?00000000000200000020612064617368656420766172696162 %?6c6520617474726962757465206e616d650000000200000018 %?000018a4000000000000000a000000140000001e0000002800 %?0000320000003c00000046000000500000005affffff74ffff %?ff8affffffa0ffffffacffffffcc3f7b736e638a7b5c3f80e3 %?2cb31a20913f91357a205da8423fa1960f6c66e01b3fb5b936 %?0cccdf763fbdbb87106a5d1f3fbff0c34e9000d53fc2ac7fc7 %?13e2f43fc31e13bb4c3af33fc85ea2f6e5bb1f3fc86067d7fa %?b7413fc973597fcf8a893fcafe1781f421c13fcbd25c765ed2 %?ba3fcc98e21de3291e3fcfc9aa8553ca883fcfd719053bfb71 %?3fd12c78c5595bfa3fd356b8b58e83763fd4305bba76b6e53f %?d4981fd3ac73363fd515f2ae17c1943fd52a1706fe4f243fd5 %?7beae30711563fd583712bd4a3203fd6bf0a59a33ad33fd705 %?0068a8c7363fd77f629c1fd3b33fd7f564fe0fb8ca3fd8a2de %?76a3422b3fd9713a5438f3083fd9ad2f2d94b17a3fd9ef1992 %?fcc4ac3fda9bca993899503fdaa64b87b728eb3fdbb3774b28 %?48123fdbecc5b2d986263fdc3442826f52c03fdc99bd59905f %?3c3fdcd5eedd76fc223fdd38264ca5af2f3fdd44fd5306d47a %?3fdd93b9668d57423fde73eeb3703f763fdf12917e2943c43f %?df66a71d0cc4ba3fdf9a4f878961113fdff0c519b4ba583fe0 %?45a4abca5ad63fe07f618eb6d4a93fe0da1458ac0a603fe0ed %?6b3fcf320d3fe145cbecd4b4533fe18c62ffa395a93fe1bfe7 %?a9cba6543fe22e3d87c16dad3fe25ee227b05d723fe31358fd %?08f5223fe3138c5b0e7a6e3fe3763c1534dc1f3fe3c53913bb %?31ac3fe3da21f0a097083fe4432c67a69c8e3fe447e63cc135 %?b13fe4c89cdf6d14a63fe4ddb1c06bda463fe4eb7cdf785f21 %?3fe610a3ea2c95763fe61c1533b206af3fe644cea1a802d83f %?e6cd7c21b6fba53fe6dc22d5c3f19d3fe6df03d27939e03fe7 %?579be0b7ecd03fe75a99a5db5bac3fe79f1d62b31fea3fe838 %?6537da34bf3fe83ce3bcd718633fe89c16eb713c6f3fe8fa32 %?8da722773fe99040be350a753fe9bb2f1d9fee2f3fea2b28a5 %?e2085f3fea9900e612d8613feaab248ccc188a3feb049f16ab %?b7a03feb29b2ac8014083feba5ed4a84963d3febcc95708686 %?543fec6337f02effdc3fedc731c826fd793fee083aea04d064 %?3fee16262aabc7ad3fee1c1cf608c4343fef1adae1d721253f %?ef233d1f9835b13fef70143df9c08c3fef8574bd94eb493fef %?a227ca2e7aa63fefbe3044b7e92a0000000200000005000000 %?1b000000640000007d3ff0b3243415cb843ff68a61c1020841 %?3fffc12e65264f8b3ff6648d418f439e3ff184eec39f60003f %?f0dad4e974b77d3ff6b2127660f43a3fffe8df1a853b843ff6 %?8c3df6ee2f973ff1ac9f78fe4bf93ff1b66aacbff3623ff78d %?a839ac301f4000623a6ee83bb43ff767d3ba396b7c3ff28835 %?3c4987de3ff373d83c9962383ff94b15c9859ef4400140f136 %?d4f31f3ff925414a12da513ff445a2cc22f6b33ff8289606f3 %?3f0e3ffdffd393df7bcb40039b501c01e18a3ffdd9ff146cb7 %?283ff8fa60967cd38a3ffab16fa7dd4297400044569a64bfaa %?4004dfbcec76e34f4000316c5aab5d583ffb833a3766d7123f %?fb52c9dcf28a3940009503b4ef637b4005306a070187204000 %?8219753601293ffc24946c7c1eb43ffcb92a1c6b7abf400148 %?33d4abdbbe4005e39a26bdff634001354994f2796c3ffd8af4 %?abf50f3a3ffceeab1e409447400162f4559668824005fe5aa7 %?a88c274001500a15dd06303ffdc075adca28c23ffeeabe3c7c %?cb9a400260fde4b4842b4006fc6436c6a7d040024e13a4fb21 %?da3fffbc88cc0660153ffeeb404fcf0cf84002613eee5da4da %?4006fca5406fc88040024e54aea442893fffbd0adf58a1743f %?ff34da474b488a4002860bea1bc2a4400721723c2de6484002 %?7321aa626052400003526b6a6e833fff8b98ccd1d2a04002b1 %?6b2cdf07ae40074cd17ef12b5440029e80ed25a55d40002eb1 %?ae2db38e3fffb0dcf476cf024002c40d40b185e040075f7392 %?c3a9844002b12300f8238e40004153c20031bf3fffcdb4a918 %?47984002d2791b02422a40076ddf6d1465cf4002bf8edb48df %?d940004fbf9c50ee0a4000033ed885716a4002eedd9efb8fc8 %?40078a43f10db36e4002dbf35f422d7740006c24204a3ba840 %?00034b2cb8a90d4002eee9f32ec76b40078a504540eb104002 %?dbffb375651a40006c30747d734a3fffeb8ce3d13a2c4002e1 %?65385ebb7440077ccb8a70df194002ce7af8a5592340005eab %?b9ad67543fff2ca33b0caa2a400281f063fc737340071d56b6 %?0e971840026f06244311223ffffe6dca963ea53ffeb134abd3 %?efa6400244391c6016314006df9f6e7239d64002314edca6b3 %?e03fff82ff3b5d84213ffe6d17df2953484002222ab60ac802 %?4006bd91081ceba740020f40765165b13fff3ee26eb2e7c43f %?fe12aee88422cd4001f4f63ab82fc54006905c8cca536a4001 %?e20bfafecd733ffee479780db7483ffe036d626fc00a4001ed %?5577adfe63400688bbc9c022084001da6b37f49c123ffed537 %?f1f954853ffdc3431cf14dad4001cd4054eec535400668a6a7 %?00e8da4001ba56153562e33ffe950dac7ae2283ffdbd2fdc28 %?57884001ca36b48a4a224006659d069c6dc74001b74c74d0e7 %?d13ffe8efa6bb1ec043ffca4b5155be07240013df951240e98 %?4005d95fa336323c40012b0f116aac463ffd767fa4e574ee3f %?fc5ff9630e00e740011b9b77fd1ed24005b701ca0f42774001 %?08b13843bc803ffd31c3f29795623ffbe24c2c2b1ca44000dc %?c4dc8bacb04005782b2e9dd0564000c9da9cd24a5f3ffcb416 %?bbb4b1203ffb62c745ff6f2840009d026975d5f240053868bb %?87f99740008a1829bc73a03ffc3491d58903a33ffa9c973125 %?d0e8400039ea5f0906d24004d550b11b2a78400027001f4fa4 %?813ffb6e61c0af65643ff9a14bc917e81e3fff7889560424da %?400457aafd1436123fff52b4d69160373ffa731658a17c993f %?f955538661c51e3fff2c91134e01da400431aedbb924923fff %?06bc93db3d373ffa271e15eb59993ff9005a8ca071183ffed7 %?98198cadd5400407325ed87a8f3ffeb1c39a19e9323ff9d225 %?1c2a05943ff81aea57f9c11c3ffdf227e4e5fdd94003947a44 %?8522923ffdcc53657339363ff8ecb4e78355983ff80ca84735 %?e9403ffde3e5d42225fc40038d593c2336a33ffdbe1154af61 %?593ff8de72d6bf7dbb3ff6948fcf7a61483ffc6bcd5c669e05 %?4002d14d004572a73ffc45f8dcf3d9623ff7665a5f03f5c43f %?f6420ba996f42a3ffc1949368330e74002a80aed53bc183ffb %?f374b7106c443ff713d6392088a63ff5da08ba7b33bd3ffbb1 %?464767707a4002740975c5dbe23ffb8b71c7f4abd63ff6abd3 %?4a04c8383ff5447aaf6a15cc3ffb1bb83c5652894002294270 %?3d4ce93ffaf5e3bce38de63ff616453ef3aa483ff4eacb8ca0 %?a30a3ffac209198cdfc64001fc6aded893883ffa9c349a1a1b %?233ff5bc961c2a37853ff4570c66950e023ffa2e49f3814abf %?4001b28b4bd2c9043ffa0875740e861c3ff528d6f61ea27e3f %?f4439cf2c6fcf93ffa1ada7fb339b64001a8d391ebc0803ff9 %?f506004075123ff51567825091743ff3cbe0b026911e3ff9a3 %?1e3d12cddb40016cf5709b8a923ff97d49bda009383ff49dab %?3fb0259a3ff2727720004da93ff849b4acec8a664000c040a8 %?8868d83ff823e02d79c5c23ff34441af89e2253ff17b27a98a %?fc153ff75265367738d240004498ed4dc00e3ff72c90b70474 %?2e3ff24cf2391490903ff0f773a28cf5e23ff6ceb12f79329f %?400002bee9cebcf43ff6a8dcb0066dfc3ff1c93e32168a5e3f %?f0a667f1b08e563ff67da57e9ccb123fffb47222c1125c3ff6 %?57d0ff2a066f3ff17832813a22d13ff01ea2f0efc72c3ff5f5 %?e07ddc03e83fff2cad22004b323ff5d00bfe693f453ff0f06d %?80795ba73fee580d9dca92953ff503445bd186073ffe3a10ff %?f5cd513ff4dd6fdc5ec1643feffba2bcddbb8c3fecee571be2 %?33853ff44e691add567f3ffd8535bf019dc93ff428949b6a91 %?dc3fee91ec3af55c7c3feab992b983a8223ff33406e9ae10ce %?3ffc6ad38dd258183ff30e326a3b4c2a3fec5d27d896d1193f %?ea41e8f5b901623ff2f83207c8bd6e3ffc2efeabed04b73ff2 %?d25d8855f8ca3febe57e14cc2a583fe8239f89e7a2ca3ff1e9 %?0d51e00e223ffb1fd9f604556b3ff1c338d26d497e3fe9c734 %?a8facbc03fe6790bd07015733ff113c3752447763ffa4a9019 %?488ec03ff0edeef5b182d33fe81ca0ef833e6a3fe5462ff17d %?1d063ff07a5585aacb403ff9b12229cf128a3ff05481063806 %?9c3fe6e9c5109045fd3fe2c41733d8a16c3fee72924db11ae6 %?3ff87015cafcd4bc3fee26e94ecb919f3fe467ac52ebca633f %?e1b07a7d6e3e2a3fed5ef59746b7a43ff7e6476fc7a31c3fed %?134c98612e5d3fe3540f9c8167213fdbc33ed59fc7763fe990 %?1a84a85d343ff5fed9e67875e43fe9447185c2d3ee3fdf0a69 %?13c619643fdbc12b878ecc643fe98f10dd9fdfac3ff5fe5512 %?f437203fe94367deba56653fdf0855c5b51e523fd7e01a8c4b %?07a23fe79e885ffdfd4a3ff50610d42345ef3fe752df611874 %?043fdb2744ca7159903fd4ef7d0168d5fa3fe626399a8ce476 %?3ff449e9716ab9853fe5da909ba75b303fd836a73f8f27e83f %?d42eef748706a03fe5c5f2d41bfcca3ff419c60e3245ae3fe5 %?7a49d53673833fd77619b2ad588e3fd0945d6812a7423fe3f8 %?a9cde1cd1a3ff333218b152dd73fe3ad00cefc43d43fd3db87 %?a638f9303fd06cab7de0b39a3fe3e4d0d8c8d3463ff3293510 %?88b0ed3fe39927d9e34a003fd3b3d5bc0705883fc8e5d48aa5 %?3f903fe1e7f03c81c95e3ff22ac4c2652bf83fe19c473d9c40 %?173fcf742906f1e36c3fc7b07edde12fbc3fe19a9ad150c568 %?3ff2041a0ccca9fe3fe14ef1d26b3c223fce3ed35a2dd3983f %?c6e9e1cf0df0083fe168f38d9bf57c3ff1eb466af242083fe1 %?1d4a8eb66c353fcd78364b5a93e43fb2ace5039318583fdc08 %?2f7495b9083ff038d88149b58c3fdb70dd76caa67c3fbfc98d %?fc2c60103fb1d9ef677605003fdbd3720d8e74343ff02ba927 %?87e4563fdb3c200fc361a63fbef698600f4cb83fae22cad4dd %?c1f03fdb214f8e4cab303feffe410f6ee42c3fda89fd908198 %?a43fbc2e0e630828b03f9dd8990b2910c03fd93a7fc4638400 %?3fef0ad92a7a50933fd8a32dc69871723fb492cf3b638be83f %?9b3a87dc2443e03fd9109eb17337303feef5e8a1022a2c3fd8 %?794cb3a824a43fb3eb4aefa258b03f9abaa8a21e70a03fd908 %?a0bdd2d9fc3feef1e9a731fb923fd8714ec007c7703fb3cb53 %?2120e3e03f846a02321204003fd80046454183143fee6dbc6a %?e9501d3fd768f4477670863faf53d27db710703f83d073f04d %?9e003fd7fb79d3335fe43fee6b5631e23e853fd76427d5684d %?563faf2d6eed45f6f03f72045ff28373803fd7a507b37b00c0 %?3fee401d22060ef43fd70db5b5afee343fac79ddef82fde03f %?6516bf240a62003fd78723b1f907b83fee312b2145126f3fd6 %?efd1b42df52a3fab8abde37335903f665bc7fc6abd003fd789 %?adc3a9c86c3fee32702a1d72ca3fd6f25bc5deb5e03fab9f0e %?70f93b403f82040a3a6837803fd7ed16858434b03fee64248b %?0aa8eb3fd755c487b922223faeba547fcc9d503f94799d5bdf %?c1203fd8a490096eef043feebfe14d0006163fd80d3e0ba3dc %?783fb23b104f9138003fa8c6c6b78a7b103fda75cf0aa24254 %?3fefa880cd99afbe3fd9de7d0cd72fc83fb9800c545e85403f %?ae227f523746b03fdb21461df7dbc83feffe3c57447c783fda %?89f4202cc93c3fbc2de8a1b4eb103fb74741012894083fdd2e %?c673fb17f43ff0827e41230d473fdc9774763005683fc231f4 %?fce0ede03fc0806f572336c43fdf9d2ddf428e543ff11e181b %?f4eadf3fdf05dbe1777bc83fc70ec3d36fdaa03fc161c5468d %?9e703fe006ec6b7be1163ff13a42d9e237d43fdf7686d92caf %?9e3fc7f019c2da424c3fc608cf667761283fe130aef37651c4 %?3ff1cf241ddf702c3fe0e505f490c87d3fcc9723e2c405043f %?c81c2c0a3f77883fe1b5861c68575c3ff2118fb25872f83fe1 %?69dd1d82ce153fceaa80868c1b643fcfab0a092de3f03fe399 %?3d9c23f2763ff3036b723640843fe34d949d3e692f3fd31caf %?42bd43e63fd119de5efc92ee3fe43b6a4956c2f03ff35481c8 %?cfa8c23fe3efc14a7139aa3fd461089d22e4dc3fd66bed575f %?e5f23fe6e471c5886c723ff4a90586e87d833fe698c8c6a2e3 %?2c3fd9b317958637e03fe287cff8f267d43fee364b12cae14e %?3ff851f22d89b7f13fedeaa213e558083fe42b65180590cc3f %?e3fe52382bf2103fefaccd52046b8a3ff90d334d267d0e3fef %?6124531ee2433fe5a1e7573f1b073fe44f80e0e656503feffd %?fbfabecfc93ff935caa183af2e3fefb252fbd946823fe5f315 %?fff97f463fe47264e16cbabc3ff0106ffda29a1b3ff9473ca1 %?c6e1643fefd536fc5faaef3fe615fa007fe3b33fea751115fe %?c1233ff311c617eb9d4e3ffc4892bc0fe4983ff2ebf19878d8 %?ab3fec18a63511ea1a3feaa8f612318cdb3ff32bb89605032a %?3ffc62853a294a743ff305e416923e873fec4c8b3144b5d23f %?ec86fae2af8a543ff41abafe4401e63ffd5187a26849303ff3 %?f4e67ed13d433fee2a9001c2b34b3fed0c97d9e2877f3ff45d %?8979dd807c3ffd94561e01c7c63ff437b4fa6abbd93feeb02c %?f8f5b0763fedc04af04a41663ff4b76305115d703ffdee2fa9 %?35a4ba3ff4918e859e98cc3fef63e00f5d6a5d3fee7018b991 %?a6823ff50f49e9b50ffe3ffe46168dd957483ff4e9756a424b %?5a3ff009d6ec5267bd6120646f74746564207661726961626c %?65206e616d6500006120646173686564207661726961626c65 %?206e616d650000 fclose(fout); disp(' ## Installing: "gt.m" (text)') fout = fopen('gt.m', 'w'); %function theResult = gt(self, other) % %% ncvar/gt -- Redirection operator. %% gt(self, theNetcdf) redirects self, an ncvar object, %% into theNetcdf, a netcdf object. This copies the %% variable definition, but not its data or attributes. %% gt(self, theNCVar) redirects the contents of self, an %% ncvar object, into theNCVar, an ncvar object. This %% copies variable data, but not the attributes. %% gt(self, theNCVar) redirects the contents of self, a %% double or char object, into theNCVar, an ncvar object. % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch class(other) % case 'netcdf' % No data or attributes copied. % result = copy(self, other, 0, 0); % case 'ncvar' % switch class(self) % case 'ncvar' % Copy the data. % result = (other < self(:)); % case 'ncatt' % Copy the attribute. % result = ncatt(name(other), datatype(other), other(:), self); % case {'double', 'char'} % Copy the data brute-force. % if isequal(prod(size(self)), prod(size(other))) | ... % prod(size(self)) == 1 % other(:) = self(:); % result = other; % end % otherwise % end % otherwise % warning(' ## Incompatible arguments.') %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "image.m" (text)') fout = fopen('image.m', 'w'); %function theResult = Mesh(varargin) % %% ncvar/mesh -- Mesh a NetCDF variable. %% mesh(z, 'thePen') meshes NetCDF variable z, %% an "ncvar" object, using 'thePen'. If z is z(x), %% for coordinate variable x, then the function is %% called recursively as NCMesh(x, z, 'thePen'). %% For z(x, y), the recursive call is NCMesh(x, y, %% z, 'thePen'). The x, y, and z axes are labeled %% with the names and units of the corresponding %% variables. The title is set to the name of %% the z variable. % %% 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-Apr-1997 09:44:36. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end %result = []; % %% Isolate the pen. % %thePen = '-'; %if isstr(varargin{length(varargin)}) % thePen = varargin{length(varargin)}; % varargin(length(varargin)) = []; %end % %x = []; y = []; z = []; % %theXLabel = 'Index Number'; %theYLabel = 'Index Number'; %theZLabel = 'Value'; % %if length(varargin) == 1 % z = varargin{1}; % theNetCDF = parent(z); % theSize = ncsize(z); % theDims = dim(z); % if length(theDims) < 1, return, end % if length(theSize) > 0 % x = ncvar(name(theDims{1}), theNetCDF); % if isempty(x), x = (1:theSize(1)).'; end % end % if length(theSize) > 1 % y = ncvar(name(theDims{2}), theNetCDF); % if isempty(y), y = (1:theSize(2)).'; end % end % if ~isempty(y) % result = image(x, y, z, thePen); % end % elseif length(varargin) > 1 % x = varargin{1}; % z = varargin{2}; % if length(varargin) > 2 % y = varargin{2}; % z = varargin{3}; % end % if isa(x, 'ncvar') % theXLabel = name(x); % a = ncatt('units', x); % theXUnits = a(:); % if ~isempty(theXUnits), theXLabel = [theXLabel ' ' theXUnits]; end % x = x(:); % end % if isa(y, 'ncvar') % theYLabel = name(y); % a = ncatt('units', y); % theYUnits = a(:); % if ~isempty(theYUnits), theYLabel = [theYLabel ' ' theYUnits]; end % y = y(:); % end % theZLabel = name(z); % a = ncatt('units', z); % theZUnits = a(:); % if ~isempty(theZUnits), theZLabel = [theZLabel ' ' theZUnits]; end % axes(gca) % result = image(x, y, z(:), thePen); % xlabel(labelsafe(theXLabel)) % ylabellabelsafe((theYLabel)) % zlabel(labelsafe(theZLabel)) % theTitle = name(z); % title(labelsafe(theTitle)) %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "iscoord.m" (text)') fout = fopen('iscoord.m', 'w'); %function theResult = iscoord(self) % %% ncvar/iscoord -- Is self a coordinate-variable? %% iscoord(self) returns TRUE (non-zero) if self has the %% same name as a dimension; else, it returns FALSE (0). % %% 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-Aug-1997 15:45:48. % %if nargin < 1, help(mfilename), return, end % %theName = name(self); %result = (ncmex('dimid', ncid(self), name(self)) >= 0); % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "isepic.m" (text)') fout = fopen('isepic.m', 'w'); %function theResult = isepic(self) % %% ncvar/isepic -- Is this an epic variable? %% isepic(self) returns TRUE (1) if self, an "ncvar" %% object, appears to represent a NOAA epic variable. % %% 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 05-May-1997 10:43:30. % %if nargin < 1, help(mfilename), return, end % %result = 0; % %d = dim(self); %if ~isempty(d) % if strcmp(lower(name(d{1})), 'time') & ~isempty(self.epic_code) % result = 1; % end %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "isscalar.m" (text)') fout = fopen('isscalar.m', 'w'); %function theResult = isscalar(self) % %% ncvar/isscalar -- Is this a scalar variable? %% isscalar(self) returns 1 (TRUE) if self, an "ncvar" %% object, represents a NetCDF "scalar" variable, i.e. %% one with no dimensions. % %% 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-Sep-1997 10:12:33. % %if nargin < 1, help(mfilename), return, end % %result = isempty(dim(self)); % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "lt.m" (text)') fout = fopen('lt.m', 'w'); %function theResult = lt(self, other) % %% ncvar/lt -- Redirection operator. %% lt(self, other) redirects other, an ncvar, ncatt, %% double, or char object, into self, an ncvar object. % %% 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-Aug-1997 15:55:19. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch ncclass(other) %case 'cell' % result = cell(size(other)); % for i = 1:length(other) % result{i} = (self < other{i}); % end %case 'ncdim' %case 'ncvar' % result = copy(other, self, 1, 1); %case {'ncatt'} % result = copy(other, self); %case {'double', 'char'} % result = copy(other, self, 1, 0); %otherwise % warning(' ## Incompatible arguments.') %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "mesh.m" (text)') fout = fopen('mesh.m', 'w'); %function theResult = mesh(varargin) % %% ncvar/mesh -- Mesh a NetCDF variable. %% mesh(z, 'thePen') meshes NetCDF variable z, %% an "ncvar" object, using 'thePen'. If z is z(x), %% for coordinate variable x, then the function is %% called recursively as NCMesh(x, z, 'thePen'). %% For z(x, y), the recursive call is NCMesh(x, y, %% z, 'thePen'). The x, y, and z axes are labeled %% with the names and units of the corresponding %% variables. The title is set to the name of %% the z variable. % %% 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-Apr-1997 09:44:36. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end %result = []; % %% Isolate the pen. % %thePen = '-'; %if isstr(varargin{length(varargin)}) % thePen = varargin{length(varargin)}; % varargin(length(varargin)) = []; %end % %x = []; y = []; z = []; % %theXLabel = 'Index Number'; %theYLabel = 'Index Number'; %theZLabel = 'Value'; % %if length(varargin) == 1 % z = varargin{1}; % theNetCDF = parent(z); % theSize = ncsize(z); % theDims = dim(z); % if length(theDims) < 1, return, end % if length(theSize) > 0 % x = ncvar(name(theDims{1}), theNetCDF); % if isempty(x), x = (1:theSize(1)).'; end % end % if length(theSize) > 1 % y = ncvar(name(theDims{2}), theNetCDF); % if isempty(y), y = (1:theSize(2)).'; end % end % if ~isempty(y) % result = mesh(x, y, z, thePen); % end % elseif length(varargin) > 1 % x = varargin{1}; % z = varargin{2}; % if length(varargin) > 2 % y = varargin{2}; % z = varargin{3}; % end % if isa(x, 'ncvar') % theXLabel = name(x); % a = ncatt('units', x); % theXUnits = a(:); % if ~isempty(theXUnits), theXLabel = [theXLabel ' ' theXUnits]; end % x = x(:); % end % if isa(y, 'ncvar') % theYLabel = name(y); % a = ncatt('units', y); % theYUnits = a(:); % if ~isempty(theYUnits), theYLabel = [theYLabel ' ' theYUnits]; end % y = y(:); % end % theZLabel = name(z); % a = ncatt('units', z); % theZUnits = a(:); % if ~isempty(theZUnits), theZLabel = [theZLabel ' ' theZUnits]; end % axes(gca) % result = mesh(x, y, z(:), thePen); % xlabel(labelsafe(theXLabel)) % ylabellabelsafe((theYLabel)) % zlabel(labelsafe(theZLabel)) % theTitle = name(z); % title(labelsafe(theTitle)) %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "ncsize.m" (text)') fout = fopen('ncsize.m', 'w'); %function [theResult, nvars, ngatts, recdim] = size(self, index) % %% ncvar/ncsize -- Sizes of an "ncvar" object. %% ncsize(self) returns the ncsize of self, an "ncvar" %% object. One-dimensional and scalar variables %% return a size with just one element. The ncsize %% of a virtual variable is given in the reoriented %% sequence. %% ncsize(self, index) returns the size-component at %% the given index. % %% 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 19-Nov-1997 08:57:49. %% Updated 10-Oct-2001 11:29:01. % %if nargin < 1, help(mfilename), return, end % %theNCid = ncid(self); %theVarid = varid(self); % %theSize = []; %if theVarid >= 0 % [theVarname, theVartype, theVarndims, ... % theVardimids, theVarnatts, status] = ... % ncmex('varinq', theNCid, theVarid); % if status >= 0 % theSize = -ones(1, length(theVardimids)); % for i = 1:length(theVardimids) % [theDimname, theSize(i), status] = ... % ncmex('diminq', theNCid, theVardimids(i)); % if status < 0, break, end % end % end %end % %theOrientation = self.itsOrientation; %if ~isempty(theOrientation) % theSize = theSize(abs(theOrientation)); %end % %if nargin > 1 & all(index <= length(theSize)) % theSize = theSize(index); %end % %if nargout > 0 % theResult = theSize; %else % disp(theSize) %end fclose(fout); disp(' ## Installing: "ncvar.m" (text)') fout = fopen('ncvar.m', 'w'); %function self = ncvar(theVarname, theVartype, theDimnames, theNetcdf) % %% ncvar/ncvar -- Constructor for ncvar class. %% ncvar('theVarname', 'theVartype', {theDimnames}, theNetcdf) allocates %% an "ncvar" object with 'theVarname', 'theVartype', and {theDimnames}, %% in theNetcdf, a netcdf object. The re-direction syntax is %% theNetcdf < ncvar('theVarname', 'theVartype', {theDimnames}). %% The result is assigned silently to "ans" if no output argument %% is given. %% ncvar('theVarname', theNetcdf) returns an ncvar object that %% represents the existing variable named 'theVarName' in theNetcdf. %% ncvar('', 'theVartype', {theDimnames}) returns an ncvar object for: %% theNetcdf{'theVarname'} = ncvar('theVartype', {theDimnames}). %% ncvar (no argument) returns a generic "ncvar" object, suitable %% for use as a composite variable. %% ncvar (no argument) returns a raw "ncvar" object. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:55:19. %% Updated 14-Jan-2002 13:05:12. % %if nargin < 1 & nargout < 1 % help(mfilename) % return %end % %if nargout > 0, self = []; end % %% Basic structure. % %theStruct.itsVartype = ''; %theStruct.itsDimnames = {''}; %theStruct.itsOrientation = []; %theStruct.itsSubset = []; %theStruct.itsOffset = []; %theStruct.itsOrigin = []; %theStruct.itsVars = {}; %theStruct.itsSrcsubs = {}; %theStruct.itsDstsubs = {}; %theStruct.itsSlice = []; % %% Raw "ncvar" object. % %if nargin < 1 & nargout > 0 % self = class(theStruct, 'ncvar', ncitem); % return %end % %if nargin == 1 & isa(theVarname, 'ncitem') % theNCItem = theVarname; % if varid(theNCItem) >= 0 % result = ncvar(name(theNCItem), netcdf(ncid(theNCItem))); % else % result = []; % end % if nargout > 0 % self = result; % else % ncans(result) % end % return %end % %if nargin == 2 % theNetcdf = theVartype; % theNCid = ncid(theNetcdf); % switch class(theVarname) % case 'char' % [theVarid, status] = ncmex('varid', theNCid, theVarname); % case 'double' % theVarindex = theVarname; % theVarid = theVarindex-1; % [theVarname, theVartype, theVarndims, theVardimids, theVarnatts, status] = ... % ncmex('varinq', theNCid, theVarid); % otherwise % status = -1; % warning(' ## Illegal syntax') % end % if status >= 0 % theStruct.itsVartype = theVartype; % result = class(theStruct, 'ncvar', ... % ncitem(theVarname, theNCid, -1, theVarid)); % else % result = []; % end % if nargout > 0 % self = result; % else % ncans(result) % end % return %end % %theNCid = -1; %if nargin > 3, theNCid = ncid(theNetcdf); end % %if strcmp(theVartype, 'int'), theVartype = 'long'; end % %if isa(theDimnames, 'cell') % if length(theDimnames) == 1 % theDimnames = theDimnames{1}; % end %end %if isstr(theDimnames), theDimnames = {theDimnames}; end % %theDimids = zeros(1, length(theDimnames)) - 1; %for i = 1:length(theDimnames) % theDimids(i) = ncmex('dimid', theNCid, theDimnames{i}); %end % %status = 0; %theVarid = -1; %if theNCid ~= -1 % [theVarid, status] = ncmex('varid', theNCid, theVarname); % if status < 0 % namelen = max(length(theVarname), fatnames(theNetcdf)); % theTempname = setstr(zeros(1, namelen) + abs('-')); % [theVarid, status] = ncmex('vardef', theNCid, theTempname, ... % theVartype, -1, theDimids); % if status < 0 % status = ncmex('redef', theNCid); % if status >= 0 % [theVarid, status] = ncmex('vardef', theNCid, theTempname, ... % theVartype, -1, theDimids); % end % end % if status >= 0 & ~strcmp(theVarname, theTempname) % isFatNames = any(fatnames(theNetcdf)); % if isFatNames, theNetcdf = endef(theNetcdf); end % status = ncmex('varrename', theNCid, theVarid, theVarname); % if isFatNames, theNetcdf = redef(theNetcdf); end % end % end %end % %if status >= 0 % theStruct.itsVartype = theVartype; % theStruct.itsDimnames = theDimnames; % theStruct.itsSlice = zeros(1, length(theDimnames)); % result = class(theStruct, 'ncvar', ... % ncitem(theVarname, theNCid, -1, theVarid)); % else % result = []; %end % %if nargout > 0 % self = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "orient.m" (text)') fout = fopen('orient.m', 'w'); %function theResult = orient(self, theOrientation) % %% ncvar/orient -- Orientation of get/put data. %% orient(self) returns the current orientation of self, %% an "ncvar" object. The orientation is a vector that %% controls the application of "flipdim" and "permute" %% to the data when they are extracted from self. For %% example, if [1 -3 2] were specified, the data in %% the third dimension would be flipped, and then they %% would be permuted to the [1 3 2] arrangement, where %% 1..3 are indices of the dimensions of the original %% stored variable. During restoration, the inverse %% actions are taken. %% orient(self, theOrientation) sets the orientation of %% self to theOrientation, a vector of indices that %% depicts the sequence of dimensions for output. %% Negative indices cause the corresponding dimensions %% to be flipped before the data are permuted. The %% unchanged orientation [1:nDims] can also be given %% as the empty-matrix []. The self 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 23-Sep-1997 10:00:40. % %if nargin < 1, help(mfilename), return, end % %if nargin > 1 % if isempty(theOrientation) % theOrientation = 1:length(ncsize(self)); % end % self.itsOrientation = theOrientation; % result = self; % else % result = self.itsOrientation; % if isempty(result) % result = 1:length(ncsize(self)); % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "plot.m" (text)') fout = fopen('plot.m', 'w'); %function theResult = plot(varargin) % %% ncvar/plot -- Plot NetCDF variable. %% plot(z, 'thePen') plots NetCDF variable z, %% an "ncvar" object, using 'thePen'. If z is z(x), %% for coordinate variable x, then the function is %% called recursively as Plot(x, z, 'thePen'). %% For z(x, y), the recursive call is Plot(x, y, %% z, 'thePen'). The x, y, and z axes are labeled %% with the names and units of the corresponding %% variables. The title is set to the name of %% the z variable. % %% 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-Apr-1997 09:44:36. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end %result = []; % %% Isolate the pen. % %thePen = '-'; %if isstr(varargin{length(varargin)}) % thePen = varargin{length(varargin)}; % varargin(length(varargin)) = []; %end % %x = []; y = []; z = []; % %theXLabel = 'Index Number'; %theYLabel = 'Index Number'; %theZLabel = 'Value'; % %if length(varargin) == 1 % z = varargin{1}; % theNetCDF = parent(z); % theSize = ncsize(z); % theDims = dim(z); % if length(theDims) < 1, return, end % if length(theSize) > 0 % x = ncvar(name(theDims{1}), theNetCDF); % if isempty(x) % x = (1:theSize(1)).'; % theXLabel = [name(theDims{1}) ' (Index Number)']; % end % end % if length(theSize) > 1 % y = ncvar(name(theDims{2}), theNetCDF); % if isempty(y) % y = (1:theSize(2)).'; % theYLabel = [name(theDims{2}) ' (Index Number)']; % end % end % if ~isempty(y) & 0 % result = plot3(x, y, z, thePen); % xlabel(labelsafe(theXLabel)) % ylabel(labelsafe(theYLabel)) % else % result = plot(x, z, thePen); % end % elseif length(varargin) > 1 % x = varargin{1}; % z = varargin{2}; % if length(varargin) > 2 % y = varargin{2}; % z = varargin{3}; % end % if isa(x, 'ncvar') % theXLabel = name(x); % a = ncatt('units', x); % theXUnits = labelsafe(a(:)); % if ~isempty(theXUnits), theXLabel = [theXLabel ' (' theXUnits ')']; end % switch lower(name(x)) % case 'time' % Epic-awareness: epic_code = 624. % t = x; %% x = x(:); % x = ncsubsref(x, '()', {':'}); % t2 = ncvar('time2', parent(t)); % if ~isempty(t2) % e = ncatt('epic_code', t); % e2 = ncatt('epic_code', t2); % if isequal(e(:), 624) & isequal(e2(:), 624) % tt = ncsubsref(t, '()', ':'); % tt2 = ncsubsref(t2, '()', ':'); % x = tt + tt2 ./ (24 .* 3600 .* 1000); % theXOffset = floor(min(min(x))); % x = x - theXOffset; % theXLabel = [theXLabel ' - ' int2str(theXOffset)]; % end % end % otherwise %% x = x(:); % x = ncsubsref(x, '()', {':'}); % end % elseif isa(z, 'ncvar') % theDims = dim(z); % if length(theDims) > 0 % theXLabel = [name(theDims{1}) ' (Index Number)']; % end % end % if isa(y, 'ncvar') % theYLabel = name(y); % a = ncatt('units', y); % theYUnits = labelsafe(a(:)); % if ~isempty(theYUnits), theYLabel = [theYLabel ' (' theYUnits ')']; end %% y = y(:); % y = ncsubsref(y, '()', {':'}); % elseif isa(z, 'ncvar') % theDims = dim(z); % if length(theDims) > 1 % theYLabel = [name(theDims{2}) ' (Index Number)']; % end % end % theZLabel = name(z); % a = ncatt('units', z); % theZUnits = labelsafe(a(:)); % if ~isempty(theZUnits), theZLabel = [theZLabel ' (' theZUnits ')']; end % axes(gca) % if length(varargin) < 3 | 1 % zz = ncsubsref(z, '()', {':'}); % result = stackplot(x, zz, thePen); % xlabel(labelsafe(theXLabel)) % ylabel(labelsafe(theZLabel)) % set(result, 'ButtonDownFcn', 'findpt') % else % zz = ncsubsref(z, '()', {':'}); % result = plot3(x, y, zz, thePen); % xlabel(labelsafe(theXLabel)) % ylabel(labelsafe(theYLabel)) % zlabel(labelsafe(theZLabel)) % end % theTitle = name(z); % title(labelsafe(theTitle)) %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "resize.m" (text)') fout = fopen('resize.m', 'w'); %function theResult = resize(self, newSize) % %% ncvar/resize -- Resize variable dimensions. %% resize(self, newSize) resizes the dimensions of self, %% an "ncvar" object. All variables related to the %% changed dimensions are similarly affected. The %% newSize must have the same number of dimensions %% as the existing variable. The new self is returned. % %% 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 03-Nov-1998 08:52:22. %% Updated 12-Aug-1999 09:42:01. % %if nargin < 1, help(mfilename), return, end %if nargout > 0, theResult = self; end % %% Check for no-change. % %if isequal(ncsize(self), newSize) % result = self; % if nargout > 0 % theResult = result; % else % ncans(result) % end % return %end % %theItemName = name(self); % %% Check for writeability. % %f = parent(self); %thePermission = permission(f); %theSrcName = name(f); % %if isequal(thePermission, 'nowrite') % disp([' ## NetCDF source file must be writeable.']) % return %end % %% Check request. % %d = dim(self); %for i = 1:length(d) % if ~isrecdim(d{i}) & newSize(i) <= 0 % disp([' ## Dimension "' name(d{i}) '" size requires positive integer.']) % return % end %end % %% Create temporary file. % %g = []; % %i = 0; %while isempty(g) % i = i + 1; % theTmpName = ['tmp_' int2str(i) '.nc']; % if exist(theTmpName, 'file') ~= 2 % g = netcdf(theTmpName, 'noclobber'); % end %end % %theTmpName = name(g); % %% Copy affected dimensions first. % %d = dim(self); %for i = 1:length(d) % if isrecdim(d{i}) % g(name(d{i})) = 0; % elseif newSize(i) <= 0 % error([' ## Dimension "' name(d{i}) '" requires positive integer.']) % else % g(name(d{i})) = newSize(i); % end %end % %% Copy other dimensions. % %d = dim(f); %for i = 1:length(d) % g(name(d{i})) = ncsize(d{i}); %end % %% Copy global attributes. % %a = att(f); %for i = 1:length(a) % copy(a{i}, g) %end % %% Copy variable definitions and attributes. % %v = var(f); %for i = 1:length(v) % copy(v{i}, g, 0, 1) %end % %% Copy variable data as minimal rectangular array. %% Note that the "()" operator is out-of-context %% inside this method, so we have to build our own %% calls to "ncvar/subsref" and "ncvar/subsasgn". %% It might be easier for us to use "virtual" %% variables instead, which could be transferred %% with the more intelligent "ncvar/copy" method. % %v = var(f); %w = var(g); % %for i = 1:length(v) % sv = ncsize(v{i}); % sw = ncsize(w{i}); % if ~isempty(sw) % d = dim(w{i}); % if isrecdim(d{1}) % if sw(1) == 0 % if isequal(name(d{1}), theItemName) % sw(1) = newSize; % else % sw(1) = sv(1); % end % end % end % end % theMinimalSize = min(sv, sw); % if prod(theMinimalSize) > 0 % if isequal(sv, sw) % copy(v{i}, g, 1) % else % theIndices = cell(size(theMinimalSize)); % for j = 1:length(theIndices) % theIndices{j} = 1:theMinimalSize(j); % end % theStruct.type = '()'; % theStruct.subs = theIndices; % theData = subsref(v{i}, theStruct); % w{i} = subsasgn(w{i}, theStruct, theData); % end % end %end % %% Close both files. % %f = close(f); %g = close(g); % %% Delete old file. % %delete(theSrcName) % %% Rename new file to old file name. % %fcopy(theTmpName, theSrcName) %delete(theTmpName) % %% Open the new file. % %g = netcdf(theSrcName, thePermission); % %% Return the resized variable. % %result = g{theItemName}; % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "scalefactor.m" (text)') fout = fopen('scalefactor.m', 'w'); %function theResult = scalefactor(self, theNewScalefactor) % %% ncvar/scalefactor -- "scale-factor" attribute value. %% scalefactor(self) returns the "scale_factor" attribute %% value of self, an "ncvar" object, or 1 if no such %% attribute exists. %% scalefactor(self, theNewScalefactor) changes the scale-factor %% of self, an "ncvar" object, to theNewScalefactor. % %% 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 22-Dec-1998 10:04:05. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % result = 1; % theAtt = ncatt('scale_factor', self); % if ~isempty(theAtt), result = theAtt(:); end % else % theVartype = datatype(self); % theAtttype = theVartype; % theAtt = ncatt('scale_factor', theAtttype, theNewScalefactor, self); % result = theAtt; %end % %if nargout > 0 % theResult = result; % elseif nargin < 2 % disp(result) %end fclose(fout); disp(' ## Installing: "slice.m" (text)') fout = fopen('slice.m', 'w'); %function theResult = slice(self, theSliceDim) % %% ncvar/slice -- Set/get slice-dimension. %% slice(self, theSliceDim) sets the slice information of self, %% an ncvar object, to theSliceDim, which can be specified by %% the dimension name, a logical-vector with the value one (1) %% in the sequence of dimensions, or an ncdim object. The %% self is returned. %% slice(self) returns a logical-vector with the value one (1) %% in the position of the slice-dimension. All other elements %% are zero (0). % %% 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-Aug-1997 15:55:19. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2 % result = self.itsSlice; % else % theDims = dim(self); % theSlice = zeros(1, length(theDims)); % switch class(theSliceDim) % case 'char' % for i = 1:length(theDims) % if strcmp(name(theDims{i}), theSliceDim) % theSlice(i) = 1; % break; % end % end % case 'double' % for i = 1:min(length(theSliceDim), s) % if theDim(i) % theSlice(i) = 1; % break % end % end % case 'ncdim' % for i = 1:length(theDims) % if isequal(theDims{i}, theSliceDim) % theSlice(i) = 1; % break % end % end % otherwise % illegal ncvar/slice % end % self.itsSlice = theSlice; % result = self; %end % %if nargout > 0 % theResult = result; % elseif nargin < 2 % disp(result) %end fclose(fout); disp(' ## Installing: "subs.m" (text)') fout = fopen('subs.m', 'w'); %function [theSrc, theDst] = subs(self, theSrcsubs, theDstsubs) % %% ncvar/subs -- Manipulate origin. %% [{theSrcsubs}, {theDstsubs}] = subs(self) returns the "src" %% and "dst" subscripts of self, a composite "ncvar" object. %% subs(self, {theSrcsubs}, {theDstsubs}) sets the "src" and %% "dst" subscripts of self to the given structs. % %% 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 29-Sep-1997 09:33:06. % %if nargin < 1, help(mfilename), return, end % %if nargin == 1 % src = self.itsSrcsubs; % dst = self.itsDstsubs; % if isempty(src), src = {}; end % if isempty(dst), dst = {}; end %elseif nargin > 1 % self.itsSrcsubs = theSrcsubs; % if nargin > 2 % self.itsDstsubs = theDstsubs; % end % result = self; %end % %if nargout > 0 % if nargin > 1 % theSrc = result; % else % theSrc = src; % theDst = dst; % end %else % ncans([src dst]); %end fclose(fout); disp(' ## Installing: "subsasgn.m" (text)') fout = fopen('subsasgn.m', 'w'); %function theResult = subsasgn(self, theStruct, other) % %% ncvar/subsasgn -- Assignment with subscripting. %% subsasgn(self, theStruct, other) is called whenever %% self is used with subscripting on the left-side of %% an assignment, such as in self(...) = other, for %% self, an "ncvar" object. All other usages are illegal. %% If fewer than the full number of indices are provided, %% the unsupplied ones default to 1, unless the last one %% provided is ':', in which case the rest default to ':' %% as well. Indices beyond the full number needed are %% ignored. The argument called "other" must be a scalar, %% a vector having any orientation, or an array having %% the same shape as the destination slab. %% ## Only a constant stride is permitted at present. %% %% If the "quick" flag is set, faster "vanilla-flavored" %% processing is forced. Except for autoscaling, no %% special treatments are performed, such as virtual %% indexing, implicit indexing (including ":"), unsigned %% conversions, or auto-NaNing. % %% Also see: ncvar/subsref. % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:55:19. %% Updated 12-Oct-2001 17:50:28. % %if nargin < 1, help(mfilename), return, end % %% Quick processing. %% The NetCDF file must already be in "data" mode. % %isQuick = quick(self) & ... % length(theStruct) == 1 & isequal(theStruct.type, '()'); % %if isQuick % indices = theStruct.subs; % if ~iscell(indices), indices = {indices}; end % if (0) % Slow, but proper. % theNCid = ncid(self); % theVarid = varid(self); % theSize = ncsize(self); % Slow. % start = zeros(size(theSize)); % count = zeros(size(theSize)); % theAutoscaleflag = autoscale(self); % else % Fast, but very bad manners. % s = struct(self); % s = s.ncitem; % s = struct(s); % theNCid = s.itsNCid; % theVarid = s.itsVarid; % start = zeros(1, length(indices)); % count = zeros(1, length(indices)); % theAutoscaleflag = s.itIsAutoscaling; % end % for i = 1:length(indices) % k = indices{i}; % start(i) = min(k) - 1; % count(i) = length(k); % end % while length(count) < 2, count = [count 1]; end % rhs = zeros(count); % rhs(:) = other; % rhs = permute(rhs, length(size(rhs)):-1:1); % count = count(1:length(start)); % status = ncmex('varput', theNCid, theVarid, ... % start, count, rhs, theAutoscaleflag); % result = self; % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Composite-variable processing. % %% Can we consolidate some of this mess? % %theVars = var(self); % A cell. %if ~isempty(theVars) % [theSrcsubs, theDstsubs] = subs(self); % The mappings. % for j = 1:length(theSrcsubs) % siz = size(theVars{j}); % src = theSrcsubs{j}; % for i = 1:length(src) % if isequal(src{i}, ':') % Convert to numbers. % src{i} = 1:siz(i); % end % end % theSrcsubs{j} = src; % end % theSize = zeros(size(theDstsubs)); % for j = 1:length(theDstsubs) % dst = theDstsubs{j}; % for i = 1:length(dst) % theSize(i) = max(theSize(i), max(dst{i})); % end % end % theSubs = theStruct(1).subs; % if ~iscell(theSubs), theSubs = {theSubs}; end % isColon = isequal(theSubs{end}, ':'); % if isColon, s = ':'; else, s = 1; end % while length(theSubs) < length(theSize) % theSubs{end+1} = s; % end % %% Note: We compute a base-1 surrogate of theSubs, %% in order to keep the pre-allocated "result" matrix %% as small as possible. % % subsx = cell(size(theSubs)); % siz = zeros(size(subsx)); % for i = 1:length(theSubs) % if isequal(theSubs{i}, ':') % theSubs{i} = 1:theSize(i); % end % subsx{i} = theSubs{i} - min(theSubs{i}) + 1; % Base-1. % siz(i) = max(subsx{i}); % end % %% We need to reshape "other" for the %% following to work, since we have %% to select a piece of "other" for %% each "ncsubsasgn" action. How to %% do the "reshape"? % % % temp = zeros(siz); % temp(subsx{:}) = other; % % for j = 1:length(theVars) % [from, to] = mapsubs(theSrcsubs{j}, theDstsubs{j}, subsx); % if ~isempty(from) & ~isempty(to) % x = temp(to{:}); % Is this correct? % theVars{j} = ncsubsasgn(theVars{j}, '()', from, x); % end % end % % result = self; % if nargout > 0 % theResult = result; % else % disp(result) % end % return % % %end % % %if (0) % OLD stuff below here. % % result = []; % for i = length(theVars):-1:1 % Construct. % src = theSrcsubs{i}; % A cell. % dst = theDstsubs{i}; % A cell. %% x = theVars{i}(src{:}); % x = ncsubsref(theVars{i}, '()', src); % result(dst{:}) = x; % end % result(theStruct(1).subs{:}) = other; % Substitute. % for i = 1:length(theVars) % Restore. % src = theSrcsubs{i}; % A cell. % dst = theDstsubs{i}; % A cell. % x = result(dst{:}); %% theVars{i}(src{:}) = x; % theVars{i} = ncsubsasgn(theVars{i}, '()', src, x); % end % result = self; % if nargout > 0 % theResult = result; % else % disp(result) % end % return % %end % end of old unused stuff. % %% Regular processing. % %result = []; %if nargout > 0, theResult = result; end % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %nccheck(self) %theAutoscaleflag = (autoscale(self) == 1); %theDatatype = datatype(self); %theTypelen = ncmex('typelen', theDatatype); %isUnsigned = unsigned(self); %theFillvalue = fillval(self); %theAutonanflag = (autonan(self) == 1) & ~isempty(theFillvalue); %if theAutoscaleflag % theScalefactor = scalefactor(self); % theAddoffset = addoffset(self); %end % %switch theType %case '()' % if isempty(other) & length(theSubs) == 1 & strcmp(theSubs{1}, ':') % result = delete(self); % Delete. % if nargout > 0 % theResult = result; % else % disp(result) % end % return % end %otherwise %end % %switch theType %case '()' % indices = theSubs; % theSize = ncsize(self); % % for i = 1:length(indices) % if isa(indices{i}, 'double') % if any(diff(diff(indices{i}))) % disp(' ## Indexing strides must be positive and constant.') % return % end % end % end % %% Flip and permute indices before proceeding, %% since we are using virtual indexing. % % theOrientation = orient(self); % if any(theOrientation < 0) | any(diff(theOrientation) ~= 1) % for i = 1:length(theOrientation) % if theOrientation(i) < 0 % if isa(indices{i}, 'double') % Slide the indices. % indices{i} = fliplr(theSize(i) + 1 - indices{i}); % end % end % end % indices(abs(theOrientation)) = indices; % theSize(abs(theOrientation)) = theSize; % end % % start = zeros(1, length(theSize)); % count = ones(1, length(theSize)); % stride = ones(1, length(theSize)); % for i = 1:min(length(indices), length(theSize)) % k = indices{i}; % if ~isstr(k) & ~strcmp(k, ':') % start(i) = k(1)-1; % count(i) = length(k); % d = 0; % if length(k) > 1, d = diff(k); end % stride(i) = max(d(1), 1); % else % count(i) = -1; % if i == length(indices) & i < length(theSize) % j = i+1:length(theSize); % count(j) = -ones(1, length(j)); % end % end % end % start(start < 0) = 0; % stride(stride < 0) = 1; % for i = 1:length(count) % if count(i) == -1 % maxcount = fix((theSize(i)-start(i)+stride(i)-1) ./ ... % stride(i)); % count(i) = maxcount; % end % end % count(count < 0) = 0; % if any(count == 0), error(' ## Bad count.'), end % while length(count) < 2, count = [count 1]; end % temp = zeros(count); % count = count(1:length(start)); % if isa(other, 'ncitem'), other = other(:); end % if isstr(other), temp = setstr(temp); end % temp(:) = other; % theOrientation = orient(self); % if any(theOrientation < 0) | any(diff(theOrientation) ~= 1) % if length(theOrientation) < 2 % theOrientation = [theOrientation 2]; % end % temp = ipermute(temp, abs(theOrientation)); % for i = 1:length(theOrientation) % if theOrientation(i) < 0 % temp = flipdim(temp, abs(theOrientation(i))); % end % end % end % temp = permute(temp, length(size(temp)):-1:1); % theNetCDF = parent(self); % theNetCDF = endef(theNetCDF); % if isUnsigned & prod(size(temp)) > 0 % nBits = 8*theTypelen; % i = (temp >= 2^(nBits-1)); % temp(i) = temp(i) - 2^(nBits); % end % if theAutoscaleflag & ~isempty(temp) % temp = (temp - theAddoffset) ./ theScalefactor; % end % if theAutonanflag & ~isempty(temp) % f = find(isnan(temp)); % if any(f), temp(f) = theFillvalue; end % end % if all(count == 1) % status = ncmex('varput1', ncid(self), varid(self), ... % start, temp, 0); % elseif all(stride == 1) % status = ncmex('varput', ncid(self), varid(self), ... % start, count, temp, 0); % else % imap = []; % status = ncmex('varputg', ncid(self), varid(self), ... % start, count, stride, imap, temp, 0); % end % result = self; %case '.' % Attribute by name: self.theAttname(...). % theAttname = theSubs; % while length(s) > 0 % Dotted name. % switch s(1).type % case '.' % theAttname = [theAttname '.' s(1).subs]; % s(1) = []; % otherwise % break % end % end % if length(s) < 1 & isa(other, 'cell') & length(other) == 2 % theAtttype = other{1}; % theAttvalue = other{2}; % result = ncatt(theAttname, theAtttype, theAttvalue, self); % elseif length(s) < 1 % if ~isempty(other) % result = ncatt(theAttname, other, self); % else % result = delete(ncatt(theAttname, self)); % Delete. % end % else % result = subsasgn(att(self, theAttname), s, other); % end % result = self; %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "subsasgn.m-OLD" (binary)') fout = fopen('subsasgn.m-OLD', 'w'); %?66756e6374696f6e20746865526573756c74203d2073756273 %?6173676e2873656c662c207468655374727563742c206f7468 %?6572290d0d25206e637661722f737562736173676e202d2d20 %?41737369676e6d656e74207769746820737562736372697074 %?696e672e0d252020737562736173676e2873656c662c207468 %?655374727563742c206f74686572292069732063616c6c6564 %?207768656e657665720d2520202073656c6620697320757365 %?64207769746820737562736372697074696e67206f6e207468 %?65206c6566742d73696465206f660d25202020616e20617373 %?69676e6d656e742c207375636820617320696e2073656c6628 %?2e2e2e29203d206f746865722c20666f720d2520202073656c %?662c20616e20226e6376617222206f626a6563742e2020416c %?6c206f74686572207573616765732061726520696c6c656761 %?6c2e0d252020204966206665776572207468616e2074686520 %?66756c6c206e756d626572206f6620696e6469636573206172 %?652070726f76696465642c0d2520202074686520756e737570 %?706c696564206f6e65732064656661756c7420746f20312c20 %?756e6c65737320746865206c617374206f6e650d2520202070 %?726f766964656420697320273a272c20696e20776869636820 %?636173652074686520726573742064656661756c7420746f20 %?273a270d2520202061732077656c6c2e2020496e6469636573 %?206265796f6e64207468652066756c6c206e756d626572206e %?6565646564206172650d2520202069676e6f7265642e202054 %?686520617267756d656e742063616c6c656420226f74686572 %?22206d7573742062652061207363616c61722c0d2520202061 %?20766563746f7220686176696e6720616e79206f7269656e74 %?6174696f6e2c206f7220616e20617272617920686176696e67 %?0d252020207468652073616d65207368617065206173207468 %?652064657374696e6174696f6e20736c61622e0d2520202023 %?23204f6e6c79206120636f6e7374616e742073747269646520 %?6973207065726d69747465642061742070726573656e742e0d %?250d252020204966207468652022717569636b2220666c6167 %?206973207365742c20666173746572202276616e696c6c612d %?666c61766f726564220d2520202070726f63657373696e6720 %?697320666f726365642e202045786365707420666f72206175 %?746f7363616c696e672c206e6f0d252020207370656369616c %?2074726561746d656e74732061726520706572666f726d6564 %?2c2073756368206173207669727475616c0d25202020696e64 %?6578696e672c20696d706c6963697420696e646578696e6720 %?28696e636c7564696e6720223a22292c20756e7369676e6564 %?0d25202020636f6e76657273696f6e732c206f72206175746f %?2d4e614e696e672e0d0d2520416c736f207365653a206e6376 %?61722f737562737265662e0d200d2520436f70797269676874 %?2028432920313939362d372044722e20436861726c65732052 %?2e2044656e68616d2c205a594445434f2e0d252020416c6c20 %?5269676874732052657365727665642e0d2520202044697363 %?6c6f7375726520776974686f7574206578706c696369742077 %?72697474656e20636f6e73656e742066726f6d207468650d25 %?20202020636f70797269676874206f776e657220646f657320 %?6e6f7420636f6e73746974757465207075626c69636174696f %?6e2e0d200d252056657273696f6e206f662030372d4175672d %?313939372031353a35353a31392e0d25205570646174656420 %?20202032372d4d61722d323030302031363a34333a34332e0d %?0d6966206e617267696e203c20312c2068656c70286d66696c %?656e616d65292c2072657475726e2c20656e640d0d25205175 %?69636b2070726f63657373696e672e0d252020546865204e65 %?744344462066696c65206d75737420616c7265616479206265 %?20696e20226461746122206d6f64652e0d0d6973517569636b %?203d20717569636b2873656c66292026202e2e2e0d096c656e %?6774682874686553747275637429203d3d2031202620697365 %?7175616c287468655374727563742e747970652c2027282927 %?293b0d0d6966206973517569636b0d09696e6469636573203d %?207468655374727563742e737562733b0d096966207e697363 %?656c6c28696e6469636573292c20696e6469636573203d207b %?696e64696365737d3b20656e640d0969662028302920202025 %?20536c6f772c206275742070726f7065722e0d09097468654e %?436964203d206e6369642873656c66293b0d09097468655661 %?726964203d2076617269642873656c66293b0d090974686553 %?697a65203d206e6373697a652873656c66293b202020252053 %?6c6f772e0d09097374617274203d207a65726f732873697a65 %?2874686553697a6529293b0d0909636f756e74203d207a6572 %?6f732873697a652874686553697a6529293b0d090974686541 %?75746f7363616c65666c6167203d206175746f7363616c6528 %?73656c66293b0d09656c73652020202520466173742c206275 %?74207665727920626164206d616e6e6572732e0d090973203d %?207374727563742873656c66293b0d090973203d20732e6e63 %?6974656d3b0d090973203d207374727563742873293b0d0909 %?7468654e436964203d20732e6974734e4369643b0d09097468 %?655661726964203d20732e69747356617269643b0d09097374 %?617274203d207a65726f7328312c206c656e67746828696e64 %?6963657329293b0d0909636f756e74203d207a65726f732831 %?2c206c656e67746828696e646963657329293b0d0909746865 %?4175746f7363616c65666c6167203d20732e69744973417574 %?6f7363616c696e673b0d09656e640d09666f722069203d2031 %?3a6c656e67746828696e6469636573290d09096b203d20696e %?64696365737b697d3b0d09097374617274286929203d206d69 %?6e286b29202d20313b0d0909636f756e74286929203d206c65 %?6e677468286b293b0d09656e640d097768696c65206c656e67 %?746828636f756e7429203c20322c20636f756e74203d205b63 %?6f756e7420315d3b20656e640d09726873203d207a65726f73 %?28636f756e74293b0d09726873283a29203d206f746865723b %?0d09726873203d207065726d757465287268732c206c656e67 %?74682873697a652872687329293a2d313a31293b0d09636f75 %?6e74203d20636f756e7428313a6c656e677468287374617274 %?29293b0d09737461747573203d206e636d6578282776617270 %?7574272c207468654e4369642c2074686556617269642c202e %?2e2e0d090909090909090973746172742c20636f756e742c20 %?7268732c207468654175746f7363616c65666c6167293b0d09 %?726573756c74203d2073656c663b0d096966206e6172676f75 %?74203e20300d09202020746865526573756c74203d20726573 %?756c743b0d09656c73650d092020206469737028726573756c %?74290d09656e640d0972657475726e0d656e640d0d2520436f %?6d706f736974652d7661726961626c652070726f6365737369 %?6e672e0d252020576520636f6e737472756374207468652066 %?756c6c207669727475616c2d7661726961626c652061727261 %?792c0d25202073756273746974757465207468652064657369 %?7265642070696563652c207468656e20726573746f72652e0d %?0d74686556617273203d207661722873656c66293b20202025 %?20412063656c6c2e0d6966207e6973656d7074792874686556 %?617273290d2020205b746865537263737562732c2074686544 %?7374737562735d203d20737562732873656c66293b20202520 %?546865206d617070696e67732e0d202020726573756c74203d %?205b5d3b0d202020666f722069203d206c656e677468287468 %?6556617273293a2d313a312020202520436f6e737472756374 %?2e0d202020202020737263203d20746865537263737562737b %?697d3b2020202520412063656c6c2e0d202020202020647374 %?203d20746865447374737562737b697d3b2020202520412063 %?656c6c2e0d25202020202078203d20746865566172737b697d %?287372637b3a7d293b0d20202020202078203d206e63737562 %?7372656628746865566172737b697d2c20272829272c207372 %?63293b0d202020202020726573756c74286473747b3a7d2920 %?3d20783b0d202020656e640d202020726573756c7428746865 %?5374727563742831292e737562737b3a7d29203d206f746865 %?723b20202520537562737469747574652e0d202020666f7220 %?69203d20313a6c656e67746828746865566172732920202025 %?20526573746f72652e0d202020202020737263203d20746865 %?537263737562737b697d3b2020202520412063656c6c2e0d20 %?2020202020647374203d20746865447374737562737b697d3b %?2020202520412063656c6c2e0d20202020202078203d207265 %?73756c74286473747b3a7d293b0d2520202020207468655661 %?72737b697d287372637b3a7d29203d20783b0d202020202020 %?746865566172737b697d203d206e63737562736173676e2874 %?6865566172737b697d2c20272829272c207372632c2078293b %?0d202020656e640d202020726573756c74203d2073656c663b %?0d2020206966206e6172676f7574203e20300d202020202020 %?746865526573756c74203d20726573756c743b0d202020656c %?73650d2020202020206469737028726573756c74290d202020 %?656e640d20202072657475726e0d656e640d0d252052656775 %?6c61722070726f63657373696e672e0d2020200d726573756c %?74203d205b5d3b0d6966206e6172676f7574203e20302c2074 %?6865526573756c74203d20726573756c743b20656e640d0d73 %?203d207468655374727563743b0d74686554797065203d2073 %?2831292e747970653b0d74686553756273203d20732831292e %?737562733b0d73283129203d205b5d3b0d0d6e63636865636b %?2873656c66290d7468654175746f7363616c65666c6167203d %?20286175746f7363616c652873656c6629203d3d2031293b0d %?7468654461746174797065203d206461746174797065287365 %?6c66293b0d746865547970656c656e203d206e636d65782827 %?747970656c656e272c207468654461746174797065293b0d69 %?73556e7369676e6564203d20756e7369676e65642873656c66 %?293b0d74686546696c6c76616c7565203d2066696c6c76616c %?2873656c66293b0d7468654175746f6e616e666c6167203d20 %?286175746f6e616e2873656c6629203d3d2031292026207e69 %?73656d7074792874686546696c6c76616c7565293b0d696620 %?7468654175746f7363616c65666c61670d097468655363616c %?65666163746f72203d207363616c65666163746f722873656c %?66293b0d097468654164646f6666736574203d206164646f66 %?667365742873656c66293b0d656e640d0d7377697463682074 %?6865547970650d6361736520272829270d2020206966206973 %?656d707479286f74686572292026206c656e67746828746865 %?5375627329203d3d2031202620737472636d70287468655375 %?62737b317d2c20273a27290d202020202020726573756c7420 %?3d2064656c6574652873656c66293b202020252044656c6574 %?652e0d2020202020206966206e6172676f7574203e2020300d %?202020202020202020746865526573756c74203d2072657375 %?6c743b0d202020202020656c73650d20202020202020202064 %?69737028726573756c74290d202020202020656e640d202020 %?20202072657475726e0d202020656e640d6f74686572776973 %?650d656e640d0d73776974636820746865547970650d636173 %?6520272829270d202020696e6469636573203d207468655375 %?62733b0d20202074686553697a65203d206e6373697a652873 %?656c66293b0d2020200d202020666f722069203d20313a6c65 %?6e67746828696e6469636573290d2020202020206966206973 %?6128696e64696365737b697d2c2027646f75626c6527290d20 %?2020202020202020696620616e792864696666286469666628 %?696e64696365737b697d2929290d2020202020202020202020 %?2064697370282720232320496e646578696e67207374726964 %?6573206d75737420626520706f73697469766520616e642063 %?6f6e7374616e742e27290d2020202020202020202020207265 %?7475726e0d202020202020202020656e640d20202020202065 %?6e640d202020656e640d2020200d2520466c697020616e6420 %?7065726d75746520696e6469636573206265666f7265207072 %?6f63656564696e672c0d25202073696e636520776520617265 %?207573696e67207669727475616c20696e646578696e672e0d %?2020200d2020207468654f7269656e746174696f6e203d206f %?7269656e742873656c66293b0d202020696620616e79287468 %?654f7269656e746174696f6e203c203029207c20616e792864 %?696666287468654f7269656e746174696f6e29207e3d203129 %?0d202020202020666f722069203d20313a6c656e6774682874 %?68654f7269656e746174696f6e290d20202020202020202069 %?66207468654f7269656e746174696f6e286929203c20300d20 %?202020202020202020202069662069736128696e6469636573 %?7b697d2c2027646f75626c6527292020202520536c69646520 %?74686520696e64696365732e0d202020202020202020202020 %?202020696e64696365737b697d203d20666c69706c72287468 %?6553697a65286929202b2031202d20696e64696365737b697d %?293b0d202020202020202020202020656e640d202020202020 %?202020656e640d202020202020656e640d202020202020696e %?646963657328616273287468654f7269656e746174696f6e29 %?29203d20696e64696365733b0d20202020202074686553697a %?6528616273287468654f7269656e746174696f6e2929203d20 %?74686553697a653b0d202020656e640d0d2020207374617274 %?203d207a65726f7328312c206c656e6774682874686553697a %?6529293b0d202020636f756e74203d206f6e657328312c206c %?656e6774682874686553697a6529293b0d2020207374726964 %?65203d206f6e657328312c206c656e6774682874686553697a %?6529293b0d202020666f722069203d20313a6d696e286c656e %?67746828696e6469636573292c206c656e6774682874686553 %?697a6529290d2020202020206b203d20696e64696365737b69 %?7d3b0d2020202020206966207e6973737472286b292026207e %?737472636d70286b2c20273a27290d20202020202020202073 %?74617274286929203d206b2831292d313b0d20202020202020 %?2020636f756e74286929203d206c656e677468286b293b0d20 %?202020202020202064203d20303b0d20202020202020202069 %?66206c656e677468286b29203e20312c2064203d2064696666 %?286b293b20656e640d20202020202020202073747269646528 %?6929203d206d617828642831292c2031293b0d202020202020 %?656c73650d202020202020202020636f756e74286929203d20 %?2d313b0d20202020202020202069662069203d3d206c656e67 %?746828696e64696365732920262069203c206c656e67746828 %?74686553697a65290d2020202020202020202020206a203d20 %?692b313a6c656e6774682874686553697a65293b0d20202020 %?2020202020202020636f756e74286a29203d202d6f6e657328 %?312c206c656e677468286a29293b0d20202020202020202065 %?6e640d202020202020656e640d202020656e640d2020207374 %?617274287374617274203c203029203d20303b0d2020207374 %?7269646528737472696465203c203029203d20313b0d202020 %?666f722069203d20313a6c656e67746828636f756e74290d20 %?2020202020696620636f756e74286929203d3d202d310d2020 %?202020202020206d6178636f756e74203d2066697828287468 %?6553697a652869292d73746172742869292b73747269646528 %?69292d3129202e2f202e2e2e0d202020202020202020202020 %?20202020202020202020202020202020202020202020202020 %?2020202020202020202020202020737472696465286929293b %?0d202020202020202020636f756e74286929203d206d617863 %?6f756e743b0d202020202020656e640d202020656e640d2020 %?20636f756e7428636f756e74203c203029203d20303b0d2020 %?20696620616e7928636f756e74203d3d2030292c206572726f %?7228272023232042616420636f756e742e27292c20656e640d %?2020207768696c65206c656e67746828636f756e7429203c20 %?322c20636f756e74203d205b636f756e7420315d3b20656e64 %?0d20202074656d70203d207a65726f7328636f756e74293b0d %?09636f756e74203d20636f756e7428313a6c656e6774682873 %?7461727429293b0d202020696620697361286f746865722c20 %?276e636974656d27292c206f74686572203d206f7468657228 %?3a293b20656e640d2020206966206973737472286f74686572 %?292c2074656d70203d207365747374722874656d70293b2065 %?6e640d20202074656d70283a29203d206f746865723b0d2020 %?207468654f7269656e746174696f6e203d206f7269656e7428 %?73656c66293b0d202020696620616e79287468654f7269656e %?746174696f6e203c203029207c20616e792864696666287468 %?654f7269656e746174696f6e29207e3d2031290d2020202020 %?206966206c656e677468287468654f7269656e746174696f6e %?29203c20320d2020202020202020207468654f7269656e7461 %?74696f6e203d205b7468654f7269656e746174696f6e20325d %?3b0d202020202020656e640d20202020202074656d70203d20 %?697065726d7574652874656d702c20616273287468654f7269 %?656e746174696f6e29293b0d202020202020666f722069203d %?20313a6c656e677468287468654f7269656e746174696f6e29 %?0d2020202020202020206966207468654f7269656e74617469 %?6f6e286929203c20300d20202020202020202020202074656d %?70203d20666c697064696d2874656d702c2061627328746865 %?4f7269656e746174696f6e28692929293b0d20202020202020 %?2020656e640d202020202020656e640d202020656e640d2020 %?2074656d70203d207065726d7574652874656d702c206c656e %?6774682873697a652874656d7029293a2d313a31293b0d2020 %?207468654e6574434446203d20706172656e742873656c6629 %?3b0d2020207468654e6574434446203d20656e646566287468 %?654e6574434446293b0d096966206973556e7369676e656420 %?262070726f642873697a652874656d702929203e20300d0909 %?6e42697473203d20382a746865547970656c656e3b0d090969 %?203d202874656d70203e3d20325e286e426974732d3129293b %?0d090974656d70286929203d2074656d70286929202d20325e %?286e42697473293b0d09656e640d096966207468654175746f %?7363616c65666c61672026207e6973656d7074792874656d70 %?290d090974656d70203d202874656d70202d20746865416464 %?6f666673657429202e2f207468655363616c65666163746f72 %?3b0d09656e640d096966207468654175746f6e616e666c6167 %?2026207e6973656d7074792874656d70290d090966203d2066 %?696e642869736e616e2874656d7029293b0d0909696620616e %?792866292c2074656d70286629203d2074686546696c6c7661 %?6c75653b20656e640d09656e640d202020696620616c6c2863 %?6f756e74203d3d2031290d202020202020737461747573203d %?206e636d6578282776617270757431272c206e636964287365 %?6c66292c2076617269642873656c66292c202e2e2e0d202020 %?20202020202020202020202020202073746172742c2074656d %?702c2030293b0d202020656c7365696620616c6c2873747269 %?6465203d3d2031290d202020202020737461747573203d206e %?636d65782827766172707574272c206e6369642873656c6629 %?2c2076617269642873656c66292c202e2e2e0d202020202020 %?20202020202020202020202073746172742c20636f756e742c %?2074656d702c2030293b0d202020656c73650d202020202020 %?696d6170203d205b5d3b0d202020202020737461747573203d %?206e636d6578282776617270757467272c206e636964287365 %?6c66292c2076617269642873656c66292c202e2e2e0d202020 %?20202020202020202020202020202073746172742c20636f75 %?6e742c207374726964652c20696d61702c2074656d702c2030 %?293b0d202020656e640d202020726573756c74203d2073656c %?663b0d6361736520272e272020202520417474726962757465 %?206279206e616d653a2073656c662e7468654174746e616d65 %?282e2e2e292e0d2020207468654174746e616d65203d207468 %?65537562733b0d2020207768696c65206c656e677468287329 %?203e20302020202520446f74746564206e616d652e0d202020 %?20202073776974636820732831292e747970650d2020202020 %?206361736520272e270d202020202020202020746865417474 %?6e616d65203d205b7468654174746e616d6520272e27207328 %?31292e737562735d3b0d20202020202020202073283129203d %?205b5d3b0d2020202020206f74686572776973650d20202020 %?2020202020627265616b0d202020202020656e640d20202065 %?6e640d2020206966206c656e677468287329203c2031202620 %?697361286f746865722c202763656c6c27292026206c656e67 %?7468286f7468657229203d3d20320d20202020202074686541 %?747474797065203d206f746865727b317d3b0d202020202020 %?74686541747476616c7565203d206f746865727b327d3b0d20 %?2020202020726573756c74203d206e63617474287468654174 %?746e616d652c20746865417474747970652c20746865417474 %?76616c75652c2073656c66293b0d202020656c73656966206c %?656e677468287329203c20310d2020202020206966207e6973 %?656d707479286f74686572290d202020202020202020726573 %?756c74203d206e63617474287468654174746e616d652c206f %?746865722c2073656c66293b0d202020202020656c73650d20 %?2020202020202020726573756c74203d2064656c657465286e %?63617474287468654174746e616d652c2073656c6629293b20 %?2020252044656c6574652e0d202020202020656e640d202020 %?656c73650d202020202020726573756c74203d207375627361 %?73676e286174742873656c662c207468654174746e616d6529 %?2c20732c206f74686572293b0d202020656e640d2020207265 %?73756c74203d2073656c663b0d6f74686572776973650d2020 %?207761726e696e67285b2720232320496c6c6567616c207379 %?6e7461783a2022272074686554797065202722275d290d656e %?640d0d6966206e6172676f7574203e2020300d202020746865 %?526573756c74203d20726573756c743b0d656c73650d202020 %?6469737028726573756c74290d656e640d fclose(fout); disp(' ## Installing: "subsindex.m" (text)') fout = fopen('subsindex.m', 'w'); %function theResult = subsindex(self) % %% ncvar/subsindex -- Value of an ncvar object as an index. %% subsindex(self) returns the set of zero-based indices %% equivalent to the value of self, an "ncvar" object. %% The result is [find(isfinite(self(:)) ~= 0) - 1], %% corresponding to the one-dimensional indices of %% all the finite, non-zero elements in the contents %% of self. %% %% Also see: ncdim/subsindex. % %% 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-Aug-1997 15:55:19. % %if nargin < 1, help(mfilename), return, end % %result = find(isfinite(self(:)) ~= 0) - 1; % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "subsref.m" (text)') fout = fopen('subsref.m', 'w'); %function theResult = subsref(self, theStruct) % %% ncvar/subsref -- Overloaded "{}", ".", and "()" operators. %% subsref(self, theStruct) processes the subscripting %% operator () for self, an "ncvar" object referenced on %% the righthand side of an assignment, such as in %% result = self(i, j, ...), where the sole operator %% is '()'. If the syntax is result = self.theAttname %% or result = self.theAttname(...), the named attribute %% object of self is processed. If fewer than the full %% number of indices are provided, the silent ones %% default to 1, unless the last one provided is ':', %% in which case the remainder default to ':' as well. %% Indices beyond the full number needed are ignored. %% ## Only a constant stride is permitted at present. %% %% If the "quick" flag is set, faster "vanilla-flavored" %% processing is forced. Except for autoscaling, no %% special treatments are performed, such as virtual %% indexing, implicit indexing (including ":"), unsigned %% conversions, or auto-NaNing. % %% Also see: ncvar/subsasgn. % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:55:19. %% Updated 25-Mar-2003 11:35:17. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % result = self; % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Quick processing. %% The NetCDF file must already be in "data" mode. % %isQuick = quick(self) & ... % length(theStruct) == 1 & ... % isequal(theStruct.type, '()'); % %if isQuick % indices = theStruct.subs; % if ~iscell(indices), indices = {indices}; end % if (0) % Slow, but proper. % theNCid = ncid(self); % theVarid = varid(self); % theSize = ncsize(self); % Slow. % start = zeros(size(theSize)); % count = zeros(size(theSize)); % theAutoscaleflag = autoscale(self); % else % Fast, but very bad manners. % s = struct(self); % s = s.ncitem; % s = struct(s); % theNCid = s.itsNCid; % theVarid = s.itsVarid; % start = zeros(1, length(indices)); % count = zeros(1, length(indices)); % theAutoscaleflag = s.itIsAutoscaling; % end % for i = 1:length(indices) % k = indices{i}; % start(i) = min(k) - 1; % count(i) = length(k); % end % [result, status] = ncmex('varget', theNCid, theVarid, ... % start, count, theAutoscaleflag); % if status >= 0 % result = permute(result, length(size(result)):-1:1); % end % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Composite-variable processing. %% We map the source-indices to the destination-indices %% for each composite-variable participant. The indices %% are in cells of cells, arranged in the same order as %% the variables, which themselves are in a cell. % %% Can we consolidate some of this mess? % %theVars = var(self); % A cell. %if ~isempty(theVars) % [theSrcsubs, theDstsubs] = subs(self); % The mappings. % for j = 1:length(theSrcsubs) % siz = size(theVars{j}); % src = theSrcsubs{j}; % for i = 1:length(src) % if isequal(src{i}, ':') % Convert to numbers. % src{i} = 1:siz(i); % end % end % theSrcsubs{j} = src; % end % theSize = zeros(size(theDstsubs)); % for j = 1:length(theDstsubs) % dst = theDstsubs{j}; % for i = 1:length(dst) % theSize(i) = max(theSize(i), max(dst{i})); % end % end % theSubs = theStruct(1).subs; % if ~iscell(theSubs), theSubs = {theSubs}; end % isColon = isequal(theSubs{end}, ':'); % if isColon, s = ':'; else, s = 1; end % while length(theSubs) < length(theSize) % theSubs{end+1} = s; % end % %% Note: We compute a base-1 surrogate of theSubs, %% in order to keep the pre-allocated "result" matrix %% as small as possible. % % subsx = cell(size(theSubs)); % "subs" is a function. % siz = zeros(size(subsx)); % for i = 1:length(theSubs) % if isequal(theSubs{i}, ':') % theSubs{i} = 1:theSize(i); % end % subsx{i} = theSubs{i} - min(theSubs{i}) + 1; % Base-1. % siz(i) = max(subsx{i}); % end % % result = zeros(siz); % Pre-allocate. % % for j = 1:length(theVars) %% [from, to] = mapsubs(theSrcsubs{j}, theDstsubs{j}, theSubs); % [from, to] = mapsubs(theSrcsubs{j}, theDstsubs{j}, subsx); % if ~isempty(from) & ~isempty(to) % x = ncsubsref(theVars{j}, '()', from); % result(to{:}) = x; % end % end % %% result = result(theSubs{:}); % Subset. % % result = result(subsx{:}); % Subset. % % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Regular processing. % %result = []; %if nargout > 0, theResult = result; end % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %nccheck(self) %theAutoscaleflag = (autoscale(self) == 1); %theDatatype = datatype(self); %theTypelen = ncmex('typelen', theDatatype); %isUnsigned = unsigned(self); %theFillvalue = fillval(self); %theAutonanflag = (autonan(self) == 1) & ~isempty(theFillvalue); %if theAutoscaleflag % theScalefactor = scalefactor(self); % theAddoffset = addoffset(self); %end % %switch theType %case '()' % Variable data by index: self(..., ...). % indices = theSubs; % theSize = ncsize(self); % for i = 1:length(indices) % if isa(indices{i}, 'double') % if any(diff(diff(indices{i}))) % disp(' ## Indexing strides must be positive and constant.') % return % end % end % end % %% Flip and permute indices before proceeding, %% since we are using virtual indexing. % % theOrientation = orient(self); % if any(theOrientation < 0) | any(diff(theOrientation) ~= 1) % for i = 1:length(theOrientation) % if theOrientation(i) < 0 % if isa(indices{i}, 'double') % Slide the indices. % indices{i} = fliplr(theSize(i) + 1 - indices{i}); % end % end % end % indices(abs(theOrientation)) = indices; % theSize(abs(theOrientation)) = theSize; % end % % if prod(theSize) > 0 % start = zeros(1, length(theSize)); % count = ones(1, length(theSize)); % stride = ones(1, length(theSize)); % for i = 1:min(length(indices), length(theSize)) % k = indices{i}; % if ~isstr(k) & ~strcmp(k, ':') & ~strcmp(k, '-') % start(i) = k(1)-1; % count(i) = length(k); % d = 0; % if length(k) > 1, d = diff(k); end % stride(i) = max(d(1), 1); % else % count(i) = -1; % if i == length(indices) & i < length(theSize) % j = i+1:length(theSize); % count(j) = -ones(1, length(j)); % end % end % end % start(start < 0) = 0; % stride(stride < 0) = 1; % for i = 1:length(count) % if count(i) == -1 % maxcount = fix((theSize(i)-start(i)+stride(i)-1) ./ stride(i)); % count(i) = maxcount; % end % end % theNetCDF = parent(self); % theNetCDF = endef(theNetCDF); % count(count < 0) = 0; % if any(count == 0), error(' ## Bad count.'), end % if all(count == 1) % [result, status] = ncmex('varget1', ncid(self), varid(self), ... % start, 0); % %elseif all(stride == 1) % % [result, status] = ncmex('varget', ncid(self), varid(self), ... % start, count, 0); % else % imap = []; % [result, status] = ncmex('vargetg', ncid(self), varid(self), ... % start, count, stride, imap, ... % 0); % end % if theAutonanflag & status >= 0 % f = find(result == theFillvalue); % if any(f), result(f) = NaN; end % end % if theAutoscaleflag & status >= 0 % result = result .* theScalefactor + theAddoffset; % end % if isUnsigned & prod(size(result)) > 0 % result(result < 0) = 2^(8*theTypelen) + result(result < 0); % end % else % result = []; % status = 0; % end % if status >= 0 & prod(size(result)) > 0 % result = permute(result, length(size(result)):-1:1); % theOrientation = orient(self); % if any(theOrientation < 0) | any(diff(theOrientation) ~= 1) % for i = 1:length(theOrientation) % if theOrientation(i) < 0 % result = flipdim(result, abs(theOrientation(i))); % end % end % if length(theOrientation) < 2 % theOrientation = [theOrientation 2]; % end % result = permute(result, abs(theOrientation)); % end % elseif status >= 0 & prod(size(result)) == 0 % result = []; % else % status, prod_size_result = prod(size(result)) % *** % warning(' ## ncvar/subsref failure.') % end %case '.' % Attribute: self.theAttname(...) % theAttname = theSubs; % while length(s) > 0 % Dotted name. % switch s(1).type % case '.' % theAttname = [theAttname '.' s(1).subs]; % s(1) = []; % otherwise % break % end % end % result = att(self, theAttname); % if ~isempty(result), result = subsref(result, s); end %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % Always true. % theResult = result; %else % Is there any way to force this? % c = ncatt('C_format', self); % if ~isempty(c) % c = c(:); % s = size(result) % result = result.'; % result = result(:); % step = prod(s)/s(1); % k = 1:step; % for i = 1:s(1) % fprintf(c, result(k)); % fprintf('\n'); % k = k + step; % end % else % disp(result) % end %end fclose(fout); disp(' ## Installing: "subsref.m-OLD" (binary)') fout = fopen('subsref.m-OLD', 'w'); %?66756e6374696f6e20746865526573756c74203d2073756273 %?7265662873656c662c20746865537472756374290d0d25206e %?637661722f73756273726566202d2d204f7665726c6f616465 %?6420227b7d222c20222e222c20616e642022282922206f7065 %?7261746f72732e0d252020737562737265662873656c662c20 %?746865537472756374292070726f6365737365732074686520 %?737562736372697074696e670d252020206f70657261746f72 %?20282920666f722073656c662c20616e20226e637661722220 %?6f626a656374207265666572656e636564206f6e0d25202020 %?74686520726967687468616e642073696465206f6620616e20 %?61737369676e6d656e742c207375636820617320696e0d2520 %?2020726573756c74203d2073656c6628692c206a2c202e2e2e %?292c2077686572652074686520736f6c65206f70657261746f %?720d25202020697320272829272e2020496620746865207379 %?6e74617820697320726573756c74203d2073656c662e746865 %?4174746e616d650d252020206f7220726573756c74203d2073 %?656c662e7468654174746e616d65282e2e2e292c2074686520 %?6e616d6564206174747269627574650d252020206f626a6563 %?74206f662073656c662069732070726f6365737365642e2020 %?4966206665776572207468616e207468652066756c6c0d2520 %?20206e756d626572206f6620696e6469636573206172652070 %?726f76696465642c207468652073696c656e74206f6e65730d %?2520202064656661756c7420746f20312c20756e6c65737320 %?746865206c617374206f6e652070726f766964656420697320 %?273a272c0d25202020696e2077686963682063617365207468 %?652072656d61696e6465722064656661756c7420746f20273a %?272061732077656c6c2e0d25202020496e6469636573206265 %?796f6e64207468652066756c6c206e756d626572206e656564 %?6564206172652069676e6f7265642e0d252020202323204f6e %?6c79206120636f6e7374616e74207374726964652069732070 %?65726d69747465642061742070726573656e742e0d250d2520 %?20204966207468652022717569636b2220666c616720697320 %?7365742c20666173746572202276616e696c6c612d666c6176 %?6f726564220d2520202070726f63657373696e672069732066 %?6f726365642e202045786365707420666f72206175746f7363 %?616c696e672c206e6f0d252020207370656369616c20747265 %?61746d656e74732061726520706572666f726d65642c207375 %?6368206173207669727475616c0d25202020696e646578696e %?672c20696d706c6963697420696e646578696e672028696e63 %?6c7564696e6720223a22292c20756e7369676e65640d252020 %?20636f6e76657273696f6e732c206f72206175746f2d4e614e %?696e672e0d0d2520416c736f207365653a206e637661722f73 %?7562736173676e2e0d200d2520436f70797269676874202843 %?2920313939362d372044722e20436861726c657320522e2044 %?656e68616d2c205a594445434f2e0d252020416c6c20526967 %?6874732052657365727665642e0d25202020446973636c6f73 %?75726520776974686f7574206578706c696369742077726974 %?74656e20636f6e73656e742066726f6d207468650d25202020 %?20636f70797269676874206f776e657220646f6573206e6f74 %?20636f6e73746974757465207075626c69636174696f6e2e0d %?200d252056657273696f6e206f662030372d4175672d313939 %?372031353a35353a31392e0d25205570646174656420202020 %?31312d4d61792d323030312031313a31373a31342e0d0d6966 %?206e617267696e203c20312c2068656c70286d66696c656e61 %?6d65292c2072657475726e2c20656e640d0d6966206c656e67 %?74682874686553747275637429203c20310d09726573756c74 %?203d2073656c663b0d096966206e6172676f7574203e20300d %?0909746865526573756c74203d20726573756c743b0d09656c %?73650d09096469737028726573756c74290d09656e640d0972 %?657475726e0d656e640d0d2520517569636b2070726f636573 %?73696e672e0d252020546865204e65744344462066696c6520 %?6d75737420616c726561647920626520696e20226461746122 %?206d6f64652e0d0d6973517569636b203d20717569636b2873 %?656c66292026202e2e2e0d0909096c656e6774682874686553 %?747275637429203d3d20312026202e2e2e0d09090969736571 %?75616c287468655374727563742e747970652c202728292729 %?3b0d0d6966206973517569636b0d09696e6469636573203d20 %?7468655374727563742e737562733b0d096966207e69736365 %?6c6c28696e6469636573292c20696e6469636573203d207b69 %?6e64696365737d3b20656e640d096966202830292020202520 %?536c6f772c206275742070726f7065722e0d09097468654e43 %?6964203d206e6369642873656c66293b0d0909746865566172 %?6964203d2076617269642873656c66293b0d09097468655369 %?7a65203d206e6373697a652873656c66293b2020202520536c %?6f772e0d09097374617274203d207a65726f732873697a6528 %?74686553697a6529293b0d0909636f756e74203d207a65726f %?732873697a652874686553697a6529293b0d09097468654175 %?746f7363616c65666c6167203d206175746f7363616c652873 %?656c66293b0d09656c73652020202520466173742c20627574 %?207665727920626164206d616e6e6572732e0d090973203d20 %?7374727563742873656c66293b0d090973203d20732e6e6369 %?74656d3b0d090973203d207374727563742873293b0d090974 %?68654e436964203d20732e6974734e4369643b0d0909746865 %?5661726964203d20732e69747356617269643b0d0909737461 %?7274203d207a65726f7328312c206c656e67746828696e6469 %?63657329293b0d0909636f756e74203d207a65726f7328312c %?206c656e67746828696e646963657329293b0d090974686541 %?75746f7363616c65666c6167203d20732e697449734175746f %?7363616c696e673b0d09656e640d09666f722069203d20313a %?6c656e67746828696e6469636573290d09096b203d20696e64 %?696365737b697d3b0d09097374617274286929203d206d696e %?286b29202d20313b0d0909636f756e74286929203d206c656e %?677468286b293b0d09656e640d095b726573756c742c207374 %?617475735d203d206e636d65782827766172676574272c2074 %?68654e4369642c2074686556617269642c202e2e2e0d090909 %?090909090973746172742c20636f756e742c20746865417574 %?6f7363616c65666c6167293b0d09696620737461747573203e %?3d20300d0909726573756c74203d207065726d757465287265 %?73756c742c206c656e6774682873697a6528726573756c7429 %?293a2d313a31293b0d09656e640d096966206e6172676f7574 %?203e20300d09202020746865526573756c74203d2072657375 %?6c743b0d09656c73650d092020206469737028726573756c74 %?290d09656e640d0972657475726e0d656e640d0d2520436f6d %?706f736974652d7661726961626c652070726f63657373696e %?672e0d2520205765206d61702074686520736f757263652d69 %?6e646963657320746f207468652064657374696e6174696f6e %?2d696e64696365730d252020666f72206561636820636f6d70 %?6f736974652d7661726961626c65207061727469636970616e %?742e202054686520696e64696365730d25202061726520696e %?2063656c6c73206f662063656c6c732c20617272616e676564 %?20696e207468652073616d65206f726465722061730d252020 %?746865207661726961626c65732c207768696368207468656d %?73656c7665732061726520696e20612063656c6c2e0d0d7468 %?6556617273203d207661722873656c66293b20202025204120 %?63656c6c2e0d6966207e6973656d7074792874686556617273 %?290d095b746865537263737562732c20746865447374737562 %?735d203d20737562732873656c66293b20202520546865206d %?617070696e67732e0d09726573756c74203d205b5d3b0d0966 %?6f722069203d206c656e6774682874686556617273293a2d31 %?3a310d092020737263203d20746865537263737562737b697d %?3b2020202520412063656c6c2e0d092020647374203d207468 %?65447374737562737b697d3b2020202520412063656c6c2e0d %?25202020202078203d20746865566172737b697d287372637b %?3a7d293b0d09202078203d206e637375627372656628746865 %?566172737b697d2c20272829272c20737263293b0d09202072 %?6573756c74286473747b3a7d29203d20783b0d09656e640d09 %?74686553697a65203d2073697a6528726573756c74293b0d09 %?74686553756273203d207468655374727563742831292e7375 %?62733b0d096966206c656e6774682874686553697a6529203e %?206c656e6774682874686553756273290d0909696620697365 %?7175616c28746865537562737b6c656e677468287468655375 %?6273297d2c20273a27290d0909096578747261203d20273a27 %?3b0d0909656c73650d0909096578747261203d20313b0d0909 %?656e640d0909666f722069203d206c656e6774682874686553 %?756273292b313a6c656e6774682874686553697a65290d0909 %?09746865537562737b697d203d2065787472613b0d0909656e %?640d09656e640d09726573756c74203d20726573756c742874 %?6865537562737b3a7d293b202025205375627365742e0d0969 %?66206e6172676f7574203e20300d0909746865526573756c74 %?203d20726573756c743b0d09656c73650d0909646973702872 %?6573756c74290d09656e640d0972657475726e0d656e640d0d %?2520526567756c61722070726f63657373696e672e0d0d7265 %?73756c74203d205b5d3b0d6966206e6172676f7574203e2030 %?2c20746865526573756c74203d20726573756c743b20656e64 %?0d2020200d73203d207468655374727563743b0d7468655479 %?7065203d20732831292e747970653b0d74686553756273203d %?20732831292e737562733b0d73283129203d205b5d3b0d0d6e %?63636865636b2873656c66290d7468654175746f7363616c65 %?666c6167203d20286175746f7363616c652873656c6629203d %?3d2031293b0d7468654461746174797065203d206461746174 %?7970652873656c66293b0d746865547970656c656e203d206e %?636d65782827747970656c656e272c20746865446174617479 %?7065293b0d6973556e7369676e6564203d20756e7369676e65 %?642873656c66293b0d74686546696c6c76616c7565203d2066 %?696c6c76616c2873656c66293b0d7468654175746f6e616e66 %?6c6167203d20286175746f6e616e2873656c6629203d3d2031 %?292026207e6973656d7074792874686546696c6c76616c7565 %?293b0d6966207468654175746f7363616c65666c61670d0974 %?68655363616c65666163746f72203d207363616c6566616374 %?6f722873656c66293b0d097468654164646f6666736574203d %?206164646f66667365742873656c66293b0d656e640d0d7377 %?6974636820746865547970650d636173652027282927202020 %?25205661726961626c65206461746120627920696e6465783a %?2073656c66282e2e2e2c202e2e2e292e0d09696e6469636573 %?203d20746865537562733b0d0974686553697a65203d206e63 %?73697a652873656c66293b0d09666f722069203d20313a6c65 %?6e67746828696e6469636573290d090969662069736128696e %?64696365737b697d2c2027646f75626c6527290d0909096966 %?20616e792864696666286469666628696e64696365737b697d %?2929290d0909090964697370282720232320496e646578696e %?672073747269646573206d75737420626520706f7369746976 %?6520616e6420636f6e7374616e742e27290d09090909726574 %?75726e0d090909656e640d0909656e640d09656e640d202020 %?0d2520466c697020616e64207065726d75746520696e646963 %?6573206265666f72652070726f63656564696e672c0d252020 %?73696e636520776520617265207573696e6720766972747561 %?6c20696e646578696e672e0d2020200d097468654f7269656e %?746174696f6e203d206f7269656e742873656c66293b0d0969 %?6620616e79287468654f7269656e746174696f6e203c203029 %?207c20616e792864696666287468654f7269656e746174696f %?6e29207e3d2031290d0909666f722069203d20313a6c656e67 %?7468287468654f7269656e746174696f6e290d090909696620 %?7468654f7269656e746174696f6e286929203c20300d090909 %?0969662069736128696e64696365737b697d2c2027646f7562 %?6c6527292020202520536c6964652074686520696e64696365 %?732e0d0909090909696e64696365737b697d203d20666c6970 %?6c722874686553697a65286929202b2031202d20696e646963 %?65737b697d293b0d09090909656e640d090909656e640d0909 %?656e640d0909696e646963657328616273287468654f726965 %?6e746174696f6e2929203d20696e64696365733b0d09097468 %?6553697a6528616273287468654f7269656e746174696f6e29 %?29203d2074686553697a653b0d09656e640d0d096966207072 %?6f642874686553697a6529203e20300d09097374617274203d %?207a65726f7328312c206c656e6774682874686553697a6529 %?293b0d0909636f756e74203d206f6e657328312c206c656e67 %?74682874686553697a6529293b0d0909737472696465203d20 %?6f6e657328312c206c656e6774682874686553697a6529293b %?0d0909666f722069203d20313a6d696e286c656e6774682869 %?6e6469636573292c206c656e6774682874686553697a652929 %?0d090909096b203d20696e64696365737b697d3b0d09090909 %?6966207e6973737472286b292026207e737472636d70286b2c %?20273a27292026207e737472636d70286b2c20272d27290d09 %?0909097374617274286929203d206b2831292d313b0d090909 %?09636f756e74286929203d20206c656e677468286b293b0d09 %?09090964203d20303b0d090909096966206c656e677468286b %?29203e20312c2064203d2064696666286b293b20656e640d09 %?090909737472696465286929203d206d617828642831292c20 %?31293b0d090909656c73650d09090909636f756e7428692920 %?3d202d313b0d0909090969662069203d3d206c656e67746828 %?696e64696365732920262069203c206c656e67746828746865 %?53697a65290d09090909096a203d20692b313a6c656e677468 %?2874686553697a65293b0d0909090909636f756e74286a2920 %?3d202d6f6e657328312c206c656e677468286a29293b0d0909 %?0909656e640d090909656e640d0909656e640d090973746172 %?74287374617274203c203029203d20303b0d09097374726964 %?6528737472696465203c203029203d20313b0d0909666f7220 %?69203d20313a6c656e67746828636f756e74290d0909096966 %?20636f756e74286929203d3d202d310d090909096d6178636f %?756e74203d20666978282874686553697a652869292d737461 %?72742869292b7374726964652869292d3129202e2f20737472 %?696465286929293b0d09090909636f756e74286929203d206d %?6178636f756e743b0d090909656e640d0909656e640d090974 %?68654e6574434446203d20706172656e742873656c66293b0d %?09097468654e6574434446203d20656e646566287468654e65 %?74434446293b0d0909636f756e7428636f756e74203c203029 %?203d20303b0d0909696620616e7928636f756e74203d3d2030 %?292c206572726f7228272023232042616420636f756e742e27 %?292c20656e640d0909696620616c6c28636f756e74203d3d20 %?31290d0909095b726573756c742c207374617475735d203d20 %?6e636d6578282776617267657431272c206e6369642873656c %?66292c2076617269642873656c66292c202e2e2e0d09090909 %?09090909090973746172742c2030293b0d0d656c7365696620 %?616c6c28737472696465203d3d2031290d0d0909095b726573 %?756c742c207374617475735d203d206e636d65782827766172 %?676574272c206e6369642873656c66292c2076617269642873 %?656c66292c202e2e2e0d090909090909090909097374617274 %?2c20636f756e742c2030293b0d0909656c73650d090909696d %?6170203d205b5d3b0d0909095b726573756c742c2073746174 %?75735d203d206e636d6578282776617267657467272c206e63 %?69642873656c66292c2076617269642873656c66292c202e2e %?2e0d0909090909090909090973746172742c20636f756e742c %?207374726964652c20696d61702c202e2e2e0d090909090909 %?0909090930293b0d0909656e640d0909696620746865417574 %?6f6e616e666c6167202620737461747573203e3d20300d0909 %?0966203d2066696e6428726573756c74203d3d207468654669 %?6c6c76616c7565293b0d090909696620616e792866292c2072 %?6573756c74286629203d204e614e3b20656e640d0909656e64 %?0d09096966207468654175746f7363616c65666c6167202620 %?737461747573203e3d20300d090909726573756c74203d2072 %?6573756c74202e2a207468655363616c65666163746f72202b %?207468654164646f66667365743b0d0909656e640d09096966 %?206973556e7369676e656420262070726f642873697a652872 %?6573756c742929203e20300d090909726573756c7428726573 %?756c74203c203029203d20325e28382a746865547970656c65 %?6e29202b20726573756c7428726573756c74203c2030293b0d %?0909656e640d0920656c73650d0909726573756c74203d205b %?5d3b0d0909737461747573203d20303b0d09656e640d096966 %?20737461747573203e3d203020262070726f642873697a6528 %?726573756c742929203e20300d0909726573756c74203d2070 %?65726d75746528726573756c742c206c656e6774682873697a %?6528726573756c7429293a2d313a31293b0d09097468654f72 %?69656e746174696f6e203d206f7269656e742873656c66293b %?0d0909696620616e79287468654f7269656e746174696f6e20 %?3c203029207c20616e792864696666287468654f7269656e74 %?6174696f6e29207e3d2031290d090909666f722069203d2031 %?3a6c656e677468287468654f7269656e746174696f6e290d09 %?0909096966207468654f7269656e746174696f6e286929203c %?20300d0909090909726573756c74203d20666c697064696d28 %?726573756c742c20616273287468654f7269656e746174696f %?6e28692929293b0d09090909656e640d09092009656e640d09 %?09096966206c656e677468287468654f7269656e746174696f %?6e29203c20320d090909097468654f7269656e746174696f6e %?203d205b7468654f7269656e746174696f6e20325d3b0d0909 %?09656e640d090909726573756c74203d207065726d75746528 %?726573756c742c20616273287468654f7269656e746174696f %?6e29293b0d0909656e640d09656c7365696620737461747573 %?203e3d203020262070726f642873697a6528726573756c7429 %?29203d3d20300d0909726573756c74203d205b5d3b0d09656c %?73650d09097374617475732c2070726f645f73697a655f7265 %?73756c74203d2070726f642873697a6528726573756c742929 %?20202025202a2a2a0d09097761726e696e672827202323206e %?637661722f73756273726566206661696c7572652e27290d09 %?656e640d6361736520272e2720202025204174747269627574 %?653a2073656c662e7468654174746e616d65282e2e2e290d09 %?7468654174746e616d65203d20746865537562733b0d097768 %?696c65206c656e677468287329203e20302020202520446f74 %?746564206e616d652e0d090973776974636820732831292e74 %?7970650d09096361736520272e270d0909097468654174746e %?616d65203d205b7468654174746e616d6520272e2720732831 %?292e737562735d3b0d09090973283129203d205b5d3b0d0909 %?6f74686572776973650d090909627265616b0d0909656e640d %?09656e640d09726573756c74203d206174742873656c662c20 %?7468654174746e616d65293b0d096966207e6973656d707479 %?28726573756c74292c20726573756c74203d20737562737265 %?6628726573756c742c2073293b20656e640d6f746865727769 %?73650d097761726e696e67285b2720232320496c6c6567616c %?2073796e7461783a2022272074686554797065202722275d29 %?0d656e640d0d6966206e6172676f7574203e20302020202520 %?416c7761797320747275652e0d09746865526573756c74203d %?20726573756c743b0d656c7365202020252049732074686572 %?6520616e792077617920746f20666f72636520746869733f0d %?0963203d206e636174742827435f666f726d6174272c207365 %?6c66293b0d096966207e6973656d7074792863290d09096320 %?3d2063283a293b0d090973203d2073697a6528726573756c74 %?290d0909726573756c74203d20726573756c742e273b0d0909 %?726573756c74203d20726573756c74283a293b0d0909737465 %?70203d2070726f642873292f732831293b0d09096b203d2031 %?3a737465703b0d0909666f722069203d20313a732831290d09 %?0909667072696e746628632c20726573756c74286b29293b0d %?090909667072696e746628275c6e27293b0d0909096b203d20 %?6b202b20737465703b0d0909656e640d09656c73650d090964 %?69737028726573756c74290d09656e640d656e640d fclose(fout); disp(' ## Installing: "subsref_original.m" (text)') fout = fopen('subsref_original.m', 'w'); %function theResult = subsref(self, theStruct) % %% ncvar/subsref -- Overloaded "{}", ".", and "()" operators. %% subsref(self, theStruct) processes the subscripting %% operator () for self, an "ncvar" object referenced on %% the righthand side of an assignment, such as in %% result = self(i, j, ...), where the sole operator %% is '()'. If the syntax is result = self.theAttname %% or result = self.theAttname(...), the named attribute %% object of self is processed. If fewer than the full %% number of indices are provided, the silent ones %% default to 1, unless the last one provided is ':', %% in which case the remainder default to ':' as well. %% Indices beyond the full number needed are ignored. %% ## Only a constant stride is permitted at present. %% %% If the "quick" flag is set, faster "vanilla-flavored" %% processing is forced. Except for autoscaling, no %% special treatments are performed, such as virtual %% indexing, implicit indexing (including ":"), unsigned %% conversions, or auto-NaNing. % %% Also see: ncvar/subsasgn. % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 15:55:19. %% Updated 11-May-2001 11:17:14. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % result = self; % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Quick processing. %% The NetCDF file must already be in "data" mode. % %isQuick = quick(self) & ... % length(theStruct) == 1 & ... % isequal(theStruct.type, '()'); % %if isQuick % indices = theStruct.subs; % if ~iscell(indices), indices = {indices}; end % if (0) % Slow, but proper. % theNCid = ncid(self); % theVarid = varid(self); % theSize = ncsize(self); % Slow. % start = zeros(size(theSize)); % count = zeros(size(theSize)); % theAutoscaleflag = autoscale(self); % else % Fast, but very bad manners. % s = struct(self); % s = s.ncitem; % s = struct(s); % theNCid = s.itsNCid; % theVarid = s.itsVarid; % start = zeros(1, length(indices)); % count = zeros(1, length(indices)); % theAutoscaleflag = s.itIsAutoscaling; % end % for i = 1:length(indices) % k = indices{i}; % start(i) = min(k) - 1; % count(i) = length(k); % end % [result, status] = ncmex('varget', theNCid, theVarid, ... % start, count, theAutoscaleflag); % if status >= 0 % result = permute(result, length(size(result)):-1:1); % end % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Composite-variable processing. %% We map the source-indices to the destination-indices %% for each composite-variable participant. The indices %% are in cells of cells, arranged in the same order as %% the variables, which themselves are in a cell. % %theVars = var(self); % A cell. %if ~isempty(theVars) % [theSrcsubs, theDstsubs] = subs(self); % The mappings. % result = []; % for i = length(theVars):-1:1 % src = theSrcsubs{i}; % A cell. % dst = theDstsubs{i}; % A cell. %% x = theVars{i}(src{:}); % x = ncsubsref(theVars{i}, '()', src); % result(dst{:}) = x; % end % theSize = size(result); % theSubs = theStruct(1).subs; % if length(theSize) > length(theSubs) % if isequal(theSubs{length(theSubs)}, ':') % extra = ':'; % else % extra = 1; % end % for i = length(theSubs)+1:length(theSize) % theSubs{i} = extra; % end % end % result = result(theSubs{:}); % Subset. % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Regular processing. % %result = []; %if nargout > 0, theResult = result; end % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %nccheck(self) %theAutoscaleflag = (autoscale(self) == 1); %theDatatype = datatype(self); %theTypelen = ncmex('typelen', theDatatype); %isUnsigned = unsigned(self); %theFillvalue = fillval(self); %theAutonanflag = (autonan(self) == 1) & ~isempty(theFillvalue); %if theAutoscaleflag % theScalefactor = scalefactor(self); % theAddoffset = addoffset(self); %end % %switch theType %case '()' % Variable data by index: self(..., ...). % indices = theSubs; % theSize = ncsize(self); % for i = 1:length(indices) % if isa(indices{i}, 'double') % if any(diff(diff(indices{i}))) % disp(' ## Indexing strides must be positive and constant.') % return % end % end % end % %% Flip and permute indices before proceeding, %% since we are using virtual indexing. % % theOrientation = orient(self); % if any(theOrientation < 0) | any(diff(theOrientation) ~= 1) % for i = 1:length(theOrientation) % if theOrientation(i) < 0 % if isa(indices{i}, 'double') % Slide the indices. % indices{i} = fliplr(theSize(i) + 1 - indices{i}); % end % end % end % indices(abs(theOrientation)) = indices; % theSize(abs(theOrientation)) = theSize; % end % % if prod(theSize) > 0 % start = zeros(1, length(theSize)); % count = ones(1, length(theSize)); % stride = ones(1, length(theSize)); % for i = 1:min(length(indices), length(theSize)) % k = indices{i}; % if ~isstr(k) & ~strcmp(k, ':') & ~strcmp(k, '-') % start(i) = k(1)-1; % count(i) = length(k); % d = 0; % if length(k) > 1, d = diff(k); end % stride(i) = max(d(1), 1); % else % count(i) = -1; % if i == length(indices) & i < length(theSize) % j = i+1:length(theSize); % count(j) = -ones(1, length(j)); % end % end % end % start(start < 0) = 0; % stride(stride < 0) = 1; % for i = 1:length(count) % if count(i) == -1 % maxcount = fix((theSize(i)-start(i)+stride(i)-1) ./ stride(i)); % count(i) = maxcount; % end % end % theNetCDF = parent(self); % theNetCDF = endef(theNetCDF); % count(count < 0) = 0; % if any(count == 0), error(' ## Bad count.'), end % if all(count == 1) % [result, status] = ncmex('varget1', ncid(self), varid(self), ... % start, 0); % %elseif all(stride == 1) % % [result, status] = ncmex('varget', ncid(self), varid(self), ... % start, count, 0); % else % imap = []; % [result, status] = ncmex('vargetg', ncid(self), varid(self), ... % start, count, stride, imap, ... % 0); % end % if theAutonanflag & status >= 0 % f = find(result == theFillvalue); % if any(f), result(f) = NaN; end % end % if theAutoscaleflag & status >= 0 % result = result .* theScalefactor + theAddoffset; % end % if isUnsigned & prod(size(result)) > 0 % result(result < 0) = 2^(8*theTypelen) + result(result < 0); % end % else % result = []; % status = 0; % end % if status >= 0 & prod(size(result)) > 0 % result = permute(result, length(size(result)):-1:1); % theOrientation = orient(self); % if any(theOrientation < 0) | any(diff(theOrientation) ~= 1) % for i = 1:length(theOrientation) % if theOrientation(i) < 0 % result = flipdim(result, abs(theOrientation(i))); % end % end % if length(theOrientation) < 2 % theOrientation = [theOrientation 2]; % end % result = permute(result, abs(theOrientation)); % end % elseif status >= 0 & prod(size(result)) == 0 % result = []; % else % status, prod_size_result = prod(size(result)) % *** % warning(' ## ncvar/subsref failure.') % end %case '.' % Attribute: self.theAttname(...) % theAttname = theSubs; % while length(s) > 0 % Dotted name. % switch s(1).type % case '.' % theAttname = [theAttname '.' s(1).subs]; % s(1) = []; % otherwise % break % end % end % result = att(self, theAttname); % if ~isempty(result), result = subsref(result, s); end %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % Always true. % theResult = result; %else % Is there any way to force this? % c = ncatt('C_format', self); % if ~isempty(c) % c = c(:); % s = size(result) % result = result.'; % result = result(:); % step = prod(s)/s(1); % k = 1:step; % for i = 1:s(1) % fprintf(c, result(k)); % fprintf('\n'); % k = k + step; % end % else % disp(result) % end %end fclose(fout); disp(' ## Installing: "surf.m" (text)') fout = fopen('surf.m', 'w'); %function theResult = surf(varargin) % %% ncvar/surf -- Surface-plot of a NetCDF variable. %% surf(z, 'thePen') surfs NetCDF variable z, an %% "ncvar" object, using 'thePen'. The x, y, and %% z axes are labeled with the names and units of %% the corresponding coordinate variables. The %% title is set to the name of the z variable. % %% 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-Apr-1997 09:44:36. % %if nargin < 1, help(mfilename), return, end % %if nargout > 0, theResult = []; end %result = []; % %% Isolate the pen. % %thePen = '-'; %if isstr(varargin{length(varargin)}) % thePen = varargin{length(varargin)}; % varargin(length(varargin)) = []; %end % %x = []; y = []; z = []; % %theXLabel = 'Index Number'; %theYLabel = 'Index Number'; %theZLabel = 'Value'; % %if length(varargin) == 1 % z = varargin{1}; % theNetCDF = parent(z); % theSize = ncsize(z); % theDims = dim(z); % if length(theDims) < 1, return, end % if length(theSize) > 0 % x = ncvar(name(theDims{1}), theNetCDF); % if isempty(x), x = (1:theSize(1)).'; end % end % if length(theSize) > 1 % y = ncvar(name(theDims{2}), theNetCDF); % if isempty(y), y = (1:theSize(2)).'; end % end % if ~isempty(y) % result = surf(x, y, z, thePen); % end % elseif length(varargin) > 1 % x = varargin{1}; % z = varargin{2}; % if length(varargin) > 2 % y = varargin{2}; % z = varargin{3}; % end % if isa(x, 'ncvar') % theXLabel = name(x); % a = ncatt('units', x); % theXUnits = a(:); % if ~isempty(theXUnits), theXLabel = [theXLabel ' ' theXUnits]; end % x = x(:); % end % if isa(y, 'ncvar') % theYLabel = name(y); % a = ncatt('units', y); % theYUnits = a(:); % if ~isempty(theYUnits), theYLabel = [theYLabel ' ' theYUnits]; end % y = y(:); % end % theZLabel = name(z); % a = ncatt('units', z); % theZUnits = a(:); % if ~isempty(theZUnits), theZLabel = [theZLabel ' ' theZUnits]; end % axes(gca) % if length(varargin) > 2 % result = surf(x, y, z(:), thePen); % xlabel(labelsafe(theXLabel)) % ylabel(labelsafe(theYLabel)) % zlabel(labelsafe(theZLabel)) % end % theTitle = name(z); % title(labelsafe(theTitle)) %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "var.m" (text)') fout = fopen('var.m', 'w'); %function theResult = var(varargin) % %% ncvar/var -- Manipulate the constituent-variables. %% var(self) returns the list of variables that contribute %% to self, a composite "ncvar" object. A non-composite %% variable returns the empty-cell {}. %% var(v1, s1, d1, v2, s2, d2, ...) returns a composite "ncvar" %% object, based on the variables v1, ..., their respective %% source-indices s1, ..., and their corresponding destination- %% indices d1, ... Each set of indices is contained in a cell; %% use the string ':' for a standalone-colon. The source- %% indices refer to the participating "ncvar" objects, whereas %% the destination-indices refer to the composite output array. %% A composite-variable behaves much like a regular variable. %% var(v1, v2, ...) returns an "ncvar" object representing %% a composite-variable, whose constituents are the given %% "ncvar" objects v1, v2, ... Use "ncvar/subs" to set-up %% the corresponding source and destination indices. % %% 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 29-Sep-1997 15:47:27. % %if nargin < 1, help(mfilename), return, end % %if nargin == 1 % self = varargin{1}; % result = self.itsVars; % if isempty(result), result = {}; end %elseif nargin > 1 & isa(varargin{2}, 'ncvar') % self = ncvar; % theVars = varargin; % if isempty(theVars), theVars = {}; end % self.itsVars = theVars; % result = self; %elseif nargin > 2 & ... % rem(nargin, 3) == 0 & ... % isa(varargin{2}, 'cell') % self = ncvar; % theVars = varargin(1:3:length(varargin)); % theSrcsubs = varargin(2:3:length(varargin)); % theDstsubs = varargin(3:3:length(varargin)); % self.itsVars = theVars; % self.itsSrcsubs = theSrcsubs; % self.itsDstsubs = theDstsubs; % result = self; %else % result = ncvar; % warning(' ## Invalid syntax.') %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'ncvar') fclose(fout); cd ('..') bund_setdir('@netcdf') disp(' ## Installing: "abort.m" (text)') fout = fopen('abort.m', 'w'); %function theResult = abort(self) % %% netcdf/abort -- Abort recent definitions in the NetCDF file. %% abort(self) aborts recent definitions in the NetCDF %% file represented by self, a netcdf object. % %% 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 29-Jul-1997 09:36:10. % %if nargin < 1, help(mfilename), return, end % %status = ncmex('abort', ncid(self)); % %result = self; % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "att.m" (text)') fout = fopen('att.m', 'w'); %function theResult = att(self, theAttname) % %% netcdf/att -- Attributes of a netcdf object. %% att(self, 'theAttname') returns the ncatt object %% whose name is theAttname, associated with self, %% a netcdf object. %% att(self) returns the cell-list of ncatt objects %% associated with self, a netcdf object. % %if nargin < 1, help netcdf/att, return, end % %result = []; % %if nargin == 1 % [ndims, nvars, ngatts, recdim, status] = ... % ncmex('inquire', ncid(self)); % result = cell(1, ngatts); % for i = 1:ngatts % theAttnum = i-1; % [theAttname, status] = ... % ncmex('attname', ncid(self), varid(self), theAttnum); % result{i} = ncatt(theAttname, self); % end % else % result = ncatt(theAttname, self); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "close.m" (text)') fout = fopen('close.m', 'w'); %function theResult = close(self) % %% netcdf/close -- Close the file of a "netcdf" object. %% close(self) closes the NetCDF file associated %% with self, a "netcdf" object. The empty matrix %% [] is returned if successful; otherwise self %% is returned. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if (ncmex('close', ncid(self)) < 0) % result = self; % warning([' ## ' mfilename ' failed: ' name(self)]) %end % %ncregister(self, result) %result = ncregister(self); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "coord.m" (text)') fout = fopen('coord.m', 'w'); %function theResult = coord(self) % %% netcdf/coord -- Coordinate variables %% coord(self) returns the coordinate variables %% of self. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %vars = var(self); % %for i = length(vars):-1:1 % if ~iscoord(vars{i}), vars(i) = []; end %end % %if nargout > 0 % theResult = vars; % else % for i = 1:length(vars) % disp(name(vars{i})) % end %end fclose(fout); disp(' ## Installing: "copy.m" (text)') fout = fopen('copy.m', 'w'); %function theResult = copy(self, theDestination) % %% netcdf/copy -- Copy one NetCDF into another. %% copy(self, theDestination) copies the contents %% of self, a netcdf or cell, into theDestination, %% a netcdf. If self is a cell, the enclosed %% items are processed in the order given, with %% variable data copying reserved for last. % %% 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 20-May-1997 09:09:49. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch ncclass(theDestination) %case 'netcdf' % switch ncclass(self) % case 'cell' % theItems = self; % case 'netcdf' % theItems = [att(self), dim(self), var(self)]; % otherwise % disp(' ## Incompatible arguments.') % end % for i = 1:length(theItems) % it = theItems{i}; % switch ncclass(it) % case {'netcdf', 'ncdim', 'ncatt', 'ncrec'} % result{i} = copy(it, theDestination); % case 'ncvar' % result{i} = copy(it, theDestination, 0, 1); % otherwise % disp(' ## Incompatible arguments.') % end % end % for i = 1:length(theItems) % it = theItems{i}; % switch ncclass(it) % case 'ncvar' % result{i} = copy(it, theDestination, 1, 0); % otherwise % end % end %otherwise %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "create.m" (text)') fout = fopen('create.m', 'w'); %function theResult = create(self, thePermission) % %% netcdf/create -- Create the file for a netcdf object. %% create(self, 'thePermission') creates the NetCDF file %% associated with self, a netcdf object, using %% thePermission, either 'clobber' or 'noclobber' %% (default). The object (self) is returned. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2, thePermission = 'noclobber'; end % %[theNCid, status] = ncmex('create', name(self), thePermission); % %if status >= 0 % w = which(name(self)); % if ~isempty(w), self = name(self, w); end % self = ncid(self, theNCid); % self.itsDefineMode = 'define'; % [ndims, nvars, ngatts, theRecdim, status] = ... % ncmex('inquire', ncid(self)); % if status >= 0, self = recdim(self, theRecdim); end % ncregister(self) % self = ncregister(self); %end % %result = self; % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "delete.m" (text)') fout = fopen('delete.m', 'w'); %function theResult = delete(self, varargin) % %% netcdf/delete -- Delete items from NetCDF file. %% delete(self, item1, item2, ...) deletes the given items %% ("ncdim", "ncvar", or "ncatt" objects) from the NetCDF %% file represented by self, a "netcdf" object. The %% updated "netcdf" object 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 13-Aug-1997 08:51:21. %% Updated 12-Nov-2002 14:41:20. % %result = []; %if nargout > 0, theResult = result; end % %if nargin < 2, help(mfilename), return, end % %self = ncregister(self); % %theItems = varargin; %if length(varargin) < 1, return, end % %switch permission(self) %case 'nowrite' % disp([' ## No "' mfilename '" action taken; ' ... % 'file "' name(self) '" permission is "nowrite".']) % return %otherwise %end % %% All objects. % %theObjects = [att(self) dim(self) var(self)]; % %% Cull items to be deleted. % %for i = 1:length(theItems) % for k = length(theObjects):-1:1 % if isequal(theObjects{k}, theItems{i}) % theObjects(k) = []; % end % end %end % %% Temporary file. % %temp = netcdf('random'); %if isempty(temp), return, end % %% Copy dimensions and global attributes. % %for k = 1:length(theObjects) % switch ncclass(theObjects{k}) % case 'ncdim' % d = theObjects{k}; % copy(d, temp) % case 'ncatt' % g = theObjects{k}; % if isglobal(g), copy(g, temp), end % otherwise % end %end % %% Copy variable definitions and attributes. % %for k = 1:length(theObjects) % switch ncclass(theObjects{k}) % case 'ncvar' % v = theObjects{k}; % copy(v, temp, 0, 0, 0) % a = att(v); % for j = length(a):-1:1 % for i = 1:length(theItems) % if isequal(a{j}, theItems{i}), a(j) = []; end % end % end % %% Matlab 6.5 is acting odd with respect to "subsref/subsasgn". %% It seems to forget or ignore the fact that some variables %% are objects, not doubles or cells. For example, the %% following "u = temp{name(v)}" generates an error, saying %% that "{...}" refers to a cell where no cell exists -- %% indeed, "temp" is a "netcdf" object, which has its %% own "{...}" non-cell syntax. Evidently, Matlab would %% prefer that we not use "(){}." syntax within the body %% of methods of the same class. But what about derived %% classes? % %if (0) % hello % temp % class(temp) % name(v) % u = temp{name(v)}; %end % % u = ncvar(name(v), temp); % Revised from above. % % for j = 1:length(a), copy(a{j}, u), end % end %end % %% Copy variable data. % %for k = 1:length(theObjects) % switch ncclass(theObjects{k}) % case 'ncvar' % v = theObjects{k}; % copy(v, temp, 1, 0, 0) % otherwise % end %end % %theTempFilename = name(temp); %theFilename = name(self); % %close(temp) %close(self) % %fcopy(theTempFilename, theFilename) %delete(theTempFilename) % %result = netcdf(theFilename, 'write'); % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "dim.m" (text)') fout = fopen('dim.m', 'w'); %function theResult = dim(self, theDimname) % %% netcdf/dim -- Dimensions of a netcdf object. %% dim(self, 'theDimname') returns the ncdim object %% whose name is theDimname, associated with self, %% a netcdf object. %% dim(self) returns the cell-list of ncdim objects %% associated with self, a netcdf object. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %result = []; % %if nargin < 2 % [ndims, nvars, ngatts, recdim, status] = ... % ncmex('inquire', ncid(self)); % result = cell(1, ndims); % for i = 1:ndims % theDimid = i-1; % [theDimname, theDimsize, status] = ... % ncmex('diminq', ncid(self), theDimid); % result{i} = ncdim(theDimname, self); % end %else % result = ncdim(theDimname, self); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "endef.m" (text)') fout = fopen('endef.m', 'w'); %function theResult = endef(self) % %% netcdf/endef -- Disable the NetCDF "define" mode. %% endef(self) disables the "define" mode of the netCDF %% file associated with self, a netcdf object. Use %% redef(self) to enable the "define" mode. Self is %% returned with 'itsDefineMode' field set to 'define' %% or 'data'. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %result = redef(self, 'data'); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "fatnames.m" (text)') fout = fopen('fatnames.m', 'w'); %function theResult = fatnames(self, theMaxNameLen) % %% netcdf/fatnames -- Enable fat-names. %% fatnames(f, theMaxNameLen) makes provision in self, %% a "netcdf" object, for the storage of names up to the %% given maximum length (not to exceed the MAX_NC_NAME %% parameter). The purpose is to allow for the later %% renaming of NetCDF items without forcing the rewriting %% of the NetCDF file itself whenever a new name exceeds %% the length of the original. Set theMaxNameLen to 0 %% (zero) to disable the feature (the default behavior). %% The "netcdf" object is returned. %% fatnames(f) returns the present "fatnames" length. %% %% N.B. This routine is experimental at present. % %% 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 13-May-1999 08:46:20. % %if nargin < 1, help(mfilename), return, end % %self = ncregister(self); % %if nargin < 2 % result = self.itsMaxNameLen; %else % result = self; % max_nc_name = ncmex('parameter', 'MAX_NC_NAME'); % result.itsMaxNameLen = min(max(theMaxNameLen, 0), max_nc_name); % ncregister(result) %end % %if nargout > 0 % theResult = result; %else % disp(result); %end fclose(fout); disp(' ## Installing: "inquire.m" (text)') fout = fopen('inquire.m', 'w'); %function theResult = inquire(self) % %% netcdf/inquire -- Deep inquiry of a netCDF file. %% inquire(self) returns self, a netcdf object, after %% updating its fields with the results of a deep inquiry %% into all of its dimensions, variables, and attributes. % %if nargin < 1, help(mfilename), return, end % %result = []; % %[ndims, nvars, ngatts, theRecdim, status] = ncmex(id(self)); % %if status ~= 0 % warning(' ## ' mfilename ' failure.') % return %end % %% Variables. % %theVars = cell(nvars, 1); %for theVarid = -1:nvars-1 % theVars{i} = ncvar(id(self), theVarid); %end % %self = var(self, theVars); %result = self; % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "isepic.m" (text)') fout = fopen('isepic.m', 'w'); %function theResult = isepic(self) % %% netcdf/isepic -- Is this an epic file? %% isepic(self) returns TRUE (1) if self, a "netcdf" %% object, appears to represent a NOAA epic file. % %% 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 05-May-1997 10:43:30. % %if nargin < 1, help(mfilename), return, end % %result = 0; %if (0) % Matlab pre-5.3 syntax. % theTime = self{'time'}; % theTime2 = self{'time2'}; %else % Matlab 5.3. % s.type = '{}'; % s.subs = {'time'}; % theTime = subsref(self, s); % s.subs = {'time2'}; % theTime2 = subsref(self, s); %end % %if ~isempty(theTime) & ~isempty(theTime2) % theEpicCode = theTime.epic_code; % theEpicCode2 = theTime2.epic_code; % if ~isempty(theEpicCode) & ~isempty(theEpicCode2) % result = 1; % end %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "lt.m" (text)') fout = fopen('lt.m', 'w'); %function theResult = lt(self, theItem) % %% netcdf/lt -- Redirect an item into self. %% lt(self, theItem) redirects theItem, derived from %% the ncitem class, into self, a netcdf object. %% If theItem is a cell-array, its elements are %% processed one at a time in the order given. %% When intending to copy more than one variable, %% use a cell-array of variables for efficiency. %% The returned value is the destination object %% or list of objects, depending on context. % %% 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 19-May-1997 13:25:31. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch ncclass(self) %case 'netcdf' % switch ncclass(theItem) % case {'cell', 'netcdf', 'ncdim', 'ncvar', 'ncatt', 'ncrec'} % result = copy(theItem, self); % otherwise % warning(' ## Incompatible arguments.') % end %otherwise % warning(' ## Incompatible arguments.') %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "mode.m" (text)') fout = fopen('mode.m', 'w'); %function theResult = mode(self) % %% netcdf/mode -- Define/data mode. %% mode(self) returns the "define" mode ('define' %% or 'data') of self, a "netcdf" object. % %% 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 11-Aug-1997 10:43:29. % %if nargin < 1, help(mfilename), return, end % %self = ncregister(self); % %result = self.itsDefineMode; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ncregister.m" (text)') fout = fopen('ncregister.m', 'w'); %function theResult = ncregister(self, theValue) % %% netcdf/ncregister -- Register a netcdf object. %% theResult = ncregister(self) returns the current %% registry entry for self, a "netcdf" object. %% ncregister(self, theValue) registers self as theValue, %% either self on "open" or [] on "close". %% ncregister(self) calls "ncregister(self, self)" to %% place self in the registry. % %% 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 13-Aug-1997 10:22:21. % %global NETCDF_REGISTRY %global NETCDF_INITIALIZED % %theRegistryIndex = ncid(self) + 1; % %if nargout > 0 % if theRegistryIndex > 0 % theResult = NETCDF_REGISTRY{theRegistryIndex}; % else % theResult = []; % end %else % if nargin < 2, theValue = self; end % if theRegistryIndex > 0 % NETCDF_REGISTRY{theRegistryIndex} = theValue; % end %end % %if isempty(NETCDF_INITIALIZED) % NETCDF_INITIALIZED = 1; % ncquiet %end fclose(fout); disp(' ## Installing: "netcdf.m" (text)') fout = fopen('netcdf.m', 'w'); %function self = netcdf(theFilename, thePermission) % %% netcdf/netcdf -- Constructor for netcdf class. %% %% netcdf (no arguments) shows extensive "help". %% netcdf('version') shows the present version number. %% %% netcdf('theFilename', 'thePermission') creates and/or %% opens 'theFilename' if 'thePermission' is one of %% {'clobber', 'noclobber', 'write', 'nowrite'} or a %% unique abbreviation thereof. The "netcdf" object %% is assigned silently to "ans" if no output argument %% is provided. %% %% netcdf('thePermission') invokes Matlab's "uiputfile" %% or "uigetfile" dialog for selecting the file to create %% or open, respectively, depending on 'thePermission' %% (default = 'nowrite' if possible, then 'noclobber'). %% %% netcdf('random') creates a NetCDF file with a unique, %% random name, suitable for use as a temporary file. %% %% self = netcdf (no argument) calls "netcdf('nowrite')", %% which invokes matlab's "uigetfile" dialog. The returned %% "self" is the "netcdf" object that was opened. %% %% netcdf(theNCid) returns a "netcdf" object corresponding %% to theNCid of an open NetCDF file. This function does %% not re-open the file. TheNCid is the formal identification %% number that would be returned ordinarily by a call to the %% NetCDF "nccreate" or "ncopen" function. %% %% Other permissions: The word 'readonly' is a synonym for 'nowrite'. %% The word 'define' can be used to open an existing file in 'define' %% mode, although this is not strictly necessary, since the "NetCDF %% Toolbox" switches context automatically, as needed. %% %% <<<<<<<<<< Language Synopsis of the NetCDF Toolbox >>>>>>>>>> %% %% [...] denotes default value. %% %% Create or open a NetCDF file: %% f = netcdf('myNetCDF.nc', 'clobber | noclobber') %% f = netcdf('myNetCDF.nc', 'write | [nowrite]') %% where f is the returned "netcdf" object. %% f = netcdf('clobber | noclobber') for "uiputfile" dialog. %% f = netcdf('write | [nowrite]') for "uigetfile" dialog. %% f = netcdf('random') to create a randomly named file. %% %% Define a NetCDF global attribute: %% f.myGlobalAttribute = [myGlobalAttributeDoubleData] %% f.myGlobalAttribute = 'myGlobalAttributeCharData' %% f.myGlobalAttribute = nctype(myGlobalAttributeData) %% where nctype = [ncdouble] | ncfloat | nclong | ... %% ncint | ncshort | ncbyte | [ncchar] %% (N.B. default depends on context.) %% (See "NetCDF User's Guide" for datatype definitions.) %% %% f.myGlobalAttribute = [] deletes the attribute. %% g = f.myGlobalAttribute is the object. %% g(:) = [] deletes the attribute. %% %% Define a NetCDF record-dimension: %% f('myRecordDimension') = 0 defines a record-dimension. %% f('myRecordDimension') = [] deletes the dimension. %% r = f('myRecordDimension') is the object. %% r(:) = [] deletes the dimension. %% r(:) = newSize resizes the dimension. %% %% Define a NetCDF dimension: %% f('myDimension') = myDimensionLength %% f('myDimension') = [] deletes the dimension. %% d = f('myDimension') is the object. %% d(:) = [] deletes the dimension. %% d(:) = newSize resizes the dimension. %% isrecdim(d) determines whether d is the record-dimension. %% iscoord(v) determines whether d is a coordinate-dimension. %% %% Define a NetCDF variable: %% f{'myVariable'} = nctype(myRecordDimension, myDimension, ...) %% f{'myVariable'} = nctype(myDimension, ...) %% f{'myVariable'} = nctype(r, d, ...) %% f{'myVariable'} = nctype(d, ...) %% f('myVariable') = [] deletes the variable. %% v = f{'myVariable'} returns the object. %% v = f{'myVariable', 1} returns the object -- auto-scaling enabled. %% v(:) = [] deletes the variable. %% iscoord(v) determines whether v is a coordinate-variable. %% isscalar(v) determines whether v is a scalar-variable. %% %% Define a NetCDF attribute: %% f{'myVariable'}.myAttribute = [myAttributeDoubleData] %% f{'myVariable'}.myAttribute = 'myAttributeCharData' %% f{'myVariable'}.myAttribute = nctype(myAttributeData) %% f{'myVariable'}.myAttribute = [] deletes the attribute. %% v.myAttribute = [myAttributeDoubleData] %% v.myAttribute = 'myAttributeCharData' %% v.myAttribute = nctype(myAttributeData) %% v.myAttribute = [] deletes the attribute. %% a = f{'myVariable'}.myAttribute is the object. %% a = v.myAttribute is the object. %% a(:) = [] deletes the attribute. %% %% Store and retrieve NetCDF variable data: %% f{'myVariable'}(i, j, ...) = myVariableData %% f{'myVariable', 1}(i, j, ...) = myVariableData -- auto-scaling enabled. %% v(i, j, ...) = myVariableData %% myVariableData = f{'myVariable'}(i, j, ...) %% myVariableData = f{'myVariable', 1}(i, j, ...) -- auto-scaling enabled. %% myVariableData = v(i, j, ...) %% %% Store and retrieve NetCDF attribute data: (always a row vector) %% f.myGlobalAttribute(i) = myGlobalAttributeData %% g(i) = myGlobalAttributeData %% f{'myVariable'}.myAttribute(i) = myAttributeData %% v.myAttribute(i) = myAttributeData %% a(i) = myAttributeData %% myGlobalAttributeData = f.myGlobalAttribute(i) %% myGlobalAttributeData = g(i) %% myAttributeData = f{'myVariable'}.myAttribute(i) %% myAttributeData = v.myAttribute(i) %% myAttributeData = a(i) %% EXCEPTION: v.FillValue_ references the "_FillValue" attribute. %% Use the "fillval(v, ...)" method to avoid confusion. %% %% Store and retrieve NetCDF record data: %% s = f(0) returns the object. %% t = s(0) returns the record template as a struct. %% u = r(i) returns the i-th record data as a struct. %% x = r(i).field(...) returns a subset of a field (variable). %% s(i) = t sets the i-th record to the struct data. %% %% Indexing defaults for NetCDF variables and attributes: %% ":" means 'all', including unstated indices to the right. %% Otherwise, unstated indices to the right default to 1. %% Note: ":" does NOT impose columnization on the result. %% %% Last index: %% The keyword "end" can serve as the last index for any %% dimensional direction, as in "v(1:2:end, ...)". %% %% Duplication of NetCDF objects via "<" operator: %% (Also see use of "copy" below.) %% f < myObject copies the complete myObject into NetCDF %% file f, where myObject represents a dimension, %% variable, attribute, or another NetCDF file. %% f < myRecord copies the data of myRecord object into f. %% v < myVariable copies the data and attributes of myVariable into v. %% v < myAttribute copies myAttribute into variable v. %% v < myArray copies myArray into the data of v. %% a < myAttribute copies the contents of myAttribute into attribute a. %% a < myArray copies myArray into attribute a. %% %% Duplication of NetCDF objects via "copy": %% copy(f, myNetCDF) copies netcdf f into myNetCDF. %% copy(d, f) copies dimension d into netcdf f. %% copy(a, f) copies attribute a into netcdf f. %% copy(a, v) copies attribute a into variable v. %% copy(v, f, copyData, copyAttributes) copies variable v into %% netcdf f, as directed by the flags (defaults = 0). %% copy(v, myVariable, copyData, copyAttributes) copies the %% contents of variable v into variable myVariable, as %% directed by the flags (defaults = 0). %% %% Deletion of objects. %% delete(myObject1, myObject2, ...) deletes the objects. %% %% Lists of objects: %% dim(f) returns the dimension objects of f in a cell-array. %% var(f) returns the variable objects of f in a cell-array. %% att(f) returns the global attribute objects of f in a cell-array. %% dim(v) returns the dimension objects of v in a cell-array. %% att(v) returns the attribute objects of v in a cell-array. %% coord(f) returns the coordinate-variable objects of f. %% recdim(f) returns the record-dimension object of f. %% recdim(v) returns the record-dimension object of v. %% recvar(f) returns the record-variable objects of f in a cell-array. %% %% Basic properties of NetCDF objects: %% name(x) returns the name of object x. %% name(x, 'newname') renames object x to 'newname'. %% ncnames({list_of_objects}) returns the names of the objects. %% size(x) returns the Matlab-like size of object x. %% size(x, k) returns the k-th element of the size of object x. %% ncsize(x) returns the NetCDF-like size of object x. %% ncsize(x, k) returns the k-th element of the ncsize of object x. %% length(x) returns the Matlab-like length of object x. %% datatype(x) returns the datatype of object x. %% class(x) returns the class of x. %% ncclass(x) returns the netcdf parent class of derived x. %% parent(x) returns the parent (netcdf or ncvar) of object x. %% permission(x) returns the parent file's create/open permission. %% mode(x) returns the parent file's current "define" mode. %% fillval(v, ...) manipulates the "_FillValue" attribute. %% setfill(f, ...) manipulates the "fill-mode" of f. %% orient(v, ...) manipulates the get/put orientation of v. %% resize(d, newsize) resizes dimension d to the newsize. %% resize(v, [newsize]) resizes variable v to the [newsize]. %% %% Unsigned interpretation of integer data: %% unsigned(v) returns the "unsigned" flag of variable v. %% unsigned(v, isUnsigned) sets the "unsigned" flag of variable v. %% unsigned(a) returns the "unsigned" flag of attribute a. %% unsigned(a, isUnsigned) sets the "unsigned" flag of attribute v. %% %% Automatic scaling of variable data: %% autoscale(v, isAutoScaling) sets the "autostate" state of variable v. %% autoscale(v) returns the current "autoscale" state of variable v. %% %% Automatic substitution of fill-value by NaN: %% autonan(v, isAutoNaNing) sets the "autonan" state of variable v. %% autonan(v) returns the current "autonan" state of variable v. %% %% Quick-mode for variable input/output: %% quick(v, isQuick) sets the variable v to "quick" mode. %% quick(v) returns the current "quick" state of variable v. %% %% Arithmetic operators with NetCDF objects (right-side only): %% y = d op x returns d(:) op x for operator op, such as "-". %% y = v op x returns v(:) op x for operator op, such as "-". %% y = a op x returns a(:) op x for operator op, such as "-". %% y = op d returns op d(:) for unary operator op, such as '-'. %% y = op v returns op v(:) for unary operator op, such as '-'. %% y = op a returns op a(:) for unary operator op, such as '-'. %% %% NetCDF Conventions: %% v.FillValue_ references the "_FillValue" attribute. %% (Matlab cannot parse a beginning under-score.) %% %% Save/Load NetCDF Variables (no attributes transfered): %% ncsave('myNetCDF.nc', ...) updates variables in 'myNetCDF.nc'. %% ncload('myNetCDF.nc', ...) loads variables from 'myNetCDF.nc'. %% %% Composite-Variables: (Not for the faint-of-heart!) %% v = var(v1, s1, d1, v2, s2, d2, ...) returns a composite- %% variable using NetCDF variables v1, ..., whose s1, ... %% source-indices map to the d1, ... destination-indices %% in the composite output array. See "help ncvar/var". %% %% Miscellaneous: %% isepic(v) determines whether v is an EPIC variable. %% fatnames(f) invokes the "fatnames" facility. %% ncweb() links to the WWW home-page of the NetCDF Toolbox. %% %% Example M-Files: %% ncexample() creates, populates, and reads a NetCDF file. %% tnetcdf() exercizes the NetCDF Toolbox extensively. %% %% WWW: . %% %% <<<<<<<<<<<<<<<<< End of NetCDF Language Synopsis >>>>>>>>>>>>>>>>> % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Updated 18-Aug-1997 09:39:52. %% Updated 20-May-1999 09:33:04. %% Updated 24-Aug-1999 09:12:11. %% Updated 10-Apr-2000 21:07:48. % %ncwhatsnew % %if nargin == 1 & nargout < 1 & isequal(theFilename, 'version') % version(ncitem) % return %end % %if nargin < 1 & nargout < 1 % help(mfilename) % ncversion % disp(' ') % return %end % %if nargout > 0, self = []; end % %% Open with dialog as 'nowrite'. % %if nargout > 0 & nargin < 1 % result = netcdf('nowrite'); % if ~isempty(result) % ncregister(result) % result = ncregister(result); % end % self = result; % return %end % %if nargin < 2, thePermission = ''; end % %result = []; % %% Randomly named file. % %if nargin == 1 & strcmp(theFilename, 'random') % result = []; % count = 0; % while isempty(result) & count < 32 % thePWD = pwd; % if thePWD(length(thePWD)) ~= filesep % thePWD = [thePWD filesep]; % end % theFilename = [thePWD 'temp' int2str(rand(1, 1) .* 10000) '.nc']; % result = netcdf(theFilename, 'noclobber'); % end % if ~isempty(result) % ncregister(result) % result = ncregister(result); % end % if nargout > 0 % self = result; % else % ncans(result) % end % return %end % %if nargin == 1 % switch class(theFilename) % case 'double' % theNCid = theFilename; % theStruct.itsPermission = 'unknown'; % theStruct.itsDefineMode = 'unknown'; % theStruct.itsFillMode = 'unknown'; % theStruct.itsMaxNameLen = 0; % result = class(theStruct, 'netcdf', ncitem('', theNCid)); % result = ncregister(result); % if nargout > 0 % self = result; % else % ncans(result) % end % return % case 'char' % thePermission = ''; % thePerm = ncpermission(theFilename); % switch thePerm % case {'nowrite', 'write', 'noclobber', 'clobber', ... % 'readonly', 'define'} % thePermission = thePerm; % theFilename = '*'; % otherwise % thePermission = 'nowrite'; % end % otherwise % return % end %end % %if isempty(thePermission), thePermission = 'nowrite'; end % %if any(theFilename == '*') % switch thePermission % case {'noclobber', 'clobber'} % theSuggested = theFilename; % if isequal(theFilename, '*') % theSuggested = 'unnamed.nc'; % else % theSuggested(theSuggested == '*') = ''; % end % [theFile, thePath] = uiputfile(theSuggested, 'Save NetCDF As'); % if ~any(theFile), return, end % case {'nowrite', 'write', 'readonly', 'define'} % [theFile, thePath] = uigetfile(theFilename, 'Select NetCDF File'); % if ~any(theFile), return, end % otherwise % return % end % theFilename = [thePath theFile]; % result = netcdf(theFilename, thePermission); % if ~isempty(result) % ncregister(result) % result = ncregister(result); % end % if nargout > 0 % self = result; % else % ncans(result) % end % return %end % %thePermission = ncpermission(thePermission); % %switch thePermission %case 'define' % result = netcdf(theFilename, 'write'); % if ~isempty(result), redef(result), end % if nargout > 0 % self = result; % else % ncans(result) % end % return %otherwise %end % %theDefineMode = ''; %theFillMode = 'fill'; % The NetCDF default. %theMaxNameLen = 0; % %theStruct.itsPermission = thePermission; %theStruct.itsDefineMode = theDefineMode; %theStruct.itsFillMode = theFillMode; %theStruct.itsMaxNameLen = theMaxNameLen; % %result = class(theStruct, 'netcdf', ncitem(theFilename)); % %switch thePermission %case {'clobber', 'noclobber'} % result = create(result, thePermission); % if ncid(result) >= 0, theDefineMode = 'define'; end %case {'write', 'nowrite'} % result = open(result, thePermission); % if ncid(result) >= 0 % theDefineMode = 'data'; % elseif exist(name(result)) ~= 2 % result = open(result, 'clobber'); % if ncid(result) >= 0, theDefineMode = 'define'; end % end %otherwise % help netcdf % warning([' ## No such permission: ' thePermission]) %end % %if ncid(result) >= 0 % result.itsDefineMode = theDefineMode; % ncregister(result) % result = ncregister(result); % else % disp([' ## NetCDF file not opened: ' theFilename]) % result = []; %end % %if nargout > 0 % self = result; %else % ncans(result) %end % %function theResult = ncpermission(thePermission) % %% netcdf/ncpermission -- Resolve permission string. %% netcdf/ncpermission('thePermission') returns the NetCDF permission %% string corresponding to 'thePermission', which may be uniquely %% abbreviated. % %thePerm = lower(thePermission); % %% Lists of shortened permissions: must pre-allocate. % %clobber = []; %noclobber = []; %write = []; %nowrite = []; %readonly = []; %define = []; % %perms = {'clobber', 'noclobber', 'write', 'nowrite', 'readonly', 'define'}; %for j = 1:length(perms) % p = perms{j}; % c = cell(1, length(p)); % for i = 1:length(perms{j}) % c{i} = p; % p(length(p)) = ''; % end % eval([perms{j} ' = c;']); %end % %% Formal name of thePermission. % %switch thePerm %case clobber % thePermission = 'clobber'; %case noclobber % thePermission = 'noclobber'; %case write % thePermission = 'write'; %case [nowrite readonly] % thePermission = 'nowrite'; %case [define] % thePermission = 'define'; %otherwise %end % %if nargout > 0, theResult = thePermission; end fclose(fout); disp(' ## Installing: "numel.m" (text)') fout = fopen('numel.m', 'w'); %function theResult = numel(varargin) % %% class/numel -- Overloaded NUMEL. %% numel(varargin) is called by Matlab 6.1+ during SUBSREF %% and SUBSASGN operations to figure out how many output %% and input arguments to expect, respectively. We %% believe the answer should always be 1, in keeping %% with the way we have traditionally programmed. % %% 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 30-Jul-2001 15:45:20. %% Updated 30-Jul-2001 15:45:20. % %theResult = numel_default(varargin{:}); fclose(fout); disp(' ## Installing: "open.m" (text)') fout = fopen('open.m', 'w'); %function theResult = open(self, thePermission) % %% netcdf/open -- Open the file of a netcdf object. %% open(self, 'thePermission') opens the NetCDF file %% associated with self, a netcdf object, using %% thePermission, either 'write' or 'nowrite' (default). %% The object (self) is returned. This routine can %% be used to re-open a NetCDF file, using the %% permission already established in self from a %% previous invocation. % %if nargin < 1, help(mfilename), return, end %if nargin < 2 % thePermission = self.itsPermission; % if isempty(thePermission) % thePermission = 'nowrite'; % end %end % %[theNCid, status] = ncmex('open', name(self), thePermission); % %if status >= 0 % w = which(name(self)); % if ~isempty(w), self = name(self, w); end % self = ncid(self, theNCid); % self.itsPermission = thePermission; % self.itsDefineMode = 'data'; % [ndims, nvars, ngatts, theRecdimid, status] = ... % ncmex('inquire', ncid(self)); % if status >= 0, self = recdimid(self, theRecdimid); end % ncregister(self) % self = ncregister(self); %end % %result = self; % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "permission.m" (text)') fout = fopen('permission.m', 'w'); %function theResult = permission(self) % %% netcdf/permission -- Create/open permission of a netcdf file. %% permission(self) returns the "create/open" permission %% of self, a "netcdf" object. % %% 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 11-Aug-1997 10:43:29. % %if nargin < 1, help(mfilename), return, end % %self = ncregister(self); % %result = self.itsPermission; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "rec.m" (text)') fout = fopen('rec.m', 'w'); %function theResult = rec(self, theRecindices, theRecs) % %% netcdf/rec -- Record of a netcdf object. %% rec(self, theRecindices) returns a vector of structs %% whose field-names are the names of record-variables %% of self, a netcdf object. The field-values are the %% variable-data corresponding to each of theRecindices, %% which range from 1 to the number of records. %% rec(self, theRecindices, theRecs) puts the data from %% theRecs structs into corresponding theRecindices %% records of self, a netcdf object. Self is returned. %% rec(self) returns a single struct with zeroed fields. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theRecindices = 0; end % %if nargin < 3 % if isequal(theRecindices, 0) % theRecs = ncrec(self); % else % theVars = recvar(self); % theFieldvalues = cell(1, length(theVars)); % theFieldnames = cell(1, length(theVars)); % for j = 1:length(theRecindices) % for i = 1:length(theVars) % theFieldnames{i} = name(theVars{i}); % theFieldvalues{i} = []; % if theRecindices(j) > 0 % theFieldvalues{i} = theVars{i}(theRecindices(j)); % end % end % theRecs(j) = cell2struct(theFieldvalues, theFieldnames, 2); % end % end % result = theRecs; % else % f = fields(theRecs); % for j = 1:length(theRecindices) % if theRecindices(j) > 0 % for i = 1:length(f) % s = ['self{''' f{i} '''}(' ... % int2str(theRecindices(j)) ')' ... % '=theRecs(' int2str(j) ').' f{i} ';']; % eval(s); % end % end % end % result = self; %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "recvar.m" (text)') fout = fopen('recvar.m', 'w'); %function theResult = recvar(self) % %% netcdf/recvar -- Record-variables of a netcdf object. %% recvar(self) returns a cell-list of the ncvar objects %% that correspond to the record-variables of self, a %% "netcdf" object. A record-variable is one whose leftmost %% dimension is the recdim(self). % %% 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-Aug-1997 09:29:39. % %if nargin < 1, help(mfilename), return, end % %result = []; %if nargout > 0, theResult = result; end % %theRecdim = recdim(self); %if isempty(theRecdim), return, end % %theRecdimid = dimid(theRecdim); % %theVars = var(self); %for i = length(theVars):-1:1 % theDims = dim(theVars{i}); % if length(theDims) < 1 | ... % dimid(theDims{1}) ~= theRecdimid % theVars(i) = []; % end %end % %result = theVars; % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "redef.m" (text)') fout = fopen('redef.m', 'w'); %function theResult = redef(self, theDefineMode) % %% netcdf/redef -- Set the NetCDF "define mode". %% redef(self) enables the "define" mode of the NetCDF %% file associated with self, a netcdf object. Use %% endef(self) to revert to 'data' mode. Self is %% returned, with 'itsDefineMode' set to 'define'. %% redef(self, theDefineMode) sets the "define" mode of %% the file to theDefineMode ('define' or 'data') and %% returns self. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 09:30:58. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2, theDefineMode = 'define'; end % %self = ncregister(self); % %switch theDefineMode %case 'define' % status = ncmex('redef', ncid(self)); % self.itsDefineMode = theDefineMode; %case 'data' % status = ncmex('endef', ncid(self)); % self.itsDefineMode = theDefineMode; %otherwise %end % %ncregister(self) %result = ncregister(self); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "setfill.m" (text)') fout = fopen('setfill.m', 'w'); %function theResult = setfill(self, theFillMode) % %% netcdf/setfill -- Set the NetCDF fill-mode. %% setfill(self, theFillMode) sets the fill-mode of the %% NetCDF file represented by self, a "netcdf" object. %% The modes are 'fill' [default] or 'nofill'. % %% 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 02-Sep-1997 11:08:44. % %if nargin < 1, help(mfilename), return, end % %self = ncregister(self); % %if nargout > 0 & nargin < 2 % theResult = self.itsFillMode; % return %end % %if nargin < 2, theFillMode = 'fill'; end % %result = []; % %switch theFillMode %case 0 % theFillMode = 'nofill'; %case 1 % theFillMode = 'fill'; %end % %result = ncmex('setfill', ncid(self), theFillMode); %if result >= 0, self.itsFillMode = theFillMode; end % %ncregister(self) % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "subsasgn.m" (text)') fout = fopen('subsasgn.m', 'w'); %function theResult = subsasgn(self, theStruct, other) % %% netcdf/subsasgn -- Assignment with "{}", "()", and ".". %% subsasgn(self, theStruct, other) is called whenever %% self is used with subindexing on the left-side of %% an assignment, as in self{...} = other, for %% self, a "netcdf" object. % %% Also see: netcdf/subsref. % %if nargin < 1, help(mfilename), return, end % %if length(theStruct) < 1 % result = other; % if nargout > 1 % theResult = result; % else % disp(result) % end % return %end % %result = []; % %self = ncregister(self); % %if length(theStruct) < 1 % result = other; % if nargout > 0, theResult = result; end % return %end % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %theAutoscaleflag = 0; %if isa(theSubs, 'cell') % if length(theSubs) > 1 % theAutoscaleflag = isequal(theSubs{2}, 1); % end % theSubs = theSubs{1}; %end % %switch theType %case '{}' % Variable by name or index: self(theVarindex)...(...). % theVarname = theSubs; % if length(s) < 1 & ... % (isa(other, 'cell') | isa(other, 'char') | isa(other, 'double')) % if ~isempty(other) % if isa(other, 'char'), other = {other}; end % switch other{1} % case {'byte', 'char', 'short', 'int', 'long', 'float', 'double'} % % Okay as is. % otherwise % other = [{'double'} other(:).']; % end % theVartype = other{1}; % theVardims = other; % theVardims(1) = []; % result = ncvar(theVarname, theVartype, theVardims, self); % if ~isempty(result) % result = autoscale(result, theAutoscaleflag); % end % result = self; % else % theVar = ncvar(theVarname, self); % if ~isempty(theVar) % result = delete(theVar); % Delete. % end % end % result = self; % elseif isa(other, 'ncvar') & ncid(other) < 0 % other = name(other, theVarname); % result = (self < other); % result = self; % else % v = var(self, theVarname); % if ~isempty(v) % v = autoscale(v, theAutoscaleflag); % end % result = subsasgn(v, s, other); % result = self; % end %case '()' % Record by index 1..nrecs: self(theRecindex). % switch ncclass(theSubs) % case 'char' % Dimension by name: self('theDimname'). % theDimname = theSubs; % if ~isempty(other) % result = ncdim(theDimname, other, self); % else % theDim = ncdim(theDimname, self); % result = delete(theDim); % end % result = self; % case 'double' % Record by index 1..nrecs: self(theRecindex). % theRecindices = theSubs; % result = rec(self, theRecindices, other, theAutoscaleflag); % result = self; % otherwise % warning(' ## Illegal syntax.') % end %case '.' % Global attribute by index: self.theAttname(...). % theAttname = theSubs; % while length(s) > 0 % Dotted name. % switch s(1).type % case '.' % theAttname = [theAttname '.' s(1).subs]; % s(1) = []; % otherwise % break % end % end % if length(s) < 1 & isa(other, 'cell') & length(other) == 2 % theAtttype = other{1}; % theAttvalue = other{2}; % result = ncatt(theAttname, theAtttype, theAttvalue, self); % elseif length(s) < 1 % if ~isempty(other) % result = ncatt(theAttname, ncclass(other), other, self); % else % theAtt = ncatt(theAttname, self); % if ~isempty(theAtt) % result = delete(theAtt); % Delete. % end % end % else % result = subsasgn(att(self, theAttname), s, other); % end % result = self; %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "subsref.m" (text)') fout = fopen('subsref.m', 'w'); %function theResult = subsref(self, theStruct) % %% netcdf/subsref -- Overloaded "{}", "()", and "." operators. %% subsref(self, theStruct) processes subscripting references %% of self, a "netcdf" object, as follows: %% If the first operator, contained in theStruct(1).type, %% is '{}', as in {'theVarname'} or {theVarindex}, the rest %% of theStruct is passed to the subsref function of the %% corresponding ncvar object managed by self. %% If the first operator is '()', as in ('theDimname'), the %% corresponding named ncdim object of self is processed. %% If the first operator is '.', as in .theAttname, the %% corresponding named global attribute object of self is %% processed. % %% Also see: netcdf/subsasgn. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Aug-1997 09:32:06. % %if nargin < 1, help(mfilename), return, end % %result = []; % %self = ncregister(self); % %s = theStruct; %theType = s(1).type; %theSubs = s(1).subs; %s(1) = []; % %theAutoscaleflag = 0; %if isa(theSubs, 'cell') % if length(theSubs) > 1 % theAutoscaleflag = isequal(theSubs{2}, 1); % end % theSubs = theSubs{1}; %end % %switch theType %case '{}' % Variable by name or index. % switch class(theSubs) % case 'char' % Variable by name: self{'theVarname'}. % theVarname = theSubs; % result = var(self, theVarname); % if ~isempty(result) % result = autoscale(result, theAutoscaleflag); % result = subsref(result, s); % end % case 'double' % Variable by index 1..nvars: self{theVarindex}. % theVarindex = theSubs; % result = var(self, theVarindex); % if ~isempty(result) % result = autoscale(result, theAutoscaleflag); % result = subsref(result, s); % end % otherwise % warning(' ## Illegal syntax.') % end %case '()' % Dimension by name; record by index. % switch class(theSubs) % case 'char' % Dimension by name: self('theDimname'). % theDimname = theSubs; % result = dim(self, theDimname); % if ~isempty(result), result = subsref(result, s); end % case 'double' % Record by index 1..nrecs: self(theRecindex). % theRecindex = theSubs; % result = rec(self, theRecindex); % otherwise % warning(' ## Illegal syntax.') % end %case '.' % Global attribute by name: self.theAttname(...) % theAttname = theSubs; % while length(s) > 0 % Dotted name. % switch s(1).type % case '.' % theAttname = [theAttname '.' s(1).subs]; % s(1) = []; % otherwise % break % end % end % result = att(self, theAttname); % if ~isempty(result), result = subsref(result, s); end %otherwise % warning([' ## Illegal syntax: "' theType '"']) %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "sync.m" (text)') fout = fopen('sync.m', 'w'); %function theResult = sync(self) % %% netcdf/sync -- Synchronize the NetCDF file. %% sync(self) synchronizes the NetCDF file %% represented by self, a netcdf object. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %status = ncmex('sync', ncid(self)); % %result = self; % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "var.m" (text)') fout = fopen('var.m', 'w'); %function theResult = var(self, theName, theType, theDims) % %% netcdf/var -- Variables of a netcdf object. %% var(self) returns the cell-list of ncvar objects %% associated with self, a netcdf object. %% var(self, 'theName') returns the ncvar object whose %% name is theName, associated with self, a netcdf object. %% var(self, 'theName', 'theType', {theDims}) defines a %% new NetCDF variable in self, with theName, theType %% (default = 'double'), and theDims (a cell-list of %% ncdim objects, possibly empty). The new ncvar object %% 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 07-Aug-1997 09:33:06. % %if nargin < 1, help(mfilename), return, end % %result = []; % %switch nargin % case 1 % [ndims, nvars, ngatts, recdim, status] = ... % ncmex('inquire', ncid(self)); % theVars = cell(1, nvars); % for theVarindex = 1:nvars % theVars{theVarindex} = ncvar(theVarindex, self); % end % result = theVars; % case 2 % result = ncvar(theName, self); % case 4 % result = ncvar(theName, theType, theDims, self); % otherwise % warning(' ## Illegal syntax.') %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "version.m" (text)') fout = fopen('version.m', 'w'); %function version(self) % %% Version of 30-Apr-2003 11:16:19. % %helpdlg(help(mfilename), 'netcdf') fclose(fout); disp(' ## Installing: "whos.m" (text)') fout = fopen('whos.m', 'w'); %function theResult = whos(self) % %% netcdf/whos -- WHOS for a NetCDF file. %% whos(self) returns a Matlab WHOS structure %% for self, a "netcdf" object, containing %% information about all of its items. % %% 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-Sep-1999 18:28:31. %% Updated 10-Sep-1999 11:25:37. % %if nargout > 0, theResult = []; end %if nargin < 1, help(mfilename), return, end % %items = [att(self) dim(self)]; %v = var(self); %for k = 1:length(v) % items = [items v(k) att(v{k})]; %end % %byteLen = ncmex('typelen', 'byte'); %charLen = ncmex('typelen', 'char'); %shortLen = ncmex('typelen', 'short'); %longLen = ncmex('typelen', 'long'); %floatLen = ncmex('typelen', 'float'); %doubleLen = ncmex('typelen', 'double'); % %result = []; % %for k = length(items):-1:1 % it = items{k}; % theName = name(it); % theClass = class(it); % theDatatype = class(it); % theNCSize = ncsize(it); % theSize = size(it); % theDatatype = datatype(it); % theParent = name(parent(it)); % switch theDatatype % case 'byte' % theBytes = prod(theSize)*byteLen; % case 'char' % theBytes = prod(theSize)*charLen; % case 'short' % theBytes = prod(theSize)*shortLen; % case 'long' % theBytes = prod(theSize)*longLen; % case 'float' % theBytes = prod(theSize)*floatLen; % case 'double' % theBytes = prod(theSize)*doubleLen; % otherwise % theBytes = 0; % end % result(k).name = theName; % result(k).size = theSize; % result(k).bytes = theBytes; % result(k).class = theClass; % result(k).datatype = theDatatype; % result(k).ncsize = theNCSize; % result(k).parent = theParent; %end % %if nargout > 0 % theResult = result; %else % disp(result) % assignin('caller', 'ans', result) %end fclose(fout); cd ('..') bund_setdir('ncutility') 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: "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: "fcopy.m" (text)') fout = fopen('fcopy.m', 'w'); %function theResult = fcopy(theSource, theDestination, maxCharacters) % %% fcopy -- Copy (duplicate) a file. %% fcopy(theSource, theDestination, maxCharacters) copies the %% contents of theSource file into theDestination file, %% in increments of maxCharacters (default = 16K). Each %% file can be specified by its name or by an existing %% file-pointer. %% fcopy (no arguments) demonstrates itself by copying %% "fcopy.m" to "junk.junk". % %% 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 11-Jan-2000 21:24:20. %% Updated 11-Jan-2000 21:24:20. % %if nargin < 1 % help fcopy % fcopy('fcopy.m', 'junk.junk'); % return %end %if nargin < 2, return, end %if nargin < 3, maxCharacters = 1024 .* 16; end %if ischar(maxCharacters), maxCharacters = eval(maxCharacters); end % %if isstr(theSource) % src = fopen(theSource, 'r'); % if src < 0, error(' ## Source file not opened.'); end % else % src = theSource; %end % %if isstr(theDestination) % dst = fopen(theDestination, 'w'); % if dst < 0, error(' ## Destination file not opened.'); end % else % dst = theDestination; %end % %while (1) % [s, inputCount] = fread(src, [1 maxCharacters], 'char'); % if inputCount > 0, outputCount = fwrite(dst, s, 'char'); end % if inputCount < maxCharacters | outputCount < inputCount, break, end %end % %if isstr(theDestination), result = fclose(dst); end %if isstr(theSource), result = (fclose(src) | result); end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "filesafe.m" (text)') fout = fopen('filesafe.m', 'w'); %function theResult = filesafe(theFilename) % %% filesafe -- Adjust file-separation-characters. %% filesafe('theFilename') returns 'theFilename' with its %% file-separation-characters made compatible with the %% present computer. Useful for portability, such as %% when processing URL's. Not for VMS. % %% 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 11-Dec-1997 09:57:54. % %if nargin < 1, help(mfilename), return, end % %theSeparators = {'/', '\', ':'}; % %result = theFilename; %for i = 1:length(theSeparators) % result = strrep(result, theSeparators{i}, filesep); %end % %if nargout > 1 % theResult = result; %else % disp(result) %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: "getinfo.m" (text)') fout = fopen('getinfo.m', 'w'); %function [theResult, isOkay] = getinfo(theInfo, theField) % %% getinfo -- Get field value from an "Info" struct. %% getinfo(theInfo, 'theField') returns the current %% value of 'theField' in theInfo, a struct that %% is compatible with the "uigetinfo" function. %% Non-existent fields return the empty-matrix. %% [theResult, isOkay] = ... returns isOkay = 0 %% if an error occurred; otherwise, non-zero. %% getinfo(theInfo) returns a struct containing %% the fields and current selections of theInfo. % %% 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: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 fclose(fout); disp(' ## Installing: "geturl.m" (text)') fout = fopen('geturl.m', 'w'); %function theResult = geturl(theURL, theFilename) % %% geturl -- Get a URL. %% geturl('theURL', 'theFilename') calls Netscape to get %% 'theURL', saving it to 'theFilename'. If a wildcard %% filename is provided, the "uiputfile" dialog is invoked. %% If no path is given, the current directory is used. %% If no filename is given, or if it is '', the file is %% opened in an active Netscape window. This routine %% does not wait for the completion of the download. %% %% Note to users: The path to Netscape must be hardwired %% into the "geturl.mac" AppleScript, a text file that %% can be modified with the Matlab editor. % %% 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 10-Sep-1997 16:28:22. %% Updated 28-Mar-2000 14:38:07. % %if nargout > 0, theResult = []; end % %if nargin < 1 % help(mfilename) % return %end % %if ~any(findstr(computer, 'MAC')) & 0 % disp([' ## No action taken: "' mfilename '" requires Macintosh computer.']) % return %end % %if nargin < 2, theFilename = ''; end % %if ~isempty(theFilename) & any(theFilename == '*') % theFilename = 'unnamed'; % [theFile, thePath] = uiputfile(theFilename, 'Save File As'); % if any(theFile) % if thePath(end) ~= filesep % thePath(end+1) = filesep; % end % theFilename = [thePath theFile]; % disp([' ## Saving to "' theFilename '"']) % else % disp(' ## No action taken.') % return % end %end % %if ~isempty(theFilename) % if ~any(theFilename == filesep) % thePWD = pwd; % if thePWD(end) ~= filesep % thePWD(end+1) = filesep; % end % theFilename = [thePWD theFilename]; % end %end % %% Be sure the following is hardwired into "geturl.mac". %% Passing it in as an argument does not work (so far). % %theApplication = 'priapus:WWW:Internet:Netscape:Netscape'; % %% Quote the arguments. % %theAppleScript = 'geturl.mac'; % %result = 0; % %if isunix % result = feval('wget', theURL, theFilename); %elseif any(findstr(lower(computer), 'pcwin')) % disp(' ## "geturl" requires Macintosh or Unix presently.') %elseif any(findstr(lower(computer), 'mac')) % theURL = ['"' theURL '"']; % theFilename = ['"' theFilename '"']; % theApplication = ['"' theApplication '"']; % Not used. % result = feval('applescript', theAppleScript, ... % 'theURL', theURL, ... % 'theFilename', theFilename); % result = 1; %end % %result = any(result); % %% Display status, if any. % %if ~isempty(result) & 0 % disp([' ## ' mfilename ' status: ' int2str(result)]) %end % %result = logical(isempty(result)); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "geturl.mac" (text)') fout = fopen('geturl.mac', 'w'); %-- geturl Get and store a URL for Matlab %-- geturl theURL theFilename % %-- Version of long ago. %-- Updated 12-Oct-1999 22:30:05. % %-- The following does not work: % %-- set theApplication to "alba:WWW:Internet:Netscape:Netscape" %-- tell application theApplication % %-- So, use the full path to Netscape explicitly. % %tell application "alba:WWW:Internet:Netscape:Netscape" % if theFilename is "" then % activate % GetURL theURL % -- OpenURL theURL flags 1 % else % GetURL theURL to file theFilename % -- OpenURL theURL to file theFilename % -- OpenURL theURL to file theFilename flags 1 % close window 1 % end if %end tell fclose(fout); disp(' ## Installing: "guido.m" (text)') fout = fopen('guido.m', 'w'); %function theResult = guido(theStruct, theFigureName, isModal, thePrecision) % %% guido -- Get info via Matlab struct. %% guido('demo') demonstrates itself, using the commands %% given below. %% guido(theStruct, 'theFigureName') presents a dialog %% representing the fieldnames and values of theStruct, %% a Matlab "struct" which must be compatible with %% "getinfo" and "setinfo". If theStruct contains %% embedded structs, nested dialogs are produced for %% them as needed. The empty-matrix [] is returned %% if the main "Cancel" button is pressed. Also, use %% "Cancel" to escape a sub-dialog without saving its %% most recent changes. Fields named "help_..." are %% shown in a separate dialog. If theFigureName is %% not given or is empty, the external name of %% theStruct will be used. %% guido(theStruct, 'theFigureName', isModal) uses modal %% dialogs on non-PCWIN machines if "isModal" evaluates %% to logical(1) TRUE. The default is to use non-modal %% dialogs, which allows interactions with other windows, %% except the Matlab command window. In either case, the %% the routine prevents dialogs from being dismissed out %% of sequence. %% guido(theStruct, 'theFigureName', isModal, thePrecision) %% uses thePrecision (default = 4) when displaying numbers %% in an "edit" control. %% %% Commands used in the demonstration: %% %% s.help = help(mfilename); %% s.anEdit = 'some text'; %% s.aNumber = pi; %% s.aCheckbox = {'checkbox' 0}; %% s.aRadiobutton = {'radiobutton' 0}; %% s.aPopupmenu = {{'red', 'blue', 'green'}, 1}; %% s.aSubdialog.aPopupmenu = {{10 20 30}, 1}; %% guido(s, [mfilename ' demo']) % %% Note: the present m-file can be renamed without %% requiring any changes to the Matlab code 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 15-Dec-1999 13:39:54. %% Updated 25-Jan-2000 11:47:42. % %persistent CURRENT_STRUCT %persistent CURRENT_FIGURES % %LF = char(10); %CR = char(13); %CRLF = [CR LF]; %BABY_BLUE = [8 10 10]/10; % %if nargout > 0, theResult = []; end % %% Launch a demo if this is not a callback. % %if nargin < 1 & isempty(gcbo) % help(mfilename) % ans = feval(mfilename, 'demo'); % if nargout > 0 % theResult = CURRENT_STRUCT; % else % assignin('caller', 'ans', CURRENT_STRUCT) % end % return %end % %% Do the demo. % %if nargin > 0 & isequal(theStruct, 'demo') % if nargin < 2, theFigureName = [mfilename ' demo']; end % s = []; % s.help = help(mfilename); % s.anEdit = 'some text'; % s.aNumber = pi; % s.aCheckbox = {'checkbox' 0}; % s.aRadiobutton = {'radiobutton' 0}; % s.aPopupmenu = {{'red', 'blue', 'green'}, 1}; % s.aSubdialog.aPopupmenu = {{10 20 30}, 1}; %% s.aSubdialog.bSubdialog.bPopupmenu = {{100 200 300}, 1}; % disp(s) % % assign([mfilename '_demo'], s) % result = feval(mfilename, eval([mfilename '_demo']), '', 0); % assign([mfilename '_result'], result) % % if ~isempty(eval([mfilename '_result'])) % result = feval(mfilename, eval([mfilename '_result']), '', 0); % assign([mfilename '_result'], result) % end % if nargout > 0 % assign('theResult', [mfilename '_result']) % end % return %end % %if nargin > 0 & ischar(theStruct) % theCommand = lower(theStruct); %end % %if 0 & nargin > 0 & ischar(theStruct) % switch theCommand % case '_keypress_' % theKey = get(gcbf, 'CurrentCharacter'); % if any(abs(theKey) < 32) % theCommand = '_okay_'; % end % end %end % %% Dismiss dialogs in sequence. % %if nargin > 0 & ischar(theStruct) % switch theCommand % case {'_okay_', '_cancel_'} % CURRENT_FIGURES(~ishandle(CURRENT_FIGURES)) = []; % if ~isempty(CURRENT_FIGURES) & gcbf ~= CURRENT_FIGURES(end) % figure(CURRENT_FIGURES(end)) % h = helpdlg('Dismiss dialogs in sequence.', 'Please...'); % tic % while ishandle(h) & toc < 3 % drawnow % end % if ishandle(h), delete(h), end % return % end % end %end % %% Process a command: okay or cancel. % %if nargin > 0 & ischar(theStruct) % switch theCommand % case '_okay_' % CURRENT_STRUCT = get(gcbf, 'UserData'); % theControls = findobj(gcbf, 'Type', 'uicontrol', 'Tag', mfilename); % theControls = sort(theControls); % for i = 2:2:length(theControls) % theField = get(theControls(i-1), 'String'); % theControl = theControls(i); % theStyle = get(theControl, 'Style'); % switch theStyle % case 'pushbutton' % okay = 0; % case 'checkbox' % theValue = get(theControl, 'Value'); % okay = 1; % case 'radiobutton' % theValue = get(theControl, 'Value'); % okay = 1; % case 'edit' % if isequal(theField, 'help') % okay = 0; % else % theValue = eval(get(theControl, 'String')); % okay = 1; % end % case 'popupmenu' % theValue = get(theControl, 'Value'); % okay = 1; % otherwise % okay = 0; % warning([' ## Unsupported control style: ' theStyle]) % end % if okay % CURRENT_STRUCT = setinfo(CURRENT_STRUCT, theField, theValue); % end % end % if ~isempty(CURRENT_FIGURES) & any(CURRENT_FIGURES == gcbf) % CURRENT_FIGURES(CURRENT_FIGURES == gcbf) = []; % end % delete(gcbf) % case '_cancel_' % CURRENT_STRUCT = []; % if ~isempty(CURRENT_FIGURES) & any(CURRENT_FIGURES == gcbf) % CURRENT_FIGURES(CURRENT_FIGURES == gcbf) = []; % end % delete(gcbf) % otherwise % disp([' ## Unknown command: ' theCommand]) % end % return %end % %% Build the dialog if it does not already exist. % %if nargin > 0 & isstruct(theStruct) % theStruct = setinfo(theStruct); % if nargin < 2 | isempty(theFigureName) % theFigureName = inputname(1); % if isempty(theFigureName) % theFigureName = 'unnamed'; % end % end % if isempty(theFigureName), theFigureName = mfilename; end % % f = findobj('Type', 'figure', 'Name', theFigureName, 'Tag', mfilename); % if any(f) % figure(f) % return % end % % if nargin < 3, isModal = 0; end % if nargin < 4, thePrecision = 4; end % % if all(isModal(:)) & ~any(findstr(computer, 'PCWIN')) % theWindowStyle = 'modal'; % else % theWindowStyle = 'normal'; % end % theFigures = findobj('Type', 'figure', 'Tag', mfilename); % theFigure = figure( ... % 'Name', theFigureName, ... % 'WindowStyle', theWindowStyle, ... % 'Visible', 'off', ... % 'KeyPressFcn', [mfilename ' _keypress_'], ... % 'CloseRequestFcn', [mfilename ' _cancel_'], ... % 'Tag', mfilename); % if any(theFigures) % pos = get(theFigures(1), 'Position'); % left = pos(1); % top = pos(2) + pos(4); % for i = 2:length(theFigures) % p = get(theFigures(i), 'Position'); % left = max(pos(1), p(1)); % top = min(top, p(2) + p(4)); % end % thePosition = get(theFigure, 'Position'); % thePosition(1) = left + 20; % thePosition(2) = top - thePosition(4) - 20; % set(theFigure, 'Position', thePosition) % end % theFrame = uicontrol( ... % 'Style', 'frame', ... % 'Units', 'normalized', ... % 'Position', [0 0 1 1], ... % 'BackgroundColor', BABY_BLUE); % theControls = []; % theStruct = setinfo(theStruct); % Canonical form. % theFields = fieldnames(theStruct); % for i = 1:length(theFields) % theField = theFields{i}; % theValue = getfield(theStruct, theField); % switch class(theValue) % case 'cell' % switch class(theValue{1}) % case 'cell' % if length(theValue) > 1 % theSetting = theValue{2}; % else % theSetting = 1; % theValue = {theValue, theSetting}; % theStruct = setfield(theStruct, theField, theValue); % end % theStyle = 'popupmenu'; % case 'char' % switch theValue{1} % case 'checkbox' % theStyle = 'checkbox'; % if length(theValue) > 1 % theSetting = theValue{2}; % else % theSetting = 0; % end % case 'radiobutton' % theStyle = 'radiobutton'; % if length(theValue) > 1 % theSetting = theValue{2}; % else % theSetting = 0; % end % otherwise % error([' ## Incompatible control style: ' theValue{1}]) % end % end % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', theStyle, ... % 'String', theValue{1}, ... % 'Value', theSetting); % case 'char' % f = findstr(theField, 'help_'); % if ~any(f) | f(1) ~= 1 % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'edit', ... % 'Max', 1000, ... % 'String', ['''' theValue '''']); % else % theHintName = [theField ' ' theFigureName]; % theCallback = ... % ['hint(get(gcbo, ''UserData''), ''' theHintName ''')']; % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'Callback', theCallback, ... % 'UserData', theValue, ... % 'String', 'Help...'); % end % case 'double' % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'edit', ... % 'Max', 1000, ... % 'String', mat2str(theValue, thePrecision)); % case 'struct' % theCallback = ... % [mfilename '(get(gcbo, ''UserData''), ''' theField ''')']; % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'String', 'More...', ... % 'Callback', theCallback, ... % 'UserData', theValue); % otherwise % disp(class(theValue)) % error([' ## Incompatible data type. ' class(theValue)]) % end % end % set(theControls(1:2:end), ... % 'HorizontalAlignment', 'right', ... % 'BackgroundColor', BABY_BLUE) % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'String', 'Cancel', ... % 'BackgroundColor', [10 2 2]/10, ... % 'Callback', [mfilename ' _cancel_']); % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'String', 'Okay', ... % 'BackgroundColor', [2 10 2]/10, ... % 'Callback', [mfilename ' _okay_']); % set(theControls, 'Tag', mfilename) % theLayout = []; % for i = 1:length(theControls)/2 % theLayout = [(1:2:length(theControls)); % (2:2:length(theControls))].'; % end % theLayout = theLayout(:, [1 2 2]); % uilayout(theControls, theLayout, [1 1 18 18]/20) % pos = get(0, 'DefaultUIControlPosition'); % width = pos(3) * 6; % height = 0.5 * length(theControls) * pos(4) * 20 / 15; % thePosition = get(theFigure, 'Position'); % thePosition(2) = thePosition(2) + thePosition(4) - height; % thePosition(3) = width; % thePosition(4) = height; % set(theFigure, 'Position', thePosition, 'Visible', 'on', ... % 'UserData', theStruct) % if any(CURRENT_FIGURES) % CURRENT_FIGURES(~ishandle(CURRENT_FIGURES)) = []; % end % CURRENT_FIGURES(end+1) = theFigure; % %% Wait here for the new figure to be deleted. By then, it will %% already have placed its contents in the persistent CURRENT_STRUCT %% item. % % waitfor(theFigure) % %% Now get the new info from CURRENT_STRUCT and update. % % theNewStruct = CURRENT_STRUCT; % % theFieldName = theFigureName; % % if length(theFigures) < 1 % theStruct = theNewStruct; % else % theFigure = gcf; % theStruct = get(theFigure, 'UserData'); % if ~isfield(theStruct, theFieldName) & ~isequal(theField, 'help') % disp([' ## No such field: ' theField]) % elseif ~isempty(theNewStruct) % theStruct = setfield(theStruct, theFieldName, theNewStruct); % set(theFigure, 'UserData', theStruct) % f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', mfilename); % f = sort(f); % for i = 2:2:length(f) % theField = get(f(i-1), 'String'); % if isequal(theField, theFieldName) % set(f(i), 'UserData', theNewStruct) % break % end % end % end % end % % if nargout > 0 % theResult = theStruct; % else % assignin('caller', 'ans', theStruct); % end % %end % %% ---------- assign ----------% % %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 % %% ---------- getinfo ----------% % %function [theResult, isOkay] = getinfo(theInfo, theField) % %% getinfo -- Get field value from an "Info" struct. %% getinfo(theInfo, 'theField') returns the current %% value of 'theField' in theInfo, a struct that %% is compatible with the "uigetinfo" function. %% Non-existent fields return the empty-matrix. %% [theResult, isOkay] = ... returns isOkay = 0 %% if an error occurred; otherwise, non-zero. %% getinfo(theInfo) returns a struct containing %% the fields and current selections of theInfo. % %% 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: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 fclose(fout); disp(' ## Installing: "idle.m" (text)') fout = fopen('idle.m', 'w'); %function Idle(theFigure) % %% Idle -- Set the arrow-cursor. %% Idle(theFigure) sets the arrow-cursor in theFigure. %% The companion routine is "Busy". % %% 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', 'arrow'); fclose(fout); disp(' ## Installing: "labelsafe.m" (text)') fout = fopen('labelsafe.m', 'w'); %function theResult = LabelSafe(theLabel) % %% LabelSafe -- Safe label for axes. %% LabelSafe('theLabel') modifies 'theLabel' by %% "escaping" instances of '\', '_', and '\^', %% after removing all instances of char(0) and '\0'. %% Existing escapes remain intact. The result is %% suitable as a title or axis label on a graph. %% LabelSafe (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 01-Aug-1997 14:37:55. %% Version of 17-Nov-1997 13:35:12. % %if nargin < 1 % help(mfilename) % label = '\0_hello\world^'; % result = labelsafe(label); % begets(mfilename, 1, label, result) % return %end % %result = theLabel; % %if ~isempty(result) % result = strrep(result, char(0), ''); % result = strrep(result, '\0', ''); % % result = strrep(result, '\\', char(1)); % result = strrep(result, '\_', char(2)); % result = strrep(result, '\^', char(3)); % % result = strrep(result, '\', '\\'); % result = strrep(result, '_', '\_'); % result = strrep(result, '^', '\^'); % % result = strrep(result, char(1), '\\'); % result = strrep(result, char(2), '\_'); % result = strrep(result, char(3), '\^'); %end % %if ~isempty(result) % f = find(result ~= ' '); % if any(f) % result = result(f(1):f(length(f))); % end %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "maprect.m" (text)') fout = fopen('maprect.m', 'w'); %function rect4 = MapRect(rect1, rect2, rect3) % %% MapRect -- Map rectangles. %% MapRect(rect1, rect2, rect3) returns the rectangle %% that is to rect3 what rect1 is to rect2. Each %% rectangle is given as [x1 y1 x2 y2]. %% MapRect('demo') demonstrates itself by showing %% that maprect(r1, r2, r1) ==> r2. % %% 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 19-Jun-1997 08:33:39. % %if nargin < 1, help(mfilename), rect1 = 'demo'; end % %if strcmp(rect1, 'demo') % rect1 = [0 0 3 3]; % rect2 = [1 1 2 2]; % rect3 = rect1; % r4 = maprect(rect1, rect2, rect3); % begets('MapRect', 3, rect1, rect2, rect3, r4) % return %end % %if nargin < 3, help(mfilename), return, end % %r4 = zeros(1, 4); %i = [1 3]; %for k = 1:2 % r4(i) = polyval(polyfit(rect1(i), rect2(i), 1), rect3(i)); % i = i + 1; %end % %if nargout > 0 % rect4 = r4; % else % disp(r4) %end fclose(fout); disp(' ## Installing: "mapsubs.m" (text)') fout = fopen('mapsubs.m', 'w'); %function [from, to] = mapsubs(src, dst, subs) % %% mapsubs -- Map subscripts. %% [from, to] = mapsubs(src, dst, subs) works as follows: %% indices {src} map exactly to indices {dst}. We return %% two sets of indices that allow a source array x to be %% sampled at positions corresponding to the subscripts %% {subs} of a destination array y, that is, y(subs{:}). %% The input arguments are expected to be cell-arrays, %% all of the same length, that contain vectors of %% numerical subscripting indices. The results include %% only those {subs} that lie within the bounds of the %% actual {src} and {dst} mappings. None of the indices %% need be monotonic or equally-spaced. %% %% Example: src = [ 1 3 5 7 9]; %% dst = [11 12 13 14 15]; %% subs = [10 12 14 16 18 20 22 24]; %% %% Results: from = [ 3 7]; %% to = [12 14]; %% %% Usage: y(to{:}) = x(from{:}); % %% 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 04-Oct-2001 10:41:27. %% Updated 04-Oct-2001 11:43:03. % %if nargin < 3, help(mfilename), return, end % %% Convert to cells. % %if ~iscell(src), src = {src}; end %if ~iscell(dst), dst = {dst}; end %if ~iscell(subs), subs = {subs}; end % %% Extend if some too short. % %len = max([length(src) length(dst) length(subs)]); % %while length(src) < len, src{end+1} = 1; end %while length(dst) < len, dst{end+1} = 1; end %while length(subs) < len, subs{end+1} = 1; end % %% Allocate result. % %from = cell(size(src)); %to = cell(size(dst)); % %% Perform the mapping, using "ismember". % %bad_from = ~~0; %bad_to = ~~0; % %for i = 1:length(src) % from{i} = src{i}(ismember(dst{i}, subs{i})); % to{i} = subs{i}(ismember(subs{i}, dst{i})); % if isempty(from{i}), bad_from = ~~1; end % if isempty(to{i}), bad_to = ~~1; end %end % %if bad_from, from = {}; end %if bad_to, to = {}; end fclose(fout); disp(' ## Installing: "mat2nc.m" (text)') fout = fopen('mat2nc.m', 'w'); %function theResult = mat2nc(theMatFile, theNetCDFFile, uniqueDims, noSqueeze) % %% mat2nc -- Convert Matlab Mat-file to NetCDF file. %% mat2nc('theMatFile', 'theNetCDFFile') converts the %% "double", "char", and "uint8" components of 'theMatFile' %% to dimensioned variables in 'theNetCDFFile'. Items embedded %% in "struct" and "cell" objects are named with the appropriate %% Matlab subscripting operators. Empty entities are stored as %% NetCDF scalars. Each item can be reconstituted by assigning %% its contents to its "original_name", an attribute. %% Filenames are entered via dialog if not provided as input %% arguments, or if provided as empty strings. The mat-file %% name can be wild-carded with '*'. %% If an output argument is given, the "netcdf" object is %% returned and the NetCDF file itself remains open. The %% "uniqueDims" argument defaults to 0 (FALSE), which means %% that only enough NetCDF dimensions to meet the minimal needs %% of the data will be generated. If non-zero (TRUE), then %% each variable will be given unique NetCDF dimensions. %% (Note: the typical NetCDF file allows up to 100 dimensions.) %% mat2nc(theMatFile, theNetCDFFile, uniqueDims, noSqueeze) %% defines unique dimensions to each variable if uniqueDims is %% logically TRUE; otherwise, dimensions of the same size are %% recycled. If noSqueeze is logically TRUE, all singleton %% dimensions are left intact; otherwise, they are squeezed %% out before storage, except that scalar values are given %% a single dimension of 1. % %% 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-May-1998 20:44:58. % Original. %% Updated 02-Jun-1998 14:33:02. % Dimensions recycled. %% Updated 16-Jul-1998 06:25:54. % Singletons squeezed. %% Updated 09-Apr-2003 10:47:45. % %TESTING = 0; % %if nargout > 0, theResult = []; end % %% Get the file names if not provided. % %if nargin < 1, theMatFile = ''; end %if nargin < 2, theNetCDFFile = ''; end %if nargin < 3, uniqueDims = 0; end %if nargin < 4, noSqueeze = 0; end % %if ischar(uniqueDims), uniqueDims = eval(uniqueDims); end %if ischar(noSqueeze), noSqueeze = eval(noSqueeze); end % %uniqueDims = any(uniqueDims); %noSqueeze = any(noSqueeze); % %if isempty(theMatFile), theMatFile = '*'; end % %if any(theMatFile == '*') % help(mfilename) % [theFile, thePath] = uigetfile(theMatFile, 'Select A Mat-File:'); % if ~any(theFile) % disp(' ## No Mat-file selected.') % return % end % theMatFile = [thePath theFile]; %end % %theSuggested = theMatFile; %f = find(theSuggested == '.'); %if any(f) % theSuggested(f(1):length(theSuggested)) = ''; %end %f = find(theSuggested == filesep); %if any(f) % theSuggested(1:f(length(f))) = ''; %end %theSuggested = [theSuggested '.nc']; % %if isempty(theNetCDFFile) % [theFile, thePath] = uiputfile(theSuggested, 'Save As NetCDF File:'); % if ~any(theFile) % disp(' ## No NetCDF file selected.') % return % end % theNetCDFFile = [thePath theFile]; %end % %% Save the "base" workspace, then load the Mat-file %% into it, in order to avoid name collisions with %% the present routine. We do this first to make %% sure that enough memory is available, before %% proceeding with the NetCDF allocations. The %% "base" workspace is restored at the end. % %theTempFile = 'mat2nc_temp.mat'; %evalin('base', ['save ' theTempFile]) %evalin('base', 'clear variables') %evalin('base', ['load ' theMatFile]) % %% Create the output NetCDF file. % %nc = netcdf(theNetCDFFile, 'clobber'); %if isempty(nc) % disp([' ## Unable to create NetCDF file: ' theNetCDFFile]) % return %end % %nc.CreationDate = datestr(now); %nc.CreatedBy = which(mfilename); %nc.CreatedFrom = which(theMatFile); % %% Get the Mat-file directory. % %w = whos('-file', theMatFile); % %% Expand the directory for "struct" and "cell" data. % %k = 0; %while k < length(w) % k = k + 1; % switch w(k).class % case {'struct', 'cell'} % x = evalin('base', w(k).name); % f = partnames(x, w(k).name); % j = length(w); % len = length(f); % w(j+len) = w(j); % Lengthen. % for i = 1:length(f) % a = evalin('base', f{i}); % j = j + 1; % w(j).name = f{i}; % w(j).size = size(a); % w(j).class = class(a); % end % end %end % %% Cull the "struct" and "cell" entries. % %for k = length(w):-1:1 % switch lower(w(k).class) % case {'struct', 'cell'} % w(k) = []; % end %end % %% Define the NetCDF dimensions. %% If "uniqueDims" is TRUE, we provide unique %% dimensions for each variable. If "noSqueeze" %% is TRUE, we leave all singleton dimensions %% intact. % %theVars = []; %theDimCount = 0; %for j = 1:length(w) % theVars(j).name = w(j).name; % theVars(j).class = w(j).class; % theDims = {}; % theSize = w(j).size; % f = find(theSize == 1); % if ~noSqueeze % Squeeze. % if any(f), theSize(f) = []; end % if isempty(theSize), theSize = 1; end % end % if prod(theSize) > 0 % for i = 1:length(theSize) % theDimCount = theDimCount+1; % if uniqueDims % Unique dimensions. % theDimName = ['dim_' int2str(theDimCount)]; % else % theDimName = ['dim_' int2str(theSize(i))]; % end % if isempty(nc(theDimName)) % nc(theDimName) = theSize(i); % end % theDim = nc(theDimName); % if isempty(theDim) % disp([' ## Dimension not defined: ' theDimName]) % end % theDims{i} = theDim; % end % end % theVars(j).size = theSize; % theVars(j).dims = theDims; % theVars(j).var = []; %end % %if (TESTING), nc = redef(sync(endef(nc))); end % %% Define the NetCDF variables. % %if (TESTING), theVars = theVars(1:min(length(theVars),24)); end % %for j = 1:length(theVars) % theDims = theVars(j).dims; % if ~isempty(theDims) | 1 % theDimNames = ncnames(theDims); % theVar = []; % theVarName = ncnamesafe(theVars(j).name); % switch theVars(j).class % case 'char' % nc{theVarName} = ncchar(theDimNames{:}); % theVar = nc{theVarName}; % case 'double' % nc{theVarName} = ncdouble(theDimNames{:}); % theVar = nc{theVarName}; % case 'uint8' % nc{theVarName} = ncbyte(theDimNames{:}); % theVar = nc{theVarName}; % otherwise % end % if isempty(theVar) % disp([' ## Variable not defined: ' theVarName]) % end % theVars(j).var = theVar; % if ~isempty(theVar) % theVar.original_name = theVars(j).name; % if isempty(size(theVar)) % theVar.isEmpty = 'item-is-empty'; % end % a = evalin('base', theVars(j).name, 'no-value-assigned'); % if isequal(a, 'no-value-assigned') % theVar.noValue = 'no-value-assigned'; % end % end % end %end % %if (TESTING), nc = sync(endef(nc)); end % %% Populate the NetCDF variables, checking for %% empty items and those with no assigned value. % %for j = 1:length(theVars) % theVar = theVars(j).var; % if ~isempty(theVar) % if isempty(size(theVar)) % theVar(:) = 0; % NetCDF requires a value. % else % a = evalin('base', theVars(j).name, 'no-value-assigned'); % if ~isequal(a, 'no-value-assigned') % try % theVar(:) = a; % catch % disp([' ## Unable to write data to: ' name(theVar)]) % disp([' ## ' lasterr]) % disp(' ') % end % end % end % end %end % %% Restore the "base" workspace. % %evalin('base', 'clear variables') %evalin('base', ['load ' theTempFile]) %delete(theTempFile) % %% Done. % %if nargout > 0 % theResult = nc; %else % close(nc) %end % %function theResult = ncnamesafe(theName) % %% ncnamesafe -- Name cleanup for NetCDF 3. %% ncnamesafe('theName') makes 'theName' %% safe for use as a NetCDF name. % %% 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 04-Aug-1998 10:51:31. % %TESTING = 0; % %c = '()[]{}'; % No longer allowed. % %if (TESTING), c = [c '.-']; end % %result = theName; %for i = 1:length(c) % result = strrep(result, c(i), '_'); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "mexcdf.m" (text)') fout = fopen('mexcdf.m', 'w'); %function [varargout] = mexcdf(varargin) % %% mexcdf -- Driver for Matlab-5/NetCDF C-Language interface. %% mexcdf('action', ...) performs the specified NetCDF action. %% When writing or reading a NetCDF variable, the dimensional %% sequence of the targetted Matlab array must be reversed, %% either BEFORE using 'varput' or 'varputg', or AFTER using %% 'varget' or 'vargetg'. This preserves the left-to-right %% dimensional arrangement that is defined by 'vardef' and %% retrieved by 'varinq'. Data output from a variable are %% returned as a Matlab matrix (two-dimensional), in keeping %% with the behavior of mexcdf under Matlab-4. The base-index %% for slabs is zero (0), and -1 can be used to specify the %% remaining count along any variable direction from the %% starting point. NOTE: a vector (an array with no more %% than one non-unity dimension) is always returned as %% a column, by mexcdf convention. %% %% To process multi-dimensional arrays under Matlab-5, %% use "ncmex", rather than "mexcdf". %% %% mexcdf('USAGE') %% [cdfid, rcode] = mexcdf('CREATE', 'path', cmode) %% cdfid = mexcdf('OPEN', 'path', mode) %% status = mexcdf('REDEF', cdfid) %% status = mexcdf('ENDEF', cdfid) %% [ndims, nvars, natts, recdim, status] = mexcdf('INQUIRE', cdfid) %% status = mexcdf('SYNC', cdfid) %% status = mexcdf('ABORT', cdfid) %% status = mexcdf('CLOSE', cdfid) %% %% status = mexcdf('DIMDEF', cdfid, 'name', length) %% [dimid, rcode] = mexcdf('DIMID', cdfid, 'name') %% ['name', length, status] = mexcdf('DIMINQ', cdfid, dimid) %% status = mexcdf('DIMRENAME', cdfid, 'name') %% %% status = mexcdf('VARDEF', cdfid, 'name', datatype, ndims, [dim]) %% [varid, rcode] = mexcdf('VARID', cdfid, 'name') %% ['name', datatype, ndims, [dim], natts, status] = mexcdf('VARINQ', cdfid, varid) %% status = mexcdf('VARPUT1', cdfid, varid, coords, value, autoscale) %% [value, status] = mexcdf('VARGET1', cdfid, varid, coords, autoscale) %% status = mexcdf('VARPUT', cdfid, varid, start, count, value, autoscale) %% [value, status] = mexcdf('VARGET', cdfid, varid, start, count, autoscale) %% status = mexcdf('VARPUTG', cdfid, varid, start, count, stride, [], value, autoscale) %% [value, status] = mexcdf('VARGETG', cdfid, varid, start, count, stride, [], autoscale) %% status = mexcdf('VARRENAME', cdfid, varid, 'name') %% %% status = mexcdf('ATTPUT', cdfid, varid, 'name', datatype, len, value) %% [datatype, len, status] = mexcdf('ATTINQ', cdfid, varid, 'name') %% [value, status] = mexcdf('ATTGET', cdfid, varid, 'name') %% status = mexcdf('ATTCOPY', incdf, invar, 'name', outcdf, outvar) %% ['name', status] = mexcdf('ATTNAME', cdfid, varid, attnum) %% status = mexcdf('ATTRENAME', cdfid, varid, 'name', 'newname') %% status = mexcdf('ATTDEL', cdfid, varid, 'name') %% %% status = mexcdf('RECPUT', cdfid, recnum, [data], autoscale, recdim) %% [[data], status] = mexcdf('RECGET', cdfid, recnum, autoscale, recdim) %% [[recvarids], [recsizes], status] = mexcdf('RECINQ', cdfid, recdim) %% %% len = mexcdf('TYPELEN', datatype) %% old_fillmode = mexcdf('SETFILL', cdfid, fillmode) %% %% old_ncopts = mexcdf('SETOPTS', ncopts) %% ncerr = mexcdf('ERR') %% code = mexcdf('PARAMETER', 'NC_...') %% %% Notes: %% 1. The rcode is always zero. %% 2. The dimid can be number or name. %% 3. The varid can be number or name. %% 4. The attname can be name or number. %% 5. The operation and parameter names are not case-sensitive. %% 6. The cmode defaults to 'NC_NOCLOBBER'. %% 7. The mode defaults to 'NC_NOWRITE'. %% 8. The value -1 determines length automatically. %% 9. The operation names can prepend 'nc'. %% 10. The parameter names can drop 'NC_' prefix. %% 11. Dimensions: Matlab (i, j, ...) <==> [..., j, i] NetCDF. %% 12. Indices and identifiers are zero-based. %% 13. One-dimensional slabs are returned as column-vectors. %% 14. Attributes are returned as row-vectors. %% 15. Scaling can be automated via 'scale_factor' and 'add_offset'. % %% Copyright (C) 1992-1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Version of 16-May-96 at 10:17:47.75. %% Version of 06-Jan-97 at 14:04:00. %% Version of 20-Mar-97 at 14:46:00. %% Version of 15-Jul-1997 07:52:23. %% Updated 07-Dec-2000 14:50:39. % %if nargin < 1, help(mfilename), return, end % %% Mex-file gateway. % %v = version; %if eval(v(1)) > 4 % fcn = 'mexcdf53'; % Matlab-5 or 6. %elseif eval(v(1)) == 4 % fcn = 'mexcdf4'; % Matlab-4 only. %else % error(' ## Unrecognized Matlab version.') %end % %% The "record" routines are emulated. % %op = lower(varargin{1}); %if any(findstr(op, 'rec')) % fcn = op; % if ~strcmp(fcn(1:2), 'nc') % fcn = ['nc' fcn]; % end % varargin{1} = []; %end % %% Matlab-5 comma-list syntax. % %if nargout > 0 % varargout = cell(1, nargout); % [varargout{:}] = feval(fcn, varargin{:}); %else % feval(fcn, varargin{:}); %end % %% Collapse to two-dimensions. % %if nargout > 0 % switch op % case {'varget', 'vargetg', 'ncvarget', 'ncvargetg'} % theSize = size(varargout{1}); % f = find(theSize > 1); % if ~any(f), f = 1; end % if length(theSize) > 1 % Always true in Matlab. % m = theSize(f(1)); % n = prod(theSize) ./ m; % if m == 1, m = n; n = 1; end % varargout{1} = reshape(varargout{1}, [m n]); % end % otherwise % end %end fclose(fout); disp(' ## Installing: "modplot.m" (text)') fout = fopen('modplot.m', 'w'); %function theResult = modplot(x, y, modulo, varargin) % %% modplot -- Plot with pen-up at modulo crossings. %% modplot(x, y, modulo, ...) plots y(x), modulo %% the given value. The pen is lifted at modulo %% crossings. %% modplot (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 24-Jul-1997 16:21:10. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if strcmp(x, 'demo'), x = 20; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % x = 0:n; % y = 360 .* rand(size(x)); % subplot(2, 1, 1) % plot(x, y, '-o') % axis([0 length(x) 0 360]) % subplot(2, 1, 2) % modplot(x, y, 360, '-o') % axis([0 length(x)-1 0 360]) % figure(gcf) % return %end % %if nargin < 3, modulo = 1; end % %% Find the crossings. % %f = find(abs(diff(y)) > modulo/2); % %px = x(f); py = y(f) + NaN; % %kk = [(1:length(x)).'; f(:)].'; %xx = [x(:); px(:)].'; %yy = [y(:); py(:)].'; % %[ignore, indices] = sort(kk); % Needs work. %xx = xx(indices); %yy = yy(indices); % %% Interleave NaN values at the crossings. % %% Plot the data. % %result = plot(xx, yy, varargin{:}); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "movie1.m" (text)') fout = fopen('movie1.m', 'w'); %function theResult = Movie1(x1, x2, x3, x4, x5) % %% Movie1 -- Show a movie. %% Movie1(...) uses the movie() syntax to show a movie. %% It avoids the unpleasant behavior of the Matlab movie() %% routine, which shows the film first during loading, then %% again at the requested speed, or as fast as possible, %% whichever is slower. %% Movie1(nFrames) demonstrates itself with nFrames (default = 16), %% at four frames per second. %% theResult = Movie1(nFrames) returns a demonstration movie %% of nFrames. To show theResult, use "movie1(theResult)". % %% 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-May-1997 10:24:44. %% Updated 09-Nov-1999 23:35:45. % %% Note: this routine needs to be updated %% to Matlab-5 syntax, using "varargin". % %if nargin < 1, help movie1, x1 = 16, end %if isstr(x1), x1 = eval(x1); end % %if nargin < 2 & length(x1) == 1 % help movie1 % nFrames = x1; % disp(' ## Create the movie.') % f = figure('Name', ['Movie1(' int2str(nFrames) ')']); % tic % theMovie = moviein(nFrames); % k = ceil(sqrt(nFrames)); % theFrame = zeros(k, k) + 24; % theImage = image(theFrame); % for j = 1:nFrames % theFrame = zeros(k, k) + 24; % theFrame(j) = 40; % set(theImage, 'CData', theFrame); % set(gca, 'Visible', 'off') % theText = text(1, 1, int2str(j), ... % 'HorizontalAlignment', 'center'); % theMovie(:, j) = getframe; % delete(theText) % end % toc % if nargout < 1 % disp(' ## Show the movie at 4 frames/second.') % t0 = clock; % speed = 4; % frames-per-second. % movie1(theMovie, 1, speed) % elapsed_time = etime(clock, t0); % average_frames_per_second = nFrames ./ elapsed_time % else % theResult = theMovie; % end % return %end % %theHandle = []; % %len = length(x1); %if len > 1 % theMovie = x1; % else % theHandle = x1; % theMovie = x2; %end % %nin = nargin; %if nargin < 3, x3 = 4; nin = nin+1; end %fps = x3; % %v = ''; %for i = 1:nargin % if i > 1, v = [v ' ,']; end % v = [v 'x' int2str(i)]; %end %v = ['movie(' v ')']; % %if isempty(theHandle), figure(gcf), end % %[m, nFrames] = size(theMovie); % %fps = x3; % Desired speed. %x3 = 1.5*x3; % First frame is usually slow. % %tic % Start the clock. %for j = 1:nFrames % if isempty(theHandle) % x1 = theMovie(:, j); % x2 = 1; % else % x2 = theMovie(:, j); % end % eval(v) % Show the frame. % t = toc; % Get elapsed time. % tic % Restart the clock. % speed = 1/t; %% disp(num2str(speed)) % x3 = x3 * fps / speed; % Adjust speed. %end fclose(fout); disp(' ## Installing: "nc2cdl.m" (text)') fout = fopen('nc2cdl.m', 'w'); %function nc2cdl(theNetCDFFile, theCDLFile, theDataFlag) % %% nc2cdl -- Translate NetCDF file to CDL notation. %% nc2cdl('theNetCDFFile', 'theCDLFile') translates %% 'theNetCDFFile' structure to CDL notation and %% writes it to 'theCDLFile', a new file. %% nc2cdl(..., ..., theDataFlag) includes the values %% of the NetCDF variables, if the given flag evaluates %% to TRUE. Default = FALSE. Scale-factors are not %% applied to the data values before translation. %% Single and double precision floating-point values %% are expressed with 7 and 15 significant digits, %% respectively. Strings are written as individual %% characters. % %% 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 21-Oct-2002 15:19:00. %% Updated 28-Oct-2002 09:52:32. % %if nargin < 1, help(mfilename), return, end %if nargin < 3, theDataFlag = ~~0; end %if ischar(theDataFlag) % theDataFlag = ~~eval(theDataFlag); %end % %CHUNKSIZE = 10; % Data chunk-size. % %CR = char(13); %LF = char(10); %CRLF = [CR LF]; % %if any(findstr(computer, 'MAC')) % NL = CR; %elseif ispc % NL = CRLF; %elseif isunix % NL = LF; %end % %TAB = ' '; % %% Open the NetCDF and CDL file. % %if ischar(theNetCDFFile) % nc = netcdf(theNetCDFFile, 'nowrite'); %elseif isa(theNetCDFFile, 'netcdf') % nc = theNetCDFFile; %end % %if isempty(nc) % disp(' ## Not a NetCDF File.') % return %end % %fout = fopen(theCDLFile, 'w'); %if fout < 0 % disp([' ## Unable to open outputfile: ' theCDLFile]) % return %end % %% CDL File Initialization. % %fprintf(fout, ['netcdf %s {' NL], name(nc)); % %fprintf(fout, ['// NetCDF translated to CDL on %s' NL], datestr(now)); % %fprintf(fout, ['// By "%s"' NL], which(mfilename)); % %% Global Attributes. % %fprintf(fout, ['// global attributes:' NL]); % %g = att(nc); % %for i = 1:length(g) % fprintf(fout, [TAB ':' name(g{i}) ' = ']); % x = g{i}(:); % if ischar(x) % fprintf(fout, ['"%s" ;' NL], x); % else % for k = 1:length(x) % if i > 1, fprintf(fout, ', '); end % fprintf(fout, num2str(x(k))); % end % fprintf(fout, [' ;' NL]); % end %end % %% Dimensions. % %fprintf(fout, ['dimensions:' NL]); % %d = dim(nc); %for i = 1:length(d) % len = length(d{i}); % if isrecdim(d{i}) % fprintf(fout, [TAB name(d{i}) ' = UNLIMITED ; // (' ... % num2str(len) ' currently)' NL]); % else % fprintf(fout, [TAB name(d{i}) ' = ' ... % num2str(len) ' ;' NL]); % end %end % %% Variables and Attributes. % %fprintf(fout, ['variables:' NL]); % %v = var(nc); %for i = 1:length(v) % fprintf(fout, [TAB datatype(v{i}) ' ' name(v{i}) '(']); % d = dim(v{i}); % for j = 1:length(d) % if j > 1, fprintf(fout, ', '); end % fprintf(fout, [name(d{j})]); % end % fprintf(fout, [') ;' NL]); % a = att(v{i}); % for j = 1:length(a) % fprintf(fout, [TAB TAB name(v{i}) ':' name(a{j}) ' = ']); % x = a{j}(:); % if ischar(x) % fprintf(fout, ['"%s" ;' NL], x); % else % for k = 1:length(x) % if k > 1, fprintf(fout, ', '); end % fprintf(fout, num2str(x(k))); % end % fprintf(fout, [' ;' NL]); % end % end %end % %% Data. % %if theDataFlag % fprintf(fout, ['data:' NL]); % for i = 1:length(v) % fprintf(fout, [TAB name(v{i}) ' = ' NL]); % x = v{i}(:); % theDataType = datatype(v{i}); % switch theDataType % case 'char' % CHUNK = CHUNKSIZE; % case 'float' % CHUNK = CHUNKSIZE; % case 'double' % CHUNK = ceil(CHUNKSIZE/2); % otherwise % CHUNK = CHUNKSIZE; % end % len = prod(size(x)); % for j = 1:len % if rem(j, CHUNK) == 1 % fprintf(fout, [TAB TAB]); % end % switch theDataType % case 'char' % fprintf(fout, [' ''%c'''], x(j)); % case 'float' % fprintf(fout, [' ' num2str(x(j), 7)]); % case 'double' % fprintf(fout, [' ' num2str(x(j), 15)]); % otherwise % fprintf(fout, [' ' int2str(x(j))]); % end % if j < len % fprintf(fout, ','); % else % fprintf(fout, ';'); % end % if j < len & rem(j, CHUNK) == 0 % fprintf(fout, NL); % end % end % fprintf(fout, NL); % end %end % %fprintf(fout, ['}' NL]); % %fclose(fout); % %if ischar(theNetCDFFile) % close(nc); %end fclose(fout); disp(' ## Installing: "nc2mat.m" (text)') fout = fopen('nc2mat.m', 'w'); %function nc2mat(theNetCDF, theMat) % %% nc2mat -- Convert NetCDF file to mat-file. %% nc2mat('theNetCDF', 'theMat') creates 'theMat' file %% from the contents of 'theNetCDF' file. Dimensions, %% variables, and attributes are named with prefixes %% of 'D_', 'V_', and 'A_', respectively. %% Global-attributes are prefixed by 'G'. Names %% that are not legal Matlab names are repaired with %% '_' (underscore) for each invalid character, then %% truncated to 31 characters. Repaired names are not %% checked for uniqueness. %% %% See "help whos" and "help load" for information %% about reading the contents of the mat-file. % %% 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 31-May-2001 14:07:35. %% Updated 31-May-2001 15:17:43. % %if nargin < 1, help(mfilename), theNetCDF = '*'; end %if nargin < 2, theMat = '*'; end % %if any(theNetCDF == '*') % [p, f] = uigetfile(theNetCDF, 'Select a NetCDF File'); % if ~any(f), return, end % if p(end) ~= filesep, p(end+1) = filesep; end % theNetCDF = [p f]; %end % %if any(theMat == '*') % [p, f] = uiputfile(theMat, 'Save As Mat File'); % if ~any(f), return, end % if p(end) ~= filesep, p(end+1) = filesep; end % theMat = [p f]; %end % %nc = netcdf(theNetCDF, 'nowrite'); %if isempty(nc), return, end % %Created_By = [mfilename '(''' theNetCDF ''', ''' theMat ''') % ' datestr(now)]; %save(theMat, 'Created_By') % %% Global attributes. % %gatts = att(nc); %for i = 1:length(gatts) % gattname = ['G_' name(gatts{i})]; % gattname = repair_matlab_name(gattname); % gattvalue = gatts{i}(:); % eval([gattname ' = gattvalue;']) % save(theMat, gattname, '-append') %end % %% Dimensions. % %dims = dim(nc); %for i = 1:length(dims) % dimname = name(dims{i}); % dimname = ['D_' dimname]; % dimname = repair_matlab_name(dimname); % dimlen = ncsize(dims{i}); % eval([dimname ' = dimlen;']) % save(theMat, dimname, '-append') % clear(dimname) %end % %% Variables and attributes. % %vars = var(nc); %for i = 1:length(vars) % varname = ['V_' name(vars{i})]; % varname = repair_matlab_name(varname); % atts = att(vars{i}); % for j = 1:length(atts) % attname = [varname '_A_' name(atts{j})]; % attname = repair_matlab_name(attname); % attvalue = atts{j}(:); % eval([attname ' = attvalue;']) % save(theMat, attname, '-append') % end % varvalue = vars{i}(:); % eval([varname ' = varvalue;']) % save(theMat, varname, '-append') %end % %nc = close(nc); % %disp(' ') %disp([' ## Contents of "' theMat '":']) %disp(' ') % %whos('-file', theMat) % %function y = repair_matlab_name(x, replacement) % %% repair_matlab_name -- Convert to valid Matlab name. %% repair_matlab_name('theName') converts 'theName' to %% a valid Matlab name by replacing invalid %% characters with '_' (underscore). Names %% are then truncated to 31 characters. %% repair_name('theName', 'c') uses 'c' as the %% replacement character. % %if nargin < 2, replacement = '_'; end % %f = (x == '_') | ... % (x >= 'A' & x <= 'Z') | ... % (x >= 'a' & x <= 'z') | ... % (x >= '0' & x <= '9'); % %if any(x(1) == ['_0123456789']) % f(1) = ~~0; %end % %y = x; % %if any(~f) % y(~f) = replacement; % if ~f(1), y = ['x' y]; end %end % %if length(y) > 31, y = y(1:31); end fclose(fout); disp(' ## Installing: "ncans.m" (text)') fout = fopen('ncans.m', 'w'); %function ncans(theAns, theName) % %% ncans -- Assign a value to base-workspace. %% ncans(theAns, 'theName') assigns theAns to 'theName' %% (default = 'ans') in the "base" workspace. % %% 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 11-Aug-1997 14:09:59. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2, theName = 'ans'; end % %assignin('base', theName, theAns) fclose(fout); disp(' ## Installing: "ncbevent.m" (text)') fout = fopen('ncbevent.m', 'w'); %function ncbevent(theEvent) % %% ncbevent -- Dispatch an NCBrowser event. %% ncbevent('theEvent') dispatches theEvent to %% the "ncbevent" method of the NCBrowser that %% owns the current window. % %% 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. % %self = get(gcf, 'UserData'); % %if isa(self, 'ncbrowser') % if nargin < 1 % ncbevent(self) % else % ncbevent(self, theEvent) % end %end fclose(fout); disp(' ## Installing: "nccat.m" (text)') fout = fopen('nccat.m', 'w'); %function [varargout] = nccat(theDestinationFile, varargin) % %% nccat -- Concatenate two netCDF files. %% nccat(theDestinationFile, theSourceFile1, theSourceFile2, ...) %% concatenates theSourceFile1, ... onto theDestinationFile. This %% routine behaves like the "nccat" C-language program, which %% concatenates record-variables, but no other entities. The files %% must have the same record structure. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %varargout = cell(1, nargout); % %if nargin < 2, help nccat, return, end % %if isa(theDestinationFile, 'netcdf') % f = theDestinationFile; %elseif ischar(theDestinationFile) % f = netcdf(theDestinationFile, 'write'); %else % error(' ## ') %end % %if isempty(f), return, end % %for j = 1:length(varargin) % theSourceFile = varargin{j}; % if isa(theSourceFile, 'netcdf') % g = theSourceFile; % elseif ischar(theSourceFile) % g = netcdf(theSourceFile, 'nowrite'); % else % error(' ## ') % end % if isempty(g), break, end % v = recvar(g) % for i = 1:length(v) % u = f{name(v{i})}; % if i == 1, a = size(u); end % b = size(v{i}); % u(a(1)+1:a(1)+b(1), :) = v{i}(1:b(1), :); % end % if ischar(theSourceFile) % g = close(g); % end %end % %if ischar(theSourceFile) % f = close(f); %end fclose(fout); disp(' ## Installing: "nccheck.m" (text)') fout = fopen('nccheck.m', 'w'); %function [varargout] = nccheck(varargin) % %% nccheck -- Are these all "ncitems"? %% [...] = nccheck(...) posts an error-message %% if some of its arguments are not "ncitems". %% Input arguments are passed intact to the %% output arguments, if any. % %% 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 29-Jun-1998 06:10:41. % %okay = 1; % %for i = 1:nargin % if ~isa(varargin{i}, 'ncitem') % okay = 0; % theClass = class(varargin{i}); % disp([' ## ' mfilename ': argument #' int2str(i) ' is a "' theClass '".']) % end %end % %if ~okay, error(' ## One or more non-NetCDF arguments.'), end % %for i = 1:min(nargin, nargout) % varargout{i} = varargin{i}; %end fclose(fout); disp(' ## Installing: "ncclass.m" (text)') fout = fopen('ncclass.m', 'w'); %function theResult = ncclass(theItem) % %% NCClass -- Class of an item. %% NCClass(theItem) returns the class of theItem. %% This function provides continuity with the %% ncitem/ncclass method. % %% 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 20-May-1997 07:23:32. % %result = class(theItem); % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "ncclear.m" (text)') fout = fopen('ncclear.m', 'w'); %% script ncclear % %% ncclear -- Clear Matlab of NetCDF effects. %% ncclear (no arguments) attempts to clear Matlab %% so that NetCDF activities can be resumed without %% having to quit the program. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %ncclose all %fclose('all'); %clear mex %clear functions %clear all fclose(fout); disp(' ## Installing: "ncclose.m" (text)') fout = fopen('ncclose.m', 'w'); %function theResult = ncclose(theNCid) % %% ncclose(theNCid) closes the netcdf files whose %% identifiers are the given theNCid. The default %% is 'all', which uses theNCid = [0:15]. %% %% Note: for "netcdf" objects, use "close", not %% "ncclose". % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 15-Feb-2000 09:29:46. %% Updated 08-Dec-2000 13:55:18. % %if nargin < 1, theNCid = 'all'; end % %if isa(theNCid, 'ncitem') % warning(' ## Use "close" for "netcdf" objects.') % if nargout > 0, theResult = []; end % return %end % %if isequal(theNCid, 'all') % theNCid = 0:15; %end % %theNCid = -sort(-theNCid); % %for i = 1:length(theNCid) % status(i) = ncmex('close', theNCid(i)); %end % %if nargout > 0 % theResult = status; % else % for i = 1:length(theNCid) % if status(i) >= 0 % disp([' ## closed: ncid = ' int2str(theNCid(i)) '.']) % end % end %end fclose(fout); disp(' ## Installing: "ncdim2rec.m" (text)') fout = fopen('ncdim2rec.m', 'w'); %function ncdim2rec(theNetCDF, theDim) % %% ncdim2rec -- Convert static dimension to record dimension. %% ncdim2rec(theNetCDF, theDim) converts one of the dimensions %% of theNetCDF, given as theDim, to a record-dimension. %% The arguments may be strings or NetCDF entities. %% The chosen dimension must be left-most in all the %% variables that use it. % %% 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-Nov-2001 09:25:59. %% Updated 03-Mar-2003 16:25:27. % %if nargin < 1, help(mfilename), return, end % %if ischar(theNetCDF) % theFilename = theNetCDF; % theNetCDF = netcdf(theFilename, 'nowrite'); % if isempty(theNetCDF) % disp([' ## Unable to open as NetCDF: "' theFilename '"']) % return % end %elseif ~isa(theNetCDF, 'netcdf') % disp([' ## Not a "netcdf" object.']) % return %end % %if ischar(theDim) % theDimname = theDim; % theDim = theNetCDF(theDimname); % if isempty(theDim) % disp([' ## Not a NetCDF dimension: "' theDimname '"']) % return % end %elseif ~isa(theDim, 'ncdim') % disp([' ## Not a NetCDF dimension.']) %end % %if isrecdim(theDim) % close(theNetCDF) % disp([' ## Already is a NetCDF record-dimension: "' theDimname '"']) % return %end % %% Open a randomly-named temporary file. % %for i = 1:100 % tmpname = ['temp' int2str(rand(1, 1)*10^9) '.nc']; % f = netcdf(tmpname, 'noclobber'); % if ~isempty(f), break, end %end % %if isempty(f) % close(theNetCDF) % disp([' ## Unable to open temporary NetCDF file.']) % return %end % %% Define the record-dimension. % %theDimname = name(theDim); %f(theDimname) = 0; % %% Pour everything into the new file. % %f < theNetCDF; % %% Get full filenames. % %theNetCDFname = name(theNetCDF) %theTmpname = name(f) % %% Close both files. % %close(theNetCDF) %close(f) % %% Copy temporary file to original name. % %fcopy(theTmpname, theNetCDFname) % %% Delete temporary file. % %delete(theTmpname) fclose(fout); disp(' ## Installing: "ncdimadd.m" (text)') fout = fopen('ncdimadd.m', 'w'); %function ncdimadd(theSrcFile, theDstFile, theDimName, theDimLength) % %% ncdimadd -- Add a dimension to a NetCDF file. %% ncdimadd(theSrcFile, theDstFile, 'theDimName', theDimLength) %% copies the components of theSrcFile to theDstFile (either %% filenames or "netcdf" objects), and adds the given dimension. %% If originally open, the files remain open. NOTE: theDstFile %% must be new or never have been closed or placed in "data" mode %% previously. If to be created, "clobber" permission is used. %% To add more than one dimension, use cell-arrays for the names %% and lengths. % %% 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 06-Oct-1999 10:48:23. %% Updated 06-Oct-1999 11:41:43. % %if nargin < 4, help(mfilename), return, end % %if ischar(theDimLength) % theDimLength = eval(theDimLength); %end % %% Open source file. % %if isa('netcdf', theSrcFile) % f = theSrcFile; %else % f = netcdf(theSrcFile, 'nowrite'); %end % %% Open destination file. % %if isempty(f), return, end % %if isa('netcdf', theDstFile) % g = theDstFile; %else % g = netcdf(theDstFile, 'clobber'); %end % %if isempty(g), close(f), return, end % %% Check destination for "data" mode. % %theMode = mode(g); %switch theMode %case 'data' % disp(' ## Output file requires "define" mode initially.') % close(g), close(f), return %end % %% Copy. % %disp([' ## Source file: ' name(f)]) %disp([' ## Destination file: ' name(f)]) % %g < att(f); % Copy existing global attributes. %g < dim(f); % Copy existing dimensions. % %if ~iscell(theDimName) % theDimName = {theDimName}; %end % %if ~iscell(theDimLength) % theDimLength = {theDimLength}; %end % %% Too few dimension lengths provided; adjust. % %while length(theDimLength) < length(theDimName) % theDimLength{end+1} = theDimLength{end}; %end % %% Add new dimensions. % %nDims = length(theDimName); % %for i = 1:nDims % disp([' ## ' int2str(nDims-i+1) ' Defining dimension: ' theDimName{i}]) % g(theDimName{i}) = theDimLength{i}; %end % %% Define existing variables and attributes. % %v = var(f); %nVars = length(v); % %for i = 1:nVars % disp([' ## ' int2str(nVars-i+1) ' Defining variable: ' name(v{i})]) % copy(v{i}, g, 0, 1, 1); %end % %% Fill existing variables. % %for i = 1:nVars % disp([' ## ' int2str(nVars-i+1) ' Filling variable: ' name(v{i})]) % copy(v{i}, g, 1, 0, 0); %end % %% Close files. % %if ischar(theDstFile) % g = close(g); % if ~isempty(g) % disp(' ## Unable to close destination file.') % end %end % %if ischar(theSrcFile) % f = close(f); % if ~isempty(f) % disp(' ## Unable to close source file.') % end %end fclose(fout); disp(' ## Installing: "ncdump.m" (text)') fout = fopen('ncdump.m', 'w'); %function theStatus = ncdump(theNetCDFFile, theOutputFile) % %% ncdump -- List NetCDF file headers as NetCDF Language. %% ncdump(theNetCDFFile, 'theOutputFile') displays the %% definitions of items in theNetCDFFile, a filename %% or a "netcdf" object. Similar in behavior to the %% Unidata "ncdump -h" program. If theNetCDFFile looks %% like a wild-card (contains '*'), the routine uses %% the uigetfile() dialog to get the filename. The %% default is '*.*'. The output file, which may be %% a wild-card to invoke uiputfile(), defaults to %% 'stdout', equivalent to the Matlab command window. %% (NOTE: if theOutputFile is provided as an integer %% > 2, it is assumed to be the file-id of an already %% open file.) % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Oct-1996 13:10:35.53. For ncmex4. %% Version of 19-Dec-1996 11:30:00.00. For ncmex5. %% Version of 09-Jan-1997 11:26:00.00. For netcdf objects. %% Version of 14-Jan-1997 11:34:00.00. Use nc4ml notation. %% Version of 21-Jan-1997 10:48:00.00. Names with embedded-quotes. %% Version of 11-Feb-1998 10:41:08.00. Accepts "netcdf" object. %% Version of 16-Jun-1998 10:41:08.00. Accepts id of open file. %% Updated 29-Sep-1998 09:10:49. Cleaned up the "help". % %if nargin < 1, help ncdump, theNetCDFFile = '*.*'; end %if nargin < 2, theOutputFile = 'stdout'; end % stdout. % %if isa(theNetCDFFile, 'ncitem') % theNetCDFFile = name(parent(parent(theNetCDFFile))); %end % %if any(theNetCDFFile == '*') % theFilterSpec = theNetCDFFile; % thePrompt = 'Select a NetCDF Input File:'; % [theFile, thePath] = uigetfile(theFilterSpec, thePrompt); % if ~any(theFile), return, end % theNetCDFFile = [thePath theFile]; %end % %if any(theOutputFile == '*') % theFilterSpec = theOutputFile; % thePrompt = 'Select a Text Output File:'; % [theFile, thePath] = uiputfile(theFilterSpec, thePrompt); % if ~any(theFile), return, end % theOutputFile = [thePath theFile]; %end % %nctypes = ['byte '; 'char '; 'short '; ... % 'long '; 'float '; 'double '; ...; % 'unknown'; 'unknown'; 'unknown']; % %nc = netcdf(theNetCDFFile, 'nowrite'); %theNCid = ncid(nc); % %if isempty(nc) % disp([' ## Unable to open: ' theNetCDFFile]) % return %end % %if strcmp(theOutputFile, 'stdout') % fp = 1; % elseif strcmp(theOutputFile, 'stderr') % fp = 2; % elseif isstr(theOutputFile) % fp = fopen(theOutputFile, 'w'); % else % fp = theOutputFile; %end % %if fp < 0, close(f), return, end % %[ndims, nvars, ngatts, recdim] = size(nc); % %dims = dim(nc); ndims = length(dims); %vars = var(nc); nvar = length(vars); %gatts = att(nc); ngatts = length(gatts); % %s = ' '; %fprintf(fp, '%s\n', s); %s = ['%% ncdump(''' theNetCDFFile ''')']; %s = [s ' %% Generated ' datestr(now)]; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); %s = ['nc = netcdf(''' theNetCDFFile ''', ''noclobber'');']; %fprintf(fp, '%s\n', s); %s = ['if isempty(nc), return, end']; %fprintf(fp, '%s\n', s); % %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% Global attributes:'; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% (none)'; %if ngatts < 1,fprintf(fp, '%s\n', s); end % %for i = 1:ngatts % varid = -1; % attnum = i-1; % attname = name(gatts{i}); % if any(attname ~= '_') % while attname(1) == '_' % attname = [attname(2:length(attname)) attname(1)]; % end % end % attname = strrep(attname, '''', ''''''); % theDatatype = datatype(gatts{i}); % attlen = ncsize(gatts{i}); % attvalue = gatts{i}(:); % theDatatype = ['nc' theDatatype]; % s = ['nc.' attname ' = ' theDatatype '(']; % t = mat2str(attvalue); % if length(t) > 0 & 0 % if t(1) == '[' & t(length(t)) == ']' % t = [ '{' t(2:length(t)-1) '}']; % end % end % if ~isstr(attvalue) % if (0) % f = []; % k = 1:length(t)-1; % if any(k), f = find(t(k) == t(k+1)); end % if any(f), t(f) = []; end % f = find(t == ' '); % if any(f), t(f) = setstr(t(f) .* 0 + ','); end % t = strrep(t, ',', ', '); % end % else % t = ['''' t '''']; % end % s = [s t ');']; % fprintf(fp, '%s\n', s); %end % %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% Dimensions:'; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); % %if ndims < 1, disp('%% (none)'), end % %for i = 1:ndims % dimid = i-1; % dimname = name(dims{i}); % dimname = strrep(dimname, '''', ''''''); % dimlen = ncsize(dims{i}); % s = ['nc(''' dimname ''') = ' int2str(dimlen) ';']; % if dimid == recdim, s = [s ' %% (record dimension)']; end % fprintf(fp, '%s\n', s); %end % %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% Variables and attributes:'; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); % %s = '%% (none)'; %if nvars < 1, fprintf(fp, '%s\n', s), end % %for j = 1:nvars; % varid = j-1; % varname = name(vars{j}); % varname = strrep(varname, '''', ''''''); % theDatatype = datatype(vars{j}); % theDatatype = ['nc' theDatatype]; % dims = dim(vars{j}); % ndims = length(dims); % atts = att(vars{j}); % natts = length(atts); % s = ['nc{''' varname '''} = ' theDatatype]; % for i = 1:ndims % dimname = name(dims{i}); % dimname = strrep(dimname, '''', ''''''); % dimlen = ncsize(dims{i}); % if i == 1, s = [s '(']; end % if i > 1, s = [s, ', ']; end % s = [s '''' dimname '''']; % if i == ndims, s = [s ')']; end % end % s = [s ';']; % elements = prod(ncsize(vars{j})); % s = [s ' %% ' int2str(elements) ' element']; % if elements ~= 1, s = [s 's']; end % s = [s '.']; % fprintf(fp, '%s\n', s); % for i = 1:natts % attnum = i-1; % theDatatype = datatype(atts{i}); % theDatatype = ['nc' theDatatype]; % attname = name(atts{i}); % if strcmp(attname, '_FillValue') % attname = 'FillValue_'; % end % if any(attname ~= '_') % while attname(1) == '_' % attname = [attname(2:length(attname)) attname(1)]; % end % end % attname = strrep(attname, '''', ''''''); % attlen = ncsize(atts{i}); % attvalue = atts{i}(:); % s = ['nc{''' varname '''}.' attname ' = ' theDatatype]; % t = mat2str(attvalue); % if ~isstr(attvalue) % Patch in commas. % if (0) % Doesn't work correctly. % f = []; % k = 1:length(t)-1; % if any(k), f = find(t(k) == t(k+1)); end % if any(f), t(f) = []; end % f = find(t == ' '); % if any(f), t(f) = setstr(t(f) .* 0 + ','); end % t = strrep(t, ',', ', '); % end % else % t = ['''' t '''']; % end % t = ['(' t ')']; % s = [s t ';']; % fprintf(fp, '%s\n', s); % end % s = ' '; % fprintf(fp, '%s\n', s); %end % %s = 'endef(nc)'; %fprintf(fp, '%s\n', s); %s = 'close(nc)'; %fprintf(fp, '%s\n', s); % %if ischar(theOutputFile) & fp > 2, fclose(fp); end % %close(nc) % %if nargout > 0, theStatus = status; end fclose(fout); disp(' ## Installing: "ncdumpd.m" (text)') fout = fopen('ncdumpd.m', 'w'); %function theStatus = ncdumpd(theNetCDFFile, theOutputFile) % %% ncdumpd -- List NetCDF file headers as NetCDF Language. %% ncdumpd(theNetCDFFile, 'theOutputFile') displays the %% definitions of items in theNetCDFFile, a filename %% or a "netcdf" object. Similar in behavior to the %% Unidata "ncdump -h" program. If theNetCDFFile looks %% like a wild-card (contains '*'), the routine uses %% the uigetfile() dialog to get the filename. The %% default is '*.*'. The output file, which may be %% a wild-card to invoke uiputfile(), defaults to %% 'stdout', equivalent to the Matlab command window. %% (NOTE: if theOutputFile is provided as an integer %% > 2, it is assumed to be the file-id of an already %% open file.) % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Oct-1996 13:10:35.53. For ncmex4. %% Version of 19-Dec-1996 11:30:00.00. For ncmex5. %% Version of 09-Jan-1997 11:26:00.00. For netcdf objects. %% Version of 14-Jan-1997 11:34:00.00. Use nc4ml notation. %% Version of 21-Jan-1997 10:48:00.00. Names with embedded-quotes. %% Version of 11-Feb-1998 10:41:08.00. Accepts "netcdf" object. %% Version of 16-Jun-1998 10:41:08.00. Accepts id of open file. %% Updated 29-Sep-1998 09:10:49. Cleaned up the "help". %% Updated 31-May-2001 10:07:14. Write the data. % %if nargin < 1, help ncdumpd, theNetCDFFile = '*.*'; end %if nargin < 2, theOutputFile = 'stdout'; end % stdout. % %if isa(theNetCDFFile, 'ncitem') % theNetCDFFile = name(parent(parent(theNetCDFFile))); %end % %if any(theNetCDFFile == '*') % theFilterSpec = theNetCDFFile; % thePrompt = 'Select a NetCDF Input File:'; % [theFile, thePath] = uigetfile(theFilterSpec, thePrompt); % if ~any(theFile), return, end % theNetCDFFile = [thePath theFile]; %end % %if any(theOutputFile == '*') % theFilterSpec = theOutputFile; % thePrompt = 'Select a Text Output File:'; % [theFile, thePath] = uiputfile(theFilterSpec, thePrompt); % if ~any(theFile), return, end % theOutputFile = [thePath theFile]; %end % %nctypes = ['byte '; 'char '; 'short '; ... % 'long '; 'float '; 'double '; ...; % 'unknown'; 'unknown'; 'unknown']; % %nc = netcdf(theNetCDFFile, 'nowrite'); %theNCid = ncid(nc); % %if isempty(nc) % disp([' ## Unable to open: ' theNetCDFFile]) % return %end % %if strcmp(theOutputFile, 'stdout') % fp = 1; % elseif strcmp(theOutputFile, 'stderr') % fp = 2; % elseif isstr(theOutputFile) % fp = fopen(theOutputFile, 'w'); % else % fp = theOutputFile; %end % %if fp < 0, close(f), return, end % %[ndims, nvars, ngatts, recdim] = size(nc); % %dims = dim(nc); ndims = length(dims); %vars = var(nc); nvar = length(vars); %gatts = att(nc); ngatts = length(gatts); % %s = ' '; %fprintf(fp, '%s\n', s); %s = ['%% ncdump(''' theNetCDFFile ''')']; %s = [s ' %% Generated ' datestr(now)]; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); %s = ['nc = netcdf(''' theNetCDFFile ''', ''noclobber'');']; %fprintf(fp, '%s\n', s); %s = ['if isempty(nc), return, end']; %fprintf(fp, '%s\n', s); % %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% Global attributes:'; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% (none)'; %if ngatts < 1,fprintf(fp, '%s\n', s); end % %for i = 1:ngatts % varid = -1; % attnum = i-1; % attname = name(gatts{i}); % if any(attname ~= '_') % while attname(1) == '_' % attname = [attname(2:length(attname)) attname(1)]; % end % end % attname = strrep(attname, '''', ''''''); % theDatatype = datatype(gatts{i}); % attlen = ncsize(gatts{i}); % attvalue = gatts{i}(:); % theDatatype = ['nc' theDatatype]; % s = ['nc.' attname ' = ' theDatatype '(']; % t = mat2str(attvalue); % if length(t) > 0 & 0 % if t(1) == '[' & t(length(t)) == ']' % t = [ '{' t(2:length(t)-1) '}']; % end % end % if ~isstr(attvalue) % if (0) % f = []; % k = 1:length(t)-1; % if any(k), f = find(t(k) == t(k+1)); end % if any(f), t(f) = []; end % f = find(t == ' '); % if any(f), t(f) = setstr(t(f) .* 0 + ','); end % t = strrep(t, ',', ', '); % end % else % t = ['''' t '''']; % end % s = [s t ');']; % fprintf(fp, '%s\n', s); %end % %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% Dimensions:'; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); % %if ndims < 1, disp('%% (none)'), end % %for i = 1:ndims % dimid = i-1; % dimname = name(dims{i}); % dimname = strrep(dimname, '''', ''''''); % dimlen = ncsize(dims{i}); % s = ['nc(''' dimname ''') = ' int2str(dimlen) ';']; % if dimid == recdim, s = [s ' %% (record dimension)']; end % fprintf(fp, '%s\n', s); %end % %s = ' '; %fprintf(fp, '%s\n', s); %s = '%% Variables and attributes:'; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); % %s = '%% (none)'; %if nvars < 1, fprintf(fp, '%s\n', s), end % %for j = 1:nvars; % varid = j-1; % varname = name(vars{j}); % varname = strrep(varname, '''', ''''''); % theDatatype = datatype(vars{j}); % theDatatype = ['nc' theDatatype]; % dims = dim(vars{j}); % ndims = length(dims); % atts = att(vars{j}); % natts = length(atts); % s = ['nc{''' varname '''} = ' theDatatype]; % for i = 1:ndims % dimname = name(dims{i}); % dimname = strrep(dimname, '''', ''''''); % dimlen = ncsize(dims{i}); % if i == 1, s = [s '(']; end % if i > 1, s = [s, ', ']; end % s = [s '''' dimname '''']; % if i == ndims, s = [s ')']; end % end % s = [s ';']; % elements = prod(ncsize(vars{j})); % s = [s ' %% ' int2str(elements) ' element']; % if elements ~= 1, s = [s 's']; end % s = [s '.']; % fprintf(fp, '%s\n', s); % for i = 1:natts % attnum = i-1; % theDatatype = datatype(atts{i}); % theDatatype = ['nc' theDatatype]; % attname = name(atts{i}); % if strcmp(attname, '_FillValue') % attname = 'FillValue_'; % end % if any(attname ~= '_') % while attname(1) == '_' % attname = [attname(2:length(attname)) attname(1)]; % end % end % attname = strrep(attname, '''', ''''''); % attlen = ncsize(atts{i}); % attvalue = atts{i}(:); % s = ['nc{''' varname '''}.' attname ' = ' theDatatype]; % t = mat2str(attvalue); % if ~isstr(attvalue) % Patch in commas. % if (0) % Doesn't work correctly. % f = []; % k = 1:length(t)-1; % if any(k), f = find(t(k) == t(k+1)); end % if any(f), t(f) = []; end % f = find(t == ' '); % if any(f), t(f) = setstr(t(f) .* 0 + ','); end % t = strrep(t, ',', ', '); % end % else % t = ['''' t '''']; % end % t = ['(' t ')']; % s = [s t ';']; % fprintf(fp, '%s\n', s); % end % s = ' '; % fprintf(fp, '%s\n', s); %end % %s = 'endef(nc)'; %fprintf(fp, '%s\n', s); % %for j = 1:nvars % varname = name(vars{j}); % s = [varname '(']; % d = ncsize(vars{j}); % for i = 1:length(d) % ind = ['1:' int2str(d(i))]; % s = [s ind]; % if i < length(d) % s = [s ', ']; % end % end % s = [s ') = ...']; % fprintf(fp, '\n%s\n', s); % x = vars{j}(:); % s = mat2str(x); % if ischar(x) % fprintf(fp, '%s', '[''') % end % fprintf(fp, '%s', s); % if ischar(x) % fprintf(fp, '%s', ''']') % end % fprintf(fp, '%s\n', ';') %end % %s = 'close(nc)'; %fprintf(fp, '\n%s\n', s); % %if ischar(theOutputFile) & fp > 2, fclose(fp); end % %close(nc) % %if nargout > 0, theStatus = status; end fclose(fout); disp(' ## Installing: "ncdumph.m" (text)') fout = fopen('ncdumph.m', 'w'); %function theStatus = ncdumph(theNetCDFFile, theOutputFile) % %% ncdumph -- List NetCDF file structure as NC4ML. %% ncdumph(theNetCDFFile, theOutputFile) displays the %% definitions of items in theNetCDFFile, a filename. %% Similar in behavior to the "ncdump -h" program. %% If theNetCDFFile looks like a wild-card (contains '*'), %% the routine uses uigetfile() dialog to obtain the filename. %% The default is '*.*'. The output file, which may be %% a wild-card to invoke uiputfile, defaults to 'stdout', %% equivalent to the Matlab command window. % %% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Oct-96 at 13:10:35.53. For ncmex4. %% Version of 19-Dec-96 at 11:30:00:00. For ncmex5. %% Version of 09-Jan-97 at 11:26:00:00. For netcdf objects. %% Version of 14-Jan-97 at 11:34:00:00. Use nc4ml notation. %% Version of 21-Jan-97 at 10:48:00:00. Names with embedded-quotes. %% Version of 28-Jan-97 at 09:00:00:00. List structure only. % %if nargin < 1, help ncdumph, theNetCDFFile = '*.*'; end %if nargin < 2, theOutputFile = 'stdout'; end % %if any(theNetCDFFile == '*') % theFilterSpec = theNetCDFFile; % thePrompt = 'Select a NetCDF Input File:'; % [theFile, thePath] = uigetfile(theFilterSpec, thePrompt); % if ~any(theFile), return, end % theNetCDFFile = [thePath theFile]; %end % %if any(theOutputFile == '*') % theFilterSpec = theOutputFile; % thePrompt = 'Select a Text Output File:'; % [theFile, thePath] = uiputfile(theFilterSpec, thePrompt); % if ~any(theFile), return, end % theOutputFile = [thePath theFile]; %end % %nctypes = ['byte '; 'char '; 'short '; ... % 'long '; 'float '; 'double '; ...; % 'unknown'; 'unknown'; 'unknown']; % %nc = netcdf(theNetCDFFile, 'nowrite'); %theNCid = ncid(nc); % %if isempty(nc) % disp([' ## Unable to open: ' theNetCDFFile]) % return %end % %if strcmp(theOutputFile, 'stdout') % fp = 1; % elseif strcmp(theOutputFile, 'stderr') % fp = 2; % else % fp = fopen(theOutputFile, 'w'); %end % %if fp < 0, close(f), return, end % %[ndims, nvars, ngatts, recdim] = size(nc); % %dims = dim(nc); ndims = length(dims); %vars = var(nc); nvar = length(vars); %gatts = att(nc); ngatts = length(gatts); % %s = ' '; %fprintf(fp, '%s\n', s); %s = ['%% ncdumph(''' theNetCDFFile ''')']; %s = [s ' %% Generated ' datestr(now)]; %fprintf(fp, '%s\n', s); %s = ' '; %fprintf(fp, '%s\n', s); %s = ['nc = netcdf(''' theNetCDFFile ''', ''noclobber'');']; %fprintf(fp, '%s\n', s); %s = ['if isempty(nc), return, end']; %fprintf(fp, '%s\n', s); % %s = ' '; fprintf(fp, '%s\n', s); %s = '%% Global attributes:'; fprintf(fp, '%s\n', s); %s = ' '; fprintf(fp, '%s\n', s); % %if nvars < 1, s = '%% (none)'; fprintf(fp, '%s\n', s); end % %for i = 1:ngatts % varid = -1; % attnum = i-1; % attname = name(gatts{i}); % if any(attname ~= '_') % while attname(1) == '_' % attname = [attname(2:length(attname)) attname(1)]; % end % end % attname = strrep(attname, '''', ''''''); % theDatatype = datatype(gatts{i}); % attlen = size(gatts{i}); % attvalue = gatts{i}(:); % theDatatype = ['nc' theDatatype]; % s = ['nc.' attname ' = ' theDatatype '(...)']; % fprintf(fp, '%s\n', s); %end % %s = ' '; fprintf(fp, '%s\n', s); %s = '%% Dimensions:'; fprintf(fp, '%s\n', s); %s = ' '; fprintf(fp, '%s\n', s); % %if ndims < 1, s = '%% (none)'; fprintf(fp, '%s\n', s); end % %for i = 1:ndims % dimid = i-1; % dimname = name(dims{i}); % dimname = strrep(dimname, '''', ''''''); % dimlen = size(dims{i}); % s = ['nc(''' dimname ''') = ' int2str(dimlen) ';']; % if dimid == recdim, s = [s ' %% (record dimension)']; end % fprintf(fp, '%s\n', s); %end % %s = ' '; fprintf(fp, '%s\n', s); %s = '%% Variables:'; fprintf(fp, '%s\n', s); %s = ' '; fprintf(fp, '%s\n', s); % %s = '%% (none)'; if nvars < 1, disp(s), end % %for j = 1:nvars; % varid = j-1; % varname = name(vars{j}); % varname = strrep(varname, '''', ''''''); % theDatatype = datatype(vars{j}); % theDatatype = ['nc' theDatatype]; % dims = dim(vars{j}); % ndims = length(dims); % atts = att(vars{j}); % natts = length(atts); % s = ['nc{''' varname '''} = ' theDatatype]; % for i = 1:ndims % dimname = name(dims{i}); % dimname = strrep(dimname, '''', ''''''); % dimlen = size(dims{i}); % if i == 1, s = [s '(']; end % if i > 1, s = [s, ', ']; end % s = [s '''' dimname '''']; % if i == ndims, s = [s ')']; end % end % elements = prod(size(vars{j})); % s = [s ' %% ' int2str(elements) ' element']; % if elements ~= 1, s = [s 's']; end % s = [s '.']; fprintf(fp, '%s\n', s); %end % %s = ' '; fprintf(fp, '%s\n', s); %s = '%% Attributes:'; fprintf(fp, '%s\n', s); % %for j = 1:nvars; % varid = j-1; % varname = name(vars{j}); % varname = strrep(varname, '''', ''''''); % atts = att(vars{j}); % natts = length(atts); % if natts > 0, s = ' '; fprintf(fp, '%s\n', s); end % for i = 1:natts % attnum = i-1; % theDatatype = datatype(atts{i}); % theDatatype = ['nc' theDatatype]; % attname = name(atts{i}); % if strcmp(attname, '_FillValue') % attname = 'FillValue_'; % end % if any(attname ~= '_') % while attname(1) == '_' % attname = [attname(2:length(attname)) attname(1)]; % end % end % attname = strrep(attname, '''', ''''''); % attlen = size(atts{i}); % attvalue = atts{i}(:); % s = ['nc{''' varname '''}.' attname ' = ' theDatatype '(...)']; % fprintf(fp, '%s\n', s); % end %end % %s = ' '; fprintf(fp, '%s\n', s); %s = 'endef(nc)'; fprintf(fp, '%s\n', s); %s = 'close(nc)'; fprintf(fp, '%s\n', s); % %if fp ~= 1, fclose(fp); end % %close(nc) % %if nargout > 0, theStatus = status; end fclose(fout); disp(' ## Installing: "ncexample.m" (text)') fout = fopen('ncexample.m', 'w'); %function ncexample % %% ncexample.m -- "NetCDF Toolbox for Matlab-5" example. %% ncexample (no argument) is a short example that lists %% itself, builds a simple NetCDF file, then displays %% its variables. % %% 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 12-Jun-1997 16:23:04. % %type(mfilename) % %help(mfilename) % %% ---------------------------- DEFINE THE FILE --------------------------- % % %ncquiet % No NetCDF warnings. % %nc = netcdf('ncexample.nc', 'clobber'); % Create NetCDF file. % %nc.description = 'NetCDF Example'; % Global attributes. %nc.author = 'Dr. Charles R. Denham'; %nc.date = 'June 9, 1997'; % %nc('latitude') = 10; % Define dimensions. %nc('longitude') = 10; % %nc{'latitude'} = 'latitude'; % Define variables. %nc{'longitude'} = 'longitude'; %nc{'depth'} = {'latitude', 'longitude'}; % %nc{'latitude'}.units = 'degrees'; % Attributes. %nc{'longitude'}.units = 'degrees'; %nc{'depth'}.units = 'meters'; % %% ---------------------------- STORE THE DATA ---------------------------- % % %latitude = [0 10 20 30 40 50 60 70 80 90]; % Matlab data. %longitude = [0 20 40 60 80 100 120 140 160 180]; %depth = rand(length(latitude), length(longitude)); % %nc{'latitude'}(:) = latitude; % Put all the data. %nc{'longitude'}(:) = longitude; %nc{'depth'}(:) = depth; % %nc = close(nc); % Close the file. % %% ---------------------------- RECALL THE DATA --------------------------- % % %nc = netcdf('ncexample.nc', 'nowrite'); % Open NetCDF file. %description = nc.description(:) % Global attribute. %variables = var(nc); % Get variable data. %for i = 1:length(variables) % disp([name(variables{i}) ' =']), disp(' ') % disp(variables{i}(:)) %end %nc = close(nc); % Close the file. % %% --------------------------------- DONE --------------------------------- % fclose(fout); disp(' ## Installing: "ncextract.m" (text)') fout = fopen('ncextract.m', 'w'); %function theResult = ncextract(theNCObject, theOutputName) % %% ncextract -- GUI for NetCDF data extraction. %% ncextract(theNCObject, 'theOutputName') presents a dialog %% for guiding the extraction of the values associated with %% theNCObject, a NetCDF variable or attribute object. The %% optional output-name defaults to "ans" in the "base" %% workspace, unless an actual output argument is provided. %% Matlab 5.1 -- This routine uses a "try/catch" test below. %% Comment-out the lines designated below. % %% 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 27-Jul-2000 09:28:06. %% Updated 19-Aug-2002 14:09:55. % %v = version; %f = find(v == '.'); %v(f(2):end) = ''; %if eval(v) < 5.2 % error(' ## Requires Matlab v5.2+') %end % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theOutputName = 'ans'; end % %result = []; % %if ~isa(theNCObject, 'ncvar') & ~isa(theNCObject, 'ncatt') % disp([' ## ' mfilename ' -- The item must be a NetCDF variable or attribute.']) % if nargout > 0, theResult = result; end % return %end % %theName = name(theNCObject); %theSize = ncsize(theNCObject); % %Extract.Output = theOutputName; %for i = 1:length(theSize) % label = ['Dim_' int2str(i)]; % indices = ['1:1:' int2str(theSize(i))]; % Extract = setfield(Extract, label, indices); %end % %theTitle = ['NCExtract -- ' theName]; %x = guido(Extract, theTitle); % %% Matlab 5.1 -- Comment out the try/catch/disp/end statements. % %try % Comment if Matlab 5.1. % if ~isempty(x) % theOutputName = getinfo(x, 'Output'); % s = 'theNCObject('; % for i = 1:length(theSize) % label = ['Dim_' int2str(i)]; % indices = getinfo(x, label); % if i > 1, s = [s ', ']; end % s = [s indices]; % end % s = [s ')']; % result = eval(s); % if nargout < 1 % assignin('base', theOutputName, result) % end % end %catch % Comment if Matlab 5.1. % disp([' ## ' mfilename ' -- error; try again.']) % Comment if Matlab 5.1. %end % Comment if Matlab 5.1. % %if nargout > 0, theResult = result, end fclose(fout); disp(' ## Installing: "ncfillvalues.m" (text)') fout = fopen('ncfillvalues.m', 'w'); %function theResult = ncfillvalues % %% ncfillvalues -- Create a NetCDF file containing default fill-values. %% ncfillvalues (no arguments) creates 'ncfillvalues.nc', containing %% variables with the default NetCDF fill-values. Use "ncdump" to %% see the exact NetCDF file structure. This routine returns a %% Matlab "struct" of fill-values if an output argument is given. % %% 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 14-Apr-1999 10:02:09. %% Updated 17-Jun-2002 16:45:44. % %if nargout < 1, help(mfilename), end % %theNames = {'ncbyte', 'ncchar', 'ncshort', 'nclong', 'ncfloat', 'ncdouble'}; % %f = netcdf('ncfillvalues.nc', 'clobber'); % %f.CreatedOn = datestr(now); %f.CreatedBy = mfilename; %f.MatlabVersion = version; %f.Computer = computer; % %f('index') = 1; % %for i = 1:length(theNames) % f{theNames{i}} = feval(theNames{i}, 'index'); %end % %endef(f) % %result = []; %for i = 1:length(theNames) % theFillValue = f{theNames{i}}(1); % result = setfield(result, theNames{i}, theFillValue); % f{theNames{i}}.FillValue_ = theFillValue; %end % %close(f) % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ncillegal.m" (text)') fout = fopen('ncillegal.m', 'w'); %function ncillegal(theOperation) % %% ncillegal -- Issue a warning about an illegal operation. %% ncillegal ('theOperation') issues a warning message %% that 'theOperation' (default = 'previous') is illegal. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, theOperation = 'previous'; end % %warning([' ## The "' theOperation '" operation is illegal in this context.']) fclose(fout); disp(' ## Installing: "ncind2slab.m" (text)') fout = fopen('ncind2slab.m', 'w'); %function [theStarts, theCounts] = ncind2slab(theSize, theStart, theCount) % %% ncind2slab -- Convert 1-d indices to NetCDF slab coordinates. %% ncind2slab(theSize, theStart, theCount) figures out how to %% to move elements to/from a NetCDF variable, using linear %% base-1 indexing. For theStart index and theCount of elements, %% theStarts and theCounts (taken row-wise) for the equivalent %% slabs are returned based on theSize of the targeted NetCDF array. %% Use each slab in sequence to put/get its count of elements, then %% offset the source index by the total count before using the next %% slab. On error, the routine returns the empty-matrix []. %% %% N.B. We may need to reverse the sequence of coordinates. %% N.B. This routine handles stride = 1 only. % %% 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 02-Sep-1997 13:24:05. % %if nargin < 1, theSize = 'demo'; end % %if strcmp(theSize, 'demo') % help(mfilename) % theSize = [3 5] % theStart = 2 % theCount = 10 % [theStarts_, theCounts_] = ncind2slab(theSize, theStart, theCount); % if nargout > 0 % theStarts = theStarts_; % theCounts = theCounts_; % else % theStarts_, theCounts_ % total_count = sum(prod(theCounts_.')) % end % return %end % %if nargin < 2, theStart = 1; end %if nargin < 3, theCount = 1; end % %if nargout > 0, theStarts = []; theCounts = []; end % %theCount = min(prod(theSize), theCount); % %% Strategy: We seek the largest legal slab that %% can accomodate the next piece of theCount, %% iterating until theCount has been consumed. % %theOriginalCount = theCount; % %result = zeros(0, 2); % %s = cell(size(theSize)); % %k = 0; %while theCount > 0 % [s{:}] = ind2sub(theSize, theStart); % Starting corner. % f = length(s); % for i = 1:length(s) % if s{i} > 1, f = i; break; end % end % t = s; % for i = 1:f, t{i} = theSize(i); end % Opposite corner. % theChunk = sub2ind(theSize, t{:}) - sub2ind(theSize, s{:}) + 1; % while theChunk > theCount % for i = length(t):-1:1 % if t{i} > s{i} % Binary search. % delta = 1; % while 2*delta <= (t{i} - s{i}) % delta = 2*delta; % end % t_original = t{i}; % t{i} = s{i}; % Start here. % while delta > 0 % if t{i} + delta <= t_original % Overflow check. % t{i} = t{i} + delta; % ch = sub2ind(theSize, t{:}) - sub2ind(theSize, s{:}) + 1; % if ch > theCount, t{i} = t{i} - delta; end % end % delta = fix(delta/2); % end % end % end % theChunk = sub2ind(theSize, t{:}) - sub2ind(theSize, s{:}) + 1; % end % k = k+1; % result(k, 1) = theStart; % result(k, 2) = theChunk; % theStart = theStart + theChunk; % theCount = theCount - theChunk; %end % %total_count = sum(result(:, 2)); %if total_count ~= theOriginalCount % total_count, theOriginalCount % warning(' ## Total count does not match desired count.') % return %end % %s = cell(size(theSize)); %t = cell(size(theSize)); %[m, n] = size(result); %starts = zeros(m, length(theSize)); %counts = zeros(m, length(theSize)); %for i = 1:m % [s{:}] = ind2sub(theSize, result(i, 1)); % [t{:}] = ind2sub(theSize, result(i, 1) + result(i, 2) - 1); % for j = 1:length(theSize) % starts(i, j) = s{j}; % counts(i, j) = t{j} - s{j} + 1; % end %end % %if nargout > 0 % theStarts = starts; % theCounts = counts; %else % starts, counts %end fclose(fout); disp(' ## Installing: "ncind2sub.m" (text)') fout = fopen('ncind2sub.m', 'w'); %function [theSubs, theCounts] = ncind2sub(theSize, theStart, theCount) % %% ncind2sub -- Convert 1-d indices to NetCDF slab subscripts. %% [theSubs, theCounts] = ncind2sub(theSize, theStart, theCount) %% figures out how to to move elements to/from a NetCDF variable %% with Matlab subscripting, using linear base-1 indexing. For %% theStart index and theCount of elements, this routine returns %% theSubs cell-array of subscripts for the equivalent slabs, based %% on theSize of the targeted NetCDF array. Use each row of theSubs %% in sequence to manipulate the equivalent slab, then offset the %% source index by the corresponding value of theCounts. Each row %% of theSubs cell-array can be invoked as a comma-list, using {:} %% syntax. On error, the routine returns the empty-matrix []. %% %% N.B. We may need to reverse the sequence of coordinates. %% N.B. This routine handles stride = 1 only. % %% 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 04-Sep-1997 09:16:56. % %if nargin < 1, theSize = 'demo'; end % %if strcmp(theSize, 'demo') % help(mfilename) % theSize = [3 5] % theStart = 2 % theCount = 10 % [theSubs_, theCounts_] = ncind2sub(theSize, theStart, theCount); % if nargout > 0 % theSubs = theSubs_; % theCounts = theCounts_; % else % theSubs_, theCounts_ % total_count = sum(theCounts_.') % end % return %end % %if nargin < 2, theStart = 1; end %if nargin < 3, theCount = 1; end % %if nargout > 0, theStarts = []; theCounts = []; end % %theCount = min(prod(theSize), theCount); % %% Strategy: We seek the largest legal slab that %% can accomodate the next piece of theCount, %% iterating until theCount has been consumed. % %theOriginalCount = theCount; % %result = zeros(0, 2); % %s = cell(size(theSize)); % %k = 0; %while theCount > 0 % [s{:}] = ind2sub(theSize, theStart); % Starting corner. % f = length(s); % for i = 1:length(s) % if s{i} > 1, f = i; break; end % end % t = s; % for i = 1:f, t{i} = theSize(i); end % Opposite corner. % theChunk = sub2ind(theSize, t{:}) - sub2ind(theSize, s{:}) + 1; % while theChunk > theCount % for i = length(t):-1:1 % if t{i} > s{i} % Binary search. % delta = 1; % while 2*delta <= (t{i} - s{i}) % delta = 2*delta; % end % t_original = t{i}; % t{i} = s{i}; % Start here. % while delta > 0 % if t{i} + delta <= t_original % Overflow check. % t{i} = t{i} + delta; % ch = sub2ind(theSize, t{:}) - sub2ind(theSize, s{:}) + 1; % if ch > theCount, t{i} = t{i} - delta; end % end % delta = fix(delta/2); % end % end % end % theChunk = sub2ind(theSize, t{:}) - sub2ind(theSize, s{:}) + 1; % end % k = k+1; % result(k, 1) = theStart; % result(k, 2) = theChunk; % theStart = theStart + theChunk; % theCount = theCount - theChunk; %end % %total_count = sum(result(:, 2)); %if total_count ~= theOriginalCount % total_count, theOriginalCount % warning(' ## Total count does not match desired count.') % return %end % %s = cell(size(theSize)); %t = cell(size(theSize)); %[m, n] = size(result); %starts = zeros(m, length(theSize)); %counts = zeros(m, length(theSize)); %for i = 1:m % [s{:}] = ind2sub(theSize, result(i, 1)); % [t{:}] = ind2sub(theSize, result(i, 1) + result(i, 2) - 1); % for j = 1:length(theSize) % starts(i, j) = s{j}; % counts(i, j) = t{j} - s{j} + 1; % end %end % %% Convert to subscripts. % % %subs = cell(size(starts)); %[m, n] = size(subs); %for i = 1:m % for j = 1:n % subs{i, j} = starts(i, j) + (1:counts(i, j)) - 1; % end %end % %counts = prod(counts.').'; % %if nargout > 0 % theSubs = subs; % theCounts = counts; %else % subs, counts %end fclose(fout); disp(' ## Installing: "ncload.m" (text)') fout = fopen('ncload.m', 'w'); %function theResult = ncload(theNetCDFFile, varargin) % %% ncload -- Load NetCDF variables. %% ncload('theNetCDFFile', 'var1', 'var2', ...) loads the %% given variables of 'theNetCDFFile' into the Matlab %% workspace of the "caller" of this routine. If no names %% are given, all variables are loaded. The names of the %% loaded variables are returned or assigned to "ans". %% No attributes are loaded. % %% 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-Aug-1997 10:13:57. % %if nargin < 1, help(mfilename), return, end % %result = []; %if nargout > 0, theResult = result; end % %f = netcdf(theNetCDFFile, 'nowrite'); %if isempty(f), return, end % %if isempty(varargin), varargin = ncnames(var(f)); end % %for i = 1:length(varargin) % if ~isstr(varargin{i}), varargin{i} = inputname(i+1); end % assignin('caller', varargin{i}, f{varargin{i}}(:)) %end % %result = varargin; % %close(f) % %if nargout > 0 % theResult = result %else % ncans(result) %end fclose(fout); disp(' ## Installing: "ncmemory.m" (text)') fout = fopen('ncmemory.m', 'w'); %function theResult = ncmemory(theNetCDF) % %% ncmemory -- Estimate Matlab memory for NetCDF file. %% ncmemory(theNetCDF) estimates the amount of Matlab %% memory that would be required to load all the variables %% and attributes from theNetCDF ('filename' or "netcdf" %% object). The size of the Matlab header is not included %% in the estimate. % %% 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-Sep-1999 09:12:20. %% Updated 08-Sep-1999 10:07:00. % %if nargout > 0, theResult = []; end % %if nargin < 1 % help(mfilename) % theNetCDF = '*'; %end % %% Compute byte-sizes for "char" and "double". % %charBytes = 2; %doubleBytes = 8; % %aChar = '0'; %aDouble = 0; % %w = whos('aChar', 'aDouble'); %for i = 1:length(w) % switch w(i).class % case 'char' % charBytes = w(i).bytes; % case 'double' % doubleBytes = w(i).bytes; % end %end % %theClass = class(theNetCDF); % %wasOpened = 0; %if isa(theClass, 'char') % nc = netcdf(theNetCDF, 'nowrite'); % wasOpened = ~isempty(nc); %elseif isa(theClass, 'netcdf') % nc = theNetCDF; % theNetCDF = name(nc); %else % disp(' ## Requires filename or "netcdf" object.') % return %end % %if isempty(nc), return, end % %% List of items. % %x = att(nc); %v = var(nc); %for k = 1:length(v) % x{end+1} = v{k}; % a = att(v{k}); % for i = 1:length(a) % x{end+1} = a{i}; % end %end % %% Compute Matlab memory requirements. % %result = 0; % %for i = 1:length(x) % s = prod(size(x{i})); % switch class(x{i}); % case 'char' % s = s*charBytes; % otherwise % s = s*doubleBytes; % end % result = result + s; %end % %% Done. % %if wasOpened, close(nc), end % %if nargout > 0 % theResult = result %else % disp([' ## "' theNetCDF '" requires approximately ' int2str(result) ' bytes.']) % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "ncmex.m" (text)') fout = fopen('ncmex.m', 'w'); %function [varargout] = ncmex(varargin) % %% ncmex -- Driver for NetCDF C-Language interface. %% ncmex('action', ...) performs the specified NetCDF action. %% Variables are returned as multi-dimensional arrays whose %% dimensions are arranged in the left-to-right order defined %% in 'vardef' or retrieved by 'varinq'. No pre-put or post-get %% permutation of dimensions is required. The base-index for %% slabs is zero (0), and -1 can be used to specify the remaining %% count along any variable direction from the starting point. %% %% ncmex('USAGE') %% [cdfid, rcode] = ncmex('CREATE', 'path', cmode) %% cdfid = ncmex('OPEN', 'path', mode) %% status = ncmex('REDEF', cdfid) %% status = ncmex('ENDEF', cdfid) %% [ndims, nvars, natts, recdim, status] = ncmex('INQUIRE', cdfid) %% status = ncmex('SYNC', cdfid) %% status = ncmex('ABORT', cdfid) %% status = ncmex('CLOSE', cdfid) %% %% status = ncmex('DIMDEF', cdfid, 'name', length) %% [dimid, rcode] = ncmex('DIMID', cdfid, 'name') %% ['name', length, status] = ncmex('DIMINQ', cdfid, dimid) %% status = ncmex('DIMRENAME', cdfid, 'name') %% %% status = ncmex('VARDEF', cdfid, 'name', datatype, ndims, [dim]) %% [varid, rcode] = ncmex('VARID', cdfid, 'name') %% ['name', datatype, ndims, [dim], natts, status] = ncmex('VARINQ', cdfid, varid) %% status = ncmex('VARPUT1', cdfid, varid, coords, value, autoscale) %% [value, status] = ncmex('VARGET1', cdfid, varid, coords, autoscale) %% status = ncmex('VARPUT', cdfid, varid, start, count, value, autoscale) %% [value, status] = ncmex('VARGET', cdfid, varid, start, count, autoscale) %% status = ncmex('VARPUTG', cdfid, varid, start, count, stride, [], value, autoscale) %% [value, status] = ncmex('VARGETG', cdfid, varid, start, count, stride, [], autoscale) %% status = ncmex('VARRENAME', cdfid, varid, 'name') %% %% status = ncmex('ATTPUT', cdfid, varid, 'name', datatype, len, value) %% [datatype, len, status] = ncmex('ATTINQ', cdfid, varid, 'name') %% [value, status] = ncmex('ATTGET', cdfid, varid, 'name') %% status = ncmex('ATTCOPY', incdf, invar, 'name', outcdf, outvar) %% ['name', status] = ncmex('ATTNAME', cdfid, varid, attnum) %% status = ncmex('ATTRENAME', cdfid, varid, 'name', 'newname') %% status = ncmex('ATTDEL', cdfid, varid, 'name') %% %% status = ncmex('RECPUT', cdfid, recnum, [data], autoscale, recdim) %% [[data], status] = ncmex('RECGET', cdfid, recnum, autoscale, recdim) %% [[recvarids], [recsizes], status] = ncmex('RECINQ', cdfid, recdim) %% %% len = ncmex('TYPELEN', datatype) %% old_fillmode = ncmex('SETFILL', cdfid, fillmode) %% %% old_ncopts = ncmex('SETOPTS', ncopts) %% ncerr = ncmex('ERR') %% code = ncmex('PARAMETER', 'NC_...') %% %% Notes: %% 1. The rcode is always zero. %% 2. The dimid can be number or name. %% 3. The varid can be number or name. %% 4. The attname can be name or number. %% 5. The operation and parameter names are not case-sensitive. %% 6. The cmode defaults to 'NC_NOCLOBBER'. %% 7. The mode defaults to 'NC_NOWRITE'. %% 8. The value -1 determines length automatically. %% 9. The operation names can prepend 'nc'. %% 10. The parameter names can drop 'NC_' prefix. %% 11. Dimensions: Matlab (i, j, ...) <==> [..., j, i] NetCDF. %% 12. Indices and identifiers are zero-based. %% 13. One-dimensional arrays are returned as column-vectors. % %% 14. Scaling can be automated via 'scale_factor' and 'add_offset'. % %% Copyright (C) 1992-1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Version of 16-May-96 at 10:17:47.75. %% Version of 06-Jan-97 at 14:04:00. %% Version of 12-Feb-97 at 14:08:00. %% Updated 08-Dec-2000 14:09:48. %% Updated 27-Apr-2001 09:19:06. % Added WetCDF trap. % %persistent WETCDF_IS_ACTIVE % %if nargin < 1, help ncmex, return, end % %% WetCDF gateway. % %if isempty(WETCDF_IS_ACTIVE) % WETCDF_IS_ACTIVE = ~~0; %end % %if isequal(varargin{1}, 'wetcdf') % if nargin > 1 % WETCDF_IS_ACTIVE = isequal(varargin{2}, 'on') | ... % isequal(varargin{2}, '1') | ... % isequal(varargin{2}, logical(1)); % end % if nargout > 0, varargout{1} = WETCDF_IS_ACTIVE; end % return %end % %if WETCDF_IS_ACTIVE % if nargout < 1 % wcmex(varargin{:}); % else % varargout = cell(1, nargout); % [varargout{:}] = wcmex(varargin{:}); % end % return %end % %% Mex-file gateway. % %v = version; %if eval(v(1)) > 4 % fcn = 'mexcdf53'; % Matlab-5 or 6. %elseif eval(v(1)) == 4 % fcn = 'mexcdf4'; % Matlab-4 only. %else % error(' ## Unrecognized Matlab version.') %end % %% The "record" routines are emulated. % %op = lower(varargin{1}); %if any(findstr(op, 'rec')) % fcn = op; % if ~strcmp(fcn(1:2), 'nc') % fcn = ['nc' fcn]; % end % varargin{1} = []; %end % %% Matlab-5 comma-list syntax. % %if nargout > 0 % varargout = cell(1, nargout); % [varargout{:}] = feval(fcn, varargin{:}); %else % feval(fcn, varargin{:}); %end fclose(fout); disp(' ## Installing: "ncmkmask.m" (text)') fout = fopen('ncmkmask.m', 'w'); %function theResult = ncmkmask(inFile, outFile, fillValue) % %% ncmkmask -- Make a NetCDF "mask" file. %% ncmkmask('inFile', 'outFile', fillValue) creates a "mask" %% file named 'outFile', based on the 'inFile'. The output %% variables have the names and dimensions of the input %% variables, but they contain byte-data, filled with the %% given fillValue (default = 0). Attributes are ignored. %% If a file is entered as an open "netcdf" object, it %% will remain open at the end of this routine. Use '*' %% to open a file via dialog. % %% 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 06-Jan-1999 17:59:45. % %VERBOSE = 1; % %if nargout > 0, theResult = []; end % %if nargin < 1, help(mfilename); end %if nargin < 1, inFile = '*'; end %if nargin < 2, outFile = '*'; end % %if nargin < 3, fillValue = 0; end %if ischar(fillValue), fillValue = eval(fillValue); end % %% Input file. % %if isa(inFile, 'netcdf') % f = inFile; %else % f = netcdf(inFile, 'nowrite'); %end % %if isempty(f), return, end % %% Output file. % %if isa(outFile, 'netcdf') % g = outFile; %elseif any(outFile == '*') % [p, outFile, e, v] = fileparts(name(f)); % outFile = ['*' outFile '.msk']; % g = netcdf(outFile, 'clobber'); %else % g = netcdf(outFile, 'noclobber'); %end % %if isempty(g) & ~isa(inFile, 'netcdf') % close(f) % return %end % %% Creation information. % %g.CreatedBy = mfilename; %g.CreatedOn = datestr(now); %g.BasedOnFile = name(f); % %% Transfer the dimensions. % %if VERBOSE % disp([' ## Data File: ' name(f)]) % disp([' ## Mask File: ' name(g)]) % disp(' ## Defining dimensions ...') %end % %d = dim(f); %for i = 1:length(d) % if isrecdim(d{i}) % theLength = 0; % Record-dimension. % else % theLength = length(d{i}); % end % if VERBOSE, disp([' ## ' name(d{i}) ' ...']), end % g(name(d{i})) = theLength; %end % %% Re-create the variables as "byte" data. % %if VERBOSE, disp(' ## Defining variables ...'), end %v = var(f); %for i = 1:length(v) % if VERBOSE, disp([' ## ' name(v{i}) ' ...']), end % d = ncnames(dim(v{i})); % Dim. names. % g{name(v{i})} = ncbyte(d{:}); % New variable. % g{name(v{i})}.FillValue_ = fillValue; % Fill it. %end % %g = endef(g); % %% Expand record-variables, if any. % %r = recdim(g); %if ~isempty(r) % if VERBOSE, disp(' ## Filling record-variables ...'), end % v = var(r); % for i = 1:length(v) % if VERBOSE, disp([' ## ' name(v{i}) ' ...']), end % sz = ncsize(f{name(v{i})}); % for i = 1:length(sz) % indices{i} = sz(i); % end % v{i}(indices{:}) = fillValue; % end %end % %% Done. % %if VERBOSE, disp(' ## Done.'), end %if ~isa(outFile, 'netcdf'), close(g), end %if ~isa(inFile, 'netcdf'), close(f), end fclose(fout); disp(' ## Installing: "ncmovie.m" (text)') fout = fopen('ncmovie.m', 'w'); %function theResult = ncmovie(theNetCDF, theMovieName, theMovieSpeed) % %% ncmovie -- Play a NetCDF/Matlab movie file. %% ncmovie('theNetCDF', 'theMovieName') opens 'theNetCDF' file %% and plays 'theMovieName' (default = 'movie') at theMovieSpeed %% (frames/s; default = 4). This routine calls "movie1" to play %% frame-by-frame. A more sophisticated scheme would load several %% frames at a time. % %% 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-Nov-1999 08:49:47. %% Updated 10-Nov-1999 09:06:49. % %if nargout > 0, theResult = []; end % %if nargin < 1 % help(mfilename) % theNetCDF = '*'; %end % %if nargin < 2, theMovieName = 'movie'; end %if nargin < 3, theMovieSpeed = 4; end % %nc = netcdf(theNetCDF, 'nowrite'); %if isempty(nc), return, end % %theMovie = nc{theMovieName}; % %if isempty(theMovie) % disp([' ## No such movie: ' theMovieName]) % close(nc) % return %end % %[m, nFrames] = size(theMovie); % %for frame = 1:nFrames % theFrame = theMovie(:, frame); % movie1(theFrame, theMovieSpeed) %end % %close(nc) fclose(fout); disp(' ## Installing: "ncnames.m" (text)') fout = fopen('ncnames.m', 'w'); %function theResult = NCNames(theNCItems) % %% NCNames -- List of ncitem names. %% NCNames(theNCItems) returns the list %% of names corresponding to theNCItems, %% a cell-array of NetCDF objects derived %% from the "ncitem" class. % %% 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. % %if nargin < 1, help(mfilename), return, end % %if ~iscell(theNCItems), theNCItems = {theNCItems}; end % %theNCNames = cell(size(theNCItems)); % %for i = 1:length(theNCItems) % if isa(theNCItems{i}, 'ncitem') % theNCNames{i} = name(theNCItems{i}); % end %end % %if nargin > 0 % theResult = theNCNames; % else % disp(theNCNames) %end fclose(fout); disp(' ## Installing: "ncpath.m" (text)') fout = fopen('ncpath.m', 'w'); %function ncpath % %% ncpath -- Check NetCDF Toolbox paths. %% ncpath (no arguments) checks the existing Matlab path %% for essential files and directories. The "mexcdf53" %% function must be a "Mex-file", whereas the others %% refer to "M-files". % %% 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 28-Dec-2000 11:58:17. %% Updated 28-Dec-2000 14:48:07. % %help(mfilename) % %f = { % 'mexcdf53' % 'ncmex' % 'netcdf' % 'ncitem' % 'ncatt' % 'ncdim' % 'ncvar' % 'ncrec' % 'ncbrowser' % 'ncutility' % 'nctype' % 'listpick' % }; % %oldPWD = pwd; %setdef(mfilename) %cd .., cd .. % %some_missing = 0; %for i = 1:length(f) % w = which(f{i}); % if i == 1 & ~isempty(w) & exist(f{i}, 'file') ~= 3 % disp([' ## Warning: "' f{1} '"appears not to be a Mex-file.']) % end % if isempty(w), w = '(none found)'; some_missing = 1; end % disp([' ## Path to "' f{i} '": ' w]) %end % %if some_missing % disp(' ') % disp([' ## Please locate the missing files,']) % disp([' ## adjust the Matlab path accordingly,']) % disp([' ## then run "ncpath" again.']) %end % %cd(oldPWD) %disp([' ## ' pwd]) fclose(fout); disp(' ## Installing: "ncquiet.m" (text)') fout = fopen('ncquiet.m', 'w'); %function ncquiet % %% NCQuiet -- Set NetCDF options to non-verbose. %% NCQuiet (no argument) sets the NetCDF options %% to non-verbose. % %% 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 12-Jun-1997 16:54:35. %% Updated 08-Dec-2000 13:39:26. % %ncmex('setopts', 0); fclose(fout); disp(' ## Installing: "ncrecget.m" (text)') fout = fopen('ncrecget.m', 'w'); %function [data, status] = ncrecget(ncid, recnum, ... % autoscale, recdim) % %% ncrecget -- Emulator for broken mexcdf('recget', ...). %% [data, status] = ncrecget(ncid, recnum, autoscale, recdim) %% reads the record whose record number is recnum, from the %% netcdf file whose id is ncid. The resulting data are stored %% in a single row-vector. If autoscale is non-zero, then %% the autoscale facility will be invoked. If a recdim is %% given, it substitutes for the actual recdim in the file, %% if any. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if nargin < 1, help ncrecget; return, end %if nargin < 2, recnum = 0; end %if nargin < 3, autoscale = 0; end %if nargin < 4, recdim = -1; end % %if recdim == -1 % [ndims, nvars, ngatts, recdim] = ncmex('inquire', ncid); % else % [ndims, nvars, ngatts] = ncmex('inquire', ncid); %end % %if recdim >= ndims, error(' ## Invalid recdim.'), end % %data = []; %status = 0; % %[varids, varsizes, status] = ncmex('recinq', ncid); % %if status == -1, return, end % %for i = 1:length(varids) % [varname, datatype, ndims, dimids, natts, status] = ... % ncmex('varinq', ncid, varids(i)); % if status == -1, return, end % dimsizes = zeros(1, ndims); % for j = 1:ndims % [dimname, dimsize, status] = ... % ncmex('diminq', ncid, dimids(j)); % if dimsize == 0, dimsize = 1; end % if status == -1, return, end % dimsizes(j) = dimsize; % end % f = find(dimids == recdim); % starts = dimsizes .* 0; % starts(f) = recnum; % counts = dimsizes; % counts(f) = 1; % [x, status] = ... % ncmex('varget', ncid, varids(i), starts, counts, autoscale); % if status == -1, return, end % data = [data x(:).']; %end fclose(fout); disp(' ## Installing: "ncrecinq.m" (text)') fout = fopen('ncrecinq.m', 'w'); %function [varids, varsizes, status] = ncrecinq(ncid, recdim) % %% ncrecinq -- emulator for mexcdf4('ncrecinq', ...). %% [narids, varsizes, status] = ncrecinq(ncid, recdim) %% inquires about records stored in the NetCDF file whose %% id is ncid. If recdim is provided, it substitutes for %% the actual recdim in the file, if any. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Updated 08-Dec-2000 13:48:14. % %if nargin < 1, help ncrecinq, return, end %if nargin < 2, recdim = -1; end % %if recdim == -1 % [ndims, nvars, ngatts, recdim] = ncmex('inquire', ncid); % else % [ndims, nvars, ngatts] = ncmex('inquire', ncid); %end % %if recdim >= ndims, error(' ## Invalid recdim.'), end % %status = 0; % %varids = []; %varsizes = []; %for i = 1:nvars % varid = i-1; % [varname, datatype, ndims, dimids] = ... % ncmex('varinq', ncid, varid); % if any(dimids == recdim) % varids = [varids; varid]; % varsize = 1; % for j = 1:length(dimids) % dimid = dimids(j); % if dimid ~= recdim % [dimname, dimsize] = ncmex('diminq', ncid, dimid); % varsize = varsize .* dimsize; % end % end % varsizes = [varsizes; varsize]; % end %end fclose(fout); disp(' ## Installing: "ncrecput.m" (text)') fout = fopen('ncrecput.m', 'w'); %function status = ncrecput(ncid, recnum, data, ... % autoscale, recdim) % %% ncrecget -- Emulator for broken mexcdf('recput', ...). %% status = ncrecput(ncid, recnum, data, autoscale) writes %% the record whose record number is recnum, to the netcdf %% file whose id is ncid. The data are expected to be %% a single row-vector. If autoscale is non-zero, then %% the autoscale facility will be invoked. if recdim is %% provided, it substitutes for the actual recdim in the %% file, if any. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if nargin < 1, help ncrecput; return, end %if nargin < 4, autoscale = 0; end %if nargin < 5, recdim = -1; end % %if recdim == -1 % [ndims, nvars, ngatts, recdim] = ncmex('inquire', ncid); % else % [ndims, nvars, ngatts] = ncmex('inquire', ncid); %end % %if recdim >= ndims, error(' ## Invalid recdim.'), end % %status = 0; %[varids, varsizes, status] = ncmex('recinq', ncid); %if status == -1, return, end % %k = 0; %for i = 1:length(varids) % [varname, datatype, ndims, dimids, natts, status] = ... % ncmex('varinq', ncid, varids(i)); % if status == -1, return, end % dimsizes = zeros(1, ndims); % for j = 1:ndims % [dimname, dimsize, status] = ... % ncmex('diminq', ncid, dimids(j)); % if dimsize == 0, dimsize = 1; end % if status == -1, return, end % dimsizes(j) = dimsize; % end % f = find(dimids == recdim); % starts = dimsizes .* 0; % starts(f) = recnum; % counts = dimsizes; % counts(f) = 1; % x = data(k+1:k+prod(counts)); % status = ... % ncmex('varput', ncid, varids(i), starts, counts, x, autoscale); % if status == -1, return, end % k = k + prod(counts); %end fclose(fout); disp(' ## Installing: "ncrectest.m" (text)') fout = fopen('ncrectest.m', 'w'); %function ncrectest(nrecords) % %% ncrectest -- Test of ncrecput/ncrecget. %% ncrectest(nrecords) exercises the netcdf test-file %% 'foo.cdf' by writing/reading nrecords, using %% ncrecinq(), ncrecput() and ncrecget(). % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Version of 17-Apr-96 at 16:45:57.08. %% Updated 08-Dec-2000 13:58:07. % %if nargin < 1, nrecords = 1; end % %x = 1:201; % %ncid = ncmex('open', 'foo.cdf', 'write'); % %[varids, varsizes, status] = ncrecinq(ncid); % %disp(' ## Variable ids and sizes:') %disp([varids; varsizes]) % %varid = 2; %for recnum = 0:nrecords-1 % status = ncmex('varput', ncid, varid, recnum, 1, 9999); % [d, status] = ncmex('varget', ncid, varid, recnum, 1); %end % %okay = 1; % %d = []; %for recnum = 0:nrecords-1 % status = ncrecput(ncid, recnum, x); % [d, status] = ncrecget(ncid, recnum); % if any(d(:) ~= x(:)) % disp([' ## Bad round trip: record ' int2str(recnum)]) % okay = 0; % end %end % %status = ncmex('close', ncid); % %if okay, disp(' ## Successful test.'), end fclose(fout); disp(' ## Installing: "ncsave.m" (text)') fout = fopen('ncsave.m', 'w'); %function theResult = ncsave(theNetCDFFile, varargin) % %% ncsave -- Save NetCDF variables. %% ncsave('theNetCDFFile', 'var1', 'var2', ...) saves the %% given variables in 'theNetCDFFile'. The variables must %% already have been defined in the file, and the output %% data must be properly sized. This routine does not %% alter the structure of the file itself; only the %% given variables are updated. If no variables are %% given, the caller's entire workspace is attempted. %% No attributes are updated. % %% 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-Aug-1997 10:19:05. % %if nargin < 1, help(mfilename), return, end % %result = []; %if nargout > 0, theResult = result; end % %f = netcdf(theNetCDFFile, 'write'); %if isempty(f), return, end % %if length(varargin) < 1 % varargin = evalin('caller', 'who', '{}'); %end % %result = cell(1, length(varargin)); %for i = 1:length(varargin) % theName = varargin{i}; % if ~isstr(theName), theName = inputname(i+1); end % result{i} = ''; % okay = 1; % x = evalin('caller', theName, 'okay = 0; [];'); % if okay % switch class(x) % case {'char', 'double', 'uint8'} % v = f{theName}; % if ~isempty(v) & prod(size(v)) == prod(size(x)) % v(:) = x; % result{i} = theName; % end % otherwise % end % end %end % %close(f) % %if nargout > 0 % theResult = result; %else % ncans(result) %end fclose(fout); disp(' ## Installing: "ncsize.m" (text)') fout = fopen('ncsize.m', 'w'); %function theResult = ncsize(x) % %% ncsize -- NCSIZE() for non-NetCDF objects. %% ncsize(x) returns the size of x. This routine %% also posts a warning whenever called. % %% 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-Dec-1998 09:43:20. % %warning(' ## Please use SIZE for non-NetCDF entities.') % %result = size(x); % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ncstartup.m" (text)') fout = fopen('ncstartup.m', 'w'); %function ncstartup % %% ncstartup -- Startup script for the NetCDF Toolbox. %% ncstartup (no argument) adjusts the Matlab path %% to include the components of the NetCDF Toolbox. %% %% A call to this "ncstartup" script should be made %% during Matlab startup, such as from within the %% "startup" script that is reserved for just such %% purposes. Adjust the path below as needed. %% %% Alternatively, place the appropriate "addpath" %% commands directly in the "startup.m" file. % %% 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 03-Jul-1997 09:09:29. %% Updated 12-Apr-2000 13:26:34. % %% These statements assume that the NetCDF Toolbox is %% located in the conventional Matlab "toolbox" area. %% Adjust as needed. % %toolbox_area = 'toolbox'; % %path(path, fullfile(matlabroot, toolbox_area, 'netcdf', '')) %path(path, fullfile(matlabroot, toolbox_area, 'netcdf', 'nctype', '')) %path(path, fullfile(matlabroot, toolbox_area, 'netcdf', 'ncutility', '')) %path(path, fullfile(matlabroot, toolbox_area, 'netcdf', 'ncfiles', '')) fclose(fout); disp(' ## Installing: "ncswap.m" (text)') fout = fopen('ncswap.m', 'w'); %function ncswap(theSrc, theDst, theDim1, theDim2) % %% ncswap -- Swap order of dimensions. %% ncswap('theSrc', 'theDst', 'theDim1', 'theDim2') swaps %% the order of 'theDim1' and 'theDim2' dimensions in all %% participating variables of 'theSrc' file. The result %% is placed in 'theDst' file (new file of different name). %% ncswap (no arguments) invokes dialogs to get the calling %% arguments. The routine continually asks for input until %% a dialog's "Cancel" button is pressed. %% %% N.B. This routine needs to be upgraded to be more mindful %% of "record" variables. See line #112. % %% 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-Jan-1998 17:19:31. % %if nargin < 1, help(mfilename), end % %oldPath = pwd; % %while (1) % if nargin < 1 % [theFile, thePath] = uigetfile('*.*', 'Select NetCDF File'); % if ~any(theFile), break, end % theSrc = [thePath theFile]; % cd(thePath) % end % if nargin < 2 % theSuggested = [theFile '.swap.nc']; % [theFile, thePath] = uiputfile(theSuggested, 'Save As NetCDF File:'); % if ~any(theFile), break, end % theDst = [thePath theFile]; % cd(thePath) % end % f = netcdf(theSrc, 'nowrite'); % if isempty(f), break, end % g = netcdf(theDst, 'clobber'); % if isempty(g), close(f), break, end % okay = 1; % if nargin < 4 % d = ncnames(dim(f)); % thePrompt = {'Pick Two Dimensions', 'Dimensions', 'Swap'}; % theName = 'Swap Dimensions'; % theMode = 'unique'; % okay = 0; % while ~okay % s = listpick(d, thePrompt, theName, theMode); % if length(s) == 0 % break % elseif length(s) == 2 % okay = 1; % theDim1 = s{1}; % theDim2 = s{2}; % end % thePrompt{1} = 'Pick EXACTLY Two Dimensions'; % end % end % if ~okay, close(g), close(f), break, end % g < dim(f); % Copy dimensions. % g < att(f); % Copy global attributes. % v = var(f); % Work on variables. % w = cell(size(v)); % for k = 1:length(v) % Define the variables. % theDims = dim(v{k}); % i1 = 0; % i2 = 0; % for i = 1:length(theDims) % if isequal(name(theDims{i}), theDim1) % i1 = i; % end % if isequal(name(theDims{i}), theDim2) % i2 = i; % end % end % if i1 > 0 & i2 > 0 % temp = theDims{i1}; % theDims{i1} = theDims{i2}; % theDims{i2} = temp; % end % w{k} = ncvar(name(v{k}), datatype(v{k}), ncnames(theDims), g); % a = att(v{k}); % Copy variable attributes. % for i = 1:length(a), w{k} < a{i}; end % end % for k = 1:length(v) % Fill the variables. % theDims = dim(v{k}); % i1 = 0; % i2 = 0; % for i = 1:length(theDims) % if isequal(name(theDims{i}), theDim1) % i1 = i; % end % if isequal(name(theDims{i}), theDim2) % i2 = i; % end % end % order = 1:length(theDims); % while length(order) < 2 % order = [order length(order)+1]; % end % if i1 > 0 & i2 > 0 % temp = order(i1); % order(i1) = order(i2); % order(i2) = temp; % end % now_filling = name(w{k}); %% Record-variables hate the next line. Needs improvement. % w{k}(:) = permute(v{k}(:), order); % Permute and stash. % end % close(g) % close(f) % if nargin > 1, break, end %end % %eval(['cd ' oldPath]) fclose(fout); disp(' ## Installing: "nctrim.m" (text)') fout = fopen('nctrim.m', 'w'); %function theResult = nctrim(theSrc, theDst, theIndices, theRecdim, isVerbose) % %% nctrim -- Trim records in a NetCDF file. %% nctrim('theSrc', 'theDst', theIndices, 'theRecdim') %% copies 'theSrc' NetCDF file to 'theDst', trimming %% all record-variables to just theIndices. The %% "apparent" record-dimension name can be specified %% in 'theRecdim' -- it must be the left-most dimension %% in variables that are to be treated as record-variables. %% Defaults: '', '', [], ''. %% nctrim('', ...) invokes the "uigetfile" dialog. %% nctrim(..., isVerbose) displays progress information %% if isVerbose is logically TRUE. % %% 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 13-Jan-1998 14:27:57. %% Updated 10-Aug-1999 16:30:19. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2, theDst = ''; end %if nargin < 3, theIndices = []; end %if nargin < 5, isVerbose = 0; end % %if nargout > 0, theResult = []; end % %% Open the source file. % %if isempty(theSrc) % src = netcdf('nowrite') %elseif ischar(theSrc) % src = netcdf(theSrc, 'nowrite') %elseif isa(theSrc, 'ncitem') % src = parent(parent(theSrc)); %else % disp(' ## Unknown source argument.') % return %end %if isempty(src) % disp(' ## No source file.') % return %end % %% Get the record-dimension. % %if nargin < 4, theRecdim = recdim(src); end % %if isempty(theRecdim) % disp(' ## No record-dimension found.') % close(src) % return %end % %% Open the destination file. % %if isempty(theDst) % dst = netcdf('clobber') %elseif ischar(theDst) % dst = netcdf(theDst, 'clobber') %elseif isa(theSrc, 'ncitem') % dst = parent(parent(theDst)); % theDst = name(dst); % close(dst) % dst = netcdf(theDst, 'clobber') %else % close(src) % disp(' ## Unknown destination argument.') % return %end %if isempty(dst) % close(src) % disp(' ## No destination file.') % return %end % %% Copy the global attributes. % %dst < att(src); % %if ~isempty(theRecdim) & ischar(theRecdim) % theRecdim = src(theRecdim) %else % theRecdim = recdim(src) %end % %% Define the destination dimensions. % %theDims = dim(src); %for i = 1:length(theDims) % theSize = size(theDims{i}); % if isequal(name(theDims{i}), name(theRecdim)) % theSize = 0; % end % dst(name(theDims{i})) = theSize; %end % %% Define the destination variables and attributes. % %theVars = var(src); %for i = 1:length(theVars) % copyData = 0; % copyAtts = 1; % copy(theVars{i}, dst, copyData, copyAtts); %end % %% Copy the fixed-variable data. % %for i = 1:length(theVars) % theDims = dim(theVars{i}); % if length(theDims) > 0 % if ~isequal(name(theDims{1}), name(theRecdim)) % if isVerbose % disp([' ## ' mfilename ': copying "' name(theVars{i}) '"']) % end % dst{name(theVars{i})}(:) = theVars{i}(:); % end % else % dst{name(theVars{i})}(:) = theVars{i}(:); % end %end % %% Copy the trimmed record-variable data. % %if length(theIndices) > 0 % theIndices = sort(theIndices); % Indices sorted. % f = find(diff(theIndices) == 0); % if any(f), theIndices(f) = []; end % Unique indices only. % k = 1:length(theIndices); % for i = 1:length(theVars) % theDims = dim(theVars{i}); % if length(theDims) > 0 % if isequal(name(theDims{1}), name(theRecdim)) % if isVerbose % disp([' ## ' mfilename ': trimming "' name(theVars{i}) '"']) % end % dst{name(theVars{i})}(k, :) = theVars{i}(theIndices, :); % end % end % end %end % %% Done. % %close(src) % Close src. %if nargout > 0 % theResult = dst; % Keep dst open. %else % close(dst) % Close dst. %end fclose(fout); disp(' ## Installing: "ncutility.m" (text)') fout = fopen('ncutility.m', 'w'); %function ncutility % %% ncutility -- Switch to the ncutility directory. %% ncutility (no arguments) switches to the directory %% that contains the ncutility routines. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %setdef ncutility fclose(fout); disp(' ## Installing: "ncverbose.m" (text)') fout = fopen('ncverbose.m', 'w'); %function ncverbose % %% NCVerbose -- Set NetCDF options to "verbose". %% NCVerbose (no argument) sets the NetCDF options %% to "verbose". % %% 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 12-Jun-1997 16:54:35. %% Updated 08-Dec-2000 13:42:39. % %ncmex('setopts', ncmex('parameter', 'verbose')); fclose(fout); disp(' ## Installing: "ncversion.m" (text)') fout = fopen('ncversion.m', 'w'); %function theNCVersion = NCVersion % %% NCVersion (no argument) returns or displays the modification %% date of the current "NetCDF Toolbox For Matlab-5". % %% 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 05-Sep-1997 08:58:30. % %theVersion = help('ncitem/version'); %f = find(theVersion >= '0' & theVersion <= '9'); %if any(f), theVersion = theVersion(f(1):f(length(f))); end % %if nargout < 1 % disp([' ## http://crusty.er.usgs.gov/~cdenham']) % disp([' ## NetCDF Toolbox For Matlab-5.']) % disp([' ## Version of ' theVersion]) %else % theNCVersion = theVersion; %end fclose(fout); disp(' ## Installing: "ncweb.m" (text)') fout = fopen('ncweb.m', 'w'); %function theResult = ncweb % %% ncweb -- World Wide Web site of the NetCDF Toolbox. %% ncweb (no argument) displays or returns the WWW %% site for the NetCDF Toolbox. If displayed, %% a dialog asks whether to go there. % %% 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 28-Apr-1999 19:30:28. %% Updated 18-Sep-2002 14:37:43. % %theURL = ['http://woodshole.er.usgs.gov/' ... % 'staffpages/cdenham/MexCDF/nc4ml5.html']; % %if nargout > 0 % theResult = theURL; %else % disp(['## NetCDF Toolbox Home Page:']) % disp(['## ' theURL]) % theButton = questdlg('Go To NetCDF Toolbox Home Page?', 'WWW', 'Yes', 'No', 'No'); % if isequal(theButton, 'Yes') % theStatus = web(theURL); % switch theStatus % case 1 % disp(' ## Could not find Web Browser.') % disp(' ## See "help web".') % case 2 % disp(' ## Web Browser found, but could not be launched.') % disp(' ## See "help web".') % help('web') % otherwise % end % end %end fclose(fout); disp(' ## Installing: "ncwhatsnew.m" (text)') fout = fopen('ncwhatsnew.m', 'w'); %function ncwhatsnew % %% ncwhatsnew -- What's new in the NetCDF Toolbox. %% ncwhatsnew emits a "what's new" message the first time %% it is called. % %% 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-Dec-1998 10:47:04. %% Updated 19-Jul-1999 11:07:43. % %global NC_WHATS_NEW_DISPLAYED % %if isempty(NC_WHATS_NEW_DISPLAYED) & 0 % disp(' ') % disp(' ## WHAT''S NEW in the NetCDF Toolbox') % disp(' ') % disp(' ## Starting January 1, 1999, the "size" function for') % disp(' ## netcdf items will return at least two elements,') % disp(' ## following the Matlab convention. To get the old') % disp(' ## style of size-vector, use "ncsize".') % disp(' ') % v = version; % if isequal(v(1:3), '5.3') % disp(' ## Matlab v5.3 (Release 11) Alert -- Changes to the') % disp(' ## Matlab object-oriented scheme required that we patch') % disp(' ## the NetCDF Toolbox. The present toolbox seems to be') % disp(' ## compatible with v5.3. Please let us know if you notice') % disp(' ## otherwise: (14Apr1999).') % disp(' ') % end % NC_WHATS_NEW_DISPLAYED = 1; %end fclose(fout); disp(' ## Installing: "netcdf_bundle.m" (text)') fout = fopen('netcdf_bundle.m', 'w'); %function netcdf_bundle % %% netcdf_bundle -- Bundle the NetCDF Toolbox. %% netcdf_bundle (no argument) bundles the NetCDF Toolbox %% to produce the installer "nc_install.m". % %% 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 15-Jun-2001 16:56:19. %% Updated 25-Apr-2003 11:58:00. % %theClasses = { % 'listpick' % 'ncatt' % 'ncbrowser' % 'ncdim' % 'ncitem' % 'ncrec' % 'ncvar' % 'netcdf' %}; % %for i = 1:length(theClasses) % newversion(theClasses{i}) %end % %theDirs = cell(size(theClasses)); % %theDirs = { % 'netcdf' % 'netcdf:ncfiles' % 'netcdf:nctype' % 'netcdf:ncutility' %}; %for i = 1:size(theClasses) % theDirs{end+1} = ['netcdf:@' theClasses{i}]; %end % %theTypes = { % 'ncbyte' % 'ncchar' % 'ncshort' % 'nclong' % 'ncint' % 'ncfloat' % 'ncdouble' % 'nctype' % 'ncsetstr' %}; % %theUtilities = { % mfilename % 'begets' % 'busy' % 'fcopy' % 'filesafe' % 'findpt' % 'getinfo' % 'geturl' % 'geturl.mac' % 'guido' % 'idle.m' % 'labelsafe' % 'maprect' % 'mapsubs' % 'mat2nc' % 'mexcdf.m' % 'modplot' % 'movie1' % 'nc2cdl' % 'nc2mat' % 'ncans' % 'ncbevent' % 'nccat' % 'nccheck' % 'ncclass' % 'ncclear' % 'ncclose' % 'ncdimadd' % 'ncdim2rec' % 'ncdump' % 'ncdumpd' % 'ncdumph' % 'ncexample' % 'ncextract' % 'ncfillvalues' % 'ncillegal' % 'ncind2slab' % 'ncind2sub' % 'ncload' % 'ncmemory' % 'ncmex' % 'ncmkmask' % 'ncmovie' % 'ncnames' % 'ncpath' % 'ncquiet' % 'ncrecget' % 'ncrecinq' % 'ncrecput' % 'ncrectest' % 'ncsave' % 'ncsize' % 'ncstartup' % 'ncswap' % 'nctrim' % 'ncutility' % 'ncverbose' % 'ncversion' % 'ncweb' % 'ncwhatsnew' % 'numel_default' % 'rbrect' % 'setinfo' % 'stackplot' % 'switchsafe' % 'super' % 'tmexcdf' % 'tnc4ml5' % 'tncbig' % 'tncdotted' % 'tncorder' % 'tncmex' % 'tnetcdf' % 'tscalar' % 'uilayout' % 'var2str' % 'vargstr' % 'zoomsafe' %}; % %theSources = { % 'mexcdf.h' % 'mexcdf53.c' % 'make_mexcdf53.m' %}; % %theMessages = { % ' ' % ' ## Adjust the Matlab path to include, relative to Current Directory:' % ' ## "netcdf"' % ' ## "netcdf:ncfiles"' % ' ## "netcdf:nctype"' % ' ## "netcdf:ncutility"' % ' ## Make sure the Matlab path knows where the' % ' ## "mexcdf53" Mex-file and (PCWIN only)' % ' ## "netcdf.dll" are located.' % ' ## Restart Matlab.' % ' ## Execute "rehash toolboxcache", then' % ' ## "tnetcdf" at the Matlab prompt.' %}; % %theClasses = sort(theClasses); %theTypes = sort(theTypes); %theUtilities = sort(theUtilities); %theSources = sort(theSources); % %at(mfilename) % %oldPWD = pwd; % %bund new netcdf % %bund setdir netcdf % %bund('class', theClasses) % %bund setdir ncutility %bund('mfile', theUtilities) %bund cd .. % %bund setdir nctype %bund('mfile', theTypes) %bund cd .. % %tempPWD = pwd; %cd .. %cd ncsource %bund setdir ncsource %bund('text', theSources) %bund cd .. %cd(tempPWD) % %bund setdir ncfiles %bund cd .. % %bund cd .. % %bund('message', theMessages) % %bund close % %cd(oldPWD) fclose(fout); disp(' ## Installing: "numel_default.m" (text)') fout = fopen('numel_default.m', 'w'); %function theResult = numel_default(varargin) % %% class/numel_default -- Default NUMEL method. %% numel_default(...) returns a value of 1. %% It gets called by our overloaded NUMEL %% methods, on the hope that, up to now, we %% have always expected SUBSREF and SUBSASGN %% to deliver or accept just one argument. % %% 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 30-Jul-2001 15:49:47. %% Updated 30-Jul-2001 15:49:47. % %theResult = 1; % Keep fingers crossed. fclose(fout); disp(' ## Installing: "rbrect.m" (text)') fout = fopen('rbrect.m', 'w'); %function theResult = rbrect(onMouseUp, onMouseMove, onMouseDown) % %% rbrect -- Rubber rectangle tracking (Matlab-4 and Matlab-5). %% rbrect('demo') demonstrates itself. %% rbrect('onMouseUp', 'onMouseMove', 'onMouseDown') conducts interactive %% rubber-rectangle tracking, presumably because of a mouse button press %% on the current-callback-object (gcbo). The 'on...' callbacks are %% automatically invoked with: "feval(theCallback, theInitiator, theRect)" %% after each window-button event, using the object that started this %% process, plus theRect as [xStart yStart xEnd yEnd] for the current %% rubber-rect. The callbacks default to ''. The coordinates of the %% rectangle are returned as [xStart yStart xEnd yEnd]. % %% Private interface: %% rbrect(1) is automatically called on window-button-motions. %% rbrect(2) is automatically called on window-button-up. % %% 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 03-Jun-1997 15:54:39. %% Version of 11-Jun-1997 15:17:22. %% Version of 17-Jun-1997 16:52:46. % %global RBRECT_HANDLE %global RBRECT_INITIATOR %global RBRECT_ON_MOUSE_MOVE % %if nargin < 1, onMouseUp = 0; end % %if strcmp(onMouseUp, 'demo') % help rbrect % x = cumsum(rand(200, 1) - 0.45); % y = cumsum(rand(200, 1) - 0.25); % h = plot(x, y, '-r'); % set(h, 'ButtonDownFcn', 'disp(rbrect)') % figure(gcf), set(gcf, 'Name', 'RBRECT Demo') % return % elseif isstr(onMouseUp) % theMode = 0; % else % theMode = onMouseUp; % onMouseUp = ''; %end % % %if theMode == 0 % Mouse down. % if nargin < 3, onMouseDown = ''; end % if nargin < 2, onMouseMove = ''; end % if nargin < 1, onMouseUp = ''; end % theVersion = version; % isVersion5 = (theVersion(1) == '5'); % if isVersion5 % theCurrentObject = 'gcbo'; % else % theCurrentObject = 'gco'; % end % RBRECT_INITIATOR = eval(theCurrentObject); % switch get(RBRECT_INITIATOR, 'Type') % case 'line' % theColor = get(RBRECT_INITIATOR, 'Color'); % otherwise % theColor = 'black'; % end % RBRECT_ON_MOUSE_MOVE = onMouseMove; % pt = mean(get(gca, 'CurrentPoint')); % x = [pt(1) pt(1)]; y = [pt(2) pt(2)]; % RBRECT_HANDLE = line(x, y, ... % 'EraseMode', 'xor', ... % 'LineStyle', '--', ... % 'LineWidth', 2.5, ... % 'Color', theColor, ... % 'Marker', '+', 'MarkerSize', 13, ... % 'UserData', 1); % set(gcf, 'WindowButtonMotionFcn', 'rbrect(1);') % set(gcf, 'WindowButtonUpFcn', 'rbrect(2);') % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(onMouseDown) % feval(onMouseDown, RBRECT_INITIATOR, theRBRect) % end % thePointer = get(gcf, 'Pointer'); % set(gcf, 'Pointer', 'circle'); % if isVersion5 & 0 % Disable for rbrect().. % eval('waitfor(RBRECT_HANDLE, ''UserData'', [])') % else % set(RBRECT_HANDLE, 'Visible', 'off') % Invisible. % eval('rbbox') % No "waitfor" in Matlab-4. % end % set(gcf, 'Pointer', thePointer); % set(gcf, 'WindowButtonMotionFcn', '') % set(gcf, 'WindowButtonUpFcn', '') % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % delete(RBRECT_HANDLE) % theRBRect = [x(1) y(1) x(2) y(2)]; % Scientific. % if ~isempty(onMouseUp) % feval(onMouseUp, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 1 % Mouse move. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y) % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(RBRECT_ON_MOUSE_MOVE) % feval(RBRECT_ON_MOUSE_MOVE, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 2 % Mouse up. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y, 'UserData', []) %else %end % %if nargout > 0, theResult = theRBRect; end fclose(fout); disp(' ## Installing: "setinfo.m" (text)') fout = fopen('setinfo.m', 'w'); %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 fclose(fout); disp(' ## Installing: "stackplot.m" (text)') fout = fopen('stackplot.m', 'w'); %function h = StackPlot(varargin) % %% StackPlot -- Plot of stacked curves. %% StackPlot(x, y, 'theColor', ...) plots the columns %% of y(x) adjacent to each other, with a small margin. %% The syntax is exactly the same as for "plot()". The %% "UserData" property of each line contains its column- %% number and the additive-offset from the original value %% of the column. %% StackPlot(m, n, 'theColor') demonstrates itself with a %% random array of size [m+1 n]. The size defaults to %% [20 5]. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Version of 5-Jun-96 at 12:07:42.99. %% Version of 28-Aug-1997 09:07:13. % %if nargin < 1, help(mfilename), varargin{1} = 20; end % %if isstr(varargin{1}) % if strcmp(varargin{1}, 'demo') % varargin{1} = 20; % else % varargin{1} = eval(varargin{1}); % end %end % %if length(varargin{1}) == 1 % m = varargin{1}; n = fix((m+3)./4); % if nargin > 1, n = varargin{2}; end % x = 1:m; % y = sin(sort(rand(m, n)) * n * pi); % figure('Name', 'StackPlot'); % if nargin < 3 % hh = stackplot(x, y); % else % theColor = varargin{3}; % hh = stackplot(x, y, theColor); % end % if exist('findpt') == 2 % findpt(hh) % end % if exist('zoomsafe') == 2 % zoomsafe % end % if nargout > 0, h = hh; end % return %end % %theYIndex = 1; %if nargin > 1 & ~isstr(varargin{2}) % theYIndex = 2; %end % %y = squeeze(varargin{theYIndex}); %y = reshape(y, size(y, 1), prod(size(y))./size(y, 1)); % %[m, n] = size(y); %if m > 1 % theMargin = (max(max(y)) - min(min(y))) ./ (10 .* n); % theOffset = zeros(1, n); % for j = 2:n % theOffset(j) = max(y(:, j-1)) - min(y(:, j)) + theMargin; % y(:, j) = y(:, j) + theOffset(j); % end %else % theOffset = 0; %end % %varargin{theYIndex} = y; % %hh = plot(varargin{:}); %for theIndex = 1:length(hh) % set(hh(theIndex), 'UserData', [theIndex theOffset(theIndex)]) %end % %if nargout > 0, h = hh; end fclose(fout); disp(' ## Installing: "super.m" (text)') fout = fopen('super.m', 'w'); %function theSuperObject = Super(theObject) % %% Super -- Super-object of an object. %% Super(theObject) returns the super-object %% of theObject, or [] if none exists. % %% 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 04-Apr-1997 16:51:36. % %if nargin < 1, help(mfilename), return, end % %if isobject(theObject) % theStruct = struct(theObject); % else % theStruct = theObject; %end % %f = fieldnames(theStruct); %if ~isempty(f) % s = getfield(theStruct, f{length(f)}); % if ~isobject(s), s = []; end %end % %if nargout > 0 % theSuperObject = s; % else % disp(s) %end fclose(fout); disp(' ## Installing: "switchsafe.m" (text)') fout = fopen('switchsafe.m', 'w'); %function theResult = switchsafe(x) % %% switchsafe -- Make an empty item safe for "switch" command. %% switchsafe(x) returns a version of x, where x is empty, %% that is safe to use in a "switch" statement. % %% 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 19-Mar-2002 14:58:56. %% Updated 08-Apr-2002 10:46:04. % %if nargin < 1, help(mfilename), return, end % %if isempty(x), x = ''; end % %if nargout > 0 % theResult = x; %else % assignin('caller', 'ans', x) %end fclose(fout); disp(' ## Installing: "tmexcdf.m" (text)') fout = fopen('tmexcdf.m', 'w'); %function tmexcdf % %% TMEXCDF Test of MEXCDF Mex-file routines. % %% Copyright (C) 1992-4 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Version of 20-Jan-94. %% Version of 19-Dec-96. %% Version of 15-Jul-1997 08:11:51. % %v = version; %if v(1) == '4' % if exist('mexcdf4') ~= 3 % disp([' ## TMEXCDF -- Please install the "mexcdf4" Mex-file']) % disp([' ## or adjust Matlab path, then try again.']) % return % end % elseif v(1) == '5' % if exist('mexcdf53') ~= 3 % disp([' ## TMEXCDF -- Please install the "mexcdf53" Mex-file']) % disp([' ## or adjust Matlab path, then try again.']) % return % end %end % %% Test of conventional functions. % %tic % %filename = 'foo.nc'; %disp([' TMEXCDF: Using file ' filename]); % %mexcdf('setopts', 0); % Quiet mode. % %for i = 0:3 % status = mexcdf('close', i); %end % %cdfid = mexcdf('create', filename, 'clobber'); %begets('create', 0, cdfid) % %if cdfid < 0, disp('Bad cdfid.'), return, end % %dlat = mexcdf('dimdef', cdfid, 'lat', 10); %dlon = mexcdf('dimdef', cdfid, 'lon', 5); %dtime = mexcdf('dimdef', cdfid, 'time', 'unlimited'); % %vlat = mexcdf('vardef', cdfid, 'lat', 'long', -1, dlat); %vlon = mexcdf('vardef', cdfid, 'lon', 'long', -1, dlon); %vtime = mexcdf('vardef', cdfid, 'time', 'long', -1, dtime); % %dims = [dtime dlat dlon]; % %vz = mexcdf('vardef', cdfid, 'z', 'long', -1, dims); %vt = mexcdf('vardef', cdfid, 't', 'long', -1, dims); %vp = mexcdf('vardef', cdfid, 'p', 'double', -1, dims); %vrh = mexcdf('vardef', cdfid, 'rh', 'long', -1, dims); % %status = mexcdf('attput', cdfid, vlat, 'scale_factor', 'double', -1, 2); %begets('attput', 1, 'scale_factor', status) %status = mexcdf('attput', cdfid, vlat, 'add_offset', 'double', -1, 100); %begets('attput', 1, 'add_offset', status) % %[value, status] = mexcdf('attget', cdfid, vlat, 'scale_factor'); %begets('attget', 1, 'scale_factor', value, status) %[value, status] = mexcdf('attget', cdfid, vlat, 'add_offset'); %begets('attget', 1, 'add_offset', value, status) % %status = mexcdf('attput', cdfid, vlat, 'units', 'char', -1, 'degrees_north'); %status = mexcdf('attput', cdfid, vlon, 'units', 'char', -1, 'degrees_east'); %status = mexcdf('attput', cdfid, vtime, 'units', 'char', -1, 'seconds'); % %status = mexcdf('attput', cdfid, vz, 'units', 'char', -1, 'meters'); %status = mexcdf('attput', cdfid, vz, 'valid_range', 'float', -1, [0 5000]); % %status = mexcdf('attput', cdfid, vp, '_FillValue', 'double', -1, -9999); %status = mexcdf('attput', cdfid, vp, '_FillValue', 'double', -1, NaN); %status = mexcdf('attput', cdfid, vp, '_FillValue', 'double', -1, Inf); %status = mexcdf('attput', cdfid, vp, '_FillValue', 'double', -1, -Inf); % %status = mexcdf('attput', cdfid, vrh, '_FillValue', 'long', -1, -1); % %status = mexcdf('endef', cdfid); %begets('endef', 0, status); % %[ndims, nvars, natts, recdim, status] = mexcdf('inquire', cdfid); %result = [ndims nvars natts recdim status]; %begets('incquire', 1, cdfid, result) % %for i = 0:ndims-1 % [name, len, status] = mexcdf('diminq', cdfid, i); % begets('diminq', 2, cdfid, i, name, len, status) %end % %for i = 0:nvars-1 % [name, datatype, ndims, dim, natts, status] = mexcdf('varinq', cdfid, i); % begets('varinq', 2, cdfid, i, name, datatype, ndims, dim, natts, status) % for j = 0:natts-1 % [name, status] = mexcdf('attname', cdfid, i, j); % begets('attname', 3, cdfid, i, j, name, status) % [value, status] = mexcdf('attget', cdfid, i, name); % begets('attget', 3, cdfid, i, name, value, status) % end %end % %lat = [0 10 20 30 40 50 60 70 80 90].'; %lon = [-140 -118 -96 -84 -52].'; % %for i = 1:length(lat) % status = mexcdf('varput1', cdfid, vlat, i-1, lat(i)); % begets('varput1', 0, status) % [value, status] = mexcdf('varget1', cdfid, vlat, i-1); % begets('varget1', 0, value, status) %end % %[value, status] = mexcdf('vargetg', cdfid, vlat, 0, 10, 1, []); %if value ~= lat(1:10), error('vargetg'), end % %status = mexcdf('varputg', cdfid, vlat, 0, 5, 2, [], lat(1:5)); %[value, status] = mexcdf('vargetg', cdfid, vlat, 0, 10, 1, []); %if value ~= lat(1:10), error('varputg/getg'), end % %[value, status] = mexcdf('vargetg', cdfid, vlat, 0, 5, 2, []); %if value ~= lat(1:5), error('varputg/getg'), end % %status = mexcdf('close', cdfid); %begets('close', 0, status) % %cdfid = mexcdf('open', filename, 'write'); %begets('open', 0, cdfid) % %if cdfid < 0, disp('Bad cdfid.'), return, end % %vlat = mexcdf('varid', cdfid, 'lat'); %begets('varid', 0, vlat); % %status = mexcdf('attput', cdfid, vlat, 'scale_factor', 'double', -1, 1); %begets('attput', 1, 'scale_factor', status) %status = mexcdf('attput', cdfid, vlat, 'add_offset', 'double', -1, 0); %begets('attput', 1, 'add_offset', status) % %[value, status] = mexcdf('attget', cdfid, vlat, 'scale_factor'); %begets('attget', 1, 'scale_factor', value, status) %[value, status] = mexcdf('attget', cdfid, vlat, 'add_offset'); %begets('attget', 1, 'add_offset', value, status) % %[value, status] = mexcdf('varget', cdfid, vlat, 0, length(lat)); %begets('varget', 0, value, status) % %status = mexcdf('varput', cdfid, vlat, 0, length(lat), lat); %status = mexcdf('varput', cdfid, vlat, 0, -1, lat); %begets('varput', 0, status) % %[value, status] = mexcdf('varget', cdfid, vlat, 0, length(lat)); %[value, status] = mexcdf('varget', cdfid, vlat, 0, -1); %begets('varget', 0, value, status) % %status = mexcdf('close', cdfid); %begets('close', 0, status) % %toc % %% Test of functions dealing with records. % %if (1) % %disp(' ## TMEXCDF: Record-testing...') %ncid = mexcdf('open', filename, 'write'); %[ndims, nvars, natts, recid, status] = mexcdf('inquire', ncid); %[dimname, dimlen, status] = mexcdf('diminq', ncid, recid); %[recvars, recsizes, status] = mexcdf('recinq', ncid); %oldopts = mexcdf('setopts', 0); %nrecords = dimlen; %good = 0; %recdata = 1:sum(recsizes); %nrecords = 2; %for i = 0:nrecords-1 % if (1) % status = mexcdf('recput', ncid, i, recdata); % recdata1 = mexcdf('recget', ncid, i); % status = mexcdf('recput', ncid, i, recdata1); % recdata2 = mexcdf('recget', ncid, i); % else % status = ncrecput(ncid, i, recdata); % recdata1 = ncrecget(ncid, i); % status = ncrecput(ncid, i, recdata1); % recdata2 = ncrecget(ncid, i); % end % if any(recdata2 ~= recdata) % disp([' ## Bad round-trip: record #' int2str(i)]) % else % good = good + 1; % end %end %mexcdf('setopts', oldopts); %status = mexcdf('close', ncid); % %if good == nrecords % disp(' ## TMEXCDF: Record-testing successful.') % else % disp(' ## TMEXCDF: Record-testing not successful.') %end % %end fclose(fout); disp(' ## Installing: "tnc4ml5.m" (text)') fout = fopen('tnc4ml5.m', 'w'); %function tnc4ml5 % %% tnc4ml5 -- Test nc4ml5 installation. %% tnc4ml5 (no argument) exercizes some of the %% components of "NetCDF for Matlab-5". % %% 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 15-Apr-1997 09:50:05. % %if isempty(which('mexcdf53')) | (exist('mexcdf53') ~= 3) % disp(' ## Unable to find "mexcdf53" Mex-file gateway.') % disp(' ## Please check your Matlab path:') % path % return %end % %clear mexcdf53 %clear mexcdf ncmex %clear tmexcdf tncmex tnetcdf % %mexcdf53 %mexcdf, ncmex %tmexcdf, tncmex, tnetcdf % %disp('## Testing done.') % %help netcdf fclose(fout); disp(' ## Installing: "tncbig.m" (text)') fout = fopen('tncbig.m', 'w'); %function tncbig(nBytes) % %% tncbig -- Test allowed size of file. %% tncbig(nBytes) creates a NetCDF file, then %% an array of nBytes. On Macintosh and PCWIN, %% we have long had difficulty getting beyond %% about 16K bytes, far too small for real work. %% This has forced us to create larger files %% on Unix machines. Once created, such files %% work on the smaller machines just fine. % %% 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 23-Feb-2000 08:43:12. %% Updated 23-Feb-2000 09:00:51. % %if nargin < 1, nBytes = 2^16; help(mfilename), end %if ischar(nBytes), nBytes = eval(nBytes); end % %theFilename = [mfilename '.nc']; % %n = 0; % %while n < nBytes % n = n + 1000; % disp([' ## n: ' int2str(n)]) % nc = netcdf(theFilename, 'clobber'); % nc('index') = n; % nc{'x'} = ncbyte('index'); % x = nc{'x'}; % x(:) = zeros(1, n); % status = close(nc); % delete(theFilename) % if ~isequal(status, []) % disp(' ') % disp([' ## Unable to close file on ' computer '.']) % break % end %end fclose(fout); disp(' ## Installing: "tncdotted.m" (text)') fout = fopen('tncdotted.m', 'w'); %function tncdotted(whichOne) % %% tncdotted -- Test of dotted and dashed NetCDF names. %% tncdotted('whichOne') exercizes dotted and/or dashed %% NetCDF names. If this function fails, then no such %% names can be created on the present system, though %% it may still be possible to read or write to them. %% It is best to avoid such names altogether. %% %% The 'whichOne' is one of: 'dotted', '.', 'dashed', %% '-', or 'both'. By default, whichOne = 'both'. %% %% Statements using names with dots, dashes or other %% Matlab operators must not violate Matlab syntax. %% The Matlab parser does its work first, then the %% NetCDF language is invoked if deemed appropriate. % %% 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 11-Feb-1998 09:33:14. % %if nargin < 1, whichOne = 'both'; end %if isempty(whichOne), whichOne = 'both'; end % %help(mfilename) % %theNetCDFFile = 'tncdashed.nc'; % %USE_OLD = 0; % %% Test dashed names: fails on some systems. % %switch whichOne %case {'dotted', '.', 'both'} % disp(' ') % disp(' ## Testing dotted NetCDF names.') % disp(' ## If this fails, then dotted names are not allowed.') % f = netcdf(theNetCDFFile, 'clobber'); % f.a.dotted.name = 'a dotted global attribute name'; % f('a.dotted.name') = length('a dotted variable name'); % f{'a.dotted.name'} = ncchar('a.dotted.name'); % f{'a.dotted.name'}.a.dotted.name = 'a dotted variable attribute name'; % f{'a.dotted.name'}(:) = 'a dotted variable name'; % disp(' ## Test of dotted names SUCCESSFUL.') % close(f) % USE_OLD = 1; %end % %% Test dashed names: fails on some systems. % %switch whichOne %case {'dashed', '-', 'both'} % disp(' ') % disp(' ## Testing dashed NetCDF names.') % disp(' ## If this fails, then dashed names are not allowed.') % if USE_OLD % f = netcdf(theNetCDFFile, 'write'); % else % f = netcdf(theNetCDFFile, 'clobber'); % end % ncatt('a-dashed-name', 'a dashed global attribute name', f) % f('a-dashed-name') = length('a dashed variable name'); % f{'a-dashed-name'} = ncchar('a-dashed-name'); % v = f{'a-dashed-name'}; % ncatt('a-dashed-name', 'a dashed global attribute name', v) % f{'a-dashed-name'}(:) = 'a dashed variable name'; % close(f) % disp(' ## Test of dashed names SUCCESSFUL.') %end % %ncdump(theNetCDFFile) fclose(fout); disp(' ## Installing: "tncmex.m" (text)') fout = fopen('tncmex.m', 'w'); %function tncmex % %% TNCMEX -- Test of NCMEX routine, similar to TMEXCDF. % %% 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 13-Mar-97. %% Version of 15-Jul-1997 08:11:51. %% Updated 08-Dec-2000 13:46:14. % %% Test of conventional functions. % %tic % %filename = 'foo.nc'; %disp([' TNCMEX: Using file ' filename]); % %ncmex('setopts', 0); % Quiet mode. % %for i = 0:3 % status = ncmex('close', i); %end % %cdfid = ncmex('create', filename, 'clobber'); %begets('create', 0, cdfid) % %if cdfid < 0, disp('Bad cdfid.'), return, end % %dlat = ncmex('dimdef', cdfid, 'lat', 10); %dlon = ncmex('dimdef', cdfid, 'lon', 5); %dtime = ncmex('dimdef', cdfid, 'time', 'unlimited'); % %vlat = ncmex('vardef', cdfid, 'lat', 'long', -1, dlat); %vlon = ncmex('vardef', cdfid, 'lon', 'long', -1, dlon); %vtime = ncmex('vardef', cdfid, 'time', 'long', -1, dtime); % %dims = [dtime dlat dlon]; % %vz = ncmex('vardef', cdfid, 'z', 'long', -1, dims); %vt = ncmex('vardef', cdfid, 't', 'long', -1, dims); %vp = ncmex('vardef', cdfid, 'p', 'double', -1, dims); %vrh = ncmex('vardef', cdfid, 'rh', 'long', -1, dims); % %status = ncmex('attput', cdfid, vlat, 'scale_factor', 'double', -1, 2); %begets('attput', 1, 'scale_factor', status) %status = ncmex('attput', cdfid, vlat, 'add_offset', 'double', -1, 100); %begets('attput', 1, 'add_offset', status) % %[value, status] = ncmex('attget', cdfid, vlat, 'scale_factor'); %begets('attget', 1, 'scale_factor', value, status) %[value, status] = ncmex('attget', cdfid, vlat, 'add_offset'); %begets('attget', 1, 'add_offset', value, status) % %if (1) % %status = ncmex('attput', cdfid, vlat, 'units', 'char', -1, 'degrees_north'); %status = ncmex('attput', cdfid, vlon, 'units', 'char', -1, 'degrees_east'); %status = ncmex('attput', cdfid, vtime, 'units', 'char', -1, 'seconds'); % %status = ncmex('attput', cdfid, vz, 'units', 'char', -1, 'meters'); %status = ncmex('attput', cdfid, vz, 'valid_range', 'float', -1, [0 5000]); % %end % %status = ncmex('attput', cdfid, vp, '_FillValue', 'double', -1, -9999); %status = ncmex('attput', cdfid, vp, '_FillValue', 'double', -1, NaN); %status = ncmex('attput', cdfid, vp, '_FillValue', 'double', -1, Inf); %status = ncmex('attput', cdfid, vp, '_FillValue', 'double', -1, -Inf); % %status = ncmex('attput', cdfid, vrh, '_FillValue', 'long', -1, -1); % %status = ncmex('endef', cdfid); %begets('endef', 0, status); % %[ndims, nvars, natts, recdim, status] = ncmex('inquire', cdfid); %result = [ndims nvars natts recdim status]; %begets('incquire', 1, cdfid, result) % %for i = 0:ndims-1 % [name, len, status] = ncmex('diminq', cdfid, i); % begets('diminq', 2, cdfid, i, name, len, status) %end % %for i = 0:nvars-1 % [name, datatype, ndims, dim, natts, status] = ncmex('varinq', cdfid, i); % begets('varinq', 2, cdfid, i, name, datatype, ndims, dim, natts, status) % for j = 0:natts-1 % [name, status] = ncmex('attname', cdfid, i, j); % begets('attname', 3, cdfid, i, j, name, status) % [value, status] = ncmex('attget', cdfid, i, name); % begets('attget', 3, cdfid, i, name, value, status) % end %end % %if (0), ncmex('close', cdfid), return, end % %lat = [0 10 20 30 40 50 60 70 80 90]; %lon = [-140 -118 -96 -84 -52]; % %for i = 1:length(lat) % status = ncmex('varput1', cdfid, vlat, i-1, lat(i)); % begets('varput1', 0, status) % [value, status] = ncmex('varget1', cdfid, vlat, i-1); % begets('varget1', 0, value, status) %end % %if (1) % %[value, status] = ncmex('vargetg', cdfid, vlat, 0, 10, 1, []); %if value ~= lat(1:10), error('vargetg'), end % %status = ncmex('varputg', cdfid, vlat, 0, 5, 2, [], lat(1:5)); %[value, status] = ncmex('vargetg', cdfid, vlat, 0, 10, 1, []); %if value ~= lat(1:10), error('varputg/getg'), end % %[value, status] = ncmex('vargetg', cdfid, vlat, 0, 5, 2, []); %if value ~= lat(1:5), error('varputg/getg'), end % %end % %status = ncmex('close', cdfid); %begets('close', 0, status) % %cdfid = ncmex('open', filename, 'write'); %begets('open', 0, cdfid) % %if cdfid < 0, disp('Bad cdfid.'), return, end % %vlat = ncmex('varid', cdfid, 'lat'); %begets('varid', 0, vlat); % %status = ncmex('attput', cdfid, vlat, 'scale_factor', 'double', -1, 1); %begets('attput', 1, 'scale_factor', status) %status = ncmex('attput', cdfid, vlat, 'add_offset', 'double', -1, 0); %begets('attput', 1, 'add_offset', status) % %[value, status] = ncmex('attget', cdfid, vlat, 'scale_factor'); %begets('attget', 1, 'scale_factor', value, status) %[value, status] = ncmex('attget', cdfid, vlat, 'add_offset'); %begets('attget', 1, 'add_offset', value, status) % %if (1) % %[value, status] = ncmex('varget', cdfid, vlat, 0, length(lat)); %begets('varget', 0, value, status) % %status = ncmex('varput', cdfid, vlat, 0, length(lat), lat); %status = ncmex('varput', cdfid, vlat, 0, -1, lat); %begets('varput', 0, status) % %[value, status] = ncmex('varget', cdfid, vlat, 0, length(lat)); %[value, status] = ncmex('varget', cdfid, vlat, 0, -1); %begets('varget', 0, value, status) % %end % %status = ncmex('close', cdfid); %begets('close', 0, status) % %toc % %% Test of functions dealing with records. % %if (1) % %disp(' ## TNCMEX: Record-testing using ncmex...') %ncid = ncmex('open', filename, 'write'); %[ndims, nvars, natts, recid, status] = ncmex('inquire', ncid); %[dimname, dimlen, status] = ncmex('diminq', ncid, recid); %[recvars, recsizes, status] = ncmex('recinq', ncid); %oldopts = ncmex('setopts', 0); %nrecords = dimlen; %good = 0; %recdata = 1:sum(recsizes); %nrecords = 2; %for i = 0:nrecords-1 % if (0) % status = ncmex('recput', ncid, i, recdata); % recdata1 = ncmex('recget', ncid, i); % status = ncmex('recput', ncid, i, recdata1); % recdata2 = ncmex('recget', ncid, i); % else % status = ncrecput(ncid, i, recdata); % recdata1 = ncrecget(ncid, i); % status = ncrecput(ncid, i, recdata1); % recdata2 = ncrecget(ncid, i); % end % if any(recdata2 ~= recdata) % disp([' ## Bad round-trip: record #' int2str(i)]) % else % good = good + 1; % end %end %ncmex('setopts', oldopts); %status = ncmex('close', ncid); % %if good == nrecords % disp(' ## TNCMEX: Record-testing successful.') % else % disp(' ## TNCMEX: Record-testing not successful.') %end % %end fclose(fout); disp(' ## Installing: "tncorder.m" (text)') fout = fopen('tncorder.m', 'w'); %function tncorder(m, n) % %% tncorder -- Test of NetCDF row vs. column dominance. %% tncorder(m, n) shows how a Matlab array of size [m n] %% is actually stored in a NetCDF file. % %% 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-Oct-2002 16:59:50. %% Updated 18-Oct-2002 16:59:50. % %if nargin < 1, help(mfilename), m = 3; end %if nargin < 2, n = m; end % %if ischar(m), m = eval(m); end %if ischar(n), n = eval(n); end % %fclose('all'); % %ncfile = [mfilename '.nc']; % %nc = netcdf(ncfile, 'clobber'); % %nc('i') = m; %nc('j') = n; % %nc{'x'} = ncdouble('i', 'j'); % %matlab_array = zeros(m, n); %matlab_array(:) = 1:prod(size(matlab_array)); % %nc{'x'}(:) = matlab_array; % %close(nc) % %ptr = wcvarptr(ncfile, 'x'); % %fid = fopen(ncfile, 'r'); %fseek(fid, ptr, 'bof'); %in_netcdf_file = fread(fid, [1, 9], 'double'); %fclose(fid); % %delete(ncfile) % %matlab_array %in_netcdf_file % %a = matlab_array; %b = in_netcdf_file; % %if min(m, n) > 1 % if a(:) == b(:) % disp(' ## Matlab array is stored by columns in NetCDF.') % else % disp(' ## Matlab array is stored by rows in NetCDF.') % end %end fclose(fout); disp(' ## Installing: "tnetcdf.m" (text)') fout = fopen('tnetcdf.m', 'w'); %function tnetcdf(nRecords) % %% tnetcdf -- NetCDF Toolbox test. %% tnetcdf(nRecords) tests the NetCDF Toolbox, %% including an exercize with nRecords (default = 2). % %% 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 13-Mar-1997 00:00:00. %% Updated 05-Mar-2002 15:10:36. % %% Check the Matlab path. % %a = {'ncutility', % 'nctype', % 'netcdf/netcdf', % 'ncitem/ncitem', % 'ncdim/ncdim', % 'ncvar/ncvar', % 'ncatt/ncatt', % 'ncrec/ncrec', % 'ncbrowser/ncbrowser', % 'listpick/listpick'}; % %okay = 1; %for i = 1:length(a) % if isempty(which(a{i})) % disp([' ## Unable to find: ' a{i}]) % okay = 0; % end %end % %if ~okay % disp([' ## Please adjust your Matlab path,']) % disp([' ## then restart Matlab and']) % disp([' ## execute "tnetcdf" again.']) % disp([' ## See "ncstartup" for instructions.']) % return %end % %ncversion % %if nargin < 1, nRecords = 2; end %if ischar(nRecords), nRecords = eval(nRecords); end % %filename = 'foo.nc'; % %disp(' ') %disp([' ## TNETCDF: Using file "' filename '"']); % %oldOptions = options(ncitem, 0); % Quiet mode. %ncquiet % %for i = 0:3 % status = ncmex('close', i); %end % %f = netcdf(filename, 'clobber'); % %if isempty(f) % disp(' ## NetCDF test file not created.') % return %end % %% Preamble. % %f.Description = 'Test file.'; %f.Author = 'Dr. Charles R. Denham, ZYDECO.'; %f.Created = datestr(now); % %f('time') = 0; %f('lat') = 10; %f('lon') = 5; %f('elapsed_time') = 100; %f('horse_number') = 5; % %f{'time'} = nclong('time'); %f{'lat'} = nclong('lat'); %f{'lon'} = nclong('lon'); %f{'elapsed_time'} = ncdouble('elapsed_time'); %f{'horse_number'} = nclong('horse_number'); %f{'speed'} = ncdouble('elapsed_time', 'horse_number'); % %dims = {'time'; 'lat'; 'lon'}; % %f{'z'} = nclong(dims); %f{'t'} = nclong(dims); %f{'p'} = nclong(dims); %f{'rh'} = nclong(dims); % %f{'time'}.units = 'seconds'; % %f{'lat'}.FillValue_ = nclong(-999); %f{'lat'}.scale_factor = nclong(2); %f{'lat'}.add_offset = nclong(100); %f{'lat'}.units = 'degrees_north'; % %f{'lon'}.units = 'degrees_east'; % %f{'z'}.units = 'meters'; %f{'z'}.valid_range = ncfloat([0 5000]); % %f{'p'}.FillValue_ = NaN; %f{'p'}.FillValue_ = Inf; %f{'p'}.FillValue_ = -Inf; %f{'p'}.FillValue_ = -1; % %f{'rh'}.FillValue_ = -1; % %f{'elapsed_time'}.units = 'fortnights'; %f{'speed'}.units = 'furlongs/fortnight'; % %if (1) % Disabled = 0. % %% Test dotted names: fails on some systems. % %if (1) % f('a.dotted.name') = length('a dotted variable name'); % f.a.dotted.name = 'a dotted global attribute name'; % f{'a.dotted.name'} = ncchar('a.dotted.name'); % f{'a.dotted.name'}.a.dotted.name = 'a dotted variable attribute name'; % f{'a.dotted.name'}(:) = 'a dotted variable name'; %end % %% Test dashed names: fails on some systems. % %if (1) % f('a-dashed-name') = length('a dashed variable name'); % ncatt('a-dashed-name', 'a dashed global attribute name', f) % f('a-dashed-name') = length('a dashed variable name'); % f{'a-dashed-name'} = ncchar('a-dashed-name'); % v = f{'a-dashed-name'}; % ncatt('a-dashed-name', 'a dashed variable attribute name', v) % f{'a-dashed-name'}(:) = 'a dashed variable name'; %end % %else % disp(' ## After "tnetcdf", run "tncdotted" to check') % disp(' ## whether dotted and/or dashed NetCDF names') % disp(' ## can be created on this machine.') %end % %f = close(f); % %f = netcdf(filename, 'write') % %if isempty(f) % disp(' ## NetCDF test file not opened for "write".') % return %end % %lat = [0 10 20 30 40 50 60 70 80 90].'; % Column-vectors. %lon = [-140 -118 -96 -84 -52].'; % %for i = 1:length(lat), f{'lat'}(i) = lat(i); end % %value = f{'lat'}(:); % %if ~isequal(value, lat) % original_lat = lat, retrieved_lat = value % warning(' ## Bad retrieval of lat data #1.') %end % %f{'lat'}(1:2:10) = lat(1:2:10); % %value = f{'lat'}(:); %if ~isequal(value, lat), warning(' ## Bad retrieval of lat data #2.'), end % %value = f{'lat'}(1:2:10); %if ~isequal(value, lat(1:2:10)), warning(' ## Bad retrieval of lat data #3.'), end % %f{'lon'}(:) = lon; % %theSize = [prod(size(f{'elapsed_time'})) 1]; %theDistance = sort(rand(theSize)); %f{'elapsed_time'}(:) = theDistance; %f{'horse_number'}(:) = [2; 5; 27; 100; 125]; %theSpeed = rand(size(f{'speed'})); %for j = 1:size(theSpeed, 2) % theSpeed(:, j) = filter(theSpeed(:, j), ones(1, 5), 1) + ... % sin(2*pi*theDistance) + 1; %end %f{'speed'}(:) = theSpeed; % %f = close(f); % %ncdump(filename) % %f = netcdf(filename, 'write'); % %if isempty(f) % disp(' ## NetCDF test file not opened for "write".') % return %end % %% Re-write the scale_factor and add_offset %% two different ways. % %if (1) % f{'lat'}.scale_factor = nclong(999); % f{'lat'}.add_offset = nclong(999); % f{'lat'}.scale_factor(:) = 1; % f{'lat'}.add_offset(:) = 0; %end % %f = close(f); % %% Test of functions dealing with copying. % %if (1) % disp(' ') % disp(' ## TNETCDF: Copy-testing...') % theOriginal = netcdf(filename, 'nowrite') % if isempty(theOriginal) % disp(' ## NetCDF test file not opened for "read".') % return % end % theCopy = netcdf([filename '.copy'], 'clobber'); % if isempty(theCopy) % disp(' ## NetCDF destination file not created.') % return % end % theCopy < theOriginal; % theCopy % theCopy = close(theCopy); % theOriginal = close(theOriginal); % disp(' ## TNETCDF: Copy-testing done.') %end % %% Test of functions dealing with records. % %disp(' ') %disp(' ## TNETCDF: Record-testing...') % %f = netcdf(filename, 'write'); % %if isempty(f) % disp(' ## NetCDF test file not opened for "write".') % return %end % %record = f(0); %recdata = record(0); %goodRecords = 0; %iRec = nRecords:-1:1; %for i = iRec % disp([' ## Record: ' int2str(i)]) % recdata = record(0); % recdata.time = i; % recdata.z = fix(rand(size(recdata.z))*100); % recdata.t = fix(rand(size(recdata.t))*100); % recdata.p = fix(rand(size(recdata.p))*100); % recdata.rh = fix(rand(size(recdata.rh))*100); % record(i) = recdata; % recdata1 = record(i); % record(i) = recdata1; % Round-trip. % recdata2 = record(i); % goodRecords = goodRecords + isequal(recdata1, recdata2); %end %f = close(f); % %theOptions = options(ncitem, oldOptions); % %if goodRecords == nRecords % disp(' ## TNETCDF: Record-testing successful.') % else % disp(' ## TNETCDF: Record-testing not successful.') % disp([' ## Good Records: ' int2str(goodRecords) ' of ' int2str(nRecords) '.']) %end % %% Test of virtual variables. % %disp(' ') %disp(' ## TNETCDF: Virtual-variable test...') %f = netcdf(filename, 'write'); %rh = f{'rh'}; %a = rh; %b = orient(rh, [3 1 2]); %aa = permute(a(:), [3 1 2]); % WetCDF gets "ncvar/subsref" warning here. *** %b(:) = aa; % Put-back. %aa = a(:); % Get again. %bb = ipermute(b(:), [3 1 2]); % But not here. *** %f = close(f); % %if isequal(aa, bb) % disp(' ## TNETCDF: Virtual-variable test successful.') %else % aa, bb % disp(' ## TNETCDF: Virtual-variable test NOT successful.') %end % %% Test of composite variables. % %% Note: our use of "orient" here malfunctions %% when we attempt to use [-1], rather than [+1]. % %disp(' ') %disp(' ## TNETCDF: Composite-variable test...') %f = netcdf(filename, 'write'); %lat = f{'lat'}; %m = ncsize(lat, 1); %v = var(lat, {':'}, {1:m, 1}, ... % orient(lat, [+1]), {':'}, {1:m, 2}); % Was orient(lat, [-1]). % %x1 = v(:); %v(:) = flipud(x1); %x2 = v(:); %v(:) = flipud(x2); %x3 = v(:); %f = close(f); % %if isequal(x1, x3) % disp(' ## TNETCDF: Composite-variable test successful.') %else % disp(' ## TNETCDF: Composite-variable test NOT successful.') %end % %% Test of "quick" input/output. % %disp(' ') %disp(' ## TNETCDF: Input/output in "quick-mode"...') %f = netcdf(filename, 'write'); %v = f{'speed'}; %theSize = size(v); %v = quick(v, 0); %ntimes = 20; %for k = 1:2 % tic % for i = 1:ntimes % x = v(1:theSize(1), 1:theSize(2)); % end % elapsed(k) = toc; % v = quick(v, 1); %end %close(f) %theSpeedFactor = elapsed(1) ./ elapsed(2) % %% Browser. % %if (1) % disp(' ') % disp(' ## TNETCDF: Browse test-file...') % disp(' ') % ncbrowser foo.nc nowrite %end % %disp(' ') %disp(' ## TNETCDF: Done.') fclose(fout); disp(' ## Installing: "tscalar.m" (text)') fout = fopen('tscalar.m', 'w'); %function tscalar % %% tscalar -- Test NetCDF scalar values. %% tscalar (no arguments) writes the value 99 into %% several variables for each NetCDF datatype, then %% reads and tests the data after reopening the %% file. The tested variables have lengths of 0 %% (scalar), 1, and 2. Errors are noted, if any. %% Note: ascii(99) = "c". % %% 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 23-Sep-1999 08:22:11. %% Updated 27-Jan-2000 13:38:12. % %help(mfilename) % %nc = netcdf('scalar.nc', 'clobber'); %theNetCDFFile = name(nc); %disp([' ## NetCDF File: ' theNetCDFFile]) % %theTypes = {'byte', 'char', 'short', 'long', 'float', 'double'}; %theDimNames = {'', 'one', 'two'}; % %for k = 1:length(theDimNames) % thePrefix = char('a' + k - 1); % for i = 1:length(theTypes) % t = theTypes{i}; % t(1) = upper(t(1)); % theNames{i} = [thePrefix t]; % theKinds{i} = ['nc' theTypes{i}]; % if k < 2 % nc{theNames{i}} = feval(theKinds{i}); % else % nc(theDimNames{k}) = k-1; % nc{theNames{i}} = feval(theKinds{i}, theDimNames{k}); % end % nc{theNames{i}}.value = 99; % end %end % %theNames = ncnames(var(nc)); % %for i = 1:length(theNames) % nc{theNames{i}}(:) = 99; %end % %close(nc) % %% Re-open the file. % %nc = netcdf(theNetCDFFile, 'write'); % %% Read the data. % %for i = 1:length(theNames) % theValues{i} = nc{theNames{i}}(1); %end % %disp(' ## Testing variables using "(1)" notation:') % %okay = []; % %okay(end+1) = ~~1; %for i = 1:length(theValues) % if ~all(double(theValues{i}) == 99) % disp([' ## Some values are not 99: ' theNames{i}]) % okay(end+1) = ~~0; % end %end % %% Read attributes with (1) notation. % %for i = 1:length(theNames) % theValues{i} = nc{theNames{i}}.value(1); %end % %disp(' ## Testing attributes using "(1)" notation:') % %okay(end+1) = ~~1; %for i = 1:length(theValues) % if ~all(double(theValues{i}) == 99) % disp([' ## Some values are not 99: ' theNames{i}]) % okay(end+1) = ~~0; % end %end % %% Rewrite the data. % %for i = 1:length(theNames) % nc{theNames{i}}(:) = 99; % nc{theNames{i}}.value(:) = 99; %end % %% Reread with (:) notation. % %for i = 1:length(theNames) % theValues{i} = nc{theNames{i}}(:); %end % %disp(' ## Testing variables using "(:)" notation:') % %okay(end+1) = ~~1; %for i = 1:length(theValues) % if ~all(double(theValues{i}) == 99) % disp([' ## Some values are not 99: ' theNames{i}]) % okay(end+1) = ~~0; % end %end % %% Read attributes with (:) notation. % %for i = 1:length(theNames) % theValues{i} = nc{theNames{i}}.value(:); %end % %disp(' ## Testing attributes using "(:)" notation:') % %okay(end+1) = ~~1; %for i = 1:length(theValues) % if ~all(double(theValues{i}) == 99) % disp([' ## Some values are not 99: ' theNames{i}]) % okay(end+1) = ~~0; % end %end % %close(nc) % %if all(okay) % disp(' ## Scalar test successful.') %else % disp(' ## Scalar test NOT successful.') %end fclose(fout); disp(' ## Installing: "uilayout.m" (text)') fout = fopen('uilayout.m', 'w'); %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. % %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; %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); disp(' ## Installing: "var2str.m" (text)') fout = fopen('var2str.m', 'w'); %function s = Var2Str(x) % %% Var2Str -- String equivalent to a matrix. %% Var2Str(x) converts variable x to a one-line %% string which is roughly equivalent %% to x, for display purposes. If x is %% larger than a scalar, then its values are %% written between square brackets. % %% Copyright (C) 1991 Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if nargin < 1 % help(mfilename) % x = [1 2 3; pi inf nan]; % disp(' The matrix:'), disp(' ') % disp(x), disp(' becomes the string:'), disp(' ') % disp([' ' var2str(x)]) % return %end % %if isempty(x) % if isstr(x) % s = ''''''; % else % s = '[]'; % end % return %end % %quote = ''''; % %[m, n] = size(x); % %s = ''; %bracket = isstr(x) & m > 1 | ~isstr(x) & length(x) > 1; %if bracket, s = ['[']; end % %for i = 1:m % if isstr(x) % t = [quote x(i, :) quote]; % s = [s t]; % else % for j = 1:n % z = x(i, j); % if isnan(z) % t = 'nan'; % elseif z == inf % t = 'inf'; % elseif z == -inf % t = '-inf'; % elseif z == fix(z) % t = int2str(z); % else % t = num2str(z); % end % s = [s t]; % if j < n, s = [s ' ']; end % end % end % if i < m, s = [s '; ']; end %end % %if bracket, s = [s ']']; end fclose(fout); disp(' ## Installing: "vargstr.m" (text)') fout = fopen('vargstr.m', 'w'); %function theEvalString = VargStr(fcn, nvarargin, nvarargout) % %% VargStr -- Eval-string for varargin and varargout. %% VargStr('fcn', nvarargin, nvarargout) returns a string %% that calls the 'fcn' function when eval-ed. The input %% arguments are expressed as vargargin{...} and varargout{...}, %% respectively. If nvarargin or nvarargout is a cell-object, %% its length is used. The argument-counts default to zero. % %% 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, help(mfilename), return, end % %if nargin < 2, nvarargin = 0; end %if nargin < 3, nvarargout = 0; end % %if isa(nvarargin, 'cell') % nvarargin = length(nvarargin); %end % %if isa(nvarargout, 'cell') % nvarargout = length(nvarargout); %end % %s = ''; % %if nvarargout > 0 % s = [s '[']; % for i = 1:nvarargout % if i > 1, s = [s ',']; end % s = [s 'varargout{' int2str(i) '}']; % end % s = [s ']']; %end % %if ~isempty(fcn) % if nvarargout > 0, s = [s '=']; end % s = [s fcn]; %end % %if nvarargin > 0 % s = [s '(']; % for i = 1:nvarargin % if i > 1, s = [s ',']; end % s = [s 'varargin{' int2str(i) '}']; % end % s = [s ')']; %end % %if ~isempty(fcn), s = [s ';']; end % %if nargout > 0 % theEvalString = s; % else % disp(s) %end fclose(fout); disp(' ## Installing: "zoomsafe.m" (text)') fout = fopen('zoomsafe.m', 'w'); %function theResult = zoomsafe(varargin) % %% zoomsafe -- Safe zooming with the mouse. %% zoomsafe('demo') demonstrates itself with an interactive %% line. Zooming occurs with clicks that are NOT on the line. %% zoomsafe('on') initiates safe-zooming in the current window. %% Zooming occurs with each click in the current-figure, except %% on a graphical object whose "ButtonDownFcn" is active. %% zoomsafe('on', 'all') applies any new axis limits to all the %% axes in the figure. For companion axes having exactly the %% same 'XLim' range as the one that was clicked, the 'YLim' %% range remains intact. The same synchronization is invoked %% for corresponding 'YLim' situations as well. %% zoomsafe('all') same as zoomsafe('on', 'all'). %% zoomsafe (no argument) same as zoomsafe('on'). %% zoomsafe('off') turns it off. %% zoomsafe('out') zooms fully out. %% zoomsafe(theAmount, theDirection) applies theAmount of zooming %% to theDirection: 'x', 'y', or 'xy' (default). %% Note: when zooming actually occurs, this routine returns %% logical(1); otherwise, logical(0). %% %% "Click-Mode" (Macintosh Action) Result %% "normal" (click) Zoom out x2, centered on click. %% "extend" (shift-click) Zoom in x2, centered on click. %% "alt" (option-click) Center on click without zooming. %% "open" (double-click) Revert to unzoomed state. %% (Use click-down-and-drag to invoke a rubber-rectangle.) %% %% Use click-drag to map the zooming to a rubber-rectangle. % %% 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 19-Jun-1997 08:42:57. %% Updated 02-Aug-1999 14:40:31. % %result = logical(0); % %if nargin < 1, varargin = {'on'}; end % %if isstr(varargin{1}) & ~isempty(varargin{1}) & ... % any(varargin{1}(1) == '0123456789.') % varargin{1} = eval(varargin{1}); %end % %if ~isstr(varargin{1}) % theAmount = varargin{1}; % varargin{1} = 'manual'; %end % %theFlag = logical(0); %isAll = logical(0); % %theOldXLim = get(gca, 'XLim'); %theOldYLim = get(gca, 'YLim'); % %switch varargin{1} %case 'manual' % isAll = (nargin > 2); % theDirection = 'xy'; % if nargin > 1, theDirection = varargin{2}; end % theXLim = get(gca, 'XLim'); % theYLim = get(gca, 'YLim'); % if theAmount == 0 % axis tight % switch theDirection % case 'x' % set(gca, 'YLim', theYLim) % case 'y' % set(gca, 'XLim', theXLim) % case 'xy' % otherwise % end % theAmount = 1; % theXLim = get(gca, 'XLim'); % theYLim = get(gca, 'YLim'); % end % cx = mean(theXLim); % cy = mean(theYLim); % dx = diff(theXLim) ./ 2; % dy = diff(theYLim) ./ 2; % switch theDirection % case 'x' % theXLim = cx + [-dx dx] ./ theAmount; % case 'y' % theYLim = cy + [-dy dy] ./ theAmount; % case 'xy' % theXLim = cx + [-dx dx] ./ theAmount; % theYLim = cy + [-dy dy] ./ theAmount; % otherwise % end % set(gca, 'XLim', theXLim, 'YLim', theYLim); % theFlag = 1; %case 'demo' % x = (0:30) ./ 30; % y = rand(size(x)) - 0.5; % for i = 2:-1:1 % subplot(1, 2, i) % theLine = plot(x, y, '-o'); % set(theLine, 'ButtonDownFcn', 'disp(''## hello'')') % set(gcf, 'Name', 'zoomsafe Demo') % end % result = zoomsafe('on', 'all'); %case 'all' % result = zoomsafe('on', 'all'); %case 'on' % isAll = (nargin > 1); % if ~isAll % set(gcf, 'WindowButtonDownFcn', 'if zoomsafe(''down''), end') % else % set(gcf, 'WindowButtonDownFcn', 'if zoomsafe(''down'', ''all''), end') % end %case 'down' % isAll = (nargin > 1); % dozoom = 0; % switch get(gcbo, 'Type') % case {'figure'} % "axes" not needed. % switch switchsafe(get(gco, 'Type')) % case {'figure'} % dozoom = 1; % otherwise % if isempty(get(gco, 'ButtonDownFcn')) % dozoom = 1; % end % end % otherwise % end % switch dozoom % case 1 % thePointer = get(gcf, 'Pointer'); % set(gcf, 'Pointer', 'watch') % theRBRect = rbrect; % x = sort(theRBRect([1 3])); % y = sort(theRBRect([2 4])); % theXLim = get(gca, 'XLim'); % theYLim = get(gca, 'YLim'); % theLimRect = [theXLim(1) theYLim(1) theXLim(2) theYLim(2)]; % d = doubleclick; % Trap any double-click. % if any(d) % Valid double-click. % if ~isAll % result = zoomsafe('out'); % else % result = zoomsafe('out', 'all'); % end % set(gcf, 'Pointer', 'arrow') % if nargout > 0, theResult = result; end % return % elseif isempty(d) % Ignore initial-click of double. % if nargout > 0, theResult = result; end % return % else % Not a double-click. % end % switch get(gcf, 'SelectionType') % case 'normal' % theFlag = 1; % theAmount = [2 2]; % Zoom-in by factor of 2. % case 'extend' % theFlag = 1; % theAmount = [0.5 0.5]; % case 'open' % Pre-empted by "doubleclick" above. % if ~isAll % result = zoomsafe('out'); % else % result = zoomsafe('out', 'all'); % end % set(gcf, 'Pointer', 'arrow') % if nargout > 0, theResult = result; end % return % otherwise % theAmount = [1 1]; % x = [mean(x) mean(x)]; % y = [mean(y) mean(y)]; % end % if diff(x) == 0 | diff(y) == 0 % cx = mean(x); % cy = mean(y); % dx = diff(theXLim) ./ 2; % dy = diff(theYLim) ./ 2; % x = cx + [-dx dx] ./ theAmount(1); % y = cy + [-dy dy] ./ theAmount(2); % else % r1 = theLimRect; % r2 = theRBRect; % switch get(gcf, 'SelectionType') % case 'normal' % r4 = maprect(r1, r2, r1); % case 'extend' % r4 = maprect(r2, r1, r1); % otherwise % r4 = r1; % end % x = r4([1 3]); % y = r4([2 4]); % end % set(gca, 'XLim', sort(x), 'YLim', sort(y)) % theFlag = 1; % result = logical(1); % switch thePointer % case {'watch', 'circle'} % thePointer = 'arrow'; % otherwise % end % set(gcf, 'Pointer', thePointer) % set(gcf, 'Pointer', 'arrow') % otherwise % end %case 'motion' %case 'up' %case 'off' % set(gcf, 'WindowButtonDownFcn', ''); %case 'out' % isAll = (nargin > 1); % theFlag = 1; % axis tight % result = logical(1); %otherwise % temp = eval(varargin{1}); % switch class(temp) % case 'double' % if ~isAll % result = zoomsafe(temp); % else % result = zoomsafe(temp, 'all'); % end % otherwise % warning('## Unknown option') % end %end % %% Synchronize the other axes. % %if isAll & theFlag & 1 % theGCA = gca; % theXLim = get(theGCA, 'XLim'); % theYLim = get(theGCA, 'YLim'); % theAxes = findobj(gcf, 'Type', 'axes'); % for i = 1:length(theAxes) % if theAxes(i) ~= theGCA % axes(theAxes(i)) % x = get(gca, 'XLim'); % y = get(gca, 'YLim'); % if all(x == theOldXLim) % set(theAxes(i), 'XLim', theXLim) % end % if all(y == theOldYLim) % set(theAxes(i), 'YLim', theYLim) % end % end % end % axes(theGCA) %end % %if nargout > 0, theResult = result; end % %% legend % Causes excessive flashing. % %function theResult = rbrect(onMouseUp, onMouseMove, onMouseDown) % %% rbrect -- Rubber rectangle tracking (Matlab-4 and Matlab-5). %% rbrect('demo') demonstrates itself. %% rbrect('onMouseUp', 'onMouseMove', 'onMouseDown') conducts interactive %% rubber-rectangle tracking, presumably because of a mouse button press %% on the current-callback-object (gcbo). The 'on...' callbacks are %% automatically invoked with: "feval(theCallback, theInitiator, theRect)" %% after each window-button event, using the object that started this %% process, plus theRect as [xStart yStart xEnd yEnd] for the current %% rubber-rect. The callbacks default to ''. The coordinates of the %% rectangle are returned as [xStart yStart xEnd yEnd]. % %% Private interface: %% rbrect(1) is automatically called on window-button-motions. %% rbrect(2) is automatically called on window-button-up. % %% 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 03-Jun-1997 15:54:39. %% Version of 11-Jun-1997 15:17:22. %% Version of 17-Jun-1997 16:52:46. % %global RBRECT_HANDLE %global RBRECT_INITIATOR %global RBRECT_ON_MOUSE_MOVE % %if nargin < 1, onMouseUp = 0; end % %if strcmp(onMouseUp, 'demo') % help rbrect % x = cumsum(rand(200, 1) - 0.45); % y = cumsum(rand(200, 1) - 0.25); % h = plot(x, y, '-r'); % set(h, 'ButtonDownFcn', 'disp(rbrect)') % figure(gcf), set(gcf, 'Name', 'RBRECT Demo') % return % elseif isstr(onMouseUp) % theMode = 0; % else % theMode = onMouseUp; % onMouseUp = ''; %end % % %if theMode == 0 % Mouse down. % if nargin < 3, onMouseDown = ''; end % if nargin < 2, onMouseMove = ''; end % if nargin < 1, onMouseUp = ''; end % theVersion = version; % isVersion5 = (theVersion(1) == '5'); % if isVersion5 % theCurrentObject = 'gcbo'; % else % theCurrentObject = 'gco'; % end % RBRECT_INITIATOR = eval(theCurrentObject); % switch get(RBRECT_INITIATOR, 'Type') % case 'line' % theColor = get(RBRECT_INITIATOR, 'Color'); % otherwise % theColor = 'black'; % end % RBRECT_ON_MOUSE_MOVE = onMouseMove; % pt = mean(get(gca, 'CurrentPoint')); % x = [pt(1) pt(1)]; y = [pt(2) pt(2)]; % RBRECT_HANDLE = line(x, y, ... % 'EraseMode', 'xor', ... % 'LineStyle', '--', ... % 'LineWidth', 2.5, ... % 'Color', theColor, ... % 'Marker', '+', 'MarkerSize', 13, ... % 'UserData', 1); % set(gcf, 'WindowButtonMotionFcn', 'rbrect(1);') % set(gcf, 'WindowButtonUpFcn', 'rbrect(2);') % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(onMouseDown) % feval(onMouseDown, RBRECT_INITIATOR, theRBRect) % end % thePointer = get(gcf, 'Pointer'); % set(gcf, 'Pointer', 'circle'); % if isVersion5 & 0 % Disable for rbrect().. % eval('waitfor(RBRECT_HANDLE, ''UserData'', [])') % else % set(RBRECT_HANDLE, 'Visible', 'off') % Invisible. % eval('rbbox') % No "waitfor" in Matlab-4. % end % set(gcf, 'Pointer', thePointer); % set(gcf, 'WindowButtonMotionFcn', '') % set(gcf, 'WindowButtonUpFcn', '') % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % delete(RBRECT_HANDLE) % theRBRect = [x(1) y(1) x(2) y(2)]; % Scientific. % if ~isempty(onMouseUp) % feval(onMouseUp, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 1 % Mouse move. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y) % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(RBRECT_ON_MOUSE_MOVE) % feval(RBRECT_ON_MOUSE_MOVE, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 2 % Mouse up. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y, 'UserData', []) %else %end % %if nargout > 0, theResult = theRBRect; end % %function rect4 = maprect(rect1, rect2, rect3) % %% maprect -- Map rectangles. %% maprect(rect1, rect2, rect3) returns the rectangle %% that is to rect3 what rect1 is to rect2. Each %% rectangle is given as [x1 y1 x2 y2]. %% maprect('demo') demonstrates itself by showing %% that maprect(r1, r2, r1) ==> r2. % %% 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 19-Jun-1997 08:33:39. % %if nargin < 1, help(mfilename), rect1 = 'demo'; end % %if strcmp(rect1, 'demo') % rect1 = [0 0 3 3]; % rect2 = [1 1 2 2]; % rect3 = rect1; % r4 = maprect(rect1, rect2, rect3); % begets(mfilename, 3, rect1, rect2, rect3, r4) % return %end % %if nargin < 3, help(mfilename), return, end % %r4 = zeros(1, 4); %i = [1 3]; %for k = 1:2 % r4(i) = polyval(polyfit(rect1(i), rect2(i), 1), rect3(i)); % i = i + 1; %end % %if nargout > 0 % rect4 = r4; % else % disp(r4) %end % %function theResult = doubleclick % %% doubleclick -- Trap for double-clicks. %% doubleclick (no argument) returns TRUE if a click %% is detected during its execution; otherwise, FALSE. %% Call "doubleclick" during a "WindowButtonDown" or %% "ButtonDown" callback, preferably at the top of %% procedure. The 'Interruptible' property of the %% callback-object must be 'on'. The double-click %% time is 0.5 sec. A valid double-click causes %% two values to be returned: first, a logical(1), %% then an empty-matrix []. The latter signifies %% the single-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. % %global CLICK_COUNT % %DOUBLE_CLICK_TIME = 1/2; % 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); cd ('..') bund_setdir('nctype') disp(' ## Installing: "ncbyte.m" (text)') fout = fopen('ncbyte.m', 'w'); %function theResult = ncbyte(varargin) % %% ncbyte -- Courier for constructing NetCDF 'byte' entities. %% ncbyte('dim1', 'dim2', ...) prepends 'byte' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'byte', varargin); % theResult = [{'byte'} varargin]; % else % help ncbyte %end fclose(fout); disp(' ## Installing: "ncchar.m" (text)') fout = fopen('ncchar.m', 'w'); %function theResult = ncchar(varargin) % %% ncchar -- Courier for constructing NetCDF 'char' entities. %% ncchar('dim1', 'dim2', ...) prepends 'char' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'char', varargin); % theResult = [{'char'} varargin]; % else % help ncchar %end fclose(fout); disp(' ## Installing: "ncdouble.m" (text)') fout = fopen('ncdouble.m', 'w'); %function theResult = ncdouble(varargin) % %% ncdouble -- Courier for constructing NetCDF 'double' entities. %% ncdouble('dim1', 'dim2', ...) prepends 'double' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'double', varargin); % theResult = [{'double'} varargin]; % else % help ncdouble %end fclose(fout); disp(' ## Installing: "ncfloat.m" (text)') fout = fopen('ncfloat.m', 'w'); %function theResult = ncfloat(varargin) % %% ncfloat -- Courier for constructing NetCDF 'float' entities. %% ncfloat('dim1', 'dim2', ...) prepends 'float' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'float', varargin); % theResult = [{'float'} varargin]; % else % help ncfloat %end fclose(fout); disp(' ## Installing: "ncint.m" (text)') fout = fopen('ncint.m', 'w'); %function theResult = ncint(varargin) % %% ncint -- Courier for constructing NetCDF 'int' entities. %% ncint('dim1', 'dim2', ...) prepends 'int' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'int', varargin); % theResult = [{'int'} varargin]; % else % help ncint %end fclose(fout); disp(' ## Installing: "nclong.m" (text)') fout = fopen('nclong.m', 'w'); %function theResult = nclong(varargin) % %% nclong -- Courier for constructing NetCDF 'long' entities. %% nclong('dim1', 'dim2', ...) prepends 'long' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'long', varargin); % theResult = [{'long'} varargin]; % else % help nclong %end fclose(fout); disp(' ## Installing: "ncsetstr.m" (text)') fout = fopen('ncsetstr.m', 'w'); %function theResult = ncsetstr(x) % %% ncsetstr -- SETSTR for NetCDF character data. %% ncsetstr(x) converts values x to unsigned-characters %% in the range 0:255, for use by Matlab. Beginning %% with Version-6, Matlab characters must be non-negative, %% whereas the sign of NetCDF "char" is undefined. % %% 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 01-Mar-2001 11:23:06. %% Updated 01-Mar-2001 11:45:03. % %if nargout > 0 % theResult = []; %end % %if nargin < 1 % help(mfilename) % return %end % %result = rem(x, 256); %result(result < 0) = result(result < 0) + 256; %result = char(result); % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ncshort.m" (text)') fout = fopen('ncshort.m', 'w'); %function theResult = ncshort(varargin) % %% ncshort -- Courier for constructing NetCDF 'short' entities. %% ncshort('dim1', 'dim2', ...) prepends 'short' to the input %% argument-list, for use by ncvar and ncatt constructors. %% %% Also see: nc... for other numeric types. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargout > 0 %% theResult = ncvar('', 'short', varargin); % theResult = [{'short'} varargin]; % else % help ncshort %end fclose(fout); disp(' ## Installing: "nctype.m" (text)') fout = fopen('nctype.m', 'w'); %function nctype % %% nctype -- Switch to the nctype directory. %% nctype (no arguments) switches to the directory %% that contains the nctype definitions. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %setdef nctype fclose(fout); cd ('..') bund_setdir('ncsource') disp(' ## Installing: "make_mexcdf53.m" (text)') fout = fopen('make_mexcdf53.m', 'w'); %function make_mexcdf53 % %% make_mexcdf53 -- Make "mexcdf53" Mex-file. %% make_mexcdf53 (no argument) builds the "mexcdf53" %% Mex-file. Adjust as needed. % %% 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 28-Aug-2002 14:53:49. %% Updated 17-Sep-2002 16:13:13. % %try % at(mfilename('fullpath')) %catch %end % %try % copyfile mexcdf53.mexmac mexcdf53.mexmac.old %catch %end % %OPTION = '-v -g'; %SOURCE = 'mexcdf53.c'; %INCLUDE = '-I/USER/netcdf-3.5.0/include/'; %LIBRARY = '/USER/netcdf-3.5.0/lib/libnetcdf.a'; % %COMMAND = ['mex ' OPTION ' ' SOURCE ' ' INCLUDE ' ' LIBRARY] %eval(COMMAND) fclose(fout); disp(' ## Installing: "mexcdf.h" (text)') fout = fopen('mexcdf.h', 'w'); %/* % * mexcdf.h Include-file for mexcdf53.c. % * % * Dr. Charles R. Denham, U.S. Geological Survey. % * % */ % %# if !defined MEXCDF_H %# define MEXCDF_H % %# define calloc(A, B) mxCalloc(A, B) %# define free(A) mxFree(A) % %# if defined __STDC__ %# if !defined HAS_VOID %# define HAS_VOID %# endif %# endif % %# if defined HAS_VOID %# define VOID void %# define VOIDP void * %# define VOIDPP void ** %# else %# define VOID %# define VOIDP char * %# define VOIDPP char ** %# endif % %# if !defined DOUBLE %# define DOUBLE double %# define INT int %# endif % %# if !defined VERBOSE %# define VERBOSE 0 /* Verbosity. */ %# endif % %# if !defined MEXCDF_4 %# define MEXCDF_4 0 %# define MEXCDF_5 1 %# define Matrix mxArray %# define COMPLEX mxCOMPLEX %# define REAL mxREAL %# define INT int %# define mxCreateFull(A, B, C) mxCreateDoubleMatrix(A, B, C) %# define mxIsString(A) mxIsChar(A) %# else %# define MEXCDF_5 0 %# endif % %# define MAX_BUFFER 32 % %/* NetCDF Operations. */ % %typedef enum s_opcode { % USAGE = 1, % CREATE, % OPEN, % REDEF, % ENDEF, % INQUIRE, % CLOSE, % SYNC, % ABORT, % DIMDEF, % DIMID, % DIMINQ, % DIMRENAME, % VARDEF, % VARID, % VARINQ, % VARPUT1, % VARGET1, % VARPUT, % VARGET, % VARPUTG, % VARGETG, % VARRENAME, % VARCOPY, % ATTPUT, % ATTINQ, % ATTGET, % ATTCOPY, % ATTNAME, % ATTRENAME, % ATTDEL, % RECPUT, % RECGET, % RECINQ, % TYPELEN, % SETFILL, % SETOPTS, % ERR, % PARAMETER, % NONE % } OPCODE; % %typedef struct s_op { % OPCODE opcode; % char * opname; % int nrhs; /* Required nrhs. */ % int nlhs; /* Maximum nlhs. */ % } op; % %op ops[] = { % USAGE, "usage", 1, 0, % CREATE, "create", 2, 2, % OPEN, "open", 2, 2, % REDEF, "redef", 1, 1, % ENDEF, "endef", 1, 1, % INQUIRE, "inquire", 2, 5, % CLOSE, "close", 2, 1, % SYNC, "sync", 2, 1, % ABORT, "abort", 2, 1, % DIMDEF, "dimdef", 4, 1, % DIMID, "dimid", 3, 1, % DIMINQ, "diminq", 3, 3, % DIMRENAME, "dimrename", 4, 1, % VARDEF, "vardef", 6, 1, % VARID, "varid", 3, 1, % VARINQ, "varinq", 3, 5, % VARPUT1, "varput1", 5, 1, % VARGET1, "varget1", 4, 2, % VARPUT, "varput", 6, 1, % VARGET, "varget", 5, 2, % VARPUTG, "varputg", 7, 1, % VARGETG, "vargetg", 6, 2, % VARRENAME, "varrename", 4, 1, % VARCOPY, "varcopy", 3, 2, % ATTPUT, "attput", 7, 1, % ATTINQ, "attinq", 4, 3, % ATTGET, "attget", 4, 2, % ATTCOPY, "attcopy", 6, 1, % ATTNAME, "attname", 4, 2, % ATTRENAME, "attrename", 5, 1, % ATTDEL, "attdel", 4, 1, % RECPUT, "recput", 4, 1, % RECGET, "recget", 3, 2, % RECINQ, "recinq", 2, 3, % TYPELEN, "typelen", 2, 2, % SETFILL, "setfill", 3, 1, % SETOPTS, "setopts", 2, 1, % ERR, "err", 1, 1, % PARAMETER, "parameter", 1, 1, % NONE, "none", 0, 0 % }; % %/* NetCDF Parameters. */ % %typedef struct s_parm { % int code; % char * name; % int len; /* Minimal unique length. */ % } parm; % %parm parms[] = { %/* % FILL_BYTE, "FILL_BYTE", 6, % FILL_CHAR, "FILL_CHAR", 6, % FILL_SHORT, "FILL_SHORT", 6, % FILL_INT, "FILL_INT", 6, % FILL_INT, "FILL_LONG", 6, % FILL_FLOAT, "FILL_FLOAT", 6, % FILL_DOUBLE, "FILL_DOUBLE", 6, %*/ % %#define MAX_NC_DIMS 100 /* max dimensions per file */ %#define MAX_NC_ATTRS 2000 /* max global or per variable attributes */ %#define MAX_NC_VARS 2000 /* max variables per file */ %#define MAX_NC_NAME 128 /* max length of a name */ %#define MAX_VAR_DIMS MAX_NC_DIMS /* max per variable dimensions */ % % MAX_NC_NAME, "MAX_NC_NAME", 8, % MAX_NC_DIMS, "MAX_NC_DIMS", 8, % MAX_NC_VARS, "MAX_NC_VARS", 8, % MAX_NC_ATTRS, "MAX_NC_ATTRS", 8, % MAX_VAR_DIMS, "MAX_VAR_DIMS", 9, % NC_BYTE, "BYTE", 1, % NC_CHAR, "CHAR", 2, % NC_CLOBBER, "CLOBBER", 2, % NC_DOUBLE, "DOUBLE", 1, % NC_FATAL, "FATAL", 2, % NC_FILL, "FILL", 2, % NC_FLOAT, "FLOAT", 2, % NC_GLOBAL, "GLOBAL", 1, % NC_LONG, "LONG", 3, % NC_LOCK, "NC_LOCK", 3, % NC_NOCLOBBER, "NOCLOBBER", 3, % NC_NOFILL, "NOFILL", 3, % NC_NOWRITE, "NOWRITE", 3, % NC_SHARE, "SHARE", 3, % NC_SHORT, "SHORT", 3, % NC_UNLIMITED, "UNLIMITED", 1, % NC_VERBOSE, "VERBOSE", 1, % NC_WRITE, "WRITE", 1, % 0, "NONE", 0 % }; % %# endif fclose(fout); disp(' ## Installing: "mexcdf53.c" (text)') fout = fopen('mexcdf53.c', 'w'); %/* % * mexcdf53.c -- For Matlab Version 5 and NetCDF Version 3. % * % * ******************** NOTICE ******************** % * % * MEXCDF53 -- USGS Preliminary Computer Software For % * Interaction Between Matlab-5 and NetCDF-3. % * % * Begun: Tuesday, July 14, 1992 6:59:54 PM. % * Version: Tuesday, March 4, 1997 3:54:00 PM. % * Version: Wednesday, December 16, 1998 4:43:00 PM. % * byte ==> (signed char) Jim Mansbridge. % * Version: Monday, January 24, 2000 19:11:50 PM. % * varget1, vargetg, attget: plhs[0] % * Version: Tuesday, September 17, 2002. % * MacOSX version built with this. % * % * Written, Maintained, and Supported By: % * Dr. Charles R. Denham % * U.S. Geological Survey % * Woods Hole, Massachusetts 02543 % * e-mail: cdenham@usgs.gov % * % * Computer Programming Language: % * The C-Language. % * % * Computer System: % * This software has been successfully linked with % * the NetCDF-3 library and executed from Matlab-5 % * on Power Macintosh and DEC Alpha hardware. The % * software is intended to be compatible with all % * installations of Matlab-4, Matlab-5, NetCDF-2, % * and NetCDF-3. % * % * Source Code Available From: % * Author. % * % * Disclaimer: % * Although this software has been used by the USGS, no % * warranty, expressed or implied, is made by the USGS % * or the United States Government as to the accuracy % * and functioning of the software and related software % * material, nor shall the fact of distribution constitute % * any such warranty or publication, and no responsibility % * is assumed by the USGS in connection therewith. % * % * Fair Use: % * This software, named "mexcdf53", may be used freely on % * condition that this NOTICE be displayed prominantly and % * in its entirety on all copies of the software, as well % * as on all copies of software that has been derived from % * this software. Furthermore, this software requires the % * UCAR/Unidata NetCDF library, whose conditions on proper % * credit, distribution, and use must be acknowledged and % * honored fully. % * % * ******************** END OF NOTICE ******************** % * % * Use mexcdf53.c and mexcdf.h, plus a valid NetCDF library, % * to build mexcdf53.mex, a mex-file function that is intended % * to be executed from Matlab. % * % * This source-code uses MATLAB Version 5 mex-file syntax, % * but it still requires that the -V4 compiler-flag be % * specified when building with the "mex" script supplied % * by MathWorks. (V4 not relevant with Matlab 6.) % * % * The strictly two-dimensional assumption of Matlab-4 can % * be recreated by specifying the MEXCDF_4 compiler-flag, % * in addition to the -V4 flag mentioned above. % * (V4 not relevant with Matlab 6.) % * % * To build mexcdf53 for use with MATLAB Version 4, specify % * the MEXCDF_4 flag, as well as other flags required by % * the "cmex" script supplied previously by MathWorks. % * % * This Mex-file invokes the high-level C-Language NetCDF-2 % * interface of the NetCDF Users Guide. All of the specified % * NetCDF input arguments are required. All output arguments % * are optional. % * % * Matlab Syntax: % * % * [out1, out2, ...] = mexcdf53('operation', in1, in2, ...) % * % * Extensions: % * % * 1. Dimensions and variables accessible by id or name. % * 2. Attributes accessible by name or number. % * 3. Parameters accessible by number or name. % * 4. Prepended "nc" not necessary for operation names. % * 5. Prepended "NC_" not necessary for specifying parameters. % * 6. Parameter names not case-sensitive. % * 7. Required lengths default to actual lengths via -1. % * 8. Scaling via "scale_factor" and "add_offset" attributes. % * 9. SETOPTS to set NetCDF options. NC_FATAL is disabled. % * 10. ERR to get and auto-reset the most recent error-code. % * 11. PARAMETER to access parameters by name. % * 12. USAGE to list mexcdf53 syntax. % * % */ % %# include %# include %# include %# include %# include % %# include "netcdf.h" % %# include "mex.h" % %# include "mexcdf.h" % %static VOID Usage (VOID); % %static Matrix * SetNum (Matrix *); %static Matrix * SetStr (Matrix *); % %static char * Mat2Str (Matrix *); %static Matrix * Str2Mat (char *); % %static int * Mat2Int (Matrix *); %static Matrix * Int2Mat (int *, int, int); % %static long * Mat2Long (Matrix *); %static Matrix * Long2Mat (long *, int, int); % %static int Scalar2Int (Matrix *); %static Matrix * Int2Scalar (int); % %static long Scalar2Long (Matrix *); %static Matrix * Long2Scalar (long); % %static int Count (Matrix *); % %static int Parameter (Matrix *); % %static VOID Free (VOIDPP); % %static DOUBLE Scale_Factor (int, int); %static DOUBLE Add_Offset (int, int); % %static int Convert (OPCODE, nc_type, int, VOIDP, % DOUBLE, DOUBLE, DOUBLE *); % %static nc_type RepairBadDataType (nc_type); % % %/* MexFunction(): Mex-file entry point. */ % %void %mexFunction ( % INT nlhs, % Matrix * plhs[], % INT nrhs, % const Matrix * prhs[] % ) % %{ % char * opname; % OPCODE opcode; % % Matrix * mat; % % int status; % char * path; % int cmode; % int mode; % int cdfid; % int ndims; % int nvars; % int natts; % int recdim; % char * name; % long length; % int dimid; % nc_type datatype; % int * dim; % int varid; % long * coords; % VOIDP value; % long * start; % long * count; % int * intcount; % long * stride; % long * imap; % long recnum; % int nrecvars; % int * recvarids; % long * recsizes; % VOIDPP datap; /* pointers for record access. */ % int len; % int incdf; % int invar; % int outcdf; % int outvar; % int attnum; % char * attname; % char * newname; % int fillmode; % % int i; % int m; % int n; % char * p; % char buffer[MAX_BUFFER]; % % DOUBLE * pr; % DOUBLE addoffset; % DOUBLE scalefactor; % int autoscale; /* do auto-scaling if this flag is non-zero. */ % % /* Disable the NC_FATAL option from ncopts. */ % % if (ncopts & NC_FATAL) { % ncopts -= NC_FATAL; % } % % /* Display usage if less than one input argument. */ % % if (nrhs < 1) { % % Usage(); % % return; % } % % /* Convert the operation name to its opcode. */ % % opname = Mat2Str(prhs[0]); % for (i = 0; i < strlen(opname); i++) { % opname[i] = (char) tolower((int) opname[i]); % } % p = opname; % if (strncmp(p, "nc", 2) == 0) { /* Trim away "nc". */ % p += 2; % } % % i = 0; % opcode = NONE; % while (ops[i].opcode != NONE) { % if (!strcmp(p, ops[i].opname)) { % opcode = ops[i].opcode; % if (ops[i].nrhs > nrhs) { % mexPrintf("MEXCDF: opname = %s\n", opname); % mexErrMsgTxt("MEXCDF: Too few input arguments.\n"); % } % else if (0 && ops[i].nlhs > nlhs) { /* Disabled. */ % mexPrintf("MEXCDF: opname = %s\n", opname); % mexErrMsgTxt("MEXCDF: Too few output arguments.\n"); % } % break; % } % else { % i++; % } % } % % if (opcode == NONE) { % mexPrintf("MEXCDF: opname = %s\n", opname); % mexErrMsgTxt("MEXCDF: No such operation.\n"); % } % % Free((VOIDPP) & opname); % % /* Extract the cdfid by number. */ % % switch (opcode) { % % case USAGE: % case CREATE: % case OPEN: % case TYPELEN: % case SETOPTS: % case ERR: % case PARAMETER: % % break; % % default: % % cdfid = Scalar2Int(prhs[1]); % % break; % } % % /* Extract the dimid by number or name. */ % % switch (opcode) { % % case DIMINQ: % case DIMRENAME: % % if (mxIsNumeric(prhs[2])) { % dimid = Scalar2Int(prhs[2]); % } % else { % name = Mat2Str(prhs[2]); % dimid = ncdimid(cdfid, name); % Free((VOIDPP) & name); % } % break; % % default: % % break; % } % % /* Extract the varid by number or name. */ % % switch (opcode) { % % case VARINQ: % case VARPUT1: % case VARGET1: % case VARPUT: % case VARGET: % case VARPUTG: % case VARGETG: % case VARRENAME: % case VARCOPY: % case ATTPUT: % case ATTINQ: % case ATTGET: % case ATTCOPY: % case ATTNAME: % case ATTRENAME: % case ATTDEL: % % if (mxIsNumeric(prhs[2])) { % varid = Scalar2Int(prhs[2]); % } % else { % name = Mat2Str(prhs[2]); % varid = ncvarid(cdfid, name); % Free((VOIDPP) & name); % if (varid == -1) { % varid = Parameter(prhs[2]); % } % } % break; % % default: % % break; % } % % /* Extract the attname by name or number. */ % % switch (opcode) { % % case ATTPUT: % case ATTINQ: % case ATTGET: % case ATTCOPY: % case ATTRENAME: % case ATTDEL: % % if (mxIsNumeric(prhs[3])) { % attnum = Scalar2Int(prhs[3]); % attname = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % status = ncattname(cdfid, varid, attnum, attname); % } % else { % attname = Mat2Str(prhs[3]); % } % break; % % default: % % break; % } % % /* Extract the "add_offset" and "scale_factor" attributes. */ % % switch (opcode) { % % case VARPUT1: % case VARGET1: % case VARPUT: % case VARGET: % case VARPUTG: % case VARGETG: % % addoffset = Add_Offset(cdfid, varid); % scalefactor = Scale_Factor(cdfid, varid); % if (scalefactor == 0.0) { % scalefactor = 1.0; % } % % break; % % default: % % break; % } % % /* Perform the NetCDF operation. */ % % switch (opcode) { % % case USAGE: % % Usage(); % % break; % % case CREATE: % % path = Mat2Str(prhs[1]); % % if (nrhs > 2) { % cmode = Parameter(prhs[2]); % } % else { % cmode = NC_NOCLOBBER; /* Default. */ % } % % cdfid = nccreate(path, cmode); % % plhs[0] = Int2Scalar(cdfid); % plhs[1] = Int2Scalar((cdfid >= 0) ? 0 : -1); % % Free((VOIDPP) & path); % % break; % % case OPEN: % % path = Mat2Str(prhs[1]); % % if (nrhs > 2) { % mode = Parameter(prhs[2]); % } % else { % mode = NC_NOWRITE; /* Default. */ % } % % cdfid = ncopen(path, mode); % % plhs[0] = Int2Scalar(cdfid); % plhs[1] = Int2Scalar((cdfid >= 0) ? 0 : -1); % % Free((VOIDPP) & path); % % break; % % case REDEF: % % status = ncredef(cdfid); % % plhs[0] = Int2Scalar(status); % % break; % % case ENDEF: % % status = ncendef(cdfid); % % plhs[0] = Int2Scalar(status); % % break; % % case CLOSE: % % status = ncclose(cdfid); % % plhs[0] = Int2Scalar(status); % % break; % % case INQUIRE: % % status = ncinquire(cdfid, & ndims, & nvars, & natts, & recdim); % % if (nlhs > 1) { % plhs[0] = Int2Scalar(ndims); % plhs[1] = Int2Scalar(nvars); % plhs[2] = Int2Scalar(natts); % plhs[3] = Int2Scalar(recdim); % plhs[4] = Int2Scalar(status); % } % else { /* Default to 1 x 5 row vector. */ % plhs[0] = mxCreateFull(1, 5, REAL); % pr = mxGetPr(plhs[0]); % if (status == 0) { % pr[0] = (DOUBLE) ndims; % pr[1] = (DOUBLE) nvars; % pr[2] = (DOUBLE) natts; % pr[3] = (DOUBLE) recdim; % } % pr[4] = (DOUBLE) status; % } % % break; % % case SYNC: % % status = ncsync(cdfid); % % plhs[0] = Int2Scalar(status); % % break; % % case ABORT: % % status = ncabort(cdfid); % % plhs[0] = Int2Scalar(status); % % break; % % case DIMDEF: % % name = Mat2Str(prhs[2]); % length = Parameter(prhs[3]); % % dimid = ncdimdef(cdfid, name, length); % % plhs[0] = Int2Scalar(dimid); % plhs[1] = Int2Scalar((dimid >= 0) ? 0 : dimid); % % Free((VOIDPP) & name); % % break; % % case DIMID: % % name = Mat2Str(prhs[2]); % % dimid = ncdimid(cdfid, name); % % plhs[0] = Int2Scalar(dimid); % plhs[1] = Int2Scalar((dimid >= 0) ? 0 : dimid); % % Free((VOIDPP) & name); % % break; % % case DIMINQ: % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % % status = ncdiminq(cdfid, dimid, name, & length); % % plhs[0] = Str2Mat(name); % plhs[1] = Long2Scalar(length); % plhs[2] = Int2Scalar(status); % % Free((VOIDPP) & name); % % break; % % case DIMRENAME: % % name = Mat2Str(prhs[3]); % % status = ncdimrename(cdfid, dimid, name); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & name); % % break; % % case VARDEF: % % name = Mat2Str(prhs[2]); % datatype = (nc_type) Parameter(prhs[3]); % ndims = Scalar2Int(prhs[4]); % if (ndims == -1) { % ndims = Count(prhs[5]); % } % dim = Mat2Int(prhs[5]); % % varid = ncvardef(cdfid, name, datatype, ndims, dim); % % Free((VOIDPP) & name); % % plhs[0] = Int2Scalar(varid); % plhs[1] = Int2Scalar((varid >= 0) ? 0 : varid); % % break; % % case VARID: % % name = Mat2Str(prhs[2]); % % varid = ncvarid(cdfid, name); % % Free((VOIDPP) & name); % % plhs[0] = Int2Scalar(varid); % plhs[1] = Int2Scalar((varid >= 0) ? 0 : varid); % % break; % % case VARINQ: % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % plhs[0] = Str2Mat(name); % plhs[1] = Int2Scalar(datatype); % plhs[2] = Int2Scalar(ndims); % plhs[3] = Int2Mat(dim, 1, ndims); % plhs[4] = Int2Scalar(natts); % plhs[5] = Int2Scalar(status); % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % break; % % case VARPUT1: % % coords = Mat2Long(prhs[3]); % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % if (datatype == NC_CHAR) { % mat = SetNum(prhs[4]); % } % else { % mat = prhs[4]; % } % if (mat == NULL) { % mat = prhs[4]; % } % % pr = mxGetPr(mat); % % autoscale = (nrhs > 5 && Scalar2Int(prhs[5]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % status = Convert(opcode, datatype, 1, buffer, scalefactor, addoffset, pr); % status = ncvarput1(cdfid, varid, coords, buffer); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & coords); % % break; % % case VARGET1: % % coords = Mat2Long(prhs[3]); % % autoscale = (nrhs > 4 && Scalar2Int(prhs[4]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % mat = Int2Scalar(0); % % pr = mxGetPr(mat); % % status = ncvarget1(cdfid, varid, coords, buffer); % status = Convert(opcode, datatype, 1, buffer, scalefactor, addoffset, pr); % % if (datatype == NC_CHAR) { % plhs[0] = SetStr(mat); % } % else { % plhs[0] = mat; % } % if (plhs[0] == NULL) { %/* prhs[0] = mat; */ % plhs[0] = mat; /* ZYDECO 24Jan2000 */ % } % % plhs[1] = Int2Scalar(status); % % Free((VOIDPP) & coords); % % break; % % case VARPUT: % % start = Mat2Long(prhs[3]); % count = Mat2Long(prhs[4]); % % autoscale = (nrhs > 6 && Scalar2Int(prhs[6]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % if (datatype == NC_CHAR) { % mat = SetNum(prhs[5]); % } % else { % mat = prhs[5]; % } % if (mat == NULL) { % mat = prhs[5]; % } % % pr = mxGetPr(mat); % % for (i = 0; i < ndims; i++) { % if (count[i] == -1) { % status = ncdiminq(cdfid, dim[i], name, & count[i]); % count[i] -= start[i]; % } % } % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % len = 0; % if (ndims > 0) { % len = 1; % for (i = 0; i < ndims; i++) { % len *= count[i]; % } % } % % value = (VOIDP) mxCalloc(len, nctypelen(datatype)); % status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr); % status = ncvarput(cdfid, varid, start, count, value); % Free((VOIDPP) & value); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & start); % Free((VOIDPP) & count); % % break; % % case VARGET: % % start = Mat2Long(prhs[3]); % count = Mat2Long(prhs[4]); % intcount = Mat2Int(prhs[4]); % % autoscale = (nrhs > 5 && Scalar2Int(prhs[5]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % for (i = 0; i < ndims; i++) { % if (count[i] == -1) { % status = ncdiminq(cdfid, dim[i], name, & count[i]); % count[i] -= start[i]; % } % } % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % m = 0; % n = 0; % if (ndims > 0) { % m = count[0]; % n = count[0]; % for (i = 1; i < ndims; i++) { % n *= count[i]; % if (count[i] > 1) { % m = count[i]; % } % } % n /= m; % } % len = m * n; % if (ndims < 2) { % m = 1; % n = len; % } % % for (i = 0; i < ndims; i++) { % intcount[i] = count[ndims-i-1]; /* Reverse order. */ % } % % if (MEXCDF_4 || ndims < 2) { % mat = mxCreateFull(m, n, mxREAL); /* mxCreateDoubleMatrix */ % } %# if MEXCDF_5 % else { % mat = mxCreateNumericArray(ndims, intcount, mxDOUBLE_CLASS, mxREAL); % } %# endif % % pr = mxGetPr(mat); % % value = (VOIDP) mxCalloc(len, nctypelen(datatype)); % status = ncvarget(cdfid, varid, start, count, value); % status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr); % Free((VOIDPP) & value); % % if (datatype == NC_CHAR) { % plhs[0] = SetStr(mat); % } % else { % plhs[0] = mat; % } % if (plhs[0] == NULL) { % plhs[0] = mat; % } % % plhs[1] = Int2Scalar(status); % % Free((VOIDPP) & intcount); % Free((VOIDPP) & count); % Free((VOIDPP) & start); % % break; % % case VARPUTG: % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % if (nrhs > 7) { % if (datatype == NC_CHAR) { % mat = SetStr(prhs[7]); % } % else { % mat = prhs[7]; % } % if (mat == NULL) { % mat = prhs[7]; % } % } % else { % if (datatype == NC_CHAR) { % mat = SetStr(prhs[6]); % } % else { % mat = prhs[6]; % } % if (mat == NULL) { % mat = prhs[6]; % } % } % pr = mxGetPr(mat); % % start = Mat2Long(prhs[3]); % count = Mat2Long(prhs[4]); % stride = Mat2Long(prhs[5]); % imap = NULL; % % for (i = 0; i < ndims; i++) { % if (count[i] == -1) { % status = ncdiminq(cdfid, dim[i], name, & count[i]); % count[i] -= start[i]; % } % } % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % len = 0; % if (ndims > 0) { % len = 1; % for (i = 0; i < ndims; i++) { % len *= count[i]; % } % } % % autoscale = (nrhs > 8 && Scalar2Int(prhs[8]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % value = (VOIDP) mxCalloc(len, nctypelen(datatype)); % status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr); % status = ncvarputg(cdfid, varid, start, count, stride, imap, value); % Free((VOIDPP) & value); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & stride); % Free((VOIDPP) & count); % Free((VOIDPP) & start); % % break; % % case VARGETG: % % start = Mat2Long(prhs[3]); % count = Mat2Long(prhs[4]); % intcount = Mat2Int(prhs[4]); % stride = Mat2Long(prhs[5]); % imap = NULL; % % autoscale = (nrhs > 7 && Scalar2Int(prhs[7]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % name = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % dim = (int *) mxCalloc(MAX_NC_DIMS, sizeof(int)); % % status = ncvarinq(cdfid, varid, name, & datatype, & ndims, dim, & natts); % % datatype = RepairBadDataType(datatype); % % for (i = 0; i < ndims; i++) { % if (count[i] == -1) { % status = ncdiminq(cdfid, dim[i], name, & count[i]); % count[i] -= start[i]; % } % } % % Free((VOIDPP) & name); % Free((VOIDPP) & dim); % % m = 0; % n = 0; % if (ndims > 0) { % m = count[0]; % n = count[0]; % for (i = 1; i < ndims; i++) { % n *= count[i]; % if (count[i] > 1) { % m = count[i]; % } % } % n /= m; % } % len = m * n; % if (ndims < 2) { % m = 1; % n = len; % } % % for (i = 0; i < ndims; i++) { % intcount[i] = count[ndims-i-1]; /* Reverse order. */ % } % % if (MEXCDF_4 || ndims < 2) { % mat = mxCreateFull(m, n, mxREAL); /* mxCreateDoubleMatrix */ % } %# if MEXCDF_5 % else { % mat = mxCreateNumericArray(ndims, intcount, mxDOUBLE_CLASS, mxREAL); % } %# endif % % pr = mxGetPr(mat); % % value = (VOIDP) mxCalloc(len, nctypelen(datatype)); % status = ncvargetg(cdfid, varid, start, count, stride, imap, value); % status = Convert(opcode, datatype, len, value, scalefactor, addoffset, pr); % Free((VOIDPP) & value); % % if (datatype == NC_CHAR) { % plhs[0] = SetStr(mat); % } % else { % plhs[0] = mat; % } % if (plhs[0] == NULL) { %/* prhs[0] = mat; */ % plhs[0] = mat; /* ZYDECO 24Jan2000 */ % } % % plhs[1] = Int2Scalar(status); % % Free((VOIDPP) & stride); % Free((VOIDPP) & intcount); % Free((VOIDPP) & count); % Free((VOIDPP) & start); % % break; % % case VARRENAME: % % name = Mat2Str(prhs[3]); % % status = ncvarrename(cdfid, varid, name); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & name); % % break; % % case VARCOPY: % % incdf = cdfid; % % invar = varid; % % outcdf = Scalar2Int(prhs[3]); % % outvar = -1; %/* outvar = ncvarcopy(incdf, invar, outcdf); */ % % plhs[0] = Int2Scalar(outvar); % plhs[1] = Int2Scalar((outvar >= 0) ? 0 : outvar); % % break; % % case ATTPUT: % % datatype = (nc_type) Parameter(prhs[4]); % % datatype = RepairBadDataType(datatype); % % if (datatype == NC_CHAR) { % mat = SetNum(prhs[6]); % } % else { % mat = prhs[6]; % } % if (mat == NULL) { % mat = prhs[6]; % } % % len = Scalar2Int(prhs[5]); % if (len == -1) { % len = Count(mat); % } % % pr = mxGetPr(mat); % value = (VOIDP) mxCalloc(len, nctypelen(datatype)); % status = Convert(opcode, datatype, len, value, (DOUBLE) 1.0, (DOUBLE) 0.0, pr); % % status = ncattput(cdfid, varid, attname, datatype, len, value); % % if (value != NULL) { % Free((VOIDPP) & value); % } % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & attname); % % break; % % case ATTINQ: % % status = ncattinq(cdfid, varid, attname, & datatype, & len); % % datatype = RepairBadDataType(datatype); % % plhs[0] = Int2Scalar((int) datatype); % plhs[1] = Int2Scalar(len); % plhs[2] = Int2Scalar(status); % % Free((VOIDPP) & attname); % % break; % % case ATTGET: % % status = ncattinq(cdfid, varid, attname, & datatype, & len); % % datatype = RepairBadDataType(datatype); % % value = (VOIDP) mxCalloc(len, nctypelen(datatype)); % status = ncattget(cdfid, varid, attname, value); % % mat = mxCreateDoubleMatrix(1, len, mxREAL); % % pr = mxGetPr(mat); % % status = Convert(opcode, datatype, len, value, (DOUBLE) 1.0, (DOUBLE) 0.0, pr); % % if (value != NULL) { % Free((VOIDPP) & value); % } % % if (datatype == NC_CHAR) { % plhs[0] = SetStr(mat); % } % else { % plhs[0] = mat; % } % if (plhs[0] == NULL) { %/* prhs[4] = mat; */ % plhs[0] = mat; /* ZYDECO 24Jan2000 */ % } % % plhs[1] = Int2Scalar(status); % % Free((VOIDPP) & attname); % % break; % % case ATTCOPY: % % incdf = cdfid; % % invar = varid; % % outcdf = Scalar2Int(prhs[4]); % % if (mxIsNumeric(prhs[5])) { % outvar = Scalar2Int(prhs[2]); % } % else { % name = Mat2Str(prhs[5]); % outvar = ncvarid(cdfid, name); % Free((VOIDPP) & name); % } % % status = ncattcopy(incdf, invar, attname, outcdf, outvar); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & attname); % % break; % % case ATTNAME: % % attnum = Scalar2Int(prhs[3]); % attname = (char *) mxCalloc(MAX_NC_NAME, sizeof(char)); % % status = ncattname(cdfid, varid, attnum, attname); % % plhs[0] = Str2Mat(attname); % plhs[1] = Int2Scalar(status); % % Free((VOIDPP) & attname); % % break; % % case ATTRENAME: % % newname = Mat2Str(prhs[4]); % % status = ncattrename(cdfid, varid, attname, newname); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & attname); % Free((VOIDPP) & newname); % % break; % % case ATTDEL: % % status = ncattdel(cdfid, varid, attname); % % plhs[0] = Int2Scalar(status); % % Free((VOIDPP) & attname); % % break; % % case RECPUT: % % recnum = Scalar2Long(prhs[2]); % pr = mxGetPr(prhs[3]); % % autoscale = (nrhs > 4 && Scalar2Int(prhs[4]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % recvarids = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int)); % recsizes = (long *) mxCalloc(MAX_VAR_DIMS, sizeof(long)); % datap = (VOIDPP) mxCalloc(MAX_VAR_DIMS, sizeof(VOIDP)); % % status = ncrecinq(cdfid, & nrecvars, recvarids, recsizes); % % if (status == -1) { % plhs[0] = Int2Scalar(status); % break; % } % % length = 0; % n = 0; % for (i = 0; i < nrecvars; i++) { % ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL); % % datatype = RepairBadDataType(datatype); % % length += recsizes[i]; % n += (recsizes[i] / nctypelen(datatype)); % } % % if (Count(prhs[3]) < n) { % status = -1; % plhs[0] = Int2Scalar(status); % break; % } % % if ((value = (VOIDP) mxCalloc((int) length, sizeof(char))) == NULL) { % status = -1; % plhs[0] = Int2Scalar(status); % break; % } % % length = 0; % p = value; % for (i = 0; i < nrecvars; i++) { % datap[i] = p; % p += recsizes[i]; % } % % p = (char *) value; % pr = mxGetPr(prhs[3]); % % for (i = 0; i < nrecvars; i++) { % ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL); % % datatype = RepairBadDataType(datatype); % % length = recsizes[i] / nctypelen(datatype); % if (autoscale) { % addoffset = Add_Offset(cdfid, recvarids[i]); % scalefactor = Scale_Factor(cdfid, recvarids[i]); % if (scalefactor == 0.0) { % scalefactor = 1.0; % } % } % Convert(opcode, datatype, length, (VOIDP) p, scalefactor, addoffset, pr); % pr += length; % p += recsizes[i]; % } % % status = ncrecput(cdfid, recnum, datap); % % plhs[0] = Int2Scalar(status); % % Free ((VOIDPP) & value); % Free ((VOIDPP) & datap); % Free ((VOIDPP) & recsizes); % Free ((VOIDPP) & recvarids); % % break; % % case RECGET: % % recnum = Scalar2Long(prhs[2]); % % autoscale = (nrhs > 3 && Scalar2Int(prhs[3]) != 0); % % if (!autoscale) { % scalefactor = 1.0; % addoffset = 0.0; % } % % recvarids = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int)); % recsizes = (long *) mxCalloc(MAX_VAR_DIMS, sizeof(long)); % datap = (VOIDPP) mxCalloc(MAX_VAR_DIMS, sizeof(VOIDP)); % % status = ncrecinq(cdfid, & nrecvars, recvarids, recsizes); % % if (status == -1) { % Free ((VOIDPP) & recsizes); % Free ((VOIDPP) & recvarids); % plhs[1] = Int2Scalar(status); % break; % } % % if (nrecvars == 0) { % Free ((VOIDPP) & recsizes); % Free ((VOIDPP) & recvarids); % plhs[0] = mxCreateFull(0, 0, REAL); % break; % } % % length = 0; % n = 0; % for (i = 0; i < nrecvars; i++) { % ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL); % % datatype = RepairBadDataType(datatype); % % length += recsizes[i]; % n += (recsizes[i] / nctypelen(datatype)); % } % % if ((value = (VOIDP) mxCalloc((int) length, sizeof(char))) == NULL) { % status = -1; % plhs[1] = Int2Scalar(status); % break; % } % % if (value == NULL) { % status = -1; % plhs[1] = Int2Scalar(status); % break; % } % % length = 0; % p = value; % for (i = 0; i < nrecvars; i++) { % datap[i] = p; % p += recsizes[i]; % } % % if ((status = ncrecget(cdfid, recnum, datap)) == -1) { % plhs[1] = Int2Scalar(status); % break; % } % % m = 1; % % plhs[0] = mxCreateFull(m, n, REAL); % % if (plhs[0] == NULL) { % status = -1; % plhs[1] = Int2Scalar(status); % break; % } % % pr = mxGetPr(plhs[0]); % p = (char *) value; % % for (i = 0; i < nrecvars; i++) { % status = ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL); % % datatype = RepairBadDataType(datatype); % % if (status == -1) { % plhs[1] = Int2Scalar(status); % break; % } % length = recsizes[i] / nctypelen(datatype); % if (autoscale) { % addoffset = Add_Offset(cdfid, recvarids[i]); % scalefactor = Scale_Factor(cdfid, recvarids[i]); % if (scalefactor == 0.0) { % scalefactor = 1.0; % } % } % Convert(opcode, datatype, length, (VOIDP) p, scalefactor, addoffset, pr); % pr += length; % p += recsizes[i]; % } % % plhs[1] = Int2Scalar(status); % % Free ((VOIDPP) & value); % Free ((VOIDPP) & datap); % Free ((VOIDPP) & recsizes); % Free ((VOIDPP) & recvarids); % % break; % % case RECINQ: % % recvarids = (int *) mxCalloc(MAX_VAR_DIMS, sizeof(int)); % recsizes = (long *) mxCalloc(MAX_VAR_DIMS, sizeof(long)); % % status = ncrecinq(cdfid, & nrecvars, recvarids, recsizes); % % if (status != -1) { % for (i = 0; i < nrecvars; i++) { % ncvarinq(cdfid, recvarids[i], NULL, & datatype, NULL, NULL, NULL); % % datatype = RepairBadDataType(datatype); % % recsizes[i] /= nctypelen(datatype); % } % m = 1; % n = nrecvars; % plhs[0] = Int2Mat(recvarids, m, n); % plhs[1] = Long2Mat(recsizes, m, n); % } % % plhs[2] = Int2Scalar(status); % % Free ((VOIDPP) & recsizes); % Free ((VOIDPP) & recvarids); % % break; % % case TYPELEN: % % datatype = (nc_type) Parameter(prhs[1]); % % len = nctypelen(datatype); % % plhs[0] = Int2Scalar(len); % plhs[1] = Int2Scalar((len >= 0) ? 0 : 1); % % break; % % case SETFILL: % % fillmode = Scalar2Int(prhs[1]); % % status = ncsetfill(cdfid, fillmode); % % plhs[0] = Int2Scalar(status); % plhs[1] = Int2Scalar(0); % % break; % % case SETOPTS: % % plhs[0] = Int2Scalar(ncopts); % plhs[1] = Int2Scalar(0); % ncopts = Scalar2Int(prhs[1]); % % break; % % case ERR: % % plhs[0] = Int2Scalar(ncerr); % ncerr = 0; % plhs[1] = Int2Scalar(0); % % break; % % case PARAMETER: % % if (nrhs > 1) { % plhs[0] = Int2Scalar(Parameter(prhs[1])); % plhs[1] = Int2Scalar(0); % } % else { % i = 0; % while (strcmp(parms[i].name, "NONE") != 0) { % mexPrintf("%12d %s\n", parms[i].code, parms[i].name); % i++; % } % plhs[0] = Int2Scalar(0); % plhs[1] = Int2Scalar(-1); % } % % break; % % default: % % break; % } % % return; %} % % %/* Convert(): Convert between DOUBLE and NetCDF numeric types. */ % %static int %Convert ( % OPCODE opcode, % nc_type datatype, % int len, % VOIDP value, % DOUBLE scalefactor, % DOUBLE addoffset, % DOUBLE * pr % ) % %{ % signed char * pbyte; % char * pchar; % short * pshort; % nclong * plong; /* Note use of nclong. */ % float * pfloat; % double * pdouble; % % int i; % int status; % % status = 0; % % switch (opcode) { % % case VARPUT: % case VARPUT1: % case ATTPUT: % % switch (datatype) { % case NC_BYTE: % pbyte = (signed char *) value; % for (i = 0; i < len; i++) { % *pbyte++ = (signed char) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_CHAR: % pchar = (char *) value; % for (i = 0; i < len; i++) { % *pchar++ = (char) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_SHORT: % pshort = (short *) value; % for (i = 0; i < len; i++) { % *pshort++ = (short) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_LONG: % plong = (nclong *) value; % for (i = 0; i < len; i++) { % *plong++ = (nclong) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_FLOAT: % pfloat = (float *) value; % for (i = 0; i < len; i++) { % *pfloat++ = (float) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_DOUBLE: % pdouble = (double *) value; % for (i = 0; i < len; i++) { % *pdouble++ = (double) ((*pr++ - addoffset) / scalefactor); % } % break; % default: % status = -1; % break; % } % break; % % case VARGET: % case VARGET1: % case ATTGET: % % switch (datatype) { % case NC_BYTE: % pbyte = (signed char *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pbyte++; % } % break; % case NC_CHAR: % pchar = (char *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pchar++; % } % break; % case NC_SHORT: % pshort = (short *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pshort++; % } % break; % case NC_LONG: % plong = (nclong *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *plong++; % } % break; % case NC_FLOAT: % pfloat = (float *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pfloat++; % } % break; % case NC_DOUBLE: % pdouble = (double *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pdouble++; % } % break; % default: % status = -1; % break; % } % break; % % case VARPUTG: % case RECPUT: % % switch (datatype) { % case NC_BYTE: % pbyte = (signed char *) value; % for (i = 0; i < len; i++) { % *pbyte++ = (signed char) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_CHAR: % pchar = (char *) value; % for (i = 0; i < len; i++) { % *pchar++ = (char) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_SHORT: % pshort = (short *) value; % for (i = 0; i < len; i++) { % *pshort++ = (short) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_LONG: % plong = (nclong *) value; % for (i = 0; i < len; i++) { % *plong++ = (nclong) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_FLOAT: % pfloat = (float *) value; % for (i = 0; i < len; i++) { % *pfloat++ = (float) ((*pr++ - addoffset) / scalefactor); % } % break; % case NC_DOUBLE: % pdouble = (double *) value; % for (i = 0; i < len; i++) { % *pdouble++ = (double) ((*pr++ - addoffset) / scalefactor); % } % break; % default: % status = -1; % break; % } % break; % % case VARGETG: % case RECGET: % % switch (datatype) { % case NC_BYTE: % pbyte = (signed char *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pbyte++; % } % break; % case NC_CHAR: % pchar = (char *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pchar++; % } % break; % case NC_SHORT: % pshort = (short *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pshort++; % } % break; % case NC_LONG: % plong = (nclong *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *plong++; % } % break; % case NC_FLOAT: % pfloat = (float *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pfloat++; % } % break; % case NC_DOUBLE: % pdouble = (double *) value; % for (i = 0; i < len; i++) { % *pr++ = addoffset + scalefactor * (DOUBLE) *pdouble++; % } % break; % default: % status = -1; % break; % } % break; % % default: % status = -1; % break; % } % % return (status); %} % % %/* Usage(): Print information on NCMEX usage. */ % %static VOID %Usage ( % ) % %{ % int i; % int j; % %# if defined __DATE__ %# if defined __TIME__ % %# if !defined __FILE__ %# define __FILE__ "mexcdf53.c" %# endif % % mexPrintf("Program %s Version %s %s\n", __FILE__, __DATE__, __TIME__); % %# endif %# endif % % if (VERBOSE) { % mexPrintf("\n"); % mexPrintf("mexcdf53(\'USAGE\')\n"); % mexPrintf("\n"); % mexPrintf("mexcdf53(\'CREATE\', \'path\', cmode) ==> [cdfid, status]\n"); % mexPrintf("mexcdf53(\'OPEN\', \'path\', mode) ==> [cdfid, status]\n"); % mexPrintf("mexcdf53(\'REDEF\', cdfid) ==> status\n"); % mexPrintf("mexcdf53(\'ENDEF\', cdfid) ==> status\n"); % mexPrintf("mexcdf53(\'INQUIRE\', cdfid) ==> [ndims, nvars, natts, recdim, status]\n"); % mexPrintf("mexcdf53(\'SYNC\', cdfid) ==> status\n"); % mexPrintf("mexcdf53(\'ABORT\', cdfid) ==> status\n"); % mexPrintf("mexcdf53(\'CLOSE\', cdfid) ==> status\n"); % mexPrintf("\n"); % mexPrintf("mexcdf53(\'DIMDEF\', cdfid, \'name\', length) ==> [dimid, status]\n"); % mexPrintf("mexcdf53(\'DIMID\', cdfid, \'name\') ==> [dimid, status]\n"); % mexPrintf("mexcdf53(\'DIMINQ\', cdfid, dimid) ==> [\'name\', length, status]\n"); % mexPrintf("mexcdf53(\'DIMRENAME\', cdfid, \'name\') ==> status\n"); % mexPrintf("\n"); % mexPrintf("mexcdf53(\'VARDEF\', cdfid, \'name\', datatype, ndims, [dim]) ==> [varid, status]\n"); % mexPrintf("mexcdf53(\'VARID\', cdfid, \'name\') ==> [varid, status]\n"); % mexPrintf("mexcdf53(\'VARINQ\', cdfid, varid) ==> [\'name\', datatype, ndims, [dim], natts, status]\n"); % mexPrintf("mexcdf53(\'VARPUT1\', cdfid, varid, [coords], value, autoscale) ==> status\n"); % mexPrintf("mexcdf53(\'VARGET1\', cdfid, varid, [coords], flag) ==> [value, status]\n"); % mexPrintf("mexcdf53(\'VARPUT\', cdfid, varid, [start], [count], [value], autoscale) ==> status\n"); % mexPrintf("mexcdf53(\'VARGET\', cdfid, varid, [start], [count], autoscale) ==> [[value], status]\n"); % mexPrintf("mexcdf53(\'VARPUTG\', cdfid, varid, [start], [count], [stride], [imap], [value], autoscale) ==> status\n"); % mexPrintf("mexcdf53(\'VARGETG\', cdfid, varid, [start], [count], [stride], [imap], autoscale) ==> [[value], status]\n"); % mexPrintf("mexcdf53(\'VARRENAME\', cdfid, varid, \'name\') ==> status\n"); % mexPrintf("\n"); % mexPrintf("mexcdf53(\'ATTPUT\', cdfid, varid, \'name\', datatype, len, [value]) ==> status\n"); % mexPrintf("mexcdf53(\'ATTINQ\', cdfid, varid, \'name\') ==> [datatype, len, status]\n"); % mexPrintf("mexcdf53(\'ATTGET\', cdfid, varid, \'name\') ==> [[value], len, status]\n"); % mexPrintf("mexcdf53(\'ATTCOPY\', incdf, invar, \'name\', outcdf, outvar) ==> status\n"); % mexPrintf("mexcdf53(\'ATTNAME\', cdfid, varid, attnum) ==> [\'name\', status]\n"); % mexPrintf("mexcdf53(\'ATTRENAME\', cdfid, varid, \'name\', \'newname\') ==> status\n"); % mexPrintf("mexcdf53(\'ATTDEL\', cdfid, varid, \'name\') ==> status\n"); % mexPrintf("\n"); % mexPrintf("mexcdf53(\'TYPELEN\', datatype) ==> [len, status]\n"); % mexPrintf("mexcdf53(\'SETFILL\', cdfid, fillmode) ==> [old_fillmode, status]\n"); % mexPrintf("mexcdf53(\'SETOPTS\', ncopts) ==> [old_ncopts, status]\n"); % mexPrintf("mexcdf53(\'ERR\') ==> [ncerr, status]\n"); % mexPrintf("mexcdf53(\'PARAMETER\', \'NC_...\') ==> [code, status]\n"); % } % % else { % % i = 0; % while (ops[i].opcode != NONE) { % % mexPrintf("mexcdf53(\'%s\'", ops[i].opname); % for (j = 1; j < ops[i].nrhs; j++) { % mexPrintf(", in%d", j); % } % mexPrintf(")"); % if (ops[i].nlhs > 0) { % mexPrintf(" ==> ["); % for (j = 1; j <= ops[i].nlhs; j++) { % mexPrintf("out%d", j); % if (j < ops[i].nlhs) { % mexPrintf(", "); % } % } % mexPrintf("]"); % } % mexPrintf("\n"); % % i++; % } % } % % return; %} % % %/* Parameter(): Get NetCDF parameter by name. */ % %static int %Parameter ( % Matrix * mat % ) % %{ % int parameter; % char * p; % char * q; % int i; % % parameter = -1; % % if (mxIsNumeric(mat)) { % parameter = Scalar2Int(mat); % } % else { % p = Mat2Str(mat); % q = p; % for (i = 0; i < strlen(p); i++) { % *q = (char) toupper((int) *q); % q++; % } % if (strncmp(p, "NC_", 3) == 0) { /* Trim away "NC_". */ % q = p + 3; % } % else { % q = p; % } % % i = 0; % while (strcmp(parms[i].name, "NONE") != 0) { % if (strncmp(q, parms[i].name, parms[i].len) == 0) { % parameter = parms[i].code; % break; % } % else { % i++; % } % } % % Free ((VOIDPP) & p); % } % % return (parameter); %} % % %/* Scale_Factor: Return "scale_factor" attribute as DOUBLE. */ % %static DOUBLE %Scale_Factor ( % int cdfid, % int varid % ) % %{ % int status; % nc_type datatype; % int len; % char value[32]; % DOUBLE d; % % d = 1.0; % % if ((status = ncattinq(cdfid, varid, "scale_factor", &datatype, &len)) == -1) { % } % else if ((status = ncattget(cdfid, varid, "scale_factor", value)) == -1) { % } % else { % switch (RepairBadDataType(datatype)) { % case NC_BYTE: % d = (DOUBLE) *((signed char *) value); % break; % case NC_CHAR: % d = (DOUBLE) *((char *) value); % break; % case NC_SHORT: % d = (DOUBLE) *((short *) value); % break; % case NC_LONG: % d = (DOUBLE) *((nclong *) value); % break; % case NC_FLOAT: % d = (DOUBLE) *((float *) value); % break; % case NC_DOUBLE: % d = (DOUBLE) *((double *) value); % break; % default: % break; % } % } % % return (d); %} % % %/* Add_Offset: Return "add_offset" attribute as DOUBLE. */ % %static DOUBLE %Add_Offset ( % int cdfid, % int varid % ) % %{ % int status; % nc_type datatype; % int len; % char value[32]; % DOUBLE d; % % d = 0.0; % % if ((status = ncattinq(cdfid, varid, "add_offset", &datatype, &len)) == -1) { % } % else if ((status = ncattget(cdfid, varid, "add_offset", value)) == -1) { % } % else { % switch (RepairBadDataType(datatype)) { % case NC_BYTE: % d = (DOUBLE) *((signed char *) value); % break; % case NC_CHAR: % d = (DOUBLE) *((char *) value); % break; % case NC_SHORT: % d = (DOUBLE) *((short *) value); % break; % case NC_LONG: % d = (DOUBLE) *((nclong *) value); % break; % case NC_FLOAT: % d = (DOUBLE) *((float *) value); % break; % case NC_DOUBLE: % d = (DOUBLE) *((double *) value); % break; % default: % break; % } % } % % return (d); %} % % %/* SetNum(): Convert matrix to numeric matrix. */ % %static Matrix * %SetNum ( % Matrix * mat % ) % %{ % Matrix * result = NULL; % int status; % % if (mxIsString(mat)) { % mexSetTrapFlag(1); % status = mexCallMATLAB(1, & result, 1, & mat, "abs"); % if (status == 1) { % result = NULL; % } % mexSetTrapFlag(0); % } % % return (result); %} % % %/* SetStr(): Convert matrix to string matrix. */ % %static Matrix * %SetStr ( % Matrix * mat % ) % %{ % Matrix * result = NULL; % int status; % % if (mxIsNumeric(mat)) { % mexSetTrapFlag(1); % status = mexCallMATLAB(1, & result, 1, & mat, "setstr"); % if (status == 1) { % result = NULL; % } % mexSetTrapFlag(0); % } % % return (result); %} % % %/* Mat2Str(): Return string from a string-matrix. */ % %static char * %Mat2Str ( % Matrix * mat % ) % %{ % DOUBLE * pr; % char * p; % char * str; % int len; % int i; % % len = mxGetM(mat) * mxGetN(mat); % % str = (char *) mxCalloc(len + 1, sizeof(char)); % % mxGetString(mat, str, len + 1); % % return (str); %} % % %/* Str2Mat(): Convert string into a string-matrix. */ % %static Matrix * %Str2Mat ( % char * str % ) % %{ % Matrix * mat; % % mat = mxCreateString(str); % % return (mat); %} % % %/* Mat2Long(): Return matrix values as a long integer array. */ % %static long * %Mat2Long ( % Matrix * mat % ) % %{ % DOUBLE * pr; % long * plong; % long * p; % int len; % int i; % % len = mxGetM(mat) * mxGetN(mat); % % plong = (long *) mxCalloc(len, sizeof(long)); % p = plong; % pr = mxGetPr(mat); % % for (i = 0; i < len; i++) { % *p++ = (long) *pr++; % } % % return (plong); %} % % %/* Long2Mat(): Convert long integer array to a matrix. */ % %static Matrix * %Long2Mat ( % long * plong, % int m, % int n % ) % %{ % Matrix * mat; % DOUBLE * pr; % long * p; % int len; % int i; % % mat = mxCreateFull(m, n, REAL); % % pr = mxGetPr(mat); % p = plong; % % len = m * n; % for (i = 0; i < len; i++) { % *pr++ = (long) *p++; % } % % return (mat); %} % % %/* Mat2Int(): Return matrix values as an integer array. */ % %static int * %Mat2Int ( % Matrix * mat % ) % %{ % DOUBLE * pr; % int * pint; % int * p; % int len; % int i; % % len = mxGetM(mat) * mxGetN(mat); % % pint = (int *) mxCalloc(len, sizeof(int)); % p = pint; % pr = mxGetPr(mat); % % for (i = 0; i < len; i++) { % *p++ = (int) *pr++; % } % % return (pint); %} % % %/* Int2Mat(): Convert integer array to a matrix. */ % %static Matrix * %Int2Mat ( % int * pint, % int m, % int n % ) % %{ % Matrix * mat; % DOUBLE * pr; % int * p; % int len; % int i; % % mat = mxCreateFull(m, n, REAL); % % pr = mxGetPr(mat); % p = pint; % % len = m * n; % for (i = 0; i < len; i++) { % *pr++ = (int) *p++; % } % % return (mat); %} % % %/* Int2Scalar(): Convert integer value to a scalar matrix. */ % %static Matrix * %Int2Scalar ( % int i % ) % %{ % Matrix * scalar; % % scalar = mxCreateFull(1, 1, REAL); % % *(mxGetPr(scalar)) = (DOUBLE) i; % % return (scalar); %} % % %/* Scalar2Int(): Return integer value of a scalar matrix.*/ % %static int %Scalar2Int ( % Matrix * scalar % ) % %{ % return ((int) *(mxGetPr(scalar))); %} % % %/* Long2Scalar(): Convert long integer value to a scalar matrix. */ % %static Matrix * %Long2Scalar ( % long along % ) % %{ % Matrix * scalar; % % scalar = mxCreateFull(1, 1, REAL); % % *(mxGetPr(scalar)) = (DOUBLE) along; % % return (scalar); %} % % %/* Scalar2Long(): Return long integer value of a scalar matrix. */ % %static long %Scalar2Long ( % Matrix * scalar % ) % %{ % return ((long) *(mxGetPr(scalar))); %} % % %/* Count(): Element count of a matrix. */ % %static int %Count ( % Matrix * mat % ) % %{ % return ((int) (mxGetM(mat) * mxGetN(mat))); %} % % %/* Free(): De-allocate memory by address of pointer. */ % %static VOID %Free ( % VOIDPP p % ) % %{ % if (*p) { % if (1) { % mxFree(*p); % *p = (VOIDP) 0; % } % } % else if (VERBOSE) { % mexPrintf(" ## MexCDF53/Free(): Attempt to free null-pointer.\n"); % } %} % % %/* RepairBadDataType(): Repair bad datatype. */ % %static nc_type %RepairBadDataType ( % nc_type theDataType % ) % %{ % if (theDataType < NC_BYTE || theDataType > NC_DOUBLE) { % if (VERBOSE) { % mexPrintf(" ## MexCDF53/RepairBadDataType: %d", theDataType); % } % if (theDataType < NC_BYTE) { % theDataType = -1; % } % else if (theDataType > NC_DOUBLE) { % while (theDataType > 255) { % theDataType /= 256; % } % while (theDataType > NC_DOUBLE) { % theDataType /= 2; % } % } % if (VERBOSE) { % mexPrintf(" Converted To %d.\n", theDataType); % } % } % % return (theDataType); %} fclose(fout); cd ('..') bund_setdir('ncfiles') cd ('..') cd ('..') disp(' ') disp(' ## Adjust the Matlab path to include, relative to Current Directory:') disp(' ## "netcdf"') disp(' ## "netcdf:ncfiles"') disp(' ## "netcdf:nctype"') disp(' ## "netcdf:ncutility"') disp(' ## Make sure the Matlab path knows where the') disp(' ## "mexcdf53" Mex-file and (PCWIN only)') disp(' ## "netcdf.dll" are located.') disp(' ## Restart Matlab.') disp(' ## Execute "rehash toolboxcache", then') disp(' ## "tnetcdf" at the Matlab prompt.')