%
%  plot_loglog_function_md_h2.m  ver 1.7   by Tom Irvine
%
function[fig_num,h2]=...
    plot_loglog_function_md_h2(fig_num,x_label,y_label,t_string,ppp,fmin,fmax,md)
%
f=ppp(:,1);
a=ppp(:,2);
%
h2=figure(fig_num);
fig_num=fig_num+1;
%
plot(f,a,'Color',[0 0.4470 0.7410]);
%
ylabel(y_label);   
xlabel(x_label);
out=sprintf(t_string);
title(out);

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

iflag=1;

while(iflag==1)
    
    iflag=0;
    
    for i=1:length(f)
        if(a(i)<1.0e-18)
            
            f(i)=[];
            a(i)=[]; 
            
            iflag=1;
            break; 
        end
    end        
end

[ymax,ymin]=ymax_ymin_md(max(a),min(a),md);

% --- Define Y-axis major ticks at each decade (and optionally 1-2-5) ---

% Get decade range
ymin_dec = floor(log10(ymin));
ymax_dec = ceil(log10(ymax));


yticks = 10.^(ymin_dec:ymax_dec);
yticks = yticks(yticks >= ymin & yticks <= ymax);

set(gca,'YTick',yticks);
set(gca,'YTickLabel', arrayfun(@(y) sprintf('%.0e',y), yticks, 'UniformOutput', false))


[xtt,xTT,iflag]=xtick_label(fmin,fmax);


if(iflag==1)
    set(gca,'xtick',xtt);
    set(gca,'XTickLabel',xTT);
    
    fmin=min(xtt);
    fmax=max(xtt);     
end

%
xlim([fmin,fmax]);

try
    ylim([ymin,ymax]);
catch
    ymin
    ymax
    warndlg(' ymin, ymax error ');
    return;
end

set(gca,'MinorGridLineStyle',':','GridLineStyle',':','XScale','log',...
                     'YScale','log','XminorTick','off','YminorTick','off',...
                     'XGrid','on','GridLineStyle','-',...
                     'YGrid','on','GridLineStyle','-');
