1 function contour(x,y,z,nz,theta,alpha,leg,flag,ebox,zlev)
3         rhs=argn(2);
4         if rhs == 0 then   // demo
6                 title_demo = [
7                         '';
8                         'Demo of contour()';
9                         '========================================';
10                         ''];
12                 s_mat=[
13                         'deff(''[z]=Surf1(x,y)'',''z=x^2+y^3'');';
14                         'x=-1:0.1:1; y=x;'
15                         'subplot(211);contour(x,y,Surf1,10);'
16                         'deff(''[z]=Surf2(x,y)'',''z=x^2+y^2'');';
17                         'z=eval3d(Surf2,x,y)'
18                         'subplot(212);plot3d(x,y,z);contour(x,y,z+0.1,10,flag=[0 2 4]);'];
20                 write(%io(2),title_demo);
21                 write(%io(2),s_mat);
22                 write(%io(2),' ');
23                 execstr(s_mat);
24                 return
25         end
28   if rhs<4, error('contour requires at least 4 arguments'),end;
29   levels=[]
31   opts=[]
32   if exists('theta','local')==1 then opts=[opts,'theta=theta'],end
33   if exists('alpha','local')==1 then opts=[opts,'alpha=alpha'],end
34   if exists('leg'  ,'local')==1 then opts=[opts,'leg=leg']    ,end
35   if exists('ebox' ,'local')==1 then opts=[opts,'ebox=ebox']  ,end
36   if exists('flag' ,'local')==0 then flag=[2 2 3], end
37   if exists('zlev' ,'local')==0 then zlev=0  ,end
39   if or(type(z)==[11 13]) then
40     fun=z;clear z //to avoid redfinition warning
41     if type(fun)==11 then comp(fun),end
42     z=feval(x,y,fun)
43   end
45   job=flag(1)
46   if rhs==4|job==2 then
47     contour2d(x,y,z,nz);
48     return,
49   end
51   if  get('figure_style')=='old' then
52     opts=strcat([opts,"flag=flag"],',')
53     execstr('oldcontour(x,y,z,nz,'+opts+')')
54     return,
55   end
57   if size(nz,'*')==1 then
58     style=1:nz,
59   else
60     style=1:size(nz,'*')
61   end
63   opts=strcat([opts,'flag=flag(2:3)'],',');
65   [xc,yc]=contour2di(x,y,z,nz);
68   fig=gcf();
69   autoc=fig.auto_clear;
70   if autoc=="on" then, xbasc(),end
71   a=gca();
72   fg=a.foreground
73   v=fig.immediate_drawing;
74   fig.immediate_drawing="off"
75   fig.auto_clear="off"
76   cnt=0
78   fpf=xget("fpf");if fpf=='' then fpf='%.2g',end
79   k=1;n=yc(k); c=0; level = %inf;
80   while k < length(xc)
81     n = yc(k)
82     if xc(k) ~= level then
83       c = c+1; level = xc(k),levels=[level levels];
84       a.foreground=c;
85       if cnt>0 then glue(a.children(1:cnt)),cnt=0,end
86     end
88     if job==1 then zz=zlev,else zz=level,end
89     execstr('param3d(xc(k+(1:n)),yc(k+(1:n)),zz*ones(1,n),'+opts+')')
91     cnt = cnt+1
92     if stripblanks(fpf)<>'' then
93       xstring(xc(k+1+n/2),yc(k+1+n/2)," "+msprintf(fpf,level))
94       e=gce();e.data(3)=zz
95       cnt=cnt+1
96     end
97     k=k+n+1;
98   end
99   if cnt>0 then glue(a.children(1:cnt)),cnt=0,end
100   set('current_obj',a);
101   a.foreground=fg
102   if flag(3) == 0 then
103     a.axes_visible='off';
104     a.box='off';
105   elseif flag(3) == 1 then
106     a.axes_visible='off';
107     a.box='off';
108   elseif flag(3) == 2 then
109     a.axes_visible='off';
110     a.box='back_half';
111   elseif flag(3)==3 then
112     a.axes_visible='off';
113     a.box='on';
114    elseif flag(3)>=4 then
115     a.axes_visible='on';
116     a.box='on';
117   end
118   fig.immediate_drawing=v;
119   fig.auto_clear=autoc;
120 endfunction