0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % CSVEXPORT Exports the data of an object to a csv file.
|
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 % FUNCTION: csvexport
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % DESCRIPTION: Exports the data of an object to a csv file.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % CALL: csvexport(in-objects)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % INPUTS: in-objects: Input objects which data should be stored to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % disc.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % OUTPUTS: success: If storing of the data was successful
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % <a href="matlab:utils.helper.displayMethodInfo('ltpda_uoh', 'csvexport')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % VERSION: $Id: csvexport.m,v 1.7 2011/04/08 08:56:30 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 function varargout = csvexport(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 %%% Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), '');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 pli = utils.helper.collect_objects(rest(:), 'plist');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 [data, plData] = csvGenerateData(objs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 pl = combine(pli, getDefaultPlist);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 filename = pl.find('filename');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 commentChar = pl.find('commentChar');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 description = pl.find('description');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % Some plausibility checks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 if isempty(filename)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 if ~isempty(rest) && ischar(rest{1})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 filename = rest{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 pl.pset('filename', filename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 error('### No filename is specified');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 if isempty(description)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 description = plData.find('DESCRIPTION');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 columns = plData.find('COLUMNS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 nrows = plData.find('NROWS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 ncols = plData.find('NCOLS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 objIDs = plData.find('OBJECT IDS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 objNames = plData.find('OBJECT NAMES');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 creator = plData.find('CREATOR');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 created = format(time(), 'yyyy-mm-dd HH:MM');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 fid = fopen(filename, 'w');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % Check fid
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 if fid == -1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 error('### Can not open the file: %s', filename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 %%% write header %%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 fprintf(fid, '%s DESCRIPTION: %s\n', commentChar, description);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 fprintf(fid, '%s COLUMNS: %s\n', commentChar, columns);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 columnNames = strtrim(regexp(columns, ',', 'split'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 maxColNames = max(cellfun(@length, columnNames));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 for ii = 1:numel(columnNames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 columnDesc = plData.find(columnNames{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 if ~isempty(columnDesc)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 off = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 off(1:maxColNames-length(columnNames{ii})) = ' ';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 fprintf(fid, '%s %s%s: %s\n', commentChar, columnNames{ii}, off, columnDesc);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 fprintf(fid, '%s NROWS: %d\n', commentChar, nrows);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 fprintf(fid, '%s NCOLS: %d\n', commentChar, ncols);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 fprintf(fid, '%s OBJECT IDS: %s\n', commentChar, objIDs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 fprintf(fid, '%s OBJECT NEAMES: %s\n', commentChar, objNames);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 fprintf(fid, '%s CREATION DATE: %s\n', commentChar, created);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 fprintf(fid, '%s CREATED BY: %s\n', commentChar, creator);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 fprintf(fid, '%s\n', commentChar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 %%% write data %%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 for nn=1:nrows
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 for dd = 1:ncols
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 if numel(data{dd}) >= nn
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 fprintf(fid, '%.17f', data{dd}(nn));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 if dd < numel(data)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 fprintf(fid, ',');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 fprintf(fid, '\n');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 fclose(fid);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % Local Functions %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 % FUNCTION: getInfo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 % DESCRIPTION: Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 pl = getDefaultPlist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 ii = minfo(mfilename, 'ltpda_uoh', 'ltpda', utils.const.categories.helper, '$Id: csvexport.m,v 1.7 2011/04/08 08:56:30 hewitson Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 % FUNCTION: getDefaultPlist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % DESCRIPTION: Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 function plout = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 persistent pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 if exist('pl', 'var')==0 || isempty(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 pl = buildplist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 plout = pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 function plo = buildplist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 plo = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 p = param({'filename' 'cvs filename.'}, '');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 p = param({'commentChar','The comment character in the file.'}, {1, {'#'}, paramValue.OPTIONAL});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 p = param({'description', 'Description for the file.'}, '');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171
|