Code covered by the BSD License  

Highlights from
Tabular Expression Toolbox

image thumbnail

Tabular Expression Toolbox

by

 

23 Sep 2010 (Updated )

A tool for creating tabular expressions in Matlab/Simulink integrating checking with PVS and CVC3.

unsuppressed_output_file(file)
function [] = unsuppressed_output_file(file)
% [] = unsuppressed_output_file(file)
%
% Outputs to the command window a list of the lines in file which likely do 
% not have suppressed output. Lines with keywords which will not produce outputs ie
% (if, else, continue, function, etc.) are ignored.

% look through a file for lines which are unsuppressed

string = [char(10) 'file = ' file char(10)];
fid = fopen(file);
if fid == -1
    string = [string 'unable to open file' char(10)];
    fprintf('%s',string);
    return;
end
data = fread(fid);
cstring = char(rot90(data));
lines = regexp(cstring,'\n','split');
count = 0;
for i = 1:size(lines,2)
    
    % don't consider comments at begining
    comment = regexp(char(lines(i)),'\s*%.*','once');
    if ~isempty(comment)
        continue;
    end
    
    % don't consider keywords at begining of expression
    keyword = regexp(strtrim(char(lines(i))),'^(end|function|methods|properties|classdef|for|if|elseif|else|switch|case|try|catch|otherwise|while|return|continue|warning|break|global|persistent|set|delete)','once');
    if ~isempty(keyword)
        continue;
    end
    
    % don't consider multiline expressions
    multiline = regexp(strtrim(char(lines(i))),'\.\.\.$','once');
    if ~isempty(multiline)
        continue;
    end
    
    % don't consider empty lines
    if isempty(char(lines(i)))
        continue;
    end
    
    % don't consider lines of just spaces
    if isempty(strtrim(char(lines(i))))
        continue;
    end
    
    % don't consider lines that end in a semi-colon and have an optional
    % comment after
    semis = regexp(strtrim(char(lines(i))),'.*;(\s*%.*)*','once');
    if ~isempty(semis)
        continue;
    end
    
    % if string passes all these tests we infer that it is what we are
    % looking for
    count = count + 1;
    string = [string 'line <a href="matlab: opentoline(which(''' file '''),' num2str(i) ')">' num2str(i) '</a>: ' char(lines(i)) char(10)];
    
    
end

% only print something if we have found a line that meets our criteria
if count ~= 0
    fprintf('%s',string);
    
end

fclose(fid);

end

Contact us