function [  ] = genCFATikzUC(fileName, totFilt )
% generates a tikz version of the unit cell
%  

[numY, numX, numBytes] = size(totFilt);

if mod(numX,2) == 0
    offX = 0.5;
else
    offX = 0;
end
if mod(numY,2) == 0
    offY = 0.5;
else
    offY = 0;
end

yEnd = floor(numY/2);
xEnd = floor(numX/2);

vecY = (-yEnd + offY):1:(yEnd - offY);
vecX = (-xEnd + offX):1:(xEnd - offX);

% totYSteps = length(vecY);
% totXSteps = length(vecX);

tikzStr1 = ['\\begin{tikzpicture}[>=stealth'',join = round, cap = round,scale = 0.4]\n\\useasboundingbox (-' num2str(numX) ',-' num2str(numY) ') -- (-' num2str(numX) ',' num2str(numY) ') -- (' num2str(numX) ',' num2str(numY) ') -- (' num2str(numX) ',-' num2str(numY) ') -- cycle;\n\\begin{scope}[scale = 2]\n'];
tikzStr4 = '    \\begin{scope}[xshift =';
tikzStr5 = 'cm, yshift = ';
tikzStr6 = 'cm,scale = 0.95]\n        \\definecolor{tempColor}{RGB}{';
tikzStr7 = '}\n        \\draw[fill=tempColor] (-0.5,-0.5) -- (-0.5,0.5) -- (0.5,0.5) -- (0.5,-0.5) -- cycle;\n    \\end{scope}';
tikzStr8 = '\\end{scope}\n\\end{tikzpicture}';

totStr = [tikzStr1];

for k = 1:numY
    for j = 1:numX
        tempStr = [tikzStr4 num2str(vecX(j)) tikzStr5 num2str(vecY(k))...
                   tikzStr6 num2str(totFilt(k,j,1)) ','...
                   num2str(totFilt(k,j,2)) ','...
                   num2str(totFilt(k,j,3)) tikzStr7 '\n'];
        totStr = [totStr tempStr];
    end
end
totStr = [totStr tikzStr8];
fid = fopen(fileName,'w+');
fprintf(fid, totStr);
fclose(fid);
end

