diff options
author | Sunil Shetye | 2018-06-07 17:48:55 +0530 |
---|---|---|
committer | Sunil Shetye | 2018-06-07 17:48:55 +0530 |
commit | 75a3a91595f06a1ac7d8ccc0a1ca0b5cd9552abf (patch) | |
tree | 2b584d8b6062684bd18beab96c5de019bd9c81c9 /macros/Sources | |
parent | f97e60278c61e42308c32047109fcb983ded8dcd (diff) | |
download | sci2js-75a3a91595f06a1ac7d8ccc0a1ca0b5cd9552abf.tar.gz sci2js-75a3a91595f06a1ac7d8ccc0a1ca0b5cd9552abf.tar.bz2 sci2js-75a3a91595f06a1ac7d8ccc0a1ca0b5cd9552abf.zip |
add macros from scicos_blocks from scilab 5.5.2
Diffstat (limited to 'macros/Sources')
33 files changed, 5521 insertions, 0 deletions
diff --git a/macros/Sources/CLKINV_f.sci b/macros/Sources/CLKINV_f.sci new file mode 100644 index 00000000..117cc4fc --- /dev/null +++ b/macros/Sources/CLKINV_f.sci @@ -0,0 +1,70 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=CLKINV_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics + model=arg1.model + + exprs=graphics.exprs + exprs=exprs(1) // compatibility + while %t do + [ok,prt,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "CLKINV_f");" "; .. + gettext("Event input port");" ";], "Port Number", .. + list("vec", 1),exprs); + prt=int(prt) + if ~ok then + break, + end + if prt <= 0 then + block_parameter_error(msprintf(gettext("Wrong values for ''Port Number'' parameter: %d."), prt), .. + gettext("Strictly positive integer expected.")); + else + model.ipar=prt + model.evtout=1 + model.firing=-1//compatibility + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + case "define" then + prt=1 + model=scicos_model() + model.sim="input" + model.evtout=1 + model.ipar=prt + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + exprs=string(prt) + gr_i=[] + x=standard_define([1 1],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/CLKIN_f.sci b/macros/Sources/CLKIN_f.sci new file mode 100644 index 00000000..6c4c1c6d --- /dev/null +++ b/macros/Sources/CLKIN_f.sci @@ -0,0 +1,66 @@ +// 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]=CLKIN_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + model=arg1.model; + + exprs=graphics.exprs + exprs=exprs(1) // compatibility + while %t do + [ok,prt,exprs]=scicos_getvalue("Set Event Input block parameters",.. + "Port number",list("vec",1),exprs) + prt=int(prt) + if ~ok then + break, + end + if prt<=0 then + message("Port number must be a positive integer") + else + model.ipar=prt + model.evtout=1 + model.firing=-1//compatibility + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + case "define" then + prt=1 + model=scicos_model() + model.sim="input" + model.evtout=1 + model.ipar=prt + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + exprs=string(prt) + x=standard_define([1 1],model,exprs," ") + end +endfunction diff --git a/macros/Sources/CLOCK_c.sci b/macros/Sources/CLOCK_c.sci new file mode 100644 index 00000000..02a150b5 --- /dev/null +++ b/macros/Sources/CLOCK_c.sci @@ -0,0 +1,126 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=CLOCK_c(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the evtdly block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "EVTDLY_c" then + path = i; + break; + end + end + newpar=list(); + xx=arg1.model.rpar.objs(path) + exprs=xx.graphics.exprs + model=xx.model; + t0_old=model.firing + dt_old= model.rpar(1) + model_n=model + while %t do + [ok, dt, t0, exprs0]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "CLOCK_c");" "; gettext("Event clock generator");" "; .. + gettext(" Do not start if ''Initialisation Time'' is negative");" "], [gettext("Period");gettext("Initialisation Time")], list("vec",1,"vec",1), exprs); + + if ~ok then + break, + end + if dt <= 0 then + block_parameter_error(msprintf(gettext("Wrong values for ''%s'' parameter: %5.1e."), gettext("Period"), dt), gettext("Strictly positive number expected.")); + ok=%f + end + if ok then + xx.graphics.exprs=exprs0 + model.rpar=[dt;t0] + model.firing=t0 + xx.model=model + arg1.model.rpar.objs(path)=xx// Update + break + end + end + + if ~and([t0_old dt_old]==[t0 dt]) then + // parameter changed + newpar(size(newpar)+1)=path// Notify modification + end + if t0_old<>t0 then + needcompile=2, + else + needcompile=0, + end + x=arg1 + y=needcompile + typ=newpar + case "define" then + evtdly=EVTDLY_c("define") + evtdly.graphics.orig=[320,232] + evtdly.graphics.sz=[40,40] + evtdly.graphics.flip=%t + evtdly.graphics.exprs=["0.1";"0.1"] + evtdly.graphics.pein=6 + evtdly.graphics.peout=3 + evtdly.model.rpar=[0.1;0.1] + evtdly.model.firing=0.1 + + output_port=CLKOUT_f("define") + output_port.graphics.orig=[399,162] + output_port.graphics.sz=[20,20] + output_port.graphics.flip=%t + output_port.graphics.exprs="1" + output_port.graphics.pein=5 + output_port.model.ipar=1 + + split=CLKSPLIT_f("define") + split.graphics.orig=[380.71066;172] + split.graphics.pein=3, + split.graphics.peout=[5;6] + + gr_i=[] + diagram=scicos_diagram(); + diagram.objs(1)=output_port + diagram.objs(2)=evtdly + diagram.objs(3)=scicos_link(xx=[340;340;380.71],.. + yy=[226.29;172;172],.. + ct=[5,-1],from=[2,1],to=[4,1]) + diagram.objs(4)=split + diagram.objs(5)=scicos_link(xx=[380.71;399],yy=[172;172],.. + ct=[5,-1],from=[4,1],to=[1,1]) + diagram.objs(6)=scicos_link(xx=[380.71;380.71;340;340],.. + yy=[172;302;302;277.71],.. + ct=[5,-1],from=[4,2],to=[2,1]) + x=scicos_block() + x.gui="CLOCK_c" + x.graphics.sz=[2,2] + x.graphics.gr_i=gr_i + x.graphics.peout=0 + x.model.sim="csuper" + x.model.evtout=1 + x.model.blocktype="h" + x.model.firing=%f + x.model.dep_ut=[%f %f] + x.model.rpar=diagram + end +endfunction diff --git a/macros/Sources/CLOCK_f.sci b/macros/Sources/CLOCK_f.sci new file mode 100644 index 00000000..9dd1461b --- /dev/null +++ b/macros/Sources/CLOCK_f.sci @@ -0,0 +1,124 @@ +// 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]=CLOCK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the internal edge trigger block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "EVTDLY_f" then + path = i; + break; + end + end + + newpar=list(); + xx=arg1.model.rpar.objs(path)// get the evtdly block + exprs=xx.graphics.exprs + model=xx.model; + t0_old=model.firing + dt_old= model.rpar + model_n=model + while %t do + [ok,dt,t0,exprs0]=scicos_getvalue("Set Clock block parameters",.. + ["Period";"Init time"],list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if dt<=0 then + message("period must be positive") + ok=%f + end + if ok then + xx.graphics.exprs=exprs0 + model.rpar=dt + model.firing=t0 + xx.model=model + arg1.model.rpar.objs(path)=xx// Update + break + end + end + if ~and([t0_old dt_old]==[t0 dt])|~and(exprs0==exprs) then + // parameter changed + newpar(size(newpar)+1)=path// Notify modification + end + if t0_old<>t0 then + needcompile=2, + else + needcompile=0, + end + x=arg1 + y=needcompile + typ=newpar + case "define" then + evtdly=EVTDLY_f("define") + evtdly.graphics.orig=[320,232] + evtdly.graphics.sz=[40,40] + evtdly.graphics.flip=%t + evtdly.graphics.exprs=["0.1";"0.1"] + evtdly.graphics.pein=6 + evtdly.graphics.peout=3 + evtdly.model.rpar=0.1 + evtdly.model.firing=0.1 + + output_port=CLKOUT_f("define") + output_port.graphics.orig=[399,162] + output_port.graphics.sz=[20,20] + output_port.graphics.flip=%t + output_port.graphics.exprs="1" + output_port.graphics.pein=5 + output_port.model.ipar=1 + + split=CLKSPLIT_f("define") + split.graphics.orig=[380.71066;172] + split.graphics.pein=3, + split.graphics.peout=[5;6] + + gr_i=[] + diagram=scicos_diagram(); + diagram.objs(1)=output_port + diagram.objs(2)=evtdly + diagram.objs(3)=scicos_link(xx=[340;340;380.71],.. + yy=[226.29;172;172],.. + ct=[5,-1],from=[2,1],to=[4,1]) + diagram.objs(4)=split + diagram.objs(5)=scicos_link(xx=[380.71;399],yy=[172;172],.. + ct=[5,-1],from=[4,1],to=[1,1]) + diagram.objs(6)=scicos_link(xx=[380.71;380.71;340;340],.. + yy=[172;302;302;277.71],.. + ct=[5,-1],from=[4,2],to=[2,1]) + x=scicos_block() + x.gui="CLOCK_f" + x.graphics.sz=[2,2] + x.graphics.gr_i=gr_i + x.graphics.peout=0 + x.model.sim="csuper" + x.model.evtout=1 + x.model.blocktype="h" + x.model.firing=%f + x.model.dep_ut=[%f %f] + x.model.rpar=diagram + end +endfunction diff --git a/macros/Sources/CONST.sci b/macros/Sources/CONST.sci new file mode 100644 index 00000000..71bf27e5 --- /dev/null +++ b/macros/Sources/CONST.sci @@ -0,0 +1,67 @@ +// 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]=CONST(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,C,exprs]=scicos_getvalue(["Set Contant Block"],.. + "Constant",list("vec",-1),exprs) + if ~ok then + break, + end + sz=size(C); + nout=size(C,"*") + if nout==0 then + message("C must have at least one element") + elseif and(sz > 1) then + message("C matrix is not supported, use CONST_m instead") + else + model.rpar=C(:);model.out=nout + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break; + end + end + case "define" then + C=1 + + model=scicos_model() + model.sim=list("cstblk4",4) + model.in=[] + model.out=1 + model.rpar=C + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=strcat(sci2exp(C)) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/CONST_f.sci b/macros/Sources/CONST_f.sci new file mode 100644 index 00000000..4b931195 --- /dev/null +++ b/macros/Sources/CONST_f.sci @@ -0,0 +1,65 @@ +// 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]=CONST_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs; + model=arg1.model; + while %t do + [ok,C,exprs]=scicos_getvalue(["Set Contant Block"],.. + "Constant",list("vec",-1),exprs) + if ~ok then + break, + end + nout=size(C,"*") + if nout==0 then + message("C must have at least one element") + else + model.rpar=C(:); + model.out=nout; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model; + break; + end + end + case "define" then + C=1 + + model=scicos_model() + model.sim=list("cstblk",1) + model.in=[] + model.out=1 + model.rpar=C + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=strcat(sci2exp(C)) + gr_i=[]; + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/CONST_m.sci b/macros/Sources/CONST_m.sci new file mode 100644 index 00000000..54219034 --- /dev/null +++ b/macros/Sources/CONST_m.sci @@ -0,0 +1,97 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=CONST_m(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok, C, exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "CONST_m");" "; .. + gettext("Constant value generator");" "], gettext("Constant Value"), list("vec", -1), exprs) + + if ~ok then + break, + end + nout=size(C) + if find(nout==0)<>[] then + block_parameter_error(msprintf(gettext("Wrong size for ''%s'' parameter"), gettext("Constant Value")), gettext("Constant value must have at least one element.")); + else + model.sim=list("cstblk4_m",4) + model.opar=list(C) + if (type(C)==1) then + if isreal(C) then + ot=1 + else + ot=2 + end + elseif (typeof(C)=="int32") then + ot=3 + elseif (typeof(C)=="int16") then + ot=4 + elseif (typeof(C)=="int8") then + ot=5 + elseif (typeof(C)=="uint32") then + ot=6 + elseif (typeof(C)=="uint16") then + ot=7 + elseif (typeof(C)=="uint8") then + ot=8 + else + block_parameter_error(msprintf(gettext("Wrong type for ''%s'' parameter"), gettext("Constant Value")), .. + gettext("Value type must be a numeric type (double, complex, int, int8, ...).")); + ok=%f; + end + + if ok then + model.rpar=[] + [model,graphics,ok]=set_io(model,graphics,list(),list(nout,ot),[],[]) + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break; + end + end + end + case "define" then + C=[1] + + model=scicos_model() + model.sim=list("cstblk4",4) + model.in=[] + model.out=size(C,1) + model.in2=[] + model.out2=size(C,2) + model.rpar=C + model.opar=list() + model.blocktype="d" + model.dep_ut=[%f %f] + exprs=sci2exp(C) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/CURVE_c.sci b/macros/Sources/CURVE_c.sci new file mode 100644 index 00000000..d5c87f61 --- /dev/null +++ b/macros/Sources/CURVE_c.sci @@ -0,0 +1,1296 @@ +// Scicos +// +// Copyright (C) INRIA - Masoud Najafi <masoud.najafi@inria.fr> +// Serge Steer <serge.steer@inria.fr> 1993 +// Habib Jreij 1993 +// +// 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]=CURVE_c(job,arg1,arg2) + //** 07/01/2008 : Adapted fot Scilab 5.0 by Simone Mannori + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + + x = arg1; + model = arg1.model; + graphics = arg1.graphics; + exprs = graphics.exprs; + ok = %f; + SaveExit = %f; + + while %t do + Ask_again = %f; + [ok,Method,xx,yy,PeriodicOption,graf,exprs] = scicos_getvalue("Spline data",["Spline"+... + " Method (0..7)";"x";"y";"Periodic signal(y/n)?";"Launch"+... + " graphic window(y/n)?"],list("vec",1,"vec",-1, ... + "vec",-1,"str",1,"str",1),exprs) + if ~ok then + break; + end + + if PeriodicOption=="y" | PeriodicOption=="Y" then + PO=1; + else + exprs(4)="n"; + PO=0; + end + + mtd=int(Method); + if mtd<0 then + mtd=0 + end; + + if mtd>7 then + mtd=7; + end + + METHOD = getmethod(mtd); + + if ~Ask_again then + xx=xx(:); + yy=yy(:); + [nx,mx] = size(xx); + [ny,my]=size(yy); + if ~((nx==ny)&(mx==my)) then + messagebox("Incompatible size of [x] and [y]","modal","error"); + Ask_again = %t; + end + end + + if ~Ask_again then //+++++++++++++++++++++++++++++++++++++++ + xy = [xx,yy]; + [xy] = cleandata(xy); // just for sorting to be able to compare data before and after poke_point(.) + N= size(xy,"r"); + exprs(5)="n";// exprs.graf='n' + + if graf=="y" | graf=="Y" then //_______Graphic editor___________ + ipar=[N;mtd;PO]; + rpar=[]; + + if (winsid() == []) then + curwin = 0; + else + curwin = max(winsid())+1; //** prepare a brand new win + end + //** see below in this file; "poke_point" is very similar to "edit_curv" + [orpar,oipar,ok] = poke_point(xy,ipar,rpar); //** HERE WE ARE +++++++++++++++++++++++++++++++++++ + if ~ok then + break; + end;// exit without save + + // verifying the data change + N2=oipar(1); + xy2=[orpar(1:N2),orpar(N2+1:2*N2)]; + New_methhod=oipar(2); + DChange=%f; + METHOD=getmethod(New_methhod); + if or(xy(:,1)<>xy2(:,1)) then, + DChange=%t; + end + if or(xy(1:N-1,2)<>xy2(1:N2-1,2)) then, + DChange=%t; + end + if (xy(N,2)<>xy2(N2,2) & (METHOD<>"periodic")) then, + DChange=%t; + end + if DChange then + exprs(2)=strcat(sci2exp(xy2(:,1))) + exprs(3)=strcat(sci2exp(xy2(:,2))) + end + + exprs(1)=sci2exp(New_methhod); + if oipar(3)==1 then, + perop="y"; + else, + perop="n"; + end + exprs(4)=perop; + SaveExit=%t + else//_____________________No graphics__________________________ + [Xdummy,Ydummy,orpar]=Do_Spline(N,mtd,xy(:,1),xy(:,2)); + if (METHOD=="periodic") then // periodic spline + xy(N,2)=xy(1,2); + end + if (METHOD=="order 2" | METHOD=="not_a_knot"|METHOD=="periodic" | METHOD=="monotone"| METHOD=="fast" | METHOD=="clamped") then + orpar=[xy(:,1);xy(:,2);orpar]; + else + if (METHOD=="zero order"|METHOD=="linear") + orpar=[xy(:,1);xy(:,2);] + end + end + exprs(1)=sci2exp(mtd);// pour le cas methode>7 | method<0 + oipar=[N;mtd;PO] + SaveExit=%t + end //___________________________________________________________ + end //++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + if (SaveExit) then + xp=find(orpar(1:oipar(1))>=0); + if (xp<>[]) then + model.firing=orpar(xp(1)); //first positive event + else + model.firing=-1; + end + model.rpar=orpar + model.ipar=oipar + graphics.exprs=exprs; + x.model=model + x.graphics=graphics + break + end + end + case "define" then + model=scicos_model() + xx=[0, 1, 2]; + yy=[10, 20, -30]; + N=3; + Method=3; + PeriodicOption="y"; + Graf="n" + model.sim=list("curve_c",4) + model.in=[] + model.out=1 + model.rpar=[xx(:);yy(:)] + model.ipar=[N;Method;1] + model.blocktype="c" + model.dep_ut=[%f %t] + model.evtin=1 + model.evtout=1 + model.firing=0 + exprs=[sci2exp(Method);sci2exp(xx);sci2exp(yy);PeriodicOption;Graf] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + + +function [rpar,ipar,ok] = poke_point(ixy,iparin,rparin) + + [lhs,rhs]=argn(0) + + //** get_click is already defined in "editi_curv" + //in line definition of get_click + deff("[btn,xc,yc,win,Cmenu]=get_click(flag)",[ + "if ~or(winsid() == curwin) then Cmenu = ''Quit'';return,end,"; + "if argn(2) == 1 then"; + " [btn, xc, yc, win, str] = xclick(flag);"; + "else"; + " [btn, xc, yc, win, str] = xclick();"; + "end;"; + "if btn == -1000 then"; + " if win == curwin then"; + " Cmenu = ''Quit'';"; + " else"; + " Cmenu = ''Open/Set'';"; + " end,"; + " return,"; + "end"; + "if btn == -2 then"; + " xc = 0;yc = 0;"; + " try " // added to handle unwanted menu actions in french version + " execstr(''Cmenu='' + part(str, 9:length(str) - 1));"; + " execstr(''Cmenu='' + Cmenu);"; + " catch" + " Cmenu=[]" + " end " + " return,"; + "end"; + "Cmenu=[]"]) + + ok = %f + if rhs==0 then + ixy=[]; + end; + + if size(xy,"c")<2 then + xinfo(" No [y] is provided"); + return + end + + [xy] = cleandata(ixy) + + N = size(xy,"r"); + + if rhs<=1 then + NOrder = 1; + PeridicOption = 0; + ipar = [N;NOrder;PeridicOption] + rpar = [] + else + if rhs==2 then + NOrder = iparin(2); + PeridicOption = iparin(3); + ipar = iparin; + rpar = []; + else + if rhs==3 then + NOrder = iparin(2); + PeridicOption = iparin(3); + ipar = iparin; + rpar = rparin + end + end //** ??? + end //** ??? + + Amp=[]; + wp=[]; + phase=[]; + offset=[]; + np1=[]; + Sin_exprs = list(string(Amp),string(wp), string(phase),string(offset),string(np1)); + sAmp=[]; + sTp=[]; + sdelay=[]; + Sawt1_exprs = list(string(sAmp),string(sTp),string(sdelay)); + sAmp2=[]; + sTp2 = []; + Sawt2_exprs = list(string(sAmp2),string(sTp2)); + + Amp3=[]; + Tp3=[]; + Pw3=[]; + Pd3=[]; + Bias3=[]; + Pulse_exprs=list(string(Amp3), string(Tp3),string(Pw3),string(Pd3),string(Bias3)) + + mean4=[]; + var4=[]; + seed4=[]; + sample4=[]; + np4=[]; + random_n_exprs=list(string(mean4),string(var4), string(seed4),string(sample4),string(np4)) + + min5=[]; + max5=[]; + seed5=[]; + sample5=[]; + np5=[]; + random_u_exprs=list(string(min5), string(max5), string(seed5),string(sample5),string(np5)) + + // bornes initiales du graphique + xmx = max(xy(:,1)); + xmn=min(xy(:,1)), + xmn=max(xmn,0); + ymx = max(xy(:,2)); + ymn=min(xy(:,2)); + dx = xmx-xmn; + dy = ymx-ymn + + if dx==0 then + dx=max(xmx/2,1), + end; + xmx = xmx+dx/50; + + if dy==0 then + dy=max(ymx/2,1), + end; + ymn = ymn-dy/50; + ymx = ymx+dy/50; + + rect = [xmn,ymn;xmx,ymx]; + + // initial draw + f = scf(curwin); + + + menu_r = []; + menu_s = []; + menu_o = ["zero order","linear","order 2","not_a_knot","periodic","monotone","fast","clamped"] + menu_d = ["Clear","Data Bounds","Load from text file","Save to text file","Load from Excel","Periodic signal"] + menu_t=["sine","sawtooth1","sawtooth2","pulse","random normal","random uniform"] + menu_e=["Help","Exit without save","Save/Exit"] + MENU=["Autoscale","Spline","Data","Standards","Exit"]; + menus = list(MENU,menu_s,menu_o,menu_d,menu_t,menu_e); + + scam="menus(1)(1)" + w="menus(3)("; + r=")"; + Orderm=w(ones(menu_o))+string(1:size(menu_o,"*"))+r(ones(menu_o)) + w="menus(4)("; + r=")"; + Datam=w(ones(menu_d))+string(1:size(menu_d,"*"))+r(ones(menu_d)) + w="menus(5)("; + r=")"; + Standm=w(ones(menu_t))+string(1:size(menu_t,"*"))+r(ones(menu_t)) + w="menus(6)("; + r=")"; + Exitm=w(ones(menu_e))+string(1:size(menu_e,"*"))+r(ones(menu_e)) + + execstr("Autoscale_"+string(curwin)+"=scam") + execstr("Spline_"+string(curwin)+"=Orderm") + execstr("Data_"+string(curwin)+"=Datam") + execstr("Standards_"+string(curwin)+"=Standm") + execstr("Exit_"+string(curwin)+"=Exitm") + + addmenu(curwin,MENU(1)) + addmenu(curwin,MENU(2),menu_o) + addmenu(curwin,MENU(3),menu_d) + addmenu(curwin,MENU(4),menu_t) + addmenu(curwin,MENU(5),menu_e) + //=================================================================== + + drawlater(); + a = gca(); + a.data_bounds = rect; + a.axes_visible = "on"; + a.clip_state = "on"; + xtitle( "", "time", "Output" ) ; + a.title.font_size=2; + a.title.font_style=4; + a.title.foreground=2; + + a.grid=[2 2]; + xpolys(xy(:,1),xy(:,2),[-1]); //children(2) + xpolys(xy(:,1),xy(:,2),[5]); //children(1) + splines = a.children(1).children + points = a.children(2).children + //--------------------------------------- + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + drawnow(); + // -- boucle principale + + lines(0); + while %t then //================================================= + N = size(xy,"r"); + [btn,xc,yc,win,Cmenu] = get_click(); //** see + if ((win>0) & (win<>curwin)) then + Cmenu="Mouse click is Offside!"; + end + if Cmenu==[] then + Cmenu="edit", + end + if (Cmenu=="Exit") |(Cmenu=="Quit" ) then, + ipar=[]; + rpar=[]; + ok=%f; + return; + end + //------------------------------------------------------------------- + if ((Cmenu=="zero order") | (Cmenu=="linear") | (Cmenu=="order 2")| ... + (Cmenu=="not_a_knot")| (Cmenu=="periodic")| (Cmenu=="monotone")| ... + (Cmenu=="fast")| (Cmenu=="clamped")) then + + select Cmenu + case "zero order" then + NOrder=0; + case "linear" then + NOrder=1; + case "order 2" then + NOrder=2; + case "not_a_knot" then + NOrder=3; + case "periodic" then + NOrder=4; + case "monotone" then + NOrder=5; + case "fast" then + NOrder=6; + case "clamped" then + NOrder=7; + end + ipar(2)=NOrder; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + end + //------------------------------------------------------------------- + select Cmenu + case "Data Bounds" then + rectx=findrect(a); + [mok, xmn1, xmx1, ymn1, ymx1] = scicos_getvalue("Enter new bounds",["xmin";"xmax"; "ymin";"ymax"], .. + list("vec", 1,"vec", 1,"vec", 1,"vec", 1), string(rectx(:))) + //drawlater(); + if mok then + if (xmn1 > xmx1 | ymn1 > ymx1) then + xinfo("Incorrect bounds") + mok=%f; + end + if xmn1<0 then + xinfo("X should be positive") + mok=%f; + end + if mok then + a.data_bounds=[xmn1, ymn1; xmx1, ymx1]; + end + end + //drawnow(); + //------------------------------------------------------------------- + case "Autoscale" then + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + //------------------------------------------------------------------- + case "Periodic signal" then + if PeridicOption==1 then, + ans0="y", + else, + ans0="n", + end; + [mok,myans]=scicos_getvalue("Generating periodic signal",["y/n"],list("str",1),list(ans0)); + if ((myans=="y")|(myans=="Y")) then, + PeridicOption=1, + else, + PeridicOption=0; + end; + ipar(3)=PeridicOption; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + //------------------------------------------------------------------- + case "sine" then + [mok,Amp,wp,phase,offset,np1,Sin_exprs2]=scicos_getvalue(" Sine parameters", ... + ["Amplitude";"Frequency(rad/sec)"; ... + "Phase(rad)";"Bias";"number of points"],list("vec",1,"vec",1,"vec",1, ... + "vec",1,"vec",1),Sin_exprs) + if np1< 2 then + np1=2; + end + if mok & wp>0 then + NOrder=3; + ipar(2)=NOrder; + phase=atan(tan(phase)); + xt=linspace(0,%pi*2/wp,np1)'; + yt=Amp*sin(wp*xt+phase)+offset; + xy=[xt,yt]; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + Sin_exprs=Sin_exprs2 + end + //------------------------------------------------------------------- + case "sawtooth1" then + [mok,sAmp,sTp,sdelay,Sawt1_exprs2]=scicos_getvalue("Sawtooth signal parameters", ... + ["Amplitude";"Period";"delay"], ... + list("vec",1,"vec",1,"vec",1),Sawt1_exprs) + if mok & sTp>0 then + NOrder=1; + ipar(2)=NOrder; + if sdelay<sTp then + xt=[0;sdelay;sTp]; + yt=[0;0;sAmp]; + else + xt=[0]; + yt=[0]; + end + xy=[xt,yt]; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar); + Sawt1_exprs=Sawt1_exprs2 + end + //------------------------------------------------------------------- + case "sawtooth2" then + [mok,sAmp2,sTp2,Sawt2_exprs2]=scicos_getvalue("Sawtooth signal parameters", ... + ["Amplitude";"Period"],list("vec",1,"vec",1),Sawt2_exprs) + if mok & sTp2>0 then + NOrder=1; + ipar(2)=NOrder; + xt=[0;sTp2]; + yt=[sAmp2;-sAmp2]; + xy=[xt,yt]; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar); + Sawt2_exprs=Sawt2_exprs2 + end + //------------------------------------------------------------------- + case "pulse" then + [mok,Amp3,Tp3,Pw3,Pd3,Bias3,Pulse_exprs2] = scicos_getvalue("Square wave pulse signal", ... + ["Amplitude";"Period (sec)";"Pulse width(% o"+... + "f period)";"Phase delay (sec)";"Bias"],list("vec",1, ... + "vec",1,"vec",1,"vec",1,"vec",1),Pulse_exprs); + if mok & Tp3>0 then + NOrder=0; + ipar(2)=NOrder; + if (Pd3>0) then + xt=0; + yt=Bias3; + else + xt=[]; + yt=[]; + end + //otherwise there would be double points at 0 + if Pd3<Tp3 then + if Pw3>0 then + xt=[xt;Pd3; Pw3*Tp3/100+Pd3;Tp3]; + yt=[yt;Amp3+Bias3;Bias3;Bias3]; + else + xt=[0;Tp3];yt=[Bias3;Bias3]; + end + else + xt=[0;Tp3];yt=[Bias3;Bias3]; + end + + xy=[xt,yt]; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar); + Pulse_exprs=Pulse_exprs2; + end + //------------------------------------------------------------------- + case "random normal" then + [mok,mean4,var4,seed4,sample4,np4,random_n_exprs2]=scicos_getvalue("Normal (Gaussian) random signal", ... + ["Mean";"Variance";"Initial seed";"Sample time";"Number of points"],list("vec",1, ... + "vec",1,"vec",1,"vec", ... + 1,"vec",1),random_n_exprs) + if mok & sample4>0 then + NOrder=0; + ipar(2)=NOrder; + rand("normal"); + rand("seed",seed4); + xt=0:sample4:sample4*(np4-1); + xt=xt(:); + yt=mean4+sqrt(var4)*rand(np4,1); + xy=[xt,yt]; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar); + random_n_exprs2=random_n_exprs; + end + //------------------------------------------------------------------- + case "random uniform" then + [mok,min5,max5,seed5,sample5,np5,random_u_exprs2]=scicos_getvalue("Uniform random signal", ... + ["Minimum";"Maximum";"Initial seed";"Sample time";"Number of points"],list("vec",1, ... + "vec",1,"vec",1,"vec", ... + 1,"vec",1),random_u_exprs) + if mok & sample5>0 then + NOrder=0; + ipar(2)=NOrder; + rand("uniform"); + rand("seed",seed5); + xt=0:sample5:sample5*(np5-1); + xt=xt(:); + yt=min5+(max5-min5)*rand(np5,1); + xy=[xt,yt]; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar); + random_u_exprs2=random_u_exprs; + + end + //------------------------------------------------------------------- + case "Save/Exit" then + NOrder=ipar(2); + PeridicOption=ipar(3); + + METHOD=getmethod(NOrder); + if (METHOD=="periodic") then // periodic spline + xy(N,2)=xy(1,2); + end + + if (METHOD=="order 2" | METHOD=="not_a_knot"|METHOD=="periodic" | METHOD=="monotone"| METHOD=="fast" | METHOD=="clamped") then + rpar=[xy(:,1);xy(:,2);rpar]; + else + if (METHOD=="zero order"|METHOD=="linear") + rpar=[xy(:,1);xy(:,2);] + end + end + + ok=%t + delete(f); + return + //------------------------------------------------------------------- + case "Exit without save" then + ipar=[]; + rpar=[]; + ok=%f + delete(f); + return + //------------------------------------------------------------------- + case "Clear" then + xy=[0,0]; + NOrder=0; + ipar(2)=NOrder; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + //---------------------------------------------------------------- + case "Edit text data NOT IN USE" then + // editvar xy; + [mok,xt,yt]=scicos_getvalue("Enter x and y data",["x";"y"],list("vec",-1,"vec",-1),list(strcat(sci2exp(xy(:,1))),strcat(sci2exp(xy(:,2))))); + if mok then, + xy=[xt,yt]; + [xy]=cleandata(xy), + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + end + //--------------------------------------------------------------- + case "Help" then + t1="Mouse-left click: adding a new point" + t2="Mouse-right click: remove a point" + t3="Mouse-left double click: edit a point''s coordinates" + t4="Mouse-left button press/drag/release: move a point" + t5="Change the window size: ''Data'' menu -> ''Databounds''" + messagebox([t1;t2;t3;t4;t5],"modal","info"); + //--------------------------------------------------------------- + case "Load from Excel" then + [tok,xytt]=ReadExcel() + if tok then + xy=xytt; + NOrder=1 + ipar(2)=NOrder; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + end + //--------------------------------------------------------------- + case "Load from text file" then + [tok,xytt]=ReadFromFile() + if tok then + xy=xytt; + NOrder=1 + ipar(2)=NOrder; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + end + //--------------------------------------------------------------- + case "Save to text file" then + [sok]=SaveToFile(xy) + //--------------------------------------------------------------- + case "Replot" then + if xy<>[] then + drawlater(); + points.data=xy; + [rpar,ipar]=drawSplin(a,xy,ipar,rpar); + drawnow() + end + //---------------------------------------------------------- + case "edit" then + HIT=%f + if N<>0 then + xt=xy(:,1); + yt=xy(:,2); + dist=((xt-ones(N,1)*xc))^2+((yt-ones(N,1)*yc))^2 + [dca,k]=min(dist); + rectx=a.data_bounds; + ex=abs(rectx(2,1)-rectx(1,1))/80; + ey=abs(rectx(2,2)-rectx(1,2))/80; + if (abs(xc-xt(k))<ex & abs(yc-yt(k))<ey) then + HIT=%t + end + end + + //_________________________ + // if ~((NOrder==-1|NOrder==-2|NOrder==-3|NOrder==-4)) then + if (~HIT)&(btn==0 | btn==3) then // add point + if (xc>=0) then + if (xc==0) then + zz=find(x==0); + xy(zz,:)=[]; + end + xy=[xy;xc,yc]; + [xtt,k2]=gsort(xy(:,1),"r","i");xy=xy(k2,:) + drawlater(); + points.data=xy; + [rpar,ipar]=drawSplin(a,xy,ipar,rpar); + drawnow(); + end + end + + if (HIT)&(btn==2 | btn==5) then // remove point + if (xy(k,1)>0) |( xy(k,1)==0 & (size(find(xy(:,1)==0),"*")>1)) then + xy(k,:)=[]; + end + drawlater(); + points.data = xy; + [rpar,ipar] = drawSplin(a,xy,ipar,rpar); + drawnow(); + end + + if (HIT)&(btn==0) then // move point + [xy,rpar,ipar] = movept(a,xy,ipar,rpar,k) + end + + if (HIT)&(btn==10) then // change data:: double click + [mok,xt,yt]=scicos_getvalue("Enter new x and y",["x";"y"],... + list("vec",1,"vec",1),list(sci2exp(xy(k,1)),sci2exp(xy(k,2)))); + if mok then + xy(k,:) = [xt,yt]; + [xy] = cleandata(xy) + drawlater(); + points.data=xy; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + drawnow() + end + end + + // end + //_________________________________ + + end + //---------------------------------------------------------- + end +endfunction +//======================================================================== +function [orpar,oipar] = drawSplin(a,xy,iipar,irpar) + N=size(xy,"r");// new size of xy + x=xy(:,1); + y=xy(:,2); + points=a.children(2).children + splines=a.children(1).children + order=iipar(2); + periodicoption=iipar(3); + orpar=irpar; + + METHOD=getmethod(order); + + if periodicoption==1 then + PERIODIC="periodic, T="+string(x(N)-x(1)); + else + PERIODIC="aperiodic"; + end + a.title.text=[string(N)+" points, "+"Method: "+METHOD+", "+PERIODIC]; + + if (N==0) then, + return; + end + if (N==1) then, + order=0; + end + // NP=50;// number of intermediate points between two data points + [X,Y,orpar]=Do_Spline(N,order,x,y); + if (periodicoption==1) then + X=[X;X($)]; + Y=[Y;Y(1)]; + else + xmx=max(points.data(:,1)); xmn=min(points.data(:,1)); + XMX=max(0,xmx); + XMN=max(0,xmn); + xmx1=max(a.x_ticks.locations) + XMX=max(XMX,xmx1); + X=[X;XMX]; + Y=[Y;Y($)]; + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + splines.data=[X,Y]; + oipar=[N;iipar(2);periodicoption] +endfunction +//============================================================= +function [xyt,orpar,oipar]=movept(a,xy,iipar,irpar,k) + //on bouge un point existant + points=a.children(2).children + splines=a.children(1).children + oipar=iipar + orpar=irpar + order=iipar(2); + x=xy(:,1); + y=xy(:,2); + + if (x(k)==0) then + zz=find(x==0); + x(zz)=[]; + y(zz)=[]; + ZERO_POINT=%t + else + x(k)=[]; + y(k)=[]; + ZERO_POINT=%f + end + + btn=-1 + + while ~(btn==3 | btn==0| btn==10| btn==-5) + rep=xgetmouse([%t %t]); xc=rep(1);yc=rep(2);btn=rep(3); + if (ZERO_POINT) then + xc=0; + else + if (xc<=0) then + zz=find(x==0); + x(zz)=[]; + y(zz)=[]; + ZERO_POINT=%t; + xc=0; + end + end + + xt=[x;xc]; + yt=[y;yc]; + [xt,k2]=gsort(xt,"r","i");yt=yt(k2) + xyt=[xt,yt]; + + drawlater(); + points.data=xyt; + [orpar,oipar]=drawSplin(a,xyt,oipar,orpar); + drawnow() + end + +endfunction + +//========================================================== +function rectx = findrect(a) + splines=a.children(1).children + points=a.children(2).children + + if (points.data==[]) then + rectx=a.data_bounds; + return; + end + + + ymx1=max(splines.data(:,2)); + ymn1=min(splines.data(:,2)) + + xmx=max(points.data(:,1)); + xmn=min(points.data(:,1)); + ymx=max(points.data(:,2)); + ymn=min(points.data(:,2)); + + + XMX=max(0,xmx); + XMN=max(0,xmn); + YMX=max(ymx,ymx1); + YMN=min(ymn,ymn1); + + dx=XMX-XMN; + dy=YMX-YMN + if dx==0 then + dx=max(XMX/2,1), + end; + XMX=XMX+dx/50 + if dy==0 then + dy=max(YMX/2,1), + end; + YMN=YMN-dy/50; + YMX=YMX+dy/50; + rectx=[XMN,YMN;XMX,YMX]; +endfunction + +//============================================================ +function [tok,xyo]=ReadExcel() + TA=["A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P"; ... + "Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z";"a";"b";"c";"d";"e";"f"; ... + "g";"h";"i";"j";"k";"l";"m";"n";"o";"p";"q";"r";"s";"t";"u";"v"; ... + "w";"x";"y";"z"]; + TN=["0","1","2","3","4","5","6","7","8","9"]; + xyo=[]; + tok=%f; + while %t + [zok,filen,sheetN,xa,ya]=scicos_getvalue("Excel data file ",["Filename";"Sheet #"+... + " ";"X[start:Stop]";"Y[start:stop]"],list("str",1, ... + "vec",1,"str",1, ... + "str",1), ... + list(["Classeur1.xls"],["1"],["C5:C25"],["D5:D25"])); + if ~zok then + break, + end + + try + [fd,SST,Sheetnames,Sheetpos] = xls_open(filen); + catch + xinfo("Scicos cannot find the excel file:"+filen); + break; + end + try + N=size(Sheetnames,"*"); + if ((sheetN<=N) &(sheetN>0)) then + [Value,TextInd] = xls_read(fd,Sheetpos(sheetN)) + mclose(fd) + end + xa=strsubst(xa," ",""); + px=strindex(xa,":"); + ya=strsubst(ya," ",""); + py=strindex(ya,":"); + x1=part(xa,1:px-1); + x2=part(xa,px+1:length(xa)); + y1=part(ya,1:py-1); + y2=part(ya,py+1:length(ya)); + + x1p=min(strindex(x1,TN)); + if x1p==[] then, + xinfo("Bad address in X:"+x1); + break, + end + x11=part(x1,1:x1p-1); + x12=part(x1,x1p:length(x1)); + + x2p=min(strindex(x2,TN)); + if x2p==[] then, + xinfo("Bad address in X:"+x2); + break, end + x21=par + t(x2,1:x2p-1); + x22=part(x2,x2p:length(x2)); + + y1p=min(strindex(y1,TN)); + if y1p==[] then, + xinfo("Bad address in Y:"+y1); + break, + end + y11=part(y1,1:y1p-1); + y12=part(y1,y1p:length(y1)); + + y2p=min(strindex(y2,TN)); + if y2p==[] then, + xinfo("Bad address in Y:"+y2); + break, + end + y21=part(y2,1:y2p-1); + y22=part(y2,y2p:length(y2)); + + // x11 x12: x21 x22 + + lx11=length(x11); + lx21=length(x21); + ly11=length(y11); + ly21=length(y21) + xstC=0; + for i=1:lx11, + xstC=xstC+modulo(find(TA==part(x11,lx11-i+1)),26)*26^(i-1); + end + xenC=0; + for i=1:lx21, + xenC=xenC+modulo(find(TA==part(x21,lx21-i+1)),26)*26^(i-1); + end + ystC=0; + for i=1:ly11, + ystC=ystC+modulo(find(TA==part(y11,ly11-i+1)),26)*26^(i-1); + end + yenC=0; + for i=1:ly11, + yenC=yenC+modulo(find(TA==part(y21,ly21-i+1)),26)*26^(i-1); + end + + xstR=evstr(x12); + xenR=evstr(x22); + ystR=evstr(y12); + yenR=evstr(y22); + + [mv,nv]=size(Value) + + if ~(xstR<=mv & xstR>0 & xenR<=mv & xenR>0&ystR<=mv & ystR>0¥R<=mv¥R>0 ) then + xinfo("error in Row data addresses"); + break + end + if ~(xstC<=nv & xstC>0 & xenC<=nv & xenC>0&ystC<=nv & ystC>0¥C<=nv¥C>0 ) then + xinfo("error in Column data addresses"); + break + end + + xo=Value(min(xstR,xenR):max(xstR,xenR),min(xstC,xenC):max(xstC,xenC)); + yo=Value(min(ystR,yenR):max(ystR,yenR),min(ystC,yenC):max(ystC,yenC)); + [nx,mx]=size(xo);// adjusting the x and y size + [ny,my]=size(yo); + N=min(nx,ny); + xo=xo(1:N,:); + yo=yo(1:N,:); + + xyo=[xo,yo]; + [xyo]=cleandata(xyo) + + tok=%t; + break, + catch + xinfo(" Scicos cannot read your Excel file, please verify"+... + " the parameters "); + break + end + end + +endfunction +//--------------------------------------------------------------- +function [xyo]=cleandata(xye) + xe=xye(:,1) + ye=xye(:,2) + + [nx,mx]=size(xe);// adjusting the x and y size + [ny,my]=size(ye); + N=min(nx,ny); + xe=xe(1:N,:); + ye=ye(1:N,:); + + // checking for NULL data + for i=1:N + if (xe(i)<>xe(i)) then + xinfo("x contains no data:x("+string(i)+")"); + return; + end + if (ye(i)<>ye(i)) then + xinfo("Y contains no data:y("+string(i)+")"); + return; + end + end + zz=find(xe<0); + xe(zz)=[]; + ye(zz)=[] + if (find(xe==0)==[]) then // add zero point + xe($+1)=0; + ye($+1)=0; + end + + [xo,k2]=gsort(xe,"r","i"); + yo=ye(k2) + + xyo=[xo,yo]; +endfunction +//--------------------------------------------------------------- +function [orpar,oipar] = AutoScale(a,xy,inipar,inrpar) + drawlater(); + oipar = inipar + orpar = inrpar + points = a.children(2).children + splines = a.children(1).children + points.data = xy; + splines.data = xy; + [orpar,oipar] = drawSplin(a,xy,oipar,orpar); + rectx=findrect(a); + a.data_bounds = rectx; + drawnow() +endfunction +//============================ +function METHOD = getmethod(order) + select order + case 0 then, + METHOD="zero order" + case 1 then, + METHOD="linear" + case 2 then, + METHOD="order 2" + case 3 then, + METHOD="not_a_knot" + case 4 then, + METHOD="periodic" + case 5 then, + METHOD="monotone" + case 6 then, + METHOD="fast" + case 7 then, + METHOD="clamped" + end +endfunction +//======================================= +function [sok,xye] = ReadFromFile() + xye=[];sok=%f; + while %t + [sok,filen,Cformat,Cx,Cy]=scicos_getvalue("Text data file ",["Filename";"Reading [C] f"+... + "ormat";"Abscissa column";"Output"+... + " column"],list("str",1,"str",1,"vec",1,"vec",1), ... + list(["mydatafile.dat"],["%g %g"],["1"],["2"])); + if ~sok then + break, + end + px=strindex(Cformat,"%"); + NC=size(px,"*"); + if NC==[] then, + xinfo("Bad format in reading data file"); + sok=%f; + break; + end + Lx=[]; + try + fd=mopen(filen,"r"); + Lx=mfscanf(-1,fd,Cformat); + mclose(fd); + catch + xinfo("Scicos cannot open the data file: " + filen); + break; + end + + [nD,mD] = size(Lx); + if ((mD==0) | (nD==0)) then, + xinfo("No data read"); + sok=%f; + break; + end + if (mD<>NC) then, + xinfo("Bad format"); + sok=%f; + break; + end + + xe=Lx(:,Cx); + ye=Lx(:,Cy); + xye=[xe,ye]; + [xye]=cleandata(xye) + sok=%t; + break, + end +endfunction +//======================================= +function [sok]=SaveToFile(xye) + xe=xye(:,1) + ye=xye(:,2) + sok=%f; + while %t + [sok,filen,Cformat]=scicos_getvalue("Text data file ",["Filename";"Writing [C] f"+... + "ormat"],list("str",1,"str",1), ... + list(["mydatafile.dat"],["%g %g"])); + if ~sok then + break, + end + px=strindex(Cformat,"%"); + NC=size(px,"*"); + if NC<>2 then, + xinfo("Bad format in writing data file"); + sok=%f; + break; + end + + Cformat=Cformat+"\n"; + + try + fd=mopen(filen,"w"); + mfprintf(fd,Cformat,xe,ye); + mclose(fd); + catch + xinfo("Scicos cannot open the data file:"+filen); + break; + end + + sok=%t; + break, + end +endfunction +//========================================================= +function [X,Y,orpar]=Do_Spline(N,order,x,y) + X=[]; + Y=[]; + orpar=[]; + + METHOD=getmethod(order); + + if (METHOD=="zero order") then + X=x(1); + Y=y(1); + for i=1:N-1 + X=[X;x(i);x(i+1);x(i+1)]; + Y=[Y;y(i);y(i);y(i+1)]; + end + return + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="linear") then + X=[]; + for i=1:N + X=[X;x(i)]; + Y=[Y;y(i)]; + end + return + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (N<25) then + NP=10; + else + if (N<50) then + NP=5; + else + if (N<100) then + NP=2; + else + if (N<200) then + NP=1; + else + NP=0; + end; + end; + end; + end + for i=1:N-1 + X=[X;linspace(x(i),x(i+1),NP+2)']; // pour tous sauf "linear" et "zero order" + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (N>2) & (METHOD=="order 2") then + Z=ORDER2(x,y); + A=Z(1:N-1); + B=Z(N:2*N-2); + C=Z(2*N-1:3*N-3); + + for j=1:size(X,"*") + for i=N-1:-1:1 + if X(j)>=x(i) then, + break; + end + end + Y(j)=A(i)*(X(j)-x(i))^2+B(i)*(X(j)-x(i))+C(i); + end + orpar=matrix(Z,-1,1) + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="not_a_knot") then + try + d = splin(x, y, METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="periodic") then + if y(1)<>y(N) then + y(N)=y(1) + end + try + d = splin(x, y,METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="monotone" ) then + try + d = splin(x, y, METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="fast") then + try + d = splin(x, y, METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="clamped") then + try + d = splin(x, y, METHOD,[0;0]); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + end + +endfunction +//================================================= +function [Z]=ORDER2(x,y) + N=size(x,"*")-1; + A=zeros(3*N-1,N*3); + B=zeros(3*N-1,1); + for i=1:N + j=3*(i-1)+1; + A(j,i+2*N)=1; + B(j)=y(i); + A(j+1,i)=(x(i+1)-x(i))^2; + A(j+1,i+N)=x(i+1)-x(i); + A(j+1,i+2*N)=1; + B(j+1)=y(i+1); + end + + for i=1:N-1 + j=3*(i-1)+1; + A(j+2,i)=2*(x(i+1)-x(i)); + A(j+2,i+N)=1; + A(j+2,i+N+1)=-1; + end + + Q=zeros(3*N,3*N); + for i=1:N + Q(i,i)=4*(x(i+1)-x(i))^2 + Q(i,i+N)=2*(x(i+1)-x(i)) + Q(i+N,i)=2*(x(i+1)-x(i)) + Q(i+N,i+N)=1; + end + + At=[Q,A';A,zeros(3*N-1,3*N-1)] + Bt=[zeros(3*N,1);B] + Zt=At\Bt; + Z=Zt(1:3*N,1) +endfunction +//=================================================== diff --git a/macros/Sources/CURV_f.sci b/macros/Sources/CURV_f.sci new file mode 100644 index 00000000..38b3d7c8 --- /dev/null +++ b/macros/Sources/CURV_f.sci @@ -0,0 +1,92 @@ +// 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] = CURV_f(job,arg1,arg2) + + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x = arg1; + model = arg1.model; + graphics = arg1.graphics; + rpar = model.rpar; + ipar = model.ipar; + n = ipar(1); + xx = rpar(1:n); + yy = rpar(n+1:2*n); + gc = list(rpar(2*n+1:2*n+4),ipar(2:5)) + + while %t do + [ln,fun] = where(); + if ~or(fun == "do_eval") then // cas standard + [xx, yy, ok, gc] = edit_curv(xx, yy, "axy", [" "," "," "], gc); + else + ok = %t; + end // no need anymore to overload edit_curv in do_eval + + if ~ok then + break + end + + n=size(xx,"*") + + if or(xx(2:n)-xx(1:n-1)<0) then + message("You have not defined a function"); + ok=%f + end + + if ok then + model.sim = "intplt" + model.firing = [] //compatibility + rect = gc(1) + model.rpar = [xx(:);yy(:);rect(:)] + axisdata = gc(2); + model.ipar = [size(xx,"*");axisdata(:)] + x.graphics = graphics; + x.model = model + break + end + end + + case "define" then + xx = [0;1;2]; + yy = [-5;5;0] + rect = [0,-5,2,5]; + axisdata = [2;10;2;10] + ipar = [size(xx,1);axisdata(:)] + rpar = [xx;yy;rect(:)] + model = scicos_model() + model.sim = "intplt" + model.in = [] + model.out = 1 + model.rpar = [xx;yy;rect(:)] + model.ipar = [size(xx,1);axisdata(:)] + model.blocktype = "c" + model.dep_ut = [%f %t] + + gr_i = [] + x = standard_define([2 2],model,[],gr_i) + end + +endfunction diff --git a/macros/Sources/Counter.sci b/macros/Sources/Counter.sci new file mode 100644 index 00000000..cc4feada --- /dev/null +++ b/macros/Sources/Counter.sci @@ -0,0 +1,79 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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] = Counter(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,minim,maxim,rule,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "Counter"); " "; .. + gettext("Integer counter generator");" "], .. + [gettext("Minimum"); gettext("Maximum"); .. + gettext("Rule (1:Increment, 2:Decrement)");], .. + list("vec",1,"vec",1,"vec",1),exprs); + + if ~ok then + break, + end + maxim=int(maxim); + minim=int(minim); + + if maxim < minim then + block_parameter_error(msprintf(gettext("Wrong values for ''Maximum'' and ''Minimum'' parameters: %d < %d"), minim, maxim), .. + msprintf(gettext("''Minimum'' must be less than ''Maximum''."))); + elseif (rule <> 1 & rule <> 2) then + block_parameter_error(msprintf(gettext("Wrong value for ''Rule'' parameter: %d"), rule), .. + msprintf(gettext("Must be in the interval %s."), "[1,2]")); + else + graphics.exprs=exprs + model.dstate=0 + model.ipar=[rule;maxim;minim] + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minim=0 + maxim=2 + rule=1 + model=scicos_model() + model.sim=list("counter",4) + model.evtin=1 + model.out=1 + model.out2=1 + model.dstate=0 + model.ipar=[rule;maxim;minim] + model.blocktype="c" + model.dep_ut=[%f %f] + + exprs=[string(minim);string(maxim);string(rule)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/FROMWSB.sci b/macros/Sources/FROMWSB.sci new file mode 100644 index 00000000..a97c0c9d --- /dev/null +++ b/macros/Sources/FROMWSB.sci @@ -0,0 +1,246 @@ +// 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] = FROMWSB(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the internal edge trigger block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "FROMWS_c" then + ppath = list(i); + break; + end + end + newpar=list(); + y=0; + for path=ppath do + np=size(path,"*") + spath=list() + for k=1:np + spath($+1)="model" + spath($+1)="rpar" + spath($+1)="objs" + spath($+1)=path(k) + end + xx=arg1(spath)// get the block + execstr("xxn="+xx.gui+"(''set'',xx)") + if ~isequalbitwise(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.odstate,model_n.odstate)|.. + ~isequal(model.rpar,model_n.rpar)|.. + ~isequal(model.ipar,model_n.ipar)|.. + ~isequal(model.opar,model_n.opar)|.. + ~isequal(model.label,model_n.label) + if or(model.in<>model_n.in)|or(model.out<>model_n.out)|.. + or(model.in2<>model_n.in2)|or(model.out2<>model_n.out2)|.. + or(model.outtyp<>model_n.outtyp)|or(model.intyp<>model_n.intyp) then + needcompile=1 + end + if or(model.firing<>model_n.firing) then + needcompile=2 + end + if (size(model.in,"*")<>size(model_n.in,"*"))|.. + (size(model.out,"*")<>size(model_n.out,"*")) then + needcompile=4 + 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)=path// Notify modification + y=max(y,needcompile) + end + end + x=arg1 + typ=newpar + case "define" then + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[-159.096,811.104,-121.216,617.984,1323,1008,331,284,630,480,1426,231,1.4],.. + Title="FROMWSB",.. + tol=[0.0001,0.000001,1.000D-10,100001,0,0],.. + tf=100000,.. + context=" ",.. + void1=[],.. + options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],.. + list([5,1],[4,1]),[0.8,0.8,0.8]),.. + void2=[],.. + void3=[],.. + doc=list())) + scs_m_1.objs(1)=scicos_block(.. + gui="FROMWS_c",.. + graphics=scicos_graphics(.. + orig=[260.37067,261.584],.. + sz=[70,40],.. + flip=%t,.. + theta=0,.. + exprs=["V";"1";"1";"0"],.. + pin=[],.. + pout=4,.. + pein=2,.. + peout=2,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("fromws_c",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=-1,.. + evtin=1,.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[1;-31;1;1;0],.. + opar=list(),.. + blocktype="d",.. + firing=0,.. + dep_ut=[%f,%t],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_link(.. + xx=[295.37067;295.37067;233.23733;233.23733;295.37067;295.37067],.. + yy=[255.86971;223.45067;223.45067;337.85067;337.85067;307.29829],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[1,1,0],.. + to=[1,1,1]) + scs_m_1.objs(3)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[358.9421,271.584],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=4,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=-2,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(4)=scicos_link(.. + xx=[338.9421;358.9421],.. + yy=[281.584;281.584],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[3,1,1]) + model=scicos_model(.. + sim="csuper",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=scs_m_1,.. + ipar=[],.. + opar=list(),.. + blocktype="h",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()) + //## modif made by hand + gr_i=[] + x=standard_define([5 2],model,[],gr_i) + end +endfunction diff --git a/macros/Sources/FROMWS_c.sci b/macros/Sources/FROMWS_c.sci new file mode 100644 index 00000000..6962275f --- /dev/null +++ b/macros/Sources/FROMWS_c.sci @@ -0,0 +1,100 @@ +// 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] = FROMWS_c(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,varnam,Method,ZC,OutEnd,exprs]=scicos_getvalue("Set From_Workspace block parameters",.. + ["Variable name"; + "Interpolation Method"; + "Enable zero crossing(0:No, 1:Yes)?"; + "Output at end(0:Zero, 1:Hold, 2:Repeat)"],... + list("str",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if ~(Method==0 | Method==1| Method==2| Method==3) then + message("Interpolation method should be chosen in [0,1,2,3]"); + ok=%f; + end + + if ~(ZC==0 | ZC==1) then + message("Zero crossing should be either 0 or 1"); + ok=%f; + end + + if ~(OutEnd==0 | OutEnd==1| OutEnd==2) then + message("Output at end option should be either 0 or 1"); + ok=%f; + end + + //check for valid name variable + r=%f; + ierr=execstr("r=validvar(varnam)","errcatch") + if ~r then + message(["Invalid variable name."; + "Please choose another variable name."]); + ok=%f + end + + if ok then + model.ipar=[length(varnam);_str2code(varnam);Method;ZC;OutEnd;]; + [model,graphics,ok]=set_io(model,graphics,list(),list([-1,-2],-1),1,1); + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + end + + case "define" then + varnam="V";// V.time=0; V.value=1; + Method=1; + ZC=1; + OutEnd=0; + + model=scicos_model(); + model.sim=list("fromws_c",4); + model.out=-1 + model.out2=-2 + model.outtyp=-1 + model.ipar=[length(varnam);_str2code(varnam);Method;ZC;OutEnd;]; + model.evtin=[1]; + model.evtout=[1]; + model.firing=[0]; + model.blocktype="d"; + model.dep_ut=[%f %t]; + gr_i=[] + exprs=[string(varnam);string(Method);string(ZC);string(OutEnd)]; + x=standard_define([3.5 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Sources/GENSIN_f.sci b/macros/Sources/GENSIN_f.sci new file mode 100644 index 00000000..384b9f4e --- /dev/null +++ b/macros/Sources/GENSIN_f.sci @@ -0,0 +1,76 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=GENSIN_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok, M, F, P, exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "GENSIN_f");" "; .. + gettext("Sine wave generator");" "], .. + [gettext("Magnitude"); gettext("Frequency (rad/s)"); gettext("Phase (rad)")], .. + list("vec",1,"vec",1,"vec",1), exprs); + if ~ok then + break, + end + if F < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''Frequency'' parameter: %e."), F), .. + gettext("Strictly positive integer expected.")); + ok = %f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[],1,[],[]) + model.rpar=[M;F;P] + //next two lines to fix invalid properties in scilab version + //prior 5.5.0 + model.out2=1; + model.outtyp=1; + + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + rpar=[1;1;0] + model=scicos_model() + model.sim="gensin" + model.in=[] + model.out=1 + model.out2=1 + model.outtyp=1 + model.rpar=[1;1;0] + model.blocktype="c" + model.dep_ut=[%f %t] + exprs=[string(rpar(1));string(rpar(2));string(rpar(3))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/GENSQR_f.sci b/macros/Sources/GENSQR_f.sci new file mode 100644 index 00000000..b05a5a3d --- /dev/null +++ b/macros/Sources/GENSQR_f.sci @@ -0,0 +1,70 @@ +// 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]=GENSQR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if size(exprs,"*")==2 then + exprs=exprs(2), + end //compatibility + while %t do + [ok,Amplitude,exprs]=scicos_getvalue([ + "Set Square generator block parameters"],.. + ["Amplitude"],.. + list("vec",1),exprs) + if ~ok then + break, + end + graphics.exprs=exprs + model.dstate=Amplitude + //next two lines to fix invalid properties in scilab version + //prior 5.5.0 + model.out2=1; + model.outtyp=1; + + x.graphics=graphics; + x.model=model + break + end + case "define" then + Amplitude=1 + model=scicos_model() + model.sim="gensqr" + model.out=1; + model.out2=1; + model.outtyp=1; + model.evtin=1; + model.dstate=Amplitude + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(Amplitude) + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/GEN_SQR.sci b/macros/Sources/GEN_SQR.sci new file mode 100644 index 00000000..6ff65a0e --- /dev/null +++ b/macros/Sources/GEN_SQR.sci @@ -0,0 +1,464 @@ +// 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]=GEN_SQR(job,arg1,arg2) + //Generated from SuperBlock on 8-Feb-2008 + x=[]; + y=[]; + typ=[]; + select job + case "set" then + y=needcompile + arg1.model.ipar=1; + typ=list() + graphics=arg1.graphics; + exprs=graphics.exprs + Btitre=.. + "Set GEN_SQR parameters" + Exprs0=.. + ["Amin";"Amax";"rule";"F"] + Bitems=.. + ["Minimum Value"; + "Maximum Value"; + "Initial Value( 1= Minimum Value 2= Maximum Value)"; + "Period (sec)"] + Ss=.. + list("mat",[-1,-1],"mat",[-1,-1],"pol",-1,"pol",-1) + scicos_context=struct() + x=arg1 + ok=%f + while ~ok do + [ok,scicos_context.Amin,scicos_context.Amax,scicos_context.rule,scicos_context.F,exprs]=scicos_getvalue(Btitre,Bitems,Ss,exprs) + if ~ok then + return; + end + %scicos_context=scicos_context; + sblock=x.model.rpar + [%scicos_context,ierr]=script2var(sblock.props.context,%scicos_context) + if ierr==0 then + [sblock,%w,needcompile2,ok]=do_eval(sblock,list()) + if ok then + y=max(2,needcompile,needcompile2) + x.graphics.exprs=exprs + x.model.rpar=sblock + break + end + else + message(lasterror()) + ok=%f + end + end + case "define" then + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[-176.97473,421.18646,173.61587,524.41503,827,480,0,15,827,480,755,614,1.4],.. + Title="SuperBlock",.. + tol=[0.0001,0.000001,1.000D-10,100001,0,0],.. + tf=100000,.. + context=["if typeof(Amin)<>typeof(Amax) then error(''Minimum value and Maximum value must have the same type'');end"; + "if and(rule<>[1;2]) then error(''Initial Value must be 1 (for Min) or 2 (for Max)'');end"; + "if Amin>Amax then error(''Maximum value must be greater than the Minimum Value'');end"; + "P=%pi/F"; + ""],.. + void1=[],.. + options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],.. + list([5,1],[4,1]),[0.8,0.8,0.8]),.. + void2=[],.. + void3=[],.. + doc=list())) + scs_m_1.objs(1)=scicos_block(.. + gui="Counter",.. + graphics=scicos_graphics(.. + orig=[18.229901,339.5057],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["1";"2";"rule"],.. + pin=[],.. + pout=8,.. + pein=16,.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("counter",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=1,.. + evtin=1,.. + evtout=[],.. + state=[],.. + dstate=0,.. + odstate=list(),.. + rpar=[],.. + ipar=[1;2;1],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_block(.. + gui="CONST_m",.. + graphics=scicos_graphics(.. + orig=[38.096074,293.82198],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="Amin",.. + pin=[],.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("cstblk4_m",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(-1),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(3)=scicos_block(.. + gui="CONST_m",.. + graphics=scicos_graphics(.. + orig=[37.378886,245.02389],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="Amax",.. + pin=[],.. + pout=6,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("cstblk4_m",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(1),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(4)=scicos_block(.. + gui="SELECT_m",.. + graphics=scicos_graphics(.. + orig=[116.26954,269.42294],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["-1";"2";"1"],.. + pin=[5;6],.. + pout=14,.. + pein=[9;10],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("selector_m",4),.. + in=[-1;-1],.. + in2=[-2;-2],.. + intyp=[-1;-1],.. + out=-1,.. + out2=-2,.. + outtyp=-1,.. + evtin=[1;1],.. + evtout=[],.. + state=[],.. + dstate=1,.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(5)=scicos_link(.. + xx=[86.667502;107.69811;107.69811],.. + yy=[313.82198;313.82198;296.0896],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[2,1,0],.. + to=[4,1,1]) + scs_m_1.objs(6)=scicos_link(.. + xx=[85.950315;107.69811;107.69811],.. + yy=[265.02389;265.02389;282.75627],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[4,2,1]) + scs_m_1.objs(7)=scicos_block(.. + gui="ESELECT_f",.. + graphics=scicos_graphics(.. + orig=[106.9461,339.7496],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["2";"0";"0"],.. + pin=8,.. + pout=[],.. + pein=[],.. + peout=[9;10],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("eselect",-2),.. + in=1,.. + in2=1,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[1;1],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="l",.. + firing=[-1;-1],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(8)=scicos_link(.. + xx=[86.80133;98.374671],.. + yy=[359.5057;359.7496],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[7,1,1]) + scs_m_1.objs(9)=scicos_link(.. + xx=[126.9461;129.60287],.. + yy=[334.03532;315.13722],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[7,1,0],.. + to=[4,1,1]) + scs_m_1.objs(10)=scicos_link(.. + xx=[146.9461;142.93621],.. + yy=[334.03532;315.13722],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[7,2,0],.. + to=[4,2,1]) + scs_m_1.objs(11)=mlist("Deleted") + scs_m_1.objs(12)=mlist("Deleted") + scs_m_1.objs(13)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[184.40238,278.75198],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=14,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=-2,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(14)=scicos_link(.. + xx=[164.84097;184.40238],.. + yy=[289.42294;288.75198],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[13,1,1]) + scs_m_1.objs(15)=scicos_block(.. + gui="SampleCLK",.. + graphics=scicos_graphics(.. + orig=[18.313686,403.57431],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["F/2";"0"],.. + pin=[],.. + pout=[],.. + pein=[],.. + peout=16,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="sampleclk",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[1/2;0],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=-1,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(16)=scicos_link(.. + xx=[48.313686;48.229901],.. + yy=[403.57431;385.21998],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[15,1,0],.. + to=[1,1,1]) + model=scicos_model() + model.sim="csuper" + model.in=[] + model.in2=[] + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=-1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.odstate=list() + model.rpar=scs_m_1 + model.ipar=1 + model.opar=list() + model.blocktype="h" + model.firing=[] + model.dep_ut=[%f,%f] + model.label="" + model.nzcross=0 + model.nmode=0 + model.equations=list() + Amin=-1 + Amax=1 + rule=1 + F=1 + exprs=[.. + sci2exp(Amin) + sci2exp(Amax) + sci2exp(rule) + sci2exp(F) + ] + gr_i=[] + x=standard_define([3,2],model,exprs,gr_i) + end +endfunction + + diff --git a/macros/Sources/Ground_g.sci b/macros/Sources/Ground_g.sci new file mode 100644 index 00000000..9746b9df --- /dev/null +++ b/macros/Sources/Ground_g.sci @@ -0,0 +1,47 @@ +// 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]=Ground_g(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + C=[0] + model=scicos_model() + model.sim=list("cstblk4_m",4) + model.in=[] + model.out=1 + model.in2=[] + model.out2=1 + model.outtyp=-1 + model.rpar=[] + model.opar=list(C); + model.blocktype="d" + model.dep_ut=[%f %f] + exprs=[] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/INIMPL_f.sci b/macros/Sources/INIMPL_f.sci new file mode 100644 index 00000000..e6056773 --- /dev/null +++ b/macros/Sources/INIMPL_f.sci @@ -0,0 +1,79 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=INIMPL_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if size(exprs,"*")==2 then + exprs=exprs(1), + end //compatibility + while %t do + [ok,prt,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"),"INIMPL_f");" "; .. + gettext("Implicit input port");" ";], "Port Number", .. + list("vec",1), exprs); + if ~ok then + break + end + prt=int(prt) + if prt <= 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''Port Number'' parameter: %d."), prt), .. + gettext("Strictly positive integer expected.")); + else + if model.ipar<>prt then + needcompile=4; + y=needcompile, + end + model.ipar=prt + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + case "define" then + model=scicos_model() + model.sim="inimpl" + model.out=[-1] + model.out2=[1] + model.ipar=[1] + model.dep_ut=[%f %f] + model.blocktype="c" + mo=modelica() + mo.model="PORT" + mo.outputs="n" + model.equations=mo + prt=1 + exprs="1" + gr_i=[] + x=standard_define([1 1],model,exprs,gr_i) + x.graphics.out_implicit=["I"] + + // x.graphics.flip=%f //flip it + end +endfunction diff --git a/macros/Sources/IN_f.sci b/macros/Sources/IN_f.sci new file mode 100644 index 00000000..be5bb00f --- /dev/null +++ b/macros/Sources/IN_f.sci @@ -0,0 +1,86 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=IN_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + model=arg1.model; + exprs=graphics.exprs; + if size(exprs,"*")==2 then + exprs=exprs(1), + end //compatibility + if size(exprs,"*")==1 then + exprs=[exprs(1);"[-1 -2]";"-1"], + end //compatibility + while %t do + [ok,prt,otsz,ot,exprs]=getvalue(_("Set Input block parameters"),... + [_("Port number"); + _("Outport size ([-1 -2] for inherit)"); + _("Outport Type (-1 for inherit)")],... + list("vec",1,"vec",-1,"vec",1),exprs) + if ~ok then + break, + end + prt=int(prt) + if prt<=0 then + message(_("Port number must be a positive integer")) + elseif ~isequal(size(otsz,"*"),2) then + message(_("Outport Size must be a 2 elements vector")) + elseif ((ot<1|ot>9)&(ot<>-1)) then + message(_("Outport type must be a number between 1 and 9, or -1 for inheritance.")) + else + if model.ipar<>prt then + needcompile=4; + y=needcompile, + end + model.ipar=prt + model.firing=[]; + model.out=otsz(1) + model.out2=otsz(2) + model.outtyp=ot; + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + case "define" then + prt=1 + model=scicos_model() + model.sim="input" + model.out=-1 + model.out2=-2 + model.outtyp=-1 + model.ipar=prt + model.blocktype="c" + model.dep_ut=[%f %f] + + exprs=sci2exp(prt) + gr_i=[] + x=standard_define([1 1],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/Modulo_Count.sci b/macros/Sources/Modulo_Count.sci new file mode 100644 index 00000000..edeb0941 --- /dev/null +++ b/macros/Sources/Modulo_Count.sci @@ -0,0 +1,74 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=Modulo_Count(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,ini_c,base,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "Modulo_Count");" "; gettext("Modulo counter (0 to N counter)");" "], .. + [gettext("Initial State (zero or positive number)"); gettext("Upper Limit (positive number)")], .. + list("vec",1,"vec",1), exprs); + + ini_c = int(ini_c); + base = int(base); + if ~ok then + break, + end + if ini_c <0 then + block_parameter_error(msprintf(gettext("Wrong value for ''Initial State'' parameter: %d."), ini_c), .. + gettext("Null or positive integer expected.")); + elseif base <= 0 then + block_parameter_error(msprintf(gettext("Wrong values for ''Upper Limit'' parameter: %d."), base),.. + gettext("Strictly positive integer expected.")); + else + graphics.exprs=exprs + model.ipar=base; + model.dstate=ini_c; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + ini_c=0 + base=3 + model=scicos_model() + model.sim=list("modulo_count",4) + model.evtin=1 + model.out=1 + model.dstate=ini_c + model.ipar=base + model.blocktype="c" + model.dep_ut=[%f %f] + + exprs=[string(ini_c);string(base)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/PULSE_SC.sci b/macros/Sources/PULSE_SC.sci new file mode 100644 index 00000000..0f2c2691 --- /dev/null +++ b/macros/Sources/PULSE_SC.sci @@ -0,0 +1,402 @@ +// 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]=PULSE_SC(job,arg1,arg2) + //Generated from SuperBlock on 7-Feb-2008 + x=[]; + y=[]; + typ=[]; + select job + case "set" then + y=needcompile + arg1.model.ipar=1; + typ=list() + graphics=arg1.graphics; + exprs=graphics.exprs + Btitre=.. + "Set Pulse Generator parameters" + Exprs0=.. + ["E";"W";"F";"A"] + Bitems=.. + ["Phase delay (secs):";"Pulse Width (% of period):";"Period (secs):";"Amplitude:"] + Ss=.. + list("pol",-1,"pol",-1,"pol",-1,"mat",[-1 -1]) + scicos_context=struct(); + x=arg1 + ok=%f + while ~ok do + [ok,scicos_context.E,scicos_context.W,scicos_context.F,scicos_context.A,exprs]=scicos_getvalue(Btitre,Bitems,Ss,exprs) + if ~ok then + return; + end + %scicos_context=scicos_context; + sblock=x.model.rpar + [%scicos_context,ierr]=script2var(sblock.props.context,%scicos_context) + if ierr==0 then + [sblock,%w,needcompile2,ok]=do_eval(sblock,list()) + if ok then + y=max(2,needcompile,needcompile2) + x.graphics.exprs=exprs + x.model.rpar=sblock + break + end + else + if (lasterror() <> []) then + messagebox(lasterror()) + end + ok=%f + end + end + case "define" then + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[-162.7581,435.54369,67.607292,416.67644,827,479,0,15,827,480,715,167,1.4],.. + Title=["SuperBlock","/home/fady/Scicos_examples/"],.. + tol=[0.0001;0.000001;1.000D-10;100001;0;0;0],.. + tf=10,.. + context=["E2=E+W/100*F"; + "if (W<0 | W>100) then error(''Width must be between 0 and 100'');end"; + "if (E2 >= F) then error (''Offset must be lower than (frequency*(1-Width/100))''); end"],.. + void1=[],.. + options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],.. + list([5,1],[4,1]),[0.8,0.8,0.8]),.. + void2=[],.. + void3=[],.. + doc=list())) + scs_m_1.objs(1)=scicos_block(.. + gui="CONST_m",.. + graphics=scicos_graphics(.. + orig=[30.801202,158.91733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="A",.. + pin=[],.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("cstblk4_m",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(1),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_block(.. + gui="Ground_g",.. + graphics=scicos_graphics(.. + orig=[31.534535,215.384],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=4,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("cstblk4_m",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(0),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(3)=scicos_block(.. + gui="SELECT_m",.. + graphics=scicos_graphics(.. + orig=[106.00652,186.09381],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["-1";"2";"1"],.. + pin=[4;5],.. + pout=11,.. + pein=[9;8],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("selector_m",4),.. + in=[-1;-1],.. + in2=[-2;-2],.. + intyp=[-1;-1],.. + out=-1,.. + out2=-2,.. + outtyp=-1,.. + evtin=[1;1],.. + evtout=[],.. + state=[],.. + dstate=1,.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(4)=scicos_link(.. + xx=[80.105964;97.43509;97.43509],.. + yy=[235.384;235.384;212.76048],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[2,1,0],.. + to=[3,1,1]) + scs_m_1.objs(5)=scicos_link(.. + xx=[79.372631;97.43509;97.43509],.. + yy=[178.91733;178.91733;199.42714],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[3,2,1]) + scs_m_1.objs(6)=scicos_block(.. + gui="SampleCLK",.. + graphics=scicos_graphics(.. + orig=[82.349744,274.21741],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["F";"E2"],.. + pin=[],.. + pout=[],.. + pein=[],.. + peout=9,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="sampleclk",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[1;0.4],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=-1,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(7)=scicos_block(.. + gui="SampleCLK",.. + graphics=scicos_graphics(.. + orig=[160.48879,274.21741],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["F";"E"],.. + pin=[],.. + pout=[],.. + pein=[],.. + peout=8,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="sampleclk",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[1;0.1],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=-1,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(8)=scicos_link(.. + xx=[190.48879;190.48879;132.67318;132.67318],.. + yy=[274.21741;240.99048;240.99048;231.80809],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[7,1,0],.. + to=[3,2,1]) + scs_m_1.objs(9)=scicos_link(.. + xx=[112.34974;112.34974;119.33985;119.33985],.. + yy=[274.21741;248.21372;248.21372;231.80809],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[6,1,0],.. + to=[3,1,1]) + scs_m_1.objs(10)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[174.57795,196.09381],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=11,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=-2,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(11)=scicos_link(.. + xx=[154.57795;174.57795],.. + yy=[206.09381;206.09381],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[10,1,1]) + model=scicos_model() + model.sim="csuper" + model.in=[] + model.in2=[] + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=-1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.odstate=list() + model.rpar=scs_m_1 + model.ipar=1 + model.opar=list() + model.blocktype="h" + model.firing=[] + model.dep_ut=[%f,%f] + model.label="" + model.nzcross=0 + model.nmode=0 + model.equations=list() + E=0.1 + W=30 + F=1 + A=1 + exprs=[.. + sci2exp(E) + sci2exp(W) + sci2exp(F) + sci2exp(A) + ] + gr_i=[] + x=standard_define([3,2],model,exprs,gr_i) + end +endfunction + + diff --git a/macros/Sources/RAMP.sci b/macros/Sources/RAMP.sci new file mode 100644 index 00000000..f0d9a5f6 --- /dev/null +++ b/macros/Sources/RAMP.sci @@ -0,0 +1,70 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=RAMP(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,slope,stt,iout,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "RAMP"); " "; gettext("Ramp function");" "], .. + [gettext("Slope"); gettext("Start Time"); gettext("Initial Value")], .. + list("vec",1,"vec",1,"vec",1), exprs) + if ~ok then + break, + end + if stt<0 then + block_parameter_error(msprintf(gettext("Wrong value for ''Start Time'' parameter: %e."), stt), .. + gettext("Null or positive integer expected.")); + else + model.rpar=[slope;stt;iout]; + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + slope=0; + iout=0; + stt=0; + rpar=[slope;stt;iout]; + model=scicos_model() + model.sim=list("ramp",4) + model.in=[] + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.nmode=1 + model.nzcross=1 + model.dep_ut=[%f %t] + + exprs=[string(rpar)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/RAND_f.sci b/macros/Sources/RAND_f.sci new file mode 100644 index 00000000..bd4e7c68 --- /dev/null +++ b/macros/Sources/RAND_f.sci @@ -0,0 +1,85 @@ +// 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]=RAND_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if size(exprs,"*")==5 then + exprs=exprs(1:3), + end //compatibility + if size(exprs,"*")==3 then + exprs=[exprs;string(model.dstate(1))], + end //compatibility + while %t do + [ok,flag,a,b,seed_c,exprs]=scicos_getvalue([ + "Set Random generator block parameters"; + "flag = 0 : Uniform distribution A is min and A+B max"; + "flag = 1 : Normal distribution A is mean and B deviation"; + " "; + "A and B must be vector with equal sizes"; + "seed is the seed of random number generator (integer<2**31)"],.. + ["flag";"A";"B";"seed"],.. + list("vec",1,"vec",-1,"vec","size(%2,''*'')","vec",1),exprs) + if ~ok then + break, + end + if flag<>0&flag<>1 then + message("flag must be equal to 1 or 0") + else + nout=size(a,"*") + graphics.exprs=exprs + model.out=nout + model.ipar=flag + model.rpar=[a(:);b(:)] + model.dstate=[seed_c;0*a(:)] + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + a=0 + b=1 + dt=0 + out=1 + flag=0 + model=scicos_model() + model.sim="rndblk" + model.out=out + model.evtin=1 + model.dstate=[int(rand()*(10^7-1));0*a(:)] + model.rpar=[a(:);b(:)] + model.ipar=flag + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[string(flag);sci2exp(a(:));sci2exp(b(:));string(model.dstate(1))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/RAND_m.sci b/macros/Sources/RAND_m.sci new file mode 100644 index 00000000..28b267bb --- /dev/null +++ b/macros/Sources/RAND_m.sci @@ -0,0 +1,107 @@ +// 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]=RAND_m(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if size(exprs,"*")==14 then + exprs(9)=[], + end //compatiblity + while %t do + [ok,typ,flag,a,b,seed_c,exprs]=scicos_getvalue([ + "Set Random generator block parameters"; + "flag = 0 : Uniform distribution A is min and A+B max"; + "flag = 1 : Normal distribution A is mean and B deviation"; + " "; + "A and B must be matrix with equal sizes"],.. + ["Datatype(1=real double 2=complex)";"flag";"A";"B";"SEED"],.. + list("vec",1,"vec",1,"mat",[-1 -2],"mat","[-1 -2]","mat",[1 2]),exprs) + if ~ok then + break, + end + if flag<>0&flag<>1 then + message("flag must be equal to 1 or 0") + else + out=size(a) + if typ==1 then + function_name="rndblk_m"; + model.rpar=[real(a(:));real(b(:))] + model.dstate=[seed_c(1);0*real(a(:))] + ot=1 + elseif typ==2 then + function_name="rndblkz_m"; + ot=2 + model.rpar=[real(a(:));imag(a(:));real(b(:));imag(b(:))] + model.dstate=[seed_c(:);0*[real(a(:));imag(a(:))]] + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list([],[]),list(out,ot),1,[]) + if ok then + model.sim=list(function_name,4) + graphics.exprs=exprs + model.ipar=flag + x.graphics=graphics; + x.model=model + break + end + end + end + end + case "define" then + a=0 + b=1 + dt=0 + flag=0 + function_name="rndblk_m"; + funtyp=4; + model=scicos_model() + model.sim=list(function_name,funtyp) + model.in=[] + model.in2=[] + model.intyp=[] + model.out=1 + model.out2=1 + model.outtyp=1 + model.evtin=1 + model.evtout=[] + model.state=[] + model.dstate=[int(rand()*(10^7-1));0*a(:)] + model.rpar=[a(:),b(:)] + model.ipar=flag + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=[sci2exp(1);string(flag);sci2exp([a]);sci2exp([b]);sci2exp([model.dstate(1) int(rand()*(10^7-1))])] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/READAU_f.sci b/macros/Sources/READAU_f.sci new file mode 100644 index 00000000..0c371c25 --- /dev/null +++ b/macros/Sources/READAU_f.sci @@ -0,0 +1,126 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=READAU_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + out=model.out + dstate=model.dstate + ipar=model.ipar + + imask=9+ipar(1) + tmask=ipar(imask) + lunit=dstate(3) + fname=exprs(1) + + while %t do + [ok,fname1,N,swap,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "READAU_f"); " "; .. + gettext("(Read Audio File)");" "; gettext("Read is done on a binary ''.au'' file")], .. + [gettext("Input File Name"); gettext("Buffer size"); gettext("Swap Mode (0:No, 1:Yes)")], .. + list("str",1,"vec",1,"vec",1), exprs); + tmask1=[]; + outmask=1; + frmt1="uc"; + M=1; + offset=1; + if ~ok then + break, + end //user cancel modification + fname1=stripblanks(fname1) + frmt1=stripblanks(frmt1) + if alreadyran&fname1<>fname then + block_parameter_error(gettext("Simulation running !!! You cannot modify Input file name"), .. + gettext("End current simulation first.")); + // Remove this test user can't modify time in dialog + // elseif alreadyran&size(tmask1)<>size(tmask) then + // message(['You cannot modify time management when running';'End current simulation first']) + elseif fname1 == "" then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Input File Name")), gettext("You must provide a filename.")); + elseif N < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer size"), N), msprintf(gettext("Must be greater than %d."), 1)); + elseif alreadyran & (N <> ipar(6)) then + block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running."), gettext("Buffer Size")), gettext("End current simulation first.")); + elseif swap <> 0 & swap <> 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Swap Mode"), swap), msprintf(gettext("Must be in the interval %s."),"[0, 1]")); + else + [model,graphics,ok]=check_io(model,graphics,[],1,1,[]) + frmt1=part(frmt1,1:3); + if ok then + ipar=[length(fname1); + _str2code(frmt1); + 0; + N; + M; + swap; + offset + _str2code(fname1); + tmask1 + outmask(:)] + if prod(size(dstate))<>(N*M)+3 then + dstate=[-1;-1;lunit;zeros(N*M,1)] + end + model.dstate=dstate; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + frmt="uc " + fname="test.au" + lunit=0 + N=20; + M=1 + tmask=[] + swap=0 + offset=1 + outmask=1 + ievt=0 + nout=size(outmask,"*") + + model=scicos_model() + model.sim=list("readau",2) + model.out=nout + model.evtin=1 + model.dstate=[1;1;lunit;zeros(N*M,1)] + model.ipar=[length(fname);_str2code(frmt);ievt;N;M;swap;offset;_str2code(fname); + tmask;outmask] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[fname; + string(N); + string(swap)] + gr_i=[] + x=standard_define([5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/READC_f.sci b/macros/Sources/READC_f.sci new file mode 100644 index 00000000..b47d5272 --- /dev/null +++ b/macros/Sources/READC_f.sci @@ -0,0 +1,212 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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] = READC_f(job,arg1,arg2) + + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x = arg1; + model = x.model; + graphics = arg1.graphics; + exprs = graphics.exprs + out = model.out + dstate = model.dstate + ipar = model.ipar + imask = 9+ipar(1) + tmask = ipar(imask) + lunit = dstate(3) + fname = exprs(3) + frmt = exprs(4) + + while %t do + [ok,tmask1,outmask,fname1,frmt1,M,N,offset,swap,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "READC_f" ); + " "; gettext("Read from C binary file")], [gettext("Time Record Selection"); gettext("Outputs Record Selection"); .. + gettext("Input File Name"); gettext("Input Format"); gettext("Record Size"); gettext("Buffer Size"); .. + gettext("Initial Record Index"); gettext("Swap Mode (0:No, 1:Yes)")], .. + list("vec", -1, "vec", -1, "str", 1, "str", 1, "vec", 1, "vec", 1,"vec", 1, "vec", 1), exprs); + + if ~ok then + break + end //user cancel modification + + fname1 = pathconvert(stripblanks(fname1), %f, %t) + frmt1 = stripblanks(frmt1) + fmts = [ "s","l","d","f","c","us","ul","uc","ull","uls","ubl","ubs","dl","fl","ll","sl","db","fb","lb","sb"]; + + nout = size(outmask,"*") + + if prod(size( tmask1 )) > 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Time Record Selection")), .. + gettext("Must be a scalar or an empty matrix.")) + + elseif and(frmt1 <> fmts) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s."), gettext("Input Format"), frmt1), .. + gettext("Valid formats are: " + strcat(fmts,", "))); + + elseif alreadyran & fname1 <> fname then + block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running"), gettext("Input File Name")), .. + gettext("End current simulation first.")); + + elseif N <> ipar(6) & alreadyran then + block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running."), gettext("Buffer Size")), .. + gettext("End current simulation first")); + + elseif alreadyran & size(tmask1) <> size(tmask) then + block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running."), gettext("Time Record Selection")), .. + gettext("End current simulation first.")); + + elseif fname1 == "" then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Input File Name")), .. + gettext("You must provide a file name.")); + elseif M < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Record Size"), M), .. + gettext("Strictly positive integer expected.")); + + elseif tmask1 ~= [] & (tmask1 < 1 | tmask1 > M) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Time Record Selection"), tmask1), .. + msprintf(gettext("Must be in the interval %s."), gettext("[1, Record Size = ") + string (M)+"]")); + + elseif nout == 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Outputs Record Selection"), nout), .. + gettext("Strictly positive integer expected.")); + + elseif nout > M then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Outputs Record Selection"), nout), .. + msprintf(gettext("Must be in the interval %s."), gettext("[1, Record Size = ") + string (M)+"]")); + + elseif max(outmask) > M | min(outmask) < 1 then + block_parameter_error(msprintf(gettext("Wrong value for indexes in ''%s'' parameter: %s."), gettext("Outputs Record Selection"), strcat(string(outmask(:))," ")), .. + msprintf(gettext("Must be in the interval %s."), gettext("[1, Record Size = ") + string (M)+"]")); + + elseif N < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer Size"), N), .. + gettext("Strictly positive integer expected.")); + + elseif swap <> 0 & swap <> 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Swap Mode"), swap), .. + msprintf(gettext("Must be in the interval %s."), "[0, 1]")); + + elseif offset < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Initial Record Index"), offset), .. + gettext("Strictly positive integer expected.")); + else + if tmask1 == [] then + ievt = 0; + tmask1 = 0; + outpt = []; + else + ievt = 1; + outpt = 1; + end + + out = size(outmask,"*") + [model,graphics,ok] = check_io(model,graphics,[],out,1,outpt) + frmt1 = part(frmt1,1:3); + + if ok then + if ievt == 0 then + model.firing = -1 + else + model.firing = 0 + end + + ipar = [ ... + length(fname1); ... + _str2code(frmt1); ... + ievt; ... + N; ... + M; ... + swap; ... + offset; ... + _str2code(fname1); ... + tmask1; ... + outmask(:) ... + ]; + + if prod(size(dstate)) <> (N*M) + 3 then + dstate = [-1; -1; lunit; zeros(N*M, 1)] + end + + model.dstate = dstate; + model.ipar = ipar + graphics.exprs = exprs; + x.graphics = graphics; + x.model = model + break + + end + + end + + end + + case "define" then + frmt = "d " + fname = "foo" + lunit = 0 + N = 20; + M = 1 + rpar = [] + tmask = 0 + swap = 0 + offset = 1 + outmask = 1 + ievt = 0 + nout = size(outmask,"*") + + ipar = [ ... + length(fname); _str2code(frmt); ievt; N; M; ... + swap;offset; _str2code(fname); tmask; outmask ... + ]; + + model = scicos_model() + model.sim = list("readc",2) + model.out = nout + model.evtin = 1 + model.evtout = [] + model.dstate = [1; 1; lunit; zeros(N*M,1)] + model.ipar = [ ... + length(fname); _str2code(frmt); ievt; N; M; ... + swap; offset;_str2code(fname); ... + tmask; outmask ... + ]; + + model.blocktype = "d" + model.firing = -1 + model.dep_ut = [%f %f] + + exprs = [ ... + "[]"; sci2exp(outmask); fname; frmt; string(M); ... + string(N); string(offset);string(swap) ... + ]; + + gr_i = []; + + x = standard_define([4 2],model,exprs,gr_i) + end + +endfunction diff --git a/macros/Sources/RFILE_f.sci b/macros/Sources/RFILE_f.sci new file mode 100644 index 00000000..2326109d --- /dev/null +++ b/macros/Sources/RFILE_f.sci @@ -0,0 +1,184 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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] = RFILE_f(job,arg1,arg2) + + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x = arg1; + graphics = arg1.graphics; + exprs = graphics.exprs + model = arg1.model; + dstate = model.dstate + ipar = model.ipar + ievt = ipar(3); + N = ipar(4); + imask = 5+ipar(1)+ipar(2) + tmask = ipar(imask) + lunit = dstate(3) + fname = exprs(3) + frmt = exprs(4) + //for backward compatibility + if size(exprs,"*")>5 then + exprs(6) = [] + + end + + while %t do + [ok,tmask1,outmask,fname1,frmt1,N,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "RFILE_f");" "; .. + gettext("Read from an input file"); " "; gettext("Read is done on:"); gettext(" - A binary file if no format given"); .. + gettext(" - A formatted text file if a format (fortran type) is given")], .. + [gettext("Time Record Selection"); gettext("Outputs Record Selection"); gettext("Input File Name"); gettext("Input Format"); gettext("Buffer Size")], .. + list("vec",-1,"vec",-1,"str",1,"str",1,"vec",1), exprs); + + if ~ok then + break + end //user cancel modification + + fname1 = pathconvert(stripblanks(fname1), %f, %t) + frmt1 = stripblanks(frmt1) + //out=int(out) + //nout=out + nout = size(outmask, "*") + + if prod(size(tmask1)) > 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s."), gettext("Time Record Selection"), strcat(string(tmask1(:))," ")),.. + gettext("Empty matrix or scalar expected.")); + + elseif tmask1 ~= [] & tmask1 < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d"), gettext("Time Record Selection"), tmask1), .. + gettext("Strictly positive integer expected.")); + + elseif lunit > 0 & min(length(frmt),1) <> min(length(frmt1), 1) then + block_parameter_error([gettext("Simulation running !!! You cannot switch <br />between formatted and unformatted")], .. + gettext("End current simulation first.")); + + elseif lunit > 0 & fname1 <> fname then + block_parameter_error(gettext("Simulation running !!! You cannot modify ''Input File Name''"), gettext("End current simulation first.")); + + elseif lunit > 0 & size(tmask1) <> size(tmask) then + block_parameter_error(gettext("Simulation running !!! You cannot modify ''Time Record Selection''"), gettext("End current simulation first.")); + + elseif fname1 == "" then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s"), gettext("Input File Name"), fname1), gettext("You must provide a filename.")); + // Simple check for including of the format's string in parenthesis + elseif frmt1 ~= "" & (part(frmt1, 1) ~= "(" | part(frmt1, length(frmt1)) ~= ")") + block_parameter_error(msprintf(gettext("Wrong format for ''%s'' parameter: %s."), gettext("Input Format"), frmt1), .. + gettext("You must enclose the format''s string between parentheses.")); + elseif N < 2 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer Size"), N), .. + gettext("Buffer size must be at least 2.")); + elseif nout == 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Outputs Record Selection"), nout), .. + gettext("You must read at least one field in record.")); + + elseif min(outmask) < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s"), gettext("Outputs Record Selection"), .. + strcat(string(outmask(:))," ")), gettext("Strictly positive indexes expected.")); + else + if tmask1 == [] then + ievt = 0; + cout = []; + tmask1 = 0; + else + ievt = 1 + cout = 1; + end + [model,graphics,ok] = check_io( model, graphics, [], nout, 1, cout) + if ok then + if ievt == 0 then + model.firing = [] + else + model.firing = 0 + end + ipar = [ ... + length(fname1); ... + length(frmt1); ... + ievt; ... + N; ... + _str2code(fname1); ... + _str2code(frmt1); ... + tmask1; ... + outmask(:) ... + ]; + + if prod(size(dstate)) <> (nout+ievt)*N + 3 then + dstate = [-1 ; -1; lunit; zeros((nout + ievt) * N, 1)] + end + model.dstate = dstate; + model.ipar = ipar + graphics.exprs = exprs; + x.graphics = graphics; + x.model = model + break + end + end + end + + case "define" then + out = 1; + nout = sum(out) + frmt = "(7(e10.3,1x))" + fname = "foo" + lunit = 0 + N = 2; + rpar = [] + tmask = 0 + outmask = 1 + ipar = [ ... + length(fname);length(frmt);0;N; ... + _str2code(fname);_str2code(frmt); ... + tmask;outmask ... + ]; + + dstate = [1; 1; lunit; zeros((nout)*N, 1)] + model = scicos_model() + model.sim = "readf" + model.out = nout + model.evtin = 1 + model.dstate = dstate + model.ipar = [ ... + length(fname);length(frmt);0;N; ... + _str2code(fname);_str2code(frmt); ... + tmask;outmask ... + ]; + + model.blocktype = "d" + model.dep_ut = [%f %f] + + exprs = [sci2exp([]); + sci2exp(outmask); + fname; + frmt; + string(N); + sci2exp(out)] + gr_i = []; + + x = standard_define([3 2],model,exprs,gr_i) + end + +endfunction diff --git a/macros/Sources/SAWTOOTH_f.sci b/macros/Sources/SAWTOOTH_f.sci new file mode 100644 index 00000000..e66aa26e --- /dev/null +++ b/macros/Sources/SAWTOOTH_f.sci @@ -0,0 +1,42 @@ +// 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]=SAWTOOTH_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim="sawtth" + model.out=1 + model.evtin=1 + model.dstate=0 + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=" " + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/STEP.sci b/macros/Sources/STEP.sci new file mode 100644 index 00000000..6c238078 --- /dev/null +++ b/macros/Sources/STEP.sci @@ -0,0 +1,86 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 - Bernard DUJARDIN <bernard.dujardin@contrib.scilab.org> +// +// 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]=STEP(job,arg1,arg2) + // Copyright INRIA + x=[];y=[];typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics;exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,temps,in,fi,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "STEP_FUNCTION");" "; .. + gettext("Step Function");" "], .. + [gettext("Step Time"); gettext("Initial Value"); gettext("Final Value")], .. + list("vec",1,"vec",-1,"vec",-1), exprs); + if ~ok then + break, + end + in=in(:);fi=fi(:); + if size(in,"*")<>size(fi,"*") then + if size(in,"*")==1 then + in=in*ones(fi) + elseif size(fi,"*")==1 then + fi=fi*ones(in) + else + block_parameter_error(msprintf(gettext("''Initial Value'' and ''Final Value'': incompatible sizes: %d and %d."), size(in,"*"), size(fi,"*")), gettext("Same sizes expected.")); + ok=%f + end + end + if ok then + model.out2=1; + model.outtyp=1; + [model,graphics,ok]=check_io(model,graphics,[],size(fi,"*"),1,1) + end + if ok then + model.firing=temps + if temps==0 then + rpar=[fi;fi] + else + rpar=[in;fi] + end + model.rpar=rpar + graphics.exprs=exprs + x.graphics=graphics;x.model=model + break + end + end + case "define" then + rpar=[0;1] + model=scicos_model() + model.sim=list("step_func",4) + model.evtin=1 + model.evtout=1 + model.out=1 + model.out2=1; + model.outtyp=1; + model.firing=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%f %f] + + exprs=[string(1);string(rpar)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sources/STEP_FUNCTION.sci b/macros/Sources/STEP_FUNCTION.sci new file mode 100644 index 00000000..f622ba9a --- /dev/null +++ b/macros/Sources/STEP_FUNCTION.sci @@ -0,0 +1,180 @@ +// 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]=STEP_FUNCTION(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the internal edge trigger block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "STEP" then + ppath = list(i); + break; + end + end + newpar=list(); + for path=ppath do + np=size(path,"*") + spath=list() + for k=1:np + spath($+1)="model" + spath($+1)="rpar" + spath($+1)="objs" + spath($+1)=path(k) + end + xx=arg1(spath)// get the block + execstr("xxn="+xx.gui+"(''set'',xx)") + + 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 + // input or output port sizes changed + needcompile=1 + end + if or(model.firing<>model_n.firing) then + // initexe changed + 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 + // type 'c','d','z','l' or dep_ut changed + needcompile=4 + end + if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then + // size of zero cross changed + needcompile=4 + end + if prod(size(model_n.sim))>1 then + if model_n.sim(2)>1000 then // Fortran or C Block + if model.sim(1)<>model_n.sim(1) then //function name has changed + needcompile=4 + end + end + end + else //implicit block + //force compilation if an implicit block has been edited + 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)=path// Notify modification + end + end + x=arg1 + y=needcompile + typ=newpar + case "define" then + scs_m_1=scicos_diagram(); + scs_m_1.objs(1) = STEP("define"); + scs_m_1.objs(2) = OUT_f("define"); + scs_m_1.objs(3) = scicos_link(); + scs_m_1.objs(4) = scicos_link(); + + // STEP + blk = scs_m_1.objs(1); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [0 0]; + graphics.sz = [40 40]; + + graphics.pein = 4; + graphics.peout = 4; + graphics.pout = 3; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(1) = blk; + + // OUT_f + blk = scs_m_1.objs(2); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [80 10]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pin = 3; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(2) = blk; + + // STEP -> OUT_f + lnk = scs_m_1.objs(3); + + lnk.from = [1 1 0]; + lnk.to = [2 1 1]; + + scs_m_1.objs(3) = lnk; + + // STEP -> STEP + lnk = scs_m_1.objs(4); + + lnk.xx = [0 20 -20 -20 20 1]; + lnk.yy = [0 -20 -20 60 60 1]; + + lnk.ct = [5 -1]; + lnk.from = [1 1 0]; + lnk.to = [1 1 1]; + + scs_m_1.objs(4) = lnk; + + clear blk lnk + + model=scicos_model(); + model.sim = "csuper"; + model.out = 1; + model.out2=1; + model.outtyp=1; + + model.rpar = scs_m_1; + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction + diff --git a/macros/Sources/SampleCLK.sci b/macros/Sources/SampleCLK.sci new file mode 100644 index 00000000..7ca12310 --- /dev/null +++ b/macros/Sources/SampleCLK.sci @@ -0,0 +1,83 @@ +// 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]=SampleCLK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + model=arg1.model; + exprs=graphics.exprs + while %t do + [ok,frequ,offset,exprs]=scicos_getvalue("Set block parameters",.. + ["Sample time";"Offset"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if frequ<0 then + message("Frequency must be a positif number"); + ok=%f; + end + if abs(offset) > frequ then + message("The |Offset| must be less than the Frequency"); + ok=%f + end + if ok then + if or(model.rpar(:)<>[frequ;offset]) then + needcompile=4; + y=needcompile, + end + model.rpar=[frequ;offset] + model.evtout=1 + model.firing=-1//compatibility + // aa=max(length(exprs(1)),length(exprs(2))); + // if aa>1 then + // graphics.sz=[10*aa 20] + // else + // graphics.sz=[20 20] + // end + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="sampleclk" + model.evtout=1 + model.rpar=[1,0] + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + exprs=[sci2exp(1);sci2exp(0)] + x=standard_define([2 2],model,exprs," ") + // x.graphics.id="S-CLK" + end +endfunction + + diff --git a/macros/Sources/Sigbuilder.sci b/macros/Sources/Sigbuilder.sci new file mode 100644 index 00000000..01c77507 --- /dev/null +++ b/macros/Sources/Sigbuilder.sci @@ -0,0 +1,517 @@ +// 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] = Sigbuilder(job,arg1,arg2) + //** updated for Scilab 5.1 by Simone Mannori + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + // look for the internal curve block + ppath = list(0); + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "CURVE_c" then + ppath(1) = i; + break; + end + end + newpar = list(); + y = 0; + for path = ppath do + np = size(path,"*") + spath = list() + for k=1:np + spath($+1)="model" + spath($+1)="rpar" + spath($+1)="objs" + spath($+1)=path(k) + end + xx=arg1(spath) // get the block + execstr("xxn="+xx.gui+"(''set'',xx)") + 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.odstate,model_n.odstate)|.. + ~isequal(model.rpar,model_n.rpar)|.. + ~isequal(model.ipar,model_n.ipar)|.. + ~isequal(model.opar,model_n.opar)|.. + ~isequal(model.label,model_n.label) + if or(model.in<>model_n.in)|or(model.out<>model_n.out)|.. + or(model.in2<>model_n.in2)|or(model.out2<>model_n.out2)|.. + or(model.outtyp<>model_n.outtyp)|or(model.intyp<>model_n.intyp) then + needcompile=1 + end + if or(model.firing<>model_n.firing) then + needcompile=2 + end + if (size(model.in,"*")<>size(model_n.in,"*"))|.. + (size(model.out,"*")<>size(model_n.out,"*")) then + needcompile=4 + 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)=path// Notify modification + y=max(y,needcompile) + end + end + x=arg1 + typ=newpar + + case "define" then + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["Sigbuilder","./"],.. + tol=[0.0001;0.000001;1.000D-10;100001;0;0;0],.. + tf=100,.. + context=" ",.. + void1=[],.. + options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],.. + list([5,1],[4,1]),[0.8,0.8,0.8]),.. + void2=[],.. + void3=[],.. + doc=list())) + scs_m_1.objs(1)=scicos_block(.. + gui="CURVE_c",.. + graphics=scicos_graphics(.. + orig=[329.63473,606.18517],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["3";"[0,1,2]";"[10,20,-30]";"y";"n"],.. + pin=[],.. + pout=6,.. + pein=4,.. + peout=2,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("curve_c",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[0;1;2;10;20;-30],.. + ipar=[3;3;1],.. + opar=list(),.. + blocktype="c",.. + firing=0,.. + dep_ut=[%f,%t],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_link(.. + xx=[349.63473;349.49528],.. + yy=[600.47089;565.10704],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[1,1,0],.. + to=[3,1,1]) + scs_m_1.objs(3)=scicos_block(.. + gui="CLKSPLIT_f",.. + graphics=scicos_graphics(.. + orig=[349.49528;565.10704],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=[],.. + pein=2,.. + peout=[8;4],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="split",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=[1;1],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=[%f,%f,%f],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(4)=scicos_link(.. + xx=[349.49528;266.69602;266.69602;270.35525;342.80795;342.80795;349.63473],.. + yy=[565.10704;565.10704;680.99483;680.99483;680.99483;651.89946;651.89946],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[3,2,0],.. + to=[1,1,1]) + scs_m_1.objs(5)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[398.20616,616.18517],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=6,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=-2,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(6)=scicos_link(.. + xx=[378.20616;398.20616],.. + yy=[626.18517;626.18517],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[5,1,1]) + scs_m_1.objs(7)=scicos_block(.. + gui="CLKOUTV_f",.. + graphics=scicos_graphics(.. + orig=[339.49528,505.10704],.. + sz=[20,30],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=[],.. + pein=8,.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(8)=scicos_link(.. + xx=[349.49528;349.49528],.. + yy=[565.10704;535.10704],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[3,1,0],.. + to=[7,1,1]) + model=scicos_model(.. + sim="csuper",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=scs_m_1,.. + ipar=[],.. + opar=list(),.. + blocktype="h",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()) + gr_i=[] + + x=standard_define([3 2],model,[],gr_i) + end +endfunction + + +//========================================================= +function [X,Y,orpar]=Do_Spline2(N,order,x,y) + + X=[];Y=[];orpar=[]; + METHOD=getmethod(order); + + if (METHOD=="zero order") then + X=x(1);Y=y(1); + for i=1:N-1 + X=[X;x(i);x(i+1);x(i+1)]; + Y=[Y;y(i);y(i);y(i+1)]; + end + return; + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="linear") then + X=[]; + for i=1:N + X=[X;x(i)]; + Y=[Y;y(i)]; + end + return; + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (N<20) then + NP=4; + else + if (N<40) then + NP=2; + else + if (N<100) then + NP=1; + else + NP=0; + end; + end; + end + for i=1:N-1 + X=[X;linspace(x(i),x(i+1),NP+2)']; // pour tous sauf "linear" et "zero order" + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (N>2) & (METHOD=="order 2") then + Z=ORDER2(x,y); + A=Z(1:N-1); + B=Z(N:2*N-2); + C=Z(2*N-1:3*N-3); + + for j=1:size(X,"*") + for i=N-1:-1:1 + if X(j)>=x(i) then,break;end + end + Y(j)=A(i)*(X(j)-x(i))^2+B(i)*(X(j)-x(i))+C(i); + end + orpar=matrix(Z,-1,1) + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="not_a_knot") then + try + d = splin(x, y, METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="periodic") then + if y(1)<>y(N) then + y(N)=y(1) + end + try + d = splin(x, y,METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="monotone" ) then + try + d = splin(x, y, METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="fast") then + try + d = splin(x, y, METHOD); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="clamped") then + try + d = splin(x, y, METHOD,[0;0]); + Y = interp(X, x, y, d); + orpar=d(:); + catch + xinfo("ERROR in SPLINE: "+METHOD) + end + end + +endfunction + +function METHOD=getmethod(order) + select order + case 0 then, METHOD="zero order" + case 1 then, METHOD="linear" + case 2 then, METHOD="order 2" + case 3 then, METHOD="not_a_knot" + case 4 then, METHOD="periodic" + case 5 then, METHOD="monotone" + case 6 then, METHOD="fast" + case 7 then, METHOD="clamped" + end +endfunction + + +function [Z]=ORDER2(x,y) + N=size(x,"*")-1; + A=zeros(3*N-1,N*3); + B=zeros(3*N-1,1); + for i=1:N + j=3*(i-1)+1; + A(j,i+2*N)=1; + B(j)=y(i); + A(j+1,i)=(x(i+1)-x(i))^2; + A(j+1,i+N)=x(i+1)-x(i); + A(j+1,i+2*N)=1; + B(j+1)=y(i+1); + end + + for i=1:N-1 + j=3*(i-1)+1; + A(j+2,i)=2*(x(i+1)-x(i)); + A(j+2,i+N)=1; + A(j+2,i+N+1)=-1; + end + + Q=zeros(3*N,3*N); + for i=1:N + Q(i,i)=4*(x(i+1)-x(i))^2 + Q(i,i+N)=2*(x(i+1)-x(i)) + Q(i+N,i)=2*(x(i+1)-x(i)) + Q(i+N,i+N)=1; + end + + At=[Q,A';A,zeros(3*N-1,3*N-1)] + Bt=[zeros(3*N,1);B] + Zt=At\Bt; + Z=Zt(1:3*N,1) +endfunction +//=================================================== + + + + + + diff --git a/macros/Sources/TIME_f.sci b/macros/Sources/TIME_f.sci new file mode 100644 index 00000000..0af91f55 --- /dev/null +++ b/macros/Sources/TIME_f.sci @@ -0,0 +1,40 @@ +// 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]=TIME_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + + model=scicos_model() + model.sim="timblk" + model.out=1 + model.blocktype="c" + model.dep_ut=[%f %t] + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Sources/TKSCALE.sci b/macros/Sources/TKSCALE.sci new file mode 100644 index 00000000..3f2e1131 --- /dev/null +++ b/macros/Sources/TKSCALE.sci @@ -0,0 +1,63 @@ +// 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]=TKSCALE(job,arg1,arg2) + //Source block; output defined by tk widget scale + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + [ok,a,b,f,exprs]=scicos_getvalue("Set scale block parameters",.. + ["Min value";"Max value";"Normalization"],.. + list("vec",1,"vec",1,"vec",1),exprs) + // tk widget returns a scalar, the value is divided by + // Normalization factor + if ok then + graphics.exprs=exprs + model.rpar=[a;b;f] + x.graphics=graphics; + x.model=model + end + case "define" then + a=-10; + b=10; + f=1;// default parameter values + model=scicos_model() + model.sim=list("tkscaleblk",5) + model.out=1 + model.evtin=1 + model.rpar=[a;b;f] + model.blocktype="d" + model.dep_ut=[%f %f] + exprs=[sci2exp(a);sci2exp(b);sci2exp(f)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction + + + + |