Home > classes > @ltpda_uo > save.m

save

PURPOSE ^

SAVE overloads save operator for ltpda objects.

SYNOPSIS ^

function varargout = save(varargin)

DESCRIPTION ^

 SAVE overloads save operator for ltpda objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SAVE overloads save operator for ltpda objects.

 CALL:        save(a, 'blah.mat') Save an object as a .mat file.
              save(a, 'blah.xml') Save an object as an XML file.

 PARAMETERS: 'filename' - name of the file

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('save')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('save', 'set')

 VERSION:     $Id: save.m,v 1.5 2008/09/07 18:15:04 hewitson Exp $

 HISTORY: 14-02-07 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % SAVE overloads save operator for ltpda objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: SAVE overloads save operator for ltpda objects.
0005 %
0006 % CALL:        save(a, 'blah.mat') Save an object as a .mat file.
0007 %              save(a, 'blah.xml') Save an object as an XML file.
0008 %
0009 % PARAMETERS: 'filename' - name of the file
0010 %
0011 % M-FILE INFO: Get information about this methods by calling
0012 %              >> ao.getInfo('save')
0013 %
0014 %              Get information about a specified set-plist by calling:
0015 %              >> ao.getInfo('save', 'set')
0016 %
0017 % VERSION:     $Id: save.m,v 1.5 2008/09/07 18:15:04 hewitson Exp $
0018 %
0019 % HISTORY: 14-02-07 M Hewitson
0020 %             Creation
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 function varargout = save(varargin)
0025 
0026   %%% Check if this is a call for parameters
0027   if utils.helper.isinfocall(varargin{:})
0028     varargout{1} = getInfo(varargin{3});
0029     return
0030   end
0031 
0032   %%% Collect input variable names
0033   in_names = cell(size(varargin));
0034   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0035 
0036   [objs, invars, rest] = utils.helper.collect_objects(varargin(:), '', in_names);
0037   [pls,  invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
0038 
0039   %%% REMARK: Special case for the plist-class because collect_objects collects
0040   %%%         ALL plist-objects even the plist which should set the property.
0041   %%%         In this case must be the plist which sets thte property
0042   %%%         at the last position.
0043   if isa(objs, 'plist')
0044     if nparams(objs(end)) == 1 && isparam(objs(end), 'filename')
0045       pls = [pls objs(end)];
0046       objs(end) = [];
0047     end
0048   end
0049 
0050   %%% Combine the plists
0051   if isa(pls, 'plist')
0052     pls = combine(pls);
0053   end
0054 
0055   %%% If we eliminated the objects and plists then is the rest the property name
0056   if length(rest) == 1 || ~isparam(pls, 'filename')
0057     filename = rest;
0058   else
0059     error('### Please specify [only one] filename.')
0060   end
0061 
0062   %%% If rest contains the filename then use this filename
0063   if length(filename) == 1 && ischar(filename{1})
0064     pls = combine(plist('filename', filename{1}), pls);
0065   end
0066 
0067   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   Save object   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0068 
0069   % get filename
0070   filename = find(pls, 'filename');
0071 
0072   % Inspect filename
0073   [path, name, ext] = fileparts(filename);
0074 
0075   switch ext
0076     case '.mat'
0077 
0078       objs = utils.prog.rstruct(objs);
0079       save(filename, 'objs');
0080 
0081     case '.xml'
0082 
0083       % convert object to xml
0084       xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object');
0085       parent = xml.getDocumentElement;
0086 
0087       %     % add style sheet
0088       %     stylesheet = xml.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="ingo.xsl"');
0089       %     xml.insertBefore(stylesheet, xml.getChildNodes.item(0));
0090 
0091       % add Attribute 'ltpda_version' to the root node
0092       ltpda_version   = getappdata(0, 'ltpda_version');
0093       parent.setAttribute('ltpda_version', ltpda_version);
0094 
0095       utils.helper.xmlwrite(objs, xml, parent, '');    % Save the XML document.
0096       xmlwrite(filename, xml);
0097 
0098     otherwise
0099       error('### unknown file extension.');
0100   end
0101 
0102 end
0103 
0104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0105 %                               Local Functions                               %
0106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0107 
0108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0109 %
0110 % FUNCTION:    getInfo
0111 %
0112 % DESCRIPTION: Get Info Object
0113 %
0114 % HISTORY:     11-07-07 M Hewitson
0115 %                Creation.
0116 %
0117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0118 
0119 function ii = getInfo(varargin)
0120   if nargin == 1 && strcmpi(varargin{1}, 'None')
0121     sets = {};
0122     pl   = [];
0123   else
0124     sets = {'Default'};
0125     pl   = getDefaultPlist;
0126   end
0127   % Build info object
0128   ii = minfo(mfilename, 'ltpda_uo', '', utils.const.categories.output, '$Id: save.m,v 1.5 2008/09/07 18:15:04 hewitson Exp $', sets, pl);
0129 end
0130 
0131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0132 %
0133 % FUNCTION:    getDefaultPlist
0134 %
0135 % DESCRIPTION: Get Default Plist
0136 %
0137 % HISTORY:     11-07-07 M Hewitson
0138 %                Creation.
0139 %
0140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0141 
0142 function plo = getDefaultPlist()
0143   plo = plist('filename', 'object.xml');
0144 end
0145

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003