Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/csvGenerateData.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % CSVGENERATEDATA Default method to convert a ltpda_uoh-object into csv data. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: csvGenerateData | |
5 % | |
6 % DESCRIPTION: | |
7 % | |
8 % CALL: [data, pl] = csvGenerateData(ltpda_uoh) | |
9 % | |
10 % INPUTS: ltpda_uoh: Input objects | |
11 % | |
12 % OUTPUTS: data: Cell array with the data which should should be | |
13 % written to the file. | |
14 % pl: Parameter list which contains the description of the | |
15 % data. The parameter list must contain the following | |
16 % keys: | |
17 % 'DESCRIPTION': Description for the file | |
18 % 'COLUMNS': Meaning of each column seperated by a | |
19 % comma. For additional information add | |
20 % this name as a key and a description as | |
21 % the value. For example: | |
22 % | key | value | |
23 % ----------------------- | |
24 % |COLUMNS| 'X1, X2' | |
25 % | X1 | 'x-axis data' | |
26 % | X2 | 'y-axis data' | |
27 % | |
28 % 'NROWS': Bumber of rows | |
29 % 'NCOLS': Number of columns | |
30 % 'OBJECT IDS': UUID of the objects seperated by a comma | |
31 % 'OBJECT NEAMES': Object names seperated by a comma | |
32 % 'CREATOR': Creator of the objects | |
33 % | |
34 % VERSION: $Id: csvGenerateData.m,v 1.2 2010/12/17 15:33:57 hewitson Exp $ | |
35 % | |
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
37 | |
38 function [data, pl] = csvGenerateData(objs) | |
39 | |
40 description = ''; | |
41 columns = ''; | |
42 uuids = ''; | |
43 names = ''; | |
44 creators = {}; | |
45 creatorStr = ''; | |
46 data = {}; | |
47 pl = getDefaultPlist(); | |
48 | |
49 for nn = 1:numel(objs) | |
50 | |
51 %%%%%%%%%%%%%%%%%%%%%% Define header information %%%%%%%%%%%%%%%%%%%%%% | |
52 if isempty(description) | |
53 description = objs(nn).description; | |
54 else | |
55 description = sprintf('%s | %s', description, strrep(objs(nn).description, '|', '')); | |
56 end | |
57 if isempty(uuids) | |
58 uuids = objs(nn).UUID; | |
59 else | |
60 uuids = sprintf('%s, %s', uuids, objs(nn).UUID); | |
61 end | |
62 if isempty(names) | |
63 names = objs(nn).name; | |
64 else | |
65 names = sprintf('%s, %s', names, strrep(objs(nn).name, ',', '')); | |
66 end | |
67 creator = objs(nn).creator('all'); | |
68 creators = [creators, creator]; | |
69 | |
70 %%%%%%%%%%%%%%%%%%%%%% Generate data information %%%%%%%%%%%%%%%%%%%%%% | |
71 | |
72 x = objs(nn).x; | |
73 y = objs(nn).y; | |
74 dx = objs(nn).dx; | |
75 dy = objs(nn).dy; | |
76 | |
77 if isreal(x) && isreal(y) | |
78 %%%%%%%%%% real Data %%%%%%%%%% | |
79 | |
80 | |
81 if ~isa(objs(nn).data, 'cdata') | |
82 [columns, pl] = prepareDataDesc(columns, pl, sprintf('X%d',nn), 'x-data'); | |
83 end | |
84 [columns, pl] = prepareDataDesc(columns, pl, sprintf('Y%d',nn), 'y-data'); | |
85 data = [data x y]; | |
86 | |
87 %%% Add error if it exists | |
88 if ~isempty(dx) || ~isempty(dy) | |
89 if ~isa(objs(nn).data, 'cdata') | |
90 [columns, pl] = prepareDataDesc(columns, pl, sprintf('DX%d',nn), 'error of the x-data'); | |
91 end | |
92 [columns, pl] = prepareDataDesc(columns, pl, sprintf('DY%d',nn), 'error of the y-data'); | |
93 data = [data dx dy]; | |
94 end | |
95 | |
96 else | |
97 %%%%%%%%%% complex Data %%%%%%%%%% | |
98 | |
99 if ~isa(objs(nn).data, 'cdata') | |
100 [columns, pl] = prepareDataDesc(columns, pl, sprintf('real(X%d)',nn), 'real part of the x-data'); | |
101 end | |
102 if ~isa(objs(nn).data, 'cdata') | |
103 [columns, pl] = prepareDataDesc(columns, pl, sprintf('imag(X%d)',nn), 'imaginary part of the x-data'); | |
104 end | |
105 [columns, pl] = prepareDataDesc(columns, pl, sprintf('real(Y%d)',nn), 'real part of the y-data'); | |
106 [columns, pl] = prepareDataDesc(columns, pl, sprintf('imag(Y%d)',nn), 'imaginary part of the y-data'); | |
107 data = [data real(x) imag(x) real(y) imag(y)]; | |
108 | |
109 %%% Add error if it exists | |
110 if ~isempty(dx) || ~isempty(dy) | |
111 if ~isa(objs(nn).data, 'cdata') | |
112 [columns, pl] = prepareDataDesc(columns, pl, sprintf('real(DX%d)',nn), 'real part of the error of x'); | |
113 end | |
114 if ~isa(objs(nn).data, 'cdata') | |
115 [columns, pl] = prepareDataDesc(columns, pl, sprintf('imag(DX%d)',nn), 'imaginary part of the error of x'); | |
116 end | |
117 [columns, pl] = prepareDataDesc(columns, pl, sprintf('real(DY%d)',nn), 'real part of the error of y'); | |
118 [columns, pl] = prepareDataDesc(columns, pl, sprintf('imag(DY%d)',nn), 'imaginary part of the error of y'); | |
119 data = [data real(dx) imag(dx) real(y) imag(y)]; | |
120 end | |
121 | |
122 end | |
123 | |
124 end | |
125 | |
126 nrows = max(cellfun(@length, data)); | |
127 ncols = numel(data); | |
128 if ~isempty(columns) | |
129 columns = columns(3:end); | |
130 end | |
131 creators = unique(creators); | |
132 for ii = 1:numel(creators) | |
133 if isempty(creatorStr) | |
134 creatorStr = creators{ii}; | |
135 else | |
136 creatorStr = sprintf('%s, %s', creatorStr, creators{ii}); | |
137 end | |
138 end | |
139 | |
140 pl.pset('DESCRIPTION', description); | |
141 pl.pset('COLUMNS', columns); | |
142 pl.pset('NROWS', nrows); | |
143 pl.pset('NCOLS', ncols); | |
144 pl.pset('OBJECT IDS', uuids); | |
145 pl.pset('OBJECT NAMES', names); | |
146 pl.pset('CREATOR', creatorStr); | |
147 | |
148 | |
149 | |
150 | |
151 % error('### If it is necessary to export a %-object then add a change request to MANTIS. https://ed.fbk.eu/ltpda/mantis/login_page.php', class(objs)); | |
152 | |
153 end | |
154 | |
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
156 % | |
157 % FUNCTION: getDefaultPlist | |
158 % | |
159 % DESCRIPTION: Get Default Plist | |
160 % | |
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
162 | |
163 function plout = getDefaultPlist() | |
164 persistent pl; | |
165 if exist('pl', 'var')==0 || isempty(pl) | |
166 pl = buildplist(); | |
167 end | |
168 plout = pl; | |
169 end | |
170 | |
171 function plo = buildplist() | |
172 plo = plist(... | |
173 'DESCRIPTION', '', ... | |
174 'COLUMNS', '', ... | |
175 'NROWS', -1, ... | |
176 'NCOLS', -1, ... | |
177 'OBJECT IDS', '', ... | |
178 'OBJECT NEAMES', '', ... | |
179 'CREATOR', ''); | |
180 end | |
181 | |
182 function [columns, pl] = prepareDataDesc(columns, pl, colName, colDesc) | |
183 columns = sprintf('%s, %s', columns, colName); | |
184 pl.append(colName, colDesc); | |
185 end | |
186 |