function [missing,added] = SIOActiveSensorTest(path,file,actmodlist) %this function accepts a path, file and active module list as a cell array. %It opens the log file specified by path & file, and checks to see what %modules, if any, have been added or removed from the list. %it then returns the missing and/or added modules as individual cell arrays %create full path name file_in = fullfile(path,file); %open file for reading in = fopen(file_in,'rt'); %size of actmodlist, the "old" or status quo data szactold = size(actmodlist,1); %this string indicates the start of the data set activemodstart = 'Active Modules:'; amstsize = size(activemodstart,2); %this is the end tag of the data we are after endstring = 'Inoperative Modules:'; ensize = size(endstring,2); %init modstr = ''; onflag = 0; %infinite loop while 1 %grab the whole row tline = fgetl(in); %break when the value returned by fgetl is empty if ~ischar(tline), break, end %if the line is an empty string, or shorter than the shortest tag we %are looking for, skip the line if (isempty(tline) | (amstsize > size(tline,2))) continue; end %check the flag to see if we are "on" and collecting strings, or off %and skipping them if (~onflag) %we're off if ((strcmp(tline(1:amstsize),activemodstart))) %we've seen the start tag now, let's become "on" onflag = 1; %skip to the next line, this line is just a tag continue; end else %must be that we are on if (strcmp(tline(1:ensize),endstring)) %we've hit the end tag, let's do some processing %splits the module names on spaces and inserts them into a cell %array. This is the "new" data. mods = strread(modstr,'%s','delimiter',' '); %size of the new data szactnew = size(mods,1); %init's an index of all zeros addind = zeros(szactnew,1); %iterate over the old data, checking to see if what has been %added to the new list since the last update. Since ~strcmp %outputs a logical array with a 0 where the match occurs, we XOR %all of the arrays together to get a map at the end for i=1:szactold addind = xor(addind,~strcmp(actmodlist{i},mods)); end %init's another index missind = zeros(szactold,1); %do the same thing as above, except this time we are looking %for data that has been removed since the last go around for j=1:szactnew missind = missind | strcmp(mods{j},actmodlist); end added = mods(addind); missing = actmodlist(~missind); break; end %while we're on, let's concatenate all the data into one long space %separated line modstr = [modstr ' ' tline]; end end