function fig = PLplot(action, varargin)
% This is the machine-generated representation of a Handle Graphics object
% and its children.  Note that handle values may change when these objects
% are re-created. This may cause problems with any callbacks written to
% depend on the value of the handle at the time the object was saved.
% This problem is solved by saving the output as a FIG-file.
%
% To reopen this object, just type the name of the M-file at the MATLAB
% prompt. The M-file and its associated MAT-file must be on your path.
% 
% NOTE: certain newer features in MATLAB may not have been saved in this
% M-file due to limitations of this format, which has been superseded by
% FIG-files.  Figures which have been annotated using the plot editor tools
% are incompatible with the M-file/MAT-file format, and should be saved as
% FIG-files.


if nargin<1,
  action='InitializePLplot';
end;

feval(action,varargin{:});
return;

%%%
%%%   Sub-function - InitializePLplot
%%%

function InitializePLplot()

load PLplot
redgreenblue=[0.2157 .6353 .6353]*1.2;%let's make it lighter for this figure

h0 = figure('Units','normalized', ...
	'Color',[redgreenblue], ...
	'Colormap',mat0, ...
	'FileName','c:\plgui\mygui\PLplot.m', ...
	'MenuBar','none', ...
	'Name','VPR Data Visualization', ...
	'NumberTitle','off', ...
	'PaperPosition',[18 180 576 432], ...
	'PaperUnits','points', ...
	'Position',[0.231 0.286 0.75 0.673], ...
	'Tag','VPR Data Visualization', ...
	'ToolBar','none');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'ListboxTop',0, ...
	'Position',[0.078 0.658 0.531 0.211], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'ListboxTop',0, ...
	'Position',[0.691 0.134 0.213 0.735], ...
	'Style','frame', ...
	'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'ListboxTop',0, ...
	'Position',[0.1 0.134 0.42 0.469], ...
	'Style','frame', ...
	'Tag','Frame3');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.7, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.095 0.7944 0.05 0.0401], ...
	'String','Drive', ...
	'Style','text', ...
	'Tag','StaticText Drive Letter', ...
	'TooltipString','Select Drive Letter');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.7, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.205 0.7944 0.1203 0.0401], ...
	'String','Folder', ...
	'Style','text', ...
	'Tag','StaticText Folder', ...
	'TooltipString','Select Folder');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.7, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.39 0.7944 0.0788 0.0401], ...
	'String','Cruise ', ...
	'Style','text', ...
	'Tag','StaticText Cruise Name', ...
	'TooltipString','Cruise Name');


     drives=str2mat(getdrives('-nofloppy'));
     drives=str2mat('Select',drives);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','PLplot GetFolders', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[0.15 0.7985 0.075 0.0401], ...
	'String',drives, ...
	'fontunits','normalized','fontsize',.6, ...
	'FontWeight','normal', ...
	'Style','popupmenu', ...
	'Tag','PopupMenu Disc', ...
	'TooltipString','Select Drive Letter') ;
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.2, ...
	'Callback','PLplot PlotData', ...
	'fontunits','normalized','fontsize',.3, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.7380 0.71 0.1203 0.0773], ...
	'String','PLOT DATA', ...
    'Style','pushbutton', ...
	'Tag','Pushbutton Start', ...
	'TooltipString','Plot the data');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.2, ...
	'Callback','PLplot PlotTriplet', ...
	'fontunits','normalized','fontsize',.25, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.7380 0.54 0.1203 0.0773], ...
    'Style','pushbutton', ...
    'String','ENHANCED DATA PLOTS', ...
	'Tag','Pushbutton Triplet', ...
	'TooltipString',['Generates the same plots as PLOT DATA' char(10) 'with more options.' char(10) ' ' char(10) 'Plots both VPRII and ECO Triplet Data.']);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.2, ...
	'Callback','plot_help', ...
	'fontunits','normalized','fontsize',.3, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.7433 0.37 0.1203 0.0773], ...
	'String','HELP', ...
    'Style','pushbutton', ...
	'Tag','Pushbutton Help', ...
	'TooltipString','Help for Plotting');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.2, ...
	'Callback','cd ..;cd mygui; close(gcbf)', ...
	'fontunits','normalized','fontsize',.3, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.7447 0.2 0.1203 0.0773], ...
    'Style','pushbutton', ...
	'String','EXIT', ...
	'Tag','Pushbutton Exit', ...
	'TooltipString','Exit this window');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.23 0.15 0.058], ...
	'String','Flight Data', ...
	'Style','checkbox', ...
	'Tag','Checkbox Flight', ...
   'TooltipString',['Six Panel Plot of Along-path speed, Vertical speed'...
      char(10) 'Roll, Pitch, Altimetry, Bottom Depth versus Time'], ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.47 0.242 0.058], ...
	'String','Hydrography vs. Space', ...
	'Style','checkbox', ...
	'Tag','Checkbox HydroXYZ', ...
	'TooltipString','Creates 3-D plots of CTD parameters versus Longitude, Latitude, and VPR depth.', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.41 0.242 0.058], ...
	'String','Hydrography vs. Time', ...
	'Style','checkbox', ...
	'Tag','Checkbox HydroTime', ...
    'TooltipString',['Six Panel Plot of Salinity, Temperature, Density'...
                      char(10) 'Attenuation, Fluorescence, Light vs Time'], ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.35 0.242 0.058], ...
	'String','Hydrography vs. T&S', ...
	'Style','checkbox', ...
	'Tag','Checkbox plotTS', ...
    'TooltipString','Creates Temperature-Salinity Diagrams of All Parameters (Including Plankton, if Applicable).', ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
    'Callback','set(findobj(gcbf,''Tag'',''Radiobutton CreateDotPlot''),''value'',0)', ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.36 0.47 0.14 0.05], ...
	'String',['Curtain Plots'], ...
	'Style','radiobutton', ...
	'Tag','Radiobutton CreateCurtainPlot', ...
	'TooltipString',['Create color curtain plots for sensor data (and plankton if selected)' char(10) ' Data are mapped to regular grid.'], ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
    'Callback','set(findobj(gcbf,''Tag'',''Radiobutton CreateCurtainPlot''),''value'',0)', ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.36 0.41 0.14 0.05], ...
	'String',['Dot Plots'], ...
	'Style','radiobutton', ...
	'Tag','Radiobutton CreateDotPlot', ...
	'TooltipString',['Create color dot plots for sensor data (and plankton if selected)' char(10) ' instead of the default curtain plots'], ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
    'callback',['set(findobj(gcbf,''Tag'',''PopupMenu ProcessedFiles''),''enable'',''on'');' ...
                'set(findobj(gcbf,''Tag'',''PopupMenu VPRlogFiles''),''enable'',''off'');' ...
                'set(findobj(gcbf,''Tag'',''Radiobutton LoadVPRlogFile''),''value'',0);'], ...
	'fontunits','normalized','fontsize',.7, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.1 0.7075 0.015 0.0401], ...
	'String','', ...
	'Style','radiobutton', ...
	'Tag','Radiobutton LoadProcessedSensorData', ...
	'TooltipString',['Load processed (not vprlog) data,' char(10) 'e.g. from c:\data\cruise\processed\sensordata\vpr3.mat'], ...
    'Visible','off', ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
    'callback',['set(findobj(gcbf,''Tag'',''PopupMenu ProcessedFiles''),''enable'',''off'');' ...
                'set(findobj(gcbf,''Tag'',''PopupMenu VPRlogFiles''),''enable'',''on'');' ...
                'set(findobj(gcbf,''Tag'',''Radiobutton LoadProcessedSensorData''),''value'',0);'], ...
	'fontunits','normalized','fontsize',.7, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.3 0.7075 0.015 0.0401], ...
	'String','', ...
	'Style','radiobutton', ...
	'Tag','Radiobutton LoadVPRlogFile', ...
	'TooltipString',['Load vprlog file,' char(10) 'e.g. from c:\data\cruise\vprlog\'], ...
    'Visible','off', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
    'callback',['set(findobj(gcbf,''Tag'',''PopupMenu ProcessedFiles''),''enable'',''off'');' ...
                'set(findobj(gcbf,''Tag'',''PopupMenu VPRlogFiles''),''enable'',''off'');' ...
                'set(findobj(gcbf,''Tag'',''PopupMenu VPRtows''),''enable'',''on'');' ...
                'set(findobj(gcbf,''Tag'',''Radiobutton LoadVPRlogFile''),''value'',0);' ...
                'set(findobj(gcbf,''Tag'',''Radiobutton LoadProcessedSensorData''),''value'',0);'], ...
	'fontunits','normalized','fontsize',.7, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.47 0.7075 0.015 0.0401], ...
	'String','', ...
	'Style','radiobutton', ...
	'Tag','Radiobutton LoadCTDdatFiles', ...
	'TooltipString',['Load ctd.dat files,' char(10) 'from hourly roi folders' char(10) 'for chosen VPR tow'], ...
    'Visible','off', ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.31 0.29 0.20 0.058], ...
	'String',['Save Processed Physical Data'], ...
	'Style','checkbox', ...
	'Tag','Checkbox SaveSensorData', ...
	'TooltipString',['Saves processed data to a mat file' ... 
      char(10) 'e.g. c:\data\cruise\processed\sensordata\vpr3.mat'], ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.31 0.23 0.20 0.058], ...
	'String',['Load Processed Plankton Data'], ...
	'Style','checkbox', ...
	'Tag','Checkbox LoadBugData', ...
	'TooltipString',['Load processed plankton data instead of reading autoid files,' char(10) 'e.g. load from c:\data\cruise\processed\bugs'], ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.31 0.17 0.20 0.058], ...
	'String',['Save Processed Plankton Data'], ...
	'Style','checkbox', ...
	'Tag','Checkbox SaveBugData', ...
	'TooltipString',['Saves processed bug data as binned and individual,' char(10) 'in, e.g., c:\data\cruise\processed\bugs\'], ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.17 0.15 0.058], ...
	'String','Ship Track', ...
	'Style','checkbox', ...
	'Tag','Checkbox Courseplot', ...
	'TooltipString','2-D plot of ship track', ...
	'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
    'callback','if get(gcbo,''value''),PLplot GetClassifier;end;',...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.29 0.15 0.058], ...
	'String','Plankton', ...
	'Style','checkbox', ...
	'Tag','Checkbox Plankton', ...
	'TooltipString',['Two 3-D (lat,long,depth) curtain or dot plots of Abundance (#/liter) and'...
      char(10) 'Biomass (ugC/liter) for the selected planktonic taxon'], ...
      'Value',0);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.9, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.22 0.536 0.207 0.027], ...
	'String','SELECT PLOTS', ...
	'Style','text', ...
   'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue], ...
	'fontunits','normalized','fontsize',.6, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.53 0.5294 0.1364 0.0401], ...
	'String','Replot Interval', ...
	'Style','text', ...
   'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ... 
     'Units','normalized', ...
     'BackgroundColor',[1 1 1], ...
     'ListboxTop',0, ...
     'Position',[0.55 0.4944 0.11 0.0401], ...
     'String',str2mat('only once','30 seconds','60 seconds','120 seconds'), ...
	'fontunits','normalized','fontsize',.6, ...
	'FontWeight','normal', ...
     'max',4, ...
     'min',1, ...
     'Style','popupmenu', ...
     'Tag','PopupMenu ReplotVal', ...
     'TooltipString','Select time interval for replotting data', ...
     'Value',1);

