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.3 2008/08/22 14:09:09 ingo 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.3 2008/08/22 14:09:09 ingo 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       save(filename, 'objs');
0079 
0080     case '.xml'
0081 
0082       % convert object to xml
0083       xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object');
0084       parent = xml.getDocumentElement;
0085 
0086       %     % add style sheet
0087       %     stylesheet = xml.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="ingo.xsl"');
0088       %     xml.insertBefore(stylesheet, xml.getChildNodes.item(0));
0089 
0090       % add Attribute 'ltpda_version' to the root node
0091       ltpda_version   = getappdata(0, 'ltpda_version');
0092       parent.setAttribute('ltpda_version', ltpda_version);
0093 
0094       utils.helper.xmlwrite(objs, xml, parent, '');    % Save the XML document.
0095       xmlwrite(filename, xml);
0096 
0097     otherwise
0098       error('### unknown file extension.');
0099   end
0100 
0101 end
0102 
0103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0104 %                               Local Functions                               %
0105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0106 
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 %
0109 % FUNCTION:    getInfo
0110 %
0111 % DESCRIPTION: Get Info Object
0112 %
0113 % HISTORY:     11-07-07 M Hewitson
0114 %                Creation.
0115 %
0116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0117 
0118 function ii = getInfo(varargin)
0119   if nargin == 1 && strcmpi(varargin{1}, 'None')
0120     sets = {};
0121     pl   = [];
0122   else
0123     sets = {'Default'};
0124     pl   = getDefaultPlist;
0125   end
0126   % Build info object
0127   ii = minfo(mfilename, 'ltpda_uo', '', 'Output', '$Id: save.m,v 1.3 2008/08/22 14:09:09 ingo Exp $', sets, pl);
0128 end
0129 
0130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0131 %
0132 % FUNCTION:    getDefaultPlist
0133 %
0134 % DESCRIPTION: Get Default Plist
0135 %
0136 % HISTORY:     11-07-07 M Hewitson
0137 %                Creation.
0138 %
0139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0140 
0141 function plo = getDefaultPlist()
0142   plo = plist('filename', 'object.xml');
0143 end
0144

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003