function hopsgui_profiles
% This plot draw the profiles

global hopsgui_obj


hopsgui_obj{1}.answer=1;

if ~strcmp('depth_contour',strrep(hopsgui_obj{1}.action,' ','')) & ~strcmp('kindex_contour',strrep(hopsgui_obj{1}.action,' ','')) 
disp('>>>>This option only works with kslices or depth contours')
return;
end


disp('>>>Click twice at the same place to disable the profile')
nfig=figure;
set(nfig,'Name','Vertical profile','MenuBar','none','Position',[0 0.1 0.4 0.4]);

	
while hopsgui_obj{1}.answer==1

var=hopsgui_obj{1}.variable;
if strcmp('tbath',strrep(var,' ','')) | strcmp('pbar',strrep(var,' ',''))
disp('>>>>>The variable choose is not 3D, changed to temperature')
var='temp'
end

figure(hopsgui_obj{1}.hfigure)
[x,y]=ginput(2);
time=hopsgui_obj{1}.time;


switch(var)
  case 'temp' 
	ytitle=strcat(var);	
	[pre1,st1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(1),y(1),time);
	[pre2,st2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(2),y(2),time);
	fac=1;	

  case 'salt' 
	ytitle=strcat(var);	
	[pre1,st1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(1),y(1),time);
	[pre2,st2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(2),y(2),time);
	fac=1;	

	
  case 'wvzt'
	fac=24.*36.;
	ytitle=strcat(var,' (m/day)');
	[pre1,st1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(1),y(1),time);
	[pre2,st2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(2),y(2),time);

		
  case 'wvst'
	fac=24.*36.;
	ytitle=strcat(var,' (m/day)');
	[pre1,st1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(1),y(1),time);
	[pre2,st2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(2),y(2),time);


  case 'potden'
      ytitle=var;		  
  	[pre1,temp1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'temp',x(1),y(1),time);  
	[pre1,salt1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'salt',x(1),y(1),time);  
	st1=potden80(salt1,potemp80(salt1,temp1,-pre1),-pre1);
	
	[pre2,temp2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'temp',x(2),y(2),time);  
	[pre2,salt2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'salt',x(2),y(2),time);  
	st2=potden80(salt2,potemp80(salt2,temp2,-pre2),-pre2);
	fac=1;
	
  case 'souvel'
      ytitle=var;		  
  	[pre1,temp1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'temp',x(1),y(1),time);  
	[pre1,salt1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'salt',x(1),y(1),time);  
	st1=svel80(salt1,temp1,-pre1);
	
	[pre2,temp2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'temp',x(2),y(2),time);  
	[pre2,salt2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,'salt',x(2),y(2),time);  
	st2=svel80(salt2,temp2,-pre2);
	fac=1;

  case '|Ut|'
      ytitle=var;		
	[pre1,st1,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(1),y(1),time);
	[pre2,st2,titlerun]=hopsgui_exprofiles(hopsgui_obj{1}.filein,var,x(2),y(2),time);
	fac=1;  
	
	
  otherwise
	disp(sprintf('>>>>This option is not currently installed for -%s-, edit hopsgui_profiles.m \n',var))
	close(nfig)
	return;  
  	
end		



figure(nfig)
subplot(121)
tit=sprintf('Corrd: x %6.3f, y %6.3f, %6.3f days',x(1),y(1),((hopsgui_obj{1}.time-1)*hopsgui_obj{1}.timeinterval)/24.);
plot(st1*fac,pre1);grid on;title(tit);ylabel('Depth');xlabel(ytitle)


subplot(122)
tit=sprintf('Corrd: x %6.3f, y %6.3f, %6.3f days',x(2),y(2),((hopsgui_obj{1}.time-1)*hopsgui_obj{1}.timeinterval)/24.);
plot(st2*fac,pre2);grid on;title(tit);ylabel('Depth');xlabel(ytitle)

if x(1)==x(2) & y(1)==y(2) 
hopsgui_obj{1}.answer=0;
end


if exist('h') == 1
delete(h);
end

figure(hopsgui_obj{1}.hfigure)
hold on;
h=plot(x,y,'ko');
hold off;

end

delete(h);
disp('>>>>>Finished profile display')
return;


