function argout=diagnose_ctd(theCallback)
%function argout=diagnose_ctd(theCallback)
%
%This function brings up a gui menu for creating
%plots based on ctd files in a given directory
%
%Gwyneth E. Packard, 2 December 1999
% Updated    06-Dec-1999 12:00:26.
%
%Create initial loop to make menu - no argument
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
if (nargin<1)
%set theCallback for the buttons
theCallback=[mfilename ' callback'];

%find all of the relevant files and sort them
%alphabetically, then make dummy first element
%because the gui comes up looking as if the first
%element is chosen by default when in fact it is not
d=dir('161*.cdn');
	if isempty(d)
		helpdlg(['There are no combined files in this directory'])
		return
	end
names={d(:).name};
[tmp,tmpindex]=sort(names); 
sortednames={'------------------' names{tmpindex}};

%create the buttons and list box
figure('name','Diagnostic plots','tag','bigmenu');
c(1)=uicontrol('style','listbox','string',sortednames,'tag','ladcpfiles');
c(2)=uicontrol('style','pushbutton','string','Plot ThetaS1');
c(3)=uicontrol('style','pushbutton','string','Overlay ThetaS1');
c(4)=uicontrol('style','pushbutton','string','Plot ThetaS2');
c(5)=uicontrol('style','pushbutton','string','Overlay ThetaS2');
c(6)=uicontrol('style','pushbutton','string','Plot T1 v P');
c(7)=uicontrol('style','pushbutton','string','Plot S1 v P');
c(8)=uicontrol('style','pushbutton','string','Plot T2 v P');
c(9)=uicontrol('style','pushbutton','string','Plot S2 v P');
c(10)=uicontrol('style','pushbutton','string','Plot Sig1-1 v P');
c(11)=uicontrol('style','pushbutton','string','Plot Sig1-2 v P');
c(12)=uicontrol('style','pushbutton','string','Plot Sig2-1 v P');
c(13)=uicontrol('style','pushbutton','string','Plot Sig2-2 v P');
c(14)=uicontrol('style','pushbutton','string','Plot Sig3-1 v P');
c(15)=uicontrol('style','pushbutton','string','Plot Sig3-2 v P');
c(16)=uicontrol('style','pushbutton','string','Plot Sig4-1 v P');
c(17)=uicontrol('style','pushbutton','string','Plot Sig4-2 v P');
c(18)=uicontrol('style','pushbutton','string','Plot Theta-1 v P');
c(19)=uicontrol('style','pushbutton','string','Plot Theta-2 v P');
c(20)=uicontrol('style','pushbutton','string','Plot O2 v P');
c(21)=uicontrol('style','pushbutton','string','Plot Sig0-1 v P');
c(22)=uicontrol('style','pushbutton','string','Plot Sig0-2 v P');
c(23)=uicontrol('style','pushbutton','string','Overlay Sig4-1 v P');
c(24)=uicontrol('style','pushbutton','string','Overlay Sig4-2 v P');
c(25)=uicontrol('style','pushbutton','string','Overlay Tht-1 v P');
c(26)=uicontrol('style','pushbutton','string','Overlay Tht-2 v P');
c(27)=uicontrol('style','pushbutton','string','Overlay Sig0-1 v P');
c(28)=uicontrol('style','pushbutton','string','Overlay Sig0-2 v P');
c(29)=uicontrol('style','pushbutton','string','Close figures');
c(30)=uicontrol('style','pushbutton','string','Quit');
set(c(2:end),'callback',theCallback);
%lay them out according to the following map
lay=[1 2  3  4  5
     1 18 25 19 26
     1 21 27 22 28 
     1 16 23 17 24
     1 10 11 12 13
     1 14 15 inf inf
     1 6  8  7  9
     1 20 inf inf inf
     1 inf 29 inf 30];
