function varargout=ploty(x1,y1,x2,y2,varargin)
% ploty 
%   ploty plots in two axes

%   Project: IMPACT
%   Title of Code: ploty
%   Relevant additional documentation:
%   Developer: Carlos Gonzalez
%   External Dependencies: NA
%
%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with authors.

global ax
[ax h1 h2]=plotyy(x1,y1,x2,y2,varargin{:});
h = zoom;
set(h,'ActionPreCallback',@myprecallback);
set(h,'ActionPostCallback',@mypostcallback)
switch nargout
    case 1,
        varargout(1)={ax};
    case 2,
        varargout(1)={ax};
        varargout(2)={h1};
    case 3,
        varargout(1)={ax};
        varargout(2)={h1};
        varargout(3)={h1};
    case 0,
        ;
    otherwise,
        warning('Too many output arguments');
end


function myprecallback(obj,evd)
global ax yl
yl=get(ax(2),'ylim');

function mypostcallback(obj,evd)
global ax yl
ylim=get(ax(1),'ylim');
newXlim = get(evd.Axes,'XLim');
newYlim = get(evd.Axes,'YLim');
set(ax(1),'Xlim',newXlim);
if strcmp(get(ax(1),'Xscale'),'linear')
    xp=ylim(1)+(ylim(2)-ylim(1))/(yl(2)-yl(1))*(newYlim(1)-yl(1));
    xpp=ylim(1)+(ylim(2)-ylim(1))/(yl(2)-yl(1))*(newYlim(2)-yl(1));
else
    xp=10^(log10(ylim(1))+(log10(ylim(2))-log10(ylim(1)))/(log10(yl(2))-log10(yl(1)))*(log10(newYlim(1))-log10(yl(1))));
    xpp=10^(log10(ylim(1))+(log10(ylim(2))-log10(ylim(1)))/(log10(yl(2))-log10(yl(1)))*(log10(newYlim(2))-log10(yl(1))));
end

set(ax(1),'Ylim',[xp,xpp]);
yl=newYlim;
set(ax(1),'Ytickmode','auto')
set(ax(2),'Ytickmode','auto')

        

