%
clear x;
clear y;
clear xi;
clear yi;
clear xL;
clear yL;
clear xiL;
clear yiL;
%
disp(' ');
disp(' intlog.m  ver 1.1  October 31, 2006 ');
disp(' By Tom Irvine   Email: tomirvine@aol.com ');
disp(' ');
%
disp(' This script performs logarithmic interpolation on ');
disp(' a matrix with two columns. ');
disp(' ');
%
disp(' Select file input method ');
disp('   1=external ASCII file ');
disp('   2=file preloaded into Matlab ');
file_choice = input('');
%
if(file_choice==1)
    [filename, pathname] = uigetfile('*.*');
    filename = fullfile(pathname, filename);
    fid = fopen(filename,'r');
    THM = fscanf(fid,'%g %g',[2 inf]);
    THM=THM';
else
    THM = input(' Enter the matrix name:  ');
end
%
y=double(THM(:,2));
x=double(THM(:,1));
%
disp(' ');
disp(' Enter the X-axis increment ');
df=input(' ');
%
xi=min(x):df:max(x); 
%
xL=log10(x);
yL=log10(y);
xiL=log10(xi);
%
yiL = interp1(xL,yL,xiL);
%
for(i=1:length(xi))
    xi(i)=10^xiL(i);
    yi(i)=10^yiL(i);
end
plot(xi,yi);
set(gca,'MinorGridLineStyle','none','GridLineStyle',':','XScale','log','YScale','log','XminorTick','on','YminorTick','on');
grid('on');
%
choice=input(' Export as txt file?  1=yes  2=no  ' );
disp(' ')
%
if choice == 1 
      [writefname, writepname] = uiputfile('*','Save interpolated data as');
	  writepfname = fullfile(writepname, writefname);
	  writedata = [xi' yi' ];
	  fid = fopen(writepfname,'w');
	  fprintf(fid,'  %g  %g\n',writedata');
	  fclose(fid);
end