function GUI_cut(data,time,freq)

    scrsz = get(0,'ScreenSize');

% vytvoreni noveho okna pro zobrazeni segmentu

    main_window = figure('Visible','on',...
                         'Units','normalized',...
                         'Outerposition',[0 0 1 1],...
                         'name','Data','numbertitle','off',...
                         'Resize','off');

    set(main_window,'units','pixels'); 
    set(main_window,'MenuBar','none');

%% rozdeleni na dva panely    
 % nastaveni rozmeru a optimalizace na zaklade sirky obrazovky   
    Data_Panel_width = scrsz(3)/1.4;
    Data_Panel_height = scrsz(4)/1.2;
    Data_Panel_offset = 30;

    Data_Panel = uipanel('BorderType','etchedin',...
                'Units','characters',...
                'Parent',main_window, ...
                'Title','Graph', ...
                'Units','pixels', ...
                'Position',[Data_Panel_offset Data_Panel_offset+30 Data_Panel_width Data_Panel_height],...
                'TitlePosition','centertop');

    Data_Buttons = uipanel('BorderType','etchedin',...
                'Units','characters',...
                'Parent',main_window, ...
                'Title','Analysis', ...
                'Units','pixels', ...
                'Position',[Data_Panel_offset+Data_Panel_width+10 Data_Panel_offset+30 scrsz(3)-Data_Panel_width-70 Data_Panel_height],...
                'TitlePosition','centertop');   

%% tlacitka pro panely 

  offset = 30;
  button_width = 0.85*(scrsz(3)-Data_Panel_width-120);

  % panel pro poslani dat zpet do hlavniho GUI
  Data_Send = uipanel('BorderType','etchedin',...
                'Units','characters',...
                'Parent',Data_Buttons, ...
                'Title','Load signals back to main GUI', ...
                'Units','pixels', ...
                'Position',[20, Data_Panel_height/1.3, scrsz(3)-Data_Panel_width-120, Data_Panel_height/5.5],...
                'TitlePosition','centertop');   
            
 % definovana univerzalni delka pro button
   send_button = uicontrol('Style','pushbutton','String','Send signals to MainGUI',...
                          'Parent',Data_Send,...
                          'Position',[20, 40, button_width, 30],...
                          'Callback',{@send_Callback});            
                     
%%
  m_height = Data_Panel_height/3;
  Data_Marks = uipanel('BorderType','etchedin',...
                'Units','characters',...
                'Parent',Data_Buttons, ...
                'Title','Marks', ...
                'Units','pixels', ...
                'Position',[20, Data_Panel_height/1.5-Data_Panel_height/4.5 - offset, scrsz(3)-Data_Panel_width-120, Data_Panel_height/3],...
                'TitlePosition','centertop');   
 
   mark_button = uicontrol('Style','pushbutton','String','Create marks',...
                          'Parent',Data_Marks,...
                          'Position',[20, m_height-2*offset, button_width, 30],...
                          'Callback',{@mark_Callback});   
                      
   clear_button = uicontrol('Style','pushbutton','String','Delete marks',...
                          'Parent',Data_Marks,...
                          'Position',[20, m_height-4*offset, button_width 30],...
                          'Callback',{@clear_Callback});
   
   norm_button = uicontrol('Style','pushbutton','String','Normalize',...
                          'Parent',Data_Marks,...
                          'Position',[20, m_height-6*offset,button_width 30],...
                          'Callback',{@norm_Callback});
                      
%% potvrzovací buttons
   Data_action = uipanel('BorderType','etchedin',...
                'Units','characters',...
                'Parent',Data_Buttons, ...
                'Title','Options buttons', ...
                'Units','pixels', ...
                'Position',[20, 20, scrsz(3)-Data_Panel_width-120, Data_Panel_height/3.2],...
                'TitlePosition','centertop');   
    
   cut_button = uicontrol('Style','pushbutton','String','Confirm changes',...
                          'Parent',Data_action,...
                          'Position',[20, 4.5*offset, button_width 30],...
                          'Callback',{@cut_Callback});

   reverse_button = uicontrol('Style','pushbutton','String','Undo changes',...
                          'Parent',Data_action,...
                          'Position',[20, 2.5*offset, button_width 30],...
                          'Callback',{@undo_Callback});                   
                      
                      
   save_button = uicontrol('Style','pushbutton','String','Save signals',...
                          'Parent',Data_action,...
                          'Position',[20, 20, button_width 30],...
                          'Callback',{@save_Callback});
                      
                      
%% globalni promenne

          marks = [];
          data_old = data;

%% udelans scrollsubplot pro data

          osa = scrollsubplot(1,1,1);
          set(osa,'Parent',Data_Panel);
          plot_signals();
          
          
              
%% vykresleni dat
function plot_signals()

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

            %% showing the marks        
            if(~isempty(marks))
                              yLim = get(osa,'YLim');
                              
                            for k=1:length(marks)
                                if(marks(k)>=min_bound && marks(k)<=max_bound)
                                    line([(marks(k)),(marks(k))],yLim,'Color','r','Parent',osa);
                                end
                            end
            end



    end


%% create marks for cuting  the signal
    function mark_Callback(source,eventdata)
        
    'tady budu cutovat signaly'
    
        if(isempty(marks)==1)
            i = 1;
        else
            i = length(marks)+1;
        end
        
        [x,y] = ginput(1);        
         marks(i) = x;  
         
         % zobrzeni marku
        marks(i)
         i = i+1;      
         plot_signals();     

    end 

    function cut_Callback(source,eventdata)
        data = data(marks(1)*freq:marks(2)*freq,:); 
        length(data)
        time = (1/freq:1/freq:length(data)/freq);
        marks = [];
        plot_signals();

    end 

%% funkce na vraceni zmen
    function undo_Callback(source,eventdata)
        data = data_old;
        time = (1/freq:1/freq:length(data_old)/freq);
        plot_signals();

    end 

%% funcke na vymazani markru
    function clear_Callback(source,eventdata)
        
        marks = [];
        plot_signals();
        
    end

%% normalizace dat
    function norm_Callback(source,eventdata)
        
        [vel_m vel_n] = size(data);  
        for i=1:vel_n
            if(i==1)
        data(:,i) = 1 + (data(:,i)-min(data(:,i)))/(max(data(:,i))-min(data(:,i)));
        % pro program
          
            else
        data(:,i) = (data(:,i)-min(data(:,i)))/(max(data(:,i))-min(data(:,i)));
            end
        end
        plot_signals();
        
    end

%% ulozeni signalu
    function save_Callback(source,eventdata)  

    [FileName PathName] = uiputfile('*.txt');
    [vel_m vel_n] = size(data);  
    fid=fopen([PathName FileName],'w');
    for ii = 1:vel_m
    fprintf(fid,'%g\t',data(ii,:));
    fprintf(fid,'\n');
    end

    end

%% poslani dat do MainGUI

    function send_Callback(source,eventdata)  

           setappdata(0,'NewData',data);
           setappdata(0,'TimeVector',time);
           close;
    end



end