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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
// 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]=freq_div(job,arg1,arg2)
x=[];
y=[];
typ=[];
select job
case "set" then
// look for the modulo block
for i=1:length(arg1.model.rpar.objs) do
o = arg1.model.rpar.objs(i);
if typeof(o) == "Block" & o.gui == "Modulo_Count" then
path = i;
break;
end
end
// paths to updatable parameters or states
newpar=list();
y=0;
spath=list()
spath($+1)="model"
spath($+1)="rpar"
spath($+1)="objs"
spath($+1)=path
xx=arg1(spath)// get the block
//execstr('xxn='+xx.gui+'(''set'',xx)')
xxn=xx;
graphics=xx.graphics;
exprs=graphics.exprs
model=xx.model;
while %t do
[ok,%ph,%df,exprs]=scicos_getvalue..
("Set frequency division block parameters",..
["Phase (0 to division factor -1)";"Division factor"],..
list("vec",1,"vec",1),exprs)
if ~ok then
break,
end
if ok then
if %df<1 then
%df=1,
end
%ph=abs(%ph)
if %ph>%df-1 then
%ph=%df-1,
end
graphics.exprs=exprs
model.ipar=%df;
model.dstate=%ph;
xxn.graphics=graphics;
xxn.model=model
break
end
end
if diffobjs(xxn,xx) then
model=xx.model
model_n=xxn.model
if ~is_modelica_block(xx) then
modified=or(model.sim<>model_n.sim)|..
~isequal(model.state,model_n.state)|..
~isequal(model.dstate,model_n.dstate)|..
~isequal(model.rpar,model_n.rpar)|..
~isequal(model.ipar,model_n.ipar)|..
~isequal(model.label,model_n.label)
if or(model.in<>model_n.in)|or(model.out<>model_n.out) then
needcompile=1
end
if or(model.firing<>model_n.firing) then
needcompile=2
end
if model.sim=="input"|model.sim=="output" then
if model.ipar<>model_n.ipar then
needcompile=4
end
end
if or(model.blocktype<>model_n.blocktype)|..
or(model.dep_ut<>model_n.dep_ut) then
needcompile=4
end
if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
needcompile=4
end
if prod(size(model_n.sim))>1 then
if model_n.sim(2)>1000 then
if model.sim(1)<>model_n.sim(1) then
needcompile=4
end
end
end
else
modified=or(model_n<>model)
eq=model.equations;eqn=model_n.equations;
if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
or(eq.outputs<>eqn.outputs) then
needcompile=4
end
end
// parameter or states changed
arg1(spath)=xxn// Update
newpar(size(newpar)+1)=1// Notify modification
y=max(y,needcompile)
end
x=arg1
typ=newpar
case "define" then
scs_m_1=scicos_diagram();
scs_m_1.objs(1) = Modulo_Count("define");
scs_m_1.objs(2) = CLKINV_f("define");
scs_m_1.objs(3) = CLKOUTV_f("define");
scs_m_1.objs(4) = IFTHEL_f("define");
scs_m_1.objs(5) = CLKSPLIT_f("define");
scs_m_1.objs(6) = scicos_link();
scs_m_1.objs(7) = scicos_link();
scs_m_1.objs(8) = scicos_link();
scs_m_1.objs(9) = scicos_link();
scs_m_1.objs(10) = scicos_link();
// Modulo_Count
blk = scs_m_1.objs(1);
graphics = blk.graphics;
model = blk.model;
graphics.orig = [0 -100];
graphics.sz = [60 40];
graphics.exprs = ["0";"3"];
model.dstate = 3;
model.ipar = 3;
graphics.pout = 7;
graphics.pein = 10;
blk.graphics = graphics;
blk.model = model;
scs_m_1.objs(1) = blk;
// CLKINV_f
blk = scs_m_1.objs(2);
graphics = blk.graphics;
model = blk.model;
graphics.orig = [120 0];
graphics.sz = [20 20];
graphics.exprs = ["1"];
model.ipar = 1;
graphics.peout = 6;
blk.graphics = graphics;
blk.model = model;
scs_m_1.objs(2) = blk;
// CLKOUTV_f
blk = scs_m_1.objs(3);
graphics = blk.graphics;
model = blk.model;
graphics.orig = [130 -160];
graphics.sz = [20 20];
graphics.exprs = ["1"];
model.ipar = 1;
graphics.pein = 8;
blk.graphics = graphics;
blk.model = model;
scs_m_1.objs(3) = blk;
// IFTHEL_f
blk = scs_m_1.objs(4);
graphics = blk.graphics;
model = blk.model;
graphics.orig = [100 -100];
graphics.sz = [60 40];
graphics.exprs = ["1";"0"];
model.ipar = 1;
graphics.pin = 7;
graphics.pein = 9;
graphics.peout = [0;8];
blk.graphics = graphics;
blk.model = model;
scs_m_1.objs(4) = blk;
// CLKSPLIT_f
blk = scs_m_1.objs(5);
graphics = blk.graphics;
model = blk.model;
graphics.orig = [127 -33];
graphics.sz = [7 7];
graphics.pein = 6;
graphics.peout = [9;10];
blk.graphics = graphics;
blk.model = model;
scs_m_1.objs(5) = blk;
// CLKINV_f -> CLKSPLIT_f
lnk = scs_m_1.objs(6);
lnk.ct = [5 -1];
lnk.from = [2 1 0];
lnk.to = [5 1 1];
scs_m_1.objs(6) = lnk;
// Modulo_Count -> IFTHEL_f
lnk = scs_m_1.objs(7);
lnk.from = [1 1 0];
lnk.to = [4 1 1];
scs_m_1.objs(7) = lnk;
// IFTHEL_f -> CLKOUTV_f
lnk = scs_m_1.objs(8);
lnk.ct = [5 -1];
lnk.from = [4 2 0];
lnk.to = [3 1 1];
scs_m_1.objs(8) = lnk;
// CLKSPLIT_f -> IFTHEL_f
lnk = scs_m_1.objs(9);
lnk.ct = [5 -1];
lnk.from = [5 1 0];
lnk.to = [4 1 1];
scs_m_1.objs(9) = lnk;
// CLKSPLIT_f -> Modulo_Count
lnk = scs_m_1.objs(10);
lnk.xx = [0 30 1];
lnk.yy = [0 -30 1];
lnk.ct = [5 -1];
lnk.from = [5 2 0];
lnk.to = [1 1 1];
scs_m_1.objs(10) = lnk;
clear blk lnk
model=scicos_model();
model.sim = "csuper";
model.evtin = 1;
model.evtout = 1;
model.rpar = scs_m_1;
gr_i=[];
x=standard_define([3 2],model,[],gr_i)
end
endfunction
|