source: MML/trunk/machine/SOLEIL/StorageRing/bba_mml/bbacentergui.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: 21.0 KB
Line 
1function varargout = bbacentergui(varargin)
2% BBACENTERGUI M-file for bbacentergui.fig
3%      BBACENTERGUI, by itself, creates a new BBACENTERGUI or raises the existing
4%      singleton*.
5%
6%      H = BBACENTERGUI returns the handle to a new BBACENTERGUI or the handle to
7%      the existing singleton*.
8%
9%      BBACENTERGUI('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in BBACENTERGUI.M with the given input arguments.
11%
12%      BBACENTERGUI('Property','Value',...) creates a new BBACENTERGUI or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before bbacentergui_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to bbacentergui_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 bbacentergui
24
25% Last Modified by GUIDE v2.5 30-Aug-2011 18:35:59
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30    'gui_Singleton',  gui_Singleton, ...
31    'gui_OpeningFcn', @bbacentergui_OpeningFcn, ...
32    'gui_OutputFcn',  @bbacentergui_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 bbacentergui is made visible.
48function bbacentergui_OpeningFcn(hObject, eventdata, handles, varargin)
49% This function has no output args, see OutputFcn.
50% hObject    handle to figure
51% eventdata  reserved - to be defined in a future version of MATLAB
52% handles    structure with handles and user data (see GUIDATA)
53% varargin   command line arguments to bbacentergui (see VARARGIN)
54
55% Choose default command line output for bbacentergui
56handles.output = hObject;
57
58% Update handles structure
59guidata(hObject, handles);
60
61% UIWAIT makes bbacentergui wait for user response (see UIRESUME)
62% uiwait(handles.figure1);
63
64initDirectory;
65
66function initDirectory
67% selection the direcotry to save the BBA data
68
69RootDirectory = fileparts(getfamilydata('Directory', 'BBA'));
70DirName = RootDirectory;
71while ~ischar(DirName) || (strcmpi(DirName, RootDirectory) || exist(DirName, 'dir') ~=7)
72    DirName = uigetdir(RootDirectory, 'Select or create a BBA directory');
73    if strcmpi(DirName, RootDirectory)
74        h = warndlg('Abort: Directory is not correct. Choose a subdirectory');
75        uiwait(h)
76    elseif ischar(DirName) && exist(DirName, 'dir') ~=7
77        warndlg('Abort: Directory not selected');
78    end
79end
80cd(DirName); % gotodirectory
81quadsetup(DirName);
82%cd(DirName);
83
84% --- Outputs from this function are returned to the command line.
85function varargout = bbacentergui_OutputFcn(hObject, eventdata, handles)
86% varargout  cell array for returning output args (see VARARGOUT);
87% hObject    handle to figure
88% eventdata  reserved - to be defined in a future version of MATLAB
89% handles    structure with handles and user data (see GUIDATA)
90
91% Get default command line output from handles structure
92varargout{1} = handles.output;
93
94
95% --- Executes on button press in checkbox_Q1.
96function checkbox_Q1_Callback(hObject, eventdata, handles)
97% hObject    handle to checkbox_Q1 (see GCBO)
98% eventdata  reserved - to be defined in a future version of MATLAB
99% handles    structure with handles and user data (see GUIDATA)
100
101% Hint: get(hObject,'Value') returns toggle state of checkbox_Q1
102
103% --- Executes on button press in checkbox_Q2.
104function checkbox_Q2_Callback(hObject, eventdata, handles)
105% hObject    handle to checkbox_Q2 (see GCBO)
106% eventdata  reserved - to be defined in a future version of MATLAB
107% handles    structure with handles and user data (see GUIDATA)
108
109% Hint: get(hObject,'Value') returns toggle state of checkbox_Q2
110
111
112% --- Executes on button press in checkbox_Q3.
113function checkbox_Q3_Callback(hObject, eventdata, handles)
114% hObject    handle to checkbox_Q3 (see GCBO)
115% eventdata  reserved - to be defined in a future version of MATLAB
116% handles    structure with handles and user data (see GUIDATA)
117
118% Hint: get(hObject,'Value') returns toggle state of checkbox_Q3
119
120
121% --- Executes on button press in checkbox_Q4.
122function checkbox_Q4_Callback(hObject, eventdata, handles)
123% hObject    handle to checkbox_Q4 (see GCBO)
124% eventdata  reserved - to be defined in a future version of MATLAB
125% handles    structure with handles and user data (see GUIDATA)
126
127% Hint: get(hObject,'Value') returns toggle state of checkbox_Q4
128
129
130% --- Executes on button press in checkbox_Q5.
131function checkbox_Q5_Callback(hObject, eventdata, handles)
132% hObject    handle to checkbox_Q5 (see GCBO)
133% eventdata  reserved - to be defined in a future version of MATLAB
134% handles    structure with handles and user data (see GUIDATA)
135
136% Hint: get(hObject,'Value') returns toggle state of checkbox_Q5
137
138
139% --- Executes on button press in checkbox_Q6.
140function checkbox_Q6_Callback(hObject, eventdata, handles)
141% hObject    handle to checkbox_Q6 (see GCBO)
142% eventdata  reserved - to be defined in a future version of MATLAB
143% handles    structure with handles and user data (see GUIDATA)
144
145% Hint: get(hObject,'Value') returns toggle state of checkbox_Q6
146
147
148% --- Executes on button press in checkbox_Q7.
149function checkbox_Q7_Callback(hObject, eventdata, handles)
150% hObject    handle to checkbox_Q7 (see GCBO)
151% eventdata  reserved - to be defined in a future version of MATLAB
152% handles    structure with handles and user data (see GUIDATA)
153
154% Hint: get(hObject,'Value') returns toggle state of checkbox_Q7
155
156
157% --- Executes on button press in checkbox_Q8.
158function checkbox_Q8_Callback(hObject, eventdata, handles)
159% hObject    handle to checkbox_Q8 (see GCBO)
160% eventdata  reserved - to be defined in a future version of MATLAB
161% handles    structure with handles and user data (see GUIDATA)
162
163% Hint: get(hObject,'Value') returns toggle state of checkbox_Q8
164
165
166% --- Executes on button press in checkbox_Q9.
167function checkbox_Q9_Callback(hObject, eventdata, handles)
168% hObject    handle to checkbox_Q9 (see GCBO)
169% eventdata  reserved - to be defined in a future version of MATLAB
170% handles    structure with handles and user data (see GUIDATA)
171
172% Hint: get(hObject,'Value') returns toggle state of checkbox_Q9
173
174
175% --- Executes on button press in checkbox_Q10.
176function checkbox_Q10_Callback(hObject, eventdata, handles)
177% hObject    handle to checkbox_Q10 (see GCBO)
178% eventdata  reserved - to be defined in a future version of MATLAB
179% handles    structure with handles and user data (see GUIDATA)
180
181% Hint: get(hObject,'Value') returns toggle state of checkbox_Q10
182
183
184% --- Executes on button press in checkbox_Hplane.
185function checkbox_Hplane_Callback(hObject, eventdata, handles)
186% hObject    handle to checkbox_Hplane (see GCBO)
187% eventdata  reserved - to be defined in a future version of MATLAB
188% handles    structure with handles and user data (see GUIDATA)
189
190% Hint: get(hObject,'Value') returns toggle state of checkbox_Hplane
191
192% --- Executes on button press in checkbox_Vplane.
193function checkbox_Vplane_Callback(hObject, eventdata, handles)
194% hObject    handle to checkbox_Vplane (see GCBO)
195% eventdata  reserved - to be defined in a future version of MATLAB
196% handles    structure with handles and user data (see GUIDATA)
197
198% Hint: get(hObject,'Value') returns toggle state of checkbox_Vplane
199
200
201% --- Executes on selection change in listbox1.
202function listbox1_Callback(hObject, eventdata, handles)
203% hObject    handle to listbox1 (see GCBO)
204% eventdata  reserved - to be defined in a future version of MATLAB
205% handles    structure with handles and user data (see GUIDATA)
206
207% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
208%        contents{get(hObject,'Value')} returns selected item from listbox1
209
210
211% --- Executes during object creation, after setting all properties.
212function listbox1_CreateFcn(hObject, eventdata, handles)
213% hObject    handle to listbox1 (see GCBO)
214% eventdata  reserved - to be defined in a future version of MATLAB
215% handles    empty - handles not created until after all CreateFcns called
216
217% Hint: listbox controls usually have a white background on Windows.
218%       See ISPC and COMPUTER.
219if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
220    set(hObject,'BackgroundColor','white');
221end
222
223
224% --- Executes on selection change in listbox2.
225function listbox2_Callback(hObject, eventdata, handles)
226% hObject    handle to listbox2 (see GCBO)
227% eventdata  reserved - to be defined in a future version of MATLAB
228% handles    structure with handles and user data (see GUIDATA)
229
230% Hints: contents = get(hObject,'String') returns listbox2 contents as cell array
231%        contents{get(hObject,'Value')} returns selected item from listbox2
232
233
234% --- Executes during object creation, after setting all properties.
235function listbox2_CreateFcn(hObject, eventdata, handles)
236% hObject    handle to listbox2 (see GCBO)
237% eventdata  reserved - to be defined in a future version of MATLAB
238% handles    empty - handles not created until after all CreateFcns called
239
240% Hint: listbox controls usually have a white background on Windows.
241%       See ISPC and COMPUTER.
242if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
243    set(hObject,'BackgroundColor','white');
244end
245
246
247% --- Executes on button press in pushbutton_Add.
248function pushbutton_Add_Callback(hObject, eventdata, handles)
249% hObject    handle to pushbutton_Add (see GCBO)
250% eventdata  reserved - to be defined in a future version of MATLAB
251% handles    structure with handles and user data (see GUIDATA)
252
253
254% --- Executes on button press in pushbutton_Remove.
255function pushbutton_Remove_Callback(hObject, eventdata, handles)
256% hObject    handle to pushbutton_Remove (see GCBO)
257% eventdata  reserved - to be defined in a future version of MATLAB
258% handles    structure with handles and user data (see GUIDATA)
259
260
261function launchBBA(handles)
262% main function for BBA
263
264[tmp WHO] =system('whoami');
265if strncmp(WHO, 'operateur',9),
266    ControlRoomFlag = 1;
267    Mode = 'Online';
268else
269    ControlRoomFlag = 0;
270    Mode = 'Simulator';
271end
272
273%initialization
274HFlag = 0;
275VFlag = 0;
276plane = -1;
277QuadDev = [];
278
279% get flags for planes
280if get(handles.checkbox_Hplane,'Value') == 1
281    HFlag = 1;
282end
283
284% get flags for planes
285if get(handles.checkbox_Vplane,'Value') == 1
286    VFlag = 1;
287end
288
289if (HFlag == 1) && (VFlag == 1)
290    plane = 0;
291    StrPlane = sprintf('\nH and V planes\n');
292elseif (HFlag == 1)
293    plane = 1;
294    StrPlane = sprintf('\nH-plane only\n');
295elseif (VFlag == 1)
296    plane = 2;
297    StrPlane = sprintf('\nV-plane only\n');
298else
299    warndlg('Abort: Select a plane first')
300    return;
301end
302
303
304% get BPM for doing BBA
305
306% Quadrupole Family Selection
307if get(handles.radiobutton_Quad, 'Val') == 1
308    FamilyList = {};
309    for k = 1:12,
310        if get(eval(['handles.checkbox_Q' num2str(k)]),'Value') == 1
311            FamilyList = {FamilyList{:}, ['Q' num2str(k)]};
312        end
313    end
314
315    if isempty(FamilyList)
316        FamilyList = getfamilylist;
317        [tmp,i] = ismemberof(FamilyList,'QUAD');
318        if ~isempty(i)
319            FamilyList = FamilyList(i,:);
320        end
321        if size(FamilyList,1) == 1
322            QuadFamily = deblank(FamilyList);
323        else
324            [i,ok] = listdlg('PromptString', 'Select a quadrupole family:', ...
325                'SelectionMode', 'single', ...
326                'ListString', FamilyList);
327            if ok == 0
328                return
329            else
330                QuadFamily = deblank(FamilyList(i,:));
331            end
332        end
333
334       
335        QuadDev = editlist(getlist(QuadFamily),QuadFamily,zeros(length(getlist(QuadFamily)),1));
336
337        if isempty(QuadDev)
338            warndlg('Abort: No quadrupole selected');
339            return;
340        end
341
342        clear FamilyList;
343        FamilyList{1} = QuadFamily;
344        StringMessage = sprintf('Do you want to start BBA on quadrupoles ?');
345        StringMessage = [StringMessage StrPlane];
346        for k=1:size(QuadDev, 1),
347            StringMessage = [StringMessage, sprintf('\n %s(%d,%d)', FamilyList{1}, QuadDev(k,:))];
348        end
349
350    else
351        StringMessage = sprintf('Do you want to start BBA on All quadrupoles of familyname?');
352        StringMessage = [StringMessage StrPlane];
353        for k=1:size(FamilyList, 2),
354            StringMessage = [StringMessage, sprintf('\n %s', FamilyList{k})];
355        end
356
357    end
358    StartFlag = questdlg(StringMessage, 'BBAgui','Yes','No','No');
359    if strcmp(StartFlag,'No')
360        disp('   ********************************');
361        disp('   **        BBA Aborted         **');
362        disp('   ********************************');
363        fprintf('\n');
364        return
365    end
366   
367   
368    if isempty(QuadDev)
369    %Fullfamily
370    for k = 1:size(FamilyList, 2),
371        % get device list
372        DevList = family2dev(FamilyList{k});
373        % do BBA
374        quadcenter(FamilyList{k}, DevList, plane);
375    end
376    else
377        % individual quadrupoles
378        for k = 1:size(QuadDev, 1),
379            % do BBA
380            quadcenter(FamilyList{1}, QuadDev(k,:), plane);
381        end
382    end
383    h = warndlg('BBA measurement done.');   
384    if ControlRoomFlag
385        tango_giveInformationMessage('BBA fini');
386    end
387    uiwait(h)
388end
389
390
391% if BPM choice list
392% test if BPM list selected
393if get(handles.radiobutton_BPM, 'Val') == 1
394    % Interface start with all or non BPM selected
395    if get(handles.radiobutton_ALLBPM,'Value')
396        newList = editlist(getlist('BPMx'), 'BPMx', ones(size(getlist('BPMx'),1)));
397    else
398        newList = editlist(getlist('BPMx'), 'BPMx', zeros(size(getlist('BPMx'),1)));
399    end
400    if isempty(newList)
401        warndlg('Abort: No BPM selected');
402        return;
403    end
404    Quadstruct = bpm2quad4bba('BPMx', newList );
405
406    StringMessage = sprintf('Do you want to start BBA on all these quadrupoles?');
407    StringMessage = [StringMessage StrPlane];
408    for k=1:size(newList, 1),
409        if rem(k,2) == 1,
410            StringMessage = [StringMessage, sprintf('\n BPM(%2d,%2d) %s(%2d, %2d)', newList(k,:), ...
411                Quadstruct(k).Family1, Quadstruct(k).DevList1)];
412        else
413            StringMessage = [StringMessage, sprintf('\t BPM(%2d,%2d) %s(%2d, %2d)', newList(k,:), ...
414                Quadstruct(k).Family1, Quadstruct(k).DevList1)];
415        end
416        if ~isempty(Quadstruct(k).Family2)
417            StringMessage = [StringMessage, sprintf(' %s(%d, %d)',  ...
418                Quadstruct(k).Family2, Quadstruct(k).DevList2)];
419        end
420    end
421   
422    StringMessage = [StringMessage, sprintf('\n \n .')];
423    StartFlag = questdlg(StringMessage, 'BBAgui','Yes','No','No');
424    if strcmp(StartFlag,'No')
425        disp('   ********************************');
426        disp('   **        BBA Aborted         **');
427        disp('   ********************************');
428        fprintf('\n');
429        return
430    end
431
432    for k = 1:length(Quadstruct),
433        quadcenter(Quadstruct(k).Family1, Quadstruct(k).DevList1, plane)
434        if ~isempty(Quadstruct(k).Family2)
435            quadcenter(Quadstruct(k).Family2, Quadstruct(k).DevList2, plane)
436        end
437    end
438    h = warndlg('BBA measurement done.');
439    if ControlRoomFlag
440        tango_command_inout2(devSpeakerName,'DevTalk','BBA fini');
441    end
442    uiwait(h)
443end
444
445% --- Executes on button press in pushbutton_start.
446function pushbutton_start_Callback(hObject, eventdata, handles)
447% hObject    handle to pushbutton_start (see GCBO)
448% eventdata  reserved - to be defined in a future version of MATLAB
449% handles    structure with handles and user data (see GUIDATA)
450
451StartFlag = questdlg(sprintf('Start BBA measurement. First Check\n\nShaker and tune measurement ON\n\nBooster OFF\nFBT OFF\nSOFB & FOFB OFF\n\n Are you sure?'), 'Start Confirmation box','Yes','No','No');
452if strcmp(StartFlag,'No')
453    disp('   ********************************');
454    disp('   **   Start not applied      **');
455    disp('   ********************************');
456    fprintf('\n');
457    return
458end
459
460launchBBA(handles)
461
462% --- Executes on button press in pushbutton_plotRawData.
463function pushbutton_plotRawData_Callback(hObject, eventdata, handles)
464% hObject    handle to pushbutton_plotRawData (see GCBO)
465% eventdata  reserved - to be defined in a future version of MATLAB
466% handles    structure with handles and user data (see GUIDATA)
467Dir0 = pwd;
468cd(getfamilydata('Directory', 'BBAcurrent'))
469quadplot;
470cd(Dir0);
471
472% --- Executes on button press in pushbutton_plotFinalOffset.
473function pushbutton_plotFinalOffset_Callback(hObject, eventdata, handles)
474% hObject    handle to pushbutton_plotFinalOffset (see GCBO)
475% eventdata  reserved - to be defined in a future version of MATLAB
476% handles    structure with handles and user data (see GUIDATA)
477Dir0 = pwd;
478cd(getfamilydata('Directory', 'BBAcurrent'))
479quadcalcoffset;
480cd(Dir0);
481
482% --- Executes on button press in pushbutton_createFile.
483function pushbutton_createFile_Callback(hObject, eventdata, handles)
484% hObject    handle to pushbutton_createFile (see GCBO)
485% eventdata  reserved - to be defined in a future version of MATLAB
486% handles    structure with handles and user data (see GUIDATA)
487Dir0 = pwd;
488cd(getfamilydata('Directory', 'BBAcurrent'))
489quadcalcoffset('Write', 'NoDisplay');
490cd(Dir0);
491
492
493% --- Executes on button press in pushbutton_plotAllRawData.
494function pushbutton_plotAllRawData_Callback(hObject, eventdata, handles)
495% hObject    handle to pushbutton_plotAllRawData (see GCBO)
496% eventdata  reserved - to be defined in a future version of MATLAB
497% handles    structure with handles and user data (see GUIDATA)
498Dir0 = pwd;
499cd(getfamilydata('Directory', 'BBAcurrent'))
500quadplotall;
501cd(Dir0);
502
503
504% --- Executes on button press in pushbutton_selectDirectory.
505function pushbutton_selectDirectory_Callback(hObject, eventdata, handles)
506% hObject    handle to pushbutton_selectDirectory (see GCBO)
507% eventdata  reserved - to be defined in a future version of MATLAB
508% handles    structure with handles and user data (see GUIDATA)
509
510initDirectory
511
512
513% --- Executes on button press in pushbutton_applyBBAOffset.
514function pushbutton_applyBBAOffset_Callback(hObject, eventdata, handles)
515% hObject    handle to pushbutton_applyBBAOffset (see GCBO)
516% eventdata  reserved - to be defined in a future version of MATLAB
517% handles    structure with handles and user data (see GUIDATA)
518
519% force computation of offsets
520
521pushbutton_createFile_Callback(handles.pushbutton_createFile, eventdata, handles)
522
523StartFlag = questdlg('Do you want to generate  offset table for jive?', 'Apply Offset','Yes','No','No');
524if strcmp(StartFlag,'No')
525    disp('   ********************************');
526    disp('   **   Offsets not applied      **');
527    disp('   ********************************');
528    fprintf('\n');
529    return
530end
531
532% H and V-plane
533fileNameH = fullfile(getfamilydata('Directory', 'BBAcurrent'), 'tableBBAH.mat');
534fileNameV = fullfile(getfamilydata('Directory', 'BBAcurrent'), 'tableBBAV.mat');
535Dir0 = pwd;
536cd ('/home/operateur/GrpDiagnostics/matlab/DserverBPM');
537
538
539% both plane
540if exist(fileNameH, 'file') == 2 && exist(fileNameV, 'file') == 2
541    Set_BBA_Offsets_planHV('ADD', fileNameH, fileNameV)
542elseif exist(fileNameH, 'file') == 2
543% Only H-plane
544    Set_BBA_Offsets_planH('ADD', fileNameH)
545elseif exist(fileNameV, 'file') == 2
546% Only V-plane
547    Set_BBA_Offsets_planV('ADD', fileNameV)
548end
549
550cd(Dir0)
551
552message = sprintf(['Mise en production des offsets mesures\n', ...
553    '\n 1. Ouvrir jive-rw', ...
554    '\n 2. Remplacer la propriete ''Blockparameters'' dans l''onglet Property/BPM', ...
555    '\n 3. Faire une (plus si besoin) commande ''init'' des BPM avec le bouton ''init on all BPMs'' \n']);
556uiwait(msgbox(message,'Intructions','modal'));
557
558
559% --- Executes on button press in pushbutton_InitBPM.
560function pushbutton_InitBPM_Callback(hObject, eventdata, handles)
561% hObject    handle to pushbutton_InitBPM (see GCBO)
562% eventdata  reserved - to be defined in a future version of MATLAB
563% handles    structure with handles and user data (see GUIDATA)
564
565StartFlag = questdlg('Init on all BPM. Are you sure?', 'Init Confirmation box','Yes','No','No');
566if strcmp(StartFlag,'No')
567    disp('   ********************************');
568    disp('   **   Init not applied      **');
569    disp('   ********************************');
570    fprintf('\n');
571    return
572end
573
574commandName = 'Init';
575tango_group_command_inout2(getfamilydata('BPMx', 'GroupId'),commandName,0,0);
576
577
578% --- Executes on button press in checkbox_Q11.
579function checkbox_Q11_Callback(hObject, eventdata, handles)
580% hObject    handle to checkbox_Q11 (see GCBO)
581% eventdata  reserved - to be defined in a future version of MATLAB
582% handles    structure with handles and user data (see GUIDATA)
583
584% Hint: get(hObject,'Value') returns toggle state of checkbox_Q11
585
586
587% --- Executes on button press in checkbox_Q12.
588function checkbox_Q12_Callback(hObject, eventdata, handles)
589% hObject    handle to checkbox_Q12 (see GCBO)
590% eventdata  reserved - to be defined in a future version of MATLAB
591% handles    structure with handles and user data (see GUIDATA)
592
593% Hint: get(hObject,'Value') returns toggle state of checkbox_Q12
Note: See TracBrowser for help on using the repository browser.