summaryrefslogtreecommitdiff
path: root/js/Misc/generic_block3.js
blob: 5ae91823c94ab1fc37a2471ee6156b5b87dcd7ba (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* autogenerated from "macros/Misc/generic_block3.sci" */
function generic_block3() {
    generic_block3.prototype.define = function generic_block3() {
        this.model = scicos_model();
        this.function_name = "sinblk";
        this.funtyp = 4;
        this.model.sim = list(new ScilabString([this.function_name]), new ScilabDouble([this.funtyp]));
        this.model.in = new ScilabDouble([1]);
        this.model.in2 = new ScilabDouble([1]);
        this.model.intyp = new ScilabDouble([1]);
        this.model.out = new ScilabDouble([1]);
        this.model.out2 = new ScilabDouble([1]);
        this.model.outtyp = new ScilabDouble([1]);
        this.model.dep_ut = new ScilabBoolean([true,false]);
        var label = [[this.function_name],[sci2exp(this.funtyp)],[sci2exp([this.model.in,this.model.in2])],[sci2exp(this.model.intyp)],[sci2exp([this.model.out,this.model.out2]),sci2exp(this.model.outtyp)],[sci2exp(this.model.evtin)],[sci2exp(this.model.evtout)],[sci2exp(this.model.state)],[sci2exp(this.model.dstate)],[sci2exp(this.model.odstate)],[sci2exp(this.model.rpar)],[sci2exp(this.model.ipar)],[sci2exp(this.model.opar)],[sci2exp(this.model.nmode)],[sci2exp(this.model.nzcross)],[sci2exp(this.model.firing)],["y"],["n"]];
        var gr_i = new ScilabString(["xstringb(orig(1),orig(2),\"generic_block3\",sz(1),sz(2));"]);
        this.x = new standard_define(new ScilabDouble([4,2]),this.model,new ScilabDouble(label),gr_i);
        return new BasicBlock(this.x);
    }
    generic_block3.prototype.details = function generic_block3() {
        return this.x;
    }
    generic_block3.prototype.get = function generic_block3() {
        var label = this.graphics.exprs;
        if (size(label,"*")==14) {
            label[9-1] = [];
        }
        this.set_param_popup_title = "Set GENERIC block parameters";
        var options = {
            function_name:["Simulation function",this.function_name],
            funtyp:["Function type (0,1,2,..)",this.funtyp],
            in1:["Input ports sizes",this.in1],
            it:["Input ports type",this.it],
            out:["Output port sizes",this.out],
            ot:["Output ports type",this.ot],
            ci:["Input event ports sizes",this.ci],
            co:["Output events ports sizes",this.co],
            xx:["Initial continuous state",this.xx],
            z:["Initial discrete state",this.z],
            oz:["Initial object state",this.oz],
            rpar:["Real parameters vector",this.rpar],
            ipar:["Integer parameters vector",this.ipar],
            opar:["Object parameters list",this.opar],
            nmode:["Number of modes",this.nmode],
            nzcr:["Number of zero crossings",this.nzcr],
            auto0:["Initial firing vector (<0 for no firing)",this.auto0],
            depu:["Direct feedthrough (y or n)",this.depu],
            dept:["Time dependence (y or n)",this.dept],
        }
        return options;
    }
    generic_block3.prototype.set = function generic_block3() {
        var label = this.graphics.exprs;
        if (size(label,"*")==14) {
            label[9-1] = [];
        }
        while (true) {
            var ok = true;
            this.function_name = arguments[0]["function_name"];
            this.funtyp = parseFloat(arguments[0]["funtyp"]);
            this.in1 = arguments[0]["in1"];
            this.it = arguments[0]["it"];
            this.out = arguments[0]["out"];
            this.ot = arguments[0]["ot"];
            this.ci = parseFloat(arguments[0]["ci"]);
            this.co = parseFloat(arguments[0]["co"]);
            this.xx = inverse(arguments[0]["xx"]);
            this.z = inverse(arguments[0]["z"]);
            this.oz = arguments[0]["oz"];
            this.rpar = inverse(arguments[0]["rpar"]);
            this.ipar = parseFloat(arguments[0]["ipar"]);
            this.opar = arguments[0]["opar"];
            this.nmode = arguments[0]["nmode"];
            this.nzcr = arguments[0]["nzcr"];
            this.auto0 = arguments[0]["auto0"];
            this.depu = parseBoolean(arguments[0]["depu"]);
            this.dept = parseBoolean(arguments[0]["dept"]);
            var lab = [arguments[0]["function_name"], arguments[0]["funtyp"], arguments[0]["in1"], arguments[0]["it"], arguments[0]["out"], arguments[0]["ot"], arguments[0]["ci"], arguments[0]["co"], arguments[0]["xx"], arguments[0]["z"], arguments[0]["oz"], arguments[0]["rpar"], arguments[0]["ipar"], arguments[0]["opar"], arguments[0]["nmode"], arguments[0]["nzcr"], arguments[0]["auto0"], arguments[0]["depu"], arguments[0]["dept"]];
            if (!ok) {
                break;
            }
            var label = lab;
            this.function_name = stripblanks(this.function_name);
            this.xx = this.xx.slice();
            this.z = this.z.slice();
            this.rpar = this.rpar.slice();
            this.ipar = int(this.ipar.slice());
            this.ci = int(this.ci.slice());
            this.co = int(this.co.slice());
            this.funtyp = this.funtyp;
            if (this.funtyp<0) {
                message("function type cannot be negative");
                throw "user error";
                var ok = false;
            }
            if ([[this.ci],[this.co]].length!=0) {
                if (max([[this.ci],[this.co]])>1) {
                    message("vector event links not supported");
                    throw "user error";
                    var ok = false;
                }
            }
            if (type(this.opar)!=15) {
                message("object parameter must be a list");
                throw "user error";
                var ok = false;
            }
            if (type(this.oz)!=15) {
                message("discrete object state must be a list");
                throw "user error";
                var ok = false;
            }
            this.depu = stripblanks(this.depu);
            if (part(this.depu,1)=="y") {
                this.depu = true;
            } else {
                this.depu = false;
            }
            this.dept = stripblanks(this.dept);
            if (part(this.dept,1)=="y") {
                this.dept = true;
            } else {
                this.dept = false;
            }
            var dep_ut = [this.depu,this.dept];
            if (ok) {
                var tmpvar0 = set_io(this.model,this.graphics,list(this.in1,this.it),list(this.out,this.ot),this.ci,this.co);
                this.model = tmpvar0[0];
                this.graphics = tmpvar0[1];
                var ok = tmpvar0[2];
            }
            if (ok) {
                if (this.funtyp==3) {
                    var needcompile = 4;
                }
                this.model.sim = list(new ScilabDouble([this.function_name]), new ScilabDouble([this.funtyp]));
                this.model.state = new ScilabDouble(this.xx);
                this.model.dstate = new ScilabDouble(this.z);
                this.model.odstate = new ScilabDouble([this.oz]);
                this.model.rpar = new ScilabDouble(this.rpar);
                this.model.ipar = new ScilabDouble([this.ipar]);
                this.model.opar = new ScilabDouble([this.opar]);
                this.model.firing = new ScilabDouble([this.auto0]);
                this.model.nzcross = new ScilabDouble([this.nzcr]);
                this.model.nmode = new ScilabDouble([this.nmode]);
                this.model.dep_ut = new ScilabBoolean(dep_ut);
                this.graphics.exprs = new ScilabDouble([label]);
                break;
            }
        }
        needcompile = resume(needcompile)
        return new BasicBlock(this.x);
    }
    generic_block3.prototype.get_popup_title = function generic_block3() {
        return this.set_param_popup_title;
    }
    generic_block3.prototype.importset = function generic_block3() {
        var graphics = this.x.graphics;
        var ary = getData(graphics.exprs);
        this.function_name = ary[0];
        this.funtyp = ary[1];
        this.in1 = ary[2];
        this.it = ary[3];
        this.out = ary[4];
        this.ot = ary[5];
        this.ci = ary[6];
        this.co = ary[7];
        this.xx = ary[8];
        this.z = ary[9];
        this.oz = ary[10];
        this.rpar = ary[11];
        this.ipar = ary[12];
        this.opar = ary[13];
        this.nmode = ary[14];
        this.nzcr = ary[15];
        this.auto0 = ary[16];
        this.depu = ary[17];
        this.dept = ary[18];
    }
    generic_block3.prototype.getContainer = function generic_block3() { return new BasicBlock(this.x); }
}