function floatTrack2()

clear all;
close all;

bathy = getBathy();
iUSBL = getIUSBL();
gui = buildGUI();

iUSBLTimer = timer('ExecutionMode', 'fixedRate', ...
                    'Period', 1, ...
                    'TimerFcn', {@iUSBLTimerCallback});
start(iUSBLTimer);

pause(20);

stop(iUSBLTimer);

%-----------------------
function iUSBL = getIUSBL()
    iUSBL = load('iUSBLMsg.mat');
end
% 
% %-----------------------
function [] = iUSBLTimerCallback(varargin)
        persistent index
        if isempty(index)
            index = 1;
        end

        iUSBL.msg(index,:);
        index = index +1;
        
        fields = strsplit(iUSBL.msg(index,1:end-2), {'X','Y','Z',','});
        set(gui.floatEastingEdit, 'String', fields{3});
        set(gui.floatNorthingEdit, 'String', fields{4});
        set(gui.floatDepthEdit, 'String', fields{5});
        
        axes(gui.depthAxes);
        str2double(fields{5});
       % plot(index, str2double(fields{5}), '+');  
        %StripChart('Update',hLine,fields{5})

    end        
%-----------------------
    function bathy = getBathy()
        fprintf('Loading mc15 data set \n');
        bathy = load('mc15.mat');
    end

%------------------------
    function gui = buildGUI()
         % Create the user interface for the application and return a
        % structure of handles for global use.
        gui = struct();
        % Open a window and add some menus
        gui.Window = figure( ...
            'Name', 'Float Track', ...
            'NumberTitle', 'off');
        
        bigBox = uix.HBoxFlex('Parent', gui.Window, 'Padding', 5, 'Spacing', 5);

        chartBox = uix.VBoxFlex('Parent', bigBox, 'Padding', 5, 'Spacing', 5);
        controlsBox = uix.VBox('Parent', bigBox, 'Padding', 5);
        set(bigBox, 'Widths', [-3 -1]);

        gui.chartAxes = axes('Parent', chartBox);
        surf(bathy.mc15.x, bathy.mc15.y, bathy.mc15.z, 'Parent', gui.chartAxes, ...
                'FaceColor', 'interp', ...
                'LineStyle', 'none', ...
                'FaceLighting', 'gouraud');
        cm = haxby(256);
        colormap(cm);
        daspect([1, 1, .25]);
        axis tight;
        camlight left;

        gui.depthAxes = axes('Parent', chartBox);
       % StripChart('Initialize',gca);

        hold(gui.depthAxes);
        
        set(chartBox, 'Heights', [-3 -2]);

        gui.shipLatEdit = uicontrol('Parent', controlsBox, 'Style', 'edit');
        uicontrol('Parent', controlsBox, 'Style', 'text', ... 
                    'String', 'Ship Latitude');
        
        gui.shipLonEdit = uicontrol('Parent', controlsBox, 'Style', 'edit');
        uicontrol('Parent', controlsBox, 'Style', 'text', ... 
                    'String', 'Ship Longitude')
                
        gui.floatNorthingEdit = uicontrol('Parent', controlsBox, 'Style', 'edit');
        uicontrol('Parent', controlsBox, 'Style', 'text', ... 
                    'String', 'Float Northing');
        
        gui.floatEastingEdit = uicontrol('Parent', controlsBox, 'Style', 'edit');
        uicontrol('Parent', controlsBox, 'Style', 'text', ... 
                    'String', 'Float Easting')
                
        gui.floatDepthEdit = uicontrol('Parent', controlsBox, 'Style', 'edit');
        uicontrol('Parent', controlsBox, 'Style', 'text', ... 
                    'String', 'Float Depth')
                
        gui.button1 = uicontrol('Parent', controlsBox, 'Style', 'pushbutton', ...
                             'String', 'Button 1');
        
        set(controlsBox, 'Heights', [40 20 40 20 40 20 40 20 40 20 40]);
        
%        flexGrid = uix.GridFlex('Parent', gui.Window, 'Padding', 10, 'DividerMarkings', 'on');
%        chartAxes =  axes('Parent', flexGrid);
%        depthAxes = axes('Parent', flexGrid);
%        controlBox = uix.VBoxFlex('Parent', flexGrid, 'Background', 'g');
%        set(flexGrid, 'Widths', [-5 -2], 'Heights', [-3 -1]);
%               
%         % Arrange the main interface
%         mainLayout = uix.HBoxFlex( 'Parent', gui.Window, 'Spacing', 3 );
%         
%         % + Create the panels
%         controlPanel = uix.BoxPanel( ...
%             'Parent', mainLayout, ...
%             'Title', 'Select a demo:' );
%         gui.ViewPanel = uix.BoxPanel( ...
%             'Parent', mainLayout, ...
%             'Title', 'Viewing: ???', ...
%             'HelpFcn', @onDemoHelp );
%         gui.ViewContainer = uicontainer( ...
%             'Parent', gui.ViewPanel );        
% 
%         % + Adjust the main layout
%         set( mainLayout, 'Widths', [-1,-2]  );
%         
%         
%         % + Create the controls
%         controlLayout = uix.VBox( 'Parent', controlPanel, ...
%             'Padding', 3, 'Spacing', 3 );
%         gui.ListBox = uicontrol( 'Style', 'list', ...
%             'BackgroundColor', 'w', ...
%             'Parent', controlLayout, ...
%             'String', demoList(:), ...
%             'Value', 1, ...
%             'Callback', @onListSelection);
%         gui.HelpButton = uicontrol( 'Style', 'PushButton', ...
%             'Parent', controlLayout, ...
%             'String', 'Help for <demo>', ...
%             'Callback', @onDemoHelp );
%         set( controlLayout, 'Heights', [-1 28] ); % Make the list fill the space
%         
%         % + Create the view
%         p = gui.ViewContainer;
%         gui.ViewAxes = axes( 'Parent', p );
    end
end


        


