summaryrefslogtreecommitdiff
path: root/js/Misc/AUTOMAT.js
blob: 27ef497f77c120f6325208d23bd9e18967511cdb (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
/* autogenerated from "macros/Misc/AUTOMAT.sci" */
function AUTOMAT() {
    AUTOMAT.prototype.define = function AUTOMAT() {
        NMode = 2;
        this.Minitial = 1;
        NX = 1;
        this.X0 = [0.0];
        this.XP = [[1],[1]];
        C1 = [2];
        C2 = [1];
        exprs = [[string(NMode)],[string(this.Minitial)],[string(NX)],[sci2exp(this.X0)],[sci2exp(this.XP)],[sci2exp(C1)],[sci2exp(C2)]];
        ipar = [[NMode],[this.Minitial],[NX],[this.XP],[C1],[C2]];
        rpar = [this.X0];
        this.model = scicos_model();
        this.model.sim = list(new ScilabString(["automat"]), new ScilabDouble([10004]));
        this.model.in1 = [[2*NX+1],[2*NX+1]];
        this.model.out = [[2],[2*NX]];
        this.model.state = new ScilabDouble([ones(2*NX,1)]);
        this.model.nzcross = new ScilabDouble([1]);
        this.model.blocktype = new ScilabString(["c"]);
        this.model.evtout = new ScilabDouble([1]);
        this.model.firing = new ScilabDouble([-1]);
        this.model.dep_ut = [false,true];
        this.model.ipar = ipar;
        this.model.rpar = rpar;
        gr_i = [];
        this.x = standard_define([4,2],this.model,exprs,gr_i);
        return new BasicBlock(this.x);
    }
    AUTOMAT.prototype.details = function AUTOMAT() {
        return this.x;
    }
    AUTOMAT.prototype.get = function AUTOMAT() {
        var options = {
        }
        return options;
    }
    AUTOMAT.prototype.set = function AUTOMAT() {
        this.x = arg1;
        graphics = arg1.graphics;
        exprs = graphics.exprs;
        this.model = arg1.model;
        ipar = this.model.ipar;
        NMode = ipar[1-1];
        NX = ipar[3-1];
        while (true) {
            CX = "C1";
            MSG0 = "\'Jump from Mode ";
            MSG2 = ":[..;M_final(Guard=In(";
            MSG3 = ").i);..]\'";
            MSG = MSG0+"1"+MSG2+"1"+MSG3;
            VEC = "\'mat\',[-1,1]";
            for (i=2;i<=NMode;i+=1) {
                CX = CX+","+"C"+string(i);
                MSG = MSG+";"+MSG0+string(i)+MSG2+string(i)+MSG3;
                VEC = VEC+","+"\'mat\',[-1,1]";
            }
            GTV = "[ok,NMode,Minitial,NX,X0,XP,"+CX+",exprs]=scicos_getvalue(\'Set Finite state machine model\',            [\'Number (finite-state) Modes\';\'Initial Mode\';\'Number of continuous-time states\';\'Continuous-time states intial values\';\'Xproperties of continuous-time states in each Mode\';"+MSG+"],            list(\'vec\',1,\'vec\',1,\'vec\',1,\'mat\',[-1,-1],\'mat\',[-1,-1],"+VEC+"),exprs)";
            execstr(GTV);
            if (!this.ok) {
                break;
            }
            NMode_old = size(exprs,"*")-5;
            ModifEncore = false;
            if ((NMode_old>NMode)) {
                exprs.slice(NMode+6-1,NMode_old+5) = [];
                ModifEncore = true;
            }
            if ((NMode_old<NMode)) {
                exprs.slice(NMode_old+6-1,NMode+5) = exprs[NMode_old+4-1];
                ModifEncore = true;
            }
            if ((NX!=size(this.X0,"*"))) {
                messagebox("the size of intial continuous-time states should be NX="+string(NX),"modal","error");
                ModifEncore = true;
            }
            [rXP,cXP] = size(this.XP);
            if (cXP!=NX) {
                messagebox("Xproperty matrix is not valid: it should have NX="+string(NX)+" columns","modal","error");
                ModifEncore = true;
            } else if (((rXP!=NMode)&&(rXP>1))) {
                messagebox("Xproperty matrix is not valid: it should have NMode="+string(NMode)+" or 1 row(s)","modal","error");
                ModifEncore = true;
            } else if ((rXP==1)) {
                for (i=1;i<=NMode-1;i+=1) {
                    this.XP = [[this.XP],[this.XP[1-1].slice()]];
                }
            }
            if ((NMode_old==NMode)&&(!ModifEncore)) {
                this.XP = matrix(transpose(this.XP),NMode*NX,1);
                ipar = [[NMode],[this.Minitial],[NX],[this.XP]];
                rpar = matrix(this.X0,NX,1);
                INP = ones(NMode,1);
                if (NX>0) {
                    OUT = [[2],[2*NX]];
                } else {
                    OUT = [2];
                }
                MaxModes = 1;
                nzcross = 0;
                for (i=1;i<=NMode;i+=1) {
                    Ci = evstr(exprs[5+i-1]);
                    ipar = [[ipar],[Ci]];
                    INP[i-1][1-1] = 2*NX+length(Ci);
                    if ((nzcross<length(Ci))) {
                        nzcross = length(Ci);
                    }
                    if ((MaxModes<max(Ci))) {
                        MaxModes = max(Ci);
                        imax = i;
                    }
                }
                if (MaxModes>NMode) {
                    messagebox([["Number of Modes should be "+string(MaxModes)],["A destination Mode in Mode#"+string(imax)+"\'s targets is invalid!"]],"modal","error");
                    ModifEncore = true;
                }
                if (MaxModes<NMode) {
                    messagebox(["There is an unused Mode or the Number of Modes should be "+string(MaxModes)],"modal","error");
                    ModifEncore = true;
                }
            }
            if (!ModifEncore) {
                [this.model,graphics,this.ok] = check_io(this.model,graphics,INP,OUT,[],[1]);
                if (!this.ok) {
                    break;
                }
                this.model.nzcross = new ScilabDouble([nzcross]);
                this.model.state = new ScilabDouble([ones(2*NX,1)]);
                graphics.gr_i[1-1][1-1] = "txt=[\'Automaton\';\'nM="+string(NMode)+",nX="+string(NX)+"\'];";
                graphics.exprs = exprs;
                this.x.graphics = graphics;
                this.model.ipar = ipar;
                this.model.rpar = new ScilabDouble([rpar]);
                this.x.model = this.model;
                break;
            }
        }
        return new BasicBlock(this.x);
    }
}