disp(' ');
disp(' real_div.m  January 26, 2011 ');
disp(' By Tom Irvine   Email: tomirvine@aol.com ');
disp(' ');
disp(' This program divides one function by another function. ');
disp(' Each function must contain two columns. ');
disp(' ');
%
disp(' Select file input method for file 1 (numerator file) ');
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
%
yone=double(THM(:,2));
xone=double(THM(:,1));
sz=size(THM);
out1=sprintf(' size = %d x %d \n',sz(1),sz(2));
disp(out1);
%
disp(' Select file input method for file 2 (denominator file)');
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
%
ytwo=double(THM(:,2));
xtwo=double(THM(:,1));
sz2=size(THM);
out1=sprintf(' size = %d x %d \n',sz2(1),sz2(2));
disp(out1);
%
if(sz2(1)~=sz(1))
    disp(' ');
    disp(' size error ');
    disp(' ');
end
%
df=1;
%
Q2 = real_mult_intlog(xone,yone,df);
f1=Q2(:,1);
a1=Q2(:,2);
Q2 = real_mult_intlog(xtwo,ytwo,df);
f2=Q2(:,1);
a2=Q2(:,2);
%
df2=df/2;
%
ijk=1;
for(i=1:length(f1))
    for(j=1:length(f2))
        if(abs(f1(i)-f2(j))<df2)
            ab(ijk)=a1(i)/a2(j);
            ff(ijk)=(f1(i)+f2(j))/2.;
            ijk=ijk+1;
            break;
        end
    end
end    
%
figure(1);
plot(ff,ab);
set(gca,'MinorGridLineStyle','none','GridLineStyle',':','XScale','log','YScale','log','XminorTick','on','YminorTick','on');
grid('on');
trans=[ff' ab'];
disp(' ');
disp(' Matlab output array:  trans ');
disp(' ');
%
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 = [ff' ab' ];
	  fid = fopen(writepfname,'w');
	  fprintf(fid,'  %g  %g\n',writedata');
	  fclose(fid);
end