% reflection frequency approximation
function [prm_out,dsc_out]=fr_crit_mult_lor(n_mx,fr_mx,h_mx,pw_mx,h_int,num_bands_in,num_bands_out,prm_mult,dp_mult,eps_mult,cf_alf_k,lin_dsc,ar_dsc)   

 sz_pw=size(pw_mx);
 w_pw=sz_pw(2);
sz_prm=size(prm_mult);
L_mult=sz_prm(1);
w_prm=sz_prm(2);
i_mult=1;
key_mult=1;
prm_out=zeros(1,w_prm)-1e11;
dsc_out=zeros(1,2)-1e11;
A_LIN=zeros(2,2)-1e11;
% interpolation of linear fragment at the start and final zone
for i_frg=1:2
    if i_frg==1
        h_1=h_int(3);
        h_2=h_int(4);
    else
        h_1=h_int(5);
        h_2=h_int(6);
    end
f_h_lin_0=find(h_mx>=h_1 & h_mx<h_2);
L_h_lin_0=length(f_h_lin_0);
if L_h_lin_0>=2
    f_h_lin=f_h_lin_0;
    L_h_lin=L_h_lin_0;
else
if i_frg==1    
hx_min=min(h_mx);
h_1=hx_min+h_int(14);
h_2=hx_min+h_int(15);
else
hx_max=max(h_mx);
h_1=hx_max-h_int(15);
h_2=hx_max;
end
f_h_lin=find(h_mx>=h_1 & h_mx<h_2);
L_h_lin=length(f_h_lin);
end
    if L_h_lin>=2
    fr_lin=fr_mx(f_h_lin,w_pw);
    h_lin=h_mx(f_h_lin);
 A_LIN_c=polyfit(h_lin,fr_lin,1)
 A_LIN(i_frg,:)=A_LIN_c;
    end

    
end



while key_mult
    prm_0=prm_mult(i_mult,:);
%    prm_ar=prm_ar_for_iono(prm_0,dp_mult);


f_h=find(h_mx>h_int(1) & h_mx<h_int(2));
L_h=length(f_h);
L_b1=lin_dsc(1);
L_b2=L_h*lin_dsc(2);
L_b_two=[L_b1,L_b2];
 L_b=max(L_b_two);
 
if L_h>2
    h_h=h_mx(f_h);
    pw_h=pw_mx(f_h,:);
    fr_h=fr_mx(f_h,:);
    n_h=n_mx(f_h,:);
 [Npl_ar]=Np_line_dens(h_h,fr_h,h_int,prm_0,lin_dsc);
 
 if Npl_ar(1,2)>=L_b
    nzc=Npl_ar(1,1);
    key_look=0;
    [prm_1,dsc_1]=lin_slct_iono(prm_0, ar_dsc);
    if min(prm_1)>0;
    if i_mult==1
        prm_out_0(i_mult,:)=prm_1;
        dsc_out_0(i_mult,:)=dsc_1;
    else
        key_line_iono_org=line_iono_cmp(prm_out_0,prm_1,ar_dsc);
        if key_line_iono_org>0
            prm_out_0(i_mult,:)=prm_1;
            dsc_out_0(i_mult,:)=dsc_1;
        end
    end
    end
     i_mult=i_mult+1;
    if i_mult>=L_mult
        key_mult=0;
    end
         else
 nzz1=find(Npl_ar(:,1)==1);
 if nzz1==1
     dp_mult=dp_mult/2;
     f_eps_ok=find(dp_mult>eps_mult);
     L_eps_ok=length(f_eps_ok);
    if L_eps_ok==0
         key_look=0
          i_mult=i_mult+1;
       if i_mult>=L_mult
            key_mult=0;
       end
       
    else
     prm_ar=prm_ar_for_iono(prm_0,dp_mult);   
     [Npl_ar]=Np_line_dens(h_h,fr_h,h_int,prm_ar,lin_dsc);
     
    end
 end
 
 end
end
end