function [cellID] = plotCarSim(simfile, discdynfile)

fid = fopen(simfile, 'r');
cellID = [];
C2 = [];
C3 = [];
C4 = [];
C5 = [];
C7 = [];

while (~feof(fid))
    tline = fgetl(fid);
    [s f t]=regexp(tline,'(\w+):(\d+)');
    for i=1:length(t)
        var = tline([t{i}(1,1):t{i}(1,2)]);
        value = str2num(tline([t{i}(2,1):t{i}(2,2)]));    
        if (strcmp(var, 'cellID'))
            cellID = [cellID value];
        elseif (strcmp(var, 'C2'))
            C2 = [C2 value];
        elseif (strcmp(var, 'C3'))
            C3 = [C3 value];
        elseif (strcmp(var, 'C4'))
            C4 = [C4 value];
        elseif (strcmp(var, 'C5'))
            C5 = [C5 value];
        elseif (strcmp(var, 'C7'))
            C7 = [C7 value];
        end
    end
end

fclose(fid);

if (nargin > 1)
    disc_dynamics = [];
    fid = fopen(discdynfile, 'r');
    tline = fgetl(fid);
    [s f t]=regexp(tline,'X(\d+)');
    list_prop = [];
    for i = 1:length(t)
        list_prop = [list_prop str2num(tline([t{i}(1,1):t{i}(1,2)]))];
    end
    while (~feof(fid))
        tline = fgetl(fid);
        disc_dynamics = [disc_dynamics; str2num(tline)];
    end
    fclose(fid);
    for i = 1:length(cellID)
        cellID(i) = list_prop(find(disc_dynamics(cellID(i)+1, :)==1, 1, 'first'));
    end
end

x = [];
y = [];
figure;
for i=1:length(cellID)
    clf;
    hplot = plot([0 4], [0 0],'LineWidth',3,'Color','k');
    hold on;
    plot([0 4], [1 1],'LineWidth',3,'Color','k');
    plot([1 1], [-1 2],'LineWidth',3,'Color','k');
    plot([2 2], [-1 2],'LineWidth',3,'Color','k');
    plot([3 3], [-1 2],'LineWidth',3,'Color','k');
    if (C2(i))
        patch([1 2 2 1], [0 0 1 1], 'r');
    end
    if (C3(i))
        patch([1 2 2 1], [1 1 2 2], 'r');
    end
    if (C4(i))
        patch([2 3 3 2], [-1 -1 0 0], 'r');
    end
    if (C5(i))
        patch([2 3 3 2], [0 0 1 1], 'r');
    end
    if (C7(i))
        patch([3 4 4 3], [0 0 1 1], 'r');
    end
    if (cellID(i) == 0)
        x = [x 0.5];
        y = [y 0.5];
    elseif (cellID(i) == 1)
        x = [x 1.5];
        y = [y 0.5];
    elseif (cellID(i) == 2)
        x = [x 2.5];
        y = [y 0.5];
    elseif (cellID(i) == 3)
        x = [x 2.5];
        y = [y 1.5];
    end
    plot(x, y, 'k:','LineWidth', 2);
    plot(x(end), y(end), 'ro','LineWidth', 2,'MarkerSize', 8);
    set(gca,'XTick',[],'YTick',[]);
    pause;
end