function plotafsCAA(Axes1, Axes2, AxesSOL1, AxesSOL2, xl1, xl2, yl1, yl2, lin1, lin2, AFS1, AFS2, L, R, fix1, fix2, choosen1, choosen2, isregcon, REGCON, full, selectplot, givena, givenc, tall, tcll, istrace, lcs, plotoptions)

if plotoptions(2)
    step = 1.0;
else
    step = 0;
end
liftup = 0;

mk = 'xo';
sty = '-';

intx = 2*xl2;
inty = 2*yl2;

colormap([1:-0.03:0.6]'*[1 1 1]);

plot(AxesSOL1, lin1([1 end]), [0 0], ':k','Linewidth',0.5);
plot(AxesSOL2, lin2([1 end]), [0 0], '--k','Linewidth',0.5);
hold(AxesSOL1, 'on');
hold(AxesSOL2, 'on');

if isregcon(1)
    [cp,cf] = contourf(Axes1,REGCON{1}.xl, REGCON{1}.yl, REGCON{1}.cl');
    set(cf,'Linestyle','none');
    hold(Axes1, 'on');
end

if max(selectplot) == 0
    plot(Axes1,1,0,'w');
    hold(Axes1, 'on');
else
    if selectplot(1)
        plot(Axes1, AFS1(:,1), AFS1(:,2),'-k', 0, 0, 'ok','Linewidth',1,'Markersize',4);
        hold(Axes1, 'on');
    end
    if (selectplot(2) == 1) && (full.isA)
        plotfullafsCAA(Axes1, full.AFSA, full.linesA, full.validA, full.dimA);
        hold(Axes1, 'on');
    end
end

if istrace
    plot(Axes1, tall(:,1), tall(:,2), 'o', 'Color', [.8 .8 .8]);
end

if givena.is
    if givena.adaptedis == 0
        for i=1:givena.s
            plot(Axes1, givena.afs(i,1), givena.afs(i,2),'*k','Linewidth',1,'Markersize',8);
            plot(AxesSOL1, lin1, givena.line(i,:), '-k','Linewidth',1);
        end
    else
        for i=1:givena.s
            plot(Axes1, givena.afs(i,1), givena.afs(i,2),'*k','Linewidth',1,'Markersize',8);
            plot(AxesSOL1, lin1(givena.adaptedI(1):givena.adaptedI(2)), givena.line(i,:), '-k','Linewidth',1);
        end
    end
end

for i=1:3
    if choosen1(i) == 1
        plot(Axes1, fix1(i,1), fix1(i,2),mk(1),'color',lcs(i,:),'Linewidth',2,'Markersize',12);
        tmpa = [1 fix1(i,:)]*R;
        tmpa = tmpa/max(tmpa);
        plot(AxesSOL1, lin1([1 end]), (i-1)*step*[1 1], 'k:','Linewidth',0.5);
        plot(AxesSOL1, lin1, (i-1)*step+tmpa, 'color',lcs(i,:),'Linewidth',2);
        if plotoptions(3)
            autodetect = detectallpeaksCAA(lin1,tmpa);
            for l=1:length(autodetect)
                plot(AxesSOL1, lin1(autodetect(l)), (i-1)*step+tmpa(autodetect(l)), 'k.','Linewidth',2, 'Markersize',12);
                text(AxesSOL1, lin1(autodetect(l)), (i-1)*step+tmpa(autodetect(l)),[' ',num2str(round(lin1(autodetect(l))))]);
            end
        end
        liftup = liftup+1;
    end
end

if isregcon(2)
    [cp,cf] = contourf(Axes2,REGCON{2}.xl, REGCON{2}.yl, REGCON{2}.cl');
    set(cf,'Linestyle','none');
    hold(Axes2, 'on');
end
if max(selectplot) == 0
    plot(Axes2,1,0,'w');
    hold(Axes2, 'on');
else
    if selectplot(1)
        plot(Axes2, AFS2(:,1), AFS2(:,2),'-k', 0, 0, 'ok','Linewidth',1,'Markersize',4);
        hold(Axes2, 'on');
    end
    if (selectplot(2) == 1) && (full.isC)
        plotfullafsCAA(Axes2, full.AFSC, full.linesC, full.validC, full.dimC);
        hold(Axes2, 'on');
    end
end

if istrace
    plot(Axes2, tcll(:,1), tcll(:,2), 'o', 'Color', [.8 .8 .8]);
end

if givenc.is
    for i=1:givenc.s
        plot(Axes2, givenc.afs(i,1), givenc.afs(i,2),'*k','Linewidth',1,'Markersize',8);
        plot(AxesSOL2, lin2, givenc.line(i,:), '-k','Linewidth',1);
    end
end

if sum(choosen1) == 3
    t = ones(3,3);
    t(:,2:3) = fix1;
    
    pt = pinv(t);
    if min(pt(1,:)) < 0
        sty = '--';
    end
    pt = pt*diag(1./pt(1,:))*diag(sign(pt(1,:)));
    
    if plotoptions(1)
        tmpC = L*pt;
        al = tmpC\ones(size(L,1),1);
        tmpC = tmpC*diag(al);
    end
    
    for i=1:3
        nch = setdiff(1:3,i);
        plot(Axes1, [fix1(nch(1),1) fix1(nch(2),1)], [fix1(nch(1),2) fix1(nch(2),2)],sty,'color',lcs(i+3,:),'Linewidth',2);
        
        plot(Axes2, pt(2,i), pt(3,i),mk(2),'color',lcs(3+i,:),'Linewidth',2,'Markersize',12);
        if plotoptions(1)
            plot(AxesSOL2, lin2, tmpC(:,i), 'color',lcs(3+i,:),'Linewidth',2);
        else
            plot(AxesSOL2, lin2, L*pt(:,i)/max(abs(L*pt(:,i))), 'color',lcs(3+i,:),'Linewidth',2);
        end
        plot(Axes2, pt(2,setdiff(1:3,i)), pt(3,setdiff(1:3,i)),sty,'color',lcs(i,:),'Linewidth',2);
    end
    if plotoptions(1)
        plot(AxesSOL2, lin2, tmpC*[1;1;1], 'k:','Linewidth',1);
    end
else
    for i=1:3
        if choosen1(i) == 1
            if abs(fix1(i,1)) > 1.E-7
                plot(Axes2, -1/fix1(i,1)-(fix1(i,2)/fix1(i,1))*inty,inty,'color',lcs(i,:),'Linewidth',2);
            else
                plot(Axes2, intx,-1/fix1(i,2)-(fix1(i,1)/data.fix1(i,2))*intx,'color',lcs(i,:),'Linewidth',2);
            end
        end
    end
    if sum(choosen1) == 2
        for i=1:3
            if choosen1(i) == 0
                nch = setdiff(1:3,i);
                plot(Axes1, [fix1(nch(1),1) fix1(nch(2),1)], [fix1(nch(1),2) fix1(nch(2),2)],sty,'color',lcs(i+3,:),'Linewidth',2);
                
                t = ones(2,3);
                t(:,2:3) = fix1(nch,:);
                pt = null(t);
                pt = pt/pt(1);
                plot(Axes2, pt(2,1), pt(3,1), mk(2),'color',lcs(3+i,:),'Linewidth',2,'Markersize',12);
            end
        end
    end
end

set(Axes1, 'Xlim',xl1, 'Ylim',yl1);
set(Axes2, 'Xlim',xl2, 'Ylim',yl2);

set(AxesSOL1, 'Xlim', lin1([1 end]), 'Ylim' ,[-0.2 step*2+1.05])
if plotoptions(2)
    set(AxesSOL1, 'ytick',[]);
end
if plotoptions(4)
    set(AxesSOL1, 'xdir','reverse');
end
set(AxesSOL2, 'Xlim', lin2([1 end]), 'Ylim' ,[-0.2 1.05]);

hold(Axes1, 'off');
hold(Axes2, 'off');

hold(AxesSOL1, 'off');
hold(AxesSOL2, 'off');
