function hopsgui_timeseries
% This plot draw the time series

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 time series')
nfig=figure;
set(nfig,'Name','Time series','MenuBar','none','Position',[0 0.6 0.4 0.4]);

	
while hopsgui_obj{1}.answer==1
var=hopsgui_obj{1}.variable;



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

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

  case 'wvst'

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

	
  case 'potden'

      ytitle=var;			   
  	[time,temp1,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'temp',x(1),y(1),z);
  	[time,salt1,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'salt',x(1),y(1),z);
	st1=potden80(salt1,potemp80(salt1,temp1,ones(size(temp1))*-z),ones(size(temp1))*-z);

  	[time,temp2,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'temp',x(2),y(2),z);
  	[time,salt2,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'salt',x(2),y(2),z);
	st2=potden80(salt2,potemp80(salt2,temp2,ones(size(temp2))*-z),ones(size(temp2))*-z);
	fac=1;  
	
  case 'souvel'

      ytitle=var;			   
  	[time,temp1,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'temp',x(1),y(1),z);
  	[time,salt1,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'salt',x(1),y(1),z);
	st1=svel80(salt1,temp1,ones(size(temp1))*-z);
  	[time,temp2,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'temp',x(2),y(2),z);
  	[time,salt2,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,'salt',x(2),y(2),z);
	st2=svel80(salt2,temp2,ones(size(temp2))*-z);
	fac=1;  
	
	
	
  case '|Ut|'
      ytitle=var;		
	ytitle=strcat(var);	
	[time,st1,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,var,x(1),y(1),z);
	[time,st2,titlerun]=hopsgui_extimeseries(hopsgui_obj{1}.filein,var,x(2),y(2),z);
	fac=1;  
	
	
  otherwise
	disp(sprintf('>>>>This option is not currently installed for -%s-, edit hopsgui_timeseries.m \n',var))
	close(nfig)
	return;  
  	
end		



figure(nfig)
subplot(211)
tit=sprintf('Corrd: x %6.3f, y %6.3f, depth %6.3f',x(1),y(1),z);
plot(time,st1*fac);grid on;title(tit);xlabel('Time (days)');ylabel(ytitle)


subplot(212)
tit=sprintf('Corrd: x %6.3f, y %6.3f, depth %6.3f',x(2),y(2),z);
plot(time,st2*fac);grid on;title(tit);xlabel('Time (days)');ylabel(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 time series display')
return;


