summaryrefslogtreecommitdiff
path: root/js/Linear/INTEGRAL_m.js
blob: ba1620bc1b31c16afbb7a52315dbd70c5ad631e2 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* autogenerated from "macros/Linear/INTEGRAL_m.sci" */
function INTEGRAL_m() {
    INTEGRAL_m.prototype.define = function INTEGRAL_m() {
        this.maxp = 1;
        minp = -1;
        rpar = [];
        model = scicos_model();
        model.state = 0;
        model.sim = list("integral_func",4);
        model.in1 = 1;
        model.out = 1;
        model.in2 = 1;
        model.out2 = 1;
        model.rpar = rpar;
        model.blocktype = "c";
        model.dep_ut = [false,true];
        exprs = string([[0],[0],[0],[this.maxp],[minp]]);
        gr_i = [];
        this.x = standard_define([2,2],model,exprs,gr_i);
        return new BasicBlock(this.x);
    }
    INTEGRAL_m.prototype.details = function INTEGRAL_m() {
        return this.x;
    }
    INTEGRAL_m.prototype.get = function INTEGRAL_m() {
    }
    INTEGRAL_m.prototype.set = function INTEGRAL_m() {
        this.x = arg1;
        graphics = arg1.graphics;
        exprs = graphics.exprs;
        model = arg1.model;
        while (true) {
            [ok,this.x0,this.reinit,this.satur,this.maxp,this.lowp,exprs] = scicos_getvalue("Set Integral block parameters",[["Initial Condition"],["With re-intialization (1:yes, 0:no)"],["With saturation (1:yes, 0:no)"],["Upper limit"],["Lower limit"]],list("mat",[-1,-1],"vec",1,"vec",1,"mat",[-1,-1],"mat",[-1,-1]),exprs);
            if (!ok) {
                break;
            }
            if (isreal(this.x0)) {
                Datatype = 1;
            } else {
                Datatype = 2;
            }
            if (this.reinit!=0) {
                this.reinit = 1;
            }
            if (this.satur!=0) {
                this.satur = 1;
                if (Datatype==1) {
                    if (size(this.maxp,"*")==1) {
                        this.maxp = this.maxp*ones(this.x0);
                    }
                    if (size(this.lowp,"*")==1) {
                        this.lowp = this.lowp*ones(this.x0);
                    }
                    if ((size(this.x0)!=size(this.maxp)||size(this.x0)!=size(this.lowp))) {
                        message("x0 and Upper limit and Lower limit must have same size");
                        ok = false;
                    } else if (or(this.maxp<=this.lowp)) {
                        message("Upper limits must be > Lower limits");
                        ok = false;
                    } else if (or(this.x0>this.maxp)||or(this.x0<this.lowp)) {
                        message("Initial condition x0 should be inside the limits");
                        ok = false;
                    } else {
                        rpar = [[real(this.maxp.slice())],[real(this.lowp.slice())]];
                        model.nzcross = size(this.x0,"*");
                        model.nmode = size(this.x0,"*");
                    }
                } else if ((Datatype==2)) {
                    if (size(this.maxp,"*")==1) {
                        this.maxp = math.complex(this.maxp*ones(this.x0),(this.maxp*ones(this.x0)));
                    }
                    if (size(this.lowp,"*")==1) {
                        this.lowp = math.complex(this.lowp*ones(this.x0),(this.lowp*ones(this.x0)));
                    }
                    if ((size(this.x0)!=size(this.maxp)||size(this.x0)!=size(this.lowp))) {
                        message("x0 and Upper limit and Lower limit must have same size");
                        ok = false;
                    } else if (or(real(this.maxp)<=real(this.lowp))||or(imag(this.maxp)<=imag(this.lowp))) {
                        message("Upper limits must be > Lower limits");
                        ok = false;
                    } else if (or(real(this.x0)>real(this.maxp))||or(real(this.x0)<real(this.lowp))||or(imag(this.x0)>imag(this.maxp))||or(imag(this.x0)<imag(this.lowp))) {
                        message("Initial condition x0 should be inside the limits");
                        ok = false;
                    } else {
                        rpar = [[real(this.maxp.slice())],[real(this.lowp.slice())],[imag(this.maxp.slice())],[imag(this.lowp.slice())]];
                        model.nzcross = 2*size(this.x0,"*");
                        model.nmode = 2*size(this.x0,"*");
                    }
                }
            } else {
                rpar = [];
                model.nzcross = 0;
                model.nmode = 0;
            }
            if (ok) {
                model.rpar = rpar;
                if ((Datatype==1)) {
                    model.state = real(this.x0.slice());
                    model.sim = list("integral_func",4);
                    it = [[1],[ones(this.reinit,1)]];
                    ot = 1;
                } else if ((Datatype==2)) {
                    model.state = [[real(this.x0.slice())],[imag(this.x0.slice())]];
                    model.sim = list("integralz_func",4);
                    it = [[2],[2*ones(this.reinit,1)]];
                    ot = 2;
                } else {
                    message("Datatype is not supported");
                    ok = false;
                }
                if (ok) {
                    in1 = [size(this.x0,1)*[[1],[ones(this.reinit,1)]],size(this.x0,2)*[[1],[ones(this.reinit,1)]]];
                    out = size(this.x0);
                    [model,graphics,ok] = set_io(model,graphics,list(in1,it),list(out,ot),ones(this.reinit,1),[]);
                }
            }
            if (ok) {
                graphics.exprs = exprs;
                this.x.graphics = graphics;
                this.x.model = model;
                break;
            }
        }
        return new BasicBlock(this.x);
    }
}