function fsi_slicexy(action)

switch nargin
case 0
   LocalInitFig
case 1
   switch action
   case 'grid'
      
      % Read grid spacing from the runfsi.properties file
      p    = readProperties('runfsi.properties');
      xInc = sscanf(getProperty(p, 'xinc'), '%f');
      yInc = sscanf(getProperty(p, 'yinc'), '%f');
      zInc = sscanf(getProperty(p, 'zinc'), '%f');
      
      % Get the data
      figH     = findobj('Tag','Main');
      UserData = get(figH, 'UserData');
      xColumn  = strmatch('lon', UserData.columns);
      yColumn  = strmatch('lat', UserData.columns);
      zColumn  = strmatch('depth', UserData.columns);
      
      % Get the user selected variable to graph
      bh         = findobj('Tag', 'variableName');
      dataColumn = get(bh, 'Value');
      
      % Get the slice points
      figXY = findobj('Tag', 'fsi_slicexy');
      xy = get(figXY, 'UserData');
      
      [p f e] = fileparts(UserData.filename);
      filename = [p filesep f '_' UserData.columns{dataColumn}];
      
      if exist([filename '.mat']) ~= 2
         
         % Grid the variable
         [XI, YI, ZI, VI] = grid3d(UserData.data(:, xColumn), ...
            UserData.data(:, yColumn), ...
            UserData.data(:, zColumn), ...
            UserData.data(:, dataColumn), ...
            xInc, yInc, zInc);
         
         save(filename, 'XI','YI','ZI','VI');
         
      else
         load(filename)
      end
      
      % Create the matrix specifying the slice coordinates
      % 1. create a line of points between the end points
      if xy.lon2 < xy.lon1
         xInc = xInc*-1;
      end
      
      xi = [xy.lon1:xInc:xy.lon2];
      yi = interp1([xy.lon1 xy.lon2], [xy.lat1 xy.lat2], [xy.lon1:xInc:xy.lon2]);
      % 2. create a vector of depths
      zi = [min(UserData.data(:, zColumn)):zInc:max(UserData.data(:, zColumn))];
      % 3. turn xi, yi, and zi into an array
      lx = length(xi);
      lz = length(zi);
      sx = repmat(xi, lz, 1);
      sy = repmat(yi, lz, 1);
      sz = repmat(zi', 1, lx);
      
      % Create the plot
      figure;
      slice(XI, YI, ZI, VI, sy, sx, sz);
      shading flat
      colorbar2
      set(gca, 'ZDir', 'reverse')
      grid('on')
      
      fh2 = findobj('Tag', 'fsi_slicexy');      % Get this panel
      delete(fh2)
           
   case 'selectStart'
      fh = findobj('Tag', 'fsi_slicexy');      % Get this panel
      set(0, 'CurrentFigure', fh);
      title('Select the starting location of the XY slice');
      [xy.lat1 xy.lon1] = fsi_select;
      title('Select the ending location of the XY slice');
      [xy.lat2 xy.lon2] = fsi_select;
      set(fh, 'UserData', xy);
      title('Gridding Data...please be patient');
      fsi_slicexy('grid')
   end
   
end



%%%%%%%%%%%%%%%%%%%%%
function LocalInitFig
% Creates the main figure

ScreenSize = get(0, 'ScreenSize');
figH = findobj('Tag', 'Main');
UserData = get(figH, 'UserData');

badH = findobj('Tag', 'fsi_slicexy');
if ~isempty(badH)
   delete(badH)
end


h0 = figure('Color',[0.501960784313725 0 0.250980392156863], ...
   'FileName','fsi_slicexy.m', ...
   'PaperPosition',[18 180 576 432], ...
   'PaperUnits','points', ...
   'Tag','fsi_slicexy', ...
   'ToolBar','none');

lonColumn = strmatch('lon',UserData.columns);
latColumn = strmatch('lat',UserData.columns);

plot(UserData.data(:, lonColumn), UserData.data(:, latColumn), '.', 'Markersize', 2, 'Tag', 'nav');
title('Navigation View', 'Tag', 'xyTitle')
fsi_slicexy('selectStart')