clear

fileName = 'Aug12-2010-1442.56';
fidIn = fopen(strcat(fileName, '.xls'));
fidxBow = fopen(strcat(fileName, 'xBow.csv'), 'w');
fidTens = fopen(strcat(fileName, 'Tens.csv'), 'w');
fidiLink = fopen(strcat(fileName, 'iLink.csv'), 'w');

lineNum = 0;
xBowNum = 0;
tensNum = 0;
iLinkNum = 0;
while ~feof(fidIn)
    strLine = char(fgets(fidIn));
    lineNum = lineNum + 1;
    if( length(strLine) > 8)
        if( (strcmp(strLine(1:4), 'xBow')) && (strLine(6) ~= 'G'));
            strLine = strcat(strLine, char(fgets(fidIn)));
            strLine = strcat(strLine, char(fgets(fidIn)));
            strLine = strcat(strLine, char(fgets(fidIn)));
            strLine = strcat(strLine, char(fgets(fidIn)));
            strLine = [strLine sprintf('\t%s',strtok(char(fgets(fidIn))))];
            fprintf(fidxBow, '%s\n', strLine);
            xBowNum = xBowNum + 1;
        elseif ( strcmp(strLine(1:4), 'Tens') )
            fprintf(fidTens, '%s', strLine);
            tensNum = tensNum + 1;
        elseif ( strcmp(strLine(1:5), 'iLink') )
            strLine = strcat(strLine, char(fgets(fidIn)));
            fprintf(fidiLink, '%s\n', strLine);
            iLinkNum = iLinkNum + 1;
        end
    end
end
 
fprintf('Num xBow Lines  = %d\nNum tens Lines  = %d\nNum iLink Lines = %d\n', xBowNum, tensNum, iLinkNum); 
fclose('all');