disp(' ');
disp(' interpolate_coordinates.m  ver 1.0   October 26, 2006');
disp(' by Tom Irvine  Email: tomirvine@aol.com ');
%
disp(' ');
disp(' Enter reference coordinates ');
%
x1=input(' Enter x1 ');
y1=input(' Enter y1 ');
disp(' ');
%
x2=input(' Enter x2 ');
y2=input(' Enter y2 ');
%
disp(' ');
xtype=input(' Specify X-axis type:  1=linear  2=log ');
disp(' ');
ytype=input(' Specify Y-axis type:  1=linear  2=log ');
disp(' ');
%
disp(' Select analysis type ');
disp(' 1=find new X given known Y ');
disp(' 2=find new Y given known X ');
atype=input(' ');
%
iflag=1;
while(iflag==1)
%
if(atype==1)
    y=input(' Enter Y ');  
end
if(atype==2)
    x=input(' Enter X ');  
end
%
XL=x2-x1;
YL=y2-y1;
if(x1>0 & x2>0)
    LXL=log10(x2)-log10(x1);
end
if(y1>0 & y2>0)
    LYL=log10(y2)-log10(y1);
end
%
if(xtype==1 && ytype==1)  % xlinear ylinear
    if(atype==1)
        c2=(y-y1)/YL;
        c1=1-c2;
        xn=c1*x1+c2*x2;
    else
        c2=(x-x1)/XL;
        c1=1-c2;
        yn=c1*y1+c2*y2;
    end
end
if(xtype==1 && ytype==2)  % xlinear ylog
    if(atype==1)
        c2=(log10(y)-log10(y1))/LYL;
        c1=1-c2;
        xn=c1*x1+c2*x2;       
    else
        c2=(x-x1)/XL;
        c1=1-c2;
        yn=10^(c1*log10(y1)+c2*log10(y2));      
    end
end
if(xtype==2 && ytype==1)  % xlog ylinear
    if(atype==1)
        c2=(y-y1)/YL;
        c1=1-c2;
        xn=10^(c1*log10(x1)+c2*log10(x2));     
    else
        c2=(log10(x)-log10(x1))/LXL;
        c1=1-c2;
        yn=c1*y1+c2*y2;    
    end
end
if(xtype==2 && ytype==2)  % xlog ylog
    if(atype==1)
        n=log10(x2/x1)/log10(y2/y1);
        xn=x1*(y/y1)^n;
    else
        n=log10(y2/y1)/log10(x2/x1);
        yn=y1*(x/x1)^n;
    end    
end
disp(' ');
if(atype==1)
    xx=[x1 xn x2];
    yy=[y1 y y2];
    out1=sprintf(' new x = %8.4g',xn);
end
if(atype==2)
    xx=[x1 x x2];
    yy=[y1 yn y2];
    out1=sprintf(' new y = %8.4g',yn);
end
disp(out1)
plot(xx,yy);
grid('on');
%
xmax=max(xx);
xmin=min(xx);
ymax=max(yy);
ymin=min(yy);
%
if(xmin>0)
    ndx=log10(xmax/xmin);
end
if(ymin>0)
    ndy=log10(ymax/ymin);
end
%
if(xtype==1 && ytype==1)
    set(gca,'MinorGridLineStyle','none','GridLineStyle',':','XScale','linear','YScale','linear','XminorTick','off','YminorTick','off');  
end
if(xtype==1 && ytype==2)  % xlinear ylog
    set(gca,'MinorGridLineStyle','none','GridLineStyle',':','XScale','linear','YScale','log','XminorTick','off','YminorTick','off');     
end
if(xtype==2 && ytype==1)  % xlog ylinear
    set(gca,'MinorGridLineStyle','none','GridLineStyle',':','XScale','log','YScale','linear','XminorTick','off','YminorTick','off');   
end    
if(xtype==2 && ytype==2)  % xlog ylog
    set(gca,'MinorGridLineStyle','none','GridLineStyle',':','XScale','log','YScale','log','XminorTick','off','YminorTick','off');
end
disp(' ')
iflag=input(' Repeat calculation for new case?  1=yes  2=no ');
end