function []=vpraqparsedplottriplet(plotinit,plotflag,h_opts)

global az el plotnames limn plotnow taxaplot
global basepathcruise b b_column_headings b_full classid nxgrd nygrd imdir cruise replotval repeat fn fhc lims

%Initialize (moved to reduce the number of global variables
h1=findobj(h_opts,'Tag','PopupMenu Disc');
dummystring=get(h1,'String');v=get(h1,'value');
disc=deblank(dummystring(v,:));
h1=findobj(h_opts,'Tag','PopupMenu Folder');
dummystring=get(h1,'String');v=get(h1,'value');
folder=deblank(dummystring(v,:));
basepath=[disc folder];
h1=findobj(h_opts,'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(h_opts,'Tag','Radiobutton LoadVPRlogFile'),'value');
CTDdat=get(findobj(h_opts,'Tag','Radiobutton LoadCTDdatFiles'),'value');
if Processed,
	h1=findobj(h_opts,'Tag','PopupMenu ProcessedFiles');
	dummystring=get(h1,'String');v=get(h1,'value');
elseif VPRlog,
	h1=findobj(h_opts,'Tag','PopupMenu VPRlogFiles');
	dummystring=get(h1,'String');v=get(h1,'value');
elseif CTDdat,
	h1=findobj(h_opts,'Tag','PopupMenu VPRtows');
	dummystring=get(h1,'String');v=get(h1,'value');
end
fn=deblank(dummystring(v,:));
basepathcruise=[deblank(basepath) filesep deblank(cruise)];
imdir=[deblank(basepath) filesep deblank(cruise) filesep 'rois' filesep 'vprlog' filesep];
h1=findobj(h_opts,'Tag','Checkbox HydroXYZ');
HydroXYZval=get(h1,'value');
h1=findobj(h_opts,'Tag','Checkbox HydroTime');
HydroTimeval=get(h1,'value');
h1=findobj(h_opts,'Tag','Checkbox Flight');
Flightval=get(h1,'value');
h1=findobj(h_opts,'Tag','Checkbox Courseplot');
Courseplotval=get(h1,'value');
h1=findobj(h_opts,'Tag','Checkbox Plankton');
Planktonval=get(h1,'value');
if Planktonval
    h1=findobj(h_opts,'Tag','PopupMenu VPRtows');
	dummystring=get(h1,'String');v=get(h1,'value');
    vprnum=deblank(dummystring(v,:));
    h1=findobj(h_opts,'Tag','PopupMenu GetClassifier');
    dummystring=get(h1,'String');v=get(h1,'value');
    classid=deblank(dummystring(v,:));
    taxa=cell2mat(struct2cell(load([basepathcruise filesep 'clpar' filesep classid])));
    roidir=[imdir(1:end-7) vprnum filesep];
    taxaplot=zeros(size(taxa,1),1);
    h1=findobj(h_opts,'Tag','Checkbox LoadBugData');
    LoadBugDataval=get(h1,'value');
    h1=findobj(h_opts,'Tag','Checkbox SaveBugData');
    SaveBugDataval=get(h1,'value');
end 
h1=findobj(h_opts,'Tag','Checkbox SaveSensorData');
SaveSensorDataval=get(h1,'value');
h1=findobj(h_opts,'Tag','Radiobutton CreateDotPlot');
CreateDotPlotval=get(h1,'value');
h1=findobj(h_opts,'Tag','PopupMenu ReplotVal');
replotindx=get(h1,'value');replotarray=[-1,30,60,120];
replotval=replotarray(replotindx);

%Variables to plot (change here, not elsewhere, if you add variables)
plotnames={'Temperature',5,'\bf Temperature \rm(^oC)';...
           'Salinity',6,'\bf Salinity';...
           'Density',7,'\bf Density \rm(\sigma_t)';...
           'Fluorescence',8,'\bf Fluorescence \rm(\mug chlorophyll a / liter)';...
           'Optical Backscatter',9,'\bf Optical Backscatter \rm(Nephelometric Units)';...
           'Oxygen',12,'\bf Oxygen \rm(ml/l)';...
           'Light',10,'\bf PAR'};
if strcmp(fn(1:5),'REMUS')%REMUS data
    plotnames(end,:)={'Nitrate',10,'\bf Nitrate'};%If I remember correctly, I always fixed the plots manually. Now I wouldn't need to.
elseif strcmp(fn(end-5:end),'.combo')%ECO Triplet Data
plotnames(size(plotnames,1)+1:size(plotnames,1)+3,:)= ...
           {'ECO Triplet Bb',16,'\bf ECO Total Backscattering Coefficient b_b(\lambda) \rm(m^{-1})';...
           'ECO Triplet Chl',17,'\bf ECO Triplet Chlorophyll \rm(\mug/L)';...
           'ECO Triplet CDOM',18,'\bf CDOM \rm(ppb)'};
end
plotnames_orig=plotnames;%Orig suffix is so that plankton can be included during the loop.

%Set Initial az, el
az=10;
el=30;
save azel az el;%Might not be necessary anymore.
colordef none %The magic line that sets the background black
redgreenblue=[0.2157 .6353 .6353]*1.2;

while (plotflag)
    
    if Processed,%load processed physical data
        eval(['load ' basepathcruise '\processed\sensordata\' fn]);
    elseif strcmp(fn(1:5),'REMUS')
        load([imdir filesep fn]);
        if exist('vprlogmerged'),vprlog=vprlogmerged;end
        b=vprlog;
        b(:,4)=-b(:,4);
        b_full=b;
        if plotinit
            limnbcol=cell2mat(plotnames(:,2))';
            showalldata;
        end
    elseif VPRlog,%load vprlog data
        eval(['fid=fopen(''' imdir fn ''');']);
        lineone=fgets(fid);fclose(fid);
        if lineone(5)==':',
            getprepdata_bobparse(imdir,cruise,fn);
        elseif strcmp(fn(end-5:end),'.combo')%Check if it is a ECO Triplet Combined File
        	getprepdata_newfish_triplet(imdir,cruise,fn);
            b_full=b;
        else
        	getprepdata_newfish(imdir,cruise,fn);
        	b_full=b;
        end
        if plotinit,
            PLplotsetup
            waitfor(fhc);% wait until the data limits figure is closed
            plotnow=0;
            limn=str2num(lims(:,4:end));
            limnbcol=cell2mat(plotnames(:,2))';
            limn=[limn(4:8,:);0,0;limn(9,:)];
            if length(limnbcol)==7
                limn(6,:)=[mean(b(:,12))-4*std(b(:,12)),mean(b(:,12))+4*std(b(:,12))];
            elseif length(limnbcol)>7
                for j=[6,8:length(limnbcol)]
                    limn(j,:)=[mean(b(:,cell2mat(plotnames(j,2))))-4*std(b(:,cell2mat(plotnames(j,2)))),mean(b(:,cell2mat(plotnames(j,2))))+4*std(b(:,cell2mat(plotnames(j,2))))];
                end
            end
            if replotval==-1;
                limn=[max([min(b_full(:,limnbcol))-0.25*std(b_full(:,limnbcol));limn(:,1)'])',min([max(b_full(:,limnbcol))+0.25*std(b_full(:,limnbcol));limn(:,2)'])'];
            end
            plotinit=0;
        end
        for j=1:size(limn,1),b=b((b(:,limnbcol(j))>=limn(j,1)&b(:,limnbcol(j))<=limn(j,2)),:); end%crops rows in b that are outside limits
        [totkm,af,ar]=dist(b(:,2),b(:,3)); totkm=[0 totkm/1000];totkm=cumsum(totkm)';
        %b=[b totkm];
        b_column_headings=str2mat(b_column_headings,'16 distance       cumulative distance traveled by ship during tow, in km');
        if SaveSensorDataval,%save processed data
            b=b_full;%Include All Data in export
            if exist([basepathcruise '\processed\sensordata'],'dir')~=7,
                dos(['mkdir ' basepathcruise '\processed\sensordata']);
            end
            fn=strrep(fn,'.','_');%replaces all '.' with '_' so fn will save as .mat file    
            eval(['save ' basepathcruise '\processed\sensordata\' fn ' b b_column_headings lims']);
            fn=strrep(fn,'_','.');%Revert filename change
            for j=1:size(limn,1),b=b((b(:,limnbcol(j))>=limn(j,1)&b(:,limnbcol(j))<=limn(j,2)),:); end%crops rows in b that are outside limits
        end
    elseif CTDdat,
        b=ReadparseCTDdatFiles(basepathcruise,fn);
    end
    
   	if Planktonval,
        
        pause(1);
        %Get Taxa List
        h=findobj('tag','Plankton Taxa List');
        %Make Plankton Taxa List Graphic   
        if isempty(h),figure('tag','Plankton Taxa List'),h=findobj('tag','Plankton Taxa List');else,figure(h),load azel;end;clf;
        set(h,'units','normalized','position',[0.1 0.075 0.8 0.8]);
        set(h,'numbertitle','off','name',['Plankton Taxa List :  ' cruise '  ' vprnum '  ' classid]);
        days=dir([roidir 'd*']);
        taxanum=zeros(size(taxa,1),1);
        for i=1:size(days,1)
            hours=dir([roidir days(i).name filesep 'h*']);
            for j=1:size(hours,1)
                for k=1:size(taxa,1)
                    taxonstr=[imdir(1:end-12) 'autoid' filesep deblank(taxa(k,:)) filesep 'aid' filesep classid 'aid.' days(i).name '.' hours(j).name];
                    if exist(taxonstr,'file')
                        d=dir(taxonstr);
                        if d.bytes~=0;
                            imfiles=loadname(taxonstr);
                            taxanum(k,1)=taxanum(k,1)+size(imfiles,1);
                        end
                    end
                end
            end
        end
        h1 = uicontrol('Parent',h, ...
            'Units','normalized', ...
            'ForegroundColor',[redgreenblue]*1.1, ...
            'BackgroundColor','k', ...
            'fontunits','normalized','fontsize',.6, ...
            'FontWeight','normal', ... 
            'ListboxTop',0, ...
            'HorizontalAlignment','left', ...
            'Position',[0.05 0.92 0.35 0.0602], ...
            'String',['ROIs Classified for ' vprnum ':'], ...
            'Style','text', ...
            'Tag','StaticText Taxa Title', ...
            'TooltipString','List of Taxa Supported by the Current Classifier:');
        h1=uicontrol('Parent',h, ...
            'Units','normalized', ...
            'BackgroundColor',[redgreenblue]*1.1, ...
            'fontunits','normalized','fontsize',.6, ...
            'FontWeight','normal', ... 
            'ListboxTop',0, ...
            'Position',[0.7 0.06 0.25 0.05], ...
            'Style','pushbutton', ...
            'String','Replot Now', ...
            'TooltipString',['Use to replot all graphs to reflect' char(10) 'included/excluded plankton taxa.'], ...
            'Tag','Pushbutton Update Taxa List', ... 
            'Callback','global plotnow repeat replotval plotnames;repeat=1;plotnow=1;if replotval==-1,for i=1:size(plotnames,1),close(findobj(''Tag'',cell2mat(plotnames(i,1))));end,close(findobj(''Tag'',''plot composite''));close(findobj(''Tag'',''Plankton Taxa List''));end');
        h1=uicontrol('Parent',h, ...
            'Units','normalized', ...
            'BackgroundColor',[redgreenblue]*1.1, ...
            'fontunits','normalized','fontsize',.6, ...
            'FontWeight','normal', ... 
            'ListboxTop',0, ...
            'Position',[0.7 0.005 0.25 0.05], ...
            'Style','pushbutton', ...
            'String','Close and Exit', ...
            'TooltipString',['Use to close graphs and stop replotting.'], ...
            'Tag','Pushbutton Exit Taxa List', ... 
            'Callback','global replotval plotnames;replotval=-1;for i=1:size(plotnames,1),close(findobj(''Tag'',cell2mat(plotnames(i,1))));end;close(findobj(''Tag'',''plot composite''));close(findobj(''Tag'',''Plankton Taxa List''));');
                    
        if size(taxa,1)<=45 %Can only hold 45 taxa
            for i=1:size(taxa,1) 
                left=0.35*floor(i/16)+0.05;
                up=0.06*(15-rem(i,16));
                h1 = uicontrol('Parent',h, ...
                    'Units','normalized', ...
                    'ForegroundColor',[redgreenblue]*1.1, ...
                    'BackgroundColor','k', ...
                    'fontunits','normalized','fontsize',.6, ...
                    'FontWeight','normal', ...
                    'ListboxTop',0, ...
                    'Position',[left up 0.30 0.0602], ...
                    'String',['(' int2str(taxanum(i,1)) ') ' deblank(taxa(i,:))], ...
                    'Style','checkbox', ...
                    'Tag',['Checkbox Taxa ' int2str(i)], ...
                    'Callback',['global taxaplot;taxaplot(' int2str(i) ',1)=~taxaplot(' int2str(i) ',1);'], ...
                    'TooltipString',['Click to mark this taxon for plotting.' char(10) 'The number is the number of ROIs classified as this taxa.'], ...
                    'Value',taxaplot(i,1));
            end
        else 
            for i=1:min([size(taxa,1),118]) %Can only hold 118 taxa
                h1=findobj(h,'Tag','StaticText Taxa Title');
                set(h1,'Position',[0 0.92 0.2 0.0452]);
                h1=findobj(h,'Tag','Pushbutton Update Taxa List');
                set(h1,'Position',[0.8 0.04 0.2 0.04]);
                h1=findobj(h,'Tag','Pushbutton Exit Taxa List');
                set(h1,'Position',[0.8 0.0 0.2 0.04]);
                left=0.2*floor(i/24);
                up=0.04*(23-rem(i,24));
                h1 = uicontrol('Parent',h, ...
                    'Units','normalized', ...
                    'ForegroundColor',[redgreenblue]*1.1, ...
                    'BackgroundColor','k', ...
                    'fontunits','normalized','fontsize',.6, ...
                    'FontWeight','normal', ...
                    'ListboxTop',0, ...
                    'Position',[left up 0.2 0.0402], ...
                    'String',['(' int2str(taxanum(i,1)) ') ' deblank(taxa(i,:))], ...
                    'Style','checkbox', ...
                    'Tag',['Checkbox Taxa ' int2str(i)], ...
                    'Callback',['global taxaplot;taxaplot(' int2str(i) ',1)=~taxaplot(' int2str(i) ',1);'], ...
                    'TooltipString',['Click to mark this taxon for plotting.' char(10) 'The number is the number of ROIs classified as this taxa.'], ...
                    'Value',taxaplot(i,1));
            end
        end
        for i=1:size(taxa,1)
            if taxaplot(i,1) & taxanum(i,1)>0
                bugs=realbugplot(deblank(taxa(i,:)),roidir,vprnum,LoadBugDataval,SaveBugDataval);
                b_full(:,end+1)=bugs;
                cleantaxa=deblank(taxa(i,:));
                cleantaxa=strrep(cleantaxa,'_',' ');
                plotnames(size(plotnames,1)+1,:)={cleantaxa,size(b_full,2),['\bf ' cleantaxa ' (#/L)']};
                limnbcol(1,end+1)=size(b_full,2);
                limn(end+1,:)=[0,min([max(bugs);mean(bugs(bugs~=0))+4*std(bugs(bugs~=0))])];
                b=b_full;
                for j=1:size(limn,1),b=b((b(:,limnbcol(j))>=limn(j,1)&b(:,limnbcol(j))<=limn(j,2)),:); end
            end
        end
    end

    latitude=num2str(b(end,2));if(b(end,2)>0),latitude=['  ',latitude];end %Last position for readout
    longitude=num2str(b(end,3));if(b(end,3)>0),longitude=['  ',longitude];end %Last position for readout
    [~,mindepth]=min(abs(b(end-min([500,size(b,1)-1]):end,4)));
    temperature=num2str(b(end-min([501,size(b,1)])+mindepth,5));
    salinity=num2str(b(end-min([501,size(b,1)])+mindepth,6));
    lattext=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.5,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.15 0.95 0.15 0.0401],''String'',''Latitude:   ' latitude ''',''Style'',''text'',''Tag'',''StaticText Latitude'');'];
    lontext=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.5,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.35 0.95 0.15 0.0401],''String'',''Longitude: ' longitude ''',''Style'',''text'',''Tag'',''StaticText Longitude'');'];
    temptext=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.5,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.54 0.95 0.25 0.0401],''String'',''Min Depth Temperature: ' temperature ''',''Style'',''text'',''Tag'',''StaticText Temperature'');'];
    saltext=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.5,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.79 0.95 0.21 0.0401],''String'',''Min Depth Salinity: ' salinity ''',''Style'',''text'',''Tag'',''StaticText Salinity'');'];
    %Overwrite lims to custom range
    titletext='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.10 0.22 0.0401],''String'',''Set new colorbar limits:'',''Style'',''text'',''Tag'',''StaticText limntitle'',''TooltipString'',[''Enter new colorbar minimum'' char(10) ''and maximum values,'' char(10) ''then press update'']);';
    maxtext='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.17 0.06 0.15 0.0401],''String'',''Maximum Value:'',''Style'',''text'',''Tag'',''StaticText limnmax'',''TooltipString'',[''Enter new colorbar minimum'' char(10) ''and maximum values,'' char(10) ''then press update'']);';
    mintext='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.06 0.15 0.0401],''String'',''Minimum Value:'',''Style'',''text'',''Tag'',''StaticText limnmin'',''TooltipString'',[''Enter new colorbar minimum'' char(10) ''and maximum values,'' char(10) ''then press update'']);';
    maxbox='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[1 1 1],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''Position'',[0.17 0.02 0.15 0.0401],''Style'',''edit'',''TooltipString'',[''Enter new colorbar minimum'' char(10) ''and maximum values,'' char(10) ''then press update''],''Tag'',''Edittext maxlimn';
    minbox='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[1 1 1],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''Position'',[0.01 0.02 0.15 0.0401],''Style'',''edit'',''TooltipString'',[''Enter new colorbar minimum'' char(10) ''and maximum values,'' char(10) ''then press update''],''Tag'',''Edittext minlimn';
    maxminbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.33 0.01 0.17 0.055],''Style'',''pushbutton'',''String'',''Data Min/Max Values'',''TooltipString'',[''Change listed minimum and maximum values'' char(10) ''to the minimum and maximum values in the data.'' char(10) '' '' char(10) ''This button does not update any plots, it just'' char(10) ''adjusts the typed values.''],''Tag'',''Pushbutton UpdateValues';
    updatenowbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.51 0.01 0.15 0.055],''Style'',''pushbutton'',''String'',''Change and Replot'',''TooltipString'',[''Click to change colorbar minimum and maximum '' char(10) ''values to the listed minimum and maximum values'' char(10) ''and replot.''],''Tag'',''Pushbutton UpdatePlotsNow';
    showallbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.67 0.01 0.15 0.055],''Style'',''pushbutton'',''String'',''Show All Data'',''TooltipString'',[''Click to show all data (except extreme values).'' char(10) ''Extreme values are outside of +/- 15 std from the mean.'' char(10) '' '' char(10) ''This rescales and replots all plots.''],''Callback'',''showalldata;'',''Tag'',''Pushbutton ShowAllData';
    exitbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.83 0.01 0.15 0.055],''Style'',''pushbutton'',''String'',''Close and Exit'',''TooltipString'',[''Use to close graphs and stop replotting.''],''Tag'',''Pushbutton Exit';
    [nxgrd,nygrd]=gridsize(b(:,4));
    if HydroXYZval,
        for i=1:size(plotnames,1)
            pause(1);
            h=findobj('tag',cell2mat(plotnames(i,1)));
            if isempty(h),figure('tag',cell2mat(plotnames(i,1))),h=findobj('tag',cell2mat(plotnames(i,1)));else,figure(h),load azel;end;clf;
            set(h,'units','normalized','position',[0.1 0.075 0.8 0.8]);
            ah=subplot(335);set(ah,'position',[.2 .15 .7 .7]);
            if CreateDotPlotval,cbaroutput=xyz_colordotplot_cbaroutput([b(:,3),b(:,2),b(:,4),b(:,cell2mat(plotnames(i,2)))],16,'jet',limn(i,:));else,curtain3(b,nxgrd,nygrd,1,az,el,h);end
            title(cell2mat(plotnames(i,3)),'fontsize',14);
            set(h,'numbertitle','off','name',cell2mat(plotnames(i,1)));
            cbar=colorbar;ylabel(cbar,cell2mat(plotnames(i,1)));
            set(cbar,'Color',[1 1 1]);caxis(cbaroutput);
            set(gca,'dataaspectratio',[1 1 500]);axissnug;
            cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
            eval([lattext,lontext,temptext,saltext,titletext,maxtext,mintext]);
            eval([showallbutton,int2str(i),''');']);
            eval([[maxbox,int2str(i),''',''String'',''' num2str(limn(i,2)) ''');'],[minbox,int2str(i),''',''String'',''' num2str(limn(i,1)) ''');']])
            eval([maxminbutton,int2str(i),''',''Callback'',''updateminmax(',int2str(i),',',int2str(cell2mat(plotnames(i,2))),');'');'])
            eval([updatenowbutton,int2str(i),''',''Callback'',''updateresultplots(',int2str(i),');'');'])
            eval([exitbutton,int2str(i),''',''Callback'',[''global replotval plotnames;replotval=-1;for i=1:size(plotnames,1),close(findobj(''''Tag'''',cell2mat(plotnames(i,1))));end;close(findobj(''''Tag'''',''''plot composite''''));close(findobj(''''Tag'''',''''Plankton Taxa List''''));'']);'])
        end
    end
    if HydroTimeval,
        pause(1);
        h=findobj('tag','plot env');if isempty(h),figure('tag','plot env'),h=findobj('tag','plot env');else,figure(h),end;clf;
        set(h,'numbertitle','off','name','Environmental Data');
        set(h,'units','normalized','position',[0.1 0.075 0.8 0.8])
        clf;
        vpraqplotctdftlt(b(:,1),b(:,5),b(:,6),b(:,7),b(:,8),b(:,9),b(:,10));
    end;
    if Flightval,
        pause(1);
        h=findobj('tag','plot flight');if isempty(h),figure('tag','plot flight'),h=findobj('tag','plot flight');else,figure(h),end;clf;
        set(h,'numbertitle','off','name','Flight Control Data');
        set(h,'units','normalized','position',[0.1 0.075 0.8 0.8])
        clf;
        vpraqplotsrpaz(b(:,1),b(:,4),b(:,11),b(:,12),b(:,13),b(:,14),b(:,15));
    end;
    if Courseplotval, 
        pause(1);
        h=findobj('tag','plot course');if isempty(h),figure('tag','plot course'),h=findobj('tag','plot course');else,figure(h),end;clf;
        set(h,'numbertitle','off','name','Courseplot');
        set(h,'units','normalized','position',[0.1 0.075 0.8 0.8])
        clf;
        courseplot(b(:,1),b(:,2),b(:,3));

    end
    
    pause(1);
    h=findobj('tag','plot composite');if isempty(h),figure('tag','plot composite'),h=findobj('tag','plot composite');else,figure(h),load azel;end;clf;
    if CreateDotPlotval,
        set(h,'numbertitle','off','name','Composite: Sal, Temp, Dens, Fluor');
        set(h,'units','normalized','position',[0.1 0.075 0.8 0.8]);     
        subplot(221)
        cbaroutput=xyz_colordotplot_cbaroutput([b(:,3),b(:,2),b(:,4),b(:,5)],16,'jet',limn(1,:));
        cbar=colorbar;ylabel(cbar,'Temperature');set(cbar,'Color',[1 1 1]);caxis(cbaroutput);
        title('\bf Temperature \rm(^oC)','fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        subplot(222)
        cbaroutput=xyz_colordotplot_cbaroutput([b(:,3),b(:,2),b(:,4),b(:,6)],16,'jet',limn(2,:));
        cbar=colorbar;ylabel(cbar,'Salinity');set(cbar,'Color',[1 1 1]);caxis(cbaroutput);
        title('\bf Salinity','fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        subplot(223)
        cbaroutput=xyz_colordotplot_cbaroutput([b(:,3),b(:,2),b(:,4),b(:,7)],16,'jet',limn(3,:));
        cbar=colorbar;ylabel(cbar,'Density');set(cbar,'Color',[1 1 1]);caxis(cbaroutput);
        title('\bf Density \rm(\sigma_t)','fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        subplot(224)
        cbaroutput=xyz_colordotplot_cbaroutput([b(:,3),b(:,2),b(:,4),b(:,8)],16,'jet',limn(4,:));
        cbar=colorbar;ylabel(cbar,'Fluorescence');set(cbar,'Color',[1 1 1]);caxis(cbaroutput);
        title('\bf Fluorescence \rm(\mug chlorophyll a / liter)','fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        eval([lattext,lontext,temptext,saltext])
        eval([showallbutton,' composite'');']);
        eval([exitbutton,'Composite'',''Callback'',[''global replotval plotnames;replotval=-1;for i=1:size(plotnames,1),close(findobj(''''Tag'''',cell2mat(plotnames(i,1))));end;close(findobj(''''Tag'''',''''plot composite''''));close(findobj(''''Tag'''',''''Plankton Taxa List''''));'']);'])
    end

    if replotval==-1;
        repeat=0;
        for i=1:size(plotnames,1)
            %Wait until all figures are closed.
            waitfor(findobj('Tag',cell2mat(plotnames(i,1))));
        end
        if ~repeat
            plotflag=0;
            save plotflag plotflag;
        end
    else
        waittime=0;
        while waittime<replotval && plotnow==0 % pause for replotval seconds before repeating plotting sequence
            waittime=waittime+1;
            pause(1)
            if rem(waittime,5)==0
                for i=1:size(plotnames,1)+1
                    if i>size(plotnames,1),h=findobj('Tag','plot composite');
                    else,h=findobj('Tag',cell2mat(plotnames(i,1)));end
                    h1 = uicontrol('Parent',h, ...
                        'Units','normalized', ...
                        'ForegroundColor',[redgreenblue]*1.1, ...
                        'BackgroundColor','k', ...
                        'fontunits','normalized','fontsize',.7, ...
                        'FontWeight','normal', ...
                        'ListboxTop',0, ...
                        'Position',[0.01 0.95 0.1 0.0401], ...
                        'String',int2str(waittime), ...
                        'horizontalalignment','left', ...
                        'Style','text', ...
                        'Tag','StaticText Folder', ...
                        'TooltipString','Time since last plotting.');
                end
            end
        end
        plotnow=0;
        if replotval==-1;
            for i=1:size(plotnames,1)
                %Wait until all figures are closed.
                waitfor(findobj('Tag',cell2mat(plotnames(i,1))));
                plotflag=0;
            end
        end
    end
	%Reset all values to prepare to reacquire data
	plotnames=plotnames_orig;
	limnbcol=limnbcol(1:size(plotnames,1));
	limn=limn(1:size(plotnames,1),:);
	b_full=b_full(:,1:max(limnbcol));
    %Close all plots to hopefully prevent memory limit crash
    for i=1:size(plotnames,1),close(findobj('Tag',cell2mat(plotnames(i,1))));end;close(findobj('Tag','plot composite'));close(findobj('Tag','Plankton Taxa List'));
end; %while
