source: MML/trunk/applications/mmlviewer/mmlviewer.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 27.4 KB
Line 
1function 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
28gui_Singleton = 0;
29gui_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',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46
47% --- Executes just before mmlviewer is made visible.
48function mmlviewer_OpeningFcn(hObject, eventdata, handles, varargin)
49
50% Choose default command line output for mmlviewer
51handles.output = hObject;
52
53% Update handles structure
54guidata(hObject, handles);
55
56try
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
95catch
96end
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.
105function varargout = mmlviewer_OutputFcn(hObject, eventdata, handles)
106
107% Get default command line output from handles structure
108varargout{1} = handles.output;
109
110
111% --------------------------------------------------------------------
112function FileMenu_Callback(hObject, eventdata, handles)
113
114
115
116% --------------------------------------------------------------------
117function OpenMenuItem_Callback(hObject, eventdata, handles)
118[file, Directory] = uigetfile('*.fig');
119if ~isequal(file, 0)
120    open([Directory file]);
121end
122
123
124
125% --------------------------------------------------------------------
126function 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
133delete(handles.figure1)
134
135
136
137% --------------------------------------------------------------------
138function PrintMenuItem_Callback(hObject, eventdata, handles)
139printdlg(handles.figure1)
140
141
142
143
144% --- Executes on selection change in ListBox1.
145function ListBox1_Callback(hObject, eventdata, handles)
146
147RootStruct = getappdata(handles.figure1, 'RootStruct');
148Fields = fieldnames(RootStruct);
149j = get(handles.ListBox1, 'Value');
150
151Data = RootStruct;
152
153Box0 = handles.ListBox1;
154Box1 = handles.ListBox2;
155Box2 = handles.ListBox3;
156
157CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, j);
158
159if CallNextListBox
160    ListBox2_Callback(hObject, eventdata, handles);
161else
162    set(handles.ListBox3, 'Value', 1);
163    set(handles.ListBox3, 'String', '');
164    set(handles.ListBox4, 'Value', 1);
165    set(handles.ListBox4, 'String', '');
166end
167
168
169% --- Executes on selection change in ListBox2.
170function ListBox2_Callback(hObject, eventdata, handles)
171
172RootStruct = getappdata(handles.figure1, 'RootStruct');
173Fields = fieldnames(RootStruct);
174i = get(handles.ListBox1, 'Value');
175j = get(handles.ListBox2, 'Value');
176Data = RootStruct.(Fields{i});
177
178Box0 = handles.ListBox2;
179Box1 = handles.ListBox3;
180Box2 = handles.ListBox4;
181
182CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, j, RootStruct, Fields{i});
183
184if CallNextListBox
185    ListBox3_Callback(hObject, eventdata, handles);
186else
187    set(handles.ListBox4, 'Value', 1);
188    set(handles.ListBox4, 'String', '');
189end
190
191       
192% --- Executes on selection change in ListBox3.
193function ListBox3_Callback(hObject, eventdata, handles)
194
195RootStruct = getappdata(handles.figure1, 'RootStruct');
196Fields1 = fieldnames(RootStruct);
197Fields2 = get(handles.ListBox2, 'String');
198Fields3 = get(handles.ListBox3, 'String');
199
200i = get(handles.ListBox1, 'Value');
201j = get(handles.ListBox2, 'Value');
202k = get(handles.ListBox3, 'Value');
203
204Data = RootStruct.(Fields1{i}).(Fields2{j});
205
206Box0 = handles.ListBox3;
207Box1 = handles.ListBox4;
208Box2 = handles.ListBox5;
209
210CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, k, RootStruct.(Fields1{i}), Fields2{j});
211
212if CallNextListBox
213    ListBox4_Callback(hObject, eventdata, handles);
214end
215
216
217% --- Executes on selection change in ListBox4.
218function ListBox4_Callback(hObject, eventdata, handles)
219
220i = get(handles.ListBox4, 'Value');
221Data = get(handles.ListBoxData, 'String');
222%DataFields = fieldnames(Data);
223
224if size(Data, 1) == size(get(handles.ListBox4,'String'),1)
225    set(handles.ListBoxData, 'Value', i);
226end
227
228
229
230% --- Executes on selection change in ListBox5.
231function ListBox5_Callback(hObject, eventdata, handles)
232
233RootStruct = getappdata(handles.figure1, 'RootStruct');
234Fields1 = fieldnames(RootStruct);
235Fields2 = get(handles.ListBox2, 'String');
236
237i = get(handles.ListBox1, 'Value');
238j = get(handles.ListBox2, 'Value');
239
240
241EPICSFields = get(handles.ListBox5, 'UserData');
242iEPICS = get(handles.ListBox5, 'Value');
243setappdata(handles.figure1, 'iEPICS', iEPICS);
244if ~isempty(EPICSFields)
245    DotField = EPICSFields{iEPICS};
246else
247    DotField = '';
248end
249
250
251% Get data
252try
253    Data = getandplotdata(handles, Fields1{i}, Fields2{j}, DotField, family2dev(Fields1{i}));
254catch
255    fprintf('   Could not get data for the %s family.\n', Fields1{i});
256    return;
257end
258
259
260
261% --------------------------------------------------------------------
262function Graph1_ButtonDown(hObject, eventdata, handles)
263CurrentPoint = get(handles.axes1, 'CurrentPoint');
264SposMouse = CurrentPoint(1,1);
265SposData  = getappdata(handles.figure1, 'SPosX');
266
267MeritFcn = abs(SposData-SposMouse);
268i = find(min(MeritFcn) == MeritFcn);
269if ~isempty(i)
270    set(handles.ListBoxData, 'value', i(1));
271    ListBoxData_Callback(hObject, eventdata, handles);
272end
273
274
275
276% --- Executes on selection change in ListBoxData.
277function ListBoxData_Callback(hObject, eventdata, handles)
278
279i = get(handles.ListBoxData, 'Value');
280Data = get(handles.ListBox4, 'String');
281
282if 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
288else
289    if size(Data, 1) == size(get(handles.ListBoxData,'String'),1)
290        set(handles.ListBox4, 'Value', i);
291    end
292end
293
294
295
296function CallNextListBox = ListBoxUpdate(handles, Box0, Box1, Data, j, Data0, Fields0)
297
298set(handles.ListBox5, 'Value', 1);
299set(handles.ListBox5, 'String', '');
300
301CallNextListBox = 0;
302
303if 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
506else
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', '');
516end
517
518
519
520function Data = getandplotdata(handles, Family, Field, SubField, DeviceListTotal)
521
522if nargin < 4
523    SubField = '';
524end
525if strcmpi(SubField, 'VAL')
526    SubField = '';
527end
528
529if nargin < 5
530    DeviceListTotal = family2dev(Family,0);
531end
532
533% Get data
534try
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
588catch
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
594end
595
596
597% Plot
598try
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
652catch
653    set(handles.ListBoxData, 'Visible', 'Off');
654    set(handles.DataText,    'Visible', 'Off');
655    error('An error occurred in getandplotdata the %s family', Family);
656end
657
658
659
660function plotdatastruct(handles, d, Field)
661
662s = getspos(d.FamilyName, d.DeviceList);
663plot(handles.axes1, s, d.(Field), '.-');
664xlabel(handles.axes1, 'Position [meters]');
665ylabel(handles.axes1, sprintf('%s.%s [%s]', d.FamilyName, d.Field, d.UnitsString));
666
667L = getfamilydata('Circumference');
668if ~isempty(L)
669    a = axis(handles.axes1);
670    axis(handles.axes1, [0 L a(3:4)]);
671end
672
673% Set the callback for mouse clicks on the plot
674setappdata(handles.figure1, 'SPosX', s);
675setappdata(handles.figure1, 'SPosY', d.(Field));
676set(handles.axes1, 'ButtonDownFcn', 'mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))');
677h = get(handles.axes1, 'Children');
678for i = 1:length(h)
679    set(h(i) ,'ButtonDownFcn','mmlviewer(''Graph1_ButtonDown'',gcbo,[],guidata(gcbo))');
680end
681
682% Data list box
683if get(handles.ListBoxData, 'Value') > size(d.Data,1)
684    set(handles.ListBoxData, 'Value', 1);
685end
686
687DataMat = [];
688for ii = 1:size(d.DeviceList,1)
689    DataMat = strvcat(DataMat, sprintf('%s(%d,%d) = %+.4e', d.FamilyName, d.DeviceList(ii,:), d.Data(ii,1)));
690end
691set(handles.ListBoxData,'String', DataMat);
692%set(handles.ListBoxData, 'String', num2str(Data));
693
694set(handles.ListBoxData, 'Visible', 'On');
695
696DataText(handles, d.Data);
697
698
699
700function DataText(handles, Data, iGood)
701
702if nargin < 3
703    iGood = 1:size(Data,1);
704end
705
706if isempty(iGood)
707    set(handles.DataText, 'Visible', 'Off');
708else
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
720end
721
722
723% --------------------------------------------------------------------
724function ViewAO_Callback(hObject, eventdata, handles)
725
726[Fields, RootStruct] = getfamilylist('Cell');
727setappdata(handles.figure1, 'RootStruct', RootStruct);
728
729set(handles.ListBox1, 'Value', 1);
730set(handles.ListBox1, 'String', Fields);
731ListBox1_Callback(hObject, eventdata, handles);
732
733set(handles.ViewAO,         'Checked' , 'On');
734set(handles.ViewAD,         'Checked' , 'Off');
735set(handles.ViewProduction, 'Checked' , 'Off');
736set(handles.ViewInjection,  'Checked' , 'Off');
737set(handles.ViewFile,       'Checked' , 'Off');
738
739
740% --------------------------------------------------------------------
741function ViewAD_Callback(hObject, eventdata, handles)
742
743RootStruct = getad;
744Fields = fieldnames(RootStruct);
745setappdata(handles.figure1, 'RootStruct', RootStruct);
746
747set(handles.ListBox1, 'Value', 1);
748set(handles.ListBox1, 'String', Fields);
749ListBox1_Callback(hObject, eventdata, handles);
750
751set(handles.ViewAO,         'Checked' , 'Off');
752set(handles.ViewAD,         'Checked' , 'On');
753set(handles.ViewProduction, 'Checked' , 'Off');
754set(handles.ViewInjection,  'Checked' , 'Off');
755set(handles.ViewFile,       'Checked' , 'Off');
756
757
758% --------------------------------------------------------------------
759function ViewProduction_Callback(hObject, eventdata, handles)
760
761[RootStruct, Monitor, FileName] = getproductionlattice;
762Fields = fieldnames(RootStruct);
763setappdata(handles.figure1, 'RootStruct', RootStruct);
764
765set(handles.ListBox1, 'Value', 1);
766set(handles.ListBox1, 'String', Fields);
767ListBox1_Callback(hObject, eventdata, handles);
768
769set(handles.ViewAO,         'Checked' , 'Off');
770set(handles.ViewAD,         'Checked' , 'Off');
771set(handles.ViewProduction, 'Checked' , 'On');
772set(handles.ViewInjection,  'Checked' , 'Off');
773set(handles.ViewFile,       'Checked' , 'Off');
774
775
776% --------------------------------------------------------------------
777function ViewInjection_Callback(hObject, eventdata, handles)
778
779[RootStruct, Monitor, FileName] = getinjectionlattice;
780Fields = fieldnames(RootStruct);
781setappdata(handles.figure1, 'RootStruct', RootStruct);
782
783set(handles.ListBox1, 'Value', 1);
784set(handles.ListBox1, 'String', Fields);
785ListBox1_Callback(hObject, eventdata, handles);
786
787set(handles.ViewAO,         'Checked' , 'Off');
788set(handles.ViewAD,         'Checked' , 'Off');
789set(handles.ViewProduction, 'Checked' , 'Off');
790set(handles.ViewInjection,  'Checked' , 'On');
791set(handles.ViewFile,       'Checked' , 'Off');
792
793
794% --------------------------------------------------------------------
795function ViewFile_Callback(hObject, eventdata, handles)
796
797[RootStruct, Monitor, FileName] = getlattice;
798if FileName == 0
799    return;
800end
801Fields = fieldnames(RootStruct);
802setappdata(handles.figure1, 'RootStruct', RootStruct);
803
804set(handles.ListBox1, 'Value', 1);
805set(handles.ListBox1, 'String', Fields);
806ListBox1_Callback(hObject, eventdata, handles);
807
808set(handles.ViewAO,         'Checked' , 'Off');
809set(handles.ViewAD,         'Checked' , 'Off');
810set(handles.ViewProduction, 'Checked' , 'Off');
811set(handles.ViewInjection,  'Checked' , 'Off');
812set(handles.ViewFile,       'Checked' , 'On');
813
814
815% --------------------------------------------------------------------
816function DataTypeDouble_Callback(hObject, eventdata, handles)
817set(handles.DataTypeDouble, 'Checked' , 'On');
818set(handles.DataTypeString, 'Checked' , 'Off');
819ListBox1_Callback(hObject, eventdata, handles);
820
821% --------------------------------------------------------------------
822function DataTypeString_Callback(hObject, eventdata, handles)
823set(handles.DataTypeDouble, 'Checked' , 'Off');
824set(handles.DataTypeString, 'Checked' , 'On');
825ListBox1_Callback(hObject, eventdata, handles);
826
827
828% --------------------------------------------------------------------
829function PopPlot_Callback(hObject, eventdata, handles)
830a = figure;
831b = copyobj(handles.axes1, a);
832set(b, 'Position', [0.1300    0.1100    0.7750    0.8150]);
833set(b, 'ButtonDownFcn','');
834set(b, 'XAxisLocation','Bottom');
835
836
837% --------------------------------------------------------------------
838function PopPlotHoldOn_Callback(hObject, eventdata, handles)
839
840% Find the figure that is not the current figure
841h = get(0,'children');
842
843a = [];
844for 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
849end
850if isempty(a)
851    PopPlot_Callback(hObject, eventdata, handles);
852    return;
853end
854
855x = getappdata(handles.figure1, 'SPosX');
856y = getappdata(handles.figure1, 'SPosY');
857
858figure(a);
859LegendHandle = legend; %findobj(a, 'tag', 'legend');
860YLabelOld = get(get(gca,'ylabel'),'String');
861YLabelNew = get(get(handles.axes1,'ylabel'),'String');
862
863hold on;
864Color = nxtcolor;
865plot(x, y, '.-', 'Color', Color);
866hold off
867
868axis tight;
869L = getfamilydata('Circumference');
870if ~isempty(L)
871    a = axis(handles.axes1);
872    axis(handles.axes1, [0 L a(3:4)]);
873end
874
875if isempty(LegendHandle)
876    if isempty(YLabelOld)
877        LegendCell = {};
878    else
879        LegendCell = {YLabelOld};
880    end
881else
882    LegendHandle = LegendHandle(1);
883    LegendCell = get(LegendHandle, 'String');
884    if ~iscell(LegendCell)
885        LegendCell = {LegendCell};
886    end
887end
888LegendCell(end+1) = {YLabelNew};
889legend(LegendCell);
890
891set(get(gca,'ylabel'),'String','');
Note: See TracBrowser for help on using the repository browser.