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.258 0.213 0.548], ...
	'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.6581 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','plot_help', ...
	'fontunits','normalized','fontsize',.3, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.7433 0.5000 0.1150 0.0773], ...
	'String','HELP', ...
    'Style','pushbutton', ...
	'Tag','Pushbutton Help', ...
	'TooltipString','Help for Plotting');
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.2, ...
	'Callback','close(gcbf)', ...
	'fontunits','normalized','fontsize',.3, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.7447 0.3385 0.1136 0.0790], ...
    '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.450 0.21 0.058], ...
	'String','Hydro vs Time and Depth', ...
	'Style','checkbox', ...
	'Tag','Checkbox HydroTimeDepth', ...
	'TooltipString',['Six separate 2-D plots (dot or curtain) of' char(10) ...
    'Salinity, Temperature, Density, Attenuation'...
      char(10) 'Fluorescence, Light versus Time 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.450 0.21 0.058], ...
% 	'String','3D Hydrography', ...
% 	'Style','checkbox', ...
% 	'Tag','Checkbox HydroXYZ', ...
% 	'TooltipString',['Six separate 3-D plots (dot or curtain) of Salinity, Temperature, Density, Attenuation'...
%       char(10) 'Fluorescence, Light 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.375 0.242 0.058], ...
	'String','Hydro vs Time', ...
	'Style','checkbox', ...
	'Tag','Checkbox HydroTime', ...
   'TooltipString',['Six Panel Plot of Salinity, Temperature, Density'...
      char(10) 'Attenuation, Fluorescence, Light vs Time'], ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','normalized', ...
	'BackgroundColor',[redgreenblue]*1.1, ...
	'fontunits','normalized','fontsize',.4, ...
	'FontWeight','normal', ...
	'ListboxTop',0, ...
	'Position',[0.14 0.307 0.154 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'], ...
    'enable','off',...
	'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.44 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.385 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 VPRtows''),''enable'',''off'');' ...
                'set(findobj(gcbf,''Tag'',''Radiobutton LoadCTDdatFiles''),''value'',0);' ...
                '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 VPRtows''),''enable'',''off'');' ...
                'set(findobj(gcbf,''Tag'',''Radiobutton LoadCTDdatFiles''),''value'',0);' ...
                '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',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'',''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.295 0.307 0.22 0.05], ...
	'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.295 0.244 0.22 0.05], ...
	'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.295 0.177 0.22 0.05], ...
	'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.1770 0.15 0.0584], ...
	'String','Ship Track', ...
	'Style','checkbox', ...
	'Tag','Checkbox Courseplot', ...
	'TooltipString','2-D plot of ship track', ...
    'enable','off',...
	'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.2440 0.1 0.0584], ...
	'String','Plankton', ...
	'Style','checkbox', ...
	'Tag','Checkbox Plankton', ...
	'TooltipString',['Plots plankton abundance versus time and depth' char(10)...
    'as curtain or dot plots.  Allows selection of taxon.']);
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,    
     folderarray=sortrows(lower(folderarray(3: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, ...
          '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',0,'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=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, ...
          'Style','popupmenu', ...
          'Tag','PopupMenu Cruise', ...
          'TooltipString','Select Cruise', ...
          'Value',1);
  end
end

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.075 0.0401], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          'min',1, ...
          'Style','popupmenu', ...
          'Tag','PopupMenu VPRtows', ...
          'TooltipString','Select VPR tow number', ...
          'enable','off', ...
          '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']);
  datarray=str2mat(datafiles.name);
  sd=size(datarray,1);
  if sd>2,    
     set(findobj(h,'Tag','Radiobutton LoadVPRlogFile'),'value',0,'visible','on');
     datarray=datarray(3:sd,:);
     datarray=sortrows(datarray);
     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, ...
          'Style','popupmenu', ...
          'Tag','PopupMenu VPRlogFiles', ...
          'TooltipString','Select vprlog data file to plot', ...
          'enable','off', ...
          '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');
     datarray=datarray(3:sd,:);
     datarray=sortrows(datarray);
     datarray=str2mat('Processed File',datarray);
     h1 = uicontrol('Parent',h, ...  
          'Units','normalized', ...
          'BackgroundColor',[1 1 1], ...
          'ListboxTop',0, ...
          'Position',[0.1345 0.7075 0.14 0.0401], ...
          'String',datarray, ...
	      'fontunits','normalized','fontsize',.6, ...
	      'FontWeight','normal', ...
          'max',sd, ...
          '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, ...
          '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, ...
          '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 HydroTimeDepthval 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];
%   h1=findobj(h,'Tag','Checkbox HydroXYZ');
%    HydroXYZval=get(h1,'value');
  h1=findobj(h,'Tag','Checkbox HydroTimeDepth');
   HydroTimeDepthval=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');
  CreateDotPlotval=1;
  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);
   cd ..\vpraq
   plotflag=1;save plotflag plotflag;
   vpraqparsedplot;
end
