summaryrefslogtreecommitdiff
path: root/js/Linear/GAINBLK.js
blob: 41106cac53500d6a901c37cd45ffea30bf9536f6 (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
/* autogenerated from "macros/Linear/GAINBLK.sci" */
function GAINBLK() {
    GAINBLK.prototype.define = function GAINBLK() {
        this.gain = 1;
        in1 = -1;
        out = -1;
        in2 = -2;
        out2 = -2;
        model = scicos_model();
        model.sim = list("gainblk",4);
        model.in1 = in1;
        model.out = out;
        model.in2 = in2;
        model.out2 = out2;
        model.rpar = this.gain;
        model.blocktype = "c";
        model.dep_ut = [true,false];
        exprs = [strcat(sci2exp(this.gain))];
        gr_i = [];
        this.x = standard_define([2,2],model,exprs,gr_i);
        return new BasicBlock(this.x);
    }
    GAINBLK.prototype.details = function GAINBLK() {
        return this.x;
    }
    GAINBLK.prototype.get = function GAINBLK() {
        var options = {
            gain:["Gain",this.gain],
            over:["Do On Overflow(0=Nothing 1=Saturate 2=Error)",this.over],
        }
        return options;
    }
    GAINBLK.prototype.set = function GAINBLK() {
        this.gain = parseFloat(arguments[0]["gain"])
        this.over = arguments[0]["over"]
        this.x = arg1;
        graphics = arg1.graphics;
        exprs = graphics.exprs;
        model = arg1.model;
        if (size(exprs,"*")==1) {
            exprs = [[exprs],[sci2exp(0)]];
        }
        while (true) {
            [ok,this.gain,this.over,exprs] = scicos_getvalue("Set gain block parameters",["Gain","Do On Overflow(0=Nothing 1=Saturate 2=Error)"],list("mat",[-1,-1],"vec",1),exprs);
            if (!ok) {
                break;
            }
            if (this.gain==[]) {
                message("Gain must have at least one element");
            } else {
                if (typeof(this.gain)=="constant") {
                    if (isreal(this.gain)) {
                        it = 1;
                        ot = 1;
                        model.sim = list("gainblk",4);
                        model.rpar = this.gain.slice();
                        model.opar = list();
                    } else {
                        message("type is not supported");
                        ok = false;
                    }
                } else {
                    if ((this.over==0)) {
                        if ((typeof(this.gain)=="int32")) {
                            ot = 3;
                            model.sim = list("gainblk_i32n",4);
                        } else if ((typeof(this.gain)=="int16")) {
                            ot = 4;
                            model.sim = list("gainblk_i16n",4);
                        } else if ((typeof(this.gain)=="int8")) {
                            ot = 5;
                            model.sim = list("gainblk_i8n",4);
                        } else if ((typeof(this.gain)=="uint32")) {
                            ot = 6;
                            model.sim = list("gainblk_ui32n",4);
                        } else if ((typeof(this.gain)=="uint16")) {
                            ot = 7;
                            model.sim = list("gainblk_ui16n",4);
                        } else if ((typeof(this.gain)=="uint8")) {
                            ot = 8;
                            model.sim = list("gainblk_ui8n",4);
                        } else {
                            message("type is not supported.");
                            ok = false;
                        }
                    } else if ((this.over==1)) {
                        if ((typeof(this.gain)=="int32")) {
                            ot = 3;
                            model.sim = list("gainblk_i32s",4);
                        } else if ((typeof(this.gain)=="int16")) {
                            ot = 4;
                            model.sim = list("gainblk_i16s",4);
                        } else if ((typeof(this.gain)=="int8")) {
                            ot = 5;
                            model.sim = list("gainblk_i8s",4);
                        } else if ((typeof(this.gain)=="uint32")) {
                            ot = 6;
                            model.sim = list("gainblk_ui32s",4);
                        } else if ((typeof(this.gain)=="uint16")) {
                            ot = 7;
                            model.sim = list("gainblk_ui16s",4);
                        } else if ((typeof(this.gain)=="uint8")) {
                            ot = 8;
                            model.sim = list("gainblk_ui8s",4);
                        } else {
                            message("type is not supported.");
                            ok = false;
                        }
                    } else if ((this.over==2)) {
                        if ((typeof(this.gain)=="int32")) {
                            ot = 3;
                            model.sim = list("gainblk_i32e",4);
                        } else if ((typeof(this.gain)=="int16")) {
                            ot = 4;
                            model.sim = list("gainblk_i16e",4);
                        } else if ((typeof(this.gain)=="int8")) {
                            ot = 5;
                            model.sim = list("gainblk_i8e",4);
                        } else if ((typeof(this.gain)=="uint32")) {
                            ot = 6;
                            model.sim = list("gainblk_ui32e",4);
                        } else if ((typeof(this.gain)=="uint16")) {
                            ot = 7;
                            model.sim = list("gainblk_ui16e",4);
                        } else if ((typeof(this.gain)=="uint8")) {
                            ot = 8;
                            model.sim = list("gainblk_ui8e",4);
                        } else {
                            message("type is not an integer.");
                            ok = false;
                        }
                    } else {
                        message("Do on Overflow must be 0,1,2");
                        ok = false;
                    }
                    model.rpar = [];
                    model.opar = list(this.gain.slice());
                }
                if (ok) {
                    [out,in1] = size(this.gain);
                    if (out*in1!=1) {
                        [model,graphics,ok] = set_io(model,graphics,list([in1,-1],ot),list([out,-1],ot),[],[]);
                    } else {
                        [model,graphics,ok] = set_io(model,graphics,list([-1,-2],ot),list([-1,-2],ot),[],[]);
                    }
                }
                if (ok) {
                    graphics.exprs = exprs;
                    this.x.graphics = graphics;
                    this.x.model = model;
                    break;
                }
            }
        }
        return new BasicBlock(this.x);
    }
}