function GUI_ai(data,fvz)


scrsz = get(0,'ScreenSize');   

% vytvoreni noveho okna pro zobrazeni segmentu

w_pwv = figure('Units','characters',...
            'HandleVisibility','callback',...
            'Renderer','painters',...
            'MenuBar','none', ...
            'numbertitle','off', ...
            'name','AI_manual', ...
            'Units','pixels', ... 
            'Position',[70 80 scrsz(3)/1.1 scrsz(4)/1.2]);
        
    %%    
% Okno rozdelene do 2 panelu

L_Panel_sirka = scrsz(3)/5;
L_Panel_vyska = scrsz(4)/1.2-10;
L_Panel_odsazeni = 10;

L_Panel = uipanel('BorderType','etchedin',...
		'Units','characters',...
		'Parent',w_pwv, ...
        'Title','Parameters', ...
        'Units','pixels', ...
		'Position',[L_Panel_odsazeni L_Panel_odsazeni L_Panel_sirka L_Panel_vyska],...
        'TitlePosition','centertop');
   
Podrobnosti_odsazeni = 10;
Podrobnosti_sirka = 2.6*L_Panel_sirka;
Podrobnosti_vyska = L_Panel_vyska;
    
Podrobnosti = uipanel('BorderType','etchedin',...
            'Units','characters',...
            'Parent',w_pwv, ...
            'Title','Graph', ...
            'Units','pixels', ...
            'Position', ...
            [3*Podrobnosti_odsazeni+L_Panel_sirka Podrobnosti_odsazeni Podrobnosti_sirka*1.3 Podrobnosti_vyska],...
            'TitlePosition','centertop'); 
        
 %% vytvoreni popisku a zadani vzdalenosti
 
nadpis_pocet_marks = uicontrol(L_Panel,'Style','text','String','Pocet vln:',...
                     'Units','pixels', ...
                     'Position',[15 scrsz(4)/1.4 L_Panel_sirka-30 20]);        
      
set_pocet_marks = uicontrol(L_Panel,'Style','edit','String','5','Units','pixels', ...
                     'BackgroundColor','white','Callback',{@Pocet_Callback}, ...
                     'Position',[15 scrsz(4)/1.4-20 L_Panel_sirka-30 20]); 

create_marks = uicontrol('Style','pushbutton','String','Create marks',...
                          'Parent',L_Panel,...
                          'Position',[15 scrsz(4)/1.6 L_Panel_sirka-30 30],...
                          'Callback',{@create_Callback}); 
                      
delete_marks_button = uicontrol('Style','pushbutton','String','Delete marks',...
                          'Parent',L_Panel,...
                          'Position',[15 scrsz(4)/1.6-40 L_Panel_sirka-30 30],...
                          'Callback',{@delete_Callback});  

%%                     
                                           
count_button = uicontrol('Style','pushbutton','String','Count AI',...
                          'Parent',L_Panel,...
                          'Position',[15 scrsz(4)/2-280 L_Panel_sirka-30 40],...
                          'Callback',{@count_Callback});   

nadpis_AI = uicontrol(L_Panel,'Style','text','String','AI [%]',...
                     'Units','pixels', ...
                     'Position',[15 scrsz(4)/2-325 L_Panel_sirka-30 20]);  
                      
set_AI = uicontrol(L_Panel,'Style','text','String','','Units','pixels', ...
                     'BackgroundColor','white', ...
                     'Position',[15 scrsz(4)/2-360 L_Panel_sirka-30 30]);                        
                 
                 
%% osa pro vykresleni nalezlych peaku

 axes_data = axes('Units','pixels','Position',[40 40 Podrobnosti_sirka*1.2,Podrobnosti_vyska-70], ...
                  'Parent',Podrobnosti);   
              
AI_pole = [];

%%                    
 
    function Pocet_Callback(~,~)  

    pocet = str2double(get(set_pocet_marks,'String')); 
    pocet_markru = 3*pocet;
        
    end 
          

    

% variables for marks
 m_wave = [];
 pocet = 5;
 marks = [];
 i = 1;    
 time = (1/fvz:1/fvz:length(data)/fvz);
 pocet_markru = 15;
 AI = 0;
 
 % variables for presssure
    systolic_press = [];
    reflected_press = [];
    diastolic_press = [];
 
          
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% only plot the signals

plot_signals();

    function plot_signals()

            plot(time,data);
            xlabel('t [s]');
            ylabel('Amplitude [-]');
            zoom on;
            min_bound = 0;
            max_bound = length(data);

            %% showing the marks        
            if(~isempty(marks))
                          
                yLim = get(gca,'YLim');
                
                            for k=1:length(marks)
                                    if(marks(k)>=min_bound && marks(k)<=max_bound)
                                             switch rem(k,3)
                                               case 1
                                                 line([(marks(k)),(marks(k))],yLim,'Color','r');
                                               case 2
                                                 line([(marks(k)),(marks(k))],yLim,'Color','g');
                                               case 0
                                                 line([(marks(k)),(marks(k))],yLim,'Color','y');
                                             end
                                    end
                            end
            end



    end

% then we have to do marks for every wave

%% choosing a place for a mark

    function create_Callback(source,eventdata)
 
         % msgbox('Click the start (begin of a systole) and the end (dicrotic notch)');
        pom_urc = 1;
        pole = 1;

        for i=1:pocet_markru
               switch rem(i,3)
                   case 1
                     msg = msgbox('Systolic Peak');
                     pause(1);
                     delete(msg);
                     [x,y] = ginput(1);  
                     marks(i) = round((x*1000))/1000;
                     ind = round(marks(i)*fvz);
                     systolic_press(pole) = ind;
                     line([(marks(i)),(marks(i))],[min(data) max(data)],'Color','r');
                   case 2
                     msg = msgbox('Reflected Peak');
                     pause(1);
                     delete(msg);
                     [x,y] = ginput(1);      
                     marks(i) = round((x*1000))/1000;
                     ind = round(marks(i)*fvz);
                     reflected_press(pole) = ind;
                     line([(marks(i)),(marks(i))],[min(data) max(data)],'Color','g');
                   case 0
                     msg = msgbox('Diastolic Peak');
                     pause(1);
                     delete(msg);
                     [x,y] = ginput(1); 
                     marks(i) = round((x*1000))/1000;
                     ind = round(marks(i)*fvz);
                     diastolic_press(pole) = ind;
                     line([(marks(i)),(marks(i))],[min(data) max(data)],'Color','y');
                     pole = pole+1;
               end
         end

         plot_signals();  
         
         % vypocet prumerne vlny
         AI_soucet = 0;
        
         % vypis
        systolic_press
        data(systolic_press)
        reflected_press
        data(reflected_press)
        diastolic_press
        data(diastolic_press)
         
        for j=1:pocet 
           pomer_val = (data(reflected_press(j))-data(systolic_press(j)))/(data(systolic_press(j))-data(diastolic_press(j)))
           AI_pole(j)=pomer_val;
           AI_soucet = AI_soucet + pomer_val; 
        end
        
        AI_pole
        AI = mean(AI_pole);
        
    end     
        

    function delete_Callback(source,eventdata)  

      marks = [];  
      plot_signals();
        
    end



    function count_Callback(~,~)  
 %%       
        % vypsani AI do labelu
        value_f = AI*100;
        odch = std(AI_pole)
        value_final = [num2str(value_f) ' %'];
        set(set_AI,'String',value_final);

        
        
    end
        


end