0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % Callback executed when the user clicks on the save button.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % M Hewitson
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: cb_saveBtn.m,v 1.4 2009/09/11 18:23:37 ingo Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 function cb_saveBtn(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 myh = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 mainfig = varargin{end};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % Get connection
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % mainfig = findobj('Tag', 'LTPDARepomainfig');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 conn = mainfig.connection;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 if isempty(conn) || ~isa(conn, 'database')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 utils.helper.errorDlg('Please connect to a database first', 'No connection found');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % Get variable name specs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 h = findobj(mainfig.handle, 'Tag', 'objPrefixTxt');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 prefix = get(h, 'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 if isempty(prefix)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 prefix = 'obj';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 warning('! Using default prefix (obj)');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 h = findobj(mainfig.handle, 'Tag', 'appendObjTypeChk');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 appendObj = get(h, 'Value');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 h = findobj(mainfig.handle, 'Tag', 'retrieveBinaryChk');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 retrieveBinary = get(h, 'Value');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 % Get IDs from text box
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 [ids, cids] = getIds(mainfig);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 %---------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % Retrieve these ids
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 objs = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 for j=1:length(ids)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 disp(sprintf('+ retrieving object %d', ids(j)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % determine object type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 tt = utils.mysql.getObjType(conn, ids(j));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 objname = sprintf('%s%03d', prefix, ids(j));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 if ~isempty(tt) && ~strcmp(tt, 'No Data')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 if appendObj
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 objname = [objname '_' tt];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 error('!!! Object type is unknown. Does this object really exist?');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 % add file extension
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 objname = [objname '.xml'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % Retrieve object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 a = regexp(conn.URL, '//(\S+)/', 'tokens');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 db = regexp(conn.URL, '/', 'split');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 db = db{end};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 pl = plist('hostname', a{1}, 'database', db, 'ID', ids(j), 'conn', conn);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 if retrieveBinary
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 pl.append('Binary', 'yes');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 disp(sprintf('*** performing binary retrieval.'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 obj = eval(sprintf('%s(pl);', tt));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 % write to disk
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 save(obj, objname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 % assignin('base', objname, obj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 disp(sprintf('** Retrieve object %d to disk [%s]', ids(j), objname));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 if j==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 objs = {obj};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 objs = [objs {obj}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 disp(sprintf('** Retrieved %d objects.', length(ids)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 %---------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % Retrieve these Collections
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 for k=1:length(cids)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 % get Ids from Cid
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 ids = mysql_getObjIds(conn, cids(k));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 if isempty(ids)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 error('### This collection doesn''t seem to exist.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 for j=1:length(ids)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 tt = utils.mysql.getObjType(conn, ids(j));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 if appendObj
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 objname = [objname '_' tt];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 % Retrieve object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 ipbits = regexp(conn.URL, '([0-9]+)', 'match');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 db = regexp(conn.URL, '/', 'split');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 db = db{end};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 obj = eval(sprintf('%s(pl);', tt));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 assignin('base', objname, obj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 if j==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 objs = {obj};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 objs = [objs {obj}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 end
|
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 disp(sprintf('** Retrieved %d objects.', length(ids)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 function [ids, cids] = getIds(mainfig)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 ids = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 cids = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 th = findobj(mainfig.handle, 'Tag', 'retrieveIDsTxt');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 idStr = get(th, 'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 cs = cellstr(idStr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 for j=1:length(cs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 disp('---------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 ls = cs{j};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 [s,r] = strtok(ls);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 if ~isempty(s)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 if s(1) == 'c'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 s = s(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 cids = [cids round(str2num(s))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 ids = [ids round(str2num(s))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 while ~isempty(r)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 [s,r] = strtok(r);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 if ~isempty(s)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 if s(1) == 'c'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 s = s(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 cids = [cids round(str2num(s))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 ids = [ids round(str2num(s))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 end
|