1 | function varargout = mmlviewer(varargin) |
---|
2 | % MMLVIEWER M-file for mmlviewer.fig |
---|
3 | % MMLVIEWER, by itself, creates a new MMLVIEWER or raises the existing |
---|
4 | % singleton*. |
---|
5 | % |
---|
6 | % H = MMLVIEWER returns the handle to a new MMLVIEWER or the handle to |
---|
7 | % the existing singleton*. |
---|
8 | % |
---|
9 | % MMLVIEWER('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
10 | % function named CALLBACK in MMLVIEWER.M with the given input arguments. |
---|
11 | % |
---|
12 | % MMLVIEWER('Property','Value',...) creates a new MMLVIEWER or raises the |
---|
13 | % existing singleton*. Starting from the left, property value pairs are |
---|
14 | % applied to the GUI before mmlviewer_OpeningFunction gets called. An |
---|
15 | % unrecognized property name or invalid value makes property application |
---|
16 | % stop. All inputs are passed to mmlviewer_OpeningFcn via varargin. |
---|
17 | % |
---|
18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
19 | % instance to run (singleton)". |
---|
20 | % |
---|
21 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
22 | |
---|
23 | % Edit the above text to modify the response to help mmlviewer |
---|
24 | |
---|
25 | % Last Modified by GUIDE v2.5 01-Nov-2006 11:34:04 |
---|
26 | |
---|
27 | % Begin initialization code - DO NOT EDIT |
---|
28 | gui_Singleton = 0; |
---|
29 | gui_State = struct('gui_Name', mfilename, ... |
---|
30 | 'gui_Singleton', gui_Singleton, ... |
---|
31 | 'gui_OpeningFcn', @mmlviewer_OpeningFcn, ... |
---|
32 | 'gui_OutputFcn', @mmlviewer_OutputFcn, ... |
---|
33 | 'gui_LayoutFcn', [] , ... |
---|
34 | 'gui_Callback', []); |
---|
35 | if nargin && ischar(varargin{1}) |
---|
36 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
37 | end |
---|
38 | |
---|
39 | if nargout |
---|
40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
41 | else |
---|
42 | gui_mainfcn(gui_State, varargin{:}); |
---|
43 | end |
---|
44 | % End initialization code - DO NOT EDIT |
---|
45 | |
---|
46 | |
---|
47 | % --- Executes just before mmlviewer is made visible. |
---|
48 | function mmlviewer_OpeningFcn(hObject, eventdata, handles, varargin) |
---|
49 | |
---|
50 | % Choose default command line output for mmlviewer |
---|
51 | handles.output = hObject; |
---|
52 | |
---|
53 | % Update handles structure |
---|
54 | guidata(hObject, handles); |
---|
55 | |
---|
56 | try |
---|
57 | if ~(isepics || istango) |
---|
58 | set(handles.ListBox5, 'Visible', 'Off'); |
---|
59 | else |
---|
60 | set(handles.ListBox5, 'Value', 1); |
---|
61 | set(handles.ListBox5, 'String', ''); |
---|
62 | end |
---|
63 | |
---|
64 | set(handles.axes1,'XTickLabel',''); |
---|
65 | set(handles.axes1,'YTickLabel',''); |
---|
66 | |
---|
67 | % Fill the list boxes |
---|
68 | ViewAO_Callback(hObject, eventdata, handles); |
---|
69 | %ListBox1_Callback(hObject, eventdata, handles); |
---|
70 | |
---|
71 | |
---|
72 | % Make Monitor the default, if possible |
---|
73 | Fields = get(handles.ListBox2, 'String'); |
---|
74 | if length(Fields) >= 1 |
---|
75 | k = find(strcmpi(Fields, 'Monitor')); |
---|
76 | if ~isempty(k) |
---|
77 | set(handles.ListBox2, 'Value', k); |
---|
78 | ListBox2_Callback(hObject, eventdata, handles); |
---|
79 | end |
---|
80 | end |
---|
81 | |
---|
82 | % Make TangoNames the default, if possible |
---|
83 | Fields = get(handles.ListBox3, 'String'); |
---|
84 | if length(Fields) >= 1 |
---|
85 | k = find(strcmpi(Fields, 'TangoNames')); |
---|
86 | if isempty(k) |
---|
87 | k = find(strcmpi(Fields, 'TangoNames')); |
---|
88 | end |
---|
89 | if ~isempty(k) |
---|
90 | set(handles.ListBox3, 'Value', k); |
---|
91 | ListBox3_Callback(hObject, eventdata, handles); |
---|
92 | end |
---|
93 | end |
---|
94 | |
---|
95 | catch |
---|
96 | end |
---|
97 | |
---|
98 | |
---|
99 | % UIWAIT makes mmlviewer wait for user response (see UIRESUME) |
---|
100 | % uiwait(handles.figure1); |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | % --- Outputs from this function are returned to the command line. |
---|
105 | function varargout = mmlviewer_OutputFcn(hObject, eventdata, handles) |
---|
106 | |
---|
107 | % Get default command line output from handles structure |
---|
108 | varargout{1} = handles.output; |
---|
109 | |
---|
110 | |
---|
111 | % -------------------------------------------------------------------- |
---|
112 | function FileMenu_Callback(hObject, eventdata, handles) |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | % -------------------------------------------------------------------- |
---|
117 | function OpenMenuItem_Callback(hObject, eventdata, handles) |
---|
118 | [file, Directory] = uigetfile('*.fig'); |
---|
119 | if ~isequal(file, 0) |
---|
120 | open([Directory file]); |
---|
121 | end |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | % -------------------------------------------------------------------- |
---|
126 | function CloseMenuItem_Callback(hObject, eventdata, handles) |
---|
127 | % selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],... |
---|
128 | % ['Close ' get(handles.figure1,'Name') '...'],... |
---|
129 | % 'Yes','No','Yes'); |
---|
130 | % if strcmp(selection,'No') |
---|
131 | % return; |
---|
132 | % end |
---|
133 | delete(handles.figure1) |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | % -------------------------------------------------------------------- |
---|
138 | function PrintMenuItem_Callback(hObject, eventdata, handles) |
---|
139 | printdlg(handles.figure1) |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | % --- Executes on selection change in ListBox1. |
---|
145 | function ListBox1_Callback(hObject, eventdata, handles) |
---|
146 | |
---|
147 | RootStruct = getappdata(handles.figure1, 'RootStruct'); |
---|
148 | Fields = fieldnames(RootStruct); |
---|
149 | j = get(handles.ListBox1, 'Value'); |
---|
150 | |
---|
151 | Data = RootStruct; |
---|
152 | |
---|
153 | Box0 = handles.ListBox1; |
---|
154 | Box1 = handles.ListBox2; |
---|
155 | Box2 = handles.ListBox3; |
---|
156 | |
---|
157 | CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, j); |
---|
158 | |
---|
159 | if CallNextListBox |
---|
160 | ListBox2_Callback(hObject, eventdata, handles); |
---|
161 | else |
---|
162 | set(handles.ListBox3, 'Value', 1); |
---|
163 | set(handles.ListBox3, 'String', ''); |
---|
164 | set(handles.ListBox4, 'Value', 1); |
---|
165 | set(handles.ListBox4, 'String', ''); |
---|
166 | end |
---|
167 | |
---|
168 | |
---|
169 | % --- Executes on selection change in ListBox2. |
---|
170 | function ListBox2_Callback(hObject, eventdata, handles) |
---|
171 | |
---|
172 | RootStruct = getappdata(handles.figure1, 'RootStruct'); |
---|
173 | Fields = fieldnames(RootStruct); |
---|
174 | i = get(handles.ListBox1, 'Value'); |
---|
175 | j = get(handles.ListBox2, 'Value'); |
---|
176 | Data = RootStruct.(Fields{i}); |
---|
177 | |
---|
178 | Box0 = handles.ListBox2; |
---|
179 | Box1 = handles.ListBox3; |
---|
180 | Box2 = handles.ListBox4; |
---|
181 | |
---|
182 | CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, j, RootStruct, Fields{i}); |
---|
183 | |
---|
184 | if CallNextListBox |
---|
185 | ListBox3_Callback(hObject, eventdata, handles); |
---|
186 | else |
---|
187 | set(handles.ListBox4, 'Value', 1); |
---|
188 | set(handles.ListBox4, 'String', ''); |
---|
189 | end |
---|
190 | |
---|
191 | |
---|
192 | % --- Executes on selection change in ListBox3. |
---|
193 | function ListBox3_Callback(hObject, eventdata, handles) |
---|
194 | |
---|
195 | RootStruct = getappdata(handles.figure1, 'RootStruct'); |
---|
196 | Fields1 = fieldnames(RootStruct); |
---|
197 | Fields2 = get(handles.ListBox2, 'String'); |
---|
198 | Fields3 = get(handles.ListBox3, 'String'); |
---|
199 | |
---|
200 | i = get(handles.ListBox1, 'Value'); |
---|
201 | j = get(handles.ListBox2, 'Value'); |
---|
202 | k = get(handles.ListBox3, 'Value'); |
---|
203 | |
---|
204 | Data = RootStruct.(Fields1{i}).(Fields2{j}); |
---|
205 | |
---|
206 | Box0 = handles.ListBox3; |
---|
207 | Box1 = handles.ListBox4; |
---|
208 | Box2 = handles.ListBox5; |
---|
209 | |
---|
210 | CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, k, RootStruct.(Fields1{i}), Fields2{j}); |
---|
211 | |
---|
212 | if CallNextListBox |
---|
213 | ListBox4_Callback(hObject, eventdata, handles); |
---|
214 | end |
---|
215 | |
---|
216 | |
---|
217 | % --- Executes on selection change in ListBox4. |
---|
218 | function ListBox4_Callback(hObject, eventdata, handles) |
---|
219 | |
---|
220 | i = get(handles.ListBox4, 'Value'); |
---|
221 | Data = get(handles.ListBoxData, 'String'); |
---|
222 | %DataFields = fieldnames(Data); |
---|
223 | |
---|
224 | if size(Data, 1) == size(get(handles.ListBox4,'String'),1) |
---|
225 | set(handles.ListBoxData, 'Value', i); |
---|
226 | end |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | % --- Executes on selection change in ListBox5. |
---|
231 | function ListBox5_Callback(hObject, eventdata, handles) |
---|
232 | |
---|
233 | RootStruct = getappdata(handles.figure1, 'RootStruct'); |
---|
234 | Fields1 = fieldnames(RootStruct); |
---|
235 | Fields2 = get(handles.ListBox2, 'String'); |
---|
236 | |
---|
237 | i = get(handles.ListBox1, 'Value'); |
---|
238 | j = get(handles.ListBox2, 'Value'); |
---|
239 | |
---|
240 | |
---|
241 | EPICSFields = get(handles.ListBox5, 'UserData'); |
---|
242 | iEPICS = get(handles.ListBox5, 'Value'); |
---|
243 | setappdata(handles.figure1, 'iEPICS', iEPICS); |
---|
244 | if ~isempty(EPICSFields) |
---|
245 | DotField = EPICSFields{iEPICS}; |
---|
246 | else |
---|
247 | DotField = ''; |
---|
248 | end |
---|
249 | |
---|
250 | |
---|
251 | % Get data |
---|
252 | try |
---|
253 | Data = getandplotdata(handles, Fields1{i}, Fields2{j}, DotField, family2dev(Fields1{i})); |
---|
254 | catch |
---|
255 | fprintf(' Could not get data for the %s family.\n', Fields1{i}); |
---|
256 | return; |
---|
257 | end |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | % -------------------------------------------------------------------- |
---|
262 | function Graph1_ButtonDown(hObject, eventdata, handles) |
---|
263 | CurrentPoint = get(handles.axes1, 'CurrentPoint'); |
---|
264 | SposMouse = CurrentPoint(1,1); |
---|
265 | SposData = getappdata(handles.figure1, 'SPosX'); |
---|
266 | |
---|
267 | MeritFcn = abs(SposData-SposMouse); |
---|
268 | i = find(min(MeritFcn) == MeritFcn); |
---|
269 | if ~isempty(i) |
---|
270 | set(handles.ListBoxData, 'value', i(1)); |
---|
271 | ListBoxData_Callback(hObject, eventdata, handles); |
---|
272 | end |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | % --- Executes on selection change in ListBoxData. |
---|
277 | function ListBoxData_Callback(hObject, eventdata, handles) |
---|
278 | |
---|
279 | i = get(handles.ListBoxData, 'Value'); |
---|
280 | Data = get(handles.ListBox4, 'String'); |
---|
281 | |
---|
282 | if isempty(Data) |
---|
283 | % Try list box 3 |
---|
284 | Data = get(handles.ListBox3, 'String'); |
---|
285 | if size(Data, 1) == size(get(handles.ListBoxData,'String'),1) |
---|
286 | set(handles.ListBox3, 'Value', i); |
---|
287 | end |
---|
288 | else |
---|
289 | if size(Data, 1) == size(get(handles.ListBoxData,'String'),1) |
---|
290 | set(handles.ListBox4, 'Value', i); |
---|
291 | end |
---|
292 | end |
---|
293 | |
---|
294 | |
---|
295 | |
---|
296 | function CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, j, Data0, Fields0) |
---|
297 | |
---|
298 | set(handles.ListBox5, 'Value', 1); |
---|
299 | set(handles.ListBox5, 'String', ''); |
---|
300 | |
---|
301 | CallNextListBox = 0; |
---|
302 | |
---|
303 | if isstruct(Data) |
---|
304 | DataFields = fieldnames(Data); |
---|
305 | DataField = DataFields{j}; |
---|
306 | |
---|
307 | SubData = Data.(DataField); |
---|
308 | |
---|
309 | % Special cases |
---|
310 | if strcmpi(DataField, 'TimeStamp') |
---|
311 | set(Box1, 'Value', 1); |
---|
312 | set(Box1, 'String', datestr(Data.(DataField),31)); |
---|
313 | return; |
---|
314 | elseif strcmpi(DataField, 'DataTime') |
---|
315 | set(Box1, 'Value', 1); |
---|
316 | set(Box1, 'String', datestr(Data.(DataField),31)); |
---|
317 | |
---|
318 | % Look to match it with ListBoxData |
---|
319 | if size(get(Box1, 'String'),1) == size(get(handles.ListBoxData, 'String'),1) |
---|
320 | set(Box1, 'Value', get(handles.ListBoxData,'Value')); |
---|
321 | end |
---|
322 | return; |
---|
323 | elseif strcmpi(DataField, 't') || strcmpi(DataField, 'tout') |
---|
324 | set(Box1, 'Value', 1); |
---|
325 | set(Box1, 'String', num2str(Data.(DataField))); |
---|
326 | return; |
---|
327 | elseif any(strcmp(DataField, {'Status','DeviceList','ElementList','Position'})) |
---|
328 | set(Box1, 'Value', 1); |
---|
329 | set(Box1, 'String', num2str(Data.(DataField))); |
---|
330 | |
---|
331 | % Look to match it with ListBoxData |
---|
332 | if size(get(Box1, 'String'),1) == size(get(handles.ListBoxData, 'String'),1) |
---|
333 | set(Box1, 'Value', get(handles.ListBoxData,'Value')); |
---|
334 | end |
---|
335 | return; |
---|
336 | end |
---|
337 | |
---|
338 | % Get Box1 string of cell array of strings |
---|
339 | if isstruct(SubData) |
---|
340 | SubDataField = fieldnames(Data.(DataField)); |
---|
341 | else |
---|
342 | if isnumeric(SubData) |
---|
343 | SubDataField = num2str(SubData); |
---|
344 | elseif ischar(SubData) |
---|
345 | SubDataField = SubData; |
---|
346 | elseif isa(Data,'function_handle') |
---|
347 | SubDataField = func2str(SubData); |
---|
348 | elseif iscell(SubData) |
---|
349 | if size(SubData,2) == 1 |
---|
350 | SubDataField = SubData(:); |
---|
351 | else |
---|
352 | SubDataField = 'Too big to Display'; |
---|
353 | end |
---|
354 | else |
---|
355 | SubDataField = ''; |
---|
356 | end |
---|
357 | end |
---|
358 | |
---|
359 | % If the Value of Box1 is getting changed, test for a default |
---|
360 | if get(Box1, 'Value') > size(SubDataField,1) |
---|
361 | set(Box1, 'Value', 1); |
---|
362 | |
---|
363 | % Make Monitor the default, if possible |
---|
364 | set(Box1, 'Value', 1); |
---|
365 | if length(SubDataField) >= 1 |
---|
366 | k = find(strcmpi(SubDataField, 'Monitor')); |
---|
367 | if ~isempty(k) |
---|
368 | set(Box1, 'Value', k); |
---|
369 | end |
---|
370 | end |
---|
371 | |
---|
372 | % Make TangoNames the default, if possible |
---|
373 | if length(SubDataField) >= 1 |
---|
374 | k = find(strcmpi(SubDataField, 'TangoNames')); |
---|
375 | if ~isempty(k) |
---|
376 | set(Box1, 'Value', k); |
---|
377 | end |
---|
378 | end |
---|
379 | end |
---|
380 | |
---|
381 | % Set Box1 |
---|
382 | set(Box1, 'String', SubDataField); |
---|
383 | |
---|
384 | % If appropriate, plot the data |
---|
385 | if strcmp(DataField, 'TangoNames') |
---|
386 | % Change the Value of Box1 to equal ListBoxData |
---|
387 | if size(get(Box1, 'String'),1) == size(get(handles.ListBoxData, 'String'),1) |
---|
388 | set(Box1, 'Value', get(handles.ListBoxData,'Value')); |
---|
389 | end |
---|
390 | |
---|
391 | % Plot the channels - for control system fields add sub-data fields |
---|
392 | DotField = ''; |
---|
393 | if isfield(Data, 'Mode') |
---|
394 | Mode = Data.Mode; |
---|
395 | else |
---|
396 | Mode = 'Online'; |
---|
397 | end |
---|
398 | if isepics && strcmpi(Mode, 'Online') |
---|
399 | % I should base this list on the type of channel |
---|
400 | EPICSFields = { |
---|
401 | 'VAL'; 'SCAN'; |
---|
402 | 'HOPR'; 'LOPR'; 'PREC'; 'DESC'; |
---|
403 | 'HIHI';'LOLO'; 'HIGH'; 'LOW'; 'HHSV'; 'LLSV'; 'HSV'; 'LSV'; 'HYST'; |
---|
404 | 'RVAL'; 'ROFF'; 'ASLO'; 'AOFF'; 'LINR'; 'ESLO'; 'EOFF'; 'EGUL'; 'EGUF'; |
---|
405 | 'MDEL'; 'ADEL'; |
---|
406 | 'STAT'; 'SEVR'; 'ACKS'; 'UDF'; |
---|
407 | 'PREC'; 'ORAW'; 'INIT'; |
---|
408 | 'DRVH'; 'DRVL'; 'RBV'; 'EGU'; }; |
---|
409 | set(handles.ListBox5, 'String', EPICSFields); |
---|
410 | set(handles.ListBox5, 'UserData', EPICSFields); |
---|
411 | %iEPICS = get(handles.ListBox5, 'Value'); |
---|
412 | iEPICS = getappdata(handles.figure1, 'iEPICS'); |
---|
413 | if isempty(iEPICS) |
---|
414 | iEPICS = 1; |
---|
415 | end |
---|
416 | set(handles.ListBox5, 'Value', iEPICS); |
---|
417 | if ~isempty(EPICSFields) |
---|
418 | DotField = EPICSFields{iEPICS}; |
---|
419 | end |
---|
420 | set(handles.ListBox5, 'Visible', 'On'); |
---|
421 | else |
---|
422 | set(handles.ListBox5, 'Visible', 'Off'); |
---|
423 | end |
---|
424 | |
---|
425 | if isempty(DotField) || strcmpi(DotField, 'VAL') |
---|
426 | % Get data all the data in the family |
---|
427 | try |
---|
428 | DataNew = getandplotdata(handles, Data0.FamilyName, Fields0, '', Data0.DeviceList); |
---|
429 | catch |
---|
430 | %fprintf('%s',lasterr); |
---|
431 | fprintf(' Problem occurred with family %s.\n', Data0.FamilyName); |
---|
432 | return |
---|
433 | end |
---|
434 | else |
---|
435 | % Get control system fields fields |
---|
436 | ListBox5_Callback([], [], handles); |
---|
437 | end |
---|
438 | |
---|
439 | elseif isnumeric(SubData) && strcmpi(DataField, 'Data') |
---|
440 | plotdatastruct(handles, Data, DataField); |
---|
441 | |
---|
442 | elseif strcmp(DataField, 'SpecialFunctionGet') |
---|
443 | % Plot the channels |
---|
444 | Data = getandplotdata(handles, Data0.FamilyName, Fields0, '', Data0.DeviceList); |
---|
445 | |
---|
446 | elseif isnumeric(SubData) |
---|
447 | |
---|
448 | set(handles.ListBox5, 'UserData', ''); |
---|
449 | |
---|
450 | if isfield(Data,'FamilyName') && isfield(Data, 'DeviceList') |
---|
451 | PlotData = Data.(DataField); |
---|
452 | s = getspos(Data.FamilyName, Data.DeviceList); |
---|
453 | if size(SubData,1) == length(s) && size(SubData,2) == 1 |
---|
454 | plot(handles.axes1, s, PlotData, '.-'); |
---|
455 | xlabel(handles.axes1, 'Position [meters]'); |
---|
456 | YLabelString = sprintf('%s.%s', Data.FamilyName, DataField); |
---|
457 | ylabel(handles.axes1, YLabelString); |
---|
458 | |
---|
459 | L = getfamilydata('Circumference'); |
---|
460 | if ~isempty(L) |
---|
461 | a = axis(handles.axes1); |
---|
462 | axis(handles.axes1, [0 L a(3:4)]); |
---|
463 | end |
---|
464 | |
---|
465 | % Set the callback for mouse clicks on the plot |
---|
466 | setappdata(handles.figure1, 'SPosX', s); |
---|
467 | setappdata(handles.figure1, 'SPosY', PlotData); |
---|
468 | set(handles.axes1, 'ButtonDownFcn', 'mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))'); |
---|
469 | h = get(handles.axes1, 'Children'); |
---|
470 | for i = 1:length(h) |
---|
471 | set(h(i) ,'ButtonDownFcn','mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))'); |
---|
472 | end |
---|
473 | |
---|
474 | |
---|
475 | % Reset DataBox if the new data is a shorter list |
---|
476 | if get(handles.ListBoxData, 'Value') > size(SubData,1) |
---|
477 | set(handles.ListBoxData, 'Value', 1); |
---|
478 | end |
---|
479 | |
---|
480 | DataMat = []; |
---|
481 | for ii = 1:size(Data.DeviceList,1) |
---|
482 | DataMat = strvcat(DataMat, sprintf('%s(%d,%d) = %+.4e', Data.FamilyName, Data.DeviceList(ii,:), SubData(ii,1))); |
---|
483 | end |
---|
484 | if isempty(get(handles.ListBoxData,'String')) |
---|
485 | WasEmpty = 1; |
---|
486 | else |
---|
487 | WasEmpty = 0; |
---|
488 | end |
---|
489 | set(handles.ListBoxData,'String', DataMat); |
---|
490 | %set(handles.ListBoxData, 'String', num2str(Data)); |
---|
491 | |
---|
492 | if WasEmpty |
---|
493 | set(handles.ListBoxData, 'Value', get(Box1, 'Value')); |
---|
494 | else |
---|
495 | set(Box1, 'Value', get(handles.ListBoxData, 'Value')); |
---|
496 | end |
---|
497 | set(handles.ListBoxData, 'Visible', 'On'); |
---|
498 | |
---|
499 | DataText(handles, SubData); |
---|
500 | end |
---|
501 | end |
---|
502 | else |
---|
503 | CallNextListBox = 1; |
---|
504 | end |
---|
505 | |
---|
506 | else |
---|
507 | % j points to a list |
---|
508 | % Look to match it with ListBoxData |
---|
509 | if size(get(Box0, 'String'),1) == size(get(handles.ListBoxData, 'String'),1) |
---|
510 | set(handles.ListBoxData, 'Value', get(Box0,'Value')); |
---|
511 | end |
---|
512 | |
---|
513 | % There shouldn't be anything in the next box at this point |
---|
514 | set(Box1, 'Value', 1); |
---|
515 | set(Box1, 'String', ''); |
---|
516 | end |
---|
517 | |
---|
518 | |
---|
519 | |
---|
520 | function Data = getandplotdata(handles, Family, Field, SubField, DeviceListTotal) |
---|
521 | |
---|
522 | if nargin < 4 |
---|
523 | SubField = ''; |
---|
524 | end |
---|
525 | if strcmpi(SubField, 'VAL') |
---|
526 | SubField = ''; |
---|
527 | end |
---|
528 | |
---|
529 | if nargin < 5 |
---|
530 | DeviceListTotal = family2dev(Family,0); |
---|
531 | end |
---|
532 | |
---|
533 | % Get data |
---|
534 | try |
---|
535 | % Good channel device list |
---|
536 | DeviceList = family2dev(Family); |
---|
537 | iGood = findrowindex(DeviceList, DeviceListTotal); |
---|
538 | |
---|
539 | % This only works for scalar data |
---|
540 | Data = NaN * ones(size(DeviceListTotal,1),1); |
---|
541 | |
---|
542 | if isempty(SubField) |
---|
543 | % Get by family |
---|
544 | if ~isempty(iGood) |
---|
545 | DataGood = getpv(Family, Field, DeviceList); |
---|
546 | Data(iGood,:) = DataGood; |
---|
547 | DataCell = mat2cell(num2str(Data), ones(1,size(Data,1))); |
---|
548 | |
---|
549 | if strcmpi(get(handles.DataTypeString, 'Checked') , 'On') |
---|
550 | % Put strings in the list box |
---|
551 | DataGoodString = getpv(Family, Field, DeviceList, 'String'); |
---|
552 | DataCell(iGood) = mat2cell(DataGoodString, ones(1,size(DataGoodString,1))); |
---|
553 | end |
---|
554 | |
---|
555 | end |
---|
556 | [Units, UnitsString] = getunits(Family, Field); |
---|
557 | else |
---|
558 | % Get by [channel.subfield] |
---|
559 | if ~isempty(iGood) |
---|
560 | ChanNames = family2channel(Family, Field, DeviceList); |
---|
561 | %ChanNames = get(handles.ListBox4, 'String'); |
---|
562 | ChanNames = strcat(ChanNames, ['.',SubField]); |
---|
563 | |
---|
564 | % Try 1 channel name first, so the error condition does not take so long |
---|
565 | try |
---|
566 | DataGood = getpv(deblank(ChanNames(1,:))); |
---|
567 | |
---|
568 | DataGood = getpv(ChanNames); |
---|
569 | Data(iGood,:) = DataGood; |
---|
570 | DataCell = mat2cell(num2str(Data), ones(1,size(Data,1))); |
---|
571 | |
---|
572 | if strcmpi(get(handles.DataTypeString, 'Checked') , 'On') |
---|
573 | % Put strings in the list box |
---|
574 | DataGoodString = getpv(ChanNames, 'String'); |
---|
575 | DataCell(iGood) = mat2cell(DataGoodString, ones(1,size(DataGoodString,1))); |
---|
576 | end |
---|
577 | catch |
---|
578 | Data = NaN * ones(size(DeviceListTotal,1),1); |
---|
579 | %DataCell = mat2cell(num2str(Data), ones(1,size(Data,1))); |
---|
580 | for i = 1:size(Data) |
---|
581 | DataCell{i,1} = 'No Data'; |
---|
582 | end |
---|
583 | end |
---|
584 | |
---|
585 | end |
---|
586 | UnitsString = ''; |
---|
587 | end |
---|
588 | catch |
---|
589 | Data = NaN * ones(size(DeviceListTotal,1),1); |
---|
590 | %DataCell = mat2cell(num2str(Data), ones(1,size(Data,1))); |
---|
591 | for i = 1:size(Data) |
---|
592 | DataCell{i,1} = 'No Data'; |
---|
593 | end |
---|
594 | end |
---|
595 | |
---|
596 | |
---|
597 | % Plot |
---|
598 | try |
---|
599 | s = getspos(Family, DeviceListTotal); |
---|
600 | plot(handles.axes1, s, Data, '.-'); |
---|
601 | xlabel(handles.axes1, 'Position [meters]'); |
---|
602 | |
---|
603 | YLabelString = sprintf('%s.%s', Family, Field); |
---|
604 | if ~isempty(SubField) |
---|
605 | YLabelString = sprintf('%s.%s', YLabelString, SubField); |
---|
606 | end |
---|
607 | if ~isempty(UnitsString) |
---|
608 | YLabelString = sprintf('%s [%s]', YLabelString, UnitsString); |
---|
609 | end |
---|
610 | |
---|
611 | ylabel(handles.axes1, YLabelString); |
---|
612 | |
---|
613 | L = getfamilydata('Circumference'); |
---|
614 | if ~isempty(L) |
---|
615 | a = axis(handles.axes1); |
---|
616 | axis(handles.axes1, [0 L a(3:4)]); |
---|
617 | end |
---|
618 | |
---|
619 | % Set the callback for mouse clicks on the plot |
---|
620 | setappdata(handles.figure1, 'SPosX', s); |
---|
621 | setappdata(handles.figure1, 'SPosY', Data); |
---|
622 | set(handles.axes1, 'ButtonDownFcn', 'mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))'); |
---|
623 | h = get(handles.axes1, 'Children'); |
---|
624 | for i = 1:length(h) |
---|
625 | set(h(i) ,'ButtonDownFcn','mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))'); |
---|
626 | end |
---|
627 | |
---|
628 | % Data list box |
---|
629 | |
---|
630 | % Change the value in the data list box before setting the new string |
---|
631 | DataValue = get(handles.ListBoxData, 'Value'); |
---|
632 | if DataValue > size(Data,1) |
---|
633 | set(handles.ListBoxData, 'Value', 1); |
---|
634 | DataValue = 1; |
---|
635 | end |
---|
636 | |
---|
637 | %DataMat = []; |
---|
638 | %for ii = 1:size(DeviceListTotal,1) |
---|
639 | % DataMat = strvcat(DataMat, sprintf('%s(%d,%d) = %+.4e', Family, DeviceListTotal(ii,:), Data(ii,1))); |
---|
640 | %end |
---|
641 | %set(handles.ListBoxData,'String', DataMat); |
---|
642 | %set(handles.ListBoxData, 'String', num2str(Data)); |
---|
643 | |
---|
644 | for ii = 1:size(DeviceListTotal,1) |
---|
645 | DataCell{ii} = sprintf('%s(%d,%d) = %s', Family, DeviceListTotal(ii,:), DataCell{ii}); |
---|
646 | end |
---|
647 | set(handles.ListBoxData,'String', DataCell); |
---|
648 | set(handles.ListBoxData, 'Visible', 'On'); |
---|
649 | |
---|
650 | DataText(handles, Data, iGood); |
---|
651 | |
---|
652 | catch |
---|
653 | set(handles.ListBoxData, 'Visible', 'Off'); |
---|
654 | set(handles.DataText, 'Visible', 'Off'); |
---|
655 | error('An error occurred in getandplotdata the %s family', Family); |
---|
656 | end |
---|
657 | |
---|
658 | |
---|
659 | |
---|
660 | function plotdatastruct(handles, d, Field) |
---|
661 | |
---|
662 | s = getspos(d.FamilyName, d.DeviceList); |
---|
663 | plot(handles.axes1, s, d.(Field), '.-'); |
---|
664 | xlabel(handles.axes1, 'Position [meters]'); |
---|
665 | ylabel(handles.axes1, sprintf('%s.%s [%s]', d.FamilyName, d.Field, d.UnitsString)); |
---|
666 | |
---|
667 | L = getfamilydata('Circumference'); |
---|
668 | if ~isempty(L) |
---|
669 | a = axis(handles.axes1); |
---|
670 | axis(handles.axes1, [0 L a(3:4)]); |
---|
671 | end |
---|
672 | |
---|
673 | % Set the callback for mouse clicks on the plot |
---|
674 | setappdata(handles.figure1, 'SPosX', s); |
---|
675 | setappdata(handles.figure1, 'SPosY', d.(Field)); |
---|
676 | set(handles.axes1, 'ButtonDownFcn', 'mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))'); |
---|
677 | h = get(handles.axes1, 'Children'); |
---|
678 | for i = 1:length(h) |
---|
679 | set(h(i) ,'ButtonDownFcn','mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))'); |
---|
680 | end |
---|
681 | |
---|
682 | % Data list box |
---|
683 | if get(handles.ListBoxData, 'Value') > size(d.Data,1) |
---|
684 | set(handles.ListBoxData, 'Value', 1); |
---|
685 | end |
---|
686 | |
---|
687 | DataMat = []; |
---|
688 | for ii = 1:size(d.DeviceList,1) |
---|
689 | DataMat = strvcat(DataMat, sprintf('%s(%d,%d) = %+.4e', d.FamilyName, d.DeviceList(ii,:), d.Data(ii,1))); |
---|
690 | end |
---|
691 | set(handles.ListBoxData,'String', DataMat); |
---|
692 | %set(handles.ListBoxData, 'String', num2str(Data)); |
---|
693 | |
---|
694 | set(handles.ListBoxData, 'Visible', 'On'); |
---|
695 | |
---|
696 | DataText(handles, d.Data); |
---|
697 | |
---|
698 | |
---|
699 | |
---|
700 | function DataText(handles, Data, iGood) |
---|
701 | |
---|
702 | if nargin < 3 |
---|
703 | iGood = 1:size(Data,1); |
---|
704 | end |
---|
705 | |
---|
706 | if isempty(iGood) |
---|
707 | set(handles.DataText, 'Visible', 'Off'); |
---|
708 | else |
---|
709 | MeanText = sprintf('Mean = %+9.6e', mean(Data(iGood))); |
---|
710 | RMSText = sprintf('RMS = %+9.6e', (length(Data(iGood))-1)*std(Data(iGood))/length(Data(iGood))); |
---|
711 | MaxText = sprintf('Max = %+9.6e', max(Data(iGood))); |
---|
712 | MinText = sprintf('Min = %+9.6e', min(Data(iGood))); |
---|
713 | set(handles.DataText, 'String', {MeanText; RMSText; MaxText; MinText}); |
---|
714 | set(handles.DataText, 'FontSize', 8); |
---|
715 | if isnan(mean(Data(iGood))) |
---|
716 | set(handles.DataText, 'Visible', 'Off'); |
---|
717 | else |
---|
718 | set(handles.DataText, 'Visible', 'On'); |
---|
719 | end |
---|
720 | end |
---|
721 | |
---|
722 | |
---|
723 | % -------------------------------------------------------------------- |
---|
724 | function ViewAO_Callback(hObject, eventdata, handles) |
---|
725 | |
---|
726 | [Fields, RootStruct] = getfamilylist('Cell'); |
---|
727 | setappdata(handles.figure1, 'RootStruct', RootStruct); |
---|
728 | |
---|
729 | set(handles.ListBox1, 'Value', 1); |
---|
730 | set(handles.ListBox1, 'String', Fields); |
---|
731 | ListBox1_Callback(hObject, eventdata, handles); |
---|
732 | |
---|
733 | set(handles.ViewAO, 'Checked' , 'On'); |
---|
734 | set(handles.ViewAD, 'Checked' , 'Off'); |
---|
735 | set(handles.ViewProduction, 'Checked' , 'Off'); |
---|
736 | set(handles.ViewInjection, 'Checked' , 'Off'); |
---|
737 | set(handles.ViewFile, 'Checked' , 'Off'); |
---|
738 | |
---|
739 | |
---|
740 | % -------------------------------------------------------------------- |
---|
741 | function ViewAD_Callback(hObject, eventdata, handles) |
---|
742 | |
---|
743 | RootStruct = getad; |
---|
744 | Fields = fieldnames(RootStruct); |
---|
745 | setappdata(handles.figure1, 'RootStruct', RootStruct); |
---|
746 | |
---|
747 | set(handles.ListBox1, 'Value', 1); |
---|
748 | set(handles.ListBox1, 'String', Fields); |
---|
749 | ListBox1_Callback(hObject, eventdata, handles); |
---|
750 | |
---|
751 | set(handles.ViewAO, 'Checked' , 'Off'); |
---|
752 | set(handles.ViewAD, 'Checked' , 'On'); |
---|
753 | set(handles.ViewProduction, 'Checked' , 'Off'); |
---|
754 | set(handles.ViewInjection, 'Checked' , 'Off'); |
---|
755 | set(handles.ViewFile, 'Checked' , 'Off'); |
---|
756 | |
---|
757 | |
---|
758 | % -------------------------------------------------------------------- |
---|
759 | function ViewProduction_Callback(hObject, eventdata, handles) |
---|
760 | |
---|
761 | [RootStruct, Monitor, FileName] = getproductionlattice; |
---|
762 | Fields = fieldnames(RootStruct); |
---|
763 | setappdata(handles.figure1, 'RootStruct', RootStruct); |
---|
764 | |
---|
765 | set(handles.ListBox1, 'Value', 1); |
---|
766 | set(handles.ListBox1, 'String', Fields); |
---|
767 | ListBox1_Callback(hObject, eventdata, handles); |
---|
768 | |
---|
769 | set(handles.ViewAO, 'Checked' , 'Off'); |
---|
770 | set(handles.ViewAD, 'Checked' , 'Off'); |
---|
771 | set(handles.ViewProduction, 'Checked' , 'On'); |
---|
772 | set(handles.ViewInjection, 'Checked' , 'Off'); |
---|
773 | set(handles.ViewFile, 'Checked' , 'Off'); |
---|
774 | |
---|
775 | |
---|
776 | % -------------------------------------------------------------------- |
---|
777 | function ViewInjection_Callback(hObject, eventdata, handles) |
---|
778 | |
---|
779 | [RootStruct, Monitor, FileName] = getinjectionlattice; |
---|
780 | Fields = fieldnames(RootStruct); |
---|
781 | setappdata(handles.figure1, 'RootStruct', RootStruct); |
---|
782 | |
---|
783 | set(handles.ListBox1, 'Value', 1); |
---|
784 | set(handles.ListBox1, 'String', Fields); |
---|
785 | ListBox1_Callback(hObject, eventdata, handles); |
---|
786 | |
---|
787 | set(handles.ViewAO, 'Checked' , 'Off'); |
---|
788 | set(handles.ViewAD, 'Checked' , 'Off'); |
---|
789 | set(handles.ViewProduction, 'Checked' , 'Off'); |
---|
790 | set(handles.ViewInjection, 'Checked' , 'On'); |
---|
791 | set(handles.ViewFile, 'Checked' , 'Off'); |
---|
792 | |
---|
793 | |
---|
794 | % -------------------------------------------------------------------- |
---|
795 | function ViewFile_Callback(hObject, eventdata, handles) |
---|
796 | |
---|
797 | [RootStruct, Monitor, FileName] = getlattice; |
---|
798 | if FileName == 0 |
---|
799 | return; |
---|
800 | end |
---|
801 | Fields = fieldnames(RootStruct); |
---|
802 | setappdata(handles.figure1, 'RootStruct', RootStruct); |
---|
803 | |
---|
804 | set(handles.ListBox1, 'Value', 1); |
---|
805 | set(handles.ListBox1, 'String', Fields); |
---|
806 | ListBox1_Callback(hObject, eventdata, handles); |
---|
807 | |
---|
808 | set(handles.ViewAO, 'Checked' , 'Off'); |
---|
809 | set(handles.ViewAD, 'Checked' , 'Off'); |
---|
810 | set(handles.ViewProduction, 'Checked' , 'Off'); |
---|
811 | set(handles.ViewInjection, 'Checked' , 'Off'); |
---|
812 | set(handles.ViewFile, 'Checked' , 'On'); |
---|
813 | |
---|
814 | |
---|
815 | % -------------------------------------------------------------------- |
---|
816 | function DataTypeDouble_Callback(hObject, eventdata, handles) |
---|
817 | set(handles.DataTypeDouble, 'Checked' , 'On'); |
---|
818 | set(handles.DataTypeString, 'Checked' , 'Off'); |
---|
819 | ListBox1_Callback(hObject, eventdata, handles); |
---|
820 | |
---|
821 | % -------------------------------------------------------------------- |
---|
822 | function DataTypeString_Callback(hObject, eventdata, handles) |
---|
823 | set(handles.DataTypeDouble, 'Checked' , 'Off'); |
---|
824 | set(handles.DataTypeString, 'Checked' , 'On'); |
---|
825 | ListBox1_Callback(hObject, eventdata, handles); |
---|
826 | |
---|
827 | |
---|
828 | % -------------------------------------------------------------------- |
---|
829 | function PopPlot_Callback(hObject, eventdata, handles) |
---|
830 | a = figure; |
---|
831 | b = copyobj(handles.axes1, a); |
---|
832 | set(b, 'Position', [0.1300 0.1100 0.7750 0.8150]); |
---|
833 | set(b, 'ButtonDownFcn',''); |
---|
834 | set(b, 'XAxisLocation','Bottom'); |
---|
835 | |
---|
836 | |
---|
837 | % -------------------------------------------------------------------- |
---|
838 | function PopPlotHoldOn_Callback(hObject, eventdata, handles) |
---|
839 | |
---|
840 | % Find the figure that is not the current figure |
---|
841 | h = get(0,'children'); |
---|
842 | |
---|
843 | a = []; |
---|
844 | for i = 1:length(h) |
---|
845 | if h(i)~=handles.figure1 && strcmpi(get(h(i),'Type'),'figure') && strcmpi(get(h(i),'Visible'),'On') |
---|
846 | a = h(i); |
---|
847 | break; |
---|
848 | end |
---|
849 | end |
---|
850 | if isempty(a) |
---|
851 | PopPlot_Callback(hObject, eventdata, handles); |
---|
852 | return; |
---|
853 | end |
---|
854 | |
---|
855 | x = getappdata(handles.figure1, 'SPosX'); |
---|
856 | y = getappdata(handles.figure1, 'SPosY'); |
---|
857 | |
---|
858 | figure(a); |
---|
859 | LegendHandle = legend; %findobj(a, 'tag', 'legend'); |
---|
860 | YLabelOld = get(get(gca,'ylabel'),'String'); |
---|
861 | YLabelNew = get(get(handles.axes1,'ylabel'),'String'); |
---|
862 | |
---|
863 | hold on; |
---|
864 | Color = nxtcolor; |
---|
865 | plot(x, y, '.-', 'Color', Color); |
---|
866 | hold off |
---|
867 | |
---|
868 | axis tight; |
---|
869 | L = getfamilydata('Circumference'); |
---|
870 | if ~isempty(L) |
---|
871 | a = axis(handles.axes1); |
---|
872 | axis(handles.axes1, [0 L a(3:4)]); |
---|
873 | end |
---|
874 | |
---|
875 | if isempty(LegendHandle) |
---|
876 | if isempty(YLabelOld) |
---|
877 | LegendCell = {}; |
---|
878 | else |
---|
879 | LegendCell = {YLabelOld}; |
---|
880 | end |
---|
881 | else |
---|
882 | LegendHandle = LegendHandle(1); |
---|
883 | LegendCell = get(LegendHandle, 'String'); |
---|
884 | if ~iscell(LegendCell) |
---|
885 | LegendCell = {LegendCell}; |
---|
886 | end |
---|
887 | end |
---|
888 | LegendCell(end+1) = {YLabelNew}; |
---|
889 | legend(LegendCell); |
---|
890 | |
---|
891 | set(get(gca,'ylabel'),'String',''); |
---|