function [vrb,blk]=rd_par(pth,fil)
% Reads parameter file according to description fields
% and puts the results into a cell arrays in which each element
% is an expression to evaluate, for example
% 'i_yr=98;'
% fil_nam{1}='tst.txt', etc
%clear all
%pth='d:\ont\satellites\';
%fil='sat_omni.par';
blk=[];
f_pr=sprintf('%s', pth, fil); % Full name for parameter file
i_par=fopen(f_pr);
key_blk=0;
if i_par>0   %1
    k_str=0;  % Counter of lines in the output cell array
    k_vrb=0;
    k_blk=0;
    kt_blk=0;
    % Reading variables
    key_read=1;  
    while key_read==1     %2
        s_lin=fgets(i_par);
        l_l=length(s_lin);
        if l_l>=8 & s_lin(1:8)=='#par_end'
            key_read=0;
        end
        if l_l>=3 & s_lin(1:3)=='///'           %3
            k_str=k_str+1;
            k_vrb=k_vrb+1;
            str1=s_lin(4:l_l);
            f_3=findstr(str1, '///');
            no_slash=isempty(f_3);
            if no_slash==0
                str2=str1(1:f_3(1)-1);
                frmt=sscanf(str2, '%s');
                vr_0=str1(f_3(1)+3:f_3(2)-1);
                vr=sscanf(vr_0, '%s')
                str3=str1(f_3(2)+3:l_l-3);
                num_s4=findstr(str3, '/%');
                no_cmnt=isempty(num_s4);
                if no_cmnt==0
                    str4=str3(1:num_s4(1)-1);
                else
                    str4=str3;
                end
                vr_vl=sscanf(str4,frmt)

                if frmt=='%f' | frmt =='%i'    %4
                    vr_vl=vr_vl';
                end         %3
                vrb{k_vrb,1}=frmt;
                vrb{k_vrb,2}=vr;
                vrb{k_vrb,3}=vr_vl;                   
            end
        end    %2
        if l_l>=10 & s_lin(1:10)=='#blk_start'         %3
            key_blk=1;
            k_blk=0;  
            while key_blk==1                       %4
                s_lin=fgets(i_par)
                l_l=length(s_lin);
                if l_l>=8 & s_lin(1:8)=='#blk_end'
                    key_blk=0
                end
                if l_l>=3     %5
                    str_str=s_lin(1:3);
                    if str_str=='|||' 
                        k_blk=k_blk+1;
                        k_in=1;
                    else
                        k_in=k_in+1;
                    end
                    f_cnt=findstr(s_lin, str_str);
                    f_end=findstr(s_lin, '/%');
                    f_str=[f_cnt,f_end];
                    l_f=length(f_str);
%                    pause
                    for i_bl=1:l_f-1                            %6
                        f1=f_str(i_bl)+3;
                        f2=f_str(i_bl+1)-1;
                        str=s_lin(f1:f2);


                        if k_blk<=2;          %7
                            str1=sscanf(str, '%s');
                            blk{i_bl,k_blk}=str1;
                        else
                            s_blk=size(blk);
                            w_blk=s_blk(1,1);
                             k_col=floor((k_blk-3)/w_blk)+1;
                             k_r=k_blk-2-w_blk*(k_col-1);
                            frmt=blk{k_r,1};
                                blk_vl=sscanf(str,frmt);
                                if frmt == '%f' | frmt=='%i'                     %9
                                    blk_vl=blk_vl';
                                end      %8
                                    blk{k_r,3}{k_col,k_in}=blk_vl;                                   
                         
                        end         %6
                    end             %5
                end                 %4
            end                   %3
        end
    end
    fclose(i_par);
end
            
       
