function LT2setup
%LT2SETUP - GUI for doing LT2 setup

%
% Written by Laurent S. Nadolski

AD = getad;

if isempty(AD) 
    LT2init;
elseif ~strcmpi(AD.SubMachine,'LT2')
    LT2init;
end

orbfig = findobj(allchild(0),'tag','LT2setup'); 

if ~isempty(orbfig), delete(orbfig); end
orbfig = findobj(allchild(0),'tag','LT2setup'); 


kmax = 4; % button number

height = 10 + kmax*30 + 30; %670;
a = figure('Color',[0.8 0.8 0.8], ...
    'Interruptible', 'on', ...   
    'HandleVisibility','off', ...
    'MenuBar','none', ...
    'Name', 'LT2 Command Launcher', ...
    'NumberTitle','off', ...
    'Units','pixels', ...
    'Position',[5 70 210*2 height], ...
    'Resize','off', ...
    'Tag','LT2setup');

height = height - 35;

for k = 1:kmax,
    b1(k) = uicontrol('Parent',a, ...
        'Position',[3 height-(k-1)*30 204 27], ...
        'Interruptible', 'off', ...
        'Tag','button22');
end

for k = 1:kmax,
    b2(k) = uicontrol('Parent',a, ...
        'Position',[3 + 210 height-(k-1)*30 204 27], ...
        'Interruptible', 'off', ...
        'Tag','button22');
end

set(b1(1), 'Callback','disp([''   LT2init;'']); cd(getenv(''MLROOT'')); setpathsoleil(''LT2'');', 'String','LT2init');
set(b1(2), 'Callback','disp([''   Fichiers de Consignes;'']); configgui;;', 'String','Fichiers de Consignes');
% same programme for LT1 and LT2 cycling
set(b1(3), 'Callback','disp([''   LT2cycling;'']);LT1cycling', 'String','Cyclage');
set(b1(4), 'Callback','disp([''   Timing;'']); synchro_injecteur7;', 'String','Synchronisation définitive');
set(b2(1), 'Callback','optics_LT1_LT2;', 'String','OPTIQUE');
set(b2(2), 'Callback','disp([''   Emittance'']);emittance_v15;', 'String','Emittance');

b = uicontrol('Parent',a, ...
    'Callback','close all', ...
    'String','Close All Figures', ...
    'Position',[3 height-kmax*30 204 27], ...
    'Userdata',[], ...
    'Interruptible', 'off', ...   
    'Tag','button2');

b = uicontrol('Parent',a, ...
    'Callback','diary off; close(get(findobj(gcbf,''Tag'',''button1''),''Userdata''));', ...
    'Position',[3 + 210 height-kmax*30 204 27], ...
    'String','CLOSE', ...
    'Userdata',a, ...
    'Interruptible', 'off', ...   
    'Tag','button1');

