Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@helper/saveobj.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@helper/saveobj.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,47 @@ +function varargout = saveobj(a, pl) +% SAVEOBJ saves an object to a file. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: SAVEOBJ saves an object to a file. +% +% CALL: saveobj(obj, pl) +% +% INPUTS: obj - an object (for example, an AO) +% pl - parameter list with a 'filename' parameter +% +% Supported file types are '.mat' and '.xml'. +% +% OUTPUTS: +% +% VERSION: $Id: saveobj.m,v 1.3 2010/09/17 14:12:31 ingo Exp $ +% +% HISTORY: 28-08-2007 M Hewitson +% Creation +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% get filename +filename = find(pl, 'filename'); + +% Inspect filename +[path,name,ext] = fileparts(filename); + +switch ext + case '.mat' + + save(filename, 'a'); + + case '.xml' + + % convert object to xml + xml = com.mathworks.xml.XMLUtils.createDocument('ltpda_object'); + parent = xml.getDocumentElement; + + utils.xml.xmlwrite(a, xml, parent, ''); % Save the XML document. + xmlwrite(filename, xml); + + otherwise + error('### unknown file extension.'); +end +