0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % SAVE overloads save operator for ltpda objects.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: SAVE overloads save operator for ltpda objects.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % CALL: save(obj, 'blah.mat') Save an object obj as a .mat file.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % obj.save('blah.mat') Save an object obj as a .mat file.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % obj.save(plist('filename', 'blah.mat'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % save(obj, plist('filename', 'blah.mat'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % save(a, 'blah.xml') Save an object as an XML file.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % a.save(plist('filename', 'blah.xml'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % The method accepts multiple input objects (in a list or in a vector),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % that will be save inside a single file or in multiple files according to the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % "INDIVIDUAL FILES" parameter (see the Parameters Description below)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % <a href="matlab:utils.helper.displayMethodInfo('ltpda_uo', 'save')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % VERSION: $Id: save.m,v 1.41 2011/10/05 09:49:31 ingo Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 function varargout = save(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 %%% Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 import utils.const.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 %%% Collect input variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 for ii = 1:nargin,in_names{ii} = inputname(ii);end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 [objs, objinvars, rest] = utils.helper.collect_objects(varargin(:), '', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 %%% REMARK: Special case for the plist-class because collect_objects collects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 %%% ALL plist-objects even the plist which should set the property.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 %%% In this case must be the plist which sets thte property
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 %%% at the last position.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 if isa(objs, 'plist')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 if nparams(objs(end)) == 1 && isparam(objs(end), 'filename')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 pls = [pls objs(end)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 objs(end) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 %%% Combine the plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 pls = combine(pls, getDefaultPlist());
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 %%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 % 1. Use the filename from the PLIST
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % 2. Use the input string as the filename
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % 3. Use the object name and the current folder for the filename
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 % Must be defined for each object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % 4. If there are more than one input objects and the 'individual files'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 % Switch is false then use the variable name.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 filename = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 if ~isempty(pls.find('filename'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 filename = pls.find('filename');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 elseif ~isempty(rest) && numel(rest) == 1 && iscellstr(rest)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 filename = rest{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 pls.pset('filename', filename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 %%% Make sure that the UUID is set for all objects. This should only
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 %%% happen for PLISTs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 %%% REMARK: This command will also change the plist in the workspace.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 for ii = 1:numel(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 if isempty(objs(ii).UUID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 objs(ii).UUID = char(java.util.UUID.randomUUID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Save object %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % Inspect filename
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 [path, fname, ext] = fileparts(filename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 % Save the objects as MAT files if the user doesn't specify a extension type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 if isempty(ext)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 ext = '.mat';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 % Get pre-, and postfix from the input PLIST
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 prefix = pls.find('prefix');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 postfix = pls.find('postfix');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 individualFiles = pls.find('individual files');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % ATTENTION: We keep the meaning of t0 for backwars compatibility.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % This means
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 % - before saving, t0 = t0 + toffset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % - after loading, t0 = t0 - toffset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 % But be careful. For XML files it is done in the tsdata
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 % methods 'attachToDom' and 'fromDom' because for submitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % we don't use this method.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 switch ext
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 case '.mat'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 % ATTENTION: We moved the changing to the t0 to the MATLAB methods:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 % tsdata/loadobj and tsdata/saveobj
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 objsout = objs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 v = ver('MATLAB');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 % MATLAB version number of 2008b is 7.7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 if utils.helper.ver2num(v.Version) < utils.helper.ver2num('7.7')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 warning('off', 'all')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 shape = size(objs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 objs = utils.prog.rstruct(objs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 objs = reshape(objs, shape);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 warning('on', 'all')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 if (individualFiles == true)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 %%%%% Save each object in individual file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 dummy = objs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 for ii = 1:numel(dummy)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 objs = dummy(ii);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 % Define full filename
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 if isempty(fname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 fullFilename = getFullFilename(objs.name);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 postfix = sprintf('%s_%03d', pls.find('postfix'), ii);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 fullFilename = getFullFilename(fname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 save(fullFilename, 'objs');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 %%%%% Save all objects in one file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 if isempty(fname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 fullFilename = getFullFilename(inputname(1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 warning('!!! You have not specified any file name -> Using first variable name as file name.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 fullFilename = getFullFilename(fname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 save(fullFilename, 'objs');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 objs = objsout;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 case '.xml'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 if (individualFiles == true)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 %%%%% Save each object in individual file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 for ii = 1:numel(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 if isempty(fname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 fullFilename = getFullFilename(objs(ii).name);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 postfix = sprintf('%s_%03d', pls.find('postfix'), ii);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 fullFilename = getFullFilename(fname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 saveObjectAsXML(objs(ii), fullFilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 %%%%% Save all objects in one file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 if isempty(fname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 fullFilename = getFullFilename(inputname(1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 warning('!!! You have not specified any file name -> Using first variable name as file name.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 fullFilename = getFullFilename(fname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 saveObjectAsXML (objs, fullFilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 error('### unknown file extension [%s].', ext);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 varargout{1} = objs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 % Return the full file name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 function fullFilename = getFullFilename(fname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 % concatenate the prefix, filename, postfix and the file extension.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 fname = strcat(prefix, fname, postfix, ext);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 % build full filename
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 fullFilename = fullfile(path, fname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 % Local Functions %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 % save object as XML file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 function saveObjectAsXML (obj, fullFilename)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 % Create DOM node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 dom = com.mathworks.xml.XMLUtils.createDocument('ltpda_object');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 parent = dom.getDocumentElement;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 % add Attribute 'ltpda_version' to the root node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 ltpda_version = getappdata(0, 'ltpda_version');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 parent.setAttribute('ltpda_version', ltpda_version);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 if (utils.helper.ver2num(ltpda_version) > utils.helper.ver2num('2.3')) || ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 (strcmp(strtok(ltpda_version), '2.3'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 %%%%%%%%%%%%%%%%%% saving of a new XML file %%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 % Create history root node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 % The attachToDom methods will attach their histories to this node.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 historyRootNode = dom.createElement('historyRoot');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 parent.appendChild(historyRootNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 % Write objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 obj.attachToDom(dom, parent, []);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 %%%%%%%%%%%%%%%%%% saving of a old XML file %%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 utils.xml.xmlwrite(obj, dom, parent, ''); % Save the XML document.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 % Write to file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 % Ingo: I want to use our own XML write method because I miss on my
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 % machine the indent.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 if isempty(strfind(fullFilename, filesep))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 result = javax.xml.transform.stream.StreamResult(fullfile(pwd, fullFilename));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 result = javax.xml.transform.stream.StreamResult(fullFilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 mpipeline.utils.XMLUtils.serializeXML(dom, result, 'UTF-8')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 % xmlwrite(fullFilename, dom);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 % Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 pl = getDefaultPlist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 ii = minfo(mfilename, 'ltpda_uo', 'ltpda', utils.const.categories.output, '$Id: save.m,v 1.41 2011/10/05 09:49:31 ingo Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 ii.setOutmin(0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 % Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 function plout = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 persistent pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 if ~exist('pl', 'var') || isempty(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 pl = buildplist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 plout = pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 function pl = buildplist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 % General plist for saving objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 pl = plist.SAVE_OBJ_PLIST;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283
|