summaryrefslogtreecommitdiff
path: root/macros/Misc/generic_block3.sci
blob: 1ed616d1aaa0e7d52ca81f293d905d5bc7fb282c (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
//  Scicos
//
//  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See the file ../license.txt
//

function [x,y,typ]=generic_block3(job,arg1,arg2)
    //
    x=[];
    y=[];
    typ=[];
    select job
    case "set" then
        x=arg1
        model=arg1.model;
        graphics=arg1.graphics;
        label=graphics.exprs
        if size(label,"*")==14 then
            label(9)=[],
        end //compatiblity
        while %t do
            [ok,function_name,funtyp,in,it,out,ot,ci,co,xx,z,oz,...
            rpar,ipar,opar,nmode,nzcr,auto0,depu,dept,lab]=..
            scicos_getvalue("Set GENERIC block parameters",..
            ["Simulation function";
            "Function type (0,1,2,..)";
            "Input ports sizes";
            "Input ports type";
            "Output port sizes";
            "Output ports type";
            "Input event ports sizes";
            "Output events ports sizes";
            "Initial continuous state";
            "Initial discrete state";
            "Initial object state";
            "Real parameters vector";
            "Integer parameters vector";
            "Object parameters list";
            "Number of modes";
            "Number of zero crossings";
            "Initial firing vector (<0 for no firing)";
            "Direct feedthrough (y or n)";
            "Time dependence (y or n)"],..
            list("str",1,"vec",1,"mat",[-1 2],"vec",-1,"mat",[-1 2],"vec",-1,"vec",-1,"vec",-1,..
            "vec",-1,"vec",-1,"lis",-1,"vec",-1,"vec",-1,"lis",-1,"vec",1,"vec",1,"vec","sum(%8)",..
            "str",1,"str",1),label)
            if ~ok then
                break,
            end
            label=lab
            function_name=stripblanks(function_name)
            xx=xx(:);
            z=z(:);
            rpar=rpar(:);
            ipar=int(ipar(:));
            ci=int(ci(:));
            co=int(co(:));
            funtyp=funtyp
            if funtyp<0 then
                message("function type cannot be negative");
                ok=%f;
            end
            if [ci;co]<>[] then
                if max([ci;co])>1 then
                    message("vector event links not supported");
                    ok=%f;
                end
            end
            if type(opar)<>15 then
                message("object parameter must be a list");
                ok=%f;
            end
            if type(oz)<>15 then
                message("discrete object state must be a list");
                ok=%f;
            end
            depu=stripblanks(depu);
            if part(depu,1)=="y" then
                depu=%t;
            else
                depu=%f;
            end
            dept=stripblanks(dept);
            if part(dept,1)=="y" then
                dept=%t;
            else
                dept=%f;
            end
            dep_ut=[depu dept];
            if ok then
                [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ci,co)
            end
            if ok then
                if funtyp==3 then
                    needcompile=4;
                end
                model.sim=list(function_name,funtyp);
                model.state=xx
                model.dstate=z
                model.odstate=oz
                model.rpar=rpar
                model.ipar=ipar
                model.opar=opar
                model.firing=auto0
                model.nzcross=nzcr
                model.nmode=nmode
                model.dep_ut=dep_ut
                arg1.model=model
                graphics.exprs=label
                arg1.graphics=graphics
                x=arg1
                break
            end
        end
        needcompile=resume(needcompile)
    case "define" then
        model=scicos_model()
        function_name="sinblk";
        funtyp=4;
        model.sim=list(function_name,funtyp)

        model.in=1
        model.in2=1
        model.intyp=1
        model.out=1
        model.out2=1
        model.outtyp=1
        model.dep_ut=[%t %f]
        label=[function_name;sci2exp(funtyp);
        sci2exp([model.in model.in2]);
        sci2exp(model.intyp);
        sci2exp([model.out model.out2])
        sci2exp(model.outtyp);
        sci2exp(model.evtin);
        sci2exp(model.evtout);
        sci2exp(model.state);
        sci2exp(model.dstate);
        sci2exp(model.odstate);
        sci2exp(model.rpar);
        sci2exp(model.ipar);
        sci2exp(model.opar);
        sci2exp(model.nmode);
        sci2exp(model.nzcross);
        sci2exp(model.firing);"y";"n"];
        gr_i=[]
        x=standard_define([4 2],model,label,gr_i)
    end
endfunction