%
clear x;
clear y;
clear xi;
clear yi;
clear xL;
clear yL;
clear xiL;
clear yiL;
%
disp(' ');
disp(' int_semilog.m  ver 1.1  April 7, 2009 ');
disp(' By Tom Irvine   Email: tomirvine@aol.com ');
disp(' ');
%
disp(' This script performs log-linear 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); 
%
jstart=1;
for(i=1:max(size(xi)))
    for(j=jstart:(-1+max(size(y))))
        if(xi(i)==x(j))
            yi(i)=y(j);
            jstart=j;
            break;
        end
        if(xi(i)>x(j) && xi(i)<x(j+1))
            x1=x(j);
            x2=x(j+1);
            LXL=log10(x2)-log10(x1);
            c2=(log10(xi(i))-log10(x1))/LXL;
            c1=1-c2;
            yi(i)=c1*y(j)+c2*y(j+1);
            jstart=j;      
            break;
        end
    end
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