%put up the box and leave
uilayout(c,lay);
return
end	%end initial loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%On all future calls there will be an argument
%which will be a callback by one of the buttons
%and we end up here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%first retrieve the value of the list box assuming
%there is one and deliver an error if there is not
fig=findobj('type','figure','name','Diagnostic plots','tag','bigmenu');
h=findobj(fig,'style','listbox');
whichone=get(h,'value');	%value gives gui index
if isempty(whichone) | whichone<=1
	helpdlg(['You didn''t choose a file'])
	return
end
filenames=get(h,'string');
filename=filenames{whichone};

%Finally switch on the callback string to figure out which 
%button made this call, then do whatever it claims to do
switch(lower(theCallback))
case 'callback'
	switch(lower(get(gcbo,'string')))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot thetas1'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','TS1','name',filename);
		if isempty(plotindex)
			figure('tag','TS1','name',filename);
		end
		plotindex=findobj('type','figure','tag','TS1','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsal1,st.ctdptmp1,'.')
		xlabel('Salinity')
		ylabel('Potential Temperature, Sensor 1')
		title(labelsafe(filename))
		hold on
		m=axis;
		v=[21:.2:31];
		contour(st.grd.salt,st.grd.ptmp,st.grd.pden,v);
		v2=[22:29];
		[cs,h]=contour(st.grd.salt,st.grd.ptmp,st.grd.pden,v2);
		H=clabel(cs,h,'fontsize',12,'color','k','labelspacing',150);
		axis(m)
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay thetas1'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a TS plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'TS1')
			helpdlg(['You have not chosen a base TS1 diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdsal1,st.ctdptmp1);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 1');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot thetas2'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','TS2','name',filename);
		if isempty(plotindex)
			figure('tag','TS2','name',filename);
		end
		plotindex=findobj('type','figure','tag','TS2','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsal2,st.ctdptmp2,'.')
		xlabel('Salinity')
		ylabel('Potential Temperature, Sensor 2')
		title(labelsafe(filename))
		hold on
		m=axis;
		v=[21:.2:31];
		contour(st.grd.salt,st.grd.ptmp,st.grd.pden,v);
		v2=[22:29];
		[cs,h]=contour(st.grd.salt,st.grd.ptmp,st.grd.pden,v2);
		H=clabel(cs,h,'fontsize',12,'color','k','labelspacing',150);
		axis(m)
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay thetas2'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a TS2 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'TS2')
			helpdlg(['You have not chosen a base TS2 diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdsal2,st.ctdptmp2);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 2');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot t1 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','TP1','name',filename);
		if isempty(plotindex)
			figure('tag','TP1','name',filename);
		end
		plotindex=findobj('type','figure','tag','TP1','name',filename);
		figure(plotindex)
		plot(st.ctdtmp1,st.ctdprs,'.')
		xlabel('Raw CTD Temperature (C), Sensor1')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot s1 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','SP1','name',filename);
		if isempty(plotindex)
			figure('tag','SP1','name',filename);
		end
		plotindex=findobj('type','figure','tag','SP1','name',filename);
		figure(plotindex)
		plot(st.ctdsal1,st.ctdprs,'.')
		xlabel('Raw CTD Salinity, Sensor 1')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot t2 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','TP2','name',filename);
		if isempty(plotindex)
			figure('tag','TP2','name',filename);
		end
		plotindex=findobj('type','figure','tag','TP2','name',filename);
		figure(plotindex)
		plot(st.ctdtmp2,st.ctdprs,'.')
		xlabel('Raw CTD Temperature (C), Sensor 2')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot s2 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','SP2','name',filename);
		if isempty(plotindex)
			figure('tag','SP2','name',filename);
		end
		plotindex=findobj('type','figure','tag','SP2','name',filename);
		figure(plotindex)
		plot(st.ctdsal2,st.ctdprs,'.')
		xlabel('Raw CTD Salinity, Sensor 2')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot o2 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','OP','name',filename);
		if isempty(plotindex)
			figure('tag','OP','name',filename);
		end
		plotindex=findobj('type','figure','tag','OP','name',filename);
		figure(plotindex)
		plot(st.o2.MLL,st.ctdprs,'.')
		xlabel('Oxygen (ml/l)')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig0-1 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','SG1','name',filename);
		if isempty(plotindex)
			figure('tag','SG1','name',filename);
		end
		plotindex=findobj('type','figure','tag','SG1','name',filename);
		figure(plotindex)
		plot(st.ctdpden1,st.ctdprs,'.')
		xlabel('Sigma 0, Sensor set 1')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay sig0-1 v p'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a SG1 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'SG1')
			helpdlg(['You have not chosen a base Sigma0-1/Pressure diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdpden1,st.ctdprs);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 1');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig0-2 v p'
		st=read_cmb(filename);
		plotindex=findobj('type','figure','tag','SG2','name',filename);
		if isempty(plotindex)
			figure('tag','SG2','name',filename);
		end
		plotindex=findobj('type','figure','tag','SG2','name',filename);
		figure(plotindex)
		plot(st.ctdpden2,st.ctdprs,'.')
		xlabel('Sigma 0, Sensor set 2')
		ylabel('Pressure (db)')
		axis ij
		grid on 
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay sig0-2 v p'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a SG2 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'SG2')
			helpdlg(['You have not chosen a base Sigma0-2/Pressure diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdpden2,st.ctdprs);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 2');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot theta-1 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','THTP1','name',filename);
		if isempty(plotindex)
			figure('tag','THTP1','name',filename);
		end
		plotindex=findobj('type','figure','tag','THTP1','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdptmp1,st.ctdprs,'.')
		xlabel('Potential Temperature, Sensor 1')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay tht-1 v p'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a THTP1 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'THTP1')
			helpdlg(['You have not chosen a base Theta-1/Pressure diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdptmp1,st.ctdprs);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 1');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot theta-2 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','THTP2','name',filename);
		if isempty(plotindex)
			figure('tag','THTP2','name',filename);
		end
		plotindex=findobj('type','figure','tag','THTP2','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdptmp1,st.ctdprs,'.')
		xlabel('Potential Temperature, Sensor 2')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay tht-2 v p'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a THTP2 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'THTP2')
			helpdlg(['You have not chosen a base Theta-2/Pressure diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdptmp2,st.ctdprs);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 2');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig1-1 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG11','name',filename);
		if isempty(plotindex)
			figure('tag','SIG11','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG11','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig11,st.ctdprs,'.')
		xlabel('Sigma 1, Sensor set 1')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig1-2 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG12','name',filename);
		if isempty(plotindex)
			figure('tag','SIG12','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG12','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig12,st.ctdprs,'.')
		xlabel('Sigma 1, Sensor set 2')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig2-1 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG21','name',filename);
		if isempty(plotindex)
			figure('tag','SIG21','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG21','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig21,st.ctdprs,'.')
		xlabel('Sigma 2, Sensor set 1')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig2-2 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG22','name',filename);
		if isempty(plotindex)
			figure('tag','SIG22','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG22','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig22,st.ctdprs,'.')
		xlabel('Sigma 2, Sensor set 2')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig3-1 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG31','name',filename);
		if isempty(plotindex)
			figure('tag','SIG31','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG31','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig31,st.ctdprs,'.')
		xlabel('Sigma 3, Sensor set 1')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig3-2 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG32','name',filename);
		if isempty(plotindex)
			figure('tag','SIG32','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG32','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig32,st.ctdprs,'.')
		xlabel('Sigma 3, Sensor set 2')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig4-1 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG41','name',filename);
		if isempty(plotindex)
			figure('tag','SIG41','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG41','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig41,st.ctdprs,'.')
		xlabel('Sigma 4, Sensor set 1')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay sig4-1 v p'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a SIG41 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'SIG41')
			helpdlg(['You have not chosen a base Sigma4-1/Pressure diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdsig41,st.ctdprs);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 1');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'plot sig4-2 v p'
		st=read_cmb(filename);
%I wanted to create a new figure of every type for every station, but
%never be redundant, so I am searching on name which is station and
%tag which is type.
		plotindex=findobj('type','figure','tag','SIG42','name',filename);
		if isempty(plotindex)
			figure('tag','SIG42','name',filename);
		end
		plotindex=findobj('type','figure','tag','SIG42','name',filename);
		figure(plotindex)
%Now that we are plotting in the right figure simply plot away and
%use all the desired properties such as zoom, etc.
		plot(st.ctdsig42,st.ctdprs,'.')
		xlabel('Sigma 4, Sensor set 2')
		ylabel('Pressure (db)')
		title(labelsafe(filename))
		grid on 
		axis ij
		zoom on
		clear st
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'overlay sig4-2 v p'
%In order to overlay plots I wanted to grab the current figure, the
%menu itself is always one from inside the program so I want the 
%second child on the stack
		allfigures=get(0,'children'); %grab current figure
		currentfig=allfigures(2);
%Grab the tag and check that its a SIG42 plot
		currenttag=get(currentfig,'tag');
		if ~strcmp(currenttag,'SIG42')
			helpdlg(['You have not chosen a base Sigma4-2/Pressure diagram'])
		else
%if it is then start the plot
			st=read_cmb(filename);	
%make each new line be a separate and distinguishable color		
			colormap(hsv);
			colors=colormap;
			colors=[colors;colors;colors;colors;colors;colors];
			figure(currentfig)
			hold on
%find out what other lines are out there
			lines=findobj(currentfig,'type','line');
%ask how many colors they are using
			colorsused=get(lines,'color');
			used=size(colorsused,1);
			newline=plot(st.ctdsig42,st.ctdprs);
%use the color 3 lines down in the colormap from the last one
			set(newline,'color',colors(used*5-4,:));
			set(currentfig,'name','Multiple stations, Sensor 2');
			clear st
		end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'close figures'
		ts1figs=findobj('type','figure','tag','TS1');
		close(ts1figs)
		tp1figs=findobj('type','figure','tag','TP1');
		close(tp1figs)
		sp1figs=findobj('type','figure','tag','SP1');
		close(sp1figs)
		ts2figs=findobj('type','figure','tag','TS2');
		close(ts2figs)
		tp2figs=findobj('type','figure','tag','TP2');
		close(tp2figs)
		thtp1figs=findobj('type','figure','tag','THTP1');
		close(thtp1figs)
		thtp2figs=findobj('type','figure','tag','THTP2');
		close(thtp2figs)
		sp2figs=findobj('type','figure','tag','SP2');
		close(sp2figs)
		o2figs=findobj('type','figure','tag','OP');
		close(o2figs)
		sg1figs=findobj('type','figure','tag','SG1');
		close(sg1figs)
		sg2figs=findobj('type','figure','tag','SG2');
		close(sg2figs)
		sig11figs=findobj('type','figure','tag','SIG11');
		close(sig11figs)
		sig12figs=findobj('type','figure','tag','SIG12');
		close(sig12figs)
		sig21figs=findobj('type','figure','tag','SIG21');
		close(sig21figs)
		sig22figs=findobj('type','figure','tag','SIG22');
		close(sig22figs)
		sig31figs=findobj('type','figure','tag','SIG31');
		close(sig31figs)
		sig32figs=findobj('type','figure','tag','SIG32');
		close(sig32figs)
		sig41figs=findobj('type','figure','tag','SIG41');
		close(sig41figs)
		sig42figs=findobj('type','figure','tag','SIG42');
		close(sig42figs)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	case 'quit'
		close(fig)
		return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	otherwise
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	end
otherwise
end