if nargout > 0, fig = h0; end


function GetFolders(fig)

if nargin<1,
   h=gcbf;
else
   h=fig;
end;

if ~isempty(h)
  %delete existing popups
  h1=findobj(h,'Tag','PopupMenu Folder'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu Cruise'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu VPRlogFiles'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu ProcessedFiles'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu GetClassifier'); delete(h1);
  set(findobj(h,'Tag','Radiobutton LoadVPRlogFile'),'value',1,'visible','off');
  set(findobj(h,'Tag','Radiobutton LoadProcessedSensorData'),'value',0,'visible','off');
  set(findobj(h,'Tag','Radiobutton LoadCTDdatFiles'),'value',0,'visible','off');
%find folders
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  folders=dir(disc);
  folderarray=str2mat(folders.name);
  folderarray=folderarray([folders.isdir]',:);
  sz=size(folderarray,1);
  if sz>2,    
     count=1;
     if strcmp(folderarray(1,1),'.'),count=2;end
     if strcmp(folderarray(2,1),'.'),count=3;end
     folderarray=sortrows(folderarray(count:sz,:));
     folderarray=str2mat('Select',folderarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'Callback','PLplot GetCruises', ...
          'ListboxTop',0, ...
          'Position',[0.295 0.7985 0.0909 0.0401], ...
          'String',folderarray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sz+1, ...
          'min',1, ...
          'horizontalalignment','left', ...
          'Style','popupmenu', ...
          'Tag','PopupMenu Folder', ...
          'TooltipString','Select Folder', ...
          'Value',1);
  end
end

function GetCruises(fig)

if nargin<1,
   h=gcbf;
else
   h=fig;
end;

if ~isempty(h)
  %delete existing popups
  h1=findobj(h,'Tag','PopupMenu Cruise'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu VPRlogFiles'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu ProcessedFiles'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu GetClassifier'); delete(h1);
  set(findobj(h,'Tag','Radiobutton LoadVPRlogFile'),'value',1,'visible','off');
  set(findobj(h,'Tag','Radiobutton LoadProcessedSensorData'),'value',0,'visible','off');
  set(findobj(h,'Tag','Radiobutton LoadCTDdatFiles'),'value',0,'visible','off');
%find cruises
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  cruises=dir(basepath);
  cruisearray=str2mat(cruises.name);
  sz=size(cruisearray,1);
  if sz>2,    
     cruisearray=cruisearray(3:sz,:);
     cruisearray=sortrows(cruisearray);
     cruisearray=str2mat('Select',cruisearray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'Callback','PLplot GetVPRlogFilenames;PLplot GetProcessedFilenames;PLplot GetVPRtows;', ...
          'ListboxTop',0, ...
          'Position',[0.4610 0.7985 0.12 0.0401], ...
          'String',cruisearray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sz+1, ...
          'min',1, ...
          'horizontalalignment','left', ...
          'Style','popupmenu', ...
          'Tag','PopupMenu Cruise', ...
          'TooltipString','Select Cruise', ...
          'Value',1);
  end
end
%           'Callback','PLplot GetVPRlogFilenames;PLplot GetProcessedFilenames;PLplot GetVPRtows;', ...

function GetVPRtows
h=gcbf;
if ~isempty(h)
  %delete existing VPRlogFile popup
  h1=findobj(h,'Tag','PopupMenu VPRtows'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu GetClassifier'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  h1=findobj(h,'Tag','PopupMenu Cruise');
  dummystring=get(h1,'String');v=get(h1,'value');
  cruise=deblank(dummystring(v,:));
  datafiles=dir([basepath, filesep, cruise, filesep,'rois',filesep,'vpr*']);
  datarray=str2mat(datafiles.name);
  sd=size(datarray,1);
  if sd>0,    
     set(findobj(h,'Tag','Radiobutton LoadCTDdatFiles'),'value',0,'visible','on');
     datarray=datarray(1:sd,:);
     datarray=sortrows(datarray);
     datarray=str2mat('VPR #',datarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'ListboxTop',0, ...
          'Position',[0.5 0.7075 0.07 0.0401], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          'horizontalalignment','left', ...
          'min',1, ...
          'Style','popupmenu', ...
          'Tag','PopupMenu VPRtows', ...
          'TooltipString','Select VPR tow number', ...
          'enable','on', ...
          'Value',1);
  end
end

function GetVPRlogFilenames
h=gcbf;
if ~isempty(h)
  %delete existing VPRlogFile popup
  h1=findobj(h,'Tag','PopupMenu VPRlogFiles'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu GetClassifier'); delete(h1);
  set(findobj(h,'Tag','Radiobutton LoadVPRlogFile'),'value',0,'visible','off');
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  h1=findobj(h,'Tag','PopupMenu Cruise');
  dummystring=get(h1,'String');v=get(h1,'value');
  cruise=deblank(dummystring(v,:));
%   datafiles=dir([basepath, filesep, cruise, filesep,'vprlog']);
  datafiles=dir([basepath, filesep, cruise, filesep,'rois',filesep,'vprlog']);
  datarray=str2mat(datafiles.name);
  sd=size(datarray,1);
  if sd>2,    
     set(findobj(h,'Tag','Radiobutton LoadVPRlogFile'),'value',1,'visible','on');
     count=1;
     if strcmp(datarray(1,1),'.'),count=2;end
     if strcmp(datarray(2,1),'.'),count=3;end
     datarray=sortrows(datarray(count:sd,:));
     datarray=str2mat('vprlog file',datarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'ListboxTop',0, ...
          'Position',[0.3345 0.7075 0.13 0.0401], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          'min',1, ...
          'horizontalalignment','left', ...
          'Style','popupmenu', ...
          'Tag','PopupMenu VPRlogFiles', ...
          'TooltipString','Select vprlog data file to plot', ...
          'enable','on', ...
          'Value',1);
  end
end

function GetProcessedFilenames
h=gcbf;
if ~isempty(h)
  %delete existing ProcessedFiles popup
  h1=findobj(h,'Tag','PopupMenu ProcessedFiles'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu GetClassifier'); delete(h1);
  set(findobj(h,'Tag','Radiobutton LoadProcessedSensorData'),'value',0,'visible','off');
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  h1=findobj(h,'Tag','PopupMenu Cruise');
  dummystring=get(h1,'String');v=get(h1,'value');
  cruise=deblank(dummystring(v,:));
  datafiles=dir([basepath, filesep, cruise, filesep,'processed',filesep,'sensordata']);
  datarray=str2mat(datafiles.name);
  sd=size(datarray,1);
  if sd>2,
     set(findobj(h,'Tag','Radiobutton LoadProcessedSensorData'),'value',0,'visible','on');
     count=1;
     if strcmp(datarray(1,1),'.'),count=2;end
     if strcmp(datarray(2,1),'.'),count=3;end
     datarray=sortrows(datarray(count:sd,:));
     datarray=str2mat('Processed File',datarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'ListboxTop',0, ...
          'Position',[0.1345 0.7075 0.1 0.0401], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          'horizontalalignment','left', ...
          'min',1, ...
          'Style','popupmenu', ...
          'Tag','PopupMenu ProcessedFiles', ...
          'TooltipString','Select processed data file to plot', ...
          'enable','off', ...
          'Value',1);
  end
end

function GetClassifier
h=gcbf; 
if ~isempty(h)
  %delete existing GetClassifier popup
  h1=findobj(h,'Tag','PopupMenu GetClassifier'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  h1=findobj(h,'Tag','PopupMenu Cruise');
  dummystring=get(h1,'String');v=get(h1,'value');
  cruise=deblank(dummystring(v,:));
  classifiers=dir([basepath, filesep, cruise, filesep,'clpar\*.mat']);
  datarray=str2mat(classifiers.name);
  sd=size(datarray,1);
  if sd>0,
     datarray=datarray(1:sd,:);
     datarray=sortrows(datarray);
     for j=1:sd,
         k=findstr('.mat',datarray(j,:));
         datarray(j,k:end)=' ';
     end
     datarray=str2mat('Select Classifier',datarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'Callback','PLplot SelectInitialTaxon; PLplot StartViewAutoID', ...
          'ListboxTop',0, ...
          'Position',[0.53 0.2440 0.15 0.0584], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.4, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          'min',1, ...
          'horizontalalignment','left', ...
          'Style','popupmenu', ...
          'Tag','PopupMenu GetClassifier', ...
          'TooltipString','Select classifier', ...
          'Value',1);
  end
end

function SelectInitialTaxon
h=gcbf; 
if ~isempty(h)
  %delete existing SelectInitialTaxon popup
  h1=findobj(h,'Tag','PopupMenu SelectInitialTaxon'); delete(h1);
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  h1=findobj(h,'Tag','PopupMenu Cruise');
  dummystring=get(h1,'String');v=get(h1,'value');
  cruise=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu GetClassifier');
  dummystring=get(h1,'String');v=get(h1,'value');
  classid=deblank(dummystring(v,:));
  eval(['load ',basepath,filesep,cruise,filesep,'clpar',filesep,classid,'.mat']);
  datarray=taxas;
  sd=size(datarray,1);
  if sd>=1,    
     datarray=sortrows(datarray);
     datarray=str2mat('Select Taxon',datarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'ListboxTop',0, ...
          'Position',[0.53 0.20 0.15 0.0584], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.4, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          'horizontalalignment','left', ...
          'min',1, ...
          'Style','popupmenu', ...
          'Tag','PopupMenu SelectInitialTaxon', ...
          'TooltipString','Select Initial Taxon', ...
          'Value',1);
  end
end


function StartViewAutoID
h=gcbf; 
redgreenblue=get(h,'color');
if ~isempty(h)
    h1 = uicontrol('Parent',h, ...  
        'Units','normalized', ...
        'BackgroundColor',[redgreenblue]*1.1, ...
        'Callback','PLviewautoID', ...
        'Position',[0.53 0.16 0.15 0.05], ...
        'String','View AutoID ROIs', ...
        'fontunits','normalized','fontsize',.4, ...
        'FontWeight','normal', ...
        'Style','pushbutton', ...
        'Tag','PushButton PLviewautoID', ...
        'TooltipString','Push to view and/or manually re-sort AutoID ROIs');
end


function PlotData

global classid replotval imdir cruise fn
global HydroXYZval HydroTimeval Flightval Courseplotval Planktonval Processed VPRlog CTDdat CreateDotPlotval SaveSensorDataval LoadBugDataval SaveBugDataval


h=gcbf;
if ~isempty(h)
  h1=findobj(h,'Tag','PopupMenu Disc');
  dummystring=get(h1,'String');v=get(h1,'value');
  disc=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu Folder');
  dummystring=get(h1,'String');v=get(h1,'value');
  folder=deblank(dummystring(v,:));
  basepath=[disc folder];
  h1=findobj(h,'Tag','PopupMenu Cruise');
  dummystring=get(h1,'String');v=get(h1,'value');
  cruise=deblank(dummystring(v,:));
  Processed=get(findobj(gcbf,'Tag','Radiobutton LoadProcessedSensorData'),'value');
  VPRlog=get(findobj(gcbf,'Tag','Radiobutton LoadVPRlogFile'),'value');
  CTDdat=get(findobj(gcbf,'Tag','Radiobutton LoadCTDdatFiles'),'value');

  if Processed,
      h1=findobj(h,'Tag','PopupMenu ProcessedFiles');
      dummystring=get(h1,'String');v=get(h1,'value');
  elseif VPRlog,
      h1=findobj(h,'Tag','PopupMenu VPRlogFiles');
      dummystring=get(h1,'String');v=get(h1,'value');
  elseif CTDdat,
      h1=findobj(h,'Tag','PopupMenu VPRtows');
      dummystring=get(h1,'String');v=get(h1,'value');
  end
  fn=deblank(dummystring(v,:));
%   imdir=[deblank(basepath) filesep deblank(cruise) filesep 'vprlog' filesep];
  imdir=[deblank(basepath) filesep deblank(cruise) filesep 'rois' filesep 'vprlog' filesep];
  h1=findobj(h,'Tag','Checkbox HydroXYZ');
   HydroXYZval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox HydroTime');
   HydroTimeval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox Flight');
   Flightval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox Courseplot');
   Courseplotval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox Plankton');
   Planktonval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox SaveSensorData');
   SaveSensorDataval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox LoadBugData');
   LoadBugDataval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox SaveBugData');
   SaveBugDataval=get(h1,'value');
  h1=findobj(h,'Tag','Radiobutton CreateDotPlot');
   CreateDotPlotval=get(h1,'value');
  h1=findobj(h,'Tag','PopupMenu GetClassifier');
  dummystring=get(h1,'String');v=get(h1,'value');
  classid=deblank(dummystring(v,:));
  h1=findobj(h,'Tag','PopupMenu ReplotVal');
   replotindx=get(h1,'value');replotarray=[-1,30,60,120];
   replotval=replotarray(replotindx);
   eval(['cd ..' filesep 'vpraq']);
   plotflag=1;save plotflag plotflag;
   vpraqparsedplot;
   eval(['cd ..' filesep 'mygui']);
end

function PlotTriplet(fig)
if nargin<1,
	h=gcbf;
else
	h=fig;
end;
if ~isempty(h)
   eval(['cd ..' filesep 'vpraq']);
   vpraqparsedplottriplet(1,1,h);
   eval(['cd ..' filesep 'mygui']);
end