% data selection (eqpac)
% Edits made December 11, 2002  rcg
%   Fix location of object.  Changed to usjgofs.  Fix field name value
%   for depth to depth_n.  Fill event number with leading 0 if necessary
%   since comparisons are alpha rather than numeric.   Replace call to
%   clg with clf instead.
 
clear all
loadjg('//usjgofs.whoi.edu/jgofs/eqpac/tt011/insitupp(event,lat,lon)');

% select a station
figure(1);clf
plot(lon,lat,'x',lon,lat);
xlabel('Longitude');ylabel('Latitude');
lonsave=lon;latsave=lat;eventsave=event;
hold

while(1)
figure(1);
fprintf(1,'Click on station; hit return with cursor in figure to end\n');
[x,y,b]=ginput(1);
if b>3
  return
end
% find point closest to cursor
distsq=(lonsave-x).^2+(latsave-y).^2;
[md,is]=min(distsq);
plot(lonsave(is),latsave(is),'o');
drawnow

% get data for station
ev=int2str(eventsave(is));

% Note that this is not a generized solution.  Use %20contains%20 in
% place of the "=".

[rows,cols] = size(ev);
if cols == 7
	zerovalue=0;
	zerofill=int2str(zerovalue);
	ev=sprintf('%s%s',zerofill,ev);
end
fprintf(1,'You selected event number %s\n',ev);
str=['//usjgofs.whoi.edu/jgofs/eqpac/tt011/insitupp(event=',ev,')'];
loadjg(str);

% display
figure(2)
plot(prim_p,-depth_n,light,-depth_n);
xlabel('PP (yellow) Light (purple)');ylabel('depth');
title(['Event = ',ev]);
end
