function SWE_GUI_IY

%% Figure properties

figure('Units','normalized ','Position',[0.2 0.2 0.7 0.6]);
HandAxes=axes('Units','normalized ','Position',[0.1 0.1 0.6 0.8]);
% uibuttongroup('Position',[0.82 0.1 0.16 0.8]); 
title('Shallow Water Equations Integrator','fontsize',14);
%% Controlers

HandCont(1)= uicontrol('style','popupmenu','units','norm','position',[0.81 0.82 0.1 0.1],...
    'string','Kelvin|Poincare|Rossby|Gaussian|Top hat');

HandCont(2)= uicontrol('style','edit','units','norm','position',[0.78 0.805 0.05 0.03],...
    'string','4','UserData',4,'Tag','n_x','callback',{@update_params});

HandCont(3)= uicontrol('style','edit','units','norm','position',[0.93 0.805 0.05 0.03],...
    'string','2','UserData',2,'Tag','n_y','callback',{@update_params});

HandCont(4)= uicontrol('style','pushbutton','units','norm','position',[0.84 0.14 0.06 0.05],...
    'string','Clear','callback',{@clear_axes,HandCont});

HandCont(5)= uicontrol('style','pushbutton','units','norm','position',[0.84 0.07 0.06 0.05],...
     'string','Close','callback',{@close_program});

HandCont(6)= uicontrol('style','pushbutton','units','norm','position',[0.77 0.07 0.06 0.05],...
    'string','Stop','callback',{@close_program});

HandCont(7)= uicontrol('style','pushbutton','units','norm','position',[0.77 0.14 0.06 0.05],...
    'string','Pause','callback',{@close_program});

HandCont(8)= uicontrol('style','edit','units','norm','position',[0.78 0.58 0.05 0.03],...
    'string','30','UserData',30,'Tag','latitude','callback',{@update_params});

HandCont(9)= uicontrol('style','edit','units','norm','position',[0.93 0.58 0.05 0.03],...
    'string','500','UserData',500,'Tag','H0','callback',{@update_params});

HandCont(10) = uibuttongroup('units','norm','position',[0.72 0.65 0.12 0.12],...
    'Visible','on','SelectionChangeFcn',@choose_plane);

HandCont(11) = uicontrol('Style','radiobutton','units','norm','position',[0.1 0.6 0.7 0.3],...
    'String','f plane','Parent',HandCont(10),'HandleVisibility','off','Tag','f_plane');

HandCont(12) = uicontrol('Style','radiobutton','units','norm','position',[0.1 0.1 0.7 0.3],...
    'String','beta plane','Parent',HandCont(10),'HandleVisibility','off','Tag','beta_plane');

HandCont(13)= uicontrol('style','edit','units','norm','position',[0.84 0.475 0.05 0.03],...
    'string','120','UserData',120,'Tag','time_step','callback',{@update_params});

HandCont(14)= uicontrol('style','edit','units','norm','position',[0.78 0.32 0.05 0.03],...
    'string','3000','UserData',3000,'Tag','Lx','callback',{@update_params});

HandCont(15)= uicontrol('style','edit','units','norm','position',[0.93 0.32 0.05 0.03],...
    'string','3000','UserData',3000,'Tag','Ly','callback',{@update_params});

HandCont(16)= uicontrol('style','edit','units','norm','position',[0.84 0.415 0.05 0.03],...
    'string','8000','UserData',8000,'Tag','Tmax','callback',{@update_params});

HandCont(17) = uibuttongroup('units','norm','position',[0.86 0.65 0.12 0.12],...
    'Visible','on','SelectionChangeFcn',@choose_configuration);

HandCont(18) = uicontrol('Style','radiobutton','units','norm','position',[0.1 0.6 0.7 0.3],...
    'String','Tunnel','Parent',HandCont(17),'HandleVisibility','off','Tag','Tunnel');

HandCont(19) = uicontrol('Style','radiobutton','units','norm','position',[0.1 0.1 0.7 0.3],...
    'String','Box','Parent',HandCont(17),'HandleVisibility','off','Tag','Box');

HandCont(20)= uicontrol('style','pushbutton','units','norm','position',[0.77 0.21 0.13 0.05],...
    'string','Run','callback',{@Run_SWE,HandAxes,HandCont});

%% Text Annotations
annotation('textbox',[0.72 0.825 0.1 0.1],'String','Wave type','FontName','Cambria','EdgeColor','none')
%annotation('textbox',[0.82 0.58 0.1 0.1],'String','Model parameters','EdgeColor','none')
% annotation('textbox',[0.72 0.5 0.1 0.1],'String','Integrator parameters','EdgeColor','none')
annotation('textbox',[0.72 0.52 0.1 0.1],'String','Latitude','EdgeColor','none')
annotation('textbox',[0.87 0.52 0.1 0.1],'String','H_0 [m]','EdgeColor','none')
annotation('textbox',[0.72 0.42 0.1 0.1],'String','Time Step (sec)','EdgeColor','none')
annotation('textbox',[0.72 0.36 0.1 0.1],'String','Tmax (hours)','EdgeColor','none')
annotation('textbox',[0.72 0.263 0.1 0.1],'String','L_x (km)','EdgeColor','none')
annotation('textbox',[0.87 0.263 0.1 0.1],'String','L_y (km)','EdgeColor','none')
annotation('textbox',[0.72 0.75 0.1 0.1],'String','x modes','EdgeColor','none')
annotation('textbox',[0.87 0.75 0.1 0.1],'String','y modes','EdgeColor','none')
end

%% CALLBACKS 

function Run_SWE(calling_button,eventData,HandAxes,HandCont)
    wave_type = get(HandCont(1),'value'); % gets wave type chosen by user.
    switch wave_type
        case 1
            wave_type='kelvin';
        case 2
            wave_type='poincare';
        case 3
            wave_type='rossby';
        case 4
            wave_type='gaussian';
        case 5
            wave_type='hat';
    end

    plane = get(get(HandCont(10),'SelectedObject'),'Tag');
    switch plane
        case 'f_plane'
            ModelPrms.IsBetaPlane = 0;
        case 'beta_plane'
            ModelPrms.IsBetaPlane = 1;
    end
    
    configuration = get(get(HandCont(17),'SelectedObject'),'Tag');
    switch configuration
        case 'Tunnel'
            ModelPrms.IsBox = 0;
        case 'Box'
            ModelPrms.IsBox = 1;
    end
    
    ModelPrms.n_x = get(HandCont(2),'UserData'); 
    ModelPrms.n_y = get(HandCont(3),'UserData'); 
    ModelPrms.H0 = get(HandCont(9),'UserData'); 
    ModelPrms.latitude = get(HandCont(8),'UserData'); 
    ModelPrms.time_step = get(HandCont(13),'UserData'); 
    ModelPrms.Tmax = get(HandCont(16),'UserData');     
    ModelPrms.Lx = get(HandCont(14),'UserData'); 
    ModelPrms.Ly = get(HandCont(15),'UserData'); 
    
    IntegPrms = 1; 
    SWE_solver_IY(wave_type,ModelPrms,IntegPrms,HandAxes)
end

function close_program(~,~)
close all;
end

function clear_axes(~,~,handle)
cla;
end

function update_params(calling_button,eventData)
    string=get(calling_button,'string'); 
    number=str2double(string); 
    set(calling_button,'UserData',number); 
end

function choose_plane(~,~)
end

function choose_configuration(~,~)
end

