summaryrefslogtreecommitdiff
path: root/modules/graphics/macros/Sgrayplot.sci
blob: 792f9fe436348feaa353311d008da19d3fad7508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) Bruno Pincon
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function []=Sgrayplot(x,y,z, strf, rect, nax, zminmax, colminmax, mesh, colout)
    //
    // PURPOSE
    //    Like grayplot but the function fec is used to smooth the
    //    result assuming that the underlying function is linear on
    //    a set of triangles built from the grid (here with n1=5, n2=3):
    //             _____________
    //             | /| /| /| /|
    //             |/_|/_|/_|/_|
    //             | /| /| /| /|
    //             |/_|/_|/_|/_|
    //
    // Copyright INRIA
    // Modified by Bruno Pincon (14 oct 04) to have named argument working
    // Some new modifs (Bruno Pincon, Feb 2005, demo + some checking + cleaning + add
    // mesh and colout optional args)

    [lhs,rhs] = argn();

    if rhs == 0 then   // demo

        t=-%pi:0.1:%pi;
        m=sin(t)'*cos(t)
        f=gcf();
        f.color_map = jetcolormap(64);
        f.immediate_drawing = "off";
        colorbar(-1,1);
        Sgrayplot(t,t,m,strf="041",zminmax=[-1,1]);
        xtitle("Sgrayplot demo f(x,y)=sin(x)*cos(y) on [-pi,pi]x[-pi,pi]");
        f.immediate_drawing = "on";
        return

    elseif rhs < 3 then
        error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"Sgrayplot",3));
    end

    // some checks
    if ~(type(x)==1 & isreal(x) & type(y)==1 & isreal(y) & type(z)==1 & isreal(z)) then
        error(msprintf(gettext("%s: Wrong type for input argument(s): Arguments #%d, #%d and #%d must be real.\n"), "Sgrayplot",1,2,3));
    end
    nx = length(x); ny = length(y); [p,q] = size(z)
    if p ~= nx then
        error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: The number of rows of argument #%d must be equal to the size of argument #%d.\n"),"Sgrayplot", 1, 3, 3, 1));
    elseif q~=ny then
        error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d: The number of columns of argument #%d must be equal to the size of argument #%d.\n"),"Sgrayplot", 2, 3, 3, 2));
    end

    // parsing the optional args
    opt_arg_list = ["strf", "rect","nax","zminmax", "colminmax", "mesh", "colout"]
    opt_arg_seq = []
    for opt_arg = opt_arg_list
        if exists(opt_arg,"local") then
            opt_arg_seq = opt_arg_seq +","+ opt_arg + "=" + opt_arg
        end
    end

    // build the data for fec
    [noe_x,noe_y] = ndgrid(x,y)
    nbtri = 2*(p-1)*(q-1)
    num = (1:p*(q-1))'; num(p*(1:q-1)) = []; num1 = num+1
    connect =[(1:nbtri)' , [num   num1   num+p;...
    num1  num1+p num+p]  ,  zeros(nbtri,1)]

    // then plot
    if opt_arg_seq == [] then
        fec(noe_x,noe_y,connect,z)
    else
        execstr("fec(noe_x,noe_y,connect,z"+opt_arg_seq+")")
    end
endfunction