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

global az el plotnames limn plotnow taxaplot toggle aspect dar
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 plotTS');
TSval=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);
toggle=1;

%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 TSval
    plotnames(size(plotnames,1)+1,:)={'Latitude',2,'\bf Latitude \rm(m)'};
    plotnames(size(plotnames,1)+1,:)={'Longitude',3,'\bf Longitude \rm(m)'};
    plotnames(size(plotnames,1)+1,:)={'Depth',4,'\bf Depth \rm(m)'};
end
if strcmp(fn(1:5),'REMUS')%REMUS data
    plotnames(end-1,2)={10};
    plotnames(end,:)={'Nitrate',11,'\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;
cjet=jet(64);%For colorbar colors
aspect=[17,30,1];

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;
            plotinit=0;
        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
            if toggle==2,error('Cancelled by user.');end %Implemented so the cancel line actually cancels ploting.
            b=b_full;%Keep limits from setup, but reset data.
            plotnow=0;
            limn=str2num(lims(:,4:end));
            geolimn=limn(1:3,:);%Separate out Lat/Long/Depth Limns. Only gate if data is actually removed.
            for j=1:size(geolimn,1),if(geolimn(j,2)-geolimn(j,1)<10e-10),geolimn(j,1)=geolimn(j,1)-1;geolimn(j,2)=geolimn(j,2)+1;end,end%Included to not exclude fringe cases on startup
            if geolimn(1)<min(b(:,2)),geolimn(1)=NaN;end
            if geolimn(4)>max(b(:,2)),geolimn(4)=NaN;end
            if geolimn(2)<min(b(:,3)),geolimn(2)=NaN;end
            if geolimn(5)>max(b(:,3)),geolimn(5)=NaN;end
            if geolimn(3)<min(b(:,4)),geolimn(3)=NaN;end
            if geolimn(6)>max(b(:,4)),geolimn(6)=NaN;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
        %Geographical Limits (Only changes when data is removed in initial setup.
        if ~isnan(geolimn(1)),for j=1:size(limn,1),b=b((b(:,2)>=geolimn(1)),:);end,end
        if ~isnan(geolimn(4)),for j=1:size(limn,1),b=b((b(:,2)<=geolimn(4)),:);end,end
        if ~isnan(geolimn(2)),for j=1:size(limn,1),b=b((b(:,3)>=geolimn(2)),:);end,end
        if ~isnan(geolimn(5)),for j=1:size(limn,1),b=b((b(:,3)<=geolimn(5)),:);end,end
        if ~isnan(geolimn(3)),for j=1:size(limn,1),b=b((b(:,4)>=geolimn(3)),:);end,end
        if ~isnan(geolimn(6)),for j=1:size(limn,1),b=b((b(:,4)<=geolimn(6)),:);end,end
        %Parameter Limits
        for j=1:size(limn,1),if(limn(j,2)-limn(j,1)<1e-10),limn(j,1)=limn(j,1)-1;limn(j,2)=limn(j,2)+1;end,end%Included to not exclude fringe cases on startup
        if ~toggle,for j=1:size(limn,1),b=b((b(:,limnbcol(j))>=limn(j,1)&b(:,limnbcol(j))<=limn(j,2)),:);end,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
            if ~toggle,for j=1:size(limn,1),b=b((b(:,limnbcol(j))>=limn(j,1)&b(:,limnbcol(j))<=limn(j,2)),:);end,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 repeat plotnow;repeat=1;plotnow=1;closeplots;');
        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','closeplots;');
                    
        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
        tc=0;%taxa count
        for i=1:size(taxa,1)
            if taxaplot(i,1) & taxanum(i,1)>0
                tc=tc+1;
                bugs=realbugplot(deblank(taxa(i,:)),roidir,vprnum,LoadBugDataval,SaveBugDataval);
                b_full(:,end+1)=bugs;
                cleantaxa=deblank(taxa(i,:));
                cleantaxa=strrep(cleantaxa,'_',' ');
                if size(plotnames,1)>=size(plotnames_orig,1)+tc 
                    if ~strcmp(plotnames(size(plotnames_orig,1)+tc,1),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))])];
                    end
                else%Catch for taxa initialization
                    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))])];
                end
                b=b_full;
            end
        end
        %Truncate taxa that no longer are used
        plotnames=plotnames(1:size(plotnames_orig,1)+tc,:);
        limnbcol=limnbcol(1:size(plotnames,1));
        limn=limn(1:size(plotnames,1),:);
        %Put back in limits
        if ~isnan(geolimn(1)),for j=1:size(limn,1),b=b((b(:,2)>=geolimn(1)),:);end,end
        if ~isnan(geolimn(4)),for j=1:size(limn,1),b=b((b(:,2)<=geolimn(4)),:);end,end
        if ~isnan(geolimn(2)),for j=1:size(limn,1),b=b((b(:,3)>=geolimn(2)),:);end,end
        if ~isnan(geolimn(5)),for j=1:size(limn,1),b=b((b(:,3)<=geolimn(5)),:);end,end
        if ~isnan(geolimn(3)),for j=1:size(limn,1),b=b((b(:,4)>=geolimn(3)),:);end,end
        if ~isnan(geolimn(6)),for j=1:size(limn,1),b=b((b(:,4)<=geolimn(6)),:);end,end
        if ~toggle,for j=1:size(limn,1),b=b((b(:,limnbcol(j))>=limn(j,1)&b(:,limnbcol(j))<=limn(j,2)),:);end,end
    end

    latitude=num2str(b(end,2));latitude=['  ',latitude]; %Last position for readout
    longitude=num2str(b(end,3));longitude=['  ',longitude]; %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'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.25 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'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.40 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'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.55 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'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.80 0.95 0.20 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.15 0.0401],''horizontalalignment'',''left'',''String'',''Set New Limit Values:'',''Style'',''text'',''Tag'',''StaticText limntitle'',''TooltipString'',[''Enter new limit 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 limit 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 limit 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 minimum and maximum limit'' 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'',''All Limits = Range'',''TooltipString'',[''Click adjust the limits to match the range of all variables (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';
    toggletxt='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.26 0.2 0.0401],''horizontalalignment'',''left'',''String'',''Toggle Limits:'',''Style'',''text'',''Tag'',''StaticText limntoggletext'',''TooltipString'',[''Set what the limits do by choosing a choice below:'']);';
    toggle1='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.21 0.2 0.0401],''horizontalalignment'',''left'',''String'',''Only Change Colorbar Scale'',''Style'',''radiobutton'',''Tag'',''RadioButton limntoggle1'',''TooltipString'',[''Sets limits to adjust colorbar'' char(10) ''with no data excluded.''],''Callback'',''global toggle;toggle=1;updateresultplots(1);''';%Since I already wrote the code to replot limit changes, just use the first variable.
    toggle0='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.16 0.2 0.0401],''horizontalalignment'',''left'',''String'',''Exclude Data Outside of Limits'',''Style'',''radiobutton'',''Tag'',''RadioButton limntoggle0'',''TooltipString'',[''Sets limits to adjust data shown'' char(10) ''excluding data outside range.'' char(10) ''Excluded data is absent from ALL plots.''],''Callback'',''global toggle;toggle=0;updateresultplots(1);''';
    saveallbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.83 0.07 0.15 0.055],''Style'',''pushbutton'',''String'',''Save All Plots'',''TooltipString'',[''Use to save all plots as .png in cruise folder.''],''Tag'',''Pushbutton SaveAll';
    % Change View
    viewtxt='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''horizontalalignment'',''left'',''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.95 0.2 0.0401],''String'',''Change Default Perspective:'',''Style'',''text'',''Tag'',''StaticText viewtxt'');';
    xyviewtxt='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''horizontalalignment'',''left'',''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.90 0.16 0.0401],''String'',''XY Plane:'',''Style'',''text'',''Tag'',''StaticText xyviewtxt'',''TooltipString'',[''Change default rotation (XY plane) of plot'' char(10) '' Default value is 17, range is -180 to 180.'']);';
    zviewtxt='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''horizontalalignment'',''left'',''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.85 0.16 0.0401],''String'',''Z Plane:'',''Style'',''text'',''Tag'',''StaticText zviewtxt'',''TooltipString'',[''Change inclination (Z plane) of plot'' char(10) '' Default value is 30, range is -90 to 90.'']);';
    zoomtxt='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''ForegroundColor'',[redgreenblue]*1.1,''BackgroundColor'',[0,0,0],''horizontalalignment'',''left'',''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.80 0.16 0.0401],''String'',''Zoom:'',''Style'',''text'',''Tag'',''StaticText zoomtxt'',''TooltipString'',[''Change magnification of the plot.'' char(10) '' Default value is 1, recommended range is 0.25 to 4.'']);';
    xyviewbox=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[1 1 1],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''Position'',[0.08 0.90 0.09 0.0401],''Style'',''edit'',''TooltipString'',[''Change default rotation (XY plane) of plot'' char(10) '' Default value is 17, range is -180 to 180.''],''String'',''' int2str(aspect(1)) ''',''Tag'',''Edittext xyview'];
    zviewbox=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[1 1 1],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''Position'',[0.08 0.85 0.09 0.0401],''Style'',''edit'',''TooltipString'',[''Change default inclination (Z plane) of plot'' char(10) '' Default value is 30, range is -90 to 90.''],''String'',''' int2str(aspect(2)) ''',''Tag'',''Edittext zview'];
    zoombox=['h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[1 1 1],''fontunits'',''normalized'',''fontsize'',.6,''FontWeight'',''normal'',''Position'',[0.08 0.80 0.09 0.0401],''Style'',''edit'',''TooltipString'',[''Change magnification of the plot.'' char(10) '' Default value is 1, recommended range is 0.25 to 4.''],''String'',''' num2str(aspect(3)) ''',''Tag'',''Edittext zoomview'];
    getviewcoordbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.735 0.16 0.055],''Style'',''pushbutton'',''String'',''Get Current Perspective'',''TooltipString'',[''Click to update boxes above with current XYZ orientation.'' char(10) ''Plots will not update prior to double clicking the button below.''],''Callback'',''global dar;set(gca,''''dataaspectratio'''',dar);pause(0.5);tempview=get(gca,''''View'''');set(gca,''''dataaspectratio'''',[1,1,500]);';
    updateviewbutton='h1=uicontrol(''Parent'',h,''Units'',''normalized'',''BackgroundColor'',[redgreenblue]*1.1,''fontunits'',''normalized'',''fontsize'',.38,''FontWeight'',''normal'',''ListboxTop'',0,''Position'',[0.01 0.665 0.16 0.055],''Style'',''pushbutton'',''String'',''Update Perspective'',''TooltipString'',[''Click to update default plot perspective.'' char(10) ''This rescales and replots all plots.''],''Callback'',''global aspect;';
    
    [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 .75 .7]);
            if CreateDotPlotval && sum(isnan(b(:,cell2mat(plotnames(i,2)))))<size(b,1)-10
                crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
                c=ones(size(b,1),3);
                for j=1:64%Set colors for scatter3
                    if j==1
                        num=find(b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
                    elseif j==64
                        num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j));
                    else
                        num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j) & b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
                    end
                    c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
                    clear num
                end
                scatter3(b(:,3),b(:,2),b(:,4),64,c,'.');
                %cbaroutput=xyz_colordotplot_cbaroutput([b(:,3),b(:,2),b(:,4),b(:,cell2mat(plotnames(i,2)))],16,'jet',limn(i,:));%OLD METHOD
            elseif CreateDotPlotval && ~sum(isnan(b(:,cell2mat(plotnames(i,2)))))==0
                h1=uicontrol('Parent',h,'Units','normalized','ForegroundColor',[1,1,1],'BackgroundColor',[0,0,0],'horizontalalignment','left','fontunits','normalized','fontsize',.6,'FontWeight','normal','ListboxTop',0,'Position',[0.5 0.5 0.2 0.0401],'String','NaN Values Detected','Style','text','Tag','StaticText viewtxt');
            else,curtain3(b,nxgrd,nygrd,1,az,el,h);end
            if i==1;dar=get(gca,'dataaspectratio');end
            title(cell2mat(plotnames(i,3)),'fontsize',14);
            xlabel('Longitude','fontsize',14);ylabel('Latitude','fontsize',14);zlabel('Depth','fontsize',14);
            set(h,'numbertitle','off','name',cell2mat(plotnames(i,1)));
            cbar=colorbar;colormap('jet');ylabel(cbar,cell2mat(plotnames(i,1)));
            set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
            set(gca,'dataaspectratio',[1 1 500]);
            axissnug;view(aspect(1:2));camzoom(aspect(3));
            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'',''closeplots;'');'])
            eval([toggletxt,toggle1,',''Value'',toggle);',toggle0,',''Value'',~toggle);'])
            eval([saveallbutton,int2str(i),''',''Callback'',''saveall;'');'])
            eval([viewtxt,xyviewtxt,zviewtxt,zoomtxt]);
            eval([xyviewbox,int2str(i),''');',zviewbox,int2str(i),''');',zoombox,int2str(i),''');']);
            eval([getviewcoordbutton,'set(findobj(''''Tag'''',''''Edittext xyview' int2str(i) '''''),''''String'''',num2str(tempview(1))),set(findobj(''''Tag'''',''''Edittext zview' int2str(i) '''''),''''String'''',num2str(tempview(2)))'',''Tag'',''Pushbutton GetRatio' int2str(i) ''');']);
            eval([updateviewbutton,'aspect=[str2num(get(findobj(''''Tag'''',''''Edittext xyview' int2str(i) '''''),''''String'''')),str2num(get(findobj(''''Tag'''',''''Edittext zview' int2str(i) '''''),''''String'''')),str2num(get(findobj(''''Tag'''',''''Edittext zoomview' int2str(i) '''''),''''String''''))];updateresultplots(',int2str(i),');'',''Tag'',''Pushbutton UpdateView' int2str(i) ''');']);
        end
    end
    if TSval
        stepsize=0.01;
        [meshsal,meshtemp]=meshgrid(limn(2,1):stepsize:limn(2,2),limn(1,1):stepsize:limn(1,2));
        meshsal=meshsal(:);meshtemp=meshtemp(:);
        meshmean=NaN(length(meshsal),size(plotnames,1));
        meshstd=NaN(length(meshsal),size(plotnames,1));
        meshrange=NaN(length(meshsal),size(plotnames,1));
        for k=1:length(meshsal)
            ind=find(b(:,5)>meshtemp(k)-stepsize/2 & b(:,5)<meshtemp(k)+stepsize/2);
            if ~isempty(ind)
                ind2=find(b(ind,6)>meshsal(k)-stepsize/2 & b(ind,6)<meshsal(k)+stepsize/2);
                if ~isempty(ind2)
                    meshmean(k,3:size(plotnames,1))=mean(b(ind(ind2),cell2mat(plotnames(3:end,2))),1);
                    if length(ind2)>1
                        meshstd(k,3:size(plotnames,1))=std(b(ind(ind2),cell2mat(plotnames(3:end,2))));
                        meshrange(k,3:size(plotnames,1))=max(b(ind(ind2),cell2mat(plotnames(3:end,2))))-min(b(ind(ind2),cell2mat(plotnames(3:end,2))));
                    end
                end
            end
        end
        for i=3:size(plotnames,1)
            pause(1);
            h=findobj('tag',['TS ' cell2mat(plotnames(i,1))]);
            if isempty(h),figure('tag',['TS ' cell2mat(plotnames(i,1))]),h=findobj('tag',['TS ' cell2mat(plotnames(i,1))]);else,figure(h),load azel;end;clf;
            set(h,'units','normalized','position',[0.1 0.075 0.8 0.8]);
            eval([maxtext,mintext]);
            eval([[maxbox,int2str(i),'TS'',''String'',''' num2str(limn(i,2)) ''');'],[minbox,int2str(i),'TS'',''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),',2);'');'])
            eval([saveallbutton,int2str(i),''',''Callback'',''saveall;'',''Position'',[0.67 0.01 0.15 0.055]);'])
            eval([exitbutton,int2str(i),''',''Callback'',''closeplots;'');'])
            ah=subplot(332);set(ah,'position',[.1 .61 .35 .35]);
            crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
            c=NaN(size(b,1),3);
            for j=1:64%Set colors for scatter3
                if j==1
                    num=find(b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
                elseif j==64
                    num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j));
                else
                    num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j) & b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
                end
                c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
                clear num
            end
            scatter(b(:,6),b(:,5),8,c,'.');
            title(['TS Unbinned ' cell2mat(plotnames(i,3))],'fontsize',14);
            axis([limn(2,:) limn(1,:)])
            xlabel('Salinity','fontsize',14);ylabel('Temperature','fontsize',14);zlabel('Depth','fontsize',14);
            set(h,'numbertitle','off','name',['TS ' cell2mat(plotnames(i,1))]);
            cbar=colorbar;colormap(cbar,'jet');ylabel(cbar,cell2mat(plotnames(i,1)));
            set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
            %Mean, STD, and Range
            ah=subplot(337);set(ah,'position',[.55 .61 .35 .35]);
            crange=[0,nanmean(meshstd(:,i))+2*nanstd(meshstd(:,i))];crange=crange(1):(crange(2)-crange(1))/64:crange(2);
            c=NaN(size(meshstd,1),3);
            for j=1:64%Set colors for scatter3
                if j==1
                    num=find(meshstd(:,i)<=crange(j+1));
                elseif j==64
                    num=find(meshstd(:,i)>=crange(j));
                else
                    num=find(meshstd(:,i)>=crange(j) & meshstd(:,i)<=crange(j+1));
                end
                c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
                clear num
            end
            scatter(meshsal,meshtemp,16,c,'.');
            title(['TS STD ' cell2mat(plotnames(i,3))],'fontsize',14);
            axis([limn(2,:) limn(1,:)])
            xlabel('Salinity','fontsize',14);ylabel('Temperature','fontsize',14);zlabel('Depth','fontsize',14);
            cbar=colorbar;colormap(cbar,'jet');ylabel(cbar,cell2mat(plotnames(i,1)));
            set(cbar,'Color',[1 1 1]);caxis([0,nanmean(meshstd(:,i))+2*nanstd(meshstd(:,i))]);
            ah=subplot(338);set(ah,'position',[.1 .17 .35 .35]);
            crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
            c=NaN(size(meshmean,1),3);
            for j=1:64%Set colors for scatter3
                if j==1
                    num=find(meshmean(:,i)<=crange(j+1));
                elseif j==64
                    num=find(meshmean(:,i)>=crange(j));
                else
                    num=find(meshmean(:,i)>=crange(j) & meshmean(:,i)<=crange(j+1));
                end
                c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
                clear num
            end
            scatter(meshsal,meshtemp,16,c,'.');
            title(['TS Mean ' cell2mat(plotnames(i,3))],'fontsize',14);
            axis([limn(2,:) limn(1,:)])
            xlabel('Salinity','fontsize',14);ylabel('Temperature','fontsize',14);zlabel('Depth','fontsize',14);
            cbar=colorbar;colormap(cbar,'jet');ylabel(cbar,cell2mat(plotnames(i,1)));
            set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
            ah=subplot(339);set(ah,'position',[.55 .17 .35 .35]);
            crange=[0,nanmean(meshrange(:,i))+2*nanstd(meshrange(:,i))];crange=crange(1):(crange(2)-crange(1))/64:crange(2);
            c=NaN(size(meshrange,1),3);
            for j=1:64%Set colors for scatter3
                if j==1
                    num=find(meshrange(:,i)<=crange(j+1));
                elseif j==64
                    num=find(meshrange(:,i)>=crange(j));
                else
                    num=find(meshrange(:,i)>=crange(j) & meshrange(:,i)<=crange(j+1));
                end
                c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
                clear num
            end
            scatter(meshsal,meshtemp,16,c,'.');
            title(['TS Range ' cell2mat(plotnames(i,3))],'fontsize',14);
            axis([limn(2,:) limn(1,:)])
            xlabel('Salinity','fontsize',14);ylabel('Temperature','fontsize',14);zlabel('Depth','fontsize',14);
            cbar=colorbar;colormap(cbar,'jet');ylabel(cbar,cell2mat(plotnames(i,1)));
            set(cbar,'Color',[1 1 1]);caxis([0,nanmean(meshrange(:,i))+2*nanstd(meshrange(:,i))]);
        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));
        eval([exitbutton,' time',''',''Callback'',''closeplots;'');'])
    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));
        eval([exitbutton,' flight',''',''Callback'',''closeplots;'');'])
    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));
        eval([exitbutton,' course',''',''Callback'',''closeplots;'');'])
    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)
        i=1;
        crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
        c=NaN(size(b,1),3);
        for j=1:64%Set colors for scatter3
        	if j==1
                num=find(b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
        	elseif j==64
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j));
            else
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j) & b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
            end
        	c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
        	clear num
        end
        scatter3(b(:,3),b(:,2),b(:,4),64,c,'.');view(aspect(1:2));
        xlabel('Longitude','fontsize',14);ylabel('Latitude','fontsize',14);zlabel('Depth','fontsize',14);
        cbar=colorbar;colormap('jet');ylabel(cbar,cell2mat(plotnames(i,1)));set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
        title(cell2mat(plotnames(i,3)),'fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;camzoom(aspect(3));
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        subplot(222)
        i=2;
        crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
        c=NaN(size(b,1),3);
        for j=1:64%Set colors for scatter3
        	if j==1
                num=find(b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
        	elseif j==64
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j));
            else
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j) & b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
            end
        	c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
        	clear num
        end
        scatter3(b(:,3),b(:,2),b(:,4),64,c,'.');view(aspect(1:2));
        xlabel('Longitude','fontsize',14);ylabel('Latitude','fontsize',14);zlabel('Depth','fontsize',14);
        cbar=colorbar;colormap('jet');ylabel(cbar,cell2mat(plotnames(i,1)));set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
        title(cell2mat(plotnames(i,3)),'fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;camzoom(aspect(3));
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        subplot(223)
        i=3;
        crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
        c=NaN(size(b,1),3);
        for j=1:64%Set colors for scatter3
        	if j==1
                num=find(b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
        	elseif j==64
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j));
            else
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j) & b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
            end
        	c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
        	clear num
        end
        scatter3(b(:,3),b(:,2),b(:,4),64,c,'.');view(aspect(1:2));
        xlabel('Longitude','fontsize',14);ylabel('Latitude','fontsize',14);zlabel('Depth','fontsize',14);
        cbar=colorbar;colormap('jet');ylabel(cbar,cell2mat(plotnames(i,1)));set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
        title(cell2mat(plotnames(i,3)),'fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;camzoom(aspect(3));
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        subplot(224)
        i=4;
        crange=limn(i,:);crange=crange(1):(crange(2)-crange(1))/64:crange(2);
        c=NaN(size(b,1),3);
        for j=1:64%Set colors for scatter3
        	if j==1
                num=find(b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
        	elseif j==64
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j));
            else
                num=find(b(:,cell2mat(plotnames(i,2)))>=crange(j) & b(:,cell2mat(plotnames(i,2)))<=crange(j+1));
            end
        	c(num,1)=cjet(j,1);c(num,2)=cjet(j,2);c(num,3)=cjet(j,3);
        	clear num
        end
        scatter3(b(:,3),b(:,2),b(:,4),64,c,'.');set(gca,'View',aspect(1:2));
        xlabel('Longitude','fontsize',14);ylabel('Latitude','fontsize',14);zlabel('Depth','fontsize',14);
        cbar=colorbar;colormap('jet');ylabel(cbar,cell2mat(plotnames(i,1)));set(cbar,'Color',[1 1 1]);caxis(limn(i,:));
        title(cell2mat(plotnames(i,3)),'fontsize',14);
        set(gca,'dataaspectratio',[1 1 500]);axissnug;camzoom(aspect(3));
        cameratoolbar(gcf,'show');cameratoolbar(gcf,'setmode','orbit');axis vis3d;hold off;
        eval([lattext,lontext,temptext,saltext])
        eval([saveallbutton,' composite'',''Callback'',''saveall;'',''Position'',[0.67 0.01 0.15 0.055]);'])
        eval([showallbutton,' composite'',''Position'',[0.51 0.01 0.15 0.055]);']);
        eval([exitbutton,'Composite'',''Callback'',''closeplots;'');'])
    end

    if replotval==-1;
        repeat=0;
        %Wait until all figures are closed.
        if HydroXYZval,
            for i=1:size(plotnames,1)
                waitfor(findobj('Tag',cell2mat(plotnames(i,1))));
            end
        end
        if TSval
            for i=3:size(plotnames,1)
                waitfor(findobj('Tag',['TS ' cell2mat(plotnames(i,1))]));
            end
        end
        if HydroTimeval,waitfor(findobj('Tag','plot env'));end
        if Flightval,waitfor(findobj('Tag','plot flight'));end
        if Courseplotval,waitfor(findobj('Tag','plot course'));end
        waitfor(findobj('Tag','plot composite'));
        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
	b_full=b_full(:,1:max(limnbcol(1:size(plotnames_orig,1))));
    %Close all plots to hopefully prevent memory limit crash
    tempreplotval=replotval;
    closeplots;
    replotval=tempreplotval;%Bypass the replotval change in closeplots
end %while
