summaryrefslogtreecommitdiff
path: root/js/Linear/INTEGRAL_m.js
blob: f8ea8987c64803ca58c725648f5ec8405e8bfc74 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* autogenerated from "macros/Linear/INTEGRAL_m.sci" */
function INTEGRAL_m() {
    INTEGRAL_m.prototype.define = function INTEGRAL_m() {
        this.maxp = 1;
        var minp = -1;
        var rpar = [];
        this.model = scicos_model();
        this.model.state = new ScilabDouble([0]);
        this.model.sim = list(new ScilabString(["integral_func"]), new ScilabDouble([4]));
        this.model.in = new ScilabDouble([1]);
        this.model.out = new ScilabDouble([1]);
        this.model.in2 = new ScilabDouble([1]);
        this.model.out2 = new ScilabDouble([1]);
        this.model.rpar = new ScilabDouble(rpar);
        this.model.blocktype = new ScilabString(["c"]);
        this.model.dep_ut = new ScilabBoolean([false,true]);
        var exprs = string([[0],[0],[0],[this.maxp],[minp]]);
        var gr_i = new ScilabString(["xstringb(orig(1),orig(2),\"INTEGRAL_m\",sz(1),sz(2));"]);
        this.x = new standard_define(new ScilabDouble([2,2]),this.model,new ScilabString([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() {
        var exprs = this.graphics.exprs;
        this.set_param_popup_title = "Set Integral block parameters";
        var options = {
            x0:["Initial Condition",this.x0],
            reinit:["With re-intialization (1:yes, 0:no)",this.reinit],
            satur:["With saturation (1:yes, 0:no)",this.satur],
            maxp:["Upper limit",this.maxp],
            lowp:["Lower limit",this.lowp],
        }
        return options;
    }
    INTEGRAL_m.prototype.set = function INTEGRAL_m() {
        var exprs = this.graphics.exprs;
        while (true) {
            var ok = true;
            this.x0 = arguments[0]["x0"];
            this.reinit = parseFloat(arguments[0]["reinit"]);
            this.satur = parseFloat(arguments[0]["satur"]);
            this.maxp = parseFloat(arguments[0]["maxp"]);
            this.lowp = parseFloat(arguments[0]["lowp"]);
            var exprs = [arguments[0]["x0"], arguments[0]["reinit"], arguments[0]["satur"], arguments[0]["maxp"], arguments[0]["lowp"]];
            if (!ok) {
                break;
            }
            if (isreal(this.x0)) {
                var Datatype = 1;
            } else {
                var 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");
                        throw "user error";
                        var ok = false;
                    } else if (or(this.maxp<=this.lowp)) {
                        message("Upper limits must be > Lower limits");
                        throw "user error";
                        var ok = false;
                    } else if (or(this.x0>this.maxp)||or(this.x0<this.lowp)) {
                        message("Initial condition x0 should be inside the limits");
                        throw "user error";
                        var ok = false;
                    } else {
                        var rpar = [[real(this.maxp.slice())],[real(this.lowp.slice())]];
                        this.model.nzcross = new ScilabDouble([size(this.x0,"*")]);
                        this.model.nmode = new ScilabDouble([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");
                        throw "user error";
                        var 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");
                        throw "user error";
                        var 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");
                        throw "user error";
                        var ok = false;
                    } else {
                        var rpar = [[real(this.maxp.slice())],[real(this.lowp.slice())],[imag(this.maxp.slice())],[imag(this.lowp.slice())]];
                        this.model.nzcross = new ScilabDouble([2*size(this.x0,"*")]);
                        this.model.nmode = new ScilabDouble([2*size(this.x0,"*")]);
                    }
                }
            } else {
                var rpar = [];
                this.model.nzcross = new ScilabDouble([0]);
                this.model.nmode = new ScilabDouble([0]);
            }
            if (ok) {
                this.model.rpar = new ScilabDouble(rpar);
                if ((Datatype==1)) {
                    this.model.state = new ScilabDouble([real(this.x0.slice())]);
                    this.model.sim = list(new ScilabString(["integral_func"]), new ScilabDouble([4]));
                    var it = [[1],[ones(this.reinit,1)]];
                    var ot = 1;
                } else if ((Datatype==2)) {
                    this.model.state = new ScilabDouble([real(this.x0.slice())],[imag(this.x0.slice())]);
                    this.model.sim = list(new ScilabString(["integralz_func"]), new ScilabDouble([4]));
                    var it = [[2],[2*ones(this.reinit,1)]];
                    var ot = 2;
                } else {
                    message("Datatype is not supported");
                    throw "user error";
                    var ok = false;
                }
                if (ok) {
                    var in1 = [size(this.x0,1)*[[1],[ones(this.reinit,1)]],size(this.x0,2)*[[1],[ones(this.reinit,1)]]];
                    var out = size(this.x0);
                    var tmpvar0 = set_io(this.model,this.graphics,list(in1,it),list(out,ot),ones(this.reinit,1),[]);
                    this.model = tmpvar0[0];
                    this.graphics = tmpvar0[1];
                    var ok = tmpvar0[2];
                }
            }
            if (ok) {
                this.graphics.exprs = new ScilabDouble([exprs]);
                this.x.graphics = this.graphics;
                this.x.model = this.model;
                break;
            }
        }
        return new BasicBlock(this.x);
    }
    INTEGRAL_m.prototype.get_popup_title = function INTEGRAL_m() {
        return this.set_param_popup_title;
    }
    INTEGRAL_m.prototype.importset = function INTEGRAL_m() {
        var graphics = this.x.graphics;
        var ary = getData(graphics.exprs);
        this.x0 = ary[0];
        this.reinit = ary[1];
        this.satur = ary[2];
        this.maxp = ary[3];
        this.lowp = ary[4];
    }
    INTEGRAL_m.prototype.getContainer = function INTEGRAL_m() { return new BasicBlock(this.x); }
}