function[contour_levels]=colorbar5(hh,line_type,color,line_style,bar);
if (nargin==0)
    disp('_____________________________________________________________________________________')
    disp('Usage:       [cc,hh]=contourf()')
    disp('             colorbar5(hh,line_type,color,line_style,bar)')
    disp('             clabel(cc,hh)')
    disp('hh:          is a handle to contour lines returned by [cc,hh]=contourf()')
    disp('line_type:   is a cell string of hatching types {''h'' ''v'' ''l'' ''R'' ''n'' ''hv''}')
    disp('             h-hor, v- |||, R-///, l-\\\, n-none ')
    disp('             combination like ''hv'' etc overlays ''h'' and ''v'' patterns ')
    disp('line_type    also may be a color symbol ''r''-red, ''b''-blue etc.')
    disp('             or RGB tripple ''0.5 0.5 0.5''-grey or ''0.5'' the same grey')
    disp('             Contour intervals specified by the colors (symbol or digits) ')
    disp('             are shown as shaded areas instead of hatched ones.')    
    disp('_____________________________________________________________________________________')
    disp('color        is hatching line color symbol or [RGB],      DEFAULT=''k''')
    disp('line_style:  is hatching line style ''-'',''--'', etc,    DEFAULT=''-''') 
    disp('bar       :  1 - show right-hand colorbar, 0 - dont show, DEFAULT=1 ')    
    disp('_____________________________________________________________________________________')    
    disp('contour_levels=CL, line_type=LT')
    disp('Cl(1)     CL(2)     CL(3)      ... CL(n-1)      CL(n)')
    disp('     LT(1)     LT(2)     LT(3)           LT(n-1)     LT(n)')
    disp(' length(contour_levels)=length(line_type)')
    disp('Program returns contour_levels found in the contour plot')
    disp('colorbar5(hh) returns contour levels and stops')
    disp('_____________________________________________________________________________________')
    disp('written by senya@atmos.umd.edu ')
    disp('ver 0.11, 12/09/01, ver 0.2 12/26/01, ver 0.3 04/18/02')
    disp('_____________________________________________________________________________________')
    disp('needs line_pathc2.m')
    return
end
if (nargin==2)
    color='k'; line_style='-'; bar=1;
end
%look-up table of hatching types
tabl=[{'h','v','R','l','n'};{'0' 'NaN' '1' '-1' '9999'}]';
ap=gca;

if ishold==0
    hold on
    switch_hold=1;
else
    switch_hold=0;
end

count =0;
for i = 1:length(hh);
   if (length((get(hh(i),'cdata'))) == 1 & ~isnan(get(hh(i),'cdata')))
      count = count + 1;
      h(count) = hh(i);
      cdata(count) = get(hh(i),'cdata');
   end
end
contour_levels = unique(cdata);


if (nargin==1)
    contour_levels;
    return
end

for i=1:length(line_type)
    ccc=line_type{i};
    if sum(ccc(1)=='ymcrgbwk')>0
        key(i)=1; % string color
    elseif  sum(ccc(1)=='hvRln')>0;
        key(i)=2; %hatching
    else
        key(i)=3; %digit color
    end
end


for i=1:length(line_type)
    cl=char(line_type(i));
    if key(i)==2
        nl(i)=length(cl);
        for j=1:nl(i)
            ii=find(cl(j)==char(tabl(:,1)));
            tang(i,j)=str2num(char(tabl(ii,2)));
        end
    else
        nl(i)=1;
        tang(i,1)=9999;
    end
end

%for i=1:length(hh) 10/25/02
%length(h)
%length(cdata)
for i=1:length(h)
    ii=find(cdata(i)==contour_levels);
%    xx=get(hh(i),'xdata'); 10/25/02
%    yy=get(hh(i),'ydata'); 10/25/02
    xx=get(h(i),'xdata');
    yy=get(h(i),'ydata');
    if(key(ii)==2)
        hp=patch(xx,yy,'w');
    elseif key(ii)==1
        hp=patch(xx,yy,line_type{ii});
    else
        hp=patch(xx,yy,ones(1,3).*strread(line_type{ii},'%f')');
    end

%    set(hp,'zdata',(2*i-1)*ones(size(get(hp,'xdata')))); %layer order for valid transform into a raster file
    for j=1:nl(ii)
        if(tang(ii,j)~=9999)
            al=line_patch2(xx,yy,50,tang(ii,j),color,line_style);
            %set(al,'zdata',2*i*ones(size(get(al,'xdata')))); %layer order
        end
    end
end
set(gca,'layer','top');
%draw color palette
if (bar==1)
    i1=isequal(line_type(1),line_type(2));
pos=get(gca,'position');
ax=axes;
set(ax,'gridlinestyle','-','xgrid','on','ygrid','on',...
'position',[pos(1)+pos(3)+0.01,pos(2),pos(3)*0.04,pos(4)],...
'fontsize',10,'linewidth',1,'xlim',[0 1],'ylim',[i1 length(contour_levels)],...
'xtick',[0 1],'xticklabel','','YAxisLocation', 'right',...
'ytick',[i1:length(contour_levels)],'box','on')

hold on

% draw color palette
for i=i1:length(contour_levels)-1
    if(key(i+1)==2)
        hp=patch([0 1 1 0 0],[i i i+1 i+1 i],'w');
    elseif key(i+1)==1
        hp=patch([0 1 1 0 0],[i i i+1 i+1 i],line_type{i+1});
    else
        hp=patch([0 1 1 0 0],[i i i+1 i+1 i],ones(1,3).*strread(line_type{i+1},'%f')');
    end
end

for i=i1:length(contour_levels)-1
    for j=1:nl(i+1)
        if(tang(i+1,j)~=9999)
            if(~isnan(tang(i+1,j)))
                line_patch2([0 1 1 0 0],[i i i+1 i+1 i],50,tang(i+1,j),color,line_style);
            else
                line_patch2([0 1 1 0 0],[i i i+1 i+1 i],50*0.04+2,tang(i+1,j),color,line_style);
            end    
        end
    end
end

% adjust y-axis labels
set(ax,'yticklabel',[contour_levels(1+i1:end) contour_levels(end)])
lb=cellstr(get(ax,'yticklabel'));
lb(1)={''}; lb(end)={''};
set(ax,'yticklabel',lb)
end
axes(ap);

if switch_hold==1
    hold off
end

