⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otworz_plik.m

📁 good for who wants it
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = otworz_plik(h, eventdata, handles, varargin)
% trgraph
% opens a trace file
global OPLIK TSTART TEND MAC plik katalog HEX USUNPLIK AUTOFORMAT

HEX=0;
TRGRAPH=0; %Trace graph format
USUNPLIK=1;
if OPLIK==0    
    [plik, katalog]=uigetfile({'*.tr','trace files';'*.mat','mat files';'*.out','out trace files';'*.*','all files'},'Choose a file to open');
elseif OPLIK==1
    if exist(eventdata)==0
        bledy(3);
        return;
    end
    plik=eventdata;
    sl=findstr(plik, '/');
    bsl=findstr(plik, '\');
    if length(sl) | length(bsl)
        if length(sl)
            katalog=plik(1:sl(end));
            plik=plik((sl(end)+1):end);
        elseif length(bsl)
            katalog=plik(1:bsl(end));
            plik=plik((bsl(end)+1):end);
        end
    else
        katalog=strcat(pwd, '\');
    end
end
try
if plik~=0 & isempty(findstr(plik, '.mat'))
    global C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 
    global TMAX LNOD AKTWEZ STARTWEZ PAKIETY BANDI TRACEFORMAT pole PLIKINT

    TEMPFORMAT=TRACEFORMAT;
    li=1;
    if isempty(C2) & strcmp(get(handles.timeint, 'Checked'),'on') & TSTART~=-1 & TEND~=-1
        PLIKINT=1;
    end
    if strcmp(get(handles.timeint, 'Checked'),'off') & (PLIKINT==0 | OPLIK==0)
        TSTART=-1;
        TEND=-1;
    end
    fid=fopen(strcat(katalog, plik));
    l=fgets(fid);
    if AUTOFORMAT==1
        l=autoform(plik,katalog);
    end
    fclose('all');
    fid=fopen(strcat(katalog, plik));
    if length(findstr(l, 'ip')) & length(findstr(l, 'tracegraph'))==0
        fclose(fid);
        czyplik=zamien_ip([katalog,plik]);
        if czyplik==-1
            podaj_ip([katalog,plik]);
            return;
        elseif czyplik==0
            bledy(9);
            return;
        else % file without IPs already exists
            kropa=findstr(plik,'.');
            ekst=plik(kropa(end):end);
            plik=plik(1:(kropa(end)-1));
            plik=[plik,'_no_ip',ekst];
            disp(['Trace file without IPs has been created: ', katalog, plik, 10,'Loading the file...']);
        end
    end
    if length(findstr(l, 'tracegraph'))
        if length(findstr(l, 'hex'))
            HEX=1;
        end
        TRACEFORMAT=2;
        TRGRAPH=1;
        if TSTART~=-1 & TEND~=-1
            usun_czas(fid,katalog);
            zmien_kolumny('temp',katalog);
        else
            fclose(fid);
            zmien_kolumny(plik,katalog);
        end
    elseif length(findstr(l, 'mixed12'))
        USUNPLIK=0;
        fclose('all');
        fidw=fopen(strcat(katalog,'temp'), 'wt');
        if length(findstr(l, 'hex'))
            HEX=1;
        end    
        fprintf(fidw,'tracegraph\n');                    
        fid=fopen(strcat(katalog, plik));
        l=fgets(fid);
        spacje=0;
        tint=TSTART~=-1 & TEND~=-1;
        spnum=-1;
        while l~=-1
            event=l(1);
            if length(findstr(l,'[')) %if wireless
                eventSFD=event=='s' | event=='f' | event=='D';
                if l(2)==32 & (eventSFD | event=='r')
                    sp=findstr(l,32); % searching for a space
                    if tint
                        t=str2double(l((sp(1)+1):(sp(2)-1)));
                        if t<TSTART
                            continue;
                        end    
                        if t>TEND
                            break;
                        end                    
                    end
                    spacje=0;
                    if sp(4)~=(sp(5)-1) % if there are 2 spaces between columns c4 and c5
                        sp=[1,sp]; spacje=1;
                    end
                    if eventSFD | (event=='r' & (l(sp(9)+2)~=48 | l(sp(10)+1)~=48 | l(sp(11)+1)~=48 | l(sp(12)+1)~=48))
                        if event=='D'
                            event='d';
                        end
                        if spacje==0
                            lw=[event, l(sp(1):sp(2)), l((sp(2)+2):(sp(3)-2)), l(sp(3):sp(4))];
                        else
                            lw=[event, l(sp(2):sp(3)), l((sp(3)+2):(sp(4)-2)), l(sp(4):sp(5))];
                        end
                        tmpspnum=sp(8)-sp(7);
                        if tmpspnum~=spnum
                            pkt=char(zeros(1, 15-tmpspnum)+32);
                            spnum=tmpspnum;
                        end                                    
                        if length(findstr(l,'/'))>0 | length(sp)<15
                            lw=[lw, [l((sp(6)+1):(sp(7)-1)), l(sp(7):sp(8)), pkt, l((sp(8)+1):(sp(9)-1)), l(sp(11):sp(12))]];
                            % left: hop from, hop to, fwd node, seq#
                            if event=='s'
                                if HEX==1
                                    ht=hex2dec(l((sp(10)+1):(sp(11)-1))); % hop to
                                    if (ht>=4294967000)
                                        ht='-1';
                                    else
                                        ht=num2str(ht);
                                    end
                                else
                                    if l(sp(10)+1)=='f'
                                        ht=' -1 ';
                                    else
                                        ht=l(sp(10):sp(11));
                                    end
                                end                                
                                if spacje==0 %go back because sp is moved
                                    if HEX==0
                                        fwrite(fidw, [lw, l((sp(2)+2):(sp(3)-2)), ht, '0 -1', 10], 'char');
                                    else    
                                        fwrite(fidw, [lw, l((sp(2)+2):(sp(3)-2)), 32, ht, ' 0 -1', 10], 'char');
                                    end    
                                else
                                    if HEX==0
                                        fwrite(fidw, [lw, l((sp(3)+2):(sp(4)-2)), ht, '0 -1', 10], 'char');
                                    else    
                                        fwrite(fidw, [lw, l((sp(3)+2):(sp(4)-2)), 32, ht, ' 0 -1', 10], 'char');
                                    end    
                                end
                            else % hop from, hop to, fwd, seq#
                                if spacje==0 %go back because sp is moved
                                    if HEX==0
                                        fwrite(fidw, [lw, l((sp(11)+1):sp(12)), l((sp(2)+2):(sp(3)-2)), ' 0 -1', 10], 'char');
                                    else
                                        fwrite(fidw, [lw, num2str(hex2dec(l((sp(11)+1):(sp(12)-1)))), 32, l((sp(2)+2):(sp(3)-2)), ' 0 -1', 10], 'char');
                                    end    
                                else
                                    if HEX==0
                                        fwrite(fidw, [lw, l((sp(11)+1):sp(12)), l((sp(3)+2):(sp(4)-2)), ' 0 -1', 10], 'char');
                                    else
                                        fwrite(fidw, [lw, num2str(hex2dec(l((sp(11)+1):(sp(12)-1)))), 32, l((sp(3)+2):(sp(4)-2)), ' 0 -1', 10], 'char');
                                    end    
                                end
                            end
                        else
                            sp1=findstr(l,':'); % node nr:port nr
                            if l(sp(14)+1)~='['
                                sp=[sp(1:13),sp(15:end)];
                            end
                            if length(sp)>18 % there is seq#
                                if l(sp(18)+1)=='[' 
                                    if l(sp(19)-1)==']' % seq# [no]
                                      c18=l((sp(18)+2):(sp(19)-2));
                                    else %[ack no]
                                      c18=l((sp(18)+2):(sp(19)-1));
                                    end  
                                else
                                    c18=l((sp(19)+2):(sp(20)-1)); % ...] 1 [ack no]
                                end
                                if str2double(c18)==NaN % uncomment if necessary
                                    c18='-1';
                                end
                            else 
                                c18='-1'; % there is no seq#
                            end
                            if HEX==0
                                fwrite(fidw, [lw, l((sp(6)+1):(sp(7)-1)), l(sp(7):sp(8)), pkt, ...
                                       l((sp(8)+1):(sp(9)-1)), l(sp(11):sp(12)), l((sp(14)+2):(sp1(1)-1)), ...
                                       32, l((sp(15)+1):(sp1(2)-1)), l(sp(17):(sp(18)-2)), 32, c18, 10], 'char');
                            else
                                fwrite(fidw, [lw, l((sp(6)+1):(sp(7)-1)), l(sp(7):sp(8)), pkt, ...
                                       l((sp(8)+1):sp(9)), num2str(hex2dec(l((sp(11)+1):(sp(12)-1)))), 32, l((sp(14)+2):(sp1(1)-1)), ...
                                       32, l((sp(15)+1):(sp1(2)-1)), l(sp(17):(sp(18)-2)), 32, c18, 10], 'char');                                
                            end   
                        end
                    end
                end
            elseif l(2)==32 & (event=='+' | event=='r' | event=='-' | event=='d') %if wired
                sp=findstr(l,32); % searching for a space
                lsp=length(sp);
                if lsp==11 | lsp==15
                    if tint
                        t=str2double(l((sp(1)+1):(sp(2)-1)));
                        if t<TSTART
                            continue;
                        end    
                        if t>TEND
                            break;
                        end                    
                    end
                    sp1=findstr(l,':'); 
                    if isempty(sp1)
                        sp1=findstr(l,'.'); % if there is no : find .

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -