Removed "Sfgrayplot demo:" from demo of Sfgrayplot.
[scilab.git] / scilab / modules / graphics / macros / Sfgrayplot.sci
1 function []=Sfgrayplot(x, y, f, strf, rect, nax, zminmax, colminmax, mesh, colout)
2
3         // PURPOSE
4         //    Like fgrayplot but the function fec is used to smooth the 
5         //    result assuming that the underlying function is linear on 
6         //    a set of triangles built from the grid (here with n1=5, n2=3):
7         //             _____________
8         //             | /| /| /| /|
9         //             |/_|/_|/_|/_| 
10         //             | /| /| /| /| 
11         //             |/_|/_|/_|/_|
12         //
13         // Copyright INRIA
14         // rewritten by Bruno Pincon (17 april 05) (based of my modifs of Sgrayplot)
15
16         [lhs,rhs]=argn()
17         if rhs == 0 then   // demo
18                 deff("[z]=Surf(x,y)","z=x.^3+y");
19                 f=gcf();
20                 f.color_map = jetcolormap(64);
21                 f.immediate_drawing = "off";
22                 colorbar(-2,2);
23                 Sfgrayplot(-1:0.1:1,-1:0.1:1,Surf,strf="031",rect=[-1,-1,1,1]);
24                 xtitle("$\Large f(x,y)=x^3+y$");
25                 f.immediate_drawing = "on";
26                 return
27         elseif rhs < 3 then
28                 error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "Sfgrayplot", 3, 10));
29         end
30   
31         // some checks
32         if ~(type(x)==1 & isreal(x)) then
33           error(msprintf(gettext("%s: Input argument #%d must be real.\n"), "Sfgrayplot", 1))
34         end
35         if ~(type(y)==1 & isreal(y)) then
36           error(msprintf(gettext("%s: Input argument #%d must be real.\n"), "Sfgrayplot", 2))
37         end
38         if type(f)~=11 & type(f)~=13 then 
39           error(msprintf(gettext("%s: Wrong type for input argument #%d: function expected.\n"), "Sfgrayplot", 3));
40         end
41         
42         p = length(x); q = length(y);
43         
44         // parsing the optional args
45         opt_arg_list = ["strf", "rect","nax","zminmax", "colminmax", "mesh", "colout"];
46         opt_arg_seq = [];
47         for opt_arg = opt_arg_list
48                 if exists(opt_arg,"local") then
49                         opt_arg_seq = opt_arg_seq +","+ opt_arg + "=" + opt_arg;
50                 end
51         end
52         
53         // build the data for fec
54         z = feval(x,y,f);
55         [noe_x,noe_y] = ndgrid(x,y)
56         nbtri = 2*(p-1)*(q-1)
57         num = (1:p*(q-1))'; num(p*(1:q-1)) = []; num1 = num+1
58         connect =[(1:nbtri)' , [num   num1   num+p;...
59                 num1  num1+p num+p]  ,  zeros(nbtri,1)]
60         
61         // then plot
62         if opt_arg_seq == [] then
63                 fec(noe_x,noe_y,connect,z);
64         else
65                 execstr("fec(noe_x,noe_y,connect,z"+opt_arg_seq+")");
66         end
67 endfunction