function res=treeplot2(R1,R2,str,f1,f2,FontSize,LineWidth);
%draws the average tree with columns.
n=size(R1,1);
hold on;
c=1;
counter=1;
res=[];
for i=1:n
    xxx1=plot([R1(i,1),R1(i,1)],[R1(i,2),R1(i,3)],'k','Linewidth',LineWidth);
    res(counter)=xxx1;
    tpe='line';
    set(xxx1,'UserData',tpe);
    counter=counter+1;
    xxx2=plot([R1(i,1),R1(i,4)],[R1(i,3),R1(i,3)],'k','Linewidth',LineWidth);
    res(counter)=xxx2;
    set(xxx2,'UserData',tpe);
    counter=counter+1;
    xxx3=plot([R1(i,4),R1(i,4)],[R1(i,3),R1(i,5)],'k','Linewidth',LineWidth);
     res(counter)=xxx3;
     set(xxx3,'UserData',tpe);
     counter=counter+1;
     
   if R1(i,2)==0  & round(R1(i,1))==R1(i,1)
      
                if f1==1
             res(counter)=text(R1(i,1),-.025,str(R2(R1(i,1))).name,'fontsize',FontSize);
             set(res(counter),'HorizontalAlignment','right');
             set(res(counter),'Rotation',90);
             set(res(counter),'UserData','text');
            
             counter=counter+1;
         end
        if f2==1
        
            set(xxx1,'Color',str(R2(R1(i,1))).color);
        else
            if f2==2
                set(xxx1,'Color',[0 0 0]);
            else 
                color_bw=str(R2(R1(i,1))).color_bw;
                color_bw1=str(R2(R1(i,1))).color_bw1;
                %color_bw=color_bw.*color_bw1;
                set(xxx1,'Color',color_bw);
                if (color_bw1(1)<0.3)
                    set(xxx1,'LineStyle','--');
                else
                    if color_bw1(1)<0.6
                        set(xxx1,'LineStyle',':');
                    else
                        if color_bw1(1)<0.9
                            set(xxx1,'LineStyle','-.');
                        else
                            set(xxx1,'LineStyle','-');
                        end
                    end
                end
            end        
        end;
        c=c+1;
    end
    
   if R1(i,5)==0 & round(R1(i,4))==R1(i,4)
        
         
         if f1==1
         res(counter)=text(R1(i,4),-.025,str(R2(R1(i,4))).name,'fontsize',FontSize);
         set(res(counter),'HorizontalAlignment','right');
         set(res(counter),'Rotation',90);
         set(res(counter),'UserData','text');
         counter=counter+1;
         
        end
        if f2==1
            set(xxx3,'Color',str(R2(R1(i,4))).color);
        else
            if f2==2
                set(xxx3,'Color',[0 0 0]);
            else 

            color_bw=str(R2(R1(i,4))).color_bw;
            color_bw1=str(R2(R1(i,4))).color_bw1;
            %color_bw=color_bw.*color_bw1;
            set(xxx3,'Color',color_bw);
            if (color_bw1(1)<0.3)
                set(xxx3,'LineStyle','--');
            else
                if color_bw1(1)<0.6
                    set(xxx3,'LineStyle',':');
                else
                    if color_bw1(1)<0.9
                        set(xxx3,'LineStyle','-.');
                    else
                        set(xxx3,'LineStyle','-');
                    end
                end
            end
            end

         
        end
        c=c+1;
    end
    
end
global irr_legend;
global irr_legend_handle;
if ~isempty(irr_legend)
    if isempty(irr_legend_handle)
        ax1=axes('position',[0.85 0.75 0.1 0.1],'XTick',[],'YTick',[]);
        cla;
        legend;
        irr_legend_handle=ax1;
    else
        ax1=irr_legend_handle;
        axes(ax1);
        cla;
        legend;
    end
    hold on;
    sectors=[];
    names=[];
    nsectors=0;
    for i=1:length(str)
        exa=find(sectors==str(i).type);
        if (isempty(exa))
            sectors=[sectors,str(i).type];
            nsectors=nsectors+1;
            names{nsectors}=getnamesector(str(i).type);
            color=str(i).color;
            color_bw=str(i).color_bw;
            color_bw1=str(i).color_bw1;
            xxx3=plot(0,0);
            if f2==1
                set(xxx3,'Color',color);
            else
                set(xxx3,'Color',color_bw);
                if (color_bw1(1)<0.3)
                    set(xxx3,'LineStyle','--');
                else
                    if color_bw1(1)<0.6
                        set(xxx3,'LineStyle',':');
                    else
                        if color_bw1(1)<0.9
                            set(xxx3,'LineStyle','-.');
                        else
                            set(xxx3,'LineStyle','-');
                        end
                    end
                end
            end
        end
    end

    legend(names);
end
%[10 60 40 30 25 70 35 15 45 20 50 65]



