summaryrefslogtreecommitdiff
path: root/macros/Misc/scifunc_block.sci
blob: 6407be95c9cecd8acabaa10db058a052479ae412 (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
//  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]=scifunc_block(job,arg1,arg2)
    //%Description
    // job=='set'        : block parameters acquisition
    //                    arg1 is block data structure
    //                    x is returned block data structure
    // job=='define'     : corresponding block data structure initialisation
    //                    arg1: name of block parameters acquisition macro
    //                    x   : block data structure
    //%Block data-structure definition
    // bl=list('Block',graphics,model,init,'standard_block')
    //  graphics=list([xo,yo],[l,h],orient,label)
    //          xo          - x coordinate of block origin
    //          yo          - y coordinate of block origin
    //          l           - block width
    //          h           - block height
    //          orient      - boolean, specifies if block is tilded
    //          label       - string block label
    //  model=list(eqns,#input,#output,#clk_input,#clk_output,state,..
    //             rpar,ipar,typ [,firing])
    //          eqns        - function name (in string form if fortran routine)
    //          #input      - vector of input port sizes
    //          #output     - vector of output port sizes
    //          #clk_input  - vector  of clock inputs port sizes
    //          #clk_output - vector  of clock output port sizes
    //          state       - vector (column) of initial condition
    //          rpar        - vector (column) of real parameters
    //          ipar        - vector (column) of integer parameters
    //          typ         - string: 'c' if block is continuous, 'd' if discrete
    //                        'z' if zero-crossing.
    //          firing      - vector of initial output event firing times
    //
    x=[];
    y=[];
    typ=[];
    select job
    case "set" then
        needcompile=0
        x=arg1
        model=arg1.model;
        graphics=arg1.graphics;
        exprs=graphics.exprs

        if size(exprs(1),"*")==8 then
            exprs(1)(9)="0";
        end
        while %t do
            [ok,i,o,ci,co,xx,z,rpar,auto0,deptime,lab]=scicos_getvalue(..
            ["Set scifunc_block parameters";"only regular blocks supported"],..
            ["input ports sizes";
            "output port sizes";
            "input event ports sizes";
            "output events ports sizes";
            "initial continuous state";
            "initial discrete state";
            "System parameters vector";
            "initial firing vector (<0 for no firing)";
            "is block always active (0:no, 1:yes)"  ],..
            list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,..
            "vec",-1,"vec","sum(%4)","vec",1),exprs(1))
            if ~ok then
                break,
            end
            exprs(1)=lab
            xx=xx(:);
            z=z(:);
            rpar=rpar(:)
            nrp=prod(size(rpar))
            // create simulator
            i=int(i(:));
            ni=size(i,1);
            o=int(o(:));
            no=size(o,1);
            ci=int(ci(:));
            nci=size(ci,1);
            co=int(co(:));
            nco=size(co,1);
            [ok,tt,dep_ut]=genfunc1(exprs(2),i,o,nci,nco,size(xx,1),size(z,1),..
            nrp,"c")
            dep_ut(2)=(1==deptime)
            if ~ok then
                break,
            end
            [model,graphics,ok]=check_io(model,graphics,i,o,ci,co)
            if ok then
                auto=auto0
                model.state=xx
                model.dstate=z
                model.rpar=rpar
                if model.ipar <> 0 then
                    model.opar=model.ipar;
                    model.ipar=0;
                end
                if or(model.opar<>tt) then
                    needcompile=4,
                end
                model.opar=tt
                model.firing=auto
                model.dep_ut=dep_ut
                x.model=model
                exprs(2)=tt
                graphics.exprs=exprs
                x.graphics=graphics
                break
            end
        end
        needcompile=resume(needcompile)
    case "define" then
        in=1
        out=1
        clkin=[]
        clkout=[]
        x0=[]
        z0=[]
        typ="c"
        auto=[]
        rpar=[]

        model=scicos_model()
        model.sim=list("scifunc",3)
        model.in=in
        model.out=out
        model.evtin=clkin
        model.evtout=clkout
        model.state=x0
        model.dstate=z0
        model.rpar=rpar
        model.ipar=0
        model.opar=list()
        model.blocktype=typ
        model.firing=auto
        model.dep_ut=[%t %f]

        exprs=list([sci2exp(in);sci2exp(out);sci2exp(clkin);sci2exp(clkout);
        strcat(sci2exp(x0));strcat(sci2exp(z0));
        strcat(sci2exp(rpar));sci2exp(auto)],..
        list("y1=sin(u1)"," "," ","y1=sin(u1)"," "," "," "))
        gr_i=[]
        x=standard_define([2 2],model,exprs,gr_i)
    end
endfunction