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 | |
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
274 files changed, 33890 insertions, 0 deletions
diff --git a/macros/Branching/CLKFROM.sci b/macros/Branching/CLKFROM.sci new file mode 100644 index 00000000..0bc3e39a --- /dev/null +++ b/macros/Branching/CLKFROM.sci @@ -0,0 +1,62 @@ +// 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]=CLKFROM(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,tag,exprs]=scicos_getvalue("Set block parameters",.. + "Tag",list("str",-1),exprs) + if ~ok then + break, + end + if model.opar<>list(tag) then + needcompile=4; + y=needcompile, + end + model.opar=list(tag) + model.evtout=1 + model.firing=-1//compatibility + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="clkfrom" + model.evtout=1 + model.opar=list("A") + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + exprs="A" + x=standard_define([2 1],model,exprs," ") + x.graphics.id="From" + end +endfunction diff --git a/macros/Branching/CLKGOTO.sci b/macros/Branching/CLKGOTO.sci new file mode 100644 index 00000000..19957cb5 --- /dev/null +++ b/macros/Branching/CLKGOTO.sci @@ -0,0 +1,71 @@ +// 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]=CLKGOTO(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,tag,tagvis,exprs]=scicos_getvalue("Set block parameters",.. + ["Tag";"Tag Visibility (1=Local 2=Scoped 3=Global)"], list("str",-1,"vec",1),exprs) + if ~ok then + break, + end + if ((tagvis<1)|(tagvis>3)) then + message("Tag Visibility must be between 1 and 3");ok=%f; + end + tagvis=int(tagvis); + if ok then + if ((model.opar<>list(tag))| (model.ipar<>tagvis)) then + needcompile=4;y=needcompile + end + model.opar=list(tag) + model.ipar=tagvis + model.evtin=1 + model.firing=-1//compatibility + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="clkgoto" + model.evtin=1 + model.opar=list("A") + model.ipar=int(1) + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + exprs=["A";sci2exp(1)] + x=standard_define([2 1],model,exprs," ") + x.graphics.id="Goto" + end +endfunction diff --git a/macros/Branching/CLKGotoTagVisibility.sci b/macros/Branching/CLKGotoTagVisibility.sci new file mode 100644 index 00000000..59dccf03 --- /dev/null +++ b/macros/Branching/CLKGotoTagVisibility.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] = CLKGotoTagVisibility(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,tag,exprs]=scicos_getvalue("Set parameters",.. + ["GotoTag"],.. + list("str",-1),exprs) + if ~ok then + break, + end + if ok then + if model.opar<>list(tag) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag); + x.graphics=graphics; + x.model=model; + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="clkgototagvisibility" + model.in=[] + model.in2=[] + model.out=[] + model.out2=[] + model.evtin=[] + model.intyp=1 + model.outtyp=1 + model.opar=list("A"); + model.blocktype="c" + model.firing=%f + model.dep_ut=[%f %f] + exprs="A" + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/DEMUX.sci b/macros/Branching/DEMUX.sci new file mode 100644 index 00000000..2e1cb8fa --- /dev/null +++ b/macros/Branching/DEMUX.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]=DEMUX(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,out,exprs]=scicos_getvalue("Set DEMUX block parameters",.. + ["number of output ports or vector of sizes"],list("intvec",-1),exprs) + if ~ok then + break, + end + if size(out,"*")==1 then + if out<2|out>31 then + message("Block must have at least 2 and at most 31 output ports") + ok=%f + else + [model,graphics,ok]=check_io(model,graphics,0,-[1:out]',[],[]) + end + else + if size(out,"*")<2| or(out==0)|size(out,"*")>31 then + message(["Block must have at least 2 and at most 31 output ports"; + "size 0 is not allowed"]) + ok=%f + else + if min(out)<0 then + nin=0, + else + nin=sum(out), + end + [model,graphics,ok]=check_io(model,graphics,nin,out(:),[],[]) + if ok then + out=size(out,"*"), + end + end + end + if ok then + graphics.exprs=exprs; + model.ipar=out + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + out=2 + model=scicos_model() + model.sim=list("multiplex",4) + model.in=0 //means equal to the sum of the outputs + model.out=-[1:out]' + model.ipar=out + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + + exprs=string(out) + gr_i=[] + x=standard_define([.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/DEMUX_f.sci b/macros/Branching/DEMUX_f.sci new file mode 100644 index 00000000..ebccbc0a --- /dev/null +++ b/macros/Branching/DEMUX_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]=DEMUX_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,out,exprs]=scicos_getvalue("Set DEMUX block parameters",.. + ["number of output ports or vector of sizes"],list("vec",-1),exprs) + if ~ok then + break, + end + if size(out,"*")==1 then + if out<2 | out>8 then + message("Block must have at least 2 and at most 8 output ports") + ok=%f + else + [model,graphics,ok]=check_io(model,graphics,0,-[1:out]',[],[]) + end + else + if size(out,"*")<2| size(out,"*")>8|or(out==0) then + message(["Block must have at least 2 and at most 8 output ports"; + "and size 0 is not allowed"] ) + ok=%f + else + if min(out)<0 then + nin=0, + else + nin=sum(out), + end + [model,graphics,ok]=check_io(model,graphics,nin,out(:),[],[]) + if ok then + out=size(out,"*"), + end + end + end + if ok then + graphics.exprs=exprs; + model.ipar=out + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + out=2 + model=scicos_model() + model.sim=list("demux",1) + model.in=0 //???? + model.out=-[1:out]' + model.ipar=out + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + + exprs=string(out) + gr_i=[] + x=standard_define([.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/ESELECT_f.sci b/macros/Branching/ESELECT_f.sci new file mode 100644 index 00000000..1fe26647 --- /dev/null +++ b/macros/Branching/ESELECT_f.sci @@ -0,0 +1,90 @@ +// 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]=ESELECT_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[] + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==1 then + exprs(2)=string(1); + end + if size(exprs,"*")==2 then + exprs(3)=string(0); + end + model=arg1.model; + while %t do + [ok,out,inh,nmod,exprs]=scicos_getvalue("Set ESELECT block parameters",.. + ["number of output event ports";"Inherit (1: no, 0: yes)"; + "zero-crossing (0: no, 1: yes)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if nmod<>0 then + nmod=1, + end + if inh==0 then + inh=[]; + else + inh=1; + end + out=int(out) + if out<2 then + message("Block must have at least two output ports") + else + [model,graphics,ok]=check_io(model,graphics,1,[],inh,[ones(out,1)]) + if ok then + graphics.exprs=exprs; + model.evtout=ones(out,1); + model.firing=-ones(out,1) + x.graphics=graphics; + model.nmode=nmod + model.nzcross=nmod + x.model=model + break + end + end + end + case "define" then + out=2 + model=scicos_model() + model.sim=list("eselect",-2) + model.in=1 + model.in2=1 + model.intyp=-1 + model.evtin=1 + model.evtout=ones(out,1); + model.blocktype="l" + model.firing=-ones(out,1); + model.dep_ut=[%t %f] + model.nmode=0 + model.nzcross=0 + + gr_i=[] + exprs=[string(out);string(1);string(model.nmode)] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/EXTRACTOR.sci b/macros/Branching/EXTRACTOR.sci new file mode 100644 index 00000000..dd682b7e --- /dev/null +++ b/macros/Branching/EXTRACTOR.sci @@ -0,0 +1,64 @@ +// 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]=EXTRACTOR(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,ind,exprs]=.. + scicos_getvalue("Set block parameters",.. + ["indices to extract"],.. + list("vec",-1),exprs) + if ~ok then + break, + end + ind=int(ind); + ind=ind(:); + [model,graphics,ok]=check_io(model,graphics,[-1],size(ind,1),[],[]) + if ok then + model.ipar=ind + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + ind=1 + model=scicos_model() + model.sim=list("extractor",4) + model.in=-1 + model.out=1 + model.blocktype="c" + model.dep_ut=[%t %f] + model.ipar=ind + exprs=[sci2exp(ind)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/FROM.sci b/macros/Branching/FROM.sci new file mode 100644 index 00000000..61b6e6c7 --- /dev/null +++ b/macros/Branching/FROM.sci @@ -0,0 +1,72 @@ +// 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]=FROM(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,tag,exprs]=scicos_getvalue("Set parameters",.. + ["Tag"],.. + list("str",-1),exprs) + if ~ok then + break, + end + if ok then + if model.opar<>list(tag) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag) + x.model=model + x.graphics=graphics + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="from" + model.in=[] + model.in2=[] + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=-1 + model.ipar=[] + model.opar=list("A") + model.blocktype="c" + model.dep_ut=[%f %f] + + exprs=["A"] + + gr_i=[]; + x=standard_define([2 1],model,exprs,gr_i) + x.graphics.id="From" + end +endfunction diff --git a/macros/Branching/FROMMO.sci b/macros/Branching/FROMMO.sci new file mode 100644 index 00000000..5aaf60bc --- /dev/null +++ b/macros/Branching/FROMMO.sci @@ -0,0 +1,74 @@ +// 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]=FROMMO(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,tag,exprs]=scicos_getvalue("Set parameters",.. + ["Tag"],.. + list("str",-1),exprs) + if ~ok then + break, + end + if ok then + if model.opar<>list(tag) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag) + x.model=model + x.graphics=graphics + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="frommo" + model.in=[] + model.in2=[] + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=-1 + model.ipar=[] + model.opar=list("A") + model.blocktype="c" + model.dep_ut=[%f %f] + mo=modelica() + mo.model="frommo" + mo.outputs="n" + exprs=["A"] + + gr_i=[]; + x=standard_define([2 1],model,exprs,gr_i) + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Branching/GOTO.sci b/macros/Branching/GOTO.sci new file mode 100644 index 00000000..b9ce8846 --- /dev/null +++ b/macros/Branching/GOTO.sci @@ -0,0 +1,79 @@ +// 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]=GOTO(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,tag,tagvis,exprs]=scicos_getvalue("Set parameters",.. + ["Tag";"Tag Visibility(1=Local 2=scoped 3= global)"],.. + list("str",-1,"vec",1),exprs) + if ~ok then + break, + end + tagvis=int(tagvis) + if ((tagvis<1)|(tagvis>3)) then + message("Tag Visibility must be between 1 and 3");ok=%f; + end + if ok then + if ((model.ipar<>tagvis)|(model.opar<>list(tag))) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag) + model.ipar=tagvis + x.model=model + x.graphics=graphics + arg1=x + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="goto" + model.in=-1 + model.in2=-2 + model.intyp=-1 + model.out=[] + model.out2=[] + model.outtyp=1 + model.ipar=int(1) + model.opar=list("A") + model.blocktype="c" + model.dep_ut=[%f %f] + + exprs=["A";sci2exp(1)] + + gr_i=[]; + x=standard_define([2 1],model,exprs,gr_i) + x.graphics.id="Goto" + end +endfunction + diff --git a/macros/Branching/GOTOMO.sci b/macros/Branching/GOTOMO.sci new file mode 100644 index 00000000..39743047 --- /dev/null +++ b/macros/Branching/GOTOMO.sci @@ -0,0 +1,80 @@ +// 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]=GOTOMO(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,tag,tagvis,exprs]=scicos_getvalue("Set parameters",.. + ["Tag";"Tag Visibility(1=Local 2=scoped 3= global)"],.. + list("str",-1,"vec",1),exprs) + if ~ok then + break, + end + tagvis=int(tagvis) + if ((tagvis<1)|(tagvis>3)) then + message("Tag Visibility must be between 1 and 3");ok=%f; + end + if ok then + if ((model.ipar<>tagvis)|(model.opar<>list(tag))) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag) + model.ipar=tagvis + x.model=model + x.graphics=graphics + arg1=x + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="gotomo" + model.in=-1 + model.in2=-2 + model.intyp=[] + model.out=[] + model.out2=[] + model.outtyp=1 + model.ipar=int(1) + model.opar=list("A") + model.blocktype="c" + model.dep_ut=[%f %f] + mo=modelica() + mo.model="gotomo" + mo.inputs="p" + exprs=["A";sci2exp(1)] + + gr_i=[]; + x=standard_define([2 1],model,exprs,gr_i) + x.graphics.in_implicit=["I"] + end +endfunction diff --git a/macros/Branching/GotoTagVisibility.sci b/macros/Branching/GotoTagVisibility.sci new file mode 100644 index 00000000..daa11362 --- /dev/null +++ b/macros/Branching/GotoTagVisibility.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]=GotoTagVisibility(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,tag,exprs]=scicos_getvalue("Set parameters",.. + ["GotoTag"],.. + list("str",-1),exprs) + if ~ok then + break, + end + if ok then + if model.opar<>list(tag) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag); + x.graphics=graphics; + x.model=model; + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="gototagvisibility" + model.in=[] + model.in2=[] + model.out=[] + model.out2=[] + model.evtin=[] + model.intyp=1 + model.outtyp=1 + model.opar=list("A"); + model.blocktype="c" + model.firing=%f + model.dep_ut=[%f %f] + exprs="A" + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/GotoTagVisibilityMO.sci b/macros/Branching/GotoTagVisibilityMO.sci new file mode 100644 index 00000000..72c00925 --- /dev/null +++ b/macros/Branching/GotoTagVisibilityMO.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]=GotoTagVisibilityMO(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,tag,exprs]=scicos_getvalue("Set parameters",.. + ["GotoTag"],.. + list("str",-1),exprs) + if ~ok then + break, + end + if ok then + if model.opar<>list(tag) then + needcompile=4; + y=needcompile, + end + graphics.exprs=exprs; + model.opar=list(tag); + x.graphics=graphics; + x.model=model; + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim="gototagvisibilitymo" + model.in=[] + model.in2=[] + model.out=[] + model.out2=[] + model.evtin=[] + model.intyp=1 + model.outtyp=1 + model.opar=list("A"); + model.blocktype="c" + model.firing=%f + model.dep_ut=[%f %f] + exprs="A" + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/ISELECT_f.sci b/macros/Branching/ISELECT_f.sci new file mode 100644 index 00000000..976511a3 --- /dev/null +++ b/macros/Branching/ISELECT_f.sci @@ -0,0 +1,69 @@ +// 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]=ISELECT_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,nout,z0,exprs]=scicos_getvalue("Set parameters",.. + ["number of outputs";"initial connected output"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if z0>nout|z0<=0 then + message("initial connected input is not a valid input port number") + else + [model,graphics,ok]=check_io(model,graphics,-1,-ones(nout,1),ones(nout,1),[]) + if ok then + graphics.exprs=exprs; + model.dstate=z0-1, + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + z0=0 + out=[-1;-1] + nout=2 + model=scicos_model() + model.sim=list("selector",2) + model.in=-1 + model.out=out + model.evtin=ones(out) + model.dstate=z0 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(nout);string(z0+1)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/ISELECT_m.sci b/macros/Branching/ISELECT_m.sci new file mode 100644 index 00000000..97efbbfd --- /dev/null +++ b/macros/Branching/ISELECT_m.sci @@ -0,0 +1,87 @@ +// 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]=ISELECT_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,typ,nout,z0,exprs]=scicos_getvalue("Set parameters",.. + ["Datatype(1= real double 2=Complex 3=int32 ...)";"number of outputs";"initial connected output"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if z0>nout|z0<=0 then + message("initial connected input is not a valid input port number") + elseif ((typ<1)|(typ>8)) then + message("Datatype is not supported"); + ok=%f; + else + it=typ + ot=typ*ones(1,nout) + if ok then + out=[-ones(nout,1) -2*ones(nout,1)] + in=[-1 -2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(nout,1),[]) + if ok then + graphics.exprs=exprs; + model.dstate=z0, + x.graphics=graphics; + x.model=model + break + end + end + end + end + case "define" then + z0=1 + nout=2 + + model=scicos_model() + model.sim=list("selector_m",4) + model.out=[-1;-1] + model.out2=[-2;-2] + model.outtyp=1 + model.in=-1 + model.in2=-2 + model.intyp=1 + model.evtout=[] + model.state=[] + model.rpar=[] + model.ipar=[] + model.firing=[] + model.evtin=ones(nout,1) + model.dstate=z0 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(1);sci2exp(nout);sci2exp(z0)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/MUX.sci b/macros/Branching/MUX.sci new file mode 100644 index 00000000..b6852355 --- /dev/null +++ b/macros/Branching/MUX.sci @@ -0,0 +1,84 @@ +// 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]=MUX(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,in,exprs]=scicos_getvalue("Set MUX block parameters",.. + "number of input ports or vector of sizes",list("intvec",-1),exprs) + if ~ok then + break, + end + if size(in,"*")==1 then + if in<2|in>31 then + message("Block must have at least two input ports and at most 31") + ok=%f + else + [model,graphics,ok]=check_io(model,graphics,-[1:in]',0,[],[]) + end + else + if size(in,"*")<2| or(in==0)|size(in,"*")>31 then + message(["Block must have at least two input ports"; + "and at most 31. Size 0 is not allowed. "]) + ok=%f + else + if min(in)<0 then + nout=0, + else + nout=sum(in), + end + [model,graphics,ok]=check_io(model,graphics,in(:),nout,[],[]) + if ok then + in=size(in,"*"), + end + end + end + if ok then + graphics.exprs=exprs; + model.ipar=in + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=2 + model=scicos_model() + model.sim=list("multiplex",4) + model.in=-[1:in]' + model.out=0 + model.ipar=in + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=string(in) + gr_i=[] + x=standard_define([.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/MUX_f.sci b/macros/Branching/MUX_f.sci new file mode 100644 index 00000000..0b27f23f --- /dev/null +++ b/macros/Branching/MUX_f.sci @@ -0,0 +1,84 @@ +// 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]=MUX_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,in,exprs]=scicos_getvalue("Set MUX block parameters",.. + "number of input ports or vector of sizes",list("vec",-1),exprs) + if ~ok then + break, + end + if size(in,"*")==1 then + if in<2|in>8 then + message("Block must have at least two input ports and at most eight") + ok=%f + else + [model,graphics,ok]=check_io(model,graphics,-[1:in]',0,[],[]) + end + else + if size(in,"*")<2| size(in,"*")>8|or(in==0) then + message(["Block must have at least two input ports"; + "and at most eight, and size 0 is not allowed. "]) + ok=%f + else + if min(in)<0 then + nout=0, + else + nout=sum(in), + end + [model,graphics,ok]=check_io(model,graphics,in(:),nout,[],[]) + if ok then + in=size(in,"*"), + end + end + end + if ok then + graphics.exprs=exprs; + model.ipar=in + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=2 + model=scicos_model() + model.sim=list("mux",1) + model.in=-[1:in]' + model.out=0 + model.ipar=in + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=string(in) + gr_i=[] + x=standard_define([0.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/M_SWITCH.sci b/macros/Branching/M_SWITCH.sci new file mode 100644 index 00000000..d3150c7a --- /dev/null +++ b/macros/Branching/M_SWITCH.sci @@ -0,0 +1,89 @@ +// 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]=M_SWITCH(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,nin,base,rule,exprs]=scicos_getvalue("Set parameters",.. + ["number of inputs";"zero base indexing (0), otherwise 1";.. + "rounding rule: int (0), round (1), ceil (2), floor (3)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + nin=int(nin); + base=int(base); + if nin<1 then + message("Number of inputs must be >=1 ") + elseif ~((base==1)|(base==0)) then + message("base indexing must be 1 or 0") + elseif ~((rule==1)|(rule==0)|(rule==2)|(rule==3)) then + message("incorrect rounding rule") + else + if nin==1 then + in=[1 1;-1 1]; + out=[1 1]; + else + in1=[1;-ones(nin,1)]; + in2=[1;-2*ones(nin,1)]; + in=[in1 in2]; + out=[-1 -2]; + end + it=[-1;-2*ones(nin,1)]; + ot=-2; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + //[model,graphics,ok]=check_io(model,graphics,[1;-ones(nin,1)],-1,[],[]) + if ok then + graphics.exprs=exprs; + model.ipar=[base;rule], + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + in=[1;-1;-1] + ipar=[1;3] + nin=2 + + model=scicos_model() + model.sim=list("mswitch",4) + model.in=in + model.out=-1 + model.ipar=ipar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(nin);string(ipar)] + + gr_i=[] + x=standard_define([2.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/NRMSOM_f.sci b/macros/Branching/NRMSOM_f.sci new file mode 100644 index 00000000..e02427bb --- /dev/null +++ b/macros/Branching/NRMSOM_f.sci @@ -0,0 +1,60 @@ +// 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]=NRMSOM_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,nin,exprs]=scicos_getvalue("Set parameters",.. + ["number of inputs"],list("vec",1),exprs) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,-ones(nin,1),-1,[],[]) + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break; + end + end + case "define" then + in=[-1;-1] + nin=2 + model=scicos_model() + model.sim="junk" + model.in=in + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(nin)] + gr_i=[] + x=standard_define([.2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/RELAY_f.sci b/macros/Branching/RELAY_f.sci new file mode 100644 index 00000000..50a728b7 --- /dev/null +++ b/macros/Branching/RELAY_f.sci @@ -0,0 +1,71 @@ +// 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]=RELAY_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + ipar=model.ipar + while %t do + [ok,nin,z0,exprs]=scicos_getvalue("Set parameters",.. + ["number of inputs";"initial connected input"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if z0>nin|z0<=0 then + message("initial connected input is not a valid input port number") + else + [model,graphics,ok]=check_io(model,graphics,-ones(nin,1),-1,ones(nin,1),[]) + if ok then + graphics.exprs=exprs; + model.dstate=z0-1 + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + i0=0 + in=[-1;-1] + nin=2 + model=scicos_model() + model.sim=list("relay",2) + model.in=in + model.out=-1 + model.evtin=ones(in) + model.dstate=i0 + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %t] + + exprs=[string(nin);string(i0+1)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/SCALAR2VECTOR.sci b/macros/Branching/SCALAR2VECTOR.sci new file mode 100644 index 00000000..ac3534d2 --- /dev/null +++ b/macros/Branching/SCALAR2VECTOR.sci @@ -0,0 +1,69 @@ +// 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]=SCALAR2VECTOR(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,nout,exprs]=.. + scicos_getvalue("Set block parameters",.. + ["size of output (-1: if don''t know)"],.. + list("vec",1),exprs) + if ~ok then + break, + end + nout=int(nout) + if(nout<>-1 & (nout<=0)) then + message("size of output must be -1 or >0") + ok=%f + end + if ok then + [model,graphics,ok]=check_io(model,graphics,[1],nout,[],[]) + end + if ok then + graphics.exprs=exprs;// Correction ED le 24/11/04 + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nout=-1 + model=scicos_model() + model.sim=list("scalar2vector",4) + model.out=nout + model.in=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string([nout])] + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/SELECT_f.sci b/macros/Branching/SELECT_f.sci new file mode 100644 index 00000000..dce35add --- /dev/null +++ b/macros/Branching/SELECT_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]=SELECT_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,nin,z0,exprs]=scicos_getvalue("Set parameters",.. + ["number of inputs";"initial connected input"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if z0>nin|z0<=0 then + message("initial connected input is not a valid input port number") + else + [model,graphics,ok]=check_io(model,graphics,-ones(nin,1),-1,ones(nin,1),[]) + if ok then + graphics.exprs=exprs; + model.dstate=z0-1, + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + z0=0 + in=[-1;-1] + nin=2 + + model=scicos_model() + model.sim=list("selector",2) + model.in=in + model.out=-1 + model.evtin=ones(in) + model.dstate=z0 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(nin);string(z0+1)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/SELECT_m.sci b/macros/Branching/SELECT_m.sci new file mode 100644 index 00000000..be30bdc1 --- /dev/null +++ b/macros/Branching/SELECT_m.sci @@ -0,0 +1,87 @@ +// 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]=SELECT_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,typ,nin,z0,exprs]=scicos_getvalue("Set parameters",.. + ["Datatype(1= real double 2=Complex 3=int32 ..)";"number of inputs";"initial connected input"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if z0>nin|z0<=0 then + message("initial connected input is not a valid input port number") + elseif ((typ<1)|(typ>8))& (typ<>-1) then + message("Datatype is not supported"); + ok=%f; + else + it=typ*ones(1,nin) + ot=typ + if ok then + in=[-ones(nin,1) -2*ones(nin,1)] + out=[-1 -2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(nin,1),[]) + if ok then + graphics.exprs=exprs; + model.dstate=z0, + x.graphics=graphics; + x.model=model + break + end + end + end + end + case "define" then + z0=1 + nin=2 + + model=scicos_model() + model.sim=list("selector_m",4) + model.in=[-1;-1] + model.in2=[-2;-2] + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.evtout=[] + model.state=[] + model.rpar=[] + model.ipar=[] + model.firing=[] + model.evtin=ones(nin,1) + model.dstate=z0 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(1);sci2exp(nin);sci2exp(z0)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/SELF_SWITCH.sci b/macros/Branching/SELF_SWITCH.sci new file mode 100644 index 00000000..52af0715 --- /dev/null +++ b/macros/Branching/SELF_SWITCH.sci @@ -0,0 +1,82 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt +// +// +function [x,y,typ]=SELF_SWITCH(job,arg1,arg2) + function diagram = genSwitchInnerDiagram(stateOpen) + diagram = scicos_diagram(); + // Input forward + diagram.objs(1) = IN_f("define"); + diagram.objs(1).graphics.pout = 5; + + // Output's forward + diagram.objs(2)=OUT_f("define"); + diagram.objs(2).graphics.pin = 7; + + diagram.objs(3)=CONST_m("define"); + diagram.objs(3).graphics.pout = 6; + diagram.objs(3).graphics.exprs = "0"; + diagram.objs(3).model.rpar = 0; + + diagram.objs(4)=SWITCH_f("define"); + diagram.objs(4).graphics.pin = [5 6] + diagram.objs(4).graphics.pout = 7 + if stateOpen == %t + diagram.objs(4).model.ipar = 1; + diagram.objs(4).graphics.exprs = ["2";"2"]; + else + diagram.objs(4).model.ipar = 0; + diagram.objs(4).graphics.exprs = ["2";"1"]; + end + + // IN_f <-> SWITCH_f + diagram.objs(5) = scicos_link(xx=[0, 0], yy=[0, 0], from=[1, 1], to=[4, 1]); + // CONST_m <-> SWITCH_f + diagram.objs(6) = scicos_link(xx=[0, 0], yy=[0, 0], from=[3, 1], to=[4, 2]); + // SWITCH_f <-> OUT_f + diagram.objs(7) = scicos_link(xx=[0, 0], yy=[0, 0], from=[4, 1], to=[2, 1]); + endfunction + select job + case "set" then + x = arg1; + stateOpen = x.model.opar(1); + x.model.rpar = genSwitchInnerDiagram(~stateOpen); + x.model.opar = list(~stateOpen); + y = 0; + typ=list(); + if stateOpen == %f + x.graphics.style="SELF_SWITCH_OFF" + else + x.graphics.style="SELF_SWITCH_ON" + end + + case "define" + // By default SWITCH is open + stateOpen = %t; + x = scicos_block() + x.gui="SELF_SWITCH" + x.graphics.sz=[2,2] + x.graphics.gr_i=[] + x.graphics.pin=0 + x.graphics.pout=0 + x.model.sim="csuper" + x.model.in = 1 + x.model.out = 1 + x.model.blocktype="h" + x.model.dep_ut=[%f %f] + x.model.rpar = genSwitchInnerDiagram(stateOpen); + x.model.opar = list(stateOpen); + x.graphics.in_implicit=["E"] + x.graphics.in_style="" + x.graphics.out_implicit=["E"]; + x.graphics.out_style="" + x.graphics.style="SELF_SWITCH_OFF" + end +endfunction diff --git a/macros/Branching/SWITCH2.sci b/macros/Branching/SWITCH2.sci new file mode 100644 index 00000000..11820367 --- /dev/null +++ b/macros/Branching/SWITCH2.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]=SWITCH2(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,rule,thra,nzz,exprs]=scicos_getvalue("Set parameters",.. + ["pass first input if: u2>=a (0), u2>a (1), u2~=a (2)";.. + "threshold a";"use zero crossing: yes (1), no (0)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + rule=int(rule); + if (rule<0) then + rule=0, + end + if (rule>2) then + rule=2, + end + graphics.exprs=exprs; + model.ipar=rule + model.rpar=thra + if nzz<>0 then + model.nmode=1 + model.nzcross=1 + else + model.nmode=0 + model.nzcross=0 + end + x.graphics=graphics; + x.model=model + break + end + case "define" then + in=[-1;1;-1] + ipar=[0] // rule + nzz=1 + rpar=0 + + model=scicos_model() + model.sim=list("switch2",4) + model.in=in + model.out=-1 + model.ipar=ipar + model.rpar=rpar + model.nzcross=nzz + model.nmode=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(ipar);string(rpar);string(nzz)] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/SWITCH2_m.sci b/macros/Branching/SWITCH2_m.sci new file mode 100644 index 00000000..c2682dff --- /dev/null +++ b/macros/Branching/SWITCH2_m.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]=SWITCH2_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,ot,rule,thra,nzz,exprs]=scicos_getvalue("Set parameters",.. + ["Datatype (1=real double 2=complex 3=int32 ...)";"pass first input if: u2>=a (0), u2>a (1), u2~=a (2)";.. + "threshold a";"use zero crossing: yes (1), no (0)"],.. + list("vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + rule=int(rule); + if (rule<0) then + rule=0, + end + if (rule>2) then + rule=2, + end + graphics.exprs=exprs; + model.ipar=rule + model.rpar=thra + if nzz<>0 then + model.nmode=1 + model.nzcross=1 + else + model.nmode=0 + model.nzcross=0 + end + if ((ot<1)|(ot>8))&(ot<>-1) then + message("Datatype is not supported"); + ok=%f; + end + if ok then + it(1)=ot; + it(2)=1; + it(3)=ot; + in=[model.in model.in2] + out=[model.out model.out2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + ipar=[0] // rule + nzz=1 + rpar=0 + + model=scicos_model() + model.sim=list("switch2_m",4) + model.in=[-1;1;-1] + model.in2=[-2;1;-2] + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.ipar=ipar + model.rpar=rpar + model.nzcross=nzz + model.nmode=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(1);string(ipar);string(rpar);string(nzz)] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Branching/SWITCH_f.sci b/macros/Branching/SWITCH_f.sci new file mode 100644 index 00000000..2ab52344 --- /dev/null +++ b/macros/Branching/SWITCH_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]=SWITCH_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + ipar=model.ipar + while %t do + [ok,nin,z0,exprs]=scicos_getvalue("Set switch parameters",.. + ["number of inputs";"connected input"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if z0>nin|z0<=0 then + message("initial connected input is not a valid input port number") + else + [model,graphics,ok]=check_io(model,graphics,-ones(nin,1),-1,[],[]) + if ok then + graphics.exprs=exprs; + model.ipar=z0-1 + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + i0=0 + in=[-1;-1] + nin=2 + model=scicos_model() + model.sim=list("switchn",2) + model.in=in + model.out=-1 + model.ipar=i0 + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %t] + + exprs=[string(nin);string(i0+1)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Electrical/CCS.sci b/macros/Electrical/CCS.sci new file mode 100644 index 00000000..31d60024 --- /dev/null +++ b/macros/Electrical/CCS.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]=CCS(job,arg1,arg2) + // the automatically generated interface block for Modelica CCS.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + case "define" then + ModelName="CCS" + PrametersValue=[] + ParametersName=[] + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[2,50,1,0; 70,98,2,0;70,2,-2,0] + + PortName=["Iin";"p";"n"] + + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs=[] + gr_i=[] + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2.1,3],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Electrical/CVS.sci b/macros/Electrical/CVS.sci new file mode 100644 index 00000000..a4c7a6bb --- /dev/null +++ b/macros/Electrical/CVS.sci @@ -0,0 +1,84 @@ +// 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]=CVS(job,arg1,arg2) + // the automatically generated interface block for Modelica CVS.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + case "define" then + ModelName="CVS" + PrametersValue=[] + ParametersName=[] + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[2,50,1,0; 70,98,2,0;70,2,-2,0] + + PortName=["vin";"p";"n"] + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs=[] + gr_i=[] + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2.1,3],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Electrical/Capacitor.sci b/macros/Electrical/Capacitor.sci new file mode 100644 index 00000000..3d6a9dc8 --- /dev/null +++ b/macros/Electrical/Capacitor.sci @@ -0,0 +1,71 @@ +// 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]=Capacitor(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,C,v,exprs]=scicos_getvalue("Set Capacitor block parameter",.. + ["C (F)";"Initial Voltage"],list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + model.rpar=C + model.equations.parameters(2)=list(C,v) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + C=0.01,v=0 + model.rpar=[C;v] + model.sim="Capacitor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="Capacitor" + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list(["C","v"],list(C,v),[0,1]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + + exprs=string([C;v]) + gr_i=[]; + x=standard_define([2 1.1],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/ConstantVoltage.sci b/macros/Electrical/ConstantVoltage.sci new file mode 100644 index 00000000..cff44efa --- /dev/null +++ b/macros/Electrical/ConstantVoltage.sci @@ -0,0 +1,69 @@ +// 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]=ConstantVoltage(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,V,exprs]=scicos_getvalue("Set ConstantVoltage block parameter",.. + "V (volt)",list("vec",1),exprs) + if ~ok then + break, + end + model.rpar=V + model.equations.parameters(2)=list(V) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + + case "define" then + V=0.01 + + model=scicos_model() + model.rpar=V + model.in=1;model.out=1; + model.sim="ConstantVoltage"; + model.blocktype="c" + model.dep_ut=[%f %f] + mo=modelica() + mo.model="ConstantVoltage"; + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list("V",list(V)) + model.equations=mo + exprs=string(V) + + gr_i=[] + + x=standard_define([1.5 1.1],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/CurrentSensor.sci b/macros/Electrical/CurrentSensor.sci new file mode 100644 index 00000000..84d42296 --- /dev/null +++ b/macros/Electrical/CurrentSensor.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]=CurrentSensor(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.in=1; + model.out=[1; 1]; + model.sim="CurrentSensor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="CurrentSensor" + mo.inputs="p"; + mo.outputs=["n";"i"] + model.equations=mo + exprs=[] + gr_i=[] + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I";"E"] + end +endfunction diff --git a/macros/Electrical/Diode.sci b/macros/Electrical/Diode.sci new file mode 100644 index 00000000..0ca08fd9 --- /dev/null +++ b/macros/Electrical/Diode.sci @@ -0,0 +1,74 @@ +// 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]=Diode(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,Ids,Vt,Maxexp,R,exprs]=scicos_getvalue("Set Diode block parameter",.. + ["Saturation cuurent (A)";.. + "Voltage equivalent to temperature (Volt)";.. + "Max exponent for linear continuation";.. + "R (ohm)"], list("vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + model.rpar=[Ids;Vt;Maxexp;R] + model.equations.parameters=list(["Ids","Vt","Maxexp","R"],list(Ids,Vt,Maxexp,R)) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + Ids=1.e-6; + Vt=0.04; + Maxexp=15; + R=1.e8; + model=scicos_model() + model.rpar=[Ids;Vt;Maxexp;R] + + model.in=1; + model.out=1; + model.sim="Diode"; + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="Diode"; + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list(["Ids","Vt","Maxexp","R"],list(Ids,Vt,Maxexp,R)) + + model.equations=mo + exprs=string([Ids;Vt;Maxexp;R]) + gr_i=[] + x=standard_define([2 1],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/Ground.sci b/macros/Electrical/Ground.sci new file mode 100644 index 00000000..73172434 --- /dev/null +++ b/macros/Electrical/Ground.sci @@ -0,0 +1,50 @@ +// 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(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.in=[1]; + model.out=[]; + model.sim="Ground" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="Ground" + mo.inputs="p"; + model.equations=mo + exprs="" + gr_i=[] + x=standard_define([1 1],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/Gyrator.sci b/macros/Electrical/Gyrator.sci new file mode 100644 index 00000000..8cec7e60 --- /dev/null +++ b/macros/Electrical/Gyrator.sci @@ -0,0 +1,93 @@ +// 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]=Gyrator(job,arg1,arg2) + // the automatically generated interface block for Modelica Gyrator.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + exprs=x.graphics.exprs + while %t do + [ok,G1,G2,exprs]=scicos_getvalue(["Set Gyrator block parameters:";"";"G1: Gyration conductance";"G2: Gyration conductance"],["G1";"G2"],list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + x.model.equations.parameters(2)=list(G1,G2) + x.graphics.exprs=exprs + break + end + case "define" then + ModelName="Gyrator" + PrametersValue=[1;1] + ParametersName=["G1";"G2"] + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[2.5,90,2,0;2.5,10,2,0;97.5,90,-2,0;97.5,10,-2,0] + PortName=["p1";"n1";"p2";"n2"] + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs=["1";"1"] + gr_i=[] + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2,2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Electrical/IdealTransformer.sci b/macros/Electrical/IdealTransformer.sci new file mode 100644 index 00000000..2eddd211 --- /dev/null +++ b/macros/Electrical/IdealTransformer.sci @@ -0,0 +1,94 @@ +// 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]=IdealTransformer(job,arg1,arg2) + // the automatically generated interface block for Modelica Transformer.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + exprs=x.graphics.exprs + while %t do + [ok,N,exprs]=scicos_getvalue(["Set Transformer block parameters:";"";"N:"+... + " Turn ratio (N1/N2)"],["N"],list("vec",1),exprs) + if ~ok then + break, + end + x.model.equations.parameters(2)=list(N) + x.graphics.exprs=exprs + break + end + case "define" then + ModelName="IdealTransformer" + PrametersValue=[1] + ParametersName=["N"] + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[2.5,90,2,0;2.5,10,2,0;97.5,90,-2,0;97.5,10,-2,0] + PortName=["p1";"n1";"p2";"n2"] + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs=["1"] + gr_i=[] + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2,2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Electrical/Inductor.sci b/macros/Electrical/Inductor.sci new file mode 100644 index 00000000..0bd2b7d2 --- /dev/null +++ b/macros/Electrical/Inductor.sci @@ -0,0 +1,69 @@ +// 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]=Inductor(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,L,exprs]=scicos_getvalue("Set Inductor block parameter",.. + "L (H)",list("vec",1),exprs) + if ~ok then + break, + end + model.rpar=L + model.equations.parameters(2)=list(L) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.in=[1]; + model.out=[1]; + L=1.d-5 + model.rpar=L + model.sim="Inductor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica(); + mo.model="Inductor" + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list("L",list(L)) + model.equations=mo; + exprs=string(L) + + gr_i=[] + + x=standard_define([2 0.9],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/MOTOR.sci b/macros/Electrical/MOTOR.sci new file mode 100644 index 00000000..55756401 --- /dev/null +++ b/macros/Electrical/MOTOR.sci @@ -0,0 +1,49 @@ +// 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]=MOTOR(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec deux entrees et une sortie de type implicit et de dimension 1 + // - avec des ports disposes en des positions non standard + + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.out=[1;1] + model.in=[1]; + model.sim="motor" + model.blocktype="c" + model.dep_ut=[%t %f] + gr_i=[]; + + + exprs="" + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.out_implicit=["I";"I"] + x.graphics.in_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/NMOS.sci b/macros/Electrical/NMOS.sci new file mode 100644 index 00000000..64a440e0 --- /dev/null +++ b/macros/Electrical/NMOS.sci @@ -0,0 +1,86 @@ +// 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]=NMOS(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,W,L,Beta,Vt,K2,K5,dW,dL,RDS,exprs]=scicos_getvalue("Set NMOS Transistor block parameters",.. + ["Width [m]";.. + "Length [m]";.. + "Transconductance parameter [A/(V*V)]";.. + "Zero bias threshold voltage [V]";.. + "Bulk threshold parameter";.. + "Reduction of pinch-off region";.. + "Narrowing of channel [m]";.. + "Shortening of channel [m]";.. + "Drain-Source-Resistance [Ohm]"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1),exprs) + + if ~ok then + break, + end + model.equations.parameters(2)=list(W,L,Beta,Vt,K2,K5,dW,dL,RDS) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + W=20.e-6; + L=6.e-6; + Beta=0.041e-3; + Vt=0.8; + K2=1.144; + K5= 0.7311; + dW=-2.5e-6; + dL= -1.5e-6; + RDS=1.e+7; + + model.sim="NMOS" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="NMOS"; + mo.outputs=["D";"B";"S"] + mo.inputs="G"; + mo.parameters=list(["W";"L";"Beta";"Vt";"K2";"K5";"dW";"dL";"RDS"],[W;L;Beta;Vt;K2;K5;dW;dL;RDS]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[string(W);string(L);string(Beta);string(Vt);string(K2);string(K5);string(dW);string(dL);string(RDS)] + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I";"I";"I"] + end +endfunction + + diff --git a/macros/Electrical/NPN.sci b/macros/Electrical/NPN.sci new file mode 100644 index 00000000..7be14930 --- /dev/null +++ b/macros/Electrical/NPN.sci @@ -0,0 +1,93 @@ +// 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]=NPN(job,arg1,arg2) + // the automatically generated interface block for Modelica NPN.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + exprs=x.graphics.exprs + while %t do + [ok,Bf,Br,Is,Vak,Tauf,Taur,Ccs,Cje,Cjc,Phie,Me,Phic,Mc,Gbc,Gbe,Vt,EMinMax,exprs]=scicos_getvalue(["Set NPN block parameters:";""],["Bf : Forward beta";"Br : Reverse beta";"Is : Transport saturation current";"Vak : Early voltage (inverse), 1/Volt";"Tauf: Ideal forward transit time";"Taur: Ideal reverse transit time";"Ccs : Collector-substrat(ground) cap.";"Cje : Base-emitter zero bias depletion cap.";"Cjc : Base-coll. zero bias depletion cap.";"Phie: Base-emitter diffusion voltage";"Me : Base-emitter gradation exponent";"Phic: Base-collector diffusion voltage";"Mc : Base-collector gradation exponent";"Gbc : Base-collector conductance";"Gbe : Base-emitter conductance";"Vt : Voltage equivalent of temperature";"EMinmax: if x > EMinMax, the exp(x) is linearized"],list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + x.model.equations.parameters(2)=list(Bf,Br,Is,Vak,Tauf,Taur,Ccs,Cje,Cjc,Phie,Me,Phic,Mc,Gbc,Gbe,Vt,EMinMax) + x.graphics.exprs=exprs + break + end + case "define" then + ModelName="NPN" + PrametersValue=[50;0.1;0;0.02;1.200D-10;5.000D-09;1.000D-12;4.000D-13;5.000D-13;0.8;0.4;0.8;0.333;1.000D-15;1.000D-15;0.02585;40] + ParametersName=["Bf";"Br";"Is";"Vak";"Tauf";"Taur";"Ccs";"Cje";"Cjc";"Phie";"Me";"Phic";"Mc";"Gbc";"Gbe";"Vt";"EMinMax"] + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[100,90,-2,0; 0,50,2,0; 100,10,-2,0] + PortName=["C";"B";"E"] + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs=["50";"0.1";"1.e-16";"0.02";"0.12e-9";"5e-9";"1e-12";"0.4e-12";"0.5e-12";"0.8";"0.4";"0.8";"0.333";"1e-15";"1e-15";"0.02585";"40"] + gr_i=[] + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2,2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Electrical/OpAmp.sci b/macros/Electrical/OpAmp.sci new file mode 100644 index 00000000..5f231669 --- /dev/null +++ b/macros/Electrical/OpAmp.sci @@ -0,0 +1,74 @@ +// 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]=OpAmp(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %f do + [ok,OLGain,SatH,SatL,exprs]=scicos_getvalue("Set the Operational Amplifier parameters",.. + ["Open Loop Gain";"Positive saturation voltage";"Negative saturation voltage"],.. + list("vec",1,"vec",1,"vec",1),exprs); + if ~ok then + break, + end + model.equations.parameters(2)=list(OLGain,SatH,SatL) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + // OLGain=1000; + // SatH=10; + // SatL=-10; + // S=['OLGain';'SatH';'SatL']; + // Z=eval(S); + S=[]; + Z=[]; + model=scicos_model(); + model.sim="OpAmp"; + model.blocktype="c"; + model.dep_ut=[%t %f]; + mo=modelica(); + mo.model=model.sim; + mo.inputs=["in_p";"in_n"]; + mo.outputs=["out"]; + mo.parameters=list(S,Z); + model.equations=mo; + model.in=ones(size(mo.inputs,"*"),1); + model.out=ones(size(mo.outputs,"*"),1); + model.rpar=Z; + exprs=string(Z); + gr_i=[] + x=standard_define([3 5],model,exprs,gr_i) + x.graphics.in_implicit=["I";"I"] + x.graphics.out_implicit=["I"] + end +endfunction +// OpAmp + diff --git a/macros/Electrical/PMOS.sci b/macros/Electrical/PMOS.sci new file mode 100644 index 00000000..9219fe13 --- /dev/null +++ b/macros/Electrical/PMOS.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]=PMOS(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,W,L,Beta,Vt,K2,K5,dW,dL,RDS,exprs]=scicos_getvalue("Set PMOS Transistor parameters",.. + ["Width [m]";.. + "Length [m]";.. + "Transconductance parameter [A/(V*V)]";.. + "Zero bias threshold voltage [V]";.. + "Bulk threshold parameter";.. + "Reduction of pinch-off region";.. + "Narrowing of channel [m]";.. + "Shortening of channel [m]";.. + "Drain-Source-Resistance [Ohm]"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1),exprs) + + if ~ok then + break, + end + model.equations.parameters(2)=list(W,L,Beta,Vt,K2,K5,dW,dL,RDS) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + W=50.0e-6; + L=6.0e-6; + Beta=0.0105e-3; + Vt=-1; + K2=0.41; + K5=0.839; + dW=-2.5e-6; + dL=-2.1e-6; + RDS=1.e+7; + model.sim="PMOS" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="PMOS"; + mo.outputs=["D";"B";"S"] + mo.inputs="G"; + mo.parameters=list(["W";"L";"Beta";"Vt";"K2";"K5";"dW";"dL";"RDS"],[W;L;Beta;Vt;K2;K5;dW;dL;RDS]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[string(W);string(L);string(Beta);string(Vt);string(K2);string(K5);string(dW);string(dL);string(RDS)] + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I";"I";"I"] + end +endfunction + + diff --git a/macros/Electrical/PNP.sci b/macros/Electrical/PNP.sci new file mode 100644 index 00000000..d52a335e --- /dev/null +++ b/macros/Electrical/PNP.sci @@ -0,0 +1,94 @@ +// 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]=PNP(job,arg1,arg2) + // the automatically generated interface block for Modelica PNP.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + exprs=x.graphics.exprs + while %t do + [ok,Bf,Br,Is,Vak,Tauf,Taur,Ccs,Cje,Cjc,Phie,Me,Phic,Mc,Gbc,Gbe,Vt,EMinMax,exprs]=scicos_getvalue(["Set PNP block parameters:";"";],["Bf : Forward beta";"Br : Reverse beta";"Is : Transport saturation current";"Vak : Early voltage (inverse), 1/Volt";"Tauf: Ideal forward transit time";"Taur: Ideal reverse transit time";"Ccs : Collector-substrat(ground) cap.";"Cje : Base-emitter zero bias depletion cap.";"Cjc : Base-coll. zero bias depletion cap.";"Phie: Base-emitter diffusion voltage";"Me : Base-emitter gradation exponent";"Phic: Base-collector diffusion voltage";"Mc : Base-collector gradation exponent";"Gbc : Base-collector conductance";"Gbe : Base-emitter conductance";"Vt : Voltage equivalent of temperature";"EMinMax: if x > EMinMax, the exp(x) function is linearized"],list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + x.model.equations.parameters(2)=list(Bf,Br,Is,Vak,Tauf,Taur,Ccs,Cje,Cjc,Phie,Me,Phic,Mc,Gbc,Gbe,Vt,EMinMax) + x.graphics.exprs=exprs + break + end + + case "define" then + ModelName="PNP" + PrametersValue=[50;0.1;0;0.02;1.200D-10;5.000D-09;1.000D-12;4.000D-13;5.000D-13;0.8;0.4;0.8;0.333;1.000D-15;1.000D-15;0.02585;40] + ParametersName=["Bf";"Br";"Is";"Vak";"Tauf";"Taur";"Ccs";"Cje";"Cjc";"Phie";"Me";"Phic";"Mc";"Gbc";"Gbe";"Vt";"EMinMax"] + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[100,90,-2,0;0,50,2,0;100,10,-2,0] + PortName=["C";"B";"E"] + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs=["50";"0.1";"1.e-16";"0.02";"0.12e-9";"5e-9";"1e-12";"0.4e-12";"0.5e-12";"0.8";"0.4";"0.8";"0.333";"1e-15";"1e-15";"0.02585";"40"] + gr_i=[] + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2,2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Electrical/PotentialSensor.sci b/macros/Electrical/PotentialSensor.sci new file mode 100644 index 00000000..619ac5ef --- /dev/null +++ b/macros/Electrical/PotentialSensor.sci @@ -0,0 +1,52 @@ +// 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]= PotentialSensor(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.in=[1]; + model.out=[1]; + model.rpar=[] + model.sim="PotentialSensor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="PotentialSensor" + mo.inputs="p"; + mo.outputs=["v"] + model.equations=mo + gr_i=[] + + x=standard_define([2 2],model,"",list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["E"] + end +endfunction diff --git a/macros/Electrical/Resistor.sci b/macros/Electrical/Resistor.sci new file mode 100644 index 00000000..8bb798b0 --- /dev/null +++ b/macros/Electrical/Resistor.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]=Resistor(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,R,exprs]=scicos_getvalue("Set Resistor block parameter",.. + "R (ohm)",list("vec",1),exprs) + if ~ok then + break, + end + model.rpar=R + model.equations.parameters(2)=list(R) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + R=0.01 + model.rpar=R + model.sim="resistor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="Resistor" + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list("R",list(R)) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=string(R) + gr_i=[] + x=standard_define([2 1],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/SineVoltage.sci b/macros/Electrical/SineVoltage.sci new file mode 100644 index 00000000..1baa222b --- /dev/null +++ b/macros/Electrical/SineVoltage.sci @@ -0,0 +1,79 @@ +// 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]= SineVoltage(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,V,ph,frq,offset,start,exprs]=scicos_getvalue("Set voltage source parameter",.. + ["Amplitude (Volt)";"phase (rad)";"Frequency (Hz)";"Voltageoffset (V)";"Timeoffset (s)"],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + model.rpar=[V;ph;frq;offset;start] + model.equations.parameters(2)=list(V,ph,frq,offset,start) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.in=[1]; + model.out=[1]; + V=1 + ph=0 + frq=1 + offset=0 + start=0 + model.rpar=[V;ph;frq;offset;start] + model.sim="SineVoltage" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="SineVoltage" + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list(["V";"phase";"freqHz";"offset";"startTime"],list(V,ph,frq,offset,start)) + model.equations=mo + + exprs=[string(V);string(ph);string(frq);string(offset);string(start)] + + gr_i=[] + + + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/Switch.sci b/macros/Electrical/Switch.sci new file mode 100644 index 00000000..eb248f3f --- /dev/null +++ b/macros/Electrical/Switch.sci @@ -0,0 +1,72 @@ +// 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]=Switch(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,Ron,Roff,exprs]=scicos_getvalue("Set non-ideal electrical switch parameters",.. + ["Resistance in On state (Ohm)";"Resistance in Off state (Ohm)"],list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + model.equations.parameters(2)=list(Ron,Roff) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + Ron=0.01; + Roff=1e5; + S=["Ron";"Roff"]; + Z=eval(S); + model.sim="Switch" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model=model.sim + mo.inputs=["p";"inp"]; + mo.outputs="n"; + mo.parameters=list(S,Z); + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + model.rpar=Z; + exprs=string(Z); + gr_i=[]; + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I";"E"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/VVsourceAC.sci b/macros/Electrical/VVsourceAC.sci new file mode 100644 index 00000000..9e951afa --- /dev/null +++ b/macros/Electrical/VVsourceAC.sci @@ -0,0 +1,74 @@ +// 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]=VVsourceAC(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,FR,exprs]=scicos_getvalue("Set voltage source parameter",.. + ["Frequency (Hz)"],.. + list("vec",-1),exprs) + if ~ok then + break, + end + model.rpar=[FR] + model.equations.parameters(2)=list(FR) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.in=[1;1]; + model.out=[1]; + VA=220 + FR=50 + model.rpar=[FR] + model.sim="VVsourceAC" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="VVsourceAC" + mo.inputs=["p","VA"]; + mo.outputs="n"; + mo.parameters=list(["f"],list(FR)) + model.equations=mo + + exprs=[string(FR)] + gr_i=[] + + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I","E"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/VariableResistor.sci b/macros/Electrical/VariableResistor.sci new file mode 100644 index 00000000..74848529 --- /dev/null +++ b/macros/Electrical/VariableResistor.sci @@ -0,0 +1,51 @@ +// 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]=VariableResistor(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim="VariableResistor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="VariableResistor" + mo.inputs=["p","R"]; + mo.outputs="n"; + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[] + gr_i=[] + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I","E"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Electrical/VoltageSensor.sci b/macros/Electrical/VoltageSensor.sci new file mode 100644 index 00000000..5e33531a --- /dev/null +++ b/macros/Electrical/VoltageSensor.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]=VoltageSensor(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.in=1; + model.out=[1; 1]; + model.sim="VoltageSensor" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="VoltageSensor" + mo.inputs="p"; + mo.outputs=["n";"v"] + model.equations=mo + exprs=[] + gr_i=[] + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I";"E"] + end +endfunction diff --git a/macros/Electrical/VsourceAC.sci b/macros/Electrical/VsourceAC.sci new file mode 100644 index 00000000..da087294 --- /dev/null +++ b/macros/Electrical/VsourceAC.sci @@ -0,0 +1,74 @@ +// 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]=VsourceAC(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,VA,FR,exprs]=scicos_getvalue("Set voltage source parameter",.. + ["Amplitude (Volt)";"Frequency (Hz)"],.. + list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + model.rpar=[VA;FR] + model.equations.parameters(2)=list(VA,FR) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.in=[1]; + model.out=[1]; + VA=220 + FR=50 + model.rpar=[VA;FR] + model.sim="VsourceAC" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="VsourceAC" + mo.inputs="p"; + mo.outputs="n"; + mo.parameters=list(["VA";"f"],list(VA,FR)) + model.equations=mo + + exprs=[string(VA);string(FR)] + gr_i=[] + + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Events/ANDBLK.sci b/macros/Events/ANDBLK.sci new file mode 100644 index 00000000..70bfcff7 --- /dev/null +++ b/macros/Events/ANDBLK.sci @@ -0,0 +1,109 @@ +// 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]=ANDBLK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + andlog=ANDLOG_f("define") + andlog.graphics.orig=[194,133] + andlog.graphics.sz=[60,60] + andlog.graphics.flip=%t + andlog.graphics.pout=9 + andlog.graphics.pein=[4;11] + + input_port1=CLKIN_f("define") + input_port1.graphics.orig=[149,287] + input_port1.graphics.sz=[20,20] + input_port1.graphics.flip=%t + input_port1.graphics.exprs="1" + input_port1.graphics.peout=4 + input_port1.model.ipar=1 + + output_port=CLKOUT_f("define") + output_port.graphics.orig=[450,83] + output_port.graphics.sz=[20,20] + output_port.graphics.flip=%t + output_port.graphics.exprs="1" + output_port.graphics.pein=8 + output_port.model.ipar=1 + + input_port2=CLKIN_f("define") + input_port2.graphics.orig=[141,330] + input_port2.graphics.sz=[20,20] + input_port2.graphics.flip=%t + input_port2.graphics.exprs="2" + input_port2.graphics.peout=6 + input_port2.model.ipar=2 + + ifthel=IFTHEL_f("define") + ifthel.graphics.orig=[331,137] + ifthel.graphics.sz=[60,60] + ifthel.graphics.flip=%t + ifthel.graphics.pin=9 + ifthel.graphics.pein=12 + ifthel.graphics.peout=[8;0] + + split=CLKSPLIT_f("define") + split.graphics.orig=[234;275.78348] + split.graphics.pein=6, + split.graphics.peout=[11;12] + + + diagram=scicos_diagram() + diagram.objs(1)=andlog + diagram.objs(2)=input_port1 + diagram.objs(3)=output_port + diagram.objs(4)=scicos_link(xx=[169;214;214],yy=[297;297;198.71],.. + ct=[5,-1],from=[2,1],to=[1,1]) + diagram.objs(5)=input_port2 + diagram.objs(6)=scicos_link(xx=[161;234;234],yy=[340;340;275.78],.. + ct=[5,-1],from=[5,1],to=[10,1]) + diagram.objs(7)=ifthel + diagram.objs(8)=scicos_link(xx=[351;351;450],yy=[131.29;93;93],.. + ct=[5,-1],from=[7,1],to=[3,1]) + diagram.objs(9)=scicos_link(xx=[262.57;322.43],yy=[163;167],.. + ct=[1,1],from=[1,1],to=[7,1]) + diagram.objs(10)=split + diagram.objs(11)=scicos_link(xx=[234;234],yy=[275.78;198.71],.. + ct=[5,-1],from=[10,1],to=[1,2]) + diagram.objs(12)=scicos_link(xx=[234;361;361],yy=[275.78;275.78;202.71],.. + ct=[5,-1],from=[10,2],to=[7,1]) + x=scicos_block() + x.gui="ANDBLK" + x.graphics.sz=[2,2] + x.graphics.gr_i=[]; + x.graphics.pein=[0;0] + x.graphics.peout=0 + x.model.sim="csuper" + x.model.evtin=[1;1] + 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/Events/ANDLOG_f.sci b/macros/Events/ANDLOG_f.sci new file mode 100644 index 00000000..01c9adb7 --- /dev/null +++ b/macros/Events/ANDLOG_f.sci @@ -0,0 +1,41 @@ +// 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]=ANDLOG_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim="andlog" + model.out=1 + model.evtin=[1;1] + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([3 3],model,[],gr_i) + end +endfunction diff --git a/macros/Events/CLKSOMV_f.sci b/macros/Events/CLKSOMV_f.sci new file mode 100644 index 00000000..aece0064 --- /dev/null +++ b/macros/Events/CLKSOMV_f.sci @@ -0,0 +1,43 @@ +// 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]=CLKSOMV_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + case "define" then + + model=scicos_model() + model.sim="sum" + model.evtin=[1;1;1] + model.evtout=1 + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Events/CLKSOM_f.sci b/macros/Events/CLKSOM_f.sci new file mode 100644 index 00000000..ff4470f9 --- /dev/null +++ b/macros/Events/CLKSOM_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]=CLKSOM_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim="sum" + model.evtin=[1;1;1] + model.evtout=1 + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([1 1]/1.2,model,[],gr_i) + end +endfunction diff --git a/macros/Events/CLKSPLIT_f.sci b/macros/Events/CLKSPLIT_f.sci new file mode 100644 index 00000000..518b7b37 --- /dev/null +++ b/macros/Events/CLKSPLIT_f.sci @@ -0,0 +1,81 @@ +// 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] = CLKSPLIT_f(job,arg1,arg2) + //** 22 Jun 2006: I found a problem here from scicos_new + //** 23 ... but it was not here :( + //** 26 June 2006: eliniating the /scicos_blocks/Events/<duplicate> ! + + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x=arg1; + + case "define" then + model=scicos_model() + model.sim="split" + model.evtin=1 + model.evtout=[1;1] + model.blocktype="d" + model.firing=[%f,%f,%f] //???? + model.dep_ut=[%f %f] + x = standard_define([1 1]/3,model,[],[]) + end //** ...select job + +endfunction +//**---------------------------------------------------------- + +//** 26 Jun 2006: The original source code +//function [x,y,typ]=CLKSPLIT_f(job,arg1,arg2) +//// Copyright INRIA +//x=[];y=[],typ=[]; +//select job +//case 'plot' then +//case 'getinputs' then +// orig=arg1.graphics.orig; +// x=orig(1) +// y=orig(2) +// typ=-ones(x) +//case 'getoutputs' then +// orig=arg1.graphics.orig; +// x=[1,1]*orig(1) +// y=[1,1]*orig(2) +// typ=-ones(x) +//case 'getorigin' then +// [x,y]=standard_origin(arg1) +//case 'set' then +// x=arg1; +//case 'define' then +// model=scicos_model() +// model.sim='split' +// model.evtin=1 +// model.evtout=[1;1] +// model.blocktype='d' +// model.firing=[%f,%f,%f] //???? +// model.dep_ut=[%f %f] +// +// x=standard_define([1 1]/3,model,[],[]) +//end +//endfunction diff --git a/macros/Events/END_c.sci b/macros/Events/END_c.sci new file mode 100644 index 00000000..f014d708 --- /dev/null +++ b/macros/Events/END_c.sci @@ -0,0 +1,60 @@ +// 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]=END_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,tf,exprs]=scicos_getvalue("Set final simulation time",.. + ["Final simulation time"],list("vec",1),exprs) + if ~ok then + break, + end + if ok then + graphics.exprs=exprs + model.firing=tf + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + tf=100000000 + model=scicos_model() + model.sim=list("scicosexit",4) + model.evtin=1 + model.evtout=1 + model.firing=tf + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(tf) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/EVTDLY_c.sci b/macros/Events/EVTDLY_c.sci new file mode 100644 index 00000000..e4a0e02c --- /dev/null +++ b/macros/Events/EVTDLY_c.sci @@ -0,0 +1,74 @@ +// 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]=EVTDLY_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,dt,ff,exprs]=scicos_getvalue(["Set Event Delay block parameters"; + "Delay is the delay between an input event "; + " and the generated output event"; + "Block may initially generate an output event before "; + " any input event. ""Date of initial output event"""; + " gives the date of this event. Set a negative value"; + " to disable any output event."],.. + ["Delay";"Date of initial output event"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if dt<=0 then + message("Delay must be positive") + ok=%f + end + if ok then + graphics.exprs=exprs + model.rpar=[dt;ff] + model.firing=ff + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + dt=0.1 + ff=0.0 + model=scicos_model() + model.sim=list("evtdly4",4) + model.evtin=1 + model.evtout=1 + model.rpar=[dt;ff] + model.blocktype="d" + model.firing=ff + model.dep_ut=[%f %f] + + exprs=[string(dt);sci2exp(ff)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/EVTDLY_f.sci b/macros/Events/EVTDLY_f.sci new file mode 100644 index 00000000..4a2f243e --- /dev/null +++ b/macros/Events/EVTDLY_f.sci @@ -0,0 +1,74 @@ +// 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]=EVTDLY_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,dt,ff,exprs]=scicos_getvalue(["Set Event Delay block parameters"; + "Delay is the delay between an input event "; + " and the generated output event"; + "Block may initially generate an output event before "; + " any input event. ""Date of initial output event"""; + " gives the date of this event. Set a negative value"; + " if no initial event required"],.. + ["Delay";"Date of initial output event"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if dt<=0 then + message("Delay must be positive") + ok=%f + end + if ok then + graphics.exprs=exprs + model.rpar=dt + model.firing=ff + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + dt=0.1 + ff=dt + model=scicos_model() + model.sim="evtdly" + model.evtin=1 + model.evtout=1 + model.rpar=dt + model.blocktype="d" + model.firing=ff + model.dep_ut=[%f %f] + + exprs=[string(dt);sci2exp(ff)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/EVTGEN_f.sci b/macros/Events/EVTGEN_f.sci new file mode 100644 index 00000000..b76ccc68 --- /dev/null +++ b/macros/Events/EVTGEN_f.sci @@ -0,0 +1,59 @@ +// 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]=EVTGEN_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,tt,exprs]=scicos_getvalue("Set Event time",.. + ["Event Time"],list("vec",1),exprs) + if ~ok then + break, + end + graphics.exprs=exprs + if model.firing<>tt then + model.firing=tt + end + x.graphics=graphics; + x.model=model + break + end + case "define" then + tt=0 + model=scicos_model() + model.sim="trash" + model.evtout=1 + model.blocktype="d" + model.firing=tt + model.dep_ut=[%f %f] + + exprs=string(tt) + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/EVTVARDLY.sci b/macros/Events/EVTVARDLY.sci new file mode 100644 index 00000000..ff438de7 --- /dev/null +++ b/macros/Events/EVTVARDLY.sci @@ -0,0 +1,59 @@ +// 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]=EVTVARDLY(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,fir,exprs]=scicos_getvalue("Set parameter of variable event delay",.. + "Initial event firing time (<0 if absent)",.. + list("vec",1),exprs) + if ~ok then + break, + end + graphics.exprs=exprs + model.firing=fir + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.sim=list("evtvardly",4) + model.in=1 + model.evtin=1 + model.evtout=1 + model.blocktype="d" + model.firing=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + exprs=string(model.firing) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/HALT_f.sci b/macros/Events/HALT_f.sci new file mode 100644 index 00000000..f6f5881f --- /dev/null +++ b/macros/Events/HALT_f.sci @@ -0,0 +1,60 @@ +// 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]=HALT_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,n,exprs]=scicos_getvalue("Set Halt block parameters",.. + ["State on halt"],list("vec",1),exprs) + if ~ok then + break, + end + if ok then + graphics.exprs=exprs + model.ipar=n + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + n=0 + model=scicos_model() + model.sim="hltblk" + model.evtin=1 + model.dstate=0 + model.ipar=0 + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(n) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/IFTHEL_f.sci b/macros/Events/IFTHEL_f.sci new file mode 100644 index 00000000..2261a5f0 --- /dev/null +++ b/macros/Events/IFTHEL_f.sci @@ -0,0 +1,82 @@ +// 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]=IFTHEL_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if exprs==[] then + exprs=string(1); + end + if size(exprs,"*")==1 then + exprs(2)=string(1); + end + while %t do + [ok,inh,nmod,exprs]=scicos_getvalue("Set parameters",.. + ["Inherit (1: no, 0: yes)";"zero-crossing (0: no, 1: yes)"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + model.dep_ut=[%t %f]; //compatibility + if nmod<>0 then + nmod=1, + end + if inh<>1 then + inh=[]; + end + [model,graphics,ok]=check_io(model,graphics,1,[],inh,[1;1]) + if ok then + graphics.exprs=exprs; + model.evtin=inh; + model.sim(2)=-1 + model.nmode=nmod + model.nzcross=nmod + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + model=scicos_model() + model.sim=list("ifthel",-1) + model.in=1 + model.in2=1 + model.intyp=-1 + model.evtin=1 + model.evtout=[1;1] + model.blocktype="l" + model.firing=[-1 -1] + model.dep_ut=[%t %f] + model.nmode=1 + model.nzcross=1 + + gr_i=[] + exprs=[string(model.in);string(model.nmode)]; + x=standard_define([3 3],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/MCLOCK_f.sci b/macros/Events/MCLOCK_f.sci new file mode 100644 index 00000000..2dd62f6f --- /dev/null +++ b/macros/Events/MCLOCK_f.sci @@ -0,0 +1,141 @@ +// 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]=MCLOCK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the clock block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "MFCLCK_f" then + path = i; + break; + end + end + + newpar=list(); + spath=list("model","rpar","objs",path) + xx=arg1(spath)// get the block + execstr("xxn="+xx.gui+"(''set'',xx)") + if or(xxn<>xx) then + // parameter or states changed + arg1(spath)=xxn// Update + newpar(size(newpar)+1)=path// Notify modification + end + x=arg1 + y=0 + typ=newpar + case "define" then + nn=2 + dt=0.1 + exprs=[string(dt);string(nn)] + + mfclck=MFCLCK_f("define") + mfclck.graphics.orig=[334,199] + mfclck.graphics.sz=[40,40] + mfclck.graphics.flip=%t + mfclck.graphics.exprs=exprs + mfclck.graphics.pein=12 + mfclck.graphics.peout=[4;3] + mfclck.model.rpar=0.1 + mfclck.model.ipar=nn + mfclck.model.firing=[-1 0] + + clksom=CLKSOM_f("define") + clksom.graphics.orig=[457,161] + clksom.graphics.sz=[16.666667,16.666667] + clksom.graphics.flip=%t + clksom.graphics.exprs=["0.1";"0.1"] + clksom.graphics.pein=[4;9;0] + clksom.graphics.peout=5 + + output_port1=CLKOUT_f("define") + output_port1.graphics.orig=[509,261] + output_port1.graphics.sz=[20,20] + output_port1.graphics.flip=%t + output_port1.graphics.exprs="1" + output_port1.graphics.pein=10 + output_port1.model.ipar=1 + + output_port2=CLKOUT_f("define") + output_port2.graphics.orig=[509,142] + output_port2.graphics.sz=[20,20] + output_port2.graphics.flip=%t + output_port2.graphics.exprs="2" + output_port2.graphics.pein=13 + output_port2.model.ipar=2 + + + split1=CLKSPLIT_f("define") + split1.graphics.orig=[411.92504;169.33333] + split1.graphics.pein=3, + split1.graphics.peout=[9;10] + + split2=CLKSPLIT_f("define") + split2.graphics.orig=[482.45315;169.33333] + split2.graphics.pein=5 + split2.graphics.peout=[12;13] + + gr_i=[] + + diagram=scicos_diagram(); + diagram.objs(1)=mfclck + diagram.objs(2)=clksom + diagram.objs(3)=scicos_link(xx=[360.7;360.7;411.9],.. + yy=[193.3;169.3;169.3],.. + ct=[10,-1],from=[1,2],to=[8,1]) + diagram.objs(4)=scicos_link(xx=[347.3;347.3;461.8;461.8],.. + yy=[193.3;155.5;155.5;161],.. + ct=[10,-1],from=[1,1],to=[2,1]) + diagram.objs(5)=scicos_link(xx=[468.9;482.5],yy=[169.3;169.3],.. + ct=[10,-1],from=[2,1],to=[11,1]) + + diagram.objs(6)=output_port1 + diagram.objs(7)=output_port2 + diagram.objs(8)=split1 + + diagram.objs(9)=scicos_link(xx=[411.9;457],.. + yy=[169.3;169.3],.. + ct=[10,-1],from=[8,1],to=[2,2]) + diagram.objs(10)=scicos_link(xx=[411.9;411.9;509],yy=[169.3;271;271],.. + ct=[10,-1],from=[8,2],to=[6,1]) + + diagram.objs(11)=split2 + + diagram.objs(12)=scicos_link(xx=[482.5;489.6;489.6;354;354],.. + yy=[169.3;169.3;338.3;338.3;244.7],.. + ct=[10,-1],from=[11,1],to=[1,1]) + diagram.objs(13)=scicos_link(xx=[482.4;482.4;509],yy=[169.3;152;152],.. + ct=[10,-1],from=[11,2],to=[7,1]) + x=scicos_block() + x.gui="MCLOCK_f" + x.graphics.sz=[3,2] + x.graphics.gr_i=gr_i + x.model.sim="csuper" + x.model.evtout=[1;1] + x.model.blocktype="h" + x.model.rpar=diagram + x.graphics.peout=[0;0] + end +endfunction diff --git a/macros/Events/MFCLCK_f.sci b/macros/Events/MFCLCK_f.sci new file mode 100644 index 00000000..db49bc22 --- /dev/null +++ b/macros/Events/MFCLCK_f.sci @@ -0,0 +1,62 @@ +// 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]=MFCLCK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + [ok,dt,nn,exprs]=scicos_getvalue("Set Multifrequency clock parameters",.. + ["basic period (1/f)";"multiply by (n)"],list("vec",1,"vec",1),exprs) + if ok then + model.ipar=nn + model.rpar=dt; + hh=model.firing; + hh(2)=0; + model.firing=hh //compatibility + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + end + case "define" then + nn=2 + dt=0.1 + model=scicos_model() + model.sim="mfclck" + model.evtin=1 + model.evtout=[1;1] + model.dstate=0 + model.rpar=dt + model.ipar=nn + model.blocktype="d" + model.firing=[-1 0] + model.dep_ut=[%f %f] + + exprs=[string(dt);string(nn)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Events/M_freq.sci b/macros/Events/M_freq.sci new file mode 100644 index 00000000..59c4699e --- /dev/null +++ b/macros/Events/M_freq.sci @@ -0,0 +1,110 @@ +// 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]=M_freq(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 + offset=offset(:); + frequ=frequ(:); + if (size(frequ,"*"))<>(size(offset,"*")) then + message("offset and frequency must have the same size"); + ok=%f; + elseif or(frequ<0) then + message("Frequency must be a positif number"); + ok=%f; + elseif or(abs(offset) > frequ) then + message("The |Offset| must be less than the Frequency"); + ok=%f + end + if ok then + [m,den,off,count,m1,fir,frequ,offset,ok]=mfrequ_clk(frequ,offset); + end + if ok then + model.opar=list(m,double(den),off,count) + mn=(2**size(m1,"*"))-1; + [model,graphics,ok]=set_io(model,graphics,list(),list(),1,ones(mn,1)) + if mn>3 then + graphics.sz=[40+(mn-3)*10 40] + else + graphics.sz=[50 40] + end + model.firing=fir; + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + case "define" then + model=scicos_model() + model.sim=list("m_frequ",4) + model.evtout=[1;1;1] + model.evtin=1 + model.rpar=[] + model.opar=list([1 1 0;1 1 1;1 3 2],1,0,0); + model.blocktype="d" + model.firing=[0 -1 -1] + model.dep_ut=[%f %f] + exprs=[sci2exp([1;2]);sci2exp([0;0])] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction + +function [m,k]=uni(fr,of) + k=[]; + m=[]; + ot=[]; + for i=1:size(fr,"*") + istreated=%f; + ind=find(m==fr(i)); + if ind==[] then + m=[m;fr(i)]; + ot=[ot;of(i)]; + k=[k;i]; + else + for j=ind + if of(i)==ot(j) then + istreated=%t + end + end + if ~istreated then + m=[m;fr(i)]; + ot=[ot;of(i)] + k=[k;i]; + end + end + end +endfunction diff --git a/macros/Events/VirtualCLK0.sci b/macros/Events/VirtualCLK0.sci new file mode 100644 index 00000000..b17f1e98 --- /dev/null +++ b/macros/Events/VirtualCLK0.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]=VirtualCLK0(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim="vrtclk0" + model.evtin=1 + model.opar=list() + model.ipar=[] + model.blocktype="d" + model.firing=-1 + model.dep_ut=[%f %f] + + exprs=[] + x=standard_define([2 2],model,exprs," ") + end +endfunction diff --git a/macros/Events/freq_div.sci b/macros/Events/freq_div.sci new file mode 100644 index 00000000..4fae5ea5 --- /dev/null +++ b/macros/Events/freq_div.sci @@ -0,0 +1,287 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=freq_div(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the modulo block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "Modulo_Count" then + path = i; + break; + end + end + + // paths to updatable parameters or states + newpar=list(); + y=0; + spath=list() + spath($+1)="model" + spath($+1)="rpar" + spath($+1)="objs" + spath($+1)=path + + xx=arg1(spath)// get the block + //execstr('xxn='+xx.gui+'(''set'',xx)') + xxn=xx; + graphics=xx.graphics; + exprs=graphics.exprs + model=xx.model; + while %t do + [ok,%ph,%df,exprs]=scicos_getvalue.. + ("Set frequency division block parameters",.. + ["Phase (0 to division factor -1)";"Division factor"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if ok then + if %df<1 then + %df=1, + end + %ph=abs(%ph) + if %ph>%df-1 then + %ph=%df-1, + end + graphics.exprs=exprs + model.ipar=%df; + model.dstate=%ph; + xxn.graphics=graphics; + xxn.model=model + break + end + end + + + if diffobjs(xxn,xx) then + model=xx.model + model_n=xxn.model + if ~is_modelica_block(xx) then + modified=or(model.sim<>model_n.sim)|.. + ~isequal(model.state,model_n.state)|.. + ~isequal(model.dstate,model_n.dstate)|.. + ~isequal(model.rpar,model_n.rpar)|.. + ~isequal(model.ipar,model_n.ipar)|.. + ~isequal(model.label,model_n.label) + if or(model.in<>model_n.in)|or(model.out<>model_n.out) then + needcompile=1 + end + if or(model.firing<>model_n.firing) then + needcompile=2 + end + if model.sim=="input"|model.sim=="output" then + if model.ipar<>model_n.ipar then + needcompile=4 + end + end + if or(model.blocktype<>model_n.blocktype)|.. + or(model.dep_ut<>model_n.dep_ut) then + needcompile=4 + end + if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then + needcompile=4 + end + if prod(size(model_n.sim))>1 then + if model_n.sim(2)>1000 then + if model.sim(1)<>model_n.sim(1) then + needcompile=4 + end + end + end + else + modified=or(model_n<>model) + eq=model.equations;eqn=model_n.equations; + if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|.. + or(eq.outputs<>eqn.outputs) then + needcompile=4 + end + end + // parameter or states changed + arg1(spath)=xxn// Update + newpar(size(newpar)+1)=1// Notify modification + y=max(y,needcompile) + end + x=arg1 + typ=newpar + case "define" then + scs_m_1=scicos_diagram(); + scs_m_1.objs(1) = Modulo_Count("define"); + scs_m_1.objs(2) = CLKINV_f("define"); + scs_m_1.objs(3) = CLKOUTV_f("define"); + scs_m_1.objs(4) = IFTHEL_f("define"); + scs_m_1.objs(5) = CLKSPLIT_f("define"); + scs_m_1.objs(6) = scicos_link(); + scs_m_1.objs(7) = scicos_link(); + scs_m_1.objs(8) = scicos_link(); + scs_m_1.objs(9) = scicos_link(); + scs_m_1.objs(10) = scicos_link(); + + // Modulo_Count + blk = scs_m_1.objs(1); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [0 -100]; + graphics.sz = [60 40]; + + graphics.exprs = ["0";"3"]; + model.dstate = 3; + model.ipar = 3; + + graphics.pout = 7; + graphics.pein = 10; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(1) = blk; + + // CLKINV_f + blk = scs_m_1.objs(2); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [120 0]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.peout = 6; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(2) = blk; + + // CLKOUTV_f + blk = scs_m_1.objs(3); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [130 -160]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pein = 8; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(3) = blk; + + // IFTHEL_f + blk = scs_m_1.objs(4); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [100 -100]; + graphics.sz = [60 40]; + + graphics.exprs = ["1";"0"]; + model.ipar = 1; + + graphics.pin = 7; + graphics.pein = 9; + graphics.peout = [0;8]; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(4) = blk; + + // CLKSPLIT_f + blk = scs_m_1.objs(5); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [127 -33]; + graphics.sz = [7 7]; + + graphics.pein = 6; + graphics.peout = [9;10]; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(5) = blk; + + // CLKINV_f -> CLKSPLIT_f + lnk = scs_m_1.objs(6); + + lnk.ct = [5 -1]; + lnk.from = [2 1 0]; + lnk.to = [5 1 1]; + + scs_m_1.objs(6) = lnk; + + // Modulo_Count -> IFTHEL_f + lnk = scs_m_1.objs(7); + + lnk.from = [1 1 0]; + lnk.to = [4 1 1]; + + scs_m_1.objs(7) = lnk; + + // IFTHEL_f -> CLKOUTV_f + lnk = scs_m_1.objs(8); + + lnk.ct = [5 -1]; + lnk.from = [4 2 0]; + lnk.to = [3 1 1]; + + scs_m_1.objs(8) = lnk; + + // CLKSPLIT_f -> IFTHEL_f + lnk = scs_m_1.objs(9); + + lnk.ct = [5 -1]; + lnk.from = [5 1 0]; + lnk.to = [4 1 1]; + + scs_m_1.objs(9) = lnk; + + // CLKSPLIT_f -> Modulo_Count + lnk = scs_m_1.objs(10); + + lnk.xx = [0 30 1]; + lnk.yy = [0 -30 1]; + + lnk.ct = [5 -1]; + lnk.from = [5 2 0]; + lnk.to = [1 1 1]; + + scs_m_1.objs(10) = lnk; + + clear blk lnk + + model=scicos_model(); + model.sim = "csuper"; + model.evtin = 1; + model.evtout = 1; + model.rpar = scs_m_1; + + gr_i=[]; + x=standard_define([3 2],model,[],gr_i) + end +endfunction + diff --git a/macros/Hydraulics/Bache.sci b/macros/Hydraulics/Bache.sci new file mode 100644 index 00000000..1252a1ae --- /dev/null +++ b/macros/Hydraulics/Bache.sci @@ -0,0 +1,96 @@ +// 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]=Bache(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,Patm,A,ze1,ze2,zs1,zs2,z0,T0,p_rho,exprs]=scicos_getvalue("Parametres de la bache", .. + ["Pression dans le ciel de la bache : Patm (Pa)";.. + "Section de la bache : A (m2)";.. + "Altitude du piquage d entrée 1: ze1 (m)";.. + "Altitude du piquage d entrée 2: ze2 (m)";.. + "Altitude du piquage de sortie 1: zs1 (m)";.. + "Altitude du piquage de sortie 2: zs2 (m)";.. + "Altitude initiale du fluide : z0 (m)";.. + "Température initiale du fluide : T0 (K)";.. + "Si >0, masse volumique imposée du fluide : p_rho (kg/m3)"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1),exprs) + + + if ~ok then + break, + end + model.rpar=[Patm;A;ze1;ze2;zs1;zs2;z0;T0;p_rho] + model.equations.parameters(2)=list(Patm,A,ze1,ze2,zs1,zs2,z0,T0,p_rho) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + in=2 + out=3 + model=scicos_model() + model.in=[-(1:in)']; + model.out=[-(1:out)']; + Patm=1.013E5 + A=1 + ze1=40 + ze2=0 + zs1=40 + zs2=0 + z0=30 + T0=290 + p_rho=0 + model.rpar=[Patm;A;ze1;ze2;zs1;zs2;z0;T0;p_rho] + model.sim="Bache" + model.blocktype="c" + model.dep_ut=[%t %f] + + mo=modelica() + mo.model="Bache" + mo.inputs=["Ce1" "Ce2"]; + mo.outputs=["Cs1" "Cs2" "yNiveau"]; + mo.parameters=list(["Patm";"A";"ze1";"ze2";"zs1";"zs2";"z0";"T0";"p_rho"],[Patm;A;ze1;ze2;zs1;zs2;z0;T0;p_rho]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[string(Patm);string(A);string(ze1);string(ze2);string(zs1);string(zs2);string(z0);string(T0);string(p_rho)] + gr_i=[]; + //'xfpolys(orig(1)+[0;5;7;3;5;10;10;0;0]*sz(1)/10,orig(2)+[4;2;7;7;2;0;4;0;4]*sz(2)/10,scs_color(15))' + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I";"I"] + x.graphics.out_implicit=["I";"I";"E"] + end +endfunction diff --git a/macros/Hydraulics/Flowmeter.sci b/macros/Hydraulics/Flowmeter.sci new file mode 100644 index 00000000..01eb412c --- /dev/null +++ b/macros/Hydraulics/Flowmeter.sci @@ -0,0 +1,93 @@ +// 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]=Flowmeter(job,arg1,arg2) + // Copyright INRIA + // the automatically generated interface block for Modelica CapteurD.mo model + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x=arg1 + exprs=x.graphics.exprs + while %f do + [ok,Qini,exprs]=scicos_getvalue(["Set Flowmeter block parameters:";"";"Qini: "],"Qini",list("vec",1),exprs) + if ~ok then + break, + end + x.model.equations.parameters(2)=list(Qini) + x.graphics.exprs=exprs + break + end + case "define" then + ModelName="Flowmeter" + PrametersValue=1 + ParametersName="Qini" + model=scicos_model() + Typein=[]; + Typeout=[]; + MI=[]; + MO=[] + P=[50,105,-1,90;0,10,2,0;101,10,-2,0] + PortName=["Mesure";"C1";"C2"] + for i=1:size(P,"r") + if P(i,3)==1 then + Typein= [Typein; "E"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==2 then + Typein= [Typein; "I"]; + MI=[MI;PortName(i)]; + end + if P(i,3)==-1 then + Typeout=[Typeout;"E"]; + MO=[MO;PortName(i)]; + end + if P(i,3)==-2 then + Typeout=[Typeout;"I"]; + MO=[MO;PortName(i)]; + end + end + model=scicos_model() + mo=modelica() + model.sim=ModelName; + mo.inputs=MI; + mo.outputs=MO; + model.rpar=PrametersValue; + mo.parameters=list(ParametersName,PrametersValue,zeros(ParametersName)); + exprs="1" + gr_i=[]; + model.blocktype="c" + model.dep_ut=[%f %t] + mo.model=ModelName + model.equations=mo + model.in=ones(size(MI,"*"),1) + model.out=ones(size(MO,"*"),1) + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=Typein; + x.graphics.out_implicit=Typeout; + end +endfunction diff --git a/macros/Hydraulics/PerteDP.sci b/macros/Hydraulics/PerteDP.sci new file mode 100644 index 00000000..d5125fe9 --- /dev/null +++ b/macros/Hydraulics/PerteDP.sci @@ -0,0 +1,84 @@ +// 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]=PerteDP(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,L,D,lambda,z1,z2,p_rho,exprs]=scicos_getvalue("Parametres du tuyau", .. + ["Longueur du tube : L (m)";.. + "Diamètre interne du tube : D (m)";.. + "Coefficient de perte de charge-frottement(S.U) : lambda";.. + "Altitude entrée tuyauterie : z1 (m)";.. + "Altitude sortie tuyauterie : z2 (m)";.. + "Si >0, masse volumique imposée fu fluide : p_rho (kg/m3)"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + model.rpar=[L;D;lambda;z1;z2;p_rho] + model.equations.parameters(2)=list(L,D,lambda,z1,z2,p_rho) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.in=[1]; + model.out=[1]; + L=10 + D=0.2 + lambda=0.03 + z1=0 + z2=0 + p_rho=0 + model.rpar=[L;D;lambda;z1;z2;p_rho] + model.sim="PerteDP" + model.blocktype="c" + model.dep_ut=[%t %f] + mo=modelica() + mo.model="PerteDP" + mo.inputs="C1"; + mo.outputs="C2"; + mo.parameters=list(["L";"D";"lambda";"z1";"z2";"p_rho"],[L;D;lambda;z1;z2;p_rho]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[string(L);string(D);string(lambda);string(z1);string(z2);string(p_rho)] + gr_i=[]; + x=standard_define([2 1],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Hydraulics/PuitsP.sci b/macros/Hydraulics/PuitsP.sci new file mode 100644 index 00000000..a72a7a5c --- /dev/null +++ b/macros/Hydraulics/PuitsP.sci @@ -0,0 +1,79 @@ +// 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]=PuitsP(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,P0,T0,H0,option_temperature,exprs]=scicos_getvalue("Paramètres du puits", .. + ["Pression de la source : P0 (Pa)";.. + "Temperature de la source : T0 (K)";.. + "Enthalpie spécifique de la source : H0 (J/kg)";.. + "1:température fixée - 2:enthalpie fixée : option_temperature"], .. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + model.rpar=[P0;T0;H0;option_temperature] + model.equations.parameters(2)=list(P0,T0,H0,option_temperature) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + P0=100000 + T0=290 + H0=100000 + option_temperature=1 + model.rpar=[P0;T0;H0;option_temperature] + model.sim="Puits" + model.blocktype="c" + model.dep_ut=[%t %f] + + mo=modelica() + mo.model="Puits" + mo.inputs=["C"]; + mo.parameters=list(["P0";"T0";"H0";"option_temperature"],[P0;T0;H0;option_temperature]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + //model.out=ones(size(mo.outputs,'*'),1) + exprs=[string(P0);string(T0);string(H0);string(option_temperature)] + gr_i=[]; + x=standard_define([2.5 2],model,exprs,list(gr_i,0)) + // x.graphics.in_implicit=['E';'E';'E';'I'] + x.graphics.in_implicit=["I"] + //x.graphics.out_implicit=[0] + end +endfunction diff --git a/macros/Hydraulics/SourceP.sci b/macros/Hydraulics/SourceP.sci new file mode 100644 index 00000000..5ba7694c --- /dev/null +++ b/macros/Hydraulics/SourceP.sci @@ -0,0 +1,79 @@ +// 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]=SourceP(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,P0,T0,H0,option_temperature,exprs]=scicos_getvalue("Paramètres du puits",.. + ["Pression de la source : P0 (Pa)";.. + "Temperature de la source : T0 (K)";.. + "Enthalpie spécifique de la source : H0 (J/kg)";.. + "1:température fixée - 2:enthalpie fixée : option_temperature"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + model.rpar=[P0;T0;H0;option_temperature] + model.equations.parameters(2)=list(P0,T0,H0,option_temperature) + // model.equations.parameters=list([P0;T0;H0;option_temperature]) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + P0=300000 + T0=290 + H0=100000 + option_temperature=1 + model.rpar=[P0;T0;H0;option_temperature] + model.sim="Source" + model.blocktype="c" + model.dep_ut=[%t %f] + + mo=modelica() + mo.model="Source" + mo.inputs=[]; + mo.outputs=["C"]; + mo.parameters=list(["P0";"T0";"H0";"option_temperature"],[P0;T0;H0;option_temperature]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[string(P0);string(T0);string(H0);string(option_temperature)] + gr_i=[]; + x=standard_define([2.5 2],model,exprs,list(gr_i,0)) + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/Hydraulics/VanneReglante.sci b/macros/Hydraulics/VanneReglante.sci new file mode 100644 index 00000000..b5fba365 --- /dev/null +++ b/macros/Hydraulics/VanneReglante.sci @@ -0,0 +1,77 @@ +// 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]=VanneReglante(job,arg1,arg2) + // exemple d'un bloc implicit, + // - sans entree ni sortie de conditionnement + // - avec une entree et une sortie de type implicit et de dimension 1 + // - avec un dialogue de saisie de parametre + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,Cvmax,p_rho,exprs]=scicos_getvalue("Paramètres de la vanne reglante",.. + ["Cvmax";"p_rho"],.. + list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + model.rpar=[Cvmax;p_rho] + model.equations.parameters(2)=list(Cvmax,p_rho) + // model.equations.parameters=list([Cvmax;p_rho]) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + model=scicos_model() + model.in=[1;1]; + model.out=[1]; + Cvmax=8005.42 + p_rho=0 + model.rpar=[Cvmax;p_rho] + model.sim="VanneReglante" + model.blocktype="c" + model.dep_ut=[%t %f] + + mo=modelica() + mo.model="VanneReglante" + mo.inputs=["C1" "Ouv"]; + mo.outputs="C2"; + mo.parameters=list(["Cvmax";"p_rho"],[Cvmax;p_rho]) + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + exprs=[string(Cvmax);string(p_rho)] + gr_i=[]; + x=standard_define([2 2],model,exprs,list(gr_i,0)) + x.graphics.in_implicit=["I";"E"] + x.graphics.out_implicit=["I"] + end +endfunction diff --git a/macros/IntegerOp/BITCLEAR.sci b/macros/IntegerOp/BITCLEAR.sci new file mode 100644 index 00000000..07462283 --- /dev/null +++ b/macros/IntegerOp/BITCLEAR.sci @@ -0,0 +1,120 @@ +// 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]=BITCLEAR(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,Datatype,bit,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "BITCLEAR"); " "; gettext("Clear a bit");" "],.. + [msprintf(gettext("Data Type %s"), "(3:int32, 4:int16, 5:int8, ...)"); gettext("Index of Bit (0 is least significant)")],.. + list("vec",1,"vec",1), exprs); + + if ~ok then + break, + end + in=[model.in model.in2]; + + if floor(bit) <> bit then + block_parameter_error(msprintf(gettext("Wrong type for ''%s'' parameter: %5.1f."), gettext("Index of Bit"), bit), .. + gettext("Must be integer.") .. + ); + ok=%f; + elseif (Datatype == 3) | (Datatype == 6) then + if bit > 31 | bit < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Index of Bit"), bit), .. + msprintf(gettext("Must be in the interval %s."), "[0, 31]")); + ok=%f; + else + bit=uint32(bit) + n=(2^32-1)-2^bit; + n=uint32(n) + model.sim=list("bit_clear_32",4) + end + elseif (Datatype == 4)|(Datatype == 7) then + if bit > 15 | bit < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Index of Bit"), bit), .. + msprintf(gettext("Must be in the interval %s."), "[0, 15]")); + ok=%f; + else + bit=uint16(bit) + n=(2^16-1)-2^bit; + n=uint16(n) + model.sim=list("bit_clear_16",4) + end + elseif (Datatype == 5)|(Datatype == 8) then + if bit > 7 | bit < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Index of Bit"), bit), .. + msprintf(gettext("Must be in the interval %s."), "[0, 7]")); + ok=%f; + else + bit=uint8(bit) + n=(2^8-1)-2^bit; + n=uint8(n) + model.sim=list("bit_clear_8",4) + end + else + block_parameter_error(msprintf(gettext( "Wrong value for ''%s'' parameter: %d."), gettext("Data Type"), Datatype),.. + msprintf(gettext( "Must be in the interval %s."), "[3, 8]")); + ok=%f; + end + if ok then + it=Datatype + ot=Datatype + out=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + graphics.exprs=exprs; + model.opar=list(n) + x.graphics=graphics; + x.model=model; + break + end + end + + case "define" then + model=scicos_model() + model.sim=list("bit_clear_32",4) + model.in=1 + model.in2=1 + model.out=1 + model.out2=1; + model.intyp=3 + model.outtyp=3 + model.opar=list(int32(0)) + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(3);sci2exp(0)] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + + end +endfunction diff --git a/macros/IntegerOp/BITSET.sci b/macros/IntegerOp/BITSET.sci new file mode 100644 index 00000000..58805c2b --- /dev/null +++ b/macros/IntegerOp/BITSET.sci @@ -0,0 +1,116 @@ +// 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]=BITSET(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,Datatype,bit,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "BITSET");" "; gettext("Set a bit");" "],.. + [msprintf(gettext("Data Type %s"), "(3:int32, 4:int16, 5:int8, ...)"); gettext("Index of Bit (0 is least significant)")],.. + list("vec",1,"vec",1), exprs); + + if ~ok then + break, + end + in=[model.in model.in2]; + + if floor(bit) <> bit then + block_parameter_error(msprintf(gettext("Wrong type for ''%s'' parameter: %5.1f."), gettext("Index of Bit"), bit), .. + gettext("Must be integer.")); + ok=%f; + end + if (Datatype == 3)|(Datatype == 6) then + if bit > 31 | bit < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Index of Bit"), bit), .. + msprintf(gettext("Must be in the interval %s."), "[0, 31]")); + ok=%f; + end + bit=uint32(bit) + n=2^bit; + n=uint32(n) + model.sim=list("bit_set_32",4) + elseif (Datatype==4)|(Datatype==7) then + if bit > 15 | bit < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Index of Bit"), bit), .. + msprintf(gettext("Must be in the interval %s."), "[0, 15]")); + ok=%f; + end + bit=uint16(bit) + n=2^bit; + n=uint16(n) + model.sim=list("bit_set_16",4) + elseif (Datatype==5)|(Datatype==8) then + + if bit > 7 | bit < 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Index of Bit"), bit), .. + msprintf(gettext("Must be in the interval %s."), "[0, 7]")); + ok=%f; + end + bit=uint8(bit) + n=2^bit; + n=uint8(n) + model.sim=list("bit_set_8",4) + else + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Data Type"), Datatype), .. + msprintf(gettext("Must be in the interval %s."), "[3, 8]")); + ok=%f; + end + if ok then + it=Datatype + ot=Datatype + out=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + graphics.exprs=exprs; + model.opar=list(n); + x.graphics=graphics; + x.model=model; + break + end + end + + case "define" then + model=scicos_model() + model.sim=list("bit_set_32",4) + model.in=1 + model.in2=1 + model.out=1 + model.out2=1; + model.intyp=3 + model.outtyp=3 + model.opar=list(uint32(0)) + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(3);sci2exp(0)] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + + end +endfunction diff --git a/macros/IntegerOp/CONVERT.sci b/macros/IntegerOp/CONVERT.sci new file mode 100644 index 00000000..e183b492 --- /dev/null +++ b/macros/IntegerOp/CONVERT.sci @@ -0,0 +1,403 @@ +// 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]=CONVERT(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,it,ot,np,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "CONVERT");" "; gettext("Type conversion");" "], .. + [gettext("Input Type (1:double, 3:int32, 4:int16, 5:int8, ...)"); gettext("Output Type (1:double, 3:int32, 4:int16, 5:int8, ...)"); .. + gettext("Do on Overflow (0:Nothing, 1:Saturate, 2:Error)")], .. + list("vec",1,"vec",1,"vec",1), exprs); + if ~ok then + break, + end + + if it==2 then + it =1; + end + if ot==2 then + ot=1; + end + + if (np ~= 0 & np ~= 1 & np ~= 2) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Do on Overflow"), np), .. + msprintf(gettext("Must be in the interval %s."), "[0, 2]")); + ok=%f; + elseif (it > 8 | it < 1) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Input Type"), it), .. + msprintf(gettext("Must be in the interval %s."), "[1, 8]")); + ok=%f; + elseif (ot > 8 | ot < 1) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Output Type"), ot), .. + msprintf(gettext("Must be in the interval %s."), "[1, 8]")); + ok=%f; + end + + model.sim=list("convert",4) + if (it==ot) then + model.ipar=1; + else + if (np==0) then + if (it==1) then + if (ot==3) then + model.ipar=2; + elseif (ot==4) then + model.ipar=3; + elseif (ot==5) then + model.ipar=4; + elseif (ot==6) then + model.ipar=5; + elseif (ot==7) then + model.ipar=6; + elseif (ot==8) then + model.ipar=7; + end + elseif (it==3) then + if (ot==1) then + model.ipar=8; + elseif (ot==4) then + model.ipar=9; + elseif (ot==5) then + model.ipar=10; + elseif (ot==6) then + model.ipar=1; + elseif (ot==7) then + model.ipar=11; + elseif (ot==8) then + model.ipar=12; + end + elseif (it==4) then + if (ot==1) then + model.ipar=13; + elseif (ot==3) then + model.ipar=14; + elseif (ot==5) then + model.ipar=15; + elseif (ot==6) then + model.ipar=16; + elseif (ot==7) then + model.ipar=1; + elseif (ot==8) then + model.ipar=17; + end + elseif (it==5) then + if (ot==1) then + model.ipar=18; + elseif (ot==3) then + model.ipar=19; + elseif (ot==4) then + model.ipar=20; + elseif (ot==6) then + model.ipar=21; + elseif (ot==7) then + model.ipar=22; + elseif (ot==8) then + model.ipar=1; + end + elseif (it==6) then + if (ot==1) then + model.ipar=23; + elseif (ot==3) then + model.ipar=1; + elseif (ot==4) then + model.ipar=24; + elseif (ot==5) then + model.ipar=25; + elseif (ot==7) then + model.ipar=26; + elseif (ot==8) then + model.ipar=27; + end + elseif (it==7) then + if (ot==1) then + model.ipar=28; + elseif (ot==3) then + model.ipar=29; + elseif (ot==4) then + model.ipar=1; + elseif (ot==5) then + model.ipar=30; + elseif (ot==6) then + model.ipar=31; + elseif (ot==8) then + model.ipar=32; + end + elseif (it==8) then + if (ot==1) then + model.ipar=33; + elseif (ot==3) then + model.ipar=34; + elseif (ot==4) then + model.ipar=35; + elseif (ot==5) then + model.ipar=1; + elseif (ot==6) then + model.ipar=36; + elseif (ot==7) then + model.ipar=37; + end + end + elseif (np==1) then + if (it==1) then + if (ot==3) then + model.ipar=38; + elseif (ot==4) then + model.ipar=39; + elseif (ot==5) then + model.ipar=40; + elseif (ot==6) then + model.ipar=41; + elseif (ot==7) then + model.ipar=42; + elseif (ot==8) then + model.ipar=43; + end + elseif (it==3) then + if (ot==1) then + model.ipar=8; + elseif (ot==4) then + model.ipar=44; + elseif (ot==5) then + model.ipar=45; + elseif (ot==6) then + model.ipar=46; + elseif (ot==7) then + model.ipar=47; + elseif (ot==8) then + model.ipar=48; + end + elseif (it==4) then + if (ot==1) then + model.ipar=13; + elseif (ot==3) then + model.ipar=14; + elseif (ot==5) then + model.ipar=49; + elseif (ot==6) then + model.ipar=50; + elseif (ot==7) then + model.ipar=51; + elseif (ot==8) then + model.ipar=52; + end + elseif (it==5) then + if (ot==1) then + model.ipar=18; + elseif (ot==3) then + model.ipar=19; + elseif (ot==4) then + model.ipar=20; + elseif (ot==6) then + model.ipar=53; + elseif (ot==7) then + model.ipar=54; + elseif (ot==8) then + model.ipar=55; + end + elseif (it==6) then + if (ot==1) then + model.ipar=23; + elseif (ot==3) then + model.ipar=56; + elseif (ot==4) then + model.ipar=57; + elseif (ot==5) then + model.ipar=58; + elseif (ot==7) then + model.ipar=59; + elseif (ot==8) then + model.ipar=60; + end + elseif (it==7) then + if (ot==1) then + model.ipar=28; + elseif (ot==3) then + model.ipar=29; + elseif (ot==4) then + model.ipar=61; + elseif (ot==5) then + model.ipar=62; + elseif (ot==6) then + model.ipar=31; + elseif (ot==8) then + model.ipar=63; + end + elseif (it==8) then + if (ot==1) then + model.ipar=33; + elseif (ot==3) then + model.ipar=34; + elseif (ot==4) then + model.ipar=35; + elseif (ot==5) then + model.ipar=64; + elseif (ot==6) then + model.ipar=36; + elseif (ot==7) then + model.ipar=37; + end + end + elseif (np==2) then + if (it==1) then + if (ot==3) then + model.ipar=65; + elseif (ot==4) then + model.ipar=66; + elseif (ot==5) then + model.ipar=67; + elseif (ot==6) then + model.ipar=68; + elseif (ot==7) then + model.ipar=69; + elseif (ot==8) then + model.ipar=70; + end + elseif (it==3) then + if (ot==1) then + model.ipar=8; + elseif (ot==4) then + model.ipar=71; + elseif (ot==5) then + model.ipar=72; + elseif (ot==6) then + model.ipar=73; + elseif (ot==7) then + model.ipar=74; + elseif (ot==8) then + model.ipar=75; + end + elseif (it==4) then + if (ot==1) then + model.ipar=13; + elseif (ot==3) then + model.ipar=14; + elseif (ot==5) then + model.ipar=76; + elseif (ot==6) then + model.ipar=77; + elseif (ot==7) then + model.ipar=78; + elseif (ot==8) then + model.ipar=79; + end + elseif (it==5) then + if (ot==1) then + model.ipar=18; + elseif (ot==3) then + model.ipar=19; + elseif (ot==4) then + model.ipar=20; + elseif (ot==6) then + model.ipar=80; + elseif (ot==7) then + model.ipar=81; + elseif (ot==8) then + model.ipar=82; + end + elseif (it==6) then + if (ot==1) then + model.ipar=23; + elseif (ot==3) then + model.ipar=83; + elseif (ot==4) then + model.ipar=84; + elseif (ot==5) then + model.ipar=85; + elseif (ot==7) then + model.ipar=86; + elseif (ot==8) then + model.ipar=87; + end + elseif (it==7) then + if (ot==1) then + model.ipar=28; + elseif (ot==3) then + model.ipar=29; + elseif (ot==4) then + model.ipar=88; + elseif (ot==5) then + model.ipar=89; + elseif (ot==6) then + model.ipar=31; + elseif (ot==8) then + model.ipar=90; + end + elseif (it==8) then + if (ot==1) then + model.ipar=33; + elseif (ot==3) then + model.ipar=34; + elseif (ot==4) then + model.ipar=35; + elseif (ot==5) then + model.ipar=91; + elseif (ot==6) then + model.ipar=36; + elseif (ot==7) then + model.ipar=37; + end + end + end + end + in=[model.in model.in2] + out=[model.out model.out2] + if ok then + [model,graphics,ok]=set_io(model,graphics,... + list(in,it),... + list(out,ot),[],[]) + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + + sgn=2 + model=scicos_model() + model.sim=list("convert",4) + model.in=-1 + model.out=-1 + model.in2=-2 + model.out2=-2 + model.intyp=1 + model.outtyp=3 + model.rpar=[] + model.ipar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=[sci2exp(1);sci2exp(3);sci2exp(0)] + gr_i=[] + x=standard_define([3 2],model, exprs,gr_i) + end +endfunction diff --git a/macros/IntegerOp/DFLIPFLOP.sci b/macros/IntegerOp/DFLIPFLOP.sci new file mode 100644 index 00000000..fb62b34c --- /dev/null +++ b/macros/IntegerOp/DFLIPFLOP.sci @@ -0,0 +1,1758 @@ +// 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]=DFLIPFLOP(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + scs_m=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["DFLIPFLOP"],.. + tol=[0.0001,0.000001,1.000E-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.objs(1)=scicos_block(.. + gui="CONST_m",.. + graphics=scicos_graphics(.. + orig=[109.62561,263.44465],.. + sz=[20;20],.. + flip=%t,.. + theta=0,.. + exprs="int8(0)",.. + 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=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(int8(0)),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(2)=scicos_block(.. + gui="IFTHEL_f",.. + graphics=scicos_graphics(.. + orig=[239.98293,378.2166],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=["1";"1"],.. + pin=29,.. + pout=[],.. + pein=22,.. + peout=[16;44],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("ifthel",-1),.. + in=1,.. + in2=1,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=[1;1],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="l",.. + firing=[-1,-1],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=1,.. + nmode=1,.. + equations=list()),.. + doc=list()) + scs_m.objs(3)=scicos_block(.. + gui="LOGICAL_OP",.. + graphics=scicos_graphics(.. + orig=[152.88902,260.24498],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["2";"1";"5";"0"],.. + pin=[11;39],.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("logicalop_i8",4),.. + in=[-1;-1],.. + in2=[-2;-2],.. + intyp=[5;5],.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[1;0],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(4)=scicos_block(.. + gui="SAMPHOLD_m",.. + graphics=scicos_graphics(.. + orig=[233.72156,260.24498],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="5",.. + pin=5,.. + pout=33,.. + pein=42,.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("samphold4_m",4),.. + in=-1,.. + in2=-2,.. + intyp=5,.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=1,.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(5)=scicos_link(.. + xx=[221.46044;225.15013],.. + yy=[280.24498;280.24498],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[4,1,1]) + scs_m.objs(6)=scicos_link(.. + xx=[138.19704;140.34523],.. + yy=[273.44465;273.49157],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[38,1,1]) + scs_m.objs(7)=scicos_block(.. + gui="LOGICAL_OP",.. + graphics=scicos_graphics(.. + orig=[373.24106,309.46812],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["1";"5";"5";"0"],.. + pin=36,.. + pout=13,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("logicalop_i8",4),.. + in=-1,.. + in2=-2,.. + intyp=5,.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[5;0],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(8)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[199.48466,398.2166],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="3",.. + pin=[],.. + pout=9,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=3,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(9)=scicos_link(.. + xx=[219.48466;222.54128],.. + yy=[408.2166;408.2166],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[8,1,0],.. + to=[28,1,1]) + scs_m.objs(10)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[104.31759,276.91165],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=11,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + 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.objs(11)=scicos_link(.. + xx=[124.31759;144.31759],.. + yy=[286.91165;286.91165],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[10,1,0],.. + to=[3,1,1]) + scs_m.objs(12)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[457.40928,320.20131],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=13,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(13)=scicos_link(.. + xx=[441.81249;457.40928],.. + yy=[329.46812;330.20131],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[7,1,0],.. + to=[12,1,1]) + scs_m.objs(14)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[376.4669,270.83282],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=37,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + 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=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title="Untitled",.. + tol=[0.0001,0.000001,1.000E-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="ANDLOG_f",.. + graphics=scicos_graphics(.. + orig=[194,133],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=9,.. + pein=[4;11],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="andlog",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=[],.. + outtyp=1,.. + evtin=[1;1],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_block(.. + gui="CLKIN_f",.. + graphics=scicos_graphics(.. + orig=[149,287],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=[],.. + pein=[],.. + peout=4,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="d",.. + firing=-1,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(3)=scicos_block(.. + gui="CLKOUT_f",.. + graphics=scicos_graphics(.. + orig=[450,83],.. + sz=[20,20],.. + 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(4)=scicos_link(.. + xx=[169;214;214],.. + yy=[297;297;198.71],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1],.. + to=[1,1]) + scs_m_1.objs(5)=scicos_block(.. + gui="CLKIN_f",.. + graphics=scicos_graphics(.. + orig=[141,330],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=[],.. + pout=[],.. + pein=[],.. + peout=6,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="d",.. + firing=-1,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(6)=scicos_link(.. + xx=[161;234;234],.. + yy=[340;340;275.78],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[5,1],.. + to=[10,1]) + scs_m_1.objs(7)=scicos_block(.. + gui="IFTHEL_f",.. + graphics=scicos_graphics(.. + orig=[331,137],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=["1";"1"],.. + pin=9,.. + pout=[],.. + pein=12,.. + peout=[8;0],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("ifthel",-1),.. + in=1,.. + in2=1,.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=[1;1],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="l",.. + firing=[-1,-1],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=1,.. + nmode=1,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(8)=scicos_link(.. + xx=[351;351;450],.. + yy=[131.29;93;93],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[7,1],.. + to=[3,1]) + scs_m_1.objs(9)=scicos_link(.. + xx=[262.57;322.43],.. + yy=[163;167],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1],.. + to=[7,1]) + scs_m_1.objs(10)=scicos_block(.. + gui="CLKSPLIT_f",.. + graphics=scicos_graphics(.. + orig=[234;275.78348],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=[],.. + pein=6,.. + peout=[11;12],.. + 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(11)=scicos_link(.. + xx=[234;234],.. + yy=[275.78;198.71],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[10,1],.. + to=[1,2]) + scs_m_1.objs(12)=scicos_link(.. + xx=[234;361;361],.. + yy=[275.78;275.78;202.71],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[10,2],.. + to=[7,1]) + scs_m.objs(15)=scicos_block(.. + gui="ANDBLK",.. + graphics=scicos_graphics(.. + orig=[233.73039,318.74407],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=[],.. + pein=[19;16],.. + peout=17,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="csuper",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[1;1],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=scs_m_1,.. + ipar=[],.. + opar=list(),.. + blocktype="h",.. + firing=%f,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(16)=scicos_link(.. + xx=[259.98293;260.39705],.. + yy=[372.50232;364.45835],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1,0],.. + to=[15,2,1]) + scs_m.objs(17)=scicos_link(.. + xx=[253.73039;253.72572],.. + yy=[313.02978;309.29537],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[15,1,0],.. + to=[41,1,1]) + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["EDGE_TRIGGER","./"],.. + tol=[0.0001;0.000001;1.000E-10;100001;0;0;0],.. + tf=30,.. + 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="EDGETRIGGER",.. + graphics=scicos_graphics(.. + orig=[288.58631,257.1131],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=5,.. + pout=3,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("edgetrig",4),.. + in=1,.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=0,.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=1,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_block(.. + gui="IFTHEL_f",.. + graphics=scicos_graphics(.. + orig=[388.28869,247.1131],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=["0";"0"],.. + pin=3,.. + pout=[],.. + pein=[],.. + peout=[7;0],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("ifthel",-1),.. + in=1,.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=1,.. + outtyp=[],.. + 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(3)=scicos_link(.. + xx=[357.15774;362.99107;379.71726],.. + yy=[277.1131;277.1131;277.1131],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[2,1,1]) + scs_m_1.objs(4)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[240.01488,267.1131],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=-1,.. + out=-1,.. + 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(5)=scicos_link(.. + xx=[260.01488;280.01488],.. + yy=[277.1131;277.1131],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[1,1,1]) + scs_m_1.objs(6)=scicos_block(.. + gui="CLKOUTV_f",.. + graphics=scicos_graphics(.. + orig=[398.28869,181.39881],.. + sz=[20,30],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=[],.. + pein=7,.. + 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(7)=scicos_link(.. + xx=[408.28869;408.28869],.. + yy=[241.39881;211.39881],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1,0],.. + to=[6,1,1]) + scs_m.objs(18)=scicos_block(.. + gui="EDGE_TRIGGER",.. + graphics=scicos_graphics(.. + orig=[133.90637,385.342],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=26,.. + pout=[],.. + pein=[],.. + peout=19,.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="csuper",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[],.. + 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()),.. + doc=list()) + scs_m.objs(19)=scicos_link(.. + xx=[163.90637;163.90637;247.06372],.. + yy=[379.62771;364.45835;364.45835],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[18,1,0],.. + to=[15,1,1]) + scs_m.objs(20)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[79.594811,395.47647],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=[],.. + pout=23,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["Extract_Activation","./"],.. + tol=[0.0001;0.000001;1.000E-10;100001;0;0;0],.. + tf=30,.. + 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="IFTHEL_f",.. + graphics=scicos_graphics(.. + orig=[150.65045,143.82208],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=["0";"0"],.. + pin=6,.. + pout=[],.. + pein=[],.. + peout=[3;4],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("ifthel",-1),.. + in=1,.. + in2=[],.. + 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(2)=scicos_block(.. + gui="CLKSOMV_f",.. + graphics=scicos_graphics(.. + orig=[169.82143,96.146231],.. + sz=[16.666667,16.666667],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=[],.. + pein=[3;4;0],.. + peout=8,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim="sum",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[1;1;1],.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=-1,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(3)=scicos_link(.. + xx=[170.65045;170.65045;150.04302;150.04302;169.82143],.. + yy=[138.10779;128.235;128.235;104.47956;104.47956],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[1,1,0],.. + to=[2,1,1]) + scs_m_1.objs(4)=scicos_link(.. + xx=[190.65045;190.65045;178.15476],.. + yy=[138.10779;111.55729;112.8129],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[1,2,0],.. + to=[2,2,1]) + scs_m_1.objs(5)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[102.07902,163.82208],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=6,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=-1,.. + out=-1,.. + 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=[122.07902;142.07902],.. + yy=[173.82208;173.82208],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[5,1,0],.. + to=[1,1,1]) + scs_m_1.objs(7)=scicos_block(.. + gui="CLKOUTV_f",.. + graphics=scicos_graphics(.. + orig=[168.15476,38.527183],.. + 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=[178.15476;178.15476],.. + yy=[98.527183;68.527183],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1,0],.. + to=[7,1,1]) + scs_m.objs(21)=scicos_block(.. + gui="Extract_Activation",.. + graphics=scicos_graphics(.. + orig=[239.82193,456.57677],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=31,.. + pout=[],.. + pein=[],.. + peout=22,.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="csuper",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[],.. + 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()),.. + doc=list()) + scs_m.objs(22)=scicos_link(.. + xx=[269.82193;269.98293],.. + yy=[450.86248;443.93089],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[21,1,0],.. + to=[2,1,1]) + scs_m.objs(23)=scicos_link(.. + xx=[99.594811;110.25582],.. + yy=[405.47647;405.42077],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[20,1,0],.. + to=[25,1,1]) + scs_m.objs(24)=scicos_block(.. + gui="SUM_f",.. + graphics=scicos_graphics(.. + orig=[200.5252,469.13173],.. + sz=[16.666667,16.666667],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[27;0;30],.. + pout=31,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("plusblk",2),.. + in=[-1;-1;-1],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(25)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[110.25582;405.42077],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=23,.. + pout=[26;27],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(26)=scicos_link(.. + xx=[110.25582;114.33667;125.33494],.. + yy=[405.42077;405.39945;405.342],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[25,1,0],.. + to=[18,1,1]) + scs_m.objs(27)=scicos_link(.. + xx=[110.25582;110.25582;208.85853],.. + yy=[405.42077;469.13173;469.13173],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[25,2,0],.. + to=[24,1,1]) + scs_m.objs(28)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[222.54128;408.2166],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=9,.. + pout=[29;30],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(29)=scicos_link(.. + xx=[222.54128;231.4115],.. + yy=[408.2166;408.2166],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[28,1,0],.. + to=[2,1,1]) + scs_m.objs(30)=scicos_link(.. + xx=[222.54128;222.54128;208.85853;208.85853],.. + yy=[408.2166;453.0015;453.0015;485.7984],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[28,2,0],.. + to=[24,3,1]) + scs_m.objs(31)=scicos_link(.. + xx=[219.57282;231.2505],.. + yy=[477.46506;476.57677],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[24,1,0],.. + to=[21,1,1]) + scs_m.objs(32)=scicos_block(.. + gui="SELECT_m",.. + graphics=scicos_graphics(.. + orig=[298.86371,253.57321],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["5";"2";"1"],.. + pin=[33;40],.. + pout=34,.. + pein=[43;44],.. + 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=[5;5],.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + 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.objs(33)=scicos_link(.. + xx=[282.29299;290.29229],.. + yy=[280.24498;280.23987],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[32,1,1]) + scs_m.objs(34)=scicos_link(.. + xx=[347.43514;357.57328;357.57328],.. + yy=[273.57321;273.57321;280.83282],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[32,1,0],.. + to=[35,1,1]) + scs_m.objs(35)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[357.57328,280.83282],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=34,.. + pout=[36;37],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(36)=scicos_link(.. + xx=[357.57328;357.57328;364.66964],.. + yy=[280.83282;329.46812;329.46812],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[35,1,0],.. + to=[7,1,1]) + scs_m.objs(37)=scicos_link(.. + xx=[357.57328;376.4669],.. + yy=[280.83282;280.83282],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[35,2,0],.. + to=[14,1,1]) + scs_m.objs(38)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[140.34523;273.49157],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=6,.. + pout=[39;40],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(39)=scicos_link(.. + xx=[140.34523;144.31759],.. + yy=[273.49157;273.57832],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[38,1,0],.. + to=[3,2,1]) + scs_m.objs(40)=scicos_link(.. + xx=[140.34523;140.34523;290.29229;290.29229],.. + yy=[273.49157;247.70767;247.70767;266.90654],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[38,2,0],.. + to=[32,2,1]) + scs_m.objs(41)=scicos_block(.. + gui="CLKSPLIT_f",.. + graphics=scicos_graphics(.. + orig=[253.72572;309.29537],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=[],.. + pout=[],.. + pein=17,.. + peout=[42;43],.. + 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.objs(42)=scicos_link(.. + xx=[253.72572;253.72156],.. + yy=[309.29537;305.95927],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[41,1,0],.. + to=[4,1,1]) + scs_m.objs(43)=scicos_link(.. + xx=[253.72572;312.19705;312.19705],.. + yy=[309.29537;309.29537;299.28749],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[41,2,0],.. + to=[32,1,1]) + scs_m.objs(44)=scicos_link(.. + xx=[279.98293;279.98293;325.53038;325.53038],.. + yy=[372.50232;315.89455;315.89455;299.28749],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,2,0],.. + to=[32,2,1]) + model=scicos_model() + model.sim="csuper" + model.in=[1;1;1] + model.in2=[1;1;1] + model.out=[1;1] + model.out2=[1;1] + model.intyp=[5 1 1] + model.outtyp=[5 5] + model.blocktype="h" + model.firing=%f + model.dep_ut=[%t %f] + model.rpar=scs_m + gr_i=[] + x=standard_define([2 3],model,[],gr_i) + end +endfunction diff --git a/macros/IntegerOp/DLATCH.sci b/macros/IntegerOp/DLATCH.sci new file mode 100644 index 00000000..f0a0fb4e --- /dev/null +++ b/macros/IntegerOp/DLATCH.sci @@ -0,0 +1,534 @@ +// 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]=DLATCH(job,arg1,arg2) + x=[];y=[],typ=[] + select job + case "set" then + x=arg1 + case "define" then + scs_m=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["DLATCH"],.. + tol=[0.0001,0.000001,1.000E-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.objs(1)=scicos_block(.. + gui="CONST_m",.. + graphics=scicos_graphics(.. + orig=[109.62561,263.44465],.. + sz=[20;20],.. + flip=%t,.. + theta=0,.. + exprs="int8(0)",.. + pin=[],.. + pout=7,.. + 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=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(int8(0)),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(2)=scicos_block(.. + gui="IFTHEL_f",.. + graphics=scicos_graphics(.. + orig=[233.37693,320.30536],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=["0";"1"],.. + pin=13,.. + pout=[],.. + pein=[],.. + peout=[6;0],.. + gr_i=list(.. + ["txt=[''If in>0'';'' '';'' then else''];"; + "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"],8),.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("ifthel",-1),.. + 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=1,.. + nmode=1,.. + equations=list()),.. + doc=list()) + scs_m.objs(3)=scicos_block(.. + gui="LOGICAL_OP",.. + graphics=scicos_graphics(.. + orig=[152.88902,260.24498],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["2";"1";"5";"0"],.. + pin=[15;7],.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=list(.. + "xstringb(orig(1),orig(2),[''Logical Op '';OPER],sz(1),sz(2),''fill'');",8),.. + id="",.. + in_implicit=["E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("logicalop_i8",4),.. + in=[-1;-1],.. + in2=[-2;-2],.. + intyp=[5;5],.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[1;0],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(4)=scicos_block(.. + gui="SAMPHOLD_m",.. + graphics=scicos_graphics(.. + orig=[233.72156,260.24498],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="5",.. + pin=5,.. + pout=9,.. + pein=6,.. + peout=[],.. + gr_i=list("xstringb(orig(1),orig(2),''S/H'',sz(1),sz(2),''fill'')",8),.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("samphold4_m",4),.. + in=-1,.. + in2=-2,.. + intyp=5,.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=1,.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(5)=scicos_link(.. + xx=[221.46044;225.15013],.. + yy=[280.24498;280.24498],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[4,1,1]) + scs_m.objs(6)=scicos_link(.. + xx=[253.37693;253.72156],.. + yy=[314.59108;305.95927],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1,0],.. + to=[4,1,1]) + scs_m.objs(7)=scicos_link(.. + xx=[138.19704;144.31759],.. + yy=[273.44465;273.57832],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[3,2,1]) + scs_m.objs(8)=scicos_block(.. + gui="LOGICAL_OP",.. + graphics=scicos_graphics(.. + orig=[317.46698,309.46812],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["1";"5";"5";"0"],.. + pin=11,.. + pout=17,.. + pein=[],.. + peout=[],.. + gr_i=list(.. + "xstringb(orig(1),orig(2),[''Logical Op '';OPER],sz(1),sz(2),''fill'');",8),.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("logicalop_i8",4),.. + in=-1,.. + in2=-2,.. + intyp=5,.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[5;0],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(9)=scicos_link(.. + xx=[282.29299;305.09603;305.09603],.. + yy=[280.24498;280.52797;280.83282],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[10,1,1]) + scs_m.objs(10)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[305.09603,280.83282],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=9,.. + pout=[11;19],.. + pein=[],.. + peout=[],.. + gr_i=list([],8),.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(11)=scicos_link(.. + xx=[305.09603;305.09603;308.89555],.. + yy=[280.83282;329.46812;329.46812],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[10,1,0],.. + to=[8,1,1]) + scs_m.objs(12)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[184.8055,340.30536],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=[],.. + pout=13,.. + pein=[],.. + peout=[],.. + gr_i=list(" ",8),.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(13)=scicos_link(.. + xx=[204.8055;224.8055],.. + yy=[350.30536;350.30536],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[12,1,0],.. + to=[2,1,1]) + scs_m.objs(14)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[104.31759,276.91165],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=15,.. + pein=[],.. + peout=[],.. + gr_i=list(" ",8),.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + 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.objs(15)=scicos_link(.. + xx=[124.31759;144.31759],.. + yy=[286.91165;286.91165],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[14,1,0],.. + to=[3,1,1]) + scs_m.objs(16)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[406.03841,319.46812],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=17,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=list(" ",8),.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(17)=scicos_link(.. + xx=[386.03841;406.03841],.. + yy=[329.46812;329.46812],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[8,1,0],.. + to=[16,1,1]) + scs_m.objs(18)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[325.09603,270.83282],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=19,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=list(" ",8),.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + 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.objs(19)=scicos_link(.. + xx=[305.09603;325.09603],.. + yy=[280.83282;280.83282],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[10,2,0],.. + to=[18,1,1]) + + model=scicos_model() + model.sim="csuper" + model.in=[1;1] + model.in2=[1;1] + model.out=[1;1] + model.out2=[1;1] + model.intyp=[5 -1] + model.outtyp=[5 5] + model.blocktype="h" + model.firing=%f + model.dep_ut=[%t %f] + model.rpar=scs_m + gr_i=[] + x=standard_define([2 3],model,[],gr_i) + end +endfunction diff --git a/macros/IntegerOp/EXTRACTBITS.sci b/macros/IntegerOp/EXTRACTBITS.sci new file mode 100644 index 00000000..a0f1494e --- /dev/null +++ b/macros/IntegerOp/EXTRACTBITS.sci @@ -0,0 +1,275 @@ +// 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]=EXTRACTBITS(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,Datatype,rule,bit,scal,exprs]=scicos_getvalue( .. + [msprintf(gettext("Set %s block parameters"),"EXTRACTBITS");" "; gettext("Bits Extraction");" "; .. + gettext(" - Bits to Extract:"); .. + gettext(" 1 Upper Half"); gettext(" 2 Lower Half"); .. + gettext(" 3 Range from MSB"); gettext(" 4 Range to LSB"); .. + gettext(" 5 Range of Bits"); gettext(" - Number of Bits or Index of bit : Index 0 is LSB"); .. + gettext(" If ''Bits to Extract'' is set to ''Range of bits'': [Start, End]");" "],.. + [msprintf(gettext("Data Type %s"), "(3:int32, 4:int16, 5:int8, ...)"); gettext("Bits to extract"); .. + gettext("Number of Bits or Index of Bit"); gettext("Treat Bit Field as an Integer (0:No, 1:Yes)")],.. + list("vec",1,"vec",1,"vec",-1,"vec",1), exprs); + + if ~ok then + break, + end + bitstr = strcat(string(bit(:))," ") + if (rule < 1) | (rule > 5) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Bits to Extract"), rule), .. + msprintf(gettext("Must be in the interval %s."), "[1, 5]")); + ok = %f; + elseif scal < 0 | scal > 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Treat Bit Field as an Integer"), scal), .. + msprintf(gettext("Must be in the interval %s."), "[0, 1]")); + ok = %f + else + + in=[model.in model.in2]; + bit=int(bit); + rule=int(rule); + + if (rule==3)|(rule==4) then + if (size(bit,"*") ~= 1) then + block_parameter_error(msprintf(gettext("Wrong size for ''%s'' parameter: %s."), gettext("Number of Bits or Index of Bit"), bitstr), .. + gettext("Must be a single value.")); + ok=%f; + else + numb=bit; + end + elseif (rule==5) + if (size(bit,"*") ~= 2) then + block_parameter_error(msprintf(gettext("Wrong size for ''%s'' parameter: %s."), gettext("Number of Bits or Index of Bit"), bitstr), .. + gettext("Must have this form: [Start, End].")); + ok=%f; + elseif bit(1) > bit(2) then + block_parameter_error(msprintf(gettext("Wrong values for ''%s'' parameter: %s."), gettext("Number of Bits or Index of Bit"), bitstr), .. + msprintf(gettext("''Start'' must be less than ''End''."))); + ok=%f; + else + numb=bit(2)-bit(1); + end ; + else + bit=0; + numb=[] + end + end + + if ok then + if (Datatype==3 | Datatype==6) then + + if or(bit(:) > 31) | or(bit(:) < 0) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s."), gettext("Number of Bits or Index of Bit"), bitstr), .. + msprintf(gettext("Indexes must be in the interval %s."), "[0, 31]")); + ok=%f; + end + select rule + case 1 then + select scal + case 0 then + model.sim=list("extract_bit_32_UH0",4) + case 1 then + select Datatype + case 3 then + model.sim=list("extract_bit_32_UH1",4) + case 6 then + model.sim=list("extract_bit_u32_UH1",4) + end + end + case 2 then + model.sim=list("extract_bit_32_LH",4) + case 3 then + select scal + case 0 then + model.sim=list("extract_bit_32_MSB0",4) + case 1 then + select Datatype + case 3 then + model.sim=list("extract_bit_32_MSB1",4) + case 6 then + model.sim=list("extract_bit_u32_MSB1",4) + end + end + case 4 then + model.sim=list("extract_bit_32_LSB",4) + case 5 then + select scal + case 0 then + model.sim=list("extract_bit_32_RB0",4) + case 1 then + select Datatype + case 3 then + model.sim=list("extract_bit_32_RB1",4) + case 6 then + model.sim=list("extract_bit_u32_RB1",4) + end + end + end + elseif (Datatype==4 | Datatype==7) then + if or(bit(:) > 15) | or(bit(:) < 0) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s."), gettext("Number of Bits or Index of Bit"), bitstr), .. + msprintf(gettext("Indexes must be in the interval %s."), "[0, 15]")); + ok=%f; + end + select rule + case 1 then + select scal + case 0 then + model.sim=list("extract_bit_16_UH0",4) + case 1 then + select Datatype + case 4 then + model.sim=list("extract_bit_16_UH1",4) + case 7 then + model.sim=list("extract_bit_u16_UH1",4) + end + end + case 2 then + model.sim=list("extract_bit_16_LH",4) + case 3 then + select scal + case 0 then + model.sim=list("extract_bit_16_MSB0",4) + case 1 then + select Datatype + case 4 then + model.sim=list("extract_bit_16_MSB1",4) + case 7 then + model.sim=list("extract_bit_u16_MSB1",4) + end + end + case 4 then + model.sim=list("extract_bit_16_LSB",4) + case 5 then + select scal + case 0 then + model.sim=list("extract_bit_16_RB0",4) + case 1 then + select Datatype + case 4 then + model.sim=list("extract_bit_16_RB1",4) + case 7 then + model.sim=list("extract_bit_u16_RB1",4) + end + end + end + elseif (Datatype == 5 | Datatype == 8) then + if or(bit(:) > 7) | or(bit(:) < 0) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %s."), gettext("Number of Bits or Index of Bit"), bitstr), .. + msprintf(gettext("Indexes must be in the interval %s."), "[0, 7]")); + ok=%f; + end + select rule + case 1 then + select scal + case 0 then + model.sim=list("extract_bit_8_UH0",4) + case 1 then + select Datatype + case 5 then + model.sim=list("extract_bit_8_UH1",4) + case 8 then + model.sim=list("extract_bit_u8_UH1",4) + end + end + case 2 then + model.sim=list("extract_bit_8_LH",4) + case 3 then + select scal + case 0 then + model.sim=list("extract_bit_8_MSB0",4) + case 1 then + select Datatype + case 5 then + model.sim=list("extract_bit_8_MSB1",4) + case 8 then + model.sim=list("extract_bit_u8_MSB1",4) + end + end + case 4 then + model.sim=list("extract_bit_8_LSB",4) + case 5 then + select scal + case 0 then + model.sim=list("extract_bit_8_RB0",4) + case 1 then + select Datatype + case 5 then + model.sim=list("extract_bit_8_RB1",4) + case 8 then + model.sim=list("extract_bit_u8_RB1",4) + end + end + end + else + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Data Type"), Datatype), .. + msprintf(gettext("Must be in the interval %s."), "[3, 8]")); + ok=%f; + end + end + + if ok then + it=Datatype + ot=Datatype + out=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + graphics.exprs=exprs; + model.ipar=[int(bit(:));int(numb(:))]; + x.graphics=graphics; + x.model=model; + break + end + end + + case "define" then + numb=[]; + model=scicos_model() + model.sim=list("extract_bit_32_UH0",4) + model.in=1 + model.in2=1 + model.out=1 + model.out2=1; + model.intyp=3 + model.outtyp=3 + model.ipar=[0,numb] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(3);sci2exp(1);sci2exp(0);sci2exp(0)] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + + end +endfunction diff --git a/macros/IntegerOp/INTMUL.sci b/macros/IntegerOp/INTMUL.sci new file mode 100644 index 00000000..e5772467 --- /dev/null +++ b/macros/IntegerOp/INTMUL.sci @@ -0,0 +1,137 @@ +// Scicos +// +// 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]=INTMUL(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,Datatype,np,exprs]=scicos_getvalue( .. + [msprintf(gettext("Set %s block parameters"),"INTMUL"); " "; gettext("Integer matrix multiplication");" ";],.. + [msprintf(gettext("Data Type %s"), "(3:int32, 4:int16, 5:int8, ...)"); gettext("Do on Overflow (0:Nothing, 1:Saturate, 2:Error)")],.. + list("vec",1,"vec",1), exprs) + if ~ok then + break, + end + + it=Datatype*ones(1,2); + ot=Datatype; + if (np~=0 & np~=1 & np~=2) then + block_parameter_error(msprintf( gettext("Wrong value for ''%s'' parameter: %d."), gettext("Do on Overflow"), np), .. + msprintf( gettext("Must be in the interval %s."), "[0, 2]")); + ok=%f; + elseif Datatype==3 then + if np==0 then + model.sim=list("matmul_i32n",4) + elseif np==1 then + model.sim=list("matmul_i32s",4) + else + model.sim=list("matmul_i32e",4) + end + elseif Datatype==4 then + if np==0 then + model.sim=list("matmul_i16n",4) + elseif np==1 then + model.sim=list("matmul_i16s",4) + else + model.sim=list("matmul_i16e",4) + end + elseif Datatype==5 then + if np==0 then + model.sim=list("matmul_i8n",4) + elseif np==1 then + model.sim=list("matmul_i8s",4) + else + model.sim=list("matmul_i8e",4) + end + elseif Datatype==6 then + if np==0 then + model.sim=list("matmul_ui32n",4) + elseif np==1 then + model.sim=list("matmul_ui32s",4) + else + model.sim=list("matmul_ui32e",4) + end + elseif Datatype==7 then + if np==0 then + model.sim=list("matmul_ui16n",4) + elseif np==1 then + model.sim=list("matmul_ui16s",4) + else + model.sim=list("matmul_ui16e",4) + end + elseif Datatype==8 then + if np==0 then + model.sim=list("matmul_ui8n",4) + elseif np==1 then + model.sim=list("matmul_ui8s",4) + else + model.sim=list("matmul_ui8e",4) + end + else + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Data Type"), ot), .. + msprintf(gettext("Must be in the interval %s."), "[3, 8]")); + ok=%f; + + end + in=[model.in model.in2] + out=[model.out model.out2] + if ok then + [model,graphics,ok]=set_io(model,graphics,... + list(in,it),... + list(out,ot),[],[]) + end + if ok then + model.ipar=np + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + sgn=0 + model=scicos_model() + model.sim=list("matmul_i32",4) + model.in=[-1;-2] + model.out=-1 + model.in2=[-2;-3] + model.out2=-3 + model.intyp=[3 3] + model.outtyp=3 + model.rpar=[] + model.ipar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=[sci2exp(3);sci2exp(0)] + gr_i=[] + x=standard_define([2 2],model, exprs,gr_i) + end +endfunction diff --git a/macros/IntegerOp/JKFLIPFLOP.sci b/macros/IntegerOp/JKFLIPFLOP.sci new file mode 100644 index 00000000..67405172 --- /dev/null +++ b/macros/IntegerOp/JKFLIPFLOP.sci @@ -0,0 +1,833 @@ +// 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] = JKFLIPFLOP(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the 1/z block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "DOLLAR_m" then + path = i; + break; + end + end + // if exprs==[] then exprs=sci2exp(int8(0));end + newpar=list() + xx=arg1.model.rpar.objs(path)// get the 1/z block + exprs=xx.graphics.exprs(1) + model=xx.model; + init_old= model.odstate(1) + while %t do + [ok,init,exprs0]=scicos_getvalue( .. + [msprintf(gettext("Set %s block parameters"), "JKFLIPFLOP" ); " ";gettext("JK flip-flop");" "; .. + gettext("The ''Initial Value'' must be 0 or 1 of type int8"); .. + gettext(" - Negative values are considered as int8(0)"); gettext(" - Positive values are considered as int8(1)"); " "], .. + gettext("Initial Value"), .. + list("vec",1), exprs); + + if ~ok then + break, + end + if init<=0 then + init=int8(0); + elseif init >0 then + init=int8(1); + end + if ok then + xx.graphics.exprs(1)=exprs0 + model.odstate(1)=init + xx.model=model + arg1.model.rpar.objs(path)=xx// Update + break + end + end + needcompile=0 + if init_old<>init then + // parameter changed + newpar(size(newpar)+1)=1// Notify modification + needcompile=2 + end + x=arg1 + y=needcompile + typ=newpar + case "define" then + scs_m=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["JKFLIPFLOP"],.. + tol=[0.0001;0.000001;1.000E-10;100001;0;0;0],.. + tf=60,.. + 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.objs(1)=scicos_block(.. + gui="DOLLAR_m",.. + graphics=scicos_graphics(.. + orig=[299.96961,261.584],.. + sz=[40,40],.. + flip=%f,.. + theta=0,.. + exprs=["int8(0)";"1"],.. + pin=7,.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("dollar4_m",4),.. + in=1,.. + in2=1,.. + intyp=5,.. + out=1,.. + out2=1,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(int8(0)),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["EDGE_TRIGGER","./"],.. + tol=[0.0001;0.000001;1.000E-10;100001;0;0;0],.. + tf=30,.. + 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="EDGETRIGGER",.. + graphics=scicos_graphics(.. + orig=[288.58631,257.1131],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs="-1",.. + pin=5,.. + pout=3,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("edgetrig",4),.. + in=1,.. + in2=[],.. + intyp=1,.. + out=1,.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=0,.. + odstate=list(),.. + rpar=[],.. + ipar=-1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=1,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_block(.. + gui="IFTHEL_f",.. + graphics=scicos_graphics(.. + orig=[388.28869,247.1131],.. + sz=[60,60],.. + flip=%t,.. + theta=0,.. + exprs=["0";"0"],.. + pin=3,.. + pout=[],.. + pein=[],.. + peout=[7;0],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("ifthel",-1),.. + in=1,.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=1,.. + outtyp=[],.. + 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(3)=scicos_link(.. + xx=[357.15774;362.99107;379.71726],.. + yy=[277.1131;277.1131;277.1131],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[2,1,1]) + scs_m_1.objs(4)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[240.01488,267.1131],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=5,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + 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(5)=scicos_link(.. + xx=[260.01488;280.01488],.. + yy=[277.1131;277.1131],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[1,1,1]) + scs_m_1.objs(6)=scicos_block(.. + gui="CLKOUTV_f",.. + graphics=scicos_graphics(.. + orig=[398.28869,181.39881],.. + sz=[20,30],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=[],.. + pein=7,.. + 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(7)=scicos_link(.. + xx=[408.28869;408.28869],.. + yy=[241.39881;211.39881],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1,0],.. + to=[6,1,1]) + scs_m.objs(2)=scicos_block(.. + gui="EDGE_TRIGGER",.. + graphics=scicos_graphics(.. + orig=[292.52452,323.54888],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=14,.. + pout=[],.. + pein=[],.. + peout=8,.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="csuper",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[],.. + 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()),.. + doc=list()) + scs_m.objs(3)=scicos_block(.. + gui="LOGIC",.. + graphics=scicos_graphics(.. + orig=[302.79613,202.52782],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["[0;1;1;1;0;0;1;0]";"0"],.. + pin=[5;16;18],.. + pout=4,.. + pein=8,.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("logic",4),.. + in=[1;1;1],.. + in2=[1;1;1],.. + intyp=[5;5;5],.. + out=1,.. + out2=1,.. + outtyp=5,.. + evtin=1,.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(int8([0;1;1;1;0;0;1;0])),.. + blocktype="c",.. + firing=%f,.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(4)=scicos_link(.. + xx=[351.36756;368.82793;368.82793],.. + yy=[222.52782;222.52782;223.06473],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[10,1,1]) + scs_m.objs(5)=scicos_link(.. + xx=[291.39818;274.18235;274.18235;294.2247],.. + yy=[281.584;281.584;232.52782;232.52782],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[3,1,1]) + scs_m.objs(6)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[368.82793,243.45067],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=11,.. + pout=[7;20],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(7)=scicos_link(.. + xx=[368.82793;368.82793;345.68389],.. + yy=[243.45067;281.584;281.584],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[6,1,0],.. + to=[1,1,1]) + scs_m.objs(8)=scicos_link(.. + xx=[322.52452;374.69743;374.69743;322.79613],.. + yy=[317.8346;317.8346;248.24211;248.24211],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[2,1,0],.. + to=[3,1,1]) + scs_m.objs(9)=scicos_block(.. + gui="LOGICAL_OP",.. + graphics=scicos_graphics(.. + orig=[377.63217,159.25363],.. + sz=[60,40],.. + flip=%t,.. + theta=0,.. + exprs=["1";"5";"5";"0"],.. + pin=12,.. + pout=22,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("logicalop_i8",4),.. + in=-1,.. + in2=-2,.. + intyp=5,.. + out=-1,.. + out2=-2,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[5;0],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(10)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[368.82793;223.06473],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=4,.. + pout=[11;12],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(11)=scicos_link(.. + xx=[368.82793;368.82793],.. + yy=[223.06473;243.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[10,1,0],.. + to=[6,1,1]) + scs_m.objs(12)=scicos_link(.. + xx=[368.82793;368.82793;369.06074],.. + yy=[223.06473;177.7867;179.25363],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[10,2,0],.. + to=[9,1,1]) + scs_m.objs(13)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[243.95309,333.54888],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=[],.. + pout=14,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(14)=scicos_link(.. + xx=[263.95309;283.95309],.. + yy=[343.54888;343.54888],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[13,1,0],.. + to=[2,1,1]) + scs_m.objs(15)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[254.2247,212.52782],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=16,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + 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.objs(16)=scicos_link(.. + xx=[274.2247;294.2247],.. + yy=[222.52782;222.52782],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[15,1,0],.. + to=[3,2,1]) + scs_m.objs(17)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[254.2247,202.52782],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="3",.. + pin=[],.. + pout=18,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=3,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(18)=scicos_link(.. + xx=[274.2247;294.2247],.. + yy=[212.52782;212.52782],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[17,1,0],.. + to=[3,3,1]) + scs_m.objs(19)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[388.82793,233.45067],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=20,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + 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.objs(20)=scicos_link(.. + xx=[368.82793;388.82793],.. + yy=[243.45067;243.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[6,2,0],.. + to=[19,1,1]) + scs_m.objs(21)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[466.2036,169.25363],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=22,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(22)=scicos_link(.. + xx=[446.2036;466.2036],.. + yy=[179.25363;179.25363],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[9,1,0],.. + to=[21,1,1]) + model=scicos_model() + model.sim="csuper" + model.in=[1;1;1] + model.in2=[1;1;1] + model.out=[1;1] + model.out2=[1;1] + model.intyp=[5 1 5] + model.outtyp=[5 5] + model.blocktype="h" + model.firing=%f + model.dep_ut=[%t %f] + model.rpar=scs_m + gr_i=[] + x=standard_define([2 3],model,[],gr_i) + end +endfunction + diff --git a/macros/IntegerOp/LOGIC.sci b/macros/IntegerOp/LOGIC.sci new file mode 100644 index 00000000..c2778b82 --- /dev/null +++ b/macros/IntegerOp/LOGIC.sci @@ -0,0 +1,96 @@ +// 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]=LOGIC(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,mat,herit,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "LOGIC"); " ";gettext("Combinatorial logic");" "; + gettext(" Rows of the matrix are the output values"); gettext(" Number of rows must be a power of two."); .. + gettext(" Number of columns gives the number of outputs.");" "], .. + [gettext("Truth Table (matrix of outputs)"); gettext("Accepts Inherited Events (0:No, 1:Yes)")], .. + list("mat",[-1,-2],"vec",1), exprs); + + if ~ok then + break, + end + nout=size(mat,2) + nin=(log(size(mat,1))/log(2)) + u1=floor(nin) + //if (herit<>0) then herit=1;end; The test below verify the value of parameter + if (u1 <> nin) then + block_parameter_error(msprintf(gettext("Wrong size for ''%s'' parameter: %d."), gettext("Truth Table"), size(mat,1)), .. + gettext("Number of rows must be a power of two.")); + ok=%f; + elseif (find(mat(:) <> 0 & mat(:) <> 1) <> []) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Truth Table")), .. + msprintf(gettext( "Elements must be in the interval %s."),"[0, 1]")); + ok=%f; + elseif herit <0 | herit > 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Accepts Inherited Events"), herit), .. + msprintf(gettext( "Must be in the interval %s."),"[0, 1]")); + ok=%f; + end + if ok then + in=[ones(nin,1) ones(nin,1)] + out=[ones(nout,1) ones(nout,1)] + it=5*ones(1,nin) + ot=5*ones(1,nout) + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(1-herit,1),[]) + end + if ok then + graphics.exprs=exprs; + mat=int8(mat); + model.opar=list(mat); + x.graphics=graphics; + x.model=model; + break + end + end + case "define" then + mat=[0;0;0;1] + model=scicos_model() + model.sim=list("logic",4) + model.in=[1;1] + model.in2=[1;1] + model.out=1 + model.out2=1 + model.evtin=1 + model.intyp=[5 5] + model.outtyp=5 + model.opar=list(int8(mat)); + model.blocktype="c" + model.firing=%f + model.dep_ut=[%t %f] + exprs=[sci2exp(mat);sci2exp(0)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/IntegerOp/SHIFT.sci b/macros/IntegerOp/SHIFT.sci new file mode 100644 index 00000000..01ce6bba --- /dev/null +++ b/macros/IntegerOp/SHIFT.sci @@ -0,0 +1,152 @@ +// 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]=SHIFT(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,Datatype,nb,np,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "SHIFT");" "; gettext("Shift/Rotates bits")], .. + [msprintf(gettext("Data Type %s"), "(3:int32, 4:int16, 5:int8, ...)"); gettext("Number of Bits to Shift Left (Negative number to shift right)"); .. + gettext("Shift Type (0:Arithmetic, 1:Circular)")], .. + list("vec",1,"vec",1,"vec",1), exprs); + + if ~ok then + break, + end + if (np ~= 0 & np ~= 1) then + block_parameter_error(msprintf( gettext("Wrong value for ''%s'' parameter: %d."), gettext("Shift Type"), np), .. + msprintf(gettext("Must be in the interval %s."), "[0, 1]")); + ok=%f; + end + it=Datatype; + ot=Datatype; + // model.sim=list('shift_ia',4) + if (Datatype==3 | Datatype==6) then + if nb>0 then + select np + case 0 then + model.sim=list("shift_32_LA",4) + case 1 then + model.sim=list("shift_32_LC",4) + end + elseif nb<0 + select np + case 0 then + select Datatype + case 3 then + model.sim=list("shift_32_RA",4) + case 6 then + model.sim=list("shift_u32_RA",4) + end + case 1 then + model.sim=list("shift_32_RC",4) + end + end + elseif (Datatype==4 | Datatype==7) then + if nb>0 then + select np + case 0 then + model.sim=list("shift_16_LA",4) + case 1 then + model.sim=list("shift_16_LC",4) + end + elseif nb<0 + select np + case 0 then + select Datatype + case 4 then + model.sim=list("shift_16_RA",4) + case 7 then + model.sim=list("shift_u16_RA",4) + end + case 1 then + model.sim=list("shift_16_RC",4) + end + end + elseif (Datatype==5 | Datatype==8) then + if nb>0 then + select np + case 0 then + model.sim=list("shift_8_LA",4) + case 1 then + model.sim=list("shift_8_LC",4) + end + elseif nb<0 + select np + case 0 then + select Datatype + case 5 then + model.sim=list("shift_8_RA",4) + case 8 then + model.sim=list("shift_u8_RA",4) + end + case 1 then + model.sim=list("shift_8_RC",4) + end + end + else + block_parameter_error(msprintf( gettext( "Wrong value for ''%s'' parameter: %d."), gettext("Data Type"), Datatype), .. + msprintf(gettext( "Must be in the interval %s."), "[3, 8]" )); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,... + list([-1,-2],it),... + list([-1,-2],ot),[],[]) + end + if ok then + model.ipar=nb + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + sgn=[0;0] + OPER=0; + model=scicos_model() + model.sim=list("shift_32_LA",4) + model.in=-1 + model.out=-1 + model.in2=-2 + model.out2=-2 + model.intyp=3 + model.outtyp=3 + model.rpar=[] + model.ipar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=[sci2exp(3);sci2exp(0);sci2exp(0)] + gr_i=[] + x=standard_define([3 2],model, exprs,gr_i) + end +endfunction diff --git a/macros/IntegerOp/SRFLIPFLOP.sci b/macros/IntegerOp/SRFLIPFLOP.sci new file mode 100644 index 00000000..f0d5264f --- /dev/null +++ b/macros/IntegerOp/SRFLIPFLOP.sci @@ -0,0 +1,451 @@ +// 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] = SRFLIPFLOP(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the 1/z block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "DOLLAR_m" then + path = i; + break; + end + end + + newpar=list() + xx=arg1.model.rpar.objs(path)// get the 1/z block + exprs=xx.graphics.exprs(1) + model=xx.model; + init_old= model.odstate(1) + while %t do + [ok,init,exprs0]=scicos_getvalue([msprintf(gettext("Set %s block parameters"), "SRFLIPFLOP" );" "; gettext("SR flip-flop"); " "; .. + gettext("The ''Initial Value'' must be 0 or 1 of type int8"); gettext(" - Negative values are considered as int8(0)"); .. + gettext(" - Positive values are considered as int8(1)"); " "], .. + gettext("Initial Value"), .. + list("vec",1), exprs) + + if ~ok then + break, + end + if init<=0 then + init=int8(0); + elseif init >0 then + init=int8(1); + end + if ok then + xx.graphics.exprs(1)=exprs0 + model.odstate(1)=init + xx.model=model + arg1.model.rpar.objs(path)=xx// Update + break + end + end + needcompile=0 + if init_old<>init then + // parameter changed + newpar(size(newpar)+1)=path// Notify modification + needcompile=2 + end + x=arg1 + y=needcompile + typ=newpar + case "define" then + scs_m=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["SRFLIPFLOP"],.. + tol=[0.0001;0.000001;1.000E-10;100001;0;0;0],.. + tf=60,.. + 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.objs(1)=scicos_block(.. + gui="LOGIC",.. + graphics=scicos_graphics(.. + orig=[298.504,201.45067],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["[0 1;1 0;1 0;1 0;0 1;0 1;0 0;0 0]";"1"],.. + pin=[4;10;12],.. + pout=[3;8],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E";"E"],.. + out_implicit=["E";"E"]),.. + model=scicos_model(.. + sim=list("logic",4),.. + in=[1;1;1],.. + in2=[1;1;1],.. + intyp=[5;5;5],.. + out=[1;1],.. + out2=[1;1],.. + outtyp=[5;5],.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(.. + int8([0,1; + 1,0; + 1,0; + 1,0; + 0,1; + 0,1; + 0,0; + 0,0])),.. + blocktype="c",.. + firing=%f,.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(2)=scicos_block(.. + gui="DOLLAR_m",.. + graphics=scicos_graphics(.. + orig=[299.23733,254.25067],.. + sz=[40,40],.. + flip=%f,.. + theta=0,.. + exprs=["int8(0)";"1"],.. + pin=6,.. + pout=4,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("dollar4_m",4),.. + in=1,.. + in2=1,.. + intyp=5,.. + out=1,.. + out2=1,.. + outtyp=5,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(int8(0)),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(3)=scicos_link(.. + xx=[347.07543;363.03733;363.03733],.. + yy=[228.11733;228.11733;248.584],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[5,1,1]) + scs_m.objs(4)=scicos_link(.. + xx=[290.6659;272.104;272.104;289.93257],.. + yy=[274.25067;274.25067;231.45067;231.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[2,1,0],.. + to=[1,1,1]) + scs_m.objs(5)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[363.03733,248.584],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=3,.. + pout=[6;14],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(6)=scicos_link(.. + xx=[363.03733;363.03733;344.95162],.. + yy=[248.584;274.25067;274.25067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[5,1,0],.. + to=[2,1,1]) + scs_m.objs(7)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[367.07543,204.784],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=8,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(8)=scicos_link(.. + xx=[347.07543;367.07543],.. + yy=[214.784;214.784],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,2,0],.. + to=[7,1,1]) + scs_m.objs(9)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[249.93257,211.45067],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=10,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + 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.objs(10)=scicos_link(.. + xx=[269.93257;289.93257],.. + yy=[221.45067;221.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[9,1,0],.. + to=[1,2,1]) + scs_m.objs(11)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[249.93257,201.45067],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="2",.. + pin=[],.. + pout=12,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=2,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(12)=scicos_link(.. + xx=[269.93257;289.93257],.. + yy=[211.45067;211.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[11,1,0],.. + to=[1,3,1]) + scs_m.objs(13)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[383.03733,238.584],.. + 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=[],.. + 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.objs(14)=scicos_link(.. + xx=[363.03733;383.03733],.. + yy=[248.584;248.584],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[5,2,0],.. + to=[13,1,1]) + + model=scicos_model() + model.sim="csuper" + model.in=[1;1] + model.in2=[1;1] + model.out=[1;1] + model.out2=[1;1] + model.intyp=[5 5] + model.outtyp=[5 5] + model.blocktype="h" + model.firing=%f + model.dep_ut=[%t %f] + model.rpar=scs_m + gr_i=[] + x=standard_define([2 3],model,[],gr_i) + end +endfunction + diff --git a/macros/Linear/BIGSOM_f.sci b/macros/Linear/BIGSOM_f.sci new file mode 100644 index 00000000..abfb8f35 --- /dev/null +++ b/macros/Linear/BIGSOM_f.sci @@ -0,0 +1,68 @@ +// 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]=BIGSOM_f(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,sgn,exprs]=scicos_getvalue("Set sum block parameters",.. + "Inputs ports signs/gain",list("vec",-1),exprs) + if ~ok then + break + end + + in = -ones(size(sgn,"*"),1) + + //** Patch: check added + [model,graphics,ok] = check_io(model,graphics,in,-1,[],[]); + if ok then + model.rpar = sgn(:); + graphics.exprs = exprs; + + x.graphics = graphics; + x.model = model ; + break + end + + end + case "define" then + sgn=[1;1] + model=scicos_model() + model.sim=list("sum",2) + model.in=[-1;-1] + model.out=-1 + model.rpar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=sci2exp(sgn) + gr_i=[] + x=standard_define([2 3],model, exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLINDUMMY_f.sci b/macros/Linear/CLINDUMMY_f.sci new file mode 100644 index 00000000..5fea8b0c --- /dev/null +++ b/macros/Linear/CLINDUMMY_f.sci @@ -0,0 +1,41 @@ +// 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]=CLINDUMMY_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + x0=0; + model=scicos_model() + model.sim=list("cdummy",4) + model.state=x0 + model.blocktype="c" + model.firing=[] + model.dep_ut=[%f %t] + + gr_i=[] + x=standard_define([3 2],model,[],gr_i) + end +endfunction diff --git a/macros/Linear/CLR.sci b/macros/Linear/CLR.sci new file mode 100644 index 00000000..22238125 --- /dev/null +++ b/macros/Linear/CLR.sci @@ -0,0 +1,99 @@ +// 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]=CLR(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics;exprs=graphics.exprs + model=arg1.model; + x0=model.state + rpar=model.rpar + ns=prod(size(x0));nin=1;nout=1 + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.s=%s //add s definition to the context + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set continuous SISO transfer parameters",.. + ["Numerator (s)"; + "Denominator (s)"],.. + list("pol",1,"pol",1),exprs) + + + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer function must be proper or strictly proper.") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + rpar=[matrix(A,ns1*ns1,1); + matrix(B,ns1,1); + matrix(C,ns1,1); + D] + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + model.state=x0 + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+s"] + model=scicos_model() + model.sim=list("csslti4",4) + model.in=1 + model.out=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLR_f.sci b/macros/Linear/CLR_f.sci new file mode 100644 index 00000000..6574f0be --- /dev/null +++ b/macros/Linear/CLR_f.sci @@ -0,0 +1,103 @@ +// 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]=CLR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x0=model.state + rpar=model.rpar + ns=prod(size(x0)); + nin=1; + nout=1 + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.s=%s //add s definition to the context + + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set continuous SISO transfer parameters",.. + ["Numerator (s)"; + "Denominator (s)"],.. + list("pol",1,"pol",1),exprs) + + + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer must be proper or strictly proper") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + rpar=[matrix(A,ns1*ns1,1); + matrix(B,ns1,1); + matrix(C,ns1,1); + D] + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + model.state=x0 + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+s"] + model=scicos_model() + model.sim=list("csslti",1) + model.in=1 + model.out=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + gr_i=[] + + x=standard_define([2.5 2.5],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLSS.sci b/macros/Linear/CLSS.sci new file mode 100644 index 00000000..f7a36b97 --- /dev/null +++ b/macros/Linear/CLSS.sci @@ -0,0 +1,123 @@ +// 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]=CLSS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + okD=%t + if size(D,"*")<>size(C,1)*size(B,2) then + if size(D,"*")==1 then + D = D*ones(C*B) ; + elseif size(D,"*")==0 then + D = zeros(C*B) ; + else + okD = %f ; + end + end + if ms<>ns|~okD then + message(_("Matrix A is not square or D has wrong dimension")) + else + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + in=1; + out=1 + + model=scicos_model() + model.sim=list("csslti4",4) + model.in=in + model.out=out + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)]; + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLSS_f.sci b/macros/Linear/CLSS_f.sci new file mode 100644 index 00000000..279ffbfb --- /dev/null +++ b/macros/Linear/CLSS_f.sci @@ -0,0 +1,113 @@ +// 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]=CLSS_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + in=1; + out=1 + + model=scicos_model() + model.sim=list("csslti",1) + model.in=in + model.out=out + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)]; + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DELAYV_f.sci b/macros/Linear/DELAYV_f.sci new file mode 100644 index 00000000..444e4427 --- /dev/null +++ b/macros/Linear/DELAYV_f.sci @@ -0,0 +1,90 @@ +// 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]=DELAYV_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + nin=model.in(1) + z0=model.dstate; + zz0=z0(1:$-1); + told=z0($); + + while %t do + [ok,nin,zz0,T,exprs]=scicos_getvalue("Set delay parameters",.. + ["Number of inputs"; + "Register initial condition"; + "Max delay"],.. + list("vec",1,"vec",-1,"vec",1),.. + exprs); + if ~ok then + break, + end + if size(zz0,"*")<2 then + message("Register length must be at least 2") + ok=%f + end + if T<=0 then + message("Delay must be positive") + ok=%f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[nin;1],nin,1,[1;1]) + end + if ok then + graphics.exprs=exprs; + model.dstate=[zz0(:);told]; + model.rpar=T/(size(zz0,"*")); + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nin=1 + z0=zeros(11,1); + zz0=z0(1:$-1) + T=1 + + model=scicos_model() + model.sim=list("delayv",1) + model.in=[nin;1] + model.out=nin + model.evtin=1 + model.evtout=[1;1] + model.dstate=z0 + model.rpar=T/(size(zz0,"*")) + model.blocktype="d" + model.firing=[0 -1] + model.dep_ut=[%t %f] + + exprs=[string(nin);strcat(string(z0(1:$-1)),";");string(T)]; + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DELAY_f.sci b/macros/Linear/DELAY_f.sci new file mode 100644 index 00000000..38f6c06f --- /dev/null +++ b/macros/Linear/DELAY_f.sci @@ -0,0 +1,173 @@ +// 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]=DELAY_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the children blocks + ppath = list(0,0); + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "REGISTER_f" then + ppath(1) = i; + end + if typeof(o) == "Block" & o.gui == "EVTDLY_f" then + ppath(2) = i; + end + if and(ppath <> list(0,0)) then + break; + end + end + + // paths to updatable parameters or states + x=arg1 + + newpar=list(); + register=x.model.rpar.objs(ppath(1)) //data structure of register block + evtdly=x.model.rpar.objs(ppath(2)) //data structure of evtdly block + register_exprs=register.graphics.exprs + evtdly_exprs=evtdly.graphics.exprs + exprs=[evtdly_exprs(1);register_exprs] + while %t do + [ok,dt,z0,exprs]=scicos_getvalue(["This block implements as a discretized delay"; + "it is consist of a shift register and a clock"; + "value of the delay is given by;" + "the discretization time step multiplied by the"; + "number-1 of state of the register"],.. + ["Discretization time step"; + "Register initial state"],list("vec",1,"vec",-1),exprs) + if ~ok then + break, + end + mess=[] + if prod(size(z0))<1 then + mess=[mess;"Register length must be at least 1";" "] + ok=%f + end + if dt<=0 then + mess=[mess;"Discretization time step must be positive";" "] + ok=%f + end + if ~ok then + message(mess); + else + //Change the clock + evtdly.graphics.exprs(1)=exprs(1); + // evtdly.model.firing=0; //initial delay firing date + + if evtdly.model.rpar<>dt then //Discretization time step + evtdly.model.rpar=dt + newpar($+1)=ppath(2) // notify clock changes + end + x.model.rpar.objs(ppath(2))=evtdly + + //Change the register + register.graphics.exprs=exprs(2) + if or(register.model.dstate<>z0(:)) then //Register initial state + register.model.dstate=z0(:) + newpar($+1)=ppath(1) // notify register changes + end + x.model.rpar.objs(ppath(1))=register + break + end + end + needcompile=0 + y=needcompile + typ=newpar + case "define" then + evtdly=EVTDLY_f("define") + evtdly.graphics.orig=[243,296] + evtdly.graphics.sz=[40,40] + evtdly.graphics.flip=%t + evtdly.graphics.exprs=["0.1";"0"] + evtdly.graphics.pein=10 + evtdly.graphics.peout=7 + evtdly.model.rpar=0.1 + evtdly.model.firing=0 + + register=REGISTER_f("define") + register.graphics.orig=[238,195] + register.graphics.sz=[50,50] + register.graphics.flip=%t + register.graphics.exprs="0;0;0;0;0;0;0;0;0;0" + register.graphics.pin=6 + register.graphics.pout=5 + register.graphics.pein=9 + + input_port=IN_f("define") + input_port.graphics.orig=[92,210] + input_port.graphics.sz=[20,20] + input_port.graphics.flip=%t + input_port.graphics.exprs=["1";"1"] + input_port.graphics.pout=6 + input_port.model.ipar=1 + + output_port=OUT_f("define") + output_port.graphics.orig=[440,210] + output_port.graphics.sz=[20,20] + output_port.graphics.flip=%t + output_port.graphics.exprs=["1";"1"] + output_port.graphics.pin=5 + output_port.model.ipar=1 + + split=CLKSPLIT_f("define") + split.graphics.orig=[263;271.2] + split.graphics.pein=7, + split.graphics.peout=[9;10] + + diagram=scicos_diagram(); + diagram.objs(1)=input_port + diagram.objs(2)=output_port + diagram.objs(3)=register + diagram.objs(4)=evtdly + diagram.objs(5)=scicos_link(xx=[296.6;440],yy=[220;220],.. + from=[3,1],to=[2,1]) + diagram.objs(6)=scicos_link(xx=[112;229.4],yy=[220;220],.. + from=[1,1],to=[3,1]) + diagram.objs(7)=scicos_link(xx=[263;263],yy=[290.3;271.2],ct=[5,-1],.. + from=[4,1],to=[8,1]) + diagram.objs(8)=split + diagram.objs(9)=scicos_link(xx=[263;263],yy=[271.2;250.7],ct=[5,-1],.. + from=[8,1],to=[3,1]) + diagram.objs(10)=scicos_link(xx=[263;308.6;308.6;263;263],.. + yy=[271.2;271.2;367;367;341.7],.. + ct=[5,-1],from=[8,2],to=[4,1]) + x=scicos_block() + x.gui="DELAY_f" + x.graphics.sz=[2,2] + x.graphics.gr_i=[] + x.graphics.pin=0 + x.graphics.pout=0 + x.model.sim="csuper" + x.model.in=1 + x.model.out=1 + x.model.blocktype="h" + x.model.dep_ut=[%f %f] + x.model.rpar=diagram + x.graphics.in_implicit=["E"] + x.graphics.in_style="" + x.graphics.out_implicit=["E"] + x.graphics.out_style="" + end +endfunction diff --git a/macros/Linear/DERIV.sci b/macros/Linear/DERIV.sci new file mode 100644 index 00000000..67ef0657 --- /dev/null +++ b/macros/Linear/DERIV.sci @@ -0,0 +1,43 @@ +// 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] = DERIV(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + model=scicos_model() + model.sim=list("deriv",4) + model.in=-1 + model.out=-1 + model.blocktype="x" + model.dep_ut=[%t %f] + + exprs=[] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + + diff --git a/macros/Linear/DIFF_c.sci b/macros/Linear/DIFF_c.sci new file mode 100644 index 00000000..298879bc --- /dev/null +++ b/macros/Linear/DIFF_c.sci @@ -0,0 +1,80 @@ +// Scicos +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2009-2010 - DIGITEO - Clément DAVID +// +// 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]=DIFF_c(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 + ask_again=%f + [ok,x0,xd0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["Initial state";"Initial Derivative"],list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + N=size(x0,"*"); + xd0=xd0(:); + Nxd=size(xd0,"*"); + if (N~=Nxd) then + message("Incompatible sizes: states and their derivatives should have the same size ") + ask_again=%t + end + if (N<=0 & ~ask_again) then + x_message("number of states must be > 0 ") + ask_again=%t + end + + if ~ask_again then + graphics.exprs=exprs + model.state=[x0;xd0]; + model.out=[N] + model.in=N + x.graphics=graphics; + x.model=model + break + end + end + x.model.firing=[] //compatibility + case "define" then + x0=[0;0] + model=scicos_model() + model.sim=list("diffblk_c",10004) + model.in=1 + model.out=1 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(x0(1)));strcat(sci2exp(x0(2)))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLR.sci b/macros/Linear/DLR.sci new file mode 100644 index 00000000..78d350ff --- /dev/null +++ b/macros/Linear/DLR.sci @@ -0,0 +1,99 @@ +// 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]=DLR(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x0=model.dstate; + ns=prod(size(x0)); + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.z=%z //add z definition to the context + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set discrete SISO transfer parameters",.. + ["Numerator (z)"; + "Denominator (z)"],.. + list("pol",1,"pol",1),exprs) + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer function must be proper") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + rpar=[A(:); + B(:); + C(:); + D(:)] + model.dstate=x0 + model.rpar=rpar + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + x.graphics=graphics; + x.model=model + break + end + end + x.model.firing=[] //compatibility + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+z"] + + model=scicos_model() + model.sim=list("dsslti4",4) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLR_f.sci b/macros/Linear/DLR_f.sci new file mode 100644 index 00000000..7a9c634c --- /dev/null +++ b/macros/Linear/DLR_f.sci @@ -0,0 +1,98 @@ +// 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]=DLR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x0=model.dstate; + ns=prod(size(x0)); + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.z=%z //add z definition to the context + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set discrete SISO transfer parameters",.. + ["Numerator (z)"; + "Denominator (z)"],.. + list("pol",1,"pol",1),exprs) + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer must be proper") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + rpar=[A(:); + B(:); + C(:); + D(:)] + model.dstate=x0 + model.rpar=rpar + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm,end + x.graphics=graphics; + x.model=model + break + end + end + x.model.firing=[] //compatibility + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+z"] + + model=scicos_model() + model.sim="dsslti" + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2.5 2.5],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLSS.sci b/macros/Linear/DLSS.sci new file mode 100644 index 00000000..ec3ee9e4 --- /dev/null +++ b/macros/Linear/DLSS.sci @@ -0,0 +1,120 @@ +// 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]=DLSS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set discrete linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + okD=%t + if size(D,"*")<>size(C,1)*size(B,2) then + if size(D,"*")==1 then + D = D*ones(C*B) ; + elseif size(D,"*")==0 then + D = zeros(C*B) ; + else + okD=%f + end + end + if ms<>ns|~okD then + message(_("Matrix A is not square or D has wrong dimension")) + else + [model,graphics,ok]=check_io(model,graphics,in,out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm,end + else + model.dep_ut=[%f %f]; + end + model.dstate=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + model=scicos_model() + model.sim=list("dsslti4",4) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLSS_f.sci b/macros/Linear/DLSS_f.sci new file mode 100644 index 00000000..da1e57b9 --- /dev/null +++ b/macros/Linear/DLSS_f.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]=DLSS_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set discrete linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,in,out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %f]; + end + model.dstate=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0;A=-1;B=1;C=1;D=0; + model=scicos_model() + model.sim=list("dsslti",1) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DOLLAR.sci b/macros/Linear/DOLLAR.sci new file mode 100644 index 00000000..c9e48fde --- /dev/null +++ b/macros/Linear/DOLLAR.sci @@ -0,0 +1,115 @@ +// 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]=DOLLAR(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //backward compatibility + if size(exprs,"*")<2 then + exprs(2)="0"; + end + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set 1/z block parameters",.. + ["initial condition";"Inherit (no:0, yes:1)"],... + list("mat",[-1 -2],"vec",-1),exprs) + if ~ok then + break, + end + out=[size(a,1) size(a,2)]; + if out==0 then + out=[], + end + in=out + model.sim=list("dollar4_m",4) + model.odstate=list(a); + model.dstate=[]; + if type ((a)==1) then + if isreal(a) then + it=1; + ot=1; + if (size(a,1)==1 | size(a,2)==1) then + model.sim=list("dollar4",4); + model.dstate=a(:); + model.odstate=list(); + end + else + it=2; + ot=2; + end + elseif (typeof(a)=="int32") then + it=3; + ot=3; + elseif (typeof(a)=="int16") then + it=4; + ot=4; + elseif (typeof(a)=="int8") then + it=5; + ot=5; + elseif (typeof(a)=="uint32") then + it=6; + ot=6; + elseif (typeof(a)=="uint16") then + it=7; + ot=7; + elseif (typeof(a)=="uint8") then + it=8; + ot=8; + else + message ("type is not recognized"); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(1-inh,1),[]) + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z=0 + inh=0 + in=1 + exprs=string([z;inh]) + model=scicos_model() + model.sim=list("dollar4",4) + model.in=in + model.out=in + model.evtin=1-inh + model.dstate=z + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Linear/DOLLAR_f.sci b/macros/Linear/DOLLAR_f.sci new file mode 100644 index 00000000..0f6dc285 --- /dev/null +++ b/macros/Linear/DOLLAR_f.sci @@ -0,0 +1,80 @@ +// 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]=DOLLAR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //backward compatibility + if size(exprs,"*")<2 then + exprs(2)="0"; + end + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set 1/z block parameters",.. + ["initial condition";"Inherit (no:0, yes:1)"],... + list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + out=size(a,"*"); + if out==0 then + out=[], + end + in=out + + if ok then + [model,graphics,ok]=check_io(model,graphics,-1,-1,ones(1-inh,1),[]) + end + + if ok then + graphics.exprs=exprs; + model.dstate=a; + model.in=in; + model.out=out + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + z=0 + inh=0 + in=1 + exprs=string([z;inh]) + model=scicos_model() + model.sim="dollar" + model.in=in + model.out=in + model.evtin=1-inh + model.dstate=z + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DOLLAR_m.sci b/macros/Linear/DOLLAR_m.sci new file mode 100644 index 00000000..10db92dc --- /dev/null +++ b/macros/Linear/DOLLAR_m.sci @@ -0,0 +1,115 @@ +// 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]=DOLLAR_m(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //backward compatibility + if size(exprs,"*")<2 then + exprs(2)="0"; + end + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set 1/z block parameters",.. + ["initial condition";"Inherit (no:0, yes:1)"],... + list("mat",[-1 -2],"vec",-1),exprs) + if ~ok then + break, + end + out=[size(a,1) size(a,2)]; + if out==0 then + out=[], + end + in=out + model.sim=list("dollar4_m",4) + model.odstate=list(a); + model.dstate=[]; + if (type(a)==1) then + if isreal(a) then + it=1; + ot=1; + if (size(a,1)==1 | size(a,2)==1) then + model.sim=list("dollar4",4); + model.dstate=a(:); + model.odstate=list(); + end + else + it=2; + ot=2; + end + elseif (typeof(a)=="int32") then + it=3; + ot=3; + elseif (typeof(a)=="int16") then + it=4; + ot=4; + elseif (typeof(a)=="int8") then + it=5; + ot=5; + elseif (typeof(a)=="uint32") then + it=6; + ot=6; + elseif (typeof(a)=="uint16") then + it=7; + ot=7; + elseif (typeof(a)=="uint8") then + it=8; + ot=8; + else + message ("type is not recognized"); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(1-inh,1),[]) + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z=0 + inh=0 + in=1 + exprs=string([z;inh]) + model=scicos_model() + model.sim=list("dollar4",4) + model.in=in + model.out=in + model.evtin=1-inh + model.dstate=z + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Linear/GAINBLK.sci b/macros/Linear/GAINBLK.sci new file mode 100644 index 00000000..406e1b1f --- /dev/null +++ b/macros/Linear/GAINBLK.sci @@ -0,0 +1,175 @@ +// 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] = GAINBLK(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,"*")==1 then + exprs=[exprs;sci2exp(0)]; + end // compatibility + while %t do + [ok,gain,over,exprs]=scicos_getvalue("Set gain block parameters",.. + ["Gain";.. + "Do On Overflow(0=Nothing 1=Saturate 2=Error)"],.. + list("mat",[-1,-1],"vec",1),exprs) + if ~ok then + break, + end + if gain==[] then + message("Gain must have at least one element") + else + if typeof(gain)=="constant" then + if isreal(gain) then + it =1; + ot=1; + model.sim=list("gainblk",4); + model.rpar=gain(:); + model.opar=list(); + else + message("type is not supported"); + ok=%f; + end + else + if (over==0) then + if (typeof(gain)=="int32") then + ot=3 + model.sim=list("gainblk_i32n",4) + elseif (typeof(gain)=="int16") then + ot=4 + model.sim=list("gainblk_i16n",4) + elseif (typeof(gain)=="int8") then + ot=5 + model.sim=list("gainblk_i8n",4) + elseif (typeof(gain)=="uint32") then + ot=6 + model.sim=list("gainblk_ui32n",4) + elseif (typeof(gain)=="uint16") then + ot=7 + model.sim=list("gainblk_ui16n",4) + elseif (typeof(gain)=="uint8") then + ot=8 + model.sim=list("gainblk_ui8n",4) + else + message("type is not supported."); + ok=%f; + end + elseif (over==1) then + if (typeof(gain)=="int32") then + ot=3 + model.sim=list("gainblk_i32s",4) + elseif (typeof(gain)=="int16") then + ot=4 + model.sim=list("gainblk_i16s",4) + elseif (typeof(gain)=="int8") then + ot=5 + model.sim=list("gainblk_i8s",4) + elseif (typeof(gain)=="uint32") then + ot=6 + model.sim=list("gainblk_ui32s",4) + elseif (typeof(gain)=="uint16") then + ot=7 + model.sim=list("gainblk_ui16s",4) + elseif (typeof(gain)=="uint8") then + ot=8 + model.sim=list("gainblk_ui8s",4) + else + message("type is not supported."); + ok=%f; + end + elseif (over==2) then + if (typeof(gain)=="int32") then + ot=3 + model.sim=list("gainblk_i32e",4) + elseif (typeof(gain)=="int16") then + ot=4 + model.sim=list("gainblk_i16e",4) + elseif (typeof(gain)=="int8") then + ot=5 + model.sim=list("gainblk_i8e",4) + elseif (typeof(gain)=="uint32") then + ot=6 + model.sim=list("gainblk_ui32e",4) + elseif (typeof(gain)=="uint16") then + ot=7 + model.sim=list("gainblk_ui16e",4) + elseif (typeof(gain)=="uint8") then + ot=8 + model.sim=list("gainblk_ui8e",4) + else + message("type is not an integer."); + ok=%f; + end + else + message("Do on Overflow must be 0,1,2"); + ok=%f; + end + model.rpar=[]; + model.opar=list(gain(:)); + end + if ok then + [out,in]=size(gain) + if out*in<>1 then + [model,graphics,ok]=set_io(model,graphics,... + list([in,-1],ot),... + list([out,-1],ot),[],[]) + else + [model,graphics,ok]=set_io(model,graphics,... + list([-1,-2],ot),... + list([-1,-2],ot),[],[]) + end + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + gain=1 + in=-1;out=-1 + in2=-2;out2=-2 + model=scicos_model() + model.sim=list("gainblk",4) + model.in=in + model.out=out + model.in2=in2 + model.out2=out2 + model.rpar=gain + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(gain))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/GAINBLK_f.sci b/macros/Linear/GAINBLK_f.sci new file mode 100644 index 00000000..93d22dc2 --- /dev/null +++ b/macros/Linear/GAINBLK_f.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]=GAINBLK_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,gain,exprs]=scicos_getvalue("Set gain block parameters",.. + ["Gain"],list("mat",[-1,-1]),exprs(1)) + if ~ok then + break, + end + if gain==[] then + message("Gain must have at least one element") + else + [out,in]=size(gain) + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs + model.rpar=gain(:); + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + gain=1 + in=1;out=1 + model=scicos_model() + model.sim="gain" + model.in=in + model.out=out + model.rpar=gain + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(gain))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/GAIN_f.sci b/macros/Linear/GAIN_f.sci new file mode 100644 index 00000000..f44cc32a --- /dev/null +++ b/macros/Linear/GAIN_f.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]=GAIN_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,gain,exprs]=scicos_getvalue("Set gain block parameters",.. + ["Gain"],list("mat",[-1,-1]),exprs(1)) + if ~ok then + break, + end + if gain==[] then + message("Gain must have at least one element") + else + [out,in]=size(gain) + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs + model.rpar=gain(:); + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + + gain=1;in=1;out=1; + model=scicos_model() + model.sim="gain" + model.in=1 + model.out=1 + model.rpar=gain + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(gain));strcat(sci2exp(in));strcat(sci2exp(out))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/INTEGRAL.sci b/macros/Linear/INTEGRAL.sci new file mode 100644 index 00000000..8bf1407a --- /dev/null +++ b/macros/Linear/INTEGRAL.sci @@ -0,0 +1,103 @@ +// 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]=INTEGRAL(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,x0,reinit,satur,maxp,lowp,exprs]=scicos_getvalue("Set Integral block parameters",.. + ["Initial Condition"; + "With re-intialization (1:yes, 0:no)";"With saturation (1:yes, 0:no)"; + "Upper limit";"Lower limit"],.. + list("vec",-1,"vec",1,"vec",1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + maxp=maxp(:), + lowp=lowp(:) + if reinit<>0 then + reinit=1; + end + if satur<>0 then + satur=1; + if size(maxp,"*")==1 then + maxp=maxp*ones(x0), + end + if size(lowp,"*")==1 then + lowp=lowp*ones(x0), + end + if (size(x0,1)<>size(maxp,1) | size(x0,1)<>size(lowp,1)) then + message("x0 and Upper limit and Lower limit must have same size") + ok=%f + elseif or(maxp<=lowp) then + message("Upper limits must be > Lower limits") + ok=%f + elseif or(x0>maxp)|or(x0<lowp) then + message("Initial condition x0 should be inside the limits") + ok=%f + else + rpar=[maxp;lowp] + model.nzcross=size(x0,1) + model.nmode=size(x0,1) + end + else + rpar=[] + model.nzcross=0 + model.nmode=0 + end + if ok then + model.rpar=rpar + model.state=x0 + [model,graphics,ok]=check_io(model,graphics,.. + size(x0,1)*[1;ones(reinit,1)],size(x0,1),ones(reinit,1),[]) + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + maxp=1;minp=-1;rpar=[] + model=scicos_model() + model.state=0 + model.sim=list("integral_func",4) + model.in=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=string([0;0;0;maxp;minp]) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.id="1/s" + end +endfunction diff --git a/macros/Linear/INTEGRAL_f.sci b/macros/Linear/INTEGRAL_f.sci new file mode 100644 index 00000000..16e1d950 --- /dev/null +++ b/macros/Linear/INTEGRAL_f.sci @@ -0,0 +1,61 @@ +// 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]=INTEGRAL_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,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + "Initial state",list("vec",1),exprs) + + + if ~ok then + break, + end + graphics.exprs=exprs; + model.state=x0; + x.graphics=graphics; + x.model=model + break + end + x.model.firing=[] //compatibility + case "define" then + x0=0 + model=scicos_model() + model.sim="integr" + model.in=1 + model.out=1 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=strcat(sci2exp(x0)) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/INTEGRAL_m.sci b/macros/Linear/INTEGRAL_m.sci new file mode 100644 index 00000000..6c70034c --- /dev/null +++ b/macros/Linear/INTEGRAL_m.sci @@ -0,0 +1,147 @@ +// 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] = INTEGRAL_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,x0,reinit,satur,maxp,lowp,exprs]=scicos_getvalue("Set Integral block parameters",.. + ["Initial Condition"; + "With re-intialization (1:yes, 0:no)";"With saturation (1:yes, 0:no)"; + "Upper limit";"Lower limit"],.. + list("mat",[-1 -1],"vec",1,"vec",1,"mat",[-1 -1],"mat",[-1 -1]),exprs) + if ~ok then + break, + end + if isreal(x0) then + Datatype=1; + else + Datatype=2; + end; + if reinit<>0 then + reinit=1; + end + if satur<>0 then + satur=1; + if Datatype==1 then + if size(maxp,"*")==1 then + maxp=maxp*ones(x0), + end + if size(lowp,"*")==1 then + lowp=lowp*ones(x0), + end + if (size(x0)<>size(maxp) | size(x0)<>size(lowp)) then + message("x0 and Upper limit and Lower limit must have same size") + ok=%f + elseif or(maxp<=lowp) then + message("Upper limits must be > Lower limits") + ok=%f + elseif or(x0>maxp)|or(x0<lowp) then + message("Initial condition x0 should be inside the limits") + ok=%f + else + rpar=[real(maxp(:));real(lowp(:))] + model.nzcross=size(x0,"*") + model.nmode=size(x0,"*") + end + elseif (Datatype==2) then + if size(maxp,"*")==1 then + maxp=maxp*ones(x0)+%i*(maxp*ones(x0)), + end + if size(lowp,"*")==1 then + lowp=lowp*ones(x0)+%i*(lowp*ones(x0)), + end + if (size(x0)<>size(maxp) | size(x0)<>size(lowp)) then + message("x0 and Upper limit and Lower limit must have same size") + ok=%f + elseif or(real(maxp)<=real(lowp))| or(imag(maxp)<=imag(lowp)) then + message("Upper limits must be > Lower limits") + ok=%f + elseif or(real(x0)>real(maxp))|or(real(x0)<real(lowp))| or(imag(x0)>imag(maxp))|or(imag(x0)<imag(lowp)) then + message("Initial condition x0 should be inside the limits") + ok=%f + else + rpar=[real(maxp(:));real(lowp(:));imag(maxp(:));imag(lowp(:))] + model.nzcross=2*size(x0,"*") + model.nmode=2*size(x0,"*") + end + end + else + rpar=[] + model.nzcross=0 + model.nmode=0 + end + if ok then + model.rpar=rpar + if (Datatype==1) then + model.state=real(x0(:)) + model.sim=list("integral_func",4) + it=[1;ones(reinit,1)] + ot=1; + elseif (Datatype==2) then + model.state=[real(x0(:));imag(x0(:))]; + model.sim=list("integralz_func",4) + it=[2;2*ones(reinit,1)] + ot=2; + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + in=[size(x0,1)*[1;ones(reinit,1)],size(x0,2)*[1;ones(reinit,1)]] + out=size(x0) + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(reinit,1),[]) + end + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + maxp=1; + minp=-1; + rpar=[] + model=scicos_model() + model.state=0 + model.sim=list("integral_func",4) + model.in=1 + model.out=1 + model.in2=1 + model.out2=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=string([0;0;0;maxp;minp]) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/PID.sci b/macros/Linear/PID.sci new file mode 100644 index 00000000..81f80100 --- /dev/null +++ b/macros/Linear/PID.sci @@ -0,0 +1,620 @@ +// 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]=PID(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the children blocks + ppath = list(0,0,0); + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Link" then + from = arg1.model.rpar.objs(o.from(1)); + to = arg1.model.rpar.objs(o.to(1)); + + if from.gui == "GAINBLK" then + select to.gui, + case "SUMMATION" then + ppath(1) = o.from(1), + case "INTEGRAL_m" then + ppath(2) = o.from(1), + case "DERIV" then + ppath(3) = o.from(1), + end + elseif to.gui == "GAINBLK" then + select from.gui, + case "SUMMATION" then + ppath(1) = o.to(1), + case "INTEGRAL_m" then + ppath(2) = o.to(1), + case "DERIV" then + ppath(3) = o.to(1), + end + end + + if and(ppath <> list(0,0,0)) then + break; + end + end + end + newpar=list(); + xx1=arg1.model.rpar.objs(ppath(1)) + exprs(1)=xx1.graphics.exprs(1) + p_old=xx1.model.rpar + xx2=arg1.model.rpar.objs(ppath(2)) + exprs(2)=xx2.graphics.exprs(1) + i_old=xx2.model.rpar + xx3=arg1.model.rpar.objs(ppath(3)) + exprs(3)=xx3.graphics.exprs(1) + d_old=xx3.model.rpar + y=0 + while %t do + [ok,p,i,d,exprs0]=scicos_getvalue("Set PID parameters",.. + ["Proportional";"Integral";"Derivation"],list("vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + if ok then + xx1.graphics.exprs=exprs0(1) + xx1.model.rpar=p + xx2.graphics.exprs=exprs0(2) + xx2.model.rpar=i + xx3.graphics.exprs=exprs0(3) + xx3.model.rpar=d + arg1.model.rpar.objs(ppath(1))=xx1 + arg1.model.rpar.objs(ppath(2))=xx2 + arg1.model.rpar.objs(ppath(3))=xx3 + break + end + end + needcompile=0 + if ~(p_old==p & i_old==i & d_old==d) then + newpar(size(newpar)+1)=ppath(1) + newpar(size(newpar)+1)=ppath(2) + newpar(size(newpar)+1)=ppath(3) + needcompile=2 + end + x=arg1 + y=max(y,needcompile) + typ=newpar + case "define" then + scs_m=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["PID"],.. + tol=[0.0001,0.000001,1.000E-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.objs(1)=scicos_block(.. + gui="INTEGRAL_m",.. + graphics=scicos_graphics(.. + orig=[318.304,183.11733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["0";"0";"0";"1";"-1"],.. + pin=7,.. + pout=9,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="1/s",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("integral_func",4),.. + in=1,.. + in2=1,.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=0,.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%t],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(2)=scicos_block(.. + gui="SUMMATION",.. + graphics=scicos_graphics(.. + orig=[387.97067,172.85067],.. + sz=[40,60],.. + flip=%t,.. + theta=0,.. + exprs=["1";"[1;1;1]"],.. + pin=[10;9;11],.. + pout=19,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("summation",4),.. + in=[-1;-1;-1],.. + in2=[-2;-2;-2],.. + intyp=[1;1;1],.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[1;1;1],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(3)=scicos_block(.. + gui="GAINBLK",.. + graphics=scicos_graphics(.. + orig=[321.23733,235.91733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=17,.. + pout=10,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("gainblk",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=1,.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(4)=scicos_block(.. + gui="DERIV",.. + graphics=scicos_graphics(.. + orig=[319.03733,135.45067],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=8,.. + pout=11,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="s",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("deriv",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="x",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(5)=scicos_block(.. + gui="GAINBLK",.. + graphics=scicos_graphics(.. + orig=[255.23733,183.11733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=13,.. + pout=7,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("gainblk",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=1,.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(6)=scicos_block(.. + gui="GAINBLK",.. + graphics=scicos_graphics(.. + orig=[255.23733,135.45067],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=14,.. + pout=8,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("gainblk",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=1,.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(7)=scicos_link(.. + xx=[303.80876;309.73257],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[5,1,0],.. + to=[1,1,1]) + scs_m.objs(8)=scicos_link(.. + xx=[303.80876;310.4659],.. + yy=[155.45067;155.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[6,1,0],.. + to=[4,1,1]) + scs_m.objs(9)=scicos_link(.. + xx=[366.87543;379.39924],.. + yy=[203.11733;202.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[2,2,1]) + scs_m.objs(10)=scicos_link(.. + xx=[369.80876;379.39924;379.39924],.. + yy=[255.91733;255.91733;217.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[2,1,1]) + scs_m.objs(11)=scicos_link(.. + xx=[367.60876;379.39924;379.39924],.. + yy=[155.45067;155.45067;187.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[2,3,1]) + scs_m.objs(12)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[234.704;203.11733],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=16,.. + pout=[13;14],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(13)=scicos_link(.. + xx=[234.704;246.6659],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[12,1,0],.. + to=[5,1,1]) + scs_m.objs(14)=scicos_link(.. + xx=[234.704;234.704;246.6659],.. + yy=[203.11733;155.45067;155.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[12,2,0],.. + to=[6,1,1]) + scs_m.objs(15)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[233.97067;203.11733],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=21,.. + pout=[16;17],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(16)=scicos_link(.. + xx=[233.97067;234.704],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[15,1,0],.. + to=[12,1,1]) + scs_m.objs(17)=scicos_link(.. + xx=[233.97067;233.97067;312.6659],.. + yy=[203.11733;255.91733;255.91733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[15,2,0],.. + to=[3,1,1]) + scs_m.objs(18)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[456.5421,192.85067],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=19,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + 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.objs(19)=scicos_link(.. + xx=[436.5421;456.5421],.. + yy=[202.85067;202.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[2,1,0],.. + to=[18,1,1]) + scs_m.objs(20)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[193.97067,193.11733],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=21,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + 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.objs(21)=scicos_link(.. + xx=[213.97067;233.97067],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[20,1,0],.. + to=[15,1,1]) + + model=scicos_model() + model.sim="csuper" + model.in=-1 + model.in2=-2 + model.out=-1 + model.out2=-2 + model.intyp=1 + model.outtyp=1 + model.blocktype="h" + model.firing=%f + model.dep_ut=[%f %f] + model.rpar=scs_m + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Linear/REGISTER.sci b/macros/Linear/REGISTER.sci new file mode 100644 index 00000000..1e637be3 --- /dev/null +++ b/macros/Linear/REGISTER.sci @@ -0,0 +1,105 @@ +// 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]=REGISTER(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,1)==1 then + exprs=[exprs;sci2exp(1)]; + end + while %t do + [ok,z0,it,exprs]=scicos_getvalue("Set delay parameters",.. + ["Register initial condition";.. + "Datatype (1=double 3=int32 ...)"],.. + list("vec",-1,"vec",1),exprs) + if ~ok then + break, + end + if prod(size(z0))<1 then + message("Register length must be at least 1") + ok=%f + end + if it==1 then + model.sim=list("delay4",4); + z0=double(z0); + model.dstate=z0; + model.odstate=list(); + else + if it==3 then + model.sim=list("delay4_i32",4) + z0=int32(z0) + elseif it==4 then + model.sim=list("delay4_i16",4) + z0=int16(z0) + elseif it==5 then + model.sim=list("delay4_i8",4) + z0=int8(z0) + elseif it==6 then + model.sim=list("delay4_ui32",4) + z0=uint32(z0) + elseif it==7 then + model.sim=list("delay4_ui16",4) + z0=uint16(z0) + elseif it==8 then + model.sim=list("delay4_ui8",4) + z0=uint8(z0) + else + message("Datatype is not supported"); + ok=%f + end + model.odstate=list(z0); + model.dstate=[] + end + if ok then + in=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(in,it),1,[]) + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z0=zeros(10,1) + model=scicos_model() + model.sim=list("delay4",4) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=z0 + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=strcat(string(z0), ";") + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/REGISTER_f.sci b/macros/Linear/REGISTER_f.sci new file mode 100644 index 00000000..c615b7fc --- /dev/null +++ b/macros/Linear/REGISTER_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]=REGISTER_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,z0,exprs]=scicos_getvalue("Set delay parameters",.. + "Register initial condition",list("vec",-1),exprs) + if ~ok then + break, + end + if prod(size(z0))<1 then + message("Register length must be at least 1") + ok=%f + end + if ok then + graphics.exprs=exprs; + model.dstate=z0 + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z0=zeros(10,1) + model=scicos_model() + model.sim="delay" + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=z0 + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=strcat(string(z0),";") + gr_i=[] + x=standard_define([2.5 2.5],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/SAMPHOLD.sci b/macros/Linear/SAMPHOLD.sci new file mode 100644 index 00000000..aa423a3a --- /dev/null +++ b/macros/Linear/SAMPHOLD.sci @@ -0,0 +1,43 @@ +// 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]=SAMPHOLD(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] //compatibility + case "define" then + in=-1 + model=scicos_model() + model.sim=list("samphold4",4) + model.in=-1 + model.out=-1 + model.evtin=1 + model.blocktype="d" + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model," ",gr_i) + end +endfunction diff --git a/macros/Linear/SAMPHOLD_m.sci b/macros/Linear/SAMPHOLD_m.sci new file mode 100644 index 00000000..1bd37ae3 --- /dev/null +++ b/macros/Linear/SAMPHOLD_m.sci @@ -0,0 +1,71 @@ +// 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]=SAMPHOLD_m(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] //compatibility + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + while %t do + [ok,it,exprs]=scicos_getvalue("Set parameters Block",.. + ["Datatype(1=real double 2=Complex 3=int32 ...)"],list("vec",1),label) + if ~ok then + break, + end + if ((it<1)|(it>8)) then + message ("Datatype is not supported"); + ok=%f; + end + if ok then + in=[model.in model.in2]; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(in,it),1,[]) + if ok then + graphics.exprs=exprs; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + end + case "define" then + model=scicos_model() + model.sim=list("samphold4_m",4) + model.in=-1 + model.in2=-2 + model.intyp=1 + model.outtyp=1 + model.out=-1 + model.out2=-2 + model.evtin=1 + model.blocktype="d" + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction diff --git a/macros/Linear/SAMPLEHOLD_f.sci b/macros/Linear/SAMPLEHOLD_f.sci new file mode 100644 index 00000000..10fd9bef --- /dev/null +++ b/macros/Linear/SAMPLEHOLD_f.sci @@ -0,0 +1,43 @@ +// 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]=SAMPLEHOLD_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] //compatibility + case "define" then + in=-1 + model=scicos_model() + model.sim="samphold" + model.in=-1 + model.out=-1 + model.evtin=1 + model.blocktype="d" + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model," ",gr_i) + end +endfunction diff --git a/macros/Linear/SOM_f.sci b/macros/Linear/SOM_f.sci new file mode 100644 index 00000000..4b9004fe --- /dev/null +++ b/macros/Linear/SOM_f.sci @@ -0,0 +1,72 @@ +// 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]=SOM_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + model=arg1.model; + exprs=graphics.exprs + if size(exprs,"*")==2 then + exprs=exprs(2), + end + if size(exprs,"*")<>3 then + exprs=string(model.rpar), + end + if graphics.flip then + labs=["down","left","up"] + else + labs=["down","right","up"] + end + + str = ["This sum block is obsolete" + "parameters cannot be modified. Please replace it with new sum block"; + "and gain blocks in the linear palette" + " " + "Input ports are located at up, side and down positions." + "Current gains are:"]; + + str = [str ; (part(labs(:),1:7)+exprs(:))]; + message(str); + + case "define" then + sgn=[1;1;1] + + model=scicos_model() + model.sim=list("sum",2) + model.in=[-1;-1;-1] + model.out=-1 + model.rpar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(1);sci2exp(sgn)] + + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/SUMMATION.sci b/macros/Linear/SUMMATION.sci new file mode 100644 index 00000000..f70c7882 --- /dev/null +++ b/macros/Linear/SUMMATION.sci @@ -0,0 +1,159 @@ +// 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]=SUMMATION(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,1)==1 then + exprs=[sci2exp(1);exprs;sci2exp(0)]; + elseif size(exprs,1)==2 then + exprs=[exprs;sci2exp(0)]; + end + while %t do + [ok,Datatype,sgn,satur,exprs]=scicos_getvalue("Set sum block parameters",.. + ["Datatype (1=real double 2=complex 3=int32 ...)";.. + "Number of inputs or sign vector (of +1, -1)";.. + "Do on Overflow(0=Nothing 1=Saturate 2=Error)"],.. + list("vec",1,"vec",-1,"vec",1),exprs) + if ~ok then + break, + end + sgn=sgn(:); + if (satur~=0&satur~=1&satur~=2) then + message("Do on overflow must be 0,1,2"); + ok=%f; + end + if size(sgn,1)==1 then + if sgn<1 then + message("Number of inputs must be > 0") + ok=%f + elseif sgn==1 then + in=-1;in2=-2 + sgn=[] + nout=1;nout2=1 + else + in=-ones(sgn,1); + in2=2*in + sgn=ones(sgn,1) + nout=-1;nout2=-2 + end + else + if ~and(abs(sgn)==1) then + message("Signs can only be +1 or -1") + ok=%f + else + in=-ones(size(sgn,1),1); + in2=2*in + nout=-1;nout2=-2 + end + end + it=Datatype*ones(1,size(in,1)); + ot=Datatype; + if Datatype==1 then + model.sim=list("summation",4) + elseif Datatype==2 then + model.sim=list("summation_z",4) + elseif ((Datatype<1) |(Datatype>8)) then + message("Datatype is not supported");ok=%f; + else + if satur==0 then + if Datatype==3 then + model.sim=list("summation_i32n",4) + elseif Datatype==4 then + model.sim=list("summation_i16n",4) + elseif Datatype==5 then + model.sim=list("summation_i8n",4) + elseif Datatype==6 then + model.sim=list("summation_ui32n",4) + elseif Datatype==7 then + model.sim=list("summation_ui16n",4) + elseif Datatype==8 then + model.sim=list("summation_ui8n",4) + end + elseif satur==1 then + if Datatype==3 then + model.sim=list("summation_i32s",4) + elseif Datatype==4 then + model.sim=list("summation_i16s",4) + elseif Datatype==5 then + model.sim=list("summation_i8s",4) + elseif Datatype==6 then + model.sim=list("summation_ui32s",4) + elseif Datatype==7 then + model.sim=list("summation_ui16s",4) + elseif Datatype==8 then + model.sim=list("summation_ui8s",4) + end + elseif satur==2 then + if Datatype==3 then + model.sim=list("summation_i32e",4) + elseif Datatype==4 then + model.sim=list("summation_i16e",4) + elseif Datatype==5 then + model.sim=list("summation_i8e",4) + elseif Datatype==6 then + model.sim=list("summation_ui32e",4) + elseif Datatype==7 then + model.sim=list("summation_ui16e",4) + elseif Datatype==8 then + model.sim=list("summation_ui8e",4) + end + end + end + if ok then + [model,graphics,ok]=set_io(model,graphics,... + list([in,in2],it),... + list([nout,nout2],ot),[],[]) + end + if ok then + model.rpar=satur; + model.ipar=sgn + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + sgn=[1;-1] + model=scicos_model() + model.sim=list("summation",4) + model.in=[-1;-1] + model.out=-1 + model.in2=[-2;-2] + model.out2=-2 + model.ipar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=sci2exp(sgn) + gr_i=[] + x=standard_define([2 3],model, exprs,gr_i) + end +endfunction diff --git a/macros/Linear/SUM_f.sci b/macros/Linear/SUM_f.sci new file mode 100644 index 00000000..40868bc9 --- /dev/null +++ b/macros/Linear/SUM_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]=SUM_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim=list("plusblk",2) + model.in=[-1;-1;-1] + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + + gr_i=[] + exprs=[] + x=standard_define([1 1],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/TCLSS.sci b/macros/Linear/TCLSS.sci new file mode 100644 index 00000000..7040b6ed --- /dev/null +++ b/macros/Linear/TCLSS.sci @@ -0,0 +1,115 @@ +// 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]=TCLSS(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,"*")==7 then + exprs=exprs([1:4,7]), + end //compatibility + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,[in;ms],out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:);model.rpar=rpar; + if D<>[] then + model.sim=list("tcslti4",4) + else + model.sim=list("tcsltj4",4); + end + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0;A=0;B=1;C=1;D=0; + in=1; + nx=size(x0,"*") + out=1 + + model=scicos_model() + model.sim=list("tcslti4",4) + model.in=[in;nx] + model.out=out + model.evtin=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/TCLSS_f.sci b/macros/Linear/TCLSS_f.sci new file mode 100644 index 00000000..8804969c --- /dev/null +++ b/macros/Linear/TCLSS_f.sci @@ -0,0 +1,115 @@ +// 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]=TCLSS_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,"*")==7 then + exprs=exprs([1:4,7]), + end //compatibility + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,[in;ms],out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:);model.rpar=rpar; + if D<>[] then + model.sim=list("tcslti",1) + else + model.sim=list("tcsltj",1); + end + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0;A=0;B=1;C=1;D=0; + in=1; + nx=size(x0,"*") + out=1 + + model=scicos_model() + model.sim=list("tcslti",1) + model.in=[in;nx] + model.out=out + model.evtin=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/TIME_DELAY.sci b/macros/Linear/TIME_DELAY.sci new file mode 100644 index 00000000..4ef254b9 --- /dev/null +++ b/macros/Linear/TIME_DELAY.sci @@ -0,0 +1,86 @@ +// 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_DELAY(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + nin=model.in(1) + + while %t do + [ok,T,init,N,exprs]=scicos_getvalue("Set delay parameters",.. + ["Delay";"initial input";"Buffer size"],.. + list("vec",1,"vec",1,"vec",1),.. + exprs); + if ~ok then + break, + end + if N<2 then + message("Buffer must be larger than 2") + ok=%f + end + if T<=0 then + message("Delay must be positive") + ok=%f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[-1],-1,[],[]) + end + if ok then + graphics.exprs=exprs; + model.rpar=[T;init]; + model.ipar=N + + model.dep_ut=[%f %t]; + // dp_t = %t + // updated for Scilab 5.5.1 + // see http://bugzilla.scilab.org/show_bug.cgi?id=13436 + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nin=1 + T=1 + init=0 + N=1024 + model=scicos_model() + model.sim=list("time_delay",4) + model.in=[nin] + model.out=nin + model.rpar=[T,init]; + model.ipar=N + model.blocktype="x" + model.dep_ut=[%f %t] + + exprs=[string(T);string(init);string(N)]; + gr_i=[] + x=standard_define([3.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/VARIABLE_DELAY.sci b/macros/Linear/VARIABLE_DELAY.sci new file mode 100644 index 00000000..c8055352 --- /dev/null +++ b/macros/Linear/VARIABLE_DELAY.sci @@ -0,0 +1,80 @@ +// 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]=VARIABLE_DELAY(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model;nin=model.in(1) + + while %t do + [ok,T,init,N,exprs]=scicos_getvalue("Set delay parameters",.. + ["Max delay";"initial input";"Buffer size"],.. + list("vec",1,"vec",1,"vec",1),.. + exprs); + if ~ok then + break, + end + if N<2 then + message("Buffer must be larger than 2") + ok=%f + end + if T<=0 then + message("Delay must be positive") + ok=%f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[-1;1],-1,[],[]) + end + if ok then + graphics.exprs=exprs; + model.rpar=[T;init]; + model.ipar=N + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nin=1 + T=1 + init=0 + N=1024 + model=scicos_model() + model.sim=list("variable_delay",4) + model.in=[nin;1] + model.out=nin + model.rpar=[T,init]; + model.ipar=N + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[string(T);string(init);string(N)]; + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/MatrixOp/CUMSUM.sci b/macros/MatrixOp/CUMSUM.sci new file mode 100644 index 00000000..0929fa71 --- /dev/null +++ b/macros/MatrixOp/CUMSUM.sci @@ -0,0 +1,116 @@ +// 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]=CUMSUM(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,decomptyp,lab]=scicos_getvalue("Set CUMSUM block parameters",["Datatype(1=real double 2=Complex)";"Sum along (0=the first non singleton dimension 1=Rows 2=Columns)"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + label=lab + if (typ==1) then + if (decomptyp==0) then + function_name="cumsum_m"; + out=[-1 -2] + elseif (decomptyp==1) then + function_name="cumsum_r"; + out=[-1 1]; + elseif (decomptyp==2) then + function_name="cumsum_c"; + out=[1 -2]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=1; + ot=1; + elseif (typ==2) then + if (decomptyp==0) then + function_name="cumsumz_m"; + elseif (decomptyp==1) then + function_name="cumsumz_r"; + elseif (decomptyp==2) then + function_name="cumsumz_c"; + else + message("decomposition type is not supported"); + ok=%f; + end + it=2; + ot=2 + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="cumsum_m"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(0)]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/EXTRACT.sci b/macros/MatrixOp/EXTRACT.sci new file mode 100644 index 00000000..a5aca77d --- /dev/null +++ b/macros/MatrixOp/EXTRACT.sci @@ -0,0 +1,115 @@ +// 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]=EXTRACT(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,a,b,exprs]=scicos_getvalue("Set EXTRACT Block",.. + ["Datatype (1=real double 2=Complex)";"Lines to extract";"Columns to extract"],list("vec",1,"mat",[1 -1],"mat",[1 -1]),label) + a=a(:); + b=b(:); + if ~ok then + break, + end + if (typ==1) then + function_name="extract"; + ot=1; + it=1; + elseif (typ==2) then + function_name="extractz"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + ma=size(a,1); + mb=size(b,1); + if (ma==0 | mb==0) then + message ("empty field"); + ok=%f; + end + for i=1:ma, + if (a(i)<=0) then + message("invalid index"); + ok=%f; + end; + end + for j=1:mb, + if(b(j)<=0) then + message("invalid index"); + ok=%f; + end; + end + model.ipar=[a;b;ma;mb]; + in=[model.in model.in2]; + out=[ma mb]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="extract"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[1 1 1 1] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp([1]);sci2exp([1])]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/EXTTRI.sci b/macros/MatrixOp/EXTTRI.sci new file mode 100644 index 00000000..2bfca711 --- /dev/null +++ b/macros/MatrixOp/EXTTRI.sci @@ -0,0 +1,113 @@ +// 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]=EXTTRI(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,decomptyp,lab]=scicos_getvalue("Set EXTTRI block parameters",["Datatype(1=real double 2=Complex)";"extraction type (1=lower 2=upper 3=diagonal)"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + label=lab + if (typ==1) then + if (decomptyp==1) then + function_name="exttril"; + elseif (decomptyp==2) then + function_name="exttriu"; + elseif (decomptyp==3) then + function_name="extdiag"; + else + message("decomposition type is not supported"); + ok=%f; + end + it=1; + ot=1; + elseif (typ==2) then + if (decomptyp==1) then + function_name="exttrilz"; + elseif (decomptyp==2) then + function_name="exttriuz"; + elseif (decomptyp==3) then + function_name="extdiagz"; + else + message("decomposition type is not supported"); + ok=%f; + end + it=2; + ot=2 + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2] + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="extrilz"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(1)]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATBKSL.sci b/macros/MatrixOp/MATBKSL.sci new file mode 100644 index 00000000..b7e70784 --- /dev/null +++ b/macros/MatrixOp/MATBKSL.sci @@ -0,0 +1,93 @@ +// 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]=MATBKSL(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set MATBKSL Block",.. + ["Datatype (1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_bksl"; + ot=1; + it=[1 1]; + elseif (typ==2) then + function_name="matz_bksl"; + ot=2; + it=[2 2]; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_bksl"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=[-1;-1] + model.in2=[-2;-3] + model.intyp=[1 1] + model.out=-2 + model.out2=-3 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATCATH.sci b/macros/MatrixOp/MATCATH.sci new file mode 100644 index 00000000..56f7d791 --- /dev/null +++ b/macros/MatrixOp/MATCATH.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]=MATCATH(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")>1 then //compatibility + label="size(evstr("+label(2)+"),''*'')"; + end + while %t do + [ok,nin,lab]=.. + scicos_getvalue("Set MATCATH block parameters",.. + ["Number of input"],.. + list("vec",1),label); + if ~ok then + break, + end + label=lab + in=[-1*(ones(nin,1)) -([2:nin+1]')]; + out=[-1 0] + it=-1*(ones(nin,1)); + ot=-1; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + if ok then + funtyp=4; + model.sim=list("mat_cath",funtyp) + graphics.exprs=label + arg1.graphics=graphics + arg1.model=model + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_cath"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=[-1;-1] + model.in2=[-2;-3] + model.intyp=[1 1] + model.out=-1 + model.out2=0 + model.outtyp=-1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(2)]; + gr_i=[] + x=standard_define([2 3],model,label,gr_i) + end +endfunction diff --git a/macros/MatrixOp/MATCATV.sci b/macros/MatrixOp/MATCATV.sci new file mode 100644 index 00000000..5a1d3849 --- /dev/null +++ b/macros/MatrixOp/MATCATV.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] = MATCATV(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")>1 then //compatibility + label="size(evstr("+label(2)+"),''*'')"; + end + while %t do + [ok,nin,lab]=.. + scicos_getvalue("Set MATCATV block parameters",.. + ["Number od inputs"],.. + list("vec",1),label) + if ~ok then + break, + end + label=lab + in=[-([2:nin+1]') -ones(nin,1)] + it= -ones(nin,1); + ot=-1; + out=[0 -1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + if ok then + funtyp=4; + model.sim=list("mat_catv",funtyp) + graphics.exprs=label + arg1.graphics=graphics + arg1.model=model + x=arg1 + break + end + end + case "define" then + l1=[2;2] + model=scicos_model() + function_name="mat_catv"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in2=[-1;-1] + model.in=[-2;-3] + model.intyp=[-1 -1] + model.out=0 + model.out2=-1 + model.outtyp=-1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(2)]; + gr_i=[] + x=standard_define([2 3],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATDET.sci b/macros/MatrixOp/MATDET.sci new file mode 100644 index 00000000..6763cb1e --- /dev/null +++ b/macros/MatrixOp/MATDET.sci @@ -0,0 +1,94 @@ +// 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]=MATDET(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set MATDET Block",.. + ["Datatype(1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_det"; + ot=1; + it=1; + elseif (typ==2) then + function_name="matz_det"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_det"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-1 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATDIAG.sci b/macros/MatrixOp/MATDIAG.sci new file mode 100644 index 00000000..edc7999b --- /dev/null +++ b/macros/MatrixOp/MATDIAG.sci @@ -0,0 +1,94 @@ +// 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]=MATDIAG(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set MATDIAG Block",.. + ["Datatype (1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_diag"; + ot=1; + it=1; + elseif (typ==2) then + function_name="matz_diag"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_diag"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=1 + model.intyp=1 + model.out=-1 + model.out2=-1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATDIV.sci b/macros/MatrixOp/MATDIV.sci new file mode 100644 index 00000000..a851aca5 --- /dev/null +++ b/macros/MatrixOp/MATDIV.sci @@ -0,0 +1,93 @@ +// 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]=MATDIV(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set MATDIV Block",.. + ["Datatype(1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_div"; + ot=1; + it=[1 1]; + elseif (typ==2) then + function_name="matz_div"; + ot=2; + it=[2 2]; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_div"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=[-1;-2] + model.in2=[-3;-3] + model.intyp=[1 1] + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATEIG.sci b/macros/MatrixOp/MATEIG.sci new file mode 100644 index 00000000..50c45f6e --- /dev/null +++ b/macros/MatrixOp/MATEIG.sci @@ -0,0 +1,114 @@ +// 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]=MATEIG(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,decomptyp,lab]=scicos_getvalue("Set MATEIG block parameters",["Datatype(1=real double 2=Complex)";"decomposition type (1=eig values 2=eig values+eig vectors"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + label=lab + if (typ==1) then + if (decomptyp==1) then + function_name="mat_vps"; + out=[-1 1]; + ot=2; + elseif (decomptyp==2) then + function_name="mat_vpv"; + out=[-1 -1;-1 -1]; + ot=[2 2]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=1; + elseif (typ==2) then + if (decomptyp==1) then + function_name="matz_vps"; + out=[-1 1]; + ot=2; + elseif (decomptyp==2) then + function_name="matz_vpv"; + out=[-1 -1;-1 -1]; + ot=[2 2]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[-1 -1]; + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_vps"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-1 + model.intyp=1 + model.out=-1 + model.out2=1 + model.outtyp=2 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATEXPM.sci b/macros/MatrixOp/MATEXPM.sci new file mode 100644 index 00000000..7b8fb166 --- /dev/null +++ b/macros/MatrixOp/MATEXPM.sci @@ -0,0 +1,93 @@ +// 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]=MATEXPM(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set EXPM Block",.. + ["Datatype(1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_expm"; + ot=1; + it=1; + elseif (typ==2) then + function_name="matz_expm"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics;arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_expm"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-1 + model.intyp=1 + model.out=-1 + model.out2=-1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATINV.sci b/macros/MatrixOp/MATINV.sci new file mode 100644 index 00000000..7ea7342e --- /dev/null +++ b/macros/MatrixOp/MATINV.sci @@ -0,0 +1,94 @@ +// 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]=MATINV(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set MATINV Block",.. + ["Datatype(1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_inv"; + ot=1; + it=1; + elseif (typ==2) then + function_name="matz_inv"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_inv"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-1 + model.intyp=1 + model.out=-1 + model.out2=-1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATLU.sci b/macros/MatrixOp/MATLU.sci new file mode 100644 index 00000000..ebb94d71 --- /dev/null +++ b/macros/MatrixOp/MATLU.sci @@ -0,0 +1,94 @@ +// 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]=MATLU(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,lab]=.. + scicos_getvalue("Set MATLU block parameters",["Datatype(1=real double 2=Complex)"],list("vec",1),label); + if ~ok then + break, + end + if (typ==1) then + function_name="mat_lu"; + ot=[1 1]; + it=1; + elseif (typ==2) then + function_name="matz_lu"; + ot=[2 2]; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list([model.in model.in2],it),list([model.out model.out2],ot),[],[]) + end + if ok then + funtyp=4; + model.sim=list(function_name,funtyp) + graphics.exprs=lab; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + model=scicos_model() + function_name="mat_lu"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-1 + model.intyp=1 + //model.out=[siz(1);min(siz)] + //model.out2=[min(siz);siz(2)] + model.out=[-1;-1] + model.out2=[-1;-1] + model.outtyp=[1 1] + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=sci2exp(1); + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATMAGPHI.sci b/macros/MatrixOp/MATMAGPHI.sci new file mode 100644 index 00000000..0e4ed4de --- /dev/null +++ b/macros/MatrixOp/MATMAGPHI.sci @@ -0,0 +1,96 @@ +// 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]=MATMAGPHI(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,decomptyp,lab]=scicos_getvalue("Set MATMAGPHI block parameters",["decomposition type (1=Complex2MAG&PHI 2=MAG&PHI2Complex)"],list("vec",1),label) + if ~ok then + break, + end + label=lab + if (decomptyp==1) then + function_name="matz_abs"; + in=[-1 -2]; + it=2; + out=[-1 -2;-1 -2]; + ot=[1 1]; + elseif (decomptyp==2) then + function_name="matz_absc"; + in=[-1 -2;-1 -2]; + it=[1 1]; + out=[-1 -2]; + ot=2; + else + message("decomposition type is not supported"); + ok=%f; + end + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="matz_abs"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=-1 + model.in2=-2 + model.intyp=2 + model.out=[-1;-1] + model.out2=[-2;-2] + model.outtyp=[1 1] + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATMUL.sci b/macros/MatrixOp/MATMUL.sci new file mode 100644 index 00000000..3247cedb --- /dev/null +++ b/macros/MatrixOp/MATMUL.sci @@ -0,0 +1,182 @@ +// 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] = MATMUL(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=x.graphics; + label=graphics.exprs + model=x.model; + if model.ipar==[] then + model.ipar=1; + end + if size(label,"*")==1 then + label(2)=sci2exp(1), + end //compatiblity + if size(label,"*")==2 then + label(3)=sci2exp(1); + end //compatibility + while %t do + [ok,dtype,rule,np,exprs]=scicos_getvalue(["Set MATMUL parameter"; + "For the Multipication rule:"; + " 1= Matrix by Matrix"; + " 2= Matrix by Matrix element wise "; + " 3= Matrix by Scalar"; + "In the third case the second input will be the scalar"],.. + ["Datatype(1=real double 2=Complex 3=int32 ...)"; + "Multiplication rule"; + "Do on Overflow(0=Nothing 1=Saturate 2=Error)"],list("vec",1,"vec",1,"vec",1),label) + if ~ok then + break, + end + rule=int(rule) + if (dtype<1|dtype>8) then + message("type is not supported"); + ok=%f; + end + if (rule<1|rule>3) then + message("Multiplication rule must be only 1,2 or 3"); + ok=%f; + end + if (dtype==1|dtype==2) then + np=0; + end + TABMIN=[0;0;-(2^31);-(2^15);-(2^7);0;0;0] + TABMAX=[0;0;(2^31)-1;(2^15)-1;(2^7)-1;(2^32)-1;(2^16)-1;(2^8)-1] + if rule==2 then + if np==0 then + model.sim=list("matmul2_m",4) + elseif np==1 then + model.sim=list("matmul2_s",4) + else + model.sim=list("matmul2_e",4) + end + elseif rule==3 then + if np==0 then + model.sim=list("matbyscal",4) + elseif np==1 then + model.sim=list("matbyscal_s",4) + else + model.sim=list("matbyscal_e",4) + end + else + if (dtype==1) then + model.sim=list("matmul_m",4); + elseif (dtype==2) then + model.sim=list("matzmul_m",4); + elseif dtype==3 then + if np==0 then + model.sim=list("matmul_i32n",4) + elseif np==1 then + model.sim=list("matmul_i32s",4) + else + model.sim=list("matmul_i32e",4) + end + elseif dtype==4 then + if np==0 then + model.sim=list("matmul_i16n",4) + elseif np==1 then + model.sim=list("matmul_i16s",4) + else + model.sim=list("matmul_i16e",4) + end + elseif dtype==5 then + if np==0 then + model.sim=list("matmul_i8n",4) + elseif np==1 then + model.sim=list("matmul_i8s",4) + else + model.sim=list("matmul_i8e",4) + end + elseif dtype==6 then + if np==0 then + model.sim=list("matmul_ui32n",4) + elseif np==1 then + model.sim=list("matmul_ui32s",4) + else + model.sim=list("matmul_ui32e",4) + end + elseif dtype==7 then + if np==0 then + model.sim=list("matmul_ui16n",4) + elseif np==1 then + model.sim=list("matmul_ui16s",4) + else + model.sim=list("matmul_ui16e",4) + end + elseif dtype==8 then + if np==0 then + model.sim=list("matmul_ui8n",4) + elseif np==1 then + model.sim=list("matmul_ui8s",4) + else + model.sim=list("matmul_ui8e",4) + end + end + end + kmin=TABMIN(dtype);kmax=TABMAX(dtype) + it=dtype*ones(1,2); + ot=dtype + if rule==1 then + in=[-1 -2;-2 -3]; + out=[-1 -3]; + elseif rule==2 then + in=[-1 -2;-1 -2] + out=[-1 -2] + else + in=[-1 -2;1 1] + out=[-1 -2] + end + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + if ok then + //if model.ipar<>np then needcompile=1;end + label=exprs; + model.ipar=rule + model.rpar=[kmin;kmax] + graphics.exprs=label; + x.graphics=graphics; + x.model=model; + arg1=x + break; + end + end + //needcompile=resume(needcompile) + case "define" then + model=scicos_model() + model.sim=list("matmul_m",4) + + model.in=[-1;-2] + model.in2=[-2;-3] + model.out=-1 + model.out2=-3 + model.dep_ut=[%t %f] + + model.ipar=1 + label=[sci2exp(model.ipar)] + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATPINV.sci b/macros/MatrixOp/MATPINV.sci new file mode 100644 index 00000000..435820d0 --- /dev/null +++ b/macros/MatrixOp/MATPINV.sci @@ -0,0 +1,94 @@ +// 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]=MATPINV(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,exprs]=scicos_getvalue("Set MATPINV Block",.. + ["Datatype(1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_pinv"; + ot=1; + it=1; + elseif (typ==2) then + function_name="matz_pinv"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_pinv"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=-2 + model.out2=-1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATRESH.sci b/macros/MatrixOp/MATRESH.sci new file mode 100644 index 00000000..7316cbc9 --- /dev/null +++ b/macros/MatrixOp/MATRESH.sci @@ -0,0 +1,122 @@ +// 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]=MATRESH(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,l1,out,lab]=.. + scicos_getvalue("Set MATRESH block parameters",.. + ["Datatype(1=real double 2=Complex)" + "input size"; + "output size desired"],.. + list("vec",-1,"vec",-1,"vec",-1),label) + if ~ok then + break, + end + nout=size(out) + nin=size(l1) + if nout==0 then + message("output must have at least one element"); + ok=%f; + end + if nin==0 then + message("input must have at least one element"); + ok=%f; + end + if ok then + if ((out(1)>(l1(1)*l1(2)))) then + message("the first dimension of the output is too big"); + ok=%f; + end + if ((out(2)>(l1(1)*l1(2)))) then + message("the second dimension of the output is too big"); + ok=%f; + end + if (((out(2)*out(1))>(l1(1)*l1(2)))) then + message("the dimensions of the output are too big"); + ok=%f; + end + end + if (typ==1) then + function_name="mat_reshape"; + ot=1; + it=1; + elseif (typ==2) then + function_name="matz_reshape"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + label=lab + [model,graphics,ok]=set_io(model,graphics,list(l1,it),list(out,ot),[],[]) + end + if ok then + funtyp=4; + model.sim=list(function_name,funtyp) + graphics.exprs=label + arg1.graphics=graphics + arg1.model=model + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="mat_reshape"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp([1,1]);sci2exp([1,1])]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATSING.sci b/macros/MatrixOp/MATSING.sci new file mode 100644 index 00000000..659f8f57 --- /dev/null +++ b/macros/MatrixOp/MATSING.sci @@ -0,0 +1,117 @@ +// 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]=MATSING(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,decomptyp,lab]=scicos_getvalue("Set MATSVD block parameters",["Datatype(1=real double 2=Complex)";"decomposition type (1=singular values 2=sing values+matrix U & V)"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + label=lab + if (typ==1) then + if (decomptyp==1) then + function_name="mat_sing"; + in=[-1 -2]; + out=[-1 1]; + ot=1; + elseif (decomptyp==2) then + function_name="mat_svd"; + in=[-1 -2]; + out=[-1 -1;-1 -2;-2 -2]; + ot=[1 1 1]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=1; + elseif (typ==2) then + if (decomptyp==1) then + function_name="matz_sing"; + in=[-1 -2]; + out=[-1 1]; + ot=1; + elseif (decomptyp==2) then + function_name="matz_svd"; + in=[-1 -2]; + out=[-1 -1;-1 -2;-2 -2]; + ot=[2 1 2]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_sing"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=-1 + model.out2=1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATSUM.sci b/macros/MatrixOp/MATSUM.sci new file mode 100644 index 00000000..137dd048 --- /dev/null +++ b/macros/MatrixOp/MATSUM.sci @@ -0,0 +1,118 @@ +// 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]=MATSUM(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,decomptyp,lab]=scicos_getvalue("Set MATSUM block parameters",["Datatype(1=real double 2=Complex)";"Sum along (0=all 1=lines 2=Columns)"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + label=lab + if (typ==1) then + if (decomptyp==0) then + function_name="mat_sum"; + out=[1 1]; + elseif (decomptyp==2) then + function_name="mat_suml"; + out=[-1 1]; + elseif (decomptyp==1) then + function_name="mat_sumc"; + out=[1 -2]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=1; + ot=1; + elseif (typ==2) then + if (decomptyp==0) then + function_name="matz_sum"; + out=[1 1]; + elseif (decomptyp==2) then + function_name="matz_suml"; + out=[-1 1]; + elseif (decomptyp==1) then + function_name="matz_sumc"; + out=[1 -2]; + else + message("decomposition type is not supported"); + ok=%f; + end + it=2; + ot=2 + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="mat_sum"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(0)]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATTRAN.sci b/macros/MatrixOp/MATTRAN.sci new file mode 100644 index 00000000..7db4d6e5 --- /dev/null +++ b/macros/MatrixOp/MATTRAN.sci @@ -0,0 +1,88 @@ +// 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]=MATTRAN(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + // if size(label,'*')==14 then label(9)=[],end //compatiblity + if size(label,"*")==1 then + label(2)=sci2exp(1), + end + while %t do + [ok,typ,rule,exprs]=scicos_getvalue("Set MATTRAN Block",.. + ["Datatype(1=real double 2=Complex)";"rule (1=.'' 2='')"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mattran_m"; + ot=1; + it=1; + elseif (typ==2) then + if rule==1 then + function_name="matztran_m"; + else + function_name="mathermit_m"; + end + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + model.sim=list("mattran_m",4) + + model.in=-1 + model.in2=-2 + model.out=-2 + model.out2=-1 + model.dep_ut=[%t %f] + + label=[sci2exp(1)] + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATZCONJ.sci b/macros/MatrixOp/MATZCONJ.sci new file mode 100644 index 00000000..fe2478a9 --- /dev/null +++ b/macros/MatrixOp/MATZCONJ.sci @@ -0,0 +1,55 @@ +// 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]=MATZCONJ(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + model=scicos_model() + function_name="matz_conj"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=-1 + model.in2=-2 + model.intyp=2 + model.out=-1 + model.out2=-2 + model.outtyp=2 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/MATZREIM.sci b/macros/MatrixOp/MATZREIM.sci new file mode 100644 index 00000000..98f1a5e4 --- /dev/null +++ b/macros/MatrixOp/MATZREIM.sci @@ -0,0 +1,97 @@ +// 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]=MATZREIM(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,decomptyp,lab]=scicos_getvalue("Set MATZREIM block parameters",["decomposition type (1=Complex2Real&Imag 2=Real&Imag2Complex)"],list("vec",1),label) + if ~ok then + break, + end + label=lab + if (decomptyp==1) then + function_name="matz_reim"; + in=[-1 -2]; + it=2; + out=[-1 -2;-1 -2]; + ot=[1 1]; + elseif (decomptyp==2) then + function_name="matz_reimc"; + in=[-1 -2;-1 -2]; + it=[1 1]; + out=[-1 -2]; + ot=2; + else + message("decomposition type is not supported"); + ok=%f; + end + funtyp=4; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + model.sim=list(function_name,funtyp); + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="matz_reim"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=-1 + model.in2=-2 + model.intyp=2 + model.out=[-1;-1] + model.out2=[-2;-2] + model.outtyp=[1 1] + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + + label=sci2exp(1) + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/RICC.sci b/macros/MatrixOp/RICC.sci new file mode 100644 index 00000000..fba5257d --- /dev/null +++ b/macros/MatrixOp/RICC.sci @@ -0,0 +1,80 @@ +// 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]=RICC(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,tpe,mod,exprs]=scicos_getvalue("Set RICC Block",["Type (1=Cont 2=Disc)";"Model(1=Schr 2=sign(cont) inv(disc))"],list("vec",1,"vec",1),label) + if ~ok then + break, + end + in=[model.in model.in2]; + out=[model.out model.out2]; + it=[1 1 1] + ot=1 + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + if ok then + model.ipar=[tpe;mod] + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="ricc_m"; + funtyp=4; + model.sim=list(function_name,funtyp) + model.in=[-1;-1;-1] + model.in2=[-1;-1;-1] + model.intyp=[1 1 1] + model.out=-1 + model.out2=-1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[1;1] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction diff --git a/macros/MatrixOp/ROOTCOEF.sci b/macros/MatrixOp/ROOTCOEF.sci new file mode 100644 index 00000000..329065df --- /dev/null +++ b/macros/MatrixOp/ROOTCOEF.sci @@ -0,0 +1,94 @@ +// 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]=ROOTCOEF(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,typ,inp,exprs]=scicos_getvalue("Set ROOTCOEF Block",.. + ["Datatype(1=real double 2=Complex)";"input row size";],list("vec",1,"vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="root_coef"; + ot=1; + it=1; + elseif (typ==2) then + function_name="rootz_coef"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + in=[inp model.in2]; + out=[inp+1 model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="root_coef"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=1 + model.intyp=1 + model.out=-2 + model.out2=1 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(1)]; + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/SQRT.sci b/macros/MatrixOp/SQRT.sci new file mode 100644 index 00000000..9bc22b25 --- /dev/null +++ b/macros/MatrixOp/SQRT.sci @@ -0,0 +1,80 @@ +// 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]=SQRT(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + while %t do + [ok,typ,exprs]=scicos_getvalue("Set SQRT Block",.. + ["Datatype(1=real double 2=Complex)"],list("vec",1),label) + if ~ok then + break, + end + if (typ==1) then + function_name="mat_sqrt"; + elseif (typ==2) then + function_name="matz_sqrt"; + else + message("type is not supported"); + ok=%f; + end + it=typ + ot=typ + in=[model.in model.in2]; + out=[model.out model.out2]; + funtyp=4; + if ok then + label=exprs; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + model.sim=list("mat_sqrt",4) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.outtyp=1 + model.out=-1 + model.out2=-2 + model.dep_ut=[%t %f] + + label=[sci2exp(1)] + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/MatrixOp/SUBMAT.sci b/macros/MatrixOp/SUBMAT.sci new file mode 100644 index 00000000..cadaa509 --- /dev/null +++ b/macros/MatrixOp/SUBMAT.sci @@ -0,0 +1,117 @@ +// 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]=SUBMAT(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + // if size(label,'*')==14 then label(9)=[],end + if size(label,"*")==5 then + label(6)=sci2exp([1 1]), + end //compatiblity + while %t do + [ok,typ,a,b,c,d,inp,exprs]=scicos_getvalue("Set SUBMAT Block",.. + ["Datatype (1=real double 2=Complex)";"Starting Row Index";"Ending Row Index";"Starting Column Index";"Ending Column Index";"Input Dimensions"],list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",2),label) + if ~ok then + break, + end + if (typ==1) then + function_name="submat"; + ot=1; + it=1; + elseif (typ==2) then + function_name="submatz"; + ot=2; + it=2; + else + message("Datatype is not supported"); + ok=%f; + end + if (a<=0) | (b<=0) | (c<=0) | (d<=0) then + message("invalid index"); + ok=%f; + end + if b<a then + message("ending row must be greater than starting row"); + ok=%f; + end + if d<c then + message("ending column must be greater than starting column"); + ok=%f; + end + if b>inp(1) then + message ("index of ending row is out of range"); + ok=%f; + end + if d>inp(2) then + message ("index of ending column is out of range"); + ok=%f; + end + model.ipar=[a;b;c;d]; + in=[inp(1) inp(2)]; + out=[(b-a)+1 (d-c)+1]; + funtyp=4; + label=exprs; + if ok then + + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + model.sim=list(function_name,funtyp); + graphics.exprs=label; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + case "define" then + model=scicos_model() + function_name="submat"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=-1 + model.in2=-2 + model.intyp=1 + model.out=-1 + model.out2=-2 + model.outtyp=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[1;1;1;1] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[sci2exp(1);sci2exp(1);sci2exp(1);sci2exp(1);sci2exp(1)]; + gr_i=[] + x=standard_define([2.5 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/AUTOMAT.sci b/macros/Misc/AUTOMAT.sci new file mode 100644 index 00000000..6ef82717 --- /dev/null +++ b/macros/Misc/AUTOMAT.sci @@ -0,0 +1,166 @@ +// 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]=AUTOMAT(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + ipar=model.ipar; + NMode=ipar(1) + NX=ipar(3) + while %t do + CX="C1"; + MSG0="''Jump from Mode "; + MSG2=":[..;M_final(Guard=In("; + MSG3=").i);..]''" + MSG=MSG0+"1"+MSG2+"1"+MSG3; + VEC="''mat'',[-1,1]"; + for i=2:NMode + CX=CX+","+"C"+string(i); + MSG=MSG+";"+MSG0+string(i)+MSG2+string(i)+MSG3; + VEC=VEC+","+"''mat'',[-1,1]"; + end + //=========================================== + GTV="[ok,NMode,Minitial,NX,X0,XP,"+CX+",exprs]=scicos_getvalue(''Set Finite state machine model'',.. + [''Number (finite-state) Modes'';''Initial Mode'';''Number of continuous-time states'';''Continuous-time states intial values'';''Xproperties of continuous-time states in each Mode'';"+MSG+"],.. + list(''vec'',1,''vec'',1,''vec'',1,''mat'',[-1,-1],''mat'',[-1,-1],"+VEC+"),exprs)" + execstr(GTV); + if ~ok then + break, + end + NMode_old=size(exprs,"*")-5;//-number of fileds before CX + ModifEncore=%f; + + if (NMode_old>NMode) then + exprs(NMode+6:NMode_old+5)=[];// number of fileds + ModifEncore=%t; + end + if (NMode_old<NMode) then + exprs(NMode_old+6:NMode+5)=exprs(NMode_old+4);// number of fileds + ModifEncore=%t; + end + if (NX<>size(X0,"*")) then + messagebox("the size of intial continuous-time states should be NX="+string(NX),"modal","error"); + ModifEncore=%t; + end + + [rXP,cXP]=size(XP) + if cXP<>NX then + messagebox("Xproperty matrix is not valid: it should have NX="+string(NX)+" columns","modal","error"); + ModifEncore=%t; + elseif ((rXP<>NMode) & (rXP>1)) + messagebox("Xproperty matrix is not valid: it should have NMode="+string(NMode)+" or 1 row(s)","modal","error"); + ModifEncore=%t; + elseif (rXP==1) + for i=1:NMode-1 + XP=[XP;XP(1,:)];// xproprties are identical in modes. + end + end + + if (NMode_old==NMode)&(~ModifEncore) then + XP=matrix(XP',NMode*NX,1);// put XP in column vector to be stocked in ipar + ipar=[NMode;Minitial;NX;XP]; + rpar=matrix(X0,NX,1);// put X0 in a column vector; + INP=ones(NMode,1); + if NX>0 then + OUT=[2;2*NX]; + else + OUT=[2]; + end + MaxModes=1; + nzcross=0; + for i=1:NMode + Ci=evstr(exprs(5+i));// number of fileds + ipar=[ipar;Ci]; + INP(i,1)=2*NX+length(Ci); + if (nzcross<length(Ci)) then + nzcross=length(Ci); + end + if (MaxModes<max(Ci)) then + MaxModes=max(Ci); + imax=i; + end + end + + if MaxModes>NMode then + messagebox(["Number of Modes should be "+string(MaxModes);.. + "A destination Mode in Mode#"+string(imax)+"''s targets is invalid!"],"modal","error"); + ModifEncore=%t; + end + if MaxModes<NMode then + messagebox(["There is an unused Mode or the Number of Modes should be "+string(MaxModes)],"modal","error"); + ModifEncore=%t; + end + end + if ~ModifEncore then + [model,graphics,ok]=check_io(model,graphics,INP,OUT,[],[1]) + if ~ok then + break, + end + model.nzcross=nzcross; + model.state=ones(2*NX,1); + graphics.gr_i(1)(1)="txt=[''Automaton'';''nM="+string(NMode)+",nX="+string(NX)+"''];" + graphics.exprs=exprs; + x.graphics=graphics; + model.ipar=ipar; + model.rpar=rpar; + x.model=model; + break + end + end;//while + //----------------------------------------------- + case "define" then + NMode=2; //number of Modes + Minitial=1; //initial Mode + NX=1; //number of states (NX is identical for all Modes) + X0=[0.0] + XP=[1;1]//xproperties for each Mode + C1=[2];//final_Mode after Jump du to in(2*Nx+i) + C2=[1]; + exprs=[string(NMode);string(Minitial);string(NX);sci2exp(X0);sci2exp(XP);sci2exp(C1);sci2exp(C2)]; + ipar=[NMode;Minitial;NX;XP;C1;C2]; + rpar=[X0]; + + model=scicos_model() + model.sim=list("automat",10004) + model.in=[2*NX+1;2*NX+1];//number of Modes + model.out=[2;2*NX];// [Mode;(x,xd)] + model.state=ones(2*NX,1);// [x;xd] + model.nzcross=1;// max(taille_zc(Mode_i)) + model.blocktype="c"; + model.evtout=1 + model.firing=-1; + model.dep_ut=[%f %t]; + model.ipar=ipar; + model.rpar=rpar; + + gr_i=[] + + x=standard_define([4 2],model,exprs,gr_i); + end +endfunction + diff --git a/macros/Misc/BACKLASH.sci b/macros/Misc/BACKLASH.sci new file mode 100644 index 00000000..9460d57f --- /dev/null +++ b/macros/Misc/BACKLASH.sci @@ -0,0 +1,73 @@ +// 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]=BACKLASH(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + rpar=model.rpar + while %t do + [ok,ini,gap,zcr,exprs]=scicos_getvalue("Set backlash parameters",.. + ["initial output"; + "gap";"use zero-crossing (0:no, 1:yes)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + + + if ~ok then + break, + end + if ok then + graphics.exprs=exprs; + rpar(1)=ini; + rpar(2)=gap; + if zcr<>0 then + model.nzcross=2 + else + model.nzcross=0 + end + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + exprs=["0";"1";"1"] + model=scicos_model() + model.sim=list("backlash",4) + model.in=1 + model.out=1 + model.rpar=[0;1] + model.nzcross=2; + model.blocktype="c" + model.dep_ut=[%t %f] + + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/BOUNCE.sci b/macros/Misc/BOUNCE.sci new file mode 100644 index 00000000..a8ffb2d5 --- /dev/null +++ b/macros/Misc/BOUNCE.sci @@ -0,0 +1,130 @@ +// 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]=BOUNCE(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,"*")<9 then + exprs(8)="9.81"; + exprs(9)="0"; + end + while %t do + [ok,rpar1,rpar2,walls,xt,xd,y,yd,g,C,exprs]=scicos_getvalue(["Set Bounce Block"],.. + ["Mass";"Radius";"[xmin,xmax,ymin,ymax]";"xpos";"xdpos";"ypos";.. + "ydpos";"g (gravity)";"C (aerodynamic coeff"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + xt=xt(:); + y=y(:); + xd=xd(:); + yd=yd(:); + rpar1=rpar1(:); + rpar2=rpar2(:); + n=size(xt,"*"); + walls=walls(:); + if walls(1)>walls(2) then + walls=walls([2,1]); + end + if walls(3)>walls(3) then + walls=walls([3,4]); + end + if n<>size(y,"*")|n<>size(rpar1,"*")|n<>size(rpar2,"*")|.. + n<>size(xd,"*")|n<>size(yd,"*") then + message("All vectors must have equal size") + ok=%f + elseif ~(min([rpar1;rpar2])>0) then + message("Mass and radius must be >0") + ok=%f + end + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,[],[n,n],[],[]) + if ok then + k=1;ipar=[]; + for i=1:n + for j=i+1:n + ipar(k)=i + k=k+1 + ipar(k)=j + k=k+1 + end + end + model.rpar=[rpar1;rpar2;walls;g;C]; + model.ipar=ipar; + state=[xt,xd,y,yd]; + state=state'; + model.state=state(:) + model.nzcross=n*(n-1)/2+4*n; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + n=2 + k=1;ipar=[]; + for i=1:n + for j=i+1:n + ipar(k)=i + k=k+1 + ipar(k)=j + k=k+1 + end + end + walls=[0;5;0;5] + x=[2;2.5]; + xd=[0;0]; + y=[3;5]; + yd=[0;0]; + g=9.81; + C=0 + rpar1=ones(n,1); + rpar2=rpar1; + state=[x,xd,y,yd]; + state=state'; + model=scicos_model() + model.sim=list("bounce_ball",4) + model.in=[] + model.out=[n;n] + model.state=state(:) + model.rpar=[rpar1;rpar2;walls;g;C]; + model.ipar=ipar; + model.nzcross=n*(n-1)/2+4*n; + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(rpar1));strcat(sci2exp(rpar2));strcat(sci2exp(walls));strcat(sci2exp(x));strcat(sci2exp(xd));strcat(sci2exp(y));strcat(sci2exp(yd))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/BOUNCEXY.sci b/macros/Misc/BOUNCEXY.sci new file mode 100644 index 00000000..50e79eea --- /dev/null +++ b/macros/Misc/BOUNCEXY.sci @@ -0,0 +1,132 @@ +// 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]=BOUNCEXY(job,arg1,arg2) + //Scicos 2D animated visualization block + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + dstate=model.dstate + while %t do + [ok,clrs,siz,win,imode,xmin,xmax,ymin,ymax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["colors"; + "radii"; + "window number (-1 for automatic)"; + "animation mode (0,1)"; + "Xmin"; + "Xmax"; + "Ymin"; + "Ymax"; + ],.. + list("vec",-1,"vec",-1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + + mess=[] + if size(clrs,"*")<>size(siz,"*") then + mess=[mess;"colors and radii must have equal size (number of balls)";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + rpar=[xmin;xmax;ymin;ymax] + ipar=[win;imode;clrs(:)] + z=[] + for i=1:size(clrs,"*") + z(6*(i-1)+1)=0 + z(6*(i-1)+2)=0 + z(6*(i-1)+3)=2*siz(i) + z(6*(i-1)+4)=2*siz(i) + z(6*(i-1)+5)=0.000 + z(6*(i-1)+6)=64.0*360.000; + end + model.dstate=z; + model.rpar=rpar;model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics;x.model=model + break + end + end + case "define" then + win=-1; + imode=1; + clrs=[1;2]; + siz=[1;1] + xmin=-5; + xmax=5; + ymin=0; + ymax=15 + + model=scicos_model() + model.sim=list("bouncexy",4) + model.in=[-1;-1] + model.in2=[1;1] + model.intyp = [1;1] + model.evtin=1 + z=[] + for i=1:size(clrs,"*") + z(6*(i-1)+1)=0 + z(6*(i-1)+2)=0 + z(6*(i-1)+3)=2*siz(i) + z(6*(i-1)+4)=2*siz(i) + z(6*(i-1)+5)=0.000 + z(6*(i-1)+6)=64.0*360.000; + end + model.dstate=z + model.rpar=[xmin;xmax;ymin;ymax] + model.ipar=[win;imode;clrs(:)] + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=[strcat(sci2exp(clrs)); + strcat(sci2exp(siz)); + strcat(sci2exp(win)); + strcat(sci2exp(1)); + strcat(sci2exp(xmin)); + strcat(sci2exp(xmax)); + strcat(sci2exp(ymin)); + strcat(sci2exp(ymax))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/BPLATFORM.sci b/macros/Misc/BPLATFORM.sci new file mode 100644 index 00000000..bc753479 --- /dev/null +++ b/macros/Misc/BPLATFORM.sci @@ -0,0 +1,89 @@ +// 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]=BPLATFORM(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 + while %t do + [ok,plen,csiz,phi,xmin,xmax,ymin,ymax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["pendulum length";"cart size (square side)";"slope"; + "Xmin";"Xmax"; "Ymin"; "Ymax"; ],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + mess=[] + if plen<=0|csiz<=0 then + mess=[mess;"Pendulum length and cart size must be positive.";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.rpar=rpar; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + plen=2; + csiz=2; + phi=0; + xmin=-5; + xmax=5; + ymin=0; + ymax=15 + + model=scicos_model() + model.sim=list("bplatform2",5) + model.in=[1;1] + model.evtin=1 + model.dstate=0 + model.rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(model.rpar) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Misc/CBLOCK.sci b/macros/Misc/CBLOCK.sci new file mode 100644 index 00000000..7cd31e65 --- /dev/null +++ b/macros/Misc/CBLOCK.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]=CBLOCK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + while %t do + [ok,function_name,impli,i,o,ci,co,xx,ng,z,rpar,ipar,auto0,depu,dept,lab]=.. + scicos_getvalue("Set C-Block2 block parameters",.. + ["simulation function"; + "is block implicit? (y,n)"; + "input ports sizes"; + "output ports sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "number of zero crossing surfaces"; + "initial discrete state"; + "Real parameters vector"; + "Integer parameters vector"; + "initial firing vector (<0 for no firing)"; + "direct feedthrough (y or n)"; + "time dependence (y or n)"],.. + list("str",1,"str",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec","sum(%6)",.. + "str",1,"str",1),label(1)) + if ~ok then + break, + end + label(1)=lab + funam=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + nx=size(xx,1); + nz=size(z,1); + i=int(i(:)); + o=int(o(:)); + nout=size(o,1); + ci=int(ci(:)); + nevin=size(ci,1); + co=int(co(:)); + nevout=size(co,1); + if part(impli,1)=="y" then + funtyp=12004, + else + funtyp=2004, + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + + + if funam==" " then + break, + end + + if model.sim(1)<>funam|sign(size(model.state,"*"))<>sign(nx)|.. + sign(size(model.dstate,"*"))<>sign(nz)|model.nzcross<>ng|.. + sign(size(model.evtout,"*"))<>sign(nevout) then + tt=[] + end + + tt=label(2); + while %t + + [ok,tt,cancel]=CFORTR2(funam,tt) + if ~ok then + if cancel then + break, + end + else + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + if ok then + model.sim=list(funam,funtyp) + model.in=i + model.out=o + model.evtin=ci + model.evtout=co + model.state=xx + model.dstate=z + model.rpar=rpar + model.ipar=ipar + model.firing=auto0 + model.dep_ut=dep_ut + model.nzcross=ng + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + end + if ok|cancel then + break, + end + end + + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + ipar=[] + funam="toto" + ng=0 + + model=scicos_model() + model.sim=list(" ",2004) + model.in=in + model.out=out + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=ipar + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + model.nzcross=ng + + label=list([funam,"n",sci2exp(in),sci2exp(out),sci2exp(clkin),sci2exp(clkout),.. + sci2exp(x0),sci2exp(0),sci2exp(z0),sci2exp(rpar),sci2exp(ipar),.. + sci2exp(auto),"y","n"]',[]) + + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction + + diff --git a/macros/Misc/CBLOCK4.sci b/macros/Misc/CBLOCK4.sci new file mode 100644 index 00000000..cb1fecaa --- /dev/null +++ b/macros/Misc/CBLOCK4.sci @@ -0,0 +1,196 @@ +// 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]=CBLOCK4(job,arg1,arg2) + // + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + + while %t do + [ok,function_name,impli,in,it,out,ot,ci,co,xx,z,oz,... + rpar,ipar,opar,nmode,nzcr,auto0,depu,dept,lab]=.. + scicos_getvalue("Set C-Block4 block parameters",.. + ["Simulation function"; + "Is block implicit? (y,n)"; + "Input ports sizes"; + "Input ports type"; + "Output port sizes"; + "Output ports type"; + "Input event ports sizes"; + "Output events ports sizes"; + "Initial continuous state"; + "Initial discrete state"; + "Initial object state"; + "Real parameters vector"; + "Integer parameters vector"; + "Object parameters list"; + "Number of modes"; + "Number of zero crossings"; + "Initial firing vector (<0 for no firing)"; + "Direct feedthrough (y or n)"; + "Time dependence (y or n)"],.. + list("str",1,"str",1,"mat",[-1 2],"vec",-1,"mat",[-1 2],"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"lis",-1,"vec",-1,"vec",-1,"lis",-1,"vec",1,"vec",1,"vec","sum(%8)",.. + "str",1,"str",1),label(1)) + if ~ok then + break + end + label(1)=lab + funam=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + nx=size(xx,1); + nz=size(z,1); + + ci=int(ci(:)); + nevin=size(ci,1); + co=int(co(:)); + nevout=size(co,1); + if part(impli,1)=="y" then + funtyp=12004 + else + funtyp=2004 + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + + if ok then + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + + if funam==" " then + break + end + + //cross checking + if model.sim(1)<>funam|sign(size(model.state,"*"))<>sign(nx)|.. + sign(size(model.dstate,"*"))<>sign(nz)|model.nzcross<>nzcr|.. + sign(size(model.evtout,"*"))<>sign(nevout) then + tt=[] + end + + tt=label(2); + + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ci,co) + end + + if ok then + while %t + [ok,tt,cancel]=CC4(funam,tt) + if ~ok then + if cancel then + break, + end + else + model.sim=list(funam,funtyp) + model.state=xx + model.dstate=z + model.odstate=oz + model.rpar=rpar + model.ipar=ipar + model.opar=opar + model.firing=auto0 + model.nzcross=nzcr + model.nmode=nmode + model.dep_ut=dep_ut + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + + if ok|cancel then + break + end + end + end + + case "define" then + + funam="toto" + + model=scicos_model() + model.sim=list(" ",2004) + + model.in=1 + model.in2=1 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.dep_ut=[%t %f] + label=list([funam; + "n"; + sci2exp([model.in model.in2]); + sci2exp(model.intyp); + sci2exp([model.out model.out2]); + sci2exp(model.outtyp); + sci2exp(model.evtin); + sci2exp(model.evtout); + sci2exp(model.state); + sci2exp(model.dstate); + sci2exp(model.odstate); + sci2exp(model.rpar); + sci2exp(model.ipar); + sci2exp(model.opar); + sci2exp(model.nmode); + sci2exp(model.nzcross); + sci2exp(model.firing); + "y"; + "n"],... + []); + + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction + + + + + diff --git a/macros/Misc/CONSTRAINT2_c.sci b/macros/Misc/CONSTRAINT2_c.sci new file mode 100644 index 00000000..e0db95f4 --- /dev/null +++ b/macros/Misc/CONSTRAINT2_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]=CONSTRAINT2_c(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 + ask_again=%f + + [ok,x0,xd0,id,exprs]=scicos_getvalue("Set Constraint block parameters",["Initial guess values of states x";"Initial guess values of derivative x''";"Id(i)=1: if x''(i) is present in the feedback, else Id(i)=0"],list("vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + N=size(x0,"*"); + xd0=xd0(:); + Nxd=size(xd0,"*"); + id=id(:); + Nid=size(id,"*"); + + if (N~=Nxd)|(N~=Nid) then + message("incompatible sizes, states, their derivatives, and ID should be the same size ") + ask_again=%t + end + + if (N<=0 & ~ask_again) then + x_message("number of states (constraints) must be > 0 ") + ask_again=%t + end + + if (~ask_again) then + for i=1:N, + if ~((id(i)==0) | (id(i)==1)) then + ask_again=%t + x_message(["Id(i) must be either";"0 when x''(i) is not present in the feedback";"1: when x''(i) is present in the feedback"]) + break + end + if (id(i)==0) then + id(i)=-1; + end; + end + end + + if ~ask_again then + graphics.exprs=exprs + model.state=[x0;xd0]; + model.out=[N;N] + model.in=N + model.ipar=id + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + x0=[0]; + xd0=[0]; + id=[0]; + model=scicos_model() + model.sim=list("constraint_c",10004) + model.in=1 + model.out=[1;1] + model.state=[x0;xd0] + model.ipar=id + model.blocktype="c" + model.dep_ut=[%f %t] + exprs=list(strcat(sci2exp(x0)),strcat(sci2exp(xd0)),strcat(sci2exp(id))) + + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/CONSTRAINT_c.sci b/macros/Misc/CONSTRAINT_c.sci new file mode 100644 index 00000000..e73a18f6 --- /dev/null +++ b/macros/Misc/CONSTRAINT_c.sci @@ -0,0 +1,78 @@ +// 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]=CONSTRAINT_c(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,x0,exprs]=scicos_getvalue("Set solver block parameters",.. + "Initial guess values",list("vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + N=size(x0,"*"); + + if N<=0 then + message("number of states (constraints) must be > 0 ") + else + [model,graphics,ok]=check_io(model,graphics,N,N,[],[]) + if ok then + graphics.exprs=exprs + model.state=[x0;zeros(N,1)]; + model.out=N + model.in=N + model.ipar=-1*ones(N,1); + x.graphics=graphics; + x.model=model + break + end + end + end + + + case "define" then + x0=[0;0] + model=scicos_model() + model.sim=list("constraint_c",10004) + model.in=1 + model.out=1 + model.ipar=0 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + exprs="0" + + gr_i=[]; + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction + + diff --git a/macros/Misc/DEADBAND.sci b/macros/Misc/DEADBAND.sci new file mode 100644 index 00000000..ce7a261a --- /dev/null +++ b/macros/Misc/DEADBAND.sci @@ -0,0 +1,74 @@ +// 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]=DEADBAND(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,maxp,minp,zeroc,exprs]=scicos_getvalue("Set Deadband parameters",.. + ["End of dead band";"Start of dead band";"zero crossing (0:no, 1:yes)"],list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if maxp<=minp then + message("Upper limit must be > Lower limit") + else + rpar=[maxp;minp] + model.rpar=rpar + if zeroc<>0 then + model.nzcross=2 + model.nmode=1 + else + model.nzcross=0 + model.nmode=0 + end + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minp=-.5; + maxp=.5; + rpar=[maxp;minp] + model=scicos_model() + model.sim=list("deadband",4) + model.in=1 + model.nzcross=2 + model.nmode=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(maxp);string(minp);string(model.nmode)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/DEBUG.sci b/macros/Misc/DEBUG.sci new file mode 100644 index 00000000..5aceb38a --- /dev/null +++ b/macros/Misc/DEBUG.sci @@ -0,0 +1,73 @@ +// 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]=DEBUG(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + textmp=exprs(2) + ok=%t + while 1==1 + [txt]=dialog(["Enter scilab instructions for debugging."; + " Inputs are block and flag, output is block"],.. + textmp); + + if txt<>[] then + tt=["block=debug_scicos(block,flag)"] + + if execstr("deff(tt,txt)","errcatch")==0 then + warnMode = warning("query"); + warning("off"); + save(TMPDIR+"/debug_scicos", debug_scicos) + warning(warnMode); + exprs(2)=txt + if (scicos_debug()<>2 & scicos_debug()<>3) then + scicos_debug(2) + end + break + else + message(["Error in the instructions";lasterror()]) + end + else + ok=%f; + break; + end + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + end + + case "define" then + model=scicos_model() + model.sim=list("%debug_scicos",99) + model.blocktype="d" + + exprs=list("","xcos_debug_gui(flag,block);") + gr_i=[] + x=standard_define([8 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/DEBUG_SCICOS.sci b/macros/Misc/DEBUG_SCICOS.sci new file mode 100644 index 00000000..61f390bf --- /dev/null +++ b/macros/Misc/DEBUG_SCICOS.sci @@ -0,0 +1,24 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014-2014 - Scilab Enterprises - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt +// +// + +function [x,y,typ]=DEBUG_SCICOS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + arg1.gui = "DEBUG" + [x,y,typ] = DEBUG("set", arg1); + case "define" then + x = DEBUG("define") + end +endfunction diff --git a/macros/Misc/DIFF_f.sci b/macros/Misc/DIFF_f.sci new file mode 100644 index 00000000..0992a859 --- /dev/null +++ b/macros/Misc/DIFF_f.sci @@ -0,0 +1,61 @@ +// 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]=DIFF_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,x0,xd0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["Initial state";"Initial Derivative"],list("vec",1,"vec",1),exprs) + + + if ~ok then + break, + end + graphics.exprs=exprs; + model.state=[x0(:);xd0(:)]; + x.graphics=graphics; + x.model=model + break + end + x.model.firing=[] //compatibility + case "define" then + x0=[0;0] + model=scicos_model() + model.sim=list("diffblk",10001) + model.in=1 + model.out=1 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(x0(1)));strcat(sci2exp(x0(2)))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/DSUPER.sci b/macros/Misc/DSUPER.sci new file mode 100644 index 00000000..c0a522b6 --- /dev/null +++ b/macros/Misc/DSUPER.sci @@ -0,0 +1,81 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) DIGITEO - Clément DAVID <clement.david@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] = DSUPER(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + y=needcompile // in case leaving with Exit x=arg1 + typ=list() + graphics=arg1.graphics; + if (length(graphics.exprs) == 0) then + warnBlockByUID(arg1.model.label, gettext("Invalid masked block.")); + x=arg1, + return; + end + + exprs=graphics.exprs(1) + exprs0=graphics.exprs(2)(1) + btitre=graphics.exprs(2)(2)(1) + bitems=graphics.exprs(2)(2)(2:$) + if exprs0==[] then + x=arg1, + return, + end + + // First evaluate the diagram context + context = [arg1.model.rpar.props.context]; + [%scicos_context,ierr] = script2var(context,%scicos_context); + + if ierr <> 0 then + x=arg1, + return; + end + + // then update the context with the mask parameters + tt="scicos_context."+exprs0(1); + for i=2:size(exprs0,1) + tt=tt+",scicos_context."+exprs0(i), + end + + ss=graphics.exprs(2)(3); + scicos_context = %scicos_context; + execstr("[ok,"+tt+",exprs]=scicos_getvalue(btitre,bitems,ss,exprs)") + if ok then + x=arg1; + %scicos_context = scicos_context; + sblock=x.model.rpar; + [sblock,%w,needcompile2,ok]=do_eval(sblock,list(),scicos_context); + y=max(2,needcompile,needcompile2) + x.graphics.exprs(1)=exprs; + x.model.rpar=sblock; + else + x = arg1; + end + + case "define" then + // never used + end +endfunction diff --git a/macros/Misc/EDGETRIGGER.sci b/macros/Misc/EDGETRIGGER.sci new file mode 100644 index 00000000..2d6a06a7 --- /dev/null +++ b/macros/Misc/EDGETRIGGER.sci @@ -0,0 +1,60 @@ +// 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]=EDGETRIGGER(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,edge,exprs]=scicos_getvalue("Set edge trigger block parameters",.. + ["rising (1), falling (-1), both (0)"],list("vec",1),exprs) + if ~ok then + break, + end + model.ipar=sign(edge) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + edge=1 + model=scicos_model() + model.sim=list("edgetrig",4) + model.in=1 + model.out=1 + model.dstate=0 + model.nzcross=1 + model.ipar=sign(edge) + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(edge)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/EDGE_TRIGGER.sci b/macros/Misc/EDGE_TRIGGER.sci new file mode 100644 index 00000000..b0388600 --- /dev/null +++ b/macros/Misc/EDGE_TRIGGER.sci @@ -0,0 +1,223 @@ +// 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]=EDGE_TRIGGER(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 == "EDGETRIGGER" 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 diffobjs(xxn,xx) then + model=xx.model + model_n=xxn.model + if ~is_modelica_block(xx) then + modified=or(model.sim<>model_n.sim)|.. + ~isequal(model.state,model_n.state)|.. + ~isequal(model.dstate,model_n.dstate)|.. + ~isequal(model.rpar,model_n.rpar)|.. + ~isequal(model.ipar,model_n.ipar)|.. + ~isequal(model.label,model_n.label) + if or(model.in<>model_n.in)|or(model.out<>model_n.out) then + needcompile=1 + end + if or(model.firing<>model_n.firing) then + needcompile=2 + end + if (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(); + scs_m_1.objs(1) = EDGETRIGGER("define"); + scs_m_1.objs(2) = IFTHEL_f("define"); + scs_m_1.objs(3) = IN_f("define"); + scs_m_1.objs(4) = CLKOUTV_f("define"); + scs_m_1.objs(5) = scicos_link(); + scs_m_1.objs(6) = scicos_link(); + scs_m_1.objs(7) = scicos_link(); + + // EDGETRIGGER + blk = scs_m_1.objs(1); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [60 0]; + graphics.sz = [60 40]; + + graphics.exprs = "0"; + model.ipar = 0; + + graphics.pin = 5; + graphics.pout = 6; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(1) = blk; + + // IFTHEL_f + blk = scs_m_1.objs(2); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [160 0]; + graphics.sz = [60 40]; + + graphics.exprs = ["0";"0"]; + model.evtin = []; + model.nzcross = 0; + model.nmode = 0; + + graphics.pin = 6; + graphics.peout = [7;0]; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(2) = blk; + + // IN_f + blk = scs_m_1.objs(3); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [0 10]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pout = 5; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(3) = blk; + + // CLKOUTV_f + blk = scs_m_1.objs(4); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [170 -60]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pein = 7; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(4) = blk; + + // IN_f -> EDGETRIGGER + lnk = scs_m_1.objs(5); + + lnk.from = [3 1 0]; + lnk.to = [1 1 1]; + + scs_m_1.objs(5) = lnk; + + // EDGETRIGGER -> IFTHEL_f + lnk = scs_m_1.objs(6); + + lnk.from = [1 1 0]; + lnk.to = [2 1 1]; + + scs_m_1.objs(6) = lnk; + + // IFTHEL_f -> CLKOUTV_f + lnk = scs_m_1.objs(7); + + lnk.ct = [5 -1]; + lnk.from = [2 1 0]; + lnk.to = [4 1 1]; + + scs_m_1.objs(7) = lnk; + + clear blk lnk + + model=scicos_model(); + model.sim = "csuper"; + model.in = 1; + model.evtout = 1; + model.rpar = scs_m_1; + + gr_i=[]; + x=standard_define([3 2],model,[],gr_i) + end +endfunction + diff --git a/macros/Misc/ENDBLK.sci b/macros/Misc/ENDBLK.sci new file mode 100644 index 00000000..c0f6698b --- /dev/null +++ b/macros/Misc/ENDBLK.sci @@ -0,0 +1,198 @@ +// 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]=ENDBLK(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 == "END_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,"*"))|.. + (size(model.evtin,"*")<>size(model_n.evtin,"*")) 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,0,7,1.4],.. + Title="ENDBLK",.. + tol=[0.0001,0.000001,1.000E-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="END_c",.. + graphics=scicos_graphics(.. + orig=[272.104,249.11733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1.000E+08",.. + pin=[],.. + pout=[],.. + pein=2,.. + peout=2,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("scicosexit",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=1.000E+08,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_link(.. + xx=[292.104;292.104;261.83733;261.83733;292.104;292.104],.. + yy=[243.40305;234.45067;234.45067;305.584;305.584;294.83162],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[1,1,0],.. + to=[1,1,1]) + model=scicos_model(.. + sim="csuper",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + 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()) + gr_i=[]; + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Misc/EXPRESSION.sci b/macros/Misc/EXPRESSION.sci new file mode 100644 index 00000000..aaf1fd24 --- /dev/null +++ b/macros/Misc/EXPRESSION.sci @@ -0,0 +1,232 @@ +// 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]=EXPRESSION(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + %scicos_context=%scicos_context; + for ii=1:8, + execstr("%scicos_context.u"+string(ii)+"=0"), + end + ieee(2) + while %t do + [ok,%nin,%exx,%usenz,exprs]=scicos_getvalue(.. + ["Give a scalar scilab expression using inputs u1, u2,..."; + "If only one input, input is vector [u1,u2,...] (max 8)"; + "ex: (dd*u1+sin(u2)>0)*u3"; + "Note that here dd must be defined in context"],.. + ["number of inputs";"scilab expression";"use zero-crossing (0: no, 1 yes)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + ieee(0) + clear %scicos_context + + if ~ok then + break, + end + %exx=strsubst(exprs(2)," ","") + if %exx==emptystr() then + %exx="0", + end //avoid empty + //expression + + if %nin==1 then + %nini=8, + else + %nini=%nin + end + %head="%foo(" + for %jji=1:%nini-1, + %head=%head+"u"+string(%jji)+",", + end + %head=%head+"u"+string(%nini)+")" + ok=execstr("deff(%head,%exx)","errcatch")==0 + if ~ok then + message(["Erroneous expression";lasterror()]) + else + if %nin>1 then + [model,graphics,ok]=check_io(model,graphics,ones(1,%nin),1,[],... + []) + else + [model,graphics,ok]=check_io(model,graphics,-1,1,[],... + []) + end + if ok then + + [ok,%ok1,ipar,rpar,%nz]=compiler_expression(%foo) + + if ~ok then + message(["Erroneous expression";lasterror()]) + else + if %ok1 then + model.rpar=rpar + model.ipar=ipar + if %usenz then + model.nzcross=%nz + model.nmode=%nz + else + model.nzcross=0 + model.nmode=0 + end + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + end + end + end + case "define" then + in=[1;1] + out=1 + txt="(u1>0)*sin(u2)^2" + deff("%foo(u1,u2)",txt) + [%ok1,ipar,rpar,nz]=compile_expr(%foo) + model=scicos_model() + model.sim=list("evaluate_expr",4) + model.in=in + model.out=out + model.rpar=rpar + model.ipar=ipar + model.nzcross=nz + model.nmode=nz + model.dep_ut=[%t %f] + exprs=[string(size(in,"*"));txt;"1"] + gr_i=[] + x=standard_define([5 2],model,exprs,gr_i) + end +endfunction + +function [ok,%ok1,ipar,rpar,%nz]=compiler_expression(%foo) + ok=%t,%ok1=%f,ipar=[],rpar=[],%nz=[] + if exists("%scicos_context") then + %mm=getfield(1,%scicos_context) + for %mi=%mm(3:$) + if execstr(%mi+"=%scicos_context(%mi)","errcatch")<>0 then + ok=%f + end + end + end + if ok then + ok=execstr("[%ok1,ipar,rpar,%nz]=compile_expr(%foo)","errcatch")==0 + end +endfunction + + +function [ok,%ipar,%rpar,%nz]=compile_expr(%foo) + ok=%t + %lst=macr2lst(%foo); + %mm=macrovar(%foo); + %MM=%mm(3); + %FF=["sin";"cos";"tan";"exp";"log"; + "sinh";"cosh";"tanh"; + "int";"round";"ceil";"floor"; + "sign";"abs";"max";"min"; + "asin";"acos";"atan";"asinh";"acosh";"atanh"; + "atan2"; + "log10"; + ]; // ops above 100 + %num_arg=[1;1;1;1;1; + 1;1;1 + 1;1;1;1; + 1;1;2;2; + 1;1;1;1;1;1; + 2; + 1 + ]; //number of arguments + %ZCR=[16,17,18,19,20,21,28,29,30,109,110,111,112,113,114,115,116]; // ops with zero-crossing + %UU=%mm(1) + %ipar=[] + %rpar=[] + %nrpar=0 + %nz=0 + %ijk=4 + while %ijk<length(%lst) + %ijk=%ijk+1 + select evstr(%lst(%ijk)(1)) + case 2 + %jjk=find(%lst(%ijk)(2)==%FF) + if %jjk<> [] then + if evstr(%lst(%ijk)(4))<>%num_arg(%jjk) then + message(%lst(%ijk)(2)+" must have "+string(%num_arg(%jjk))+" arguments") + ok=%f + return + else + %ipar=[%ipar;5;100+%jjk] + if or(100+%jjk==%ZCR) then + %nz=%nz+1, + end + %ijk=%ijk+1 + end + else + %jjk=find(%lst(%ijk)(2)==%MM) + if %jjk<> [] then + if ~exists(%MM(%jjk)) then + message("Variable "+%MM(%jjk)+" is not defined.") + ok=%f + return + end + %var=evstr(%MM(%jjk)) + if size(%var,"*")<>1 then + message("Variable "+%MM(%jjk)+" is not scalar.") + ok=%f + return + else + %nrpar=%nrpar+1 + %rpar(%nrpar)=%var + %ipar=[%ipar;6;%nrpar] + end + else + %jjk=find(%lst(%ijk)(2)==%UU) + if %jjk<> [] then + %ipar=[%ipar;2;%jjk] + else + message("Unknown variable "+%lst(%ijk)(2)) + ok=%f + end + //%ipar=[%ipar;2;evstr(strsubst(%lst(%ijk)(2),'u',''))] + end + end + case 5 + // case of - with one operand (-u1) + if (evstr(%lst(%ijk)(2))==2)&(evstr(%lst(%ijk)(3))==1) then + %ipar=[%ipar;5;99] + else + %ipar=[%ipar;5;evstr(%lst(%ijk)(2))] + if or(evstr(%lst(%ijk)(2))==%ZCR) then + %nz=%nz+1, + end + end + case 6 + // %ipar=[%ipar;6;evstr(%lst(%ijk)(2))] + %nrpar=%nrpar+1 + %rpar(%nrpar)=evstr(%lst(%ijk)(2)) + %ipar=[%ipar;6;%nrpar] + end + end +endfunction diff --git a/macros/Misc/Extract_Activation.sci b/macros/Misc/Extract_Activation.sci new file mode 100644 index 00000000..0ba2c371 --- /dev/null +++ b/macros/Misc/Extract_Activation.sci @@ -0,0 +1,156 @@ +// 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]=Extract_Activation(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + scs_m_1=scicos_diagram(); + scs_m_1.objs(1) = IFTHEL_f("define"); + scs_m_1.objs(2) = CLKSOMV_f("define"); + scs_m_1.objs(3) = IN_f("define"); + scs_m_1.objs(4) = CLKOUTV_f("define"); + scs_m_1.objs(5) = scicos_link(); + scs_m_1.objs(6) = scicos_link(); + scs_m_1.objs(7) = scicos_link(); + scs_m_1.objs(8) = scicos_link(); + + // IFTHEL_f + blk = scs_m_1.objs(1); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [80 0]; + graphics.sz = [60 40]; + + graphics.exprs = ["0";"0"]; + model.evtin = []; + model.nzcross = 0; + model.nmode = 0; + + graphics.pin = 7; + graphics.peout = [5;6]; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(1) = blk; + + // CLKSOMV_f + blk = scs_m_1.objs(2); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [80 -80]; + graphics.sz = [80 40]; + + graphics.pein = [5;6]; + graphics.peout = 8; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(2) = blk; + + // IN_f + blk = scs_m_1.objs(3); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [0 10]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pout = 7; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(3) = blk; + + // CLKOUTV_f + blk = scs_m_1.objs(4); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [110 -140]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pein = 8; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(4) = blk; + + // IFTHEL_f -> CLKSOMV_f + lnk = scs_m_1.objs(5); + + lnk.ct = [5 -1]; + lnk.from = [1 1 0]; + lnk.to = [2 1 1]; + + scs_m_1.objs(5) = lnk; + + // IFTHEL_f -> CLKSOMV_f + lnk = scs_m_1.objs(6); + + lnk.ct = [5 -1]; + lnk.from = [1 2 0]; + lnk.to = [2 2 1]; + + scs_m_1.objs(6) = lnk; + + // IN_f -> IFTHEL_f + lnk = scs_m_1.objs(7); + + lnk.from = [3 1 0]; + lnk.to = [1 1 1]; + + scs_m_1.objs(7) = lnk; + + // CLKSOMV_f -> CLKOUTV_f + lnk = scs_m_1.objs(8); + + lnk.ct = [5 -1]; + lnk.from = [2 1 0]; + lnk.to = [4 1 1]; + + scs_m_1.objs(8) = lnk; + + clear blk lnk + + model=scicos_model(); + model.sim = "csuper"; + model.in = 1; + model.evtout = 1; + model.rpar = scs_m_1; + + gr_i=[]; + x=standard_define([3 2],model,[],gr_i) + end +endfunction + diff --git a/macros/Misc/HYSTHERESIS.sci b/macros/Misc/HYSTHERESIS.sci new file mode 100644 index 00000000..aa9e9b9b --- /dev/null +++ b/macros/Misc/HYSTHERESIS.sci @@ -0,0 +1,77 @@ +// 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]=HYSTHERESIS(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,high_lim,low_lim,out_high,out_low,nzz,exprs]=scicos_getvalue("Set parameters",.. + ["switch on at";"switch off at";"output when on"; + "output when off";"use zero crossing: yes (1), no (0)"],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if low_lim>high_lim then + message("switch on value must be larger than switch off value") + else + graphics.exprs=exprs; + model.rpar=[high_lim,low_lim,out_high,out_low]' + if nzz>0 then + nzz=2, + end + model.nzcross=nzz + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=1 + ipar=[0] // rule + nzz=2 + rpar=[1;0;1;0] + + model=scicos_model() + model.sim=list("hystheresis",4) + model.in=in + model.out=1 + model.rpar=rpar + model.nzcross=nzz + model.nmode=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(rpar);string(sign(nzz))] + + + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/IMPSPLIT_f.sci b/macros/Misc/IMPSPLIT_f.sci new file mode 100644 index 00000000..f1759ffd --- /dev/null +++ b/macros/Misc/IMPSPLIT_f.sci @@ -0,0 +1,45 @@ +// 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]=IMPSPLIT_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model(); + model.sim = "limpsplit"; + mo=modelica() + mo.model="limpsplit" + mo.inputs="n"; + mo.outputs=["n";"n"] + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + x=standard_define([1 1]/3,model,[],[]) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I" "I"] + end + +endfunction diff --git a/macros/Misc/LOGICAL_OP.sci b/macros/Misc/LOGICAL_OP.sci new file mode 100644 index 00000000..bc768645 --- /dev/null +++ b/macros/Misc/LOGICAL_OP.sci @@ -0,0 +1,139 @@ +// 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]=LOGICAL_OP(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,1)==2 then + exprs=[exprs;sci2exp(1);sci2exp(0)]; + end + while %t do + [ok,nin,rule,Datatype,tp,exprs]=scicos_getvalue("Set parameters",.. + ["number of inputs";.. + "Operator: AND (0), OR (1), NAND (2), NOR (3), XOR (4), NOT (5)" + "Datatype (1=double 3=int32 ...)";.. + "Bitwise Rule(0=No 1=yes)"],.. + list("vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + nin=int(nin); + rule=int(rule); + tp=int(tp) + if nin<1 then + message("Number of inputs must be >=1 "); + ok=%f + elseif (rule<0)|(rule>5) then + message("Incorrect operator "+string(rule)+" ; must be 0 to 5."); + ok=%f + elseif (rule==5)&(nin>1) then + message("Only one input allowed for NOT operation") + nin=1 + elseif ((Datatype==1)&(tp~=0)) + message ("Bitwise Rule is only activated when Data type is integer"); + ok=%f + end + if ok then + if (tp~=0) then + tp=1; + end + if Datatype==1 then + model.sim=list("logicalop",4) + model.ipar=[rule], + else + if Datatype==3 then + model.sim=list("logicalop_i32",4) + elseif Datatype==4 then + model.sim=list("logicalop_i16",4) + elseif Datatype==5 then + model.sim=list("logicalop_i8",4) + elseif Datatype==6 then + model.sim=list("logicalop_ui32",4) + elseif Datatype==7 then + model.sim=list("logicalop_ui16",4) + elseif Datatype==8 then + model.sim=list("logicalop_ui8",4) + else + message ("Datatype is not supported"); + ok=%f; + end + model.ipar=[rule;tp]; + end + if ok then + it=Datatype*ones(nin,1); + ot=Datatype; + in=[-ones(nin,1) -2*ones(nin,1)] + if (rule<>5)&(nin==1) then + out=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + else + out=[-1 -2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + end + if ok then + if rule == 0 then + label = "AND"; + elseif rule == 1 then + label = "OR"; + elseif rule == 2 then + label = "NAND"; + elseif rule == 3 then + label = "NOR"; + elseif rule == 4 then + label = "XOR"; + elseif rule == 5 then + label = "NOT"; + end + graphics.exprs=exprs; + graphics.style = ["blockWithLabel;displayedLabel="+label]; + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + in=[-1;-1] + ipar=[0] + nin=2 + + model=scicos_model() + model.sim=list("logicalop",4) + model.in=in + model.out=-1 + model.ipar=ipar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(nin);string(ipar)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/MBLOCK.sci b/macros/Misc/MBLOCK.sci new file mode 100644 index 00000000..71ae263c --- /dev/null +++ b/macros/Misc/MBLOCK.sci @@ -0,0 +1,468 @@ +// 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]=MBLOCK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model + graphics=arg1.graphics + //label=graphics.exprs; + exprs=graphics.exprs + + //Compatibility + if type(exprs)==15 then + paramv=list(); + pprop=[]; + //must do something better than that ! + for i=1:size(model.rpar,"*") + paramv($+1)=string(model.rpar(i)) + pprop($+1) = 0 + end + + exprs = tlist(["MBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + exprs(1)(1),.. + exprs(1)(2),.. + exprs(1)(3),.. + exprs(1)(4),.. + exprs(1)(5),.. + paramv,... + sci2exp(pprop(:)),.. + exprs(1)(7),exprs(2)) + + end + + //lab_1 = [in,intype,out,outtype,param,nameF] + lab_1 = list(exprs.in,.. //1 + exprs.intype,.. //2 + exprs.out,.. //3 + exprs.outtype,.. //4 + exprs.param,.. //5 + exprs.pprop,.. //6 + exprs.nameF) //7 + + //lab_2 = [paramv] + lab_2 = exprs.paramv //already a list + + //store exprs before modif + //exprs.prev_exprs=exprs; + //exprs.prev_exprs.prev_exprs=tlist("MBLOCK"); + + while %t do + // [ok,Tin,Tintype,Tout,Touttype,Tparam,Tparamv,Tfunam,lab]=.. + // scicos_getvalue('Set Modelica generic block parameters',.. + // ['Input variables: ';.. + // 'Input variables types: ';.. + // 'Output variables: ';.. + // 'Output variables types:';.. + // 'Parameters in Modelica:';.. + // 'Parameter values: ';.. + // 'Function name: '],.. + // list('str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1),label(1)) + + //warning here lab_1 is a list + [ok,Tin,Tintype,Tout,Touttype,Tparam,pprop,Tfunam,lab_1]=.. + scicos_getvalue("Set Modelica generic block parameters",.. + ["Input variables: ";.. + "Input variables types: ";.. + "Output variables: ";.. + "Output variables types:";.. + "Parameters in Modelica:";.. + "Parameters properties: ";.. + "Function name: "],.. + list("str",-1,"str",-1,"str",-1,"str",-1,"str",-1,.. + "vec",-1,"str",-1),lab_1) + + //Cancel case + if ~ok then + break + end + // ierr=execstr("in=stripblanks(evstr(Tin));.. + // intype=stripblanks(evstr(Tintype));.. + // out=stripblanks(evstr(Tout));.. + // outtype=stripblanks(evstr(Touttype));.. + // param=stripblanks(evstr(Tparam));.. + // paramv=evstr(Tparamv);.. + // funam=stripblanks(Tfunam)",'errcatch') + // + //first stage of checking variable name + //put string symbolic parameters in variable + ierr=execstr("in=stripblanks(evstr(Tin));.. + intype=stripblanks(evstr(Tintype));.. + out=stripblanks(evstr(Tout));.. + outtype=stripblanks(evstr(Touttype));.. + param=stripblanks(evstr(Tparam));.. + funam=stripblanks(Tfunam)","errcatch") + + if ierr<>0 then + //You lose! Try again! Insert coin! + //messagebox("Error, try again please!","modal","error"); + messagebox("Error in evaluation of variables.","modal","error"); + ok=%f + //break + end + + //check for valid name variable + //in + if ok then + for i=1:size(in,"*") + r=%f; + ierr=execstr("r=validvar(in(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + messagebox(["Invalid variable name for the input "+string(i)+"."; + """"+in(i)+""""; + "Please choose another variable name."],"modal","error"); + end + end + //out + if ok then + for i=1:size(out,"*") + r=%f; + ierr=execstr("r=validvar(out(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + messagebox(["Invalid variable name for the output "+string(i)+"."; + """"+out(i)+""""; + "Please choose another variable name."],"modal","error"); + end + end + //param + if ok then + param=param(:) + for i=1:size(param,"*") + r=%f; + ierr=execstr("r=validvar(param(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + messagebox(["Invalid variable name for the parameter "+string(i)+"."; + """"+param(i)+""""; + "Please choose another variable name."],"modal","error"); + end + end + + // type checking + //typeok=%t; + if ok then + for i=1:size(intype,"*") + if intype(i)<>"E"&intype(i)<>"I" then + //typeok=%f; + messagebox("Input type should be ''E'' or ''I''!","modal","error"); + ok=%f + break + end + end + end + // if ~typeok then + // ok=%f + // //break + // end + + if ok then + for i=1:size(outtype,"*") + if outtype(i)<>"E"&outtype(i)<>"I" then + //typeok=%f; + messagebox("Output type should be ''E'' or ''I''!","modal","error"); + ok=%f + break + end + end + end + // if ~typeok then break, end + + //cross size checking + if ok then + if or(size(intype)<>size(in)) then + messagebox("Input variables are not well defined!","modal","error"); + ok=%f + //break; + end + end + + if ok then + if or(size(outtype)<>size(out)) then + messagebox("Output variables are not well defined!","modal","error"); + ok=%f + //break; + end + end + + //check param properties + if ok then + pprop = pprop(:) + if (size(param,"*")<>size(pprop,"*")) then + messagebox(["There is differences in"; + "size of param and size "; + "of param properties."],"modal","error"); + ok=%f + //break; + end + end + + if ok then + if max(pprop)>2 | min(pprop)<0 then + messagebox(["Parameters properties must be :"; + "0 : for simple paramater,"; + "1 : for initial state value,"; + "2 : for a fixed initial state value."],"modal","error"); + ok=%f + //break; + end + end + + //check name of modelica file + if ok then + if funam=="" then + messagebox("The filename is not defined!","modal","error"); + ok=%f + //break + end + end + + if ok then + [dirF,nameF,extF]=fileparts(funam); + if (extF<>"" & extF<>".mo")|(dirF<>"" & extF<>".mo") then + messagebox("Filename extention should be ''.mo '' !","modal","error"); + ok=%f + //break + end + end + + if ok then + //set_io checking + intypex=find(intype=="I"); outtypex=find(outtype=="I"); + //[model,graphics,ok]=check_io(model,graphics,ones(in),.. + // ones(out),[],[],intypex,outtypex) + [model,graphics,ok]=set_io(model,graphics,list([ones(in),ones(in)],ones(in)),.. + list([ones(out),ones(out)],ones(out)),.. + [],[],intypex,outtypex) + end + + //***************************************************************************** + //generate second dialog box from Tparam + if ok then + + Tparam_lab=evstr(Tparam) //labels + Tparam_sz=size(Tparam_lab,"*") //numbers of labels + + //adjust size of lab_2 according to size of Tparam + if Tparam_sz>lstsize(lab_2) then + for i=1:(Tparam_sz-lstsize(lab_2)) + lab_2($+1)="0" + end + elseif Tparam_sz<lstsize(lab_2) then + lab_2_tmp=list() + if Tparam_sz<>0 then //if param + for i=1:(lstsize(lab_2)-Tparam_sz) + lab_2_tmp(i)=lab_2(i) + end + end + lab_2=lab_2_tmp + end + + //generate lhs, label and rhs txt for scicos_getvalue + if Tparam_sz<>0 then //if param + lhs_txt="" //lhs txt + lab_txt="" //label txt + rhs_txt="" //rhs txt + for i=1:Tparam_sz + lhs_txt=lhs_txt+"%v"+string(i)+"," + if pprop(i) == 0 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+"'';" + elseif pprop(i) == 1 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (state) '';" + elseif pprop(i) == 2 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (fixed state) '';" + end + rhs_txt=rhs_txt+"''vec'',-1," + end + lhs_txt=part(lhs_txt,1:length(lhs_txt)-1) + lab_txt=part(lab_txt,1:length(lab_txt)-1) + rhs_txt=part(rhs_txt,1:length(rhs_txt)-1) + + //generate main scicos_getvalue cmd + //warning here lab_2 is a list in input and a string in output + getvalue_txt = "[ok,"+lhs_txt+",lab_2]=scicos_getvalue(''Set parameters values'',["+.. + lab_txt+"],"+.. + "list("+rhs_txt+"),lab_2)" + + //display the second dialog box + execstr(getvalue_txt) + + //restore original lab_2 if not ok + if ~ok then + lab_2 = exprs.paramv + end + end + end + + //put output param in the form of a list + //in paramv + if ok then + paramv=list(); + for i=1:Tparam_sz + execstr("paramv("+string(i)+")=%v"+string(i)) + end + end + //***************************************************************************** + + //============================---------MBLOCK2 + if ok then + if extF==".mo" & fileinfo(funam)<>[] then + tt=mgetl(funam) + else + tt=exprs.funtxt + mo=model.equations + //if model.sim(1)<>nameF then + if mo.model<>nameF then + tt=[] + end + end + //============================ + [ok,tt]=MODCOM(funam,tt,in,out,param,paramv,pprop) + if ~ok then + break + end + end + + if ok then + //------------------ + mo=modelica() + mo.model=nameF + mo.inputs=in; + mo.outputs=out; + if max(pprop)>0 then + mo.parameters=list(param',paramv,pprop') + else + mo.parameters=list(param',paramv) + end + model.equations=mo + //------------------ + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + paramv(i)(:)]//value + end + model.sim(1)=funam + //------------------ + exprs.in=lab_1(1) + exprs.intype=lab_1(2) + exprs.out=lab_1(3) + exprs.outtype=lab_1(4) + exprs.param=lab_1(5) + exprs.paramv=list(); + if Tparam_sz<>0 then //if param + if type(lab_2)==15 then //for eval + for i=1:lstsize(lab_2) + exprs.paramv(i)=lab_2(i);//string + end + else + for i=1:size(lab_2,"*") + exprs.paramv(i)=lab_2(i); + end + end + end + exprs.pprop=lab_1(6) + exprs.nameF=lab_1(7) + exprs.funtxt=tt + //label(2)=tt + //------------------ + x.model=model + graphics.gr_i(1)(1)="txt=[''Modelica'';'' " + nameF + " ''];" + graphics.in_implicit =intype + graphics.out_implicit=outtype + //graphics.exprs=label + graphics.exprs=exprs + x.graphics=graphics + break + end + end + + //Define + case "define" then + in=["u1"] + intype=["I"] + out=["y1";"y2"] + outtype=["I";"E"] + param=["R";"L"]; + //paramv=[0.1;0.0001]; + paramv=list(0.1,.0001) + pprop=[0;0]; + nameF="generic" + + //label=list([sci2exp(in),sci2exp(intype,sci2exp(out),.. + // sci2exp(outtype),sci2exp(param),sci2exp(paramv),nameF]',[]) + + exprs = tlist(["MBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + sci2exp(in(:)),.. + sci2exp(intype(:)),.. + sci2exp(out(:)),.. + sci2exp(outtype(:)),.. + sci2exp(param(:)),.. + list(string(0.1),string(.0001)),... + sci2exp(pprop(:)),.. + nameF,[]) + + model=scicos_model() + model.blocktype="c" + model.dep_ut=[%f %t] + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + paramv(i)(:)] + end + + mo=modelica() + mo.model=nameF + mo.parameters=list(param,paramv) + model.sim=list(mo.model,30004) + mo.inputs=in + mo.outputs=out + model.in=ones(size(mo.inputs,"r"),1) + model.out=ones(size(mo.outputs,"r"),1) + model.equations=mo + gr_i=[] + //x=standard_define([3 2],model,label,gr_i) + x=standard_define([3 2],model,exprs,gr_i) + x.graphics.in_implicit =intype + x.graphics.out_implicit=outtype + end +endfunction + diff --git a/macros/Misc/MEMORY_f.sci b/macros/Misc/MEMORY_f.sci new file mode 100644 index 00000000..d4aef072 --- /dev/null +++ b/macros/Misc/MEMORY_f.sci @@ -0,0 +1,77 @@ +// 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]=MEMORY_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,a,inh,exprs]=scicos_getvalue("Set memory block parameters",.. + ["initial condition";"Inherit (1: no, 0: yes)"],list("vec",-1,"vec",1),exprs) + if ~ok then + break, + end + if inh==0 then + inh=[]; + else + inh=1; + end + [model,graphics,ok]=check_io(model,graphics,-1,-1,inh,[]) + out=size(a,"*"); + if out==0 then + ok=%f, + messagebox("Initial condition empty","modal","error"); + end + in=out + if ok then + graphics.exprs=exprs; + model.rpar=a; + model.in=in; + model.out=out + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + z=0 + in=1 + exprs=[string(z);string(1)] + model=scicos_model() + model.sim="memo" + model.in=in + model.out=in + model.evtin=1 + model.dstate=0 + model.rpar=z + model.blocktype="m" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/MPBLOCK.sci b/macros/Misc/MPBLOCK.sci new file mode 100644 index 00000000..a249e9ba --- /dev/null +++ b/macros/Misc/MPBLOCK.sci @@ -0,0 +1,459 @@ +// 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]=MPBLOCK(job,arg1,arg2) + // + // Copyright INRIA Oct 2006 + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model + graphics=arg1.graphics + //label=graphics.exprs; + exprs=graphics.exprs + + //Compatibility + if type(exprs)==15 then + paramv=list(); + pprop=[]; + //must do something better than that ! + for i=1:size(model.rpar,"*") + paramv($+1)=string(model.rpar(i)) + pprop($+1) = 0 + end + + exprs = tlist(["MPBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + exprs(1)(1),.. + exprs(1)(2),.. + exprs(1)(3),.. + exprs(1)(4),.. + exprs(1)(5),.. + paramv,... + sci2exp(pprop(:)),.. + exprs(1)(7),exprs(2)) + + end + + //lab_1 = [in,intype,out,outtype,param,nameF] + lab_1 = list(exprs.in,.. //1 + exprs.intype,.. //2 + exprs.out,.. //3 + exprs.outtype,.. //4 + exprs.param,.. //5 + exprs.pprop,.. //6 + exprs.nameF) //7 + + //lab_2 = [paramv] + lab_2 = exprs.paramv //already a list + + //store exprs before modif + //exprs.prev_exprs=exprs; + //exprs.prev_exprs.prev_exprs=tlist("MPBLOCK"); + + while %t do + // [ok,Tin,Tintype,Tout,Touttype,Tparam,Tparamv,Tfunam,lab]=.. + // getvalue('Set Modelica generic block parameters',.. + // ['Input variables: ';.. + // 'Input variables types: ';.. + // 'Output variables: ';.. + // 'Output variables types:';.. + // 'Parameters in Modelica:';.. + // 'Parameter values: ';.. + // 'Function name: '],.. + // list('str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1),label(1)) + //warning here lab_1 is a list + [ok,Tin,Tintype,Tout,Touttype,Tparam,pprop,Tfunam,lab_1]=.. + getvalue("Set Modelica generic block parameters",.. + ["Input variables: ";.. + "Input variables types: ";.. + "Output variables: ";.. + "Output variables types:";.. + "Parameters in Modelica:";.. + "Parameters properties: ";.. + "Model name in packages:"],.. + list("str",-1,"str",-1,"str",-1,"str",-1,"str",-1,.. + "vec",-1,"str",-1),lab_1) + + //Cancel case + if ~ok then + break + end + // ierr=execstr("in=stripblanks(evstr(Tin));.. + // intype=stripblanks(evstr(Tintype));.. + // out=stripblanks(evstr(Tout));.. + // outtype=stripblanks(evstr(Touttype));.. + // param=stripblanks(evstr(Tparam));.. + // paramv=evstr(Tparamv);.. + // funam=stripblanks(Tfunam)",'errcatch') + // + //first stage of checking variable name + //put string symbolic parameters in variable + ierr=execstr("in=stripblanks(evstr(Tin));.. + intype=stripblanks(evstr(Tintype));.. + out=stripblanks(evstr(Tout));.. + outtype=stripblanks(evstr(Touttype));.. + param=stripblanks(evstr(Tparam));.. + funam=stripblanks(Tfunam)","errcatch") + + if ierr<>0 then + //You lose! Try again! Insert coin! + //x_message("Error, try again please!") + x_message("Error in evaluation of variables.") + ok=%f + //break + end + + //check for valid name variable + //in + if ok then + for i=1:size(in,"*") + r=%f; + ierr=execstr("r=validvar(in(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + x_message(["Invalid variable name for the input "+string(i)+"."; + """"+in(i)+""""; + "Please choose another variable name."] ); + end + end + //out + if ok then + for i=1:size(out,"*") + r=%f; + ierr=execstr("r=validvar(out(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + x_message(["Invalid variable name for the output "+string(i)+"."; + """"+out(i)+""""; + "Please choose another variable name."] ); + end + end + //param + if ok then + param=param(:) + for i=1:size(param,"*") + r=%f; + ierr=execstr("r=validvar(param(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + x_message(["Invalid variable name for the parameter "+string(i)+"."; + """"+param(i)+""""; + "Please choose another variable name."] ); + end + end + + // type checking + //typeok=%t; + if ok then + for i=1:size(intype,"*") + if intype(i)<>"E"&intype(i)<>"I" then + //typeok=%f; + x_message("Input type should be ''E'' or ''I''!"); + ok=%f + break + end + end + end + // if ~typeok then + // ok=%f + // //break + // end + + if ok then + for i=1:size(outtype,"*") + if outtype(i)<>"E"&outtype(i)<>"I" then + //typeok=%f; + x_message("Output type should be ''E'' or ''I''!"); + ok=%f + break + end + end + end + // if ~typeok then break, end + + //cross size checking + if ok then + if or(size(intype)<>size(in)) then + x_message("Input variables are not well defined!"); + ok=%f + //break; + end + end + + if ok then + if or(size(outtype)<>size(out)) then + x_message("Output variables are not well defined!"); + ok=%f + //break; + end + end + + //check param properties + if ok then + pprop = pprop(:) + if (size(param,"*")<>size(pprop,"*")) then + x_message(["There is differences in"; + "size of param and size "; + "of param properties." ]) + ok=%f + //break; + end + end + + if ok then + if max(pprop)>2 | min(pprop)<0 then + x_message(["Parameters properties must be :"; + "0 : if it is a paramaters"; + "1 : if it is an initial value of state,"; + "2 : it it is a fixed initial state value." ]) + ok=%f + //break; + end + end + + //check name of modelica file + if ok then + if funam=="" then + x_message("The model name is not defined!") + ok=%f + //break + end + end + + if ok then + [dirF,nameF,extF]=fileparts(funam); + if (extF<>"" )|(dirF<>"") then + x_message("Invalid model name!") + ok=%f + //break + end + end + + if ok then + //set_io checking + intypex=find(intype=="I"); outtypex=find(outtype=="I"); + //[model,graphics,ok]=check_io(model,graphics,ones(in),.. + // ones(out),[],[],intypex,outtypex) + [model,graphics,ok]=set_io(model,graphics,list([ones(in),ones(in)],ones(in)),.. + list([ones(out),ones(out)],ones(out)),.. + [],[],intypex,outtypex) + end + + //***************************************************************************** + //generate second dialog box from Tparam + if ok then + + Tparam_lab=evstr(Tparam) //labels + Tparam_sz=size(Tparam_lab,"*") //numbers of labels + + //adjust size of lab_2 according to size of Tparam + if Tparam_sz>lstsize(lab_2) then + for i=1:(Tparam_sz-lstsize(lab_2)) + lab_2($+1)="0" + end + elseif Tparam_sz<lstsize(lab_2) then + lab_2_tmp=list() + if Tparam_sz<>0 then //if param + for i=1:Tparam_sz + ee=evstr(exprs.param) + for j=1:size(ee,"r") + if ee(j)==Tparam_lab(i) then + lab_2_tmp(i)=lab_2(j) + end + end + end + lab_2=lab_2_tmp + end + end + //generate lhs, label and rhs txt for getvalue + if Tparam_sz<>0 then //if param + lhs_txt="" //lhs txt + lab_txt="" //label txt + rhs_txt="" //rhs txt + for i=1:Tparam_sz + lhs_txt=lhs_txt+"%v"+string(i)+"," + if pprop(i) == 0 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+"'';" + elseif pprop(i) == 1 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (state) '';" + elseif pprop(i) == 2 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (fixed state) '';" + end + rhs_txt=rhs_txt+"''vec'',-1," + end + lhs_txt=part(lhs_txt,1:length(lhs_txt)-1) + lab_txt=part(lab_txt,1:length(lab_txt)-1) + rhs_txt=part(rhs_txt,1:length(rhs_txt)-1) + + //generate main getvalue cmd + //warning here lab_2 is a list in input and a string in output + getvalue_txt = "[ok,"+lhs_txt+",lab_2]=scicos_getvalue(''Set parameters values'',["+.. + lab_txt+"],"+.. + "list("+rhs_txt+"),lab_2)" + + //display the second dialog box + execstr(getvalue_txt) + + //restore original lab_2 if not ok + if ~ok then + lab_2 = exprs.paramv + end + end + end + + //put output param in the form of a list + //in paramv + if ok then + paramv=list(); + for i=1:Tparam_sz + execstr("paramv("+string(i)+")=%v"+string(i)) + end + end + //***************************************************************************** + + //============================---------MPBLOCK + + if ok then + //------------------ + mo=modelica() + mo.model=nameF + mo.inputs=in; + mo.outputs=out; + if pprop~=[] then + if max(pprop)>0 then + mo.parameters=list(param',paramv,pprop') + else + mo.parameters=list(param',paramv) + end + end + model.equations=mo + //------------------ + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + double(paramv(i)(:))]//value + end + + model.sim(1)=funam + //------------------ + exprs.in=lab_1(1) + exprs.intype=lab_1(2) + exprs.out=lab_1(3) + exprs.outtype=lab_1(4) + exprs.param=lab_1(5) + exprs.paramv=list(); + if Tparam_sz<>0 then //if param + if type(lab_2)==15 then //for eval + for i=1:lstsize(lab_2) + exprs.paramv(i)=lab_2(i);//string + end + else + for i=1:size(lab_2,"*") + exprs.paramv(i)=lab_2(i); + end + end + end + exprs.pprop=lab_1(6) + exprs.nameF=lab_1(7) + exprs.funtxt="" // model is defined in the a package + //label(2)=tt + //------------------ + x.model=model + graphics.gr_i(1)(1)="txt=['' " + nameF + " ''];" + graphics.in_implicit =intype + graphics.out_implicit=outtype + //graphics.exprs=label + graphics.exprs=exprs + x.graphics=graphics + break + end + end + + //Define + case "define" then + in=["u"] + intype=["I"] + out=["y1";"y2"] + outtype=["I";"I"] + param=[]; + paramv=list() + pprop=[]; + nameF="myModel" + + //label=list([sci2exp(in),sci2exp(intype,sci2exp(out),.. + // sci2exp(outtype),sci2exp(param),sci2exp(paramv),nameF]',[]) + + exprs = tlist(["MPBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + sci2exp(in(:)),.. + sci2exp(intype(:)),.. + sci2exp(out(:)),.. + sci2exp(outtype(:)),.. + sci2exp(param(:)),.. + list(string(0.1),string(.0001)),... + sci2exp(pprop(:)),.. + nameF,[]) + + model=scicos_model() + model.blocktype="c" + model.dep_ut=[%t %t] + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + paramv(i)(:)] + end + + mo=modelica() + mo.model=nameF + mo.parameters=list(param,paramv) + model.sim=list(mo.model,10004) + mo.inputs=in + mo.outputs=out + model.in=ones(size(mo.inputs,"r"),1) + model.out=ones(size(mo.outputs,"r"),1) + model.equations=mo + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + x.graphics.in_implicit =intype + x.graphics.out_implicit=outtype + end +endfunction + + + diff --git a/macros/Misc/PAL_f.sci b/macros/Misc/PAL_f.sci new file mode 100644 index 00000000..2d0a7d29 --- /dev/null +++ b/macros/Misc/PAL_f.sci @@ -0,0 +1,55 @@ +// 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]=PAL_f(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + [x,newparameters,needcompile,edited]=scicos(arg1.model.rpar) + arg1.graphics.id=x.props.title(1); + arg1.model.rpar=x; + x=arg1 + y=[] + typ=[] + %exit=resume(%f) + + case "define" then + scs=scicos_diagram(); + scs.props.title="Palette"; + model=scicos_model(); + model.sim="palette"; + model.in=[]; + model.out=[]; + model.rpar=scs; + model.blocktype="h"; + model.dep_ut=[%f %f]; + + gr_i=[] + + x=standard_define([2 2],model,[],gr_i) + x.graphics.id=scs.props.title(1); + end + +endfunction diff --git a/macros/Misc/PENDULUM_ANIM.sci b/macros/Misc/PENDULUM_ANIM.sci new file mode 100644 index 00000000..dec193c9 --- /dev/null +++ b/macros/Misc/PENDULUM_ANIM.sci @@ -0,0 +1,90 @@ +// 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 +// +///withoutPrompt +function [x,y,typ]=PENDULUM_ANIM(job,arg1,arg2) + // Animation of the cart-pendulum problem + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + dstate=model.dstate + while %t do + [ok,plen,csiz,phi,xmin,xmax,ymin,ymax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["pendulum length";"cart size (square side)";"slope"; + "Xmin";"Xmax"; "Ymin"; "Ymax"; ],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + mess=[] + if plen<=0|csiz<=0 then + mess=[mess;"Pendulum length and cart size must be positive.";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + + if ~ok then + message(mess) + else + rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.rpar=rpar; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + plen=2; + csiz=2; + phi=0; + xmin=-5; + xmax=5; + ymin=-5; + ymax=5 + model=scicos_model() + model.sim=list("anim_pen",5) + model.in=[1;1] + model.evtin=1 + model.dstate=0 + model.rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(model.rpar) + gr_i=[] + x=standard_define([3 3],model,exprs,gr_i) + end + +endfunction ///\withPrompt{} diff --git a/macros/Misc/RATELIMITER.sci b/macros/Misc/RATELIMITER.sci new file mode 100644 index 00000000..c7cbed4e --- /dev/null +++ b/macros/Misc/RATELIMITER.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]=RATELIMITER(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,maxp,minp,exprs]=scicos_getvalue("Set rate limiter parameters",.. + ["max slope";"min slope";],list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if maxp<=minp|maxp<=0|minp>=0 then + message("We must have max_slope> 0 > min_slope.") + else + rpar=[maxp;minp] + model.rpar=rpar + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minp=-1; + maxp=1; + rpar=[maxp;minp] + model=scicos_model() + model.sim=list("ratelimiter",4) + model.in=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(maxp);string(minp)] + gr_i=[] + x=standard_define([3.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/RELATIONALOP.sci b/macros/Misc/RELATIONALOP.sci new file mode 100644 index 00000000..8c0c44b5 --- /dev/null +++ b/macros/Misc/RELATIONALOP.sci @@ -0,0 +1,116 @@ +// 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] = RELATIONALOP(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,1)==2 then + exprs=[exprs;sci2exp(1)]; + end + while %t do + [ok,rule,zcr,Datatype,exprs]=scicos_getvalue("Set parameters",.. + ["Operator: == (0), ~= (1), < (2), <= (3), > (4), >= (5)";.. + "Use zero crossing (no: 0), (yes: 1)" + "Datatype (1=double 3=int32 ...)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + rule=int(rule); + if zcr<>0 then + zcr=1, + end + if (rule<0)|(rule>5) then + message("Incorrect operator "+string(rule)+" ; must be 0 to 5.") + ok=%f; + end + if (Datatype==1) then + model.sim=list("relational_op",4) + elseif (Datatype==3|Datatype==9) then + model.sim=list("relational_op_i32",4) + elseif(Datatype==4) then + model.sim=list("relational_op_i16",4) + elseif(Datatype==5) then + model.sim=list("relational_op_i8",4) + elseif(Datatype==6) then + model.sim=list("relational_op_ui32",4) + elseif(Datatype==7) then + model.sim=list("relational_op_ui16",4) + elseif(Datatype==8) then + model.sim=list("relational_op_ui8",4) + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + it=Datatype*ones(1,2) + ot=Datatype + in=[-1 -2;-1 -2] + out=[-1 -2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + if rule == 0 then + label = "=="; + elseif rule == 1 then + label = "~="; + elseif rule == 2 then + label = "<"; // < + elseif rule == 3 then + label = "≤"; // <= + elseif rule == 4 then + label = ">"; // > + elseif rule == 5 then + label = "≥"; // >= + end + graphics.exprs=exprs; + graphics.style=["fontSize=13;fontStyle=1;displayedLabel="+label]; + model.ipar=[rule], + model.nzcross=zcr, + model.nmode=zcr, + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + ipar=[2] + label="<"; + model=scicos_model() + model.sim=list("relationalop",4) + model.in=[1;1] + model.out=1 + model.ipar=ipar + model.blocktype="c" + model.dep_ut=[%t %f] + exprs=[string(ipar);string(0)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.style=["fontSize=13;fontStyle=1;displayedLabel="+label]; + end +endfunction diff --git a/macros/Misc/SPLIT_f.sci b/macros/Misc/SPLIT_f.sci new file mode 100644 index 00000000..49c757c6 --- /dev/null +++ b/macros/Misc/SPLIT_f.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 +// + +//** 23 Jun 2006 + +function [x,y,typ] = SPLIT_f(job,arg1,arg2) + + + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x=arg1; + + case "define" then + model=scicos_model() ; + model.sim = "lsplit" ; + model.in = -1 ; + model.out = [-1;-1;-1] ; + model.blocktype = "c" ; + model.dep_ut = [%t %f] ; + //** + x=standard_define([1 1]/3,model,[],[]) + end + +endfunction diff --git a/macros/Misc/SUPER_f.sci b/macros/Misc/SUPER_f.sci new file mode 100644 index 00000000..1eee3a59 --- /dev/null +++ b/macros/Misc/SUPER_f.sci @@ -0,0 +1,60 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@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]=SUPER_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + // not used on Xcos, re-implemented for compatibility + xcos(arg1.model.rpar); + + case "define" then + // nested diagram settings (2 ports) + scs=scicos_diagram(); + scs.props.title="Super Block"; + + in = IN_f("define"); + in.graphics.orig = [40, 40]; + in.graphics.sz = [20, 20]; + out = OUT_f("define"); + out.graphics.orig = [240, 40]; + out.graphics.sz = [20, 20]; + + scs.objs(1) = in; + scs.objs(2) = out; + + // block settings + model=scicos_model(); + model.sim="super"; + model.in=1; + model.out=1; + model.rpar=scs; + model.blocktype="h"; + model.dep_ut=[%f %f]; + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Misc/TEXT_f.sci b/macros/Misc/TEXT_f.sci new file mode 100644 index 00000000..de7d62fb --- /dev/null +++ b/macros/Misc/TEXT_f.sci @@ -0,0 +1,117 @@ +// 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]=TEXT_f(job,arg1,arg2) + //** 22-23 Aug 2006: some carefull adjustements for the fonts + //** inside the new graphics datastructure + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x = arg1 ; + graphics = arg1.graphics ; + orig = graphics.orig ; + exprs = graphics.exprs ; + model = arg1.model ; + if size(exprs,"*")==1 then + exprs = [exprs;"3";"1"] + end // compatibility + + while %t do + [ok,txt,font,siz,exprs] = scicos_getvalue("Set Text block parameters",.. + ["Text";"Font number";"Font size"], list("str",-1,"vec",1,"vec",1),exprs) + + if ~ok then + break, + end //** + + if font<=0|font>6 then + message("Font number must be greater than 0 and less than 7") + ok=%f + end + + if siz<0 then + message("Font size must be positive") + ok=%f + end + + if ok then + graphics.exprs = exprs + + //** save the font + //** oldfont = xget('font') + gh_winpal = gca(); //** get the current Axes proprieties + default_font_style = gh_winpal.font_style ; + default_font_size = gh_winpal.font_size ; + default_font_color = gh_winpal.font_color ; + + //** set the new font + //** xset('font',font,siz) + gh_winpal.font_style = font ; + gh_winpal.font_size = siz ; + + + //** store the box coordinate that contains the string + r = xstringl(0,0,exprs(1),evstr(exprs(2)),evstr(exprs(3))); + + //** restore the old font + //** xset('font',oldfont(1),oldfont(2)); + gh_winpal.font_style = default_font_style ; + gh_winpal.font_size = default_font_size ; + gh_winpal.font_color = default_font_color ; + + sz = r(3:4) ; + graphics.sz = sz ; + x.graphics = graphics ; + ipar = [font;siz] + model.rpar = txt ; + model.ipar = ipar ; + x.model = model ; + break + end + + end //** of while + + + case "define" then + font = 2 ; + siz = 1 ; + + model = scicos_model() + model.sim = "text" + model.rpar= "Text" + model.ipar=[font;siz] + + exprs = ["Text";string(font); string(siz)] + graphics = scicos_graphics(); + graphics.orig = [0,0]; + graphics.sz =[2 1]; + graphics.exprs = exprs + + + x = mlist(["Text","graphics","model","void","gui"],graphics,model," ","TEXT_f") + + end + +endfunction diff --git a/macros/Misc/c_block.sci b/macros/Misc/c_block.sci new file mode 100644 index 00000000..a6695407 --- /dev/null +++ b/macros/Misc/c_block.sci @@ -0,0 +1,109 @@ +// 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]=c_block(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + while %t do + [ok,i,o,rpar,funam,lab]=.. + scicos_getvalue("Set C_block parameters",.. + ["input ports sizes"; + "output port sizes"; + "System parameters vector"; + "function name"],.. + list("vec",-1,"vec",-1,"vec",-1,"str",-1),label(1)) + if ~ok then + break, + end + if funam==" " then + break, + end + label(1)=lab + rpar=rpar(:) + i=int(i(:)); + ni=size(i,1); + o=int(o(:)); + no=size(o,1); + tt=label(2); + if model.sim(1)<>funam|size(model.in,"*")<>size(i,"*").. + |size(model.out,"*")<>size(o,"*") then + tt=[] + end + [ok,tt]=CFORTR(funam,tt,i,o) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,i,o,[],[]) + if ok then + model.sim(1)=funam + model.rpar=rpar + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + funam="toto" + //chek + + //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ + //model=list(list(' ',2001),in,out,clkin,clkout,x0,z0,rpar,0,typ,auto,[%t %f],.. + // ' ',list()); + + model=scicos_model() + model.sim=list(" ",2001) + model.in=in + model.out=out + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=0 + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + //********************************************************************************** + label=list([sci2exp(in);sci2exp(out); strcat(sci2exp(rpar));funam],.. + list([])) + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction diff --git a/macros/Misc/fortran_block.sci b/macros/Misc/fortran_block.sci new file mode 100644 index 00000000..f3abb85d --- /dev/null +++ b/macros/Misc/fortran_block.sci @@ -0,0 +1,93 @@ +// 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]=fortran_block(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + while %t do + [ok,i,o,rpar,funam,lab]=.. + scicos_getvalue("Set fortran_block parameters",.. + ["input ports sizes"; + "output port sizes"; + "System parameters vector"; + "function name"],.. + list("vec",-1,"vec",-1,"vec",-1,"str",-1),label(1)) + if ~ok then + break, + end + if funam==" " then + break, + end + label(1)=lab + rpar=rpar(:) + i=int(i(:)); + ni=size(i,1); + o=int(o(:)); + no=size(o,1); + tt=label(2); + if model.sim(1)<>funam|size(model.in,"*")<>size(i,"*").. + |size(model.out,"*")<>size(o,"*") then + tt=[] + end + [ok,tt]=FORTR(funam,tt,i,o) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,i,o,[],[]) + if ok then + model.sim(1)=funam + model.rpar=rpar + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + case "define" then + model=scicos_model() + model.sim=list(" ",1001) + model.in=1 + model.out=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=0 + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + funam="forty" + label=list([sci2exp(model.in);sci2exp(model.out);.. + strcat(sci2exp(model.rpar));funam],list([])) + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction diff --git a/macros/Misc/func_block.sci b/macros/Misc/func_block.sci new file mode 100644 index 00000000..03a1adec --- /dev/null +++ b/macros/Misc/func_block.sci @@ -0,0 +1,98 @@ +// 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]=func_block(job,arg1,arg2) + //%Description + // job=='plot' : block drawing + // arg1 is block data structure + // arg2 :unused + // job=='getinputs' : return position and type of inputs ports + // arg1 is block data structure + // x : x coordinates of ports + // x : y coordinates of ports + // typ: type of ports + // job=='getoutputs' : return position and type of outputs ports + // arg1 is block data structure + // x : x coordinates of ports + // x : y coordinates of ports + // typ: type of ports + // job=='getorigin' : return block origin coordinates + // x : x coordinates of block origin + // x : y coordinates of block origin + // job=='set' : block parameters acquisition + // arg1 is block data structure + // x is returned block data structure + // job=='define' : corresponding block data structure initialisation + // arg1: name of block parameters acquisition macro + // x : block data structure + //%Block data-structure definition + // bl=list('Block',graphics,model,init,'standard_block') + // graphics=list([xo,yo],[l,h],orient,exprs) + // xo - x coordinate of block origin + // yo - y coordinate of block origin + // l - block width + // h - block height + // orient - boolean, specifies if block is tilded + // exprs - string block exprs + // model=list(eqns,#input,#output,#clk_input,#clk_output,state,.. + // rpar,ipar,typ [,firing]) + // eqns - function name (in string form if fortran routine) + // #input - number of inputs + // #output - number of outputs + // #clk_input - number of clock inputs + // #clk_output - number of clock outputs + // state - vector (column) of initial condition + // rpar - vector (column) of real parameters + // ipar - vector (column) of integer parameters + // typ - string: 'c' if block is continuous, 'd' if discrete + // 'z' if zero-crossing. + // firing - boolean initial clock firing if true + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + x=arg1 + model=x.model + [ok,mac,exprs]=genfunc(exprs) + if ok then + model.sim=mac + graphics.exprs=exprs + x.model=model + x.graphics=graphics + end + case "define" then + model=scicos_model() + model.sim=" " + model.in=1 + model.out=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs="v=sin(u);y=u*v" + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/generic_block.sci b/macros/Misc/generic_block.sci new file mode 100644 index 00000000..f40a589c --- /dev/null +++ b/macros/Misc/generic_block.sci @@ -0,0 +1,143 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=generic_block(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,function_name,funtyp,i,o,ci,co,xx,z,rpar,ipar,auto0,depu,dept,lab]=.. + scicos_getvalue("Set GENERIC block parameters",.. + ["simulation function"; + "function type (0,1,2,..)"; + "input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "Real parameters vector"; + "Integer parameters vector"; + "initial firing vector (<0 for no firing)"; + "direct feedthrough (y or n)"; + "time dependence (y or n)"],.. + list("str",1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec","sum(%6)",.. + "str",1,"str",1),label) + if ~ok then + break, + end + label=lab + function_name=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + i=int(i(:)); + o=int(o(:)); + ci=int(ci(:)); + co=int(co(:)); + funtyp=int(funtyp) + if funtyp<0 then + message("function type cannot be negative"); + ok=%f; + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + if ok then + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + end + if ok then + // AVERIFIER + if funtyp==3 then + needcompile=4; + end + model.sim=list(function_name,funtyp); + model.state=xx + model.dstate=z + model.rpar=rpar + model.ipar=ipar + // needcompile=4 AVERIFIER CANEMARCHEQUAVECFORTRAN + model.firing=auto0 + model.dep_ut=dep_ut + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="sinblk"; + funtyp=1; + model.sim=list(function_name,funtyp) + + model.in=1 + model.out=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[function_name;sci2exp(funtyp); + sci2exp(model.in);sci2exp(model.out); + sci2exp(model.evtin);sci2exp(model.evtout); + sci2exp(model.state);sci2exp(model.dstate); + sci2exp(model.rpar);sci2exp(model.ipar); + sci2exp(model.firing);"y";"n"]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/generic_block2.sci b/macros/Misc/generic_block2.sci new file mode 100644 index 00000000..ae05dc2b --- /dev/null +++ b/macros/Misc/generic_block2.sci @@ -0,0 +1,148 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=generic_block2(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,function_name,funtyp,i,o,ci,co,xx,z,rpar,ipar,nmode,nzcr,auto0,depu,dept,lab]=.. + scicos_getvalue("Set GENERIC block parameters",.. + ["simulation function"; + "function type (0,1,2,..)"; + "input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "Real parameters vector"; + "Integer parameters vector"; + "number of modes"; + "number of zero_crossings"; + "initial firing vector (<0 for no firing)"; + "direct feedthrough (y or n)"; + "time dependence (y or n)"],.. + list("str",1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",1,"vec",1,"vec","sum(%6)",.. + "str",1,"str",1),label) + if ~ok then + break, + end + label=lab + function_name=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + i=int(i(:)); + o=int(o(:)); + ci=int(ci(:)); + co=int(co(:)); + funtyp=int(funtyp) + if funtyp<0 then + message("function type cannot be negative"); + ok=%f; + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + if ok then + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + end + if ok then + // AVERIFIER + if funtyp==3 then + needcompile=4; + end + model.sim=list(function_name,funtyp); + model.state=xx + model.dstate=z + model.rpar=rpar + model.ipar=ipar + // needcompile=4 AVERIFIER CANEMARCHEQUAVECFORTRAN + model.firing=auto0 + model.nzcross=nzcr + model.nmode=nmode + model.dep_ut=dep_ut + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="sinblk"; + funtyp=1; + model.sim=list(function_name,funtyp) + + model.in=1 + model.out=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[function_name;sci2exp(funtyp); + sci2exp(model.in);sci2exp(model.out); + sci2exp(model.evtin);sci2exp(model.evtout); + sci2exp(model.state);sci2exp(model.dstate); + sci2exp(model.rpar);sci2exp(model.ipar); + sci2exp(model.nmode);sci2exp(model.nzcross); + sci2exp(model.firing);"y";"n"]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/generic_block3.sci b/macros/Misc/generic_block3.sci new file mode 100644 index 00000000..1ed616d1 --- /dev/null +++ b/macros/Misc/generic_block3.sci @@ -0,0 +1,164 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=generic_block3(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,function_name,funtyp,in,it,out,ot,ci,co,xx,z,oz,... + rpar,ipar,opar,nmode,nzcr,auto0,depu,dept,lab]=.. + scicos_getvalue("Set GENERIC block parameters",.. + ["Simulation function"; + "Function type (0,1,2,..)"; + "Input ports sizes"; + "Input ports type"; + "Output port sizes"; + "Output ports type"; + "Input event ports sizes"; + "Output events ports sizes"; + "Initial continuous state"; + "Initial discrete state"; + "Initial object state"; + "Real parameters vector"; + "Integer parameters vector"; + "Object parameters list"; + "Number of modes"; + "Number of zero crossings"; + "Initial firing vector (<0 for no firing)"; + "Direct feedthrough (y or n)"; + "Time dependence (y or n)"],.. + list("str",1,"vec",1,"mat",[-1 2],"vec",-1,"mat",[-1 2],"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"lis",-1,"vec",-1,"vec",-1,"lis",-1,"vec",1,"vec",1,"vec","sum(%8)",.. + "str",1,"str",1),label) + if ~ok then + break, + end + label=lab + function_name=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + ci=int(ci(:)); + co=int(co(:)); + funtyp=funtyp + if funtyp<0 then + message("function type cannot be negative"); + ok=%f; + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + if type(opar)<>15 then + message("object parameter must be a list"); + ok=%f; + end + if type(oz)<>15 then + message("discrete object state must be a list"); + ok=%f; + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ci,co) + end + if ok then + if funtyp==3 then + needcompile=4; + end + model.sim=list(function_name,funtyp); + model.state=xx + model.dstate=z + model.odstate=oz + model.rpar=rpar + model.ipar=ipar + model.opar=opar + model.firing=auto0 + model.nzcross=nzcr + model.nmode=nmode + model.dep_ut=dep_ut + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="sinblk"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=1 + model.in2=1 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.dep_ut=[%t %f] + label=[function_name;sci2exp(funtyp); + sci2exp([model.in model.in2]); + sci2exp(model.intyp); + sci2exp([model.out model.out2]) + sci2exp(model.outtyp); + sci2exp(model.evtin); + sci2exp(model.evtout); + sci2exp(model.state); + sci2exp(model.dstate); + sci2exp(model.odstate); + sci2exp(model.rpar); + sci2exp(model.ipar); + sci2exp(model.opar); + sci2exp(model.nmode); + sci2exp(model.nzcross); + sci2exp(model.firing);"y";"n"]; + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/scifunc_block.sci b/macros/Misc/scifunc_block.sci new file mode 100644 index 00000000..6407be95 --- /dev/null +++ b/macros/Misc/scifunc_block.sci @@ -0,0 +1,161 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=scifunc_block(job,arg1,arg2) + //%Description + // job=='set' : block parameters acquisition + // arg1 is block data structure + // x is returned block data structure + // job=='define' : corresponding block data structure initialisation + // arg1: name of block parameters acquisition macro + // x : block data structure + //%Block data-structure definition + // bl=list('Block',graphics,model,init,'standard_block') + // graphics=list([xo,yo],[l,h],orient,label) + // xo - x coordinate of block origin + // yo - y coordinate of block origin + // l - block width + // h - block height + // orient - boolean, specifies if block is tilded + // label - string block label + // model=list(eqns,#input,#output,#clk_input,#clk_output,state,.. + // rpar,ipar,typ [,firing]) + // eqns - function name (in string form if fortran routine) + // #input - vector of input port sizes + // #output - vector of output port sizes + // #clk_input - vector of clock inputs port sizes + // #clk_output - vector of clock output port sizes + // state - vector (column) of initial condition + // rpar - vector (column) of real parameters + // ipar - vector (column) of integer parameters + // typ - string: 'c' if block is continuous, 'd' if discrete + // 'z' if zero-crossing. + // firing - vector of initial output event firing times + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + needcompile=0 + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + + if size(exprs(1),"*")==8 then + exprs(1)(9)="0"; + end + while %t do + [ok,i,o,ci,co,xx,z,rpar,auto0,deptime,lab]=scicos_getvalue(.. + ["Set scifunc_block parameters";"only regular blocks supported"],.. + ["input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "System parameters vector"; + "initial firing vector (<0 for no firing)"; + "is block always active (0:no, 1:yes)" ],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec","sum(%4)","vec",1),exprs(1)) + if ~ok then + break, + end + exprs(1)=lab + xx=xx(:); + z=z(:); + rpar=rpar(:) + nrp=prod(size(rpar)) + // create simulator + i=int(i(:)); + ni=size(i,1); + o=int(o(:)); + no=size(o,1); + ci=int(ci(:)); + nci=size(ci,1); + co=int(co(:)); + nco=size(co,1); + [ok,tt,dep_ut]=genfunc1(exprs(2),i,o,nci,nco,size(xx,1),size(z,1),.. + nrp,"c") + dep_ut(2)=(1==deptime) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + if ok then + auto=auto0 + model.state=xx + model.dstate=z + model.rpar=rpar + if model.ipar <> 0 then + model.opar=model.ipar; + model.ipar=0; + end + if or(model.opar<>tt) then + needcompile=4, + end + model.opar=tt + model.firing=auto + model.dep_ut=dep_ut + x.model=model + exprs(2)=tt + graphics.exprs=exprs + x.graphics=graphics + break + end + end + needcompile=resume(needcompile) + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + + model=scicos_model() + model.sim=list("scifunc",3) + model.in=in + model.out=out + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=0 + model.opar=list() + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + + exprs=list([sci2exp(in);sci2exp(out);sci2exp(clkin);sci2exp(clkout); + strcat(sci2exp(x0));strcat(sci2exp(z0)); + strcat(sci2exp(rpar));sci2exp(auto)],.. + list("y1=sin(u1)"," "," ","y1=sin(u1)"," "," "," ")) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/scifunc_block_m.sci b/macros/Misc/scifunc_block_m.sci new file mode 100644 index 00000000..be0b17ae --- /dev/null +++ b/macros/Misc/scifunc_block_m.sci @@ -0,0 +1,143 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=scifunc_block_m(job,arg1,arg2) + //%Description + // job=='set' : block parameters acquisition + // arg1 is block data structure + // x is returned block data structure + // job=='define' : corresponding block data structure initialisation + // arg1: name of block parameters acquisition macro + // x : block data structure + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + needcompile=0 + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + + while %t do + [ok,i,o,ci,co,xx,z,rpar,auto0,deptime,lab]=scicos_getvalue(.. + ["Set scifunc_block parameters";"only regular blocks supported"],.. + ["input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "System parameters vector"; + "initial firing vector (<0 for no firing)"; + "is block always active (0:no, 1:yes)"],.. + list("mat",[-1 2],"mat",[-2 2],"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",1),exprs(1)) + if ~ok then + break, + end + exprs(1)=lab + xx=xx(:); + z=z(:); + rpar=rpar(:) + it=ones(1,size(i,1)) + ot=ones(1,size(o,1)) + nrp=prod(size(rpar)) + // create simulator + //i=int(i(:)); + ni=size(i,1); + //o=int(o(:)); + no=size(o,1); + ci=int(ci(:)); + nci=size(ci,1); + co=int(co(:)); + nco=size(co,1); + [ok,tt,dep_ut]=genfunc2(exprs(2),i,o,nci,nco,size(xx,1),size(z,1),.. + nrp,"c") + dep_ut(2)=(1==deptime) + if ~ok then + break, + end + //[model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + [model,graphics,ok]=set_io(model,graphics,list(i,it),list(o,ot),ci,co) + if ok then + auto=auto0 + model.state=xx + model.dstate=z + model.rpar=rpar + if model.ipar <> 0 then + model.opar=model.ipar; + model.ipar=0; + end + if or(model.opar<>tt) then + needcompile=4, + end + model.opar=tt + model.firing=auto + model.dep_ut=dep_ut + x.model=model + exprs(2)=tt + graphics.exprs=exprs + x.graphics=graphics + break + end + end + needcompile=resume(needcompile) + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + it=1 + model=scicos_model() + model.sim=list("scifunc",3) + model.in=in + model.in2=in + model.intyp=it + model.out=out + model.out2=out + model.outtyp=it + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=0; + model.opar=list(); + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + + exprs=list([sci2exp([in in]);sci2exp([out out]);sci2exp(clkin);sci2exp(clkout); + strcat(sci2exp(x0));strcat(sci2exp(z0)); + strcat(sci2exp(rpar));sci2exp(auto);sci2exp(0)],.. + list("y1=sin(u1)"," "," ","y1=sin(u1)"," "," "," ")) + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/ABSBLK_f.sci b/macros/NonLinear/ABSBLK_f.sci new file mode 100644 index 00000000..d59ab10a --- /dev/null +++ b/macros/NonLinear/ABSBLK_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]=ABSBLK_f(job,arg1,arg2) + //Absolute value block GUI. + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim=list("absblk",1) + model.in=-1 + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/NonLinear/ABS_VALUE.sci b/macros/NonLinear/ABS_VALUE.sci new file mode 100644 index 00000000..bd6a5650 --- /dev/null +++ b/macros/NonLinear/ABS_VALUE.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]=ABS_VALUE(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,zcr,exprs]=.. + scicos_getvalue("Set block parameters",.. + ["use zero_crossing (1: yes) (0:no)"],.. + list("vec",1),exprs) + if ~ok then + break, + end + graphics.exprs=exprs + if ok then + if zcr<>0 then + model.nmode=-1; + model.nzcross=-1; + else + model.nmode=0; + model.nzcross=0; + end + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nu=-1 + model=scicos_model() + model.sim=list("absolute_value",4) + model.in=nu + model.out=nu + model.nzcross=nu + model.nmode=nu + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string([1])] + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/COSBLK_f.sci b/macros/NonLinear/COSBLK_f.sci new file mode 100644 index 00000000..fcdcec26 --- /dev/null +++ b/macros/NonLinear/COSBLK_f.sci @@ -0,0 +1,41 @@ +// 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]=COSBLK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=1 + model=scicos_model() + model.sim="cosblk" + model.in=-1 + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/NonLinear/DLRADAPT_f.sci b/macros/NonLinear/DLRADAPT_f.sci new file mode 100644 index 00000000..b26c662e --- /dev/null +++ b/macros/NonLinear/DLRADAPT_f.sci @@ -0,0 +1,96 @@ +// 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]=DLRADAPT_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,p,rn,rd,g,last_u,last_y,exprs]=scicos_getvalue("Set block parameters",.. + ["Vector of p mesh points"; + "Numerator roots (one line for each mesh)"; + "Denominator roots (one line for each mesh)"; + "Vector of gain at mesh points" ; + "past inputs (Num degree values)"; + "past outputs (Den degree values)"],.. + list("vec",-1,"mat",[-1,-1],"mat",.. + ["size(%1,''*'')","-1"],"vec","size(%1,''*'')",.. + "vec","size(%2,2)","vec","size(%3,2)"),exprs) + + + if ~ok then + break, + end + m=size(rn,2) + [npt,n]=size(rd) + if m>=n then + message("Transfer must be strictly proper"), + elseif size(rn,1)<>0&size(rn,1)<>size(p,"*") then + message("Numerator roots matrix row size''s is incorrect") + else + rpar=[p(:);real(rn(:));imag(rn(:));real(rd(:));imag(rd(:));g(:)] + ipar=[m;n;npt] + model.dstate=[last_u(:);last_y(:)] + model.rpar=rpar + model.ipar=ipar + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break; + end + end + case "define" then + p=[0;1] + rn=[] + rd=[0.2+0.8*%i,0.2-0.8*%i;0.3+0.7*%i,0.3-0.7*%i] + g=[1;1] + last_u=[] + last_y=[0;0] + + model=scicos_model() + model.sim="dlradp" + model.in=[1;1] + model.out=1 + model.evtin=1 + + model.dstate=[last_u;last_y] + model.rpar=[p(:);real(rn(:));imag(rn(:));real(rd(:));imag(rd(:));g(:)] + model.ipar=[0;2;2] + model.blocktype="d" + model.firing=[] + model.dep_ut=[%t %f] + + exprs=[sci2exp(p); + sci2exp(rn); + sci2exp(rd,0); + sci2exp(g); + sci2exp(last_u); + sci2exp(last_y)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/EXPBLK_f.sci b/macros/NonLinear/EXPBLK_f.sci new file mode 100644 index 00000000..0c4dd55b --- /dev/null +++ b/macros/NonLinear/EXPBLK_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]=EXPBLK_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 + while %t do + [ok,a,exprs]=scicos_getvalue("Set a^u block parameters",.. + "a (>0)",list("vec",1),exprs) + if ~ok then + break, + end + if or(a<=0) then + message("a^u : a must be positive") + else + graphics.exprs=exprs + model.rpar=a; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=1 + a=%e + model=scicos_model() + model.sim="expblk" + model.in=-1 + model.out=-1 + model.rpar=a + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=["%e"] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/EXPBLK_m.sci b/macros/NonLinear/EXPBLK_m.sci new file mode 100644 index 00000000..f0059b22 --- /dev/null +++ b/macros/NonLinear/EXPBLK_m.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]=EXPBLK_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,"*")==2 then + exprs=exprs(2), + end + while %t do + [ok,a,exprs]=scicos_getvalue("Set a^u block parameters",.. + "a (>0)",list("vec",1),exprs) + if ~ok then + break, + end + if or(a<=0) then + message("a^u : a must be positive") + else + graphics.exprs=exprs + model.rpar=a; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=1 + a=%e + model=scicos_model() + model.sim=list("expblk_m",4) + model.in=-1 + model.in2=-2 + model.out=-1 + model.out2=-2 + model.intyp=1 + model.outtyp=1 + model.rpar=a + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=["%e"] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/FSV_f.sci b/macros/NonLinear/FSV_f.sci new file mode 100644 index 00000000..00db92d3 --- /dev/null +++ b/macros/NonLinear/FSV_f.sci @@ -0,0 +1,43 @@ +// 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]=FSV_f(job,arg1,arg2) + //Absolute value block GUI. + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=1 //One input/output port with undefinite dimension + model=scicos_model() + model.sim=list("fsv",1) + model.in=in + model.out=in + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=" " + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/INTRP2BLK_f.sci b/macros/NonLinear/INTRP2BLK_f.sci new file mode 100644 index 00000000..c64c7c03 --- /dev/null +++ b/macros/NonLinear/INTRP2BLK_f.sci @@ -0,0 +1,69 @@ +// 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]=INTRP2BLK_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,a,b,c,exprs]=scicos_getvalue("Set Interpolation block parameters",.. + ["X coord.";"Y coord.";"Z values"],list("vec",-1,"vec",-1,"mat",[-1,-1]),exprs) + if ~ok then + break, + end + if size(a,"*") <> size(c,"c") | size(b,"*") <> size(c,"r") then + message("incompatible dimension") + elseif min(a(2:$)-a(1:$-1)) <=0 | min(b(2:$)-b(1:$-1)) <=0 then + message("X and Y must be strictly increasing") + else + if ok then + graphics.exprs=exprs + model.rpar=[a(:);b(:);c(:)] + model.ipar=[size(a,"*");size(b,"*")] + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + a=[0;1]; + b=[0;1]; + c=[0 1;1 2] + model=scicos_model() + model.sim=list("intrp2",1) + model.in=[1;1] + model.out=1 + model.rpar=[a;b;c(:)] + model.ipar=[2;2] + model.blocktype="c" + model.dep_ut=[%t %f] + exprs=[strcat(sci2exp(a));strcat(sci2exp(b));strcat(sci2exp(c,0))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/INTRPLBLK_f.sci b/macros/NonLinear/INTRPLBLK_f.sci new file mode 100644 index 00000000..0ab7f5b0 --- /dev/null +++ b/macros/NonLinear/INTRPLBLK_f.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]=INTRPLBLK_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,a,b,exprs]=scicos_getvalue("Set Interpolation block parameters",.. + ["X coord.";"Y coord."],list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + if size(a,"*") <> size(b,"*") then + message("X and Y must have the same size") + elseif min(a(2:$)-a(1:$-1)) <=0 then + message("X must be strictly increasing") + else + if ok then + graphics.exprs=exprs + model.rpar=[a(:);b(:)] + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + a=[0;1]; + b=[0;1] + model=scicos_model() + model.sim="intrpl" + model.in=1 + model.out=1 + model.rpar=[a;b] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(a));strcat(sci2exp(b))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/INVBLK.sci b/macros/NonLinear/INVBLK.sci new file mode 100644 index 00000000..4960187a --- /dev/null +++ b/macros/NonLinear/INVBLK.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]=INVBLK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=-1 + model=scicos_model() + model.sim=list("invblk4",4) + model.in=in + model.out=in + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=" " + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/INVBLK_f.sci b/macros/NonLinear/INVBLK_f.sci new file mode 100644 index 00000000..65391d7c --- /dev/null +++ b/macros/NonLinear/INVBLK_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]=INVBLK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=-1 + model=scicos_model() + model.sim="invblk" + model.in=in + model.out=in + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=" " + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/LOGBLK_f.sci b/macros/NonLinear/LOGBLK_f.sci new file mode 100644 index 00000000..eb857172 --- /dev/null +++ b/macros/NonLinear/LOGBLK_f.sci @@ -0,0 +1,68 @@ +// 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]=LOGBLK_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,a,exprs]=scicos_getvalue("Set log block parameters",.. + "Basis (>1)",list("vec",1),exprs) + if ~ok then + break, + end + if a<=1 then + message("Basis must be larger than 1") + else + if ok then + graphics.exprs=exprs + model.rpar=a + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + in=1 + a=%e + model=scicos_model() + model.sim="logblk" + model.in=-1 + model.out=-1 + model.rpar=a + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs="%e" + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/LOOKUP2D.sci b/macros/NonLinear/LOOKUP2D.sci new file mode 100644 index 00000000..62df228b --- /dev/null +++ b/macros/NonLinear/LOOKUP2D.sci @@ -0,0 +1,166 @@ +// 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]=LOOKUP2D(job,arg1,arg2) + // Copyright INRIA + + 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,xx,yy,zz,Method,graf,exprs]=scicos_getvalue("2D Lookup table parameters",["Row index input values";"Column index input values";"Table data";"Lookup method(1..5)";"Launch graphic window(y/n)?"],list("vec",-1,"vec",-1,"mat",[-1,-1],"vec",1,"str",1),exprs) + // 1 : Interpolation-extrapolation (Bilinear) + // 2 : Interpolation_endvalues + // 3 : use input nearest + // 4 : use input below + // 5 : use input above + // 6 : Interpolation-extrapolation (linear) + + if ~ok then + break; + end + mtd=int(Method); + if mtd<1 then + mtd=1; + end; + if mtd>6 then + mtd=6; + end; + if graf<>"y" & graf<>"Y" then + graf="n"; + end + exprs(5)="n";// exprs.graf='n' + exprs(4)=sci2exp(mtd);// pour le cas methode>7 | method<0 + + METHOD=getmethod(mtd); + if ~Ask_again then + xx=xx(:); + yy=yy(:); + [nx,mx]=size(xx); + [ny,my]=size(yy); + [nz,mz]=size(zz); + if ((nx<=1)|(ny<=1)) then, + x_message("input row/column data size should be greater than one"); + Ask_again=%t; + end + if ~((nx==nz)&(ny==mz)) then, + x_message("incompatible size of x and y"); + Ask_again=%t; + end + [ok]=test_increasing(xx); + if (~ok) then + x_message("Row input values must be monotonically increasing"); + Ask_again=%t; + end + [ok]=test_increasing(yy); + if (~ok) then + x_message("Column input values must be monotonically increasing"); + Ask_again=%t; + end + end + if ~Ask_again then + if (graf=="Y" | graf=="y") then + gh=gcf(); + curwin=gh.figure_id; + save_curwin=curwin; + gh2=scf(); + curwin=max(winsid())+1; + plot3d(xx,yy,zz,35,45,"X@Y@Z",[5,2,4]) ; + curwin=save_curwin; + gh.figure_id=curwin; + end + + model.rpar=[xx(:);yy(:);zz(:)] + model.ipar=[nx;ny;mtd] + graphics.exprs=exprs; + x.model=model + x.graphics=graphics + break + end + end + //====================================================================== + case "define" then + model=scicos_model(); + xx=[1:4] + yy=[1:3] + zz=[4,5,6;16,19,20;10,18,23;6, 3,-1]; + Method=1; + Graf="n" + + Nx=length(xx); + Ny=length(yy); + model.sim=list("lookup2d",4) + model.in=[1;1] + model.out=1 + + model.rpar=[xx(:);yy(:);zz(:)] + model.ipar=[Nx;Ny;Method] + model.blocktype="c" + model.dep_ut=[%t %f] + exprs=list(strcat(sci2exp(xx)),strcat(sci2exp(yy)),strcat(sci2exp(zz)),sci2exp(Method),Graf) + gr_i=[] + + x=standard_define([2.5 2],model,exprs,gr_i) + end +endfunction + +function [ok]=test_increasing(xx) + ok=%f + [nx,mx]=size(xx);// adjusting the x and y size + + for i=1:mx + if (xx(i)<>xx(i)) then + xinfo("x contains no data in x("+string(i)+")"); + return; + end + + end + + for i=1:mx-1 + if (xx(i)>xx(i+1)) then + return; + end + end + + ok=%t +endfunction +//============================ +function METHOD=getmethod(order) + select order + case 1 then, METHOD="Interpolation-extrapolation(biliniear)" + case 2 then, METHOD="Interpolation_endvalues" + case 3 then, METHOD="use input nearest" + case 4 then, METHOD="use input below" + case 5 then, METHOD="use input above" + case 6 then, METHOD="Interpolation-extrapolation" + end +endfunction +//========================================================= diff --git a/macros/NonLinear/LOOKUP_c.sci b/macros/NonLinear/LOOKUP_c.sci new file mode 100644 index 00000000..bef8e615 --- /dev/null +++ b/macros/NonLinear/LOOKUP_c.sci @@ -0,0 +1,1338 @@ +// 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]=LOOKUP_c(job,arg1,arg2) + // Masoud Najafi 01/2008 -------- + // origine: serge Steer, Habib Jreij INRIA 1993 + // Copyright INRIA + + 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,extrapo,graf,exprs]=scicos_getvalue("Lookup table parameters",.. + ["Spline Interpolation method (0..9)";.. + "x";"y";"Extrapolate method (0,1)";"Launch graphic window(y/n)?"],.. + list("vec",1,"vec",-1,"vec",-1,"vec",1,"str",1),exprs) + // 9 : nearest + // 8 : above + // 0: below + // extra: 0:hold; 1: use end values + // + + if ~ok then + break; + end + PeriodicOption="n"; + + if PeriodicOption=="y" | PeriodicOption=="Y" then, + PO=1; + else, + PO=0; + end + mtd=int(Method); + if mtd<0 then + mtd=0; + end; + if mtd>9 then + mtd=9; + end; + METHOD=getmethod(mtd); + extrapo=int(extrapo); + if extrapo<0 then + extrapo=0; + end; + if extrapo>1 then + extrapo=1; + end; + + + if ~Ask_again then + xx=xx(:); + yy=yy(:); + [nx,mx]=size(xx); + [ny,my]=size(yy); + if ~((nx==ny)&(mx==my)) then, + x_message("incompatible size of x and y"); + 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;extrapo]; + rpar=[]; + if ~exists("curwin") then + gh=gcf(); + curwin=gh.figure_id + end + save_curwin=curwin; + curwin=max(winsid())+1; + [orpar,oipar,ok]=poke_point(xy,ipar,rpar); + curwin=save_curwin; + 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); + exprs(4)=sci2exp(oipar(4)); + if oipar(3)==1 then, + perop="y"; + else, + perop="n"; + end + SaveExit=%t + else//_____________________No graphics__________________________ + [Xdummy,Ydummy,orpar]=Do_Spline(N,mtd,xy(:,1),xy(:,2),xy($,1),xy(1,1),0); + 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-below"|METHOD=="linear"|METHOD=="zero order-above"|METHOD=="zero order-nearest") then + orpar=[xy(:,1);xy(:,2);] + end + end + exprs(1)=sci2exp(mtd);// pour le cas methode>7 | method<0 + oipar=[N;mtd;PO;extrapo] + 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=[-1;0.5;1;1.5;2.5] + yy=[-6;-1;-3;3;-4] + N=length(xx); + Method=1; + Graf="n" + model.sim=list("lookup_c",4) + model.in=-1 + model.in2=-2 + model.outtyp=-1 + + model.out=-1 + model.out2=-2 + model.outtyp=-1 + + model.rpar=[xx(:);yy(:)] + model.ipar=[N;Method;0;0] + model.blocktype="c" + model.dep_ut=[%t %f] + model.evtin=[] + model.evtout=[] + model.firing=0 + exprs=[sci2exp(Method);sci2exp(xx);sci2exp(yy);sci2exp(0);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) + //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 == -100 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 provided"); + return + end + + [xy]=cleandata(ixy) + N=size(xy,"r"); + + if rhs<=1 then + NOrder=1; + PeridicOption=0; + extrapo=0 + ipar=[N;NOrder;PeridicOption;extrapo] + rpar=[] + elseif rhs==2 then + NOrder=iparin(2); + PeridicOption=iparin(3); + extrapo=iparin(4); + ipar=iparin; + rpar=[] + elseif rhs==3 then + NOrder=iparin(2); + PeridicOption=iparin(3); + extrapo=iparin(4); + ipar=iparin; + rpar=rparin + 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)), + 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]; + //=================================================================== + f=scf(); + + if getos() <> "Windows" then + delmenu(curwin,"3D Rot.") + delmenu(curwin,"Edit") + delmenu(curwin,"File") + delmenu(curwin,"Insert") + else + hidetoolbar(curwin) + // French + delmenu(curwin,"&Fichier") + delmenu(curwin,"&Editer") + delmenu(curwin,"&Outils") + delmenu(curwin,"&Inserer") + // English + delmenu(curwin,"&File") + delmenu(curwin,"&Edit") + delmenu(curwin,"&Tools") + delmenu(curwin,"&Insert") + end + //menuss=menus;menuss(1)=menus(1)(2:$);menubar(curwin,menuss) + + menu_r=[]; + menu_s=[]; + menu_o=["zero order-below","linear","order 2","not_a_knot","periodic","monotone","fast","clamped","zero order-above","zero order-nearest"] + menu_d=["Clear","Data Bounds","Load from text file","Save to text file","Load from Excel","Extrapolation"] + 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) + //=================================================================== + //initial draw + drawlater(); + a=gca(f); + 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(); + 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-below") | (Cmenu=="linear") | (Cmenu=="order 2")| ... + (Cmenu=="not_a_knot")| (Cmenu=="periodic")| (Cmenu=="monotone")| ... + (Cmenu=="fast")| (Cmenu=="clamped") |(Cmenu=="zero order-above")|(Cmenu=="zero order-nearest")) then + + select Cmenu + case "zero order-below" 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; + case "zero order-above" then + NOrder=8; + case "zero order-nearest" then + NOrder=9; + 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 mok then + a.data_bounds=[xmn1,ymn1;xmx1,ymx1]; + end + end + //drawnow(); + //------------------------------------------------------------------- + case "Autoscale" then + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + //------------------------------------------------------------------- + case "Extrapolation" then + //extrapo + if extrapo==1 then, + ans0="1", + else, + ans0="0", + end; + [mok,myans]=scicos_getvalue("Extrapolation method (just for Method 1)",["0: hold end values, 1: extrapolation"],list("vec",1),list(ans0)); + if (mok==%t) then + extrapo=int(myans); + if extrapo<0 then + extrapo=0; + end; + if extrapo>1 then + extrapo=1; + end; + ipar(4)=extrapo; + [rpar,ipar]=AutoScale(a,xy,ipar,rpar) + end + //------------------------------------------------------------------- + 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(% of 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-below"|METHOD=="linear"|METHOD=="zero order-above"|METHOD=="zero order-nearest") + 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''" + x_message([t1;t2;t3;t4;t5]); + //--------------------------------------------------------------- + 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 + 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 + + if (HIT)&(btn==2 | btn==5) then // remove point + xy(k,:)=[]; + 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); + extrapo=iipar(4); + 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 + + xmx=max(points.data(:,1)); + xmn=min(points.data(:,1)); + xmx1=max(a.x_ticks.locations); + xmn1=min(a.x_ticks.locations) + xmx=max(xmx,xmx1); + xmn=min(xmn,xmn1); + [X,Y,orpar]=Do_Spline(N,order,x,y,xmx,xmn,extrapo); + + if (periodicoption==1) then + X=[X;X($)]; + Y=[Y;Y(1)]; + else + //X=[X;XMX]; + //Y=[Y;Y($)]; + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + splines.data=[X,Y]; + oipar=[N;iipar(2);periodicoption;extrapo] +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); + + x(k)=[]; + y(k)=[]; + + btn=-1 + + while ~(btn==3 | btn==0| btn==10| btn==-5) + rep=xgetmouse([%t %t]); + xc=rep(1); + yc=rep(2); + btn=rep(3); + + 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(xmx); + XMN=max(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=part(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 + + [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-below" + 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" + case 8 then, + METHOD="zero order-above" + case 9 then, + METHOD="zero order-nearest" + end +endfunction +//======================================= +function [sok,xye]=ReadFromFile() + xye=[]; + sok=%f; + while %t + [sok,filen,Cformat,Cx,Cy]=scicos_getvalue("Text data file ",["Filename";"Reading [C] format";"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] format"],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,xmx,xmn,extrapo) + X=[]; + Y=[]; + orpar=[]; + + METHOD=getmethod(order); + + if (METHOD=="zero order-below") then + X=[xmn;x(1)]; + Y=[y(1);y(1)]; + for i=1:N-1 + X=[X;x(i+1);x(i+1)]; + Y=[Y;y(i);y(i+1)]; + end + X=[X;xmx]; + Y=[Y;y(N)]; + return + end + if (METHOD=="zero order-above") then + X=[xmn;x(1)]; + Y=[y(1);y(1)]; + for i=1:N-1 + X=[X;x(i);x(i+1)]; + Y=[Y;y(i+1);y(i+1)]; + end + X=[X;xmx]; + Y=[Y;y(N)]; + return + end + if (METHOD=="zero order-nearest") then + X=[xmn;x(1)]; + Y=[y(1);y(1)]; + for i=1:N-1 + X=[X;(x(i)+x(i+1))/2;(x(i)+x(i+1))/2]; + Y=[Y;y(i);y(i+1)]; + end + X=[X;xmx]; + Y=[Y;y(N)]; + return + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (METHOD=="linear") then + + if N<=1 then + return; + end + if extrapo==0 then + X=[xmn]; + Y=[y(1)]; + end + if extrapo==1 then + X=[xmn]; + Y=y(1)+(xmn-x(1))*(y(1)-y(2))/(x(1)-x(2)); + end + for i=1:N + X=[X;x(i)]; + Y=[Y;y(i)]; + end + if extrapo==0 then + X=[X;xmx]; + Y=[Y;y(N)]; + end + if extrapo==1 then + X=[X;xmx]; + Y=[Y;y(N)+(xmx-x(N))*(y(N)-y(N-1))/(x(N)-x(N-1))]; + end + return + end + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (N<25) then + NP=10; + elseif (N<50) then + NP=5; + elseif (N<100) then + NP=2; + elseif (N<200) then + NP=1; + else + NP=0; + 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 extrapo==1 then + X=[linspace(xmn,x(1),NP+2)';X;linspace(x(N),xmx,NP+2)']; + 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 + if extrapo==0 then + X=[X;xmx]; + Y=[Y;y(N)]; + 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/NonLinear/LOOKUP_f.sci b/macros/NonLinear/LOOKUP_f.sci new file mode 100644 index 00000000..51f1fc88 --- /dev/null +++ b/macros/NonLinear/LOOKUP_f.sci @@ -0,0 +1,72 @@ +// 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]=LOOKUP_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + rpar=model.rpar; + n=size(rpar,"*")/2 + xx=rpar(1:n); + yy=rpar(n+1:2*n) + while %t do + [ln,fun]=where(); + + if ~or(fun == "do_eval") then // cas standard + [xx,yy,ok,gc] = edit_curv(xx,yy,"axy"); + 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.rpar=[xx(:);yy(:)] + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + model=scicos_model() + model.sim="lookup" + model.in=1 + model.out=1 + model.rpar=[-2;-1;1;2;-1;1;-1;1] + model.blocktype="c" + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/NonLinear/MAXMIN.sci b/macros/NonLinear/MAXMIN.sci new file mode 100644 index 00000000..fb6db898 --- /dev/null +++ b/macros/NonLinear/MAXMIN.sci @@ -0,0 +1,95 @@ +// 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]=MAXMIN(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,mm,nin,zcr,exprs]=.. + scicos_getvalue("Set Max/Min block parameters",.. + ["Min (1) or Max (2) ";"Number of input vectors (1 or 2)";"zero-crossing (1: yes, 0;no)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if zcr<>0 then + zcr=-1, + end + if mm<>1 then + mm=2, + end + if nin<>1 & nin<>2 then + message("Wrong number of inputs, only 1 and 2 allowed") + ok=%f + end + if ok then + if nin==1 then + [model,graphics,ok]=check_io(model,graphics,-1,1,[],[]) + else + [model,graphics,ok]=check_io(model,graphics,[-1,-1],-1,[],[]) + end + end + if ok then + model.nzcross=zcr; + if nin==1 then + model.nmode=abs(zcr); + else + model.nmode=zcr + end + model.ipar=mm; + + // Update the label of the block + if mm == 1 then + label="MIN"; + else + label="MAX"; + end + graphics.style="MAXMIN;displayedLabel=" + label; + + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model; + break + end + end + case "define" then + model=scicos_model() + model.sim=list("minmax",4) + model.out=1 + model.in=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + model.ipar=0; + exprs=[string([2,1,1]')] + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.style="MAXMIN;displayedLabel=MAX" + end +endfunction + diff --git a/macros/NonLinear/MAX_f.sci b/macros/NonLinear/MAX_f.sci new file mode 100644 index 00000000..809ac54b --- /dev/null +++ b/macros/NonLinear/MAX_f.sci @@ -0,0 +1,43 @@ +// 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]=MAX_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=-1 + model=scicos_model() + model.sim="maxblk" + model.in=in + model.out=1 + model.dstate=[0;0] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=" " + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/MIN_f.sci b/macros/NonLinear/MIN_f.sci new file mode 100644 index 00000000..580b5a7f --- /dev/null +++ b/macros/NonLinear/MIN_f.sci @@ -0,0 +1,43 @@ +// 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]=MIN_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=-1 + model=scicos_model() + model.sim="minblk" + model.in=in + model.out=1 + model.dstate=[0;0] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=sci2exp(in) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/POWBLK_f.sci b/macros/NonLinear/POWBLK_f.sci new file mode 100644 index 00000000..02d8e0d6 --- /dev/null +++ b/macros/NonLinear/POWBLK_f.sci @@ -0,0 +1,69 @@ +// 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]=POWBLK_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,a,exprs]=scicos_getvalue("Set u^a block parameters",.. + "to the power of",list("vec",1),exprs) + if ~ok then + break, + end + graphics.exprs=exprs + if a==int(a) then + model.ipar=a; + model.rpar=[] + else + model.rpar=a; + model.ipar=[] + end + model.firing=[] //compatibility + x.graphics=graphics; + x.model=model + break + end + case "define" then + in=1 + a=1.5 + model=scicos_model() + model.sim="powblk" + model.in=-1 + model.out=-1 + model.rpar=a + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=string(a) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/PRODUCT.sci b/macros/NonLinear/PRODUCT.sci new file mode 100644 index 00000000..ed4ff195 --- /dev/null +++ b/macros/NonLinear/PRODUCT.sci @@ -0,0 +1,89 @@ +// 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] = PRODUCT(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,sgn,exprs]=scicos_getvalue([" Set multiplication block parameters"; + "(multiplication is set with + 1, division with -1)";""],... + "Number of inputs or sign vector",... + list("vec",-1),exprs) + if ~ok then + break, + end + sgn=sgn(:); + if size(sgn,1)==1 then + if sgn<1 then + message("Number of inputs must be > 0") + ok=%f + elseif sgn==1 then + in=-1 + sgn=[] + nout=1 + else + in=-ones(sgn,1) + sgn=ones(sgn,1) + nout=-1 + end + else + if ~and(abs(sgn)==1) then + message("Signs can only be +1 or -1") + ok=%f + else + in=-ones(size(sgn,1),1) + nout=-1 + end + end + if ok then + [model,graphics,ok]=check_io(model,graphics,in,nout,[],[]) + end + if ok then + model.ipar=sgn + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + sgn=[1;-1] + model=scicos_model() + model.sim=list("product",4) + model.in=[-1;-1] + model.out=-1 + model.ipar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=sci2exp(sgn) + gr_i=[] + x=standard_define([2 3],model, exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/PROD_f.sci b/macros/NonLinear/PROD_f.sci new file mode 100644 index 00000000..4c392e44 --- /dev/null +++ b/macros/NonLinear/PROD_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]=PROD_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim=list("prod",2) + model.in=[-1;-1] + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + + x=standard_define([1 1],model,[],[]) + end +endfunction diff --git a/macros/NonLinear/QUANT_f.sci b/macros/NonLinear/QUANT_f.sci new file mode 100644 index 00000000..3ec21a94 --- /dev/null +++ b/macros/NonLinear/QUANT_f.sci @@ -0,0 +1,77 @@ +// 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]=QUANT_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 then + [ok,pas,meth,exprs]=scicos_getvalue("Set parameters",.. + ["Step";"Quantization Type (1-4)"],.. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if meth<1|meth>4 then + message("Quantization Type must be from 1 to 4") + else + rpar=pas + model.rpar=rpar + model.ipar=meth + select meth + case 1 then + model.sim="qzrnd" + case 2 then + model.sim="qztrn" + case 3 then + model.sim="qzflr" + case 4 then + model.sim="qzcel" + end + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + pas=0.1; + meth=1 + model=scicos_model() + model.sim="qzrnd" + model.in=-1 + model.out=-1 + model.rpar=pas + model.ipar=meth + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(pas);string(meth)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/SATURATION.sci b/macros/NonLinear/SATURATION.sci new file mode 100644 index 00000000..cb2098b3 --- /dev/null +++ b/macros/NonLinear/SATURATION.sci @@ -0,0 +1,74 @@ +// 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]=SATURATION(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,maxp,minp,zeroc,exprs]=scicos_getvalue("Set Saturation parameters",.. + ["Upper limit";"Lower limit";"zero crossing (0:no, 1:yes)"],list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if maxp<=minp then + message("Upper limit must be > Lower limit") + else + rpar=[maxp;minp] + model.rpar=rpar + if zeroc<>0 then + model.nzcross=2 + model.nmode=1 + else + model.nzcross=0 + model.nmode=0 + end + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minp=-1; + maxp=1; + rpar=[maxp;minp] + model=scicos_model() + model.sim=list("satur",4) + model.in=1 + model.nzcross=2 + model.nmode=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(maxp);string(minp);string(model.nmode)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/SAT_f.sci b/macros/NonLinear/SAT_f.sci new file mode 100644 index 00000000..53f572e0 --- /dev/null +++ b/macros/NonLinear/SAT_f.sci @@ -0,0 +1,71 @@ +// 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]=SAT_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,minp,maxp,pente,exprs]=scicos_getvalue("Set Saturation parameters",.. + ["Min";"Max";"Slope"],list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if maxp<=0 then + message("Max must be strictly positive") + elseif pente<=0 then + message("Slope must be strictly positive") + else + rpar=[minp/pente;maxp/pente;pente] + model.rpar=rpar + model.firing=[] //compatibility + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minp=-1; + maxp=1; + slope=1; + rpar=[minp;maxp;slope] + + model=scicos_model() + model.sim=list("lusat",1) + model.in=1 + model.nzcross=2 + model.out=1 + model.rpar=[minp;maxp;slope] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(minp);string(maxp);string(slope)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/SIGNUM.sci b/macros/NonLinear/SIGNUM.sci new file mode 100644 index 00000000..0b2c376d --- /dev/null +++ b/macros/NonLinear/SIGNUM.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]=SIGNUM(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,zcr,exprs]=.. + scicos_getvalue("Set block parameters",.. + ["use zero_crossing (1: yes) (0:no)"],.. + list("vec",1),exprs) + if ~ok then + break, + end + graphics.exprs=exprs + if ok then + if zcr<>0 then + model.nmode=-1; + model.nzcross=-1; + else + model.nmode=0; + model.nzcross=0; + end + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nu=-1 + model=scicos_model() + model.sim=list("signum",4) + model.in=nu + model.out=nu + model.nzcross=nu + model.nmode=nu + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string([1])] + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/SINBLK_f.sci b/macros/NonLinear/SINBLK_f.sci new file mode 100644 index 00000000..e6f86d4a --- /dev/null +++ b/macros/NonLinear/SINBLK_f.sci @@ -0,0 +1,41 @@ +// 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]=SINBLK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim="sinblk" + model.in=-1 + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=" " + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/TANBLK_f.sci b/macros/NonLinear/TANBLK_f.sci new file mode 100644 index 00000000..ffea89ea --- /dev/null +++ b/macros/NonLinear/TANBLK_f.sci @@ -0,0 +1,43 @@ +// 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]=TANBLK_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] + case "define" then + in=-1 + model=scicos_model() + model.sim="tanblk" + model.in=in + model.out=in + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=sci2exp(in) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/NonLinear/TrigFun.sci b/macros/NonLinear/TrigFun.sci new file mode 100644 index 00000000..a9c1600c --- /dev/null +++ b/macros/NonLinear/TrigFun.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]=TrigFun(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + %FF=["sin";"cos";"tan"; + "asin";"acos";"atan"; + "sinh";"cosh";"tanh"; + "asinh";"acosh";"atanh"]; + %GG=["Choose among "+strcat(%FF(1:4),", ");strcat(%FF(5:$),", ")] + while %t do + [ok,fun,exprs]=scicos_getvalue(%GG,"Function",list("str",1),exprs) + if ~ok then + break, + end + if find(%FF==fun)==[] then + message("Sorry but "+fun +" is not in the list!") + else + graphics.exprs=exprs + execstr("model.sim=list(''"+fun+"_blk'',4)") + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + model=scicos_model() + model.sim=list("sin_blk",4) + model.in=-1 + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + exprs="sin" + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/PDE/PDE.sci b/macros/PDE/PDE.sci new file mode 100644 index 00000000..075465f6 --- /dev/null +++ b/macros/PDE/PDE.sci @@ -0,0 +1,199 @@ +// Scicos +// +// Copyright (C) INRIA - Author : EADS-CCR +// +// 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]=PDE(job,arg1,arg2) + // développé par EADS-CCR + // fonction graphique du bloc, elle permet le dessin et l'initialisation du bloc // + // Reference: "Scicos user guid", http://www.scicos.org // + //--------------------------------------------------------------------------------------------// + + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + params_pde=label(1); + + while %t do + [ln,fun]=where(); + if ~or(fun == "do_eval") then // cas standard + [ok,a_domaine,b_domaine,discr,signe,choix,type_meth,degre,Nbr_maillage,.. + CI,CI1,CLa_type,CLa_exp,CLb_type,CLb_exp,oper,a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,.. + a6,b6,a7,b7,k,mesures,params_pde]=IHM_EDP(params_pde); + if ok then + return; + end + else + if exists("%scicos_context") then + // evaluation du context + [ok,a_domaine,b_domaine,discr,signe,choix,type_meth,degre,Nbr_maillage,.. + CI,CI1,CLa_type,CLa_exp,CLb_type,CLb_exp,oper,a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,.. + a6,b6,a7,b7,k,mesures,params_pde]=setvalue_IHM_EDP(params_pde); + end + end + + //********************************** + // Get the name of the file + //*********************************** + okk=%f; + rdnom="PDE"; + ok1=%t; + while %t do + [okk,rdnom,lab]=scicos_getvalue("PLEASE, GIVE US THE BLOCK''s NAME. ",.. + "New block''s name :",list("str",1),label(3)); + + if okk==%f then + ok1=%f; + return; + end + label(3)=lab; + rdnom=stripblanks(rdnom); + if rdnom==emptystr() then + ok1=%f;x_message("sorry C file name not defined"); + end + if ok1 then + break, + end + end + + // arbre de decision + if (choix == 0) then + // Choix automatique + ind4=strindex(a4,"x"); + ind1=strindex(a1,"x"); + ind2=strindex(a2,"x"); + if (ind4~=[] | ind1~=[] | ind2~=[]) then + if (signe == 1) then, + delta=1; + elseif (signe == 2) then, + delta=-1; + elseif (signe == 0) then, + delta=0; + else + x_message(["le discriminant n''est pas constant,"; "Vous devez choisir son signe dans l''IHM"]); + return; + end + else + delta=evstr(a4)^2-4*evstr(a1)*evstr(a2); + end + if (delta==[]) then, + delta=0; + end + type_meth=arbre_decision(delta); + end + // a voir si c'est à rajouter pour ne pas regenerer dans le cas d'eval + //if ~ok then + [flag_type,rdnom,DF_type,tt]=translate(CI,CI1,CLa_type,CLa_exp,CLb_type,CLb_exp,oper,type_meth,degre,a_domaine,.. + b_domaine,Nbr_maillage,a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,a6,b6,a7,b7,rdnom,mesures); + //else + // tt=label(3); + //end + + // augmentation du systeme avec les noeuds fictifs + Nbr=Nbr_maillage; + if ((CLa_type == 1) & (DF_type == 0 | DF_type == 1)) | ((CLb_type == 1) & (DF_type == 0 | DF_type == 2)) then + Nbr=Nbr+1; + end + + if ( mesures ==[]) then + out=Nbr_maillage; + else + out=[Nbr_maillage;size(mesures,"*")]; + end + if (flag_type == 1) then + // explicite + model.sim=list(rdnom,2004); + if (find(oper == 1) ~= []) then + model.state=zeros(2*Nbr_maillage,1); + else + model.state=zeros(Nbr_maillage,1); + end + elseif (flag_type == 2) then + model.sim=list(rdnom,12004); + if (find(oper == 1) ~= []) then + if (type_meth ==3 & (find(oper == 2) ~= [] | find(oper == 4) ~= [])) then + model.state=zeros(6*Nbr_maillage,1); + elseif (type_meth == 1) then + model.state=zeros(4*Nbr,1); + else + model.state=zeros(4*Nbr_maillage,1); + end + else + if (type_meth == 3 & (find(oper == 2) ~= [] | find(oper == 4) ~= [])) then + model.state=zeros(4*Nbr_maillage,1); + elseif (type_meth == 1) then + model.state=zeros(2*Nbr,1); + else + model.state=zeros(2*Nbr_maillage,1); + end + end + end + + // Ecriture, compilation et linkage du code + // if (fun(3) == "clickin") then + // always ulink and link + [ok1]=CFORTREDP(rdnom,tt); + if ~ok1 then + break, + end + //end + + if ~ok then + [model,graphics,ok]=check_io(model,graphics,ones(k,1),out(:),[],[]) + end + label(1)=params_pde; + label(2)=tt; + graphics.exprs=label; + x.graphics=graphics; + x.model=model; + break + end + + case "define" then + model=scicos_model() + model.state=zeros(10,1) + model.sim=list("PDE",0) + model.in=[1;1;1;1;1] + model.out=[10;0] + model.blocktype="c" + model.dep_ut=[%f %t] + + //initialisation de l'ihm + params_pde=tlist(["paramspde";"a";"b";"txt_exp";"check_op1";"a1";"b1";"check_op2";"a2";"b2";.. + "check_op3";"a3";"b3";"check_op4";"a4";"b4";"check_op5";"a5";"b5";"check_op6";"a6";"b6";.. + "check_op7";"a7";"b7";"discr_cst";"discr_non_cst";"signe";"rad_automatique";"rad_manuel";.. + "methode";"ord1";"ord2";"ord3";"degre";"nnode";"txt_pas";"CI";"dCI";"CLa";"CLa_exp";"CLb";.. + "CLb_exp";"points"],"","","","0","","IN_EDP1(t)","0","","IN_EDP2(t)","0","","IN_EDP3(t)",.. + "0","","IN_EDP4(t)","0","","IN_EDP5(t)","0","","IN_EDP6(t)","0","","IN_EDP7(t)","0","0",.. + "0","0","0","0","","","","","","","","","0","IN_CL1(t)","0","IN_CL2(t)",""); + // dans label on mis infos de scicos_getvalue, infos ihm et le code C + label=list(params_pde,[],""); + gr_i=[] + x=standard_define([3 3],model,label,gr_i) + + end +endfunction + diff --git a/macros/Sinks/AFFICH_m.sci b/macros/Sinks/AFFICH_m.sci new file mode 100644 index 00000000..cdef16b9 --- /dev/null +++ b/macros/Sinks/AFFICH_m.sci @@ -0,0 +1,147 @@ +// 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] = AFFICH_m(job,arg1,arg2) + //** 22 Aug 2006: looking for a nasty "font" bugs + //** + //** 07 Aug 2008: this function has been update for Scilab 5.0 by + //** Simone Mannori and Jean-Baptiste Silvy + + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x = arg1 ; + graphics = arg1.graphics ; + exprs = graphics.exprs ; + model = arg1.model ; + + while %t do + [ok,in,font,fontsize,colr,nt,nd,herit,exprs]=scicos_getvalue(.. + "Set parameters",.. + ["Input Size", + "Font number"; + "Font size"; + "Color"; + "Total number of digits"; + "Number of rational part digits"; + "Block inherits (1) or not (0)"],.. + list("mat",[1 2],"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + + if ~ok then + break, + end //user cancel modification + + mess = [] ; //** no message + + if font<=0 then + mess=[mess;"Font number must be positive";" "] + ok=%f + end + + if fontsize<=0 then + mess=[mess;"Font size must be positive";" "] + ok=%f + end + + if nt<=3 then + mess=[mess;"Total number of digits must be greater than 3";" "] + ok=%f + end + + if nd<0 then + mess=[mess;"Number of rational part digits must be " + "greater or equal 0";" "] + ok=%f + end + + if ~ok then + message(["Some specified values are inconsistent:"; + " ";mess]); + end + + if ~or(herit==[0 1]) then + mess=[mess;"Accept inherited values are 0 and 1";" "] + ok=%f + end + + if ~ok then + message(["Some specified values are inconsistent:"; + " ";mess]) + end + + //** Positive case -> + if ok then + //[model,graphics,ok]=check_io(model,graphics,1,[],ones(1-herit,1),[]) + [model,graphics,ok] = set_io(model, graphics, list(in,1), list(), ones(1-herit,1), []) + end + + if ok then + model.ipar = [font;fontsize;colr;nt;nd;in(1,1)]; + model.dstate = [-1;0;0;1;1;0;zeros(in(1,1)*in(1,2),1)] + model.evtin = ones(1-herit,1) + graphics.exprs = exprs; + x.graphics = graphics; + x.model = model ; + break + end + + end + + + case "define" then + font = 1 + fontsize = 1 + colr = 1 + nt = 5 + nd = 1 + in = [1 1] + + model = scicos_model(); + model.sim = list("affich2",4) ; + model.in = in(1,1); + model.in2 = in(1,2); + model.evtin = 1 ; + model.dstate = [-1;0;0;1;1;0;zeros(in(1,1)*in(1,2),1)] + model.ipar = [font;fontsize;colr;1000;nt;nd;in(1,1)] + model.blocktype = "c" ; + model.firing = [] ; + model.dep_ut = [%t %f] + model.label = "" ; + + exprs = [ sci2exp([model.in model.in2]); + string(font); + string(fontsize); + string(colr); + string(nt); + string(nd); + string(0) ] + + gr_i=[] + + x = standard_define([3 2],model,exprs,gr_i) + + end + +endfunction diff --git a/macros/Sinks/BARXY.sci b/macros/Sinks/BARXY.sci new file mode 100644 index 00000000..ea39c3c0 --- /dev/null +++ b/macros/Sinks/BARXY.sci @@ -0,0 +1,76 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt +// +// + +function [x,y,typ]=BARXY(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,xmin,xmax,ymin,ymax,thickness,exprs]=scicos_getvalue("Set Scope parameters",.. + ["Xmin" ; "Xmax" ; "Ymin" ; "Ymax";"Segs Thickness"], .. + list("vec",1,"vec",1,"vec",1,"vec",1, "vec", 1),exprs) + if ~ok then + break + end //user cancel modification + + mess=[] + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if thickness <=0 then + mess=[mess ; "Thickness must be strictly positive."] + ok=%f + end + if ~ok then + message(mess) + else + model.rpar=[xmin ; xmax ; ymin ; ymax] + model.ipar=thickness + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model; + break + end + end + case "define" then + model=scicos_model(); + xmin = -15; + xmax = 15; + ymin = -15; + ymax = 15; + model.sim=list("BARXY_sim", 5) + model.blocktype="d"; + model.dep_ut=[%t %f]; + model.in=[-1;-1]; + model.intyp=[1]; + model.out=[]; + model.evtin=[1] + model.rpar=[xmin ; xmax ; ymin ; ymax] + model.ipar=1; + x=standard_define([2 2],model,[],[]); + x.graphics.in_implicit=["E", "E"]; + x.graphics.out_implicit=[]; + x.graphics.exprs=["-15";"15";"-15";"15";"1"] + end +endfunction diff --git a/macros/Sinks/CANIMXY.sci b/macros/Sinks/CANIMXY.sci new file mode 100644 index 00000000..6aab410a --- /dev/null +++ b/macros/Sinks/CANIMXY.sci @@ -0,0 +1,151 @@ +// 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]=CANIMXY(job,arg1,arg2) + //Scicos 2D animated visualization block + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //dstate=model.dstate + + while %t do + [ok,nbr_curves,clrs,siz,win,wpos,wdim,xmin,xmax,ymin,ymax,N,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Number of Curves"; + "color (>0) or mark (<0)"; + "line or mark size"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Xmin"; + "Xmax"; + "Ymin"; + "Ymax"; + "Buffer size"],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",-1,"vec",-1,"vec",1,.. + "vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + + mess=[] + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if nbr_curves<=0 then + mess=[mess;"Number of curves cannot be negative or null";" "] + ok=%f + end + if N<1 then + mess=[mess;"Buffer size must be at least 1";" "] + ok=%f + end + if N==1 & clrs>0 then + mess=[mess;"Buffer size must be at least 2";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + in = nbr_curves*ones(2,1); + in2 = ones(2,1); + [model,graphics,ok]=set_io(model,graphics,list([in in2],ones(2,1)),list(),ones(1,1),[]); + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=[xmin;xmax;ymin;ymax] + ipar=[win;1;N;clrs;siz;0;wpos(:);wdim(:);nbr_curves] + //if prod(size(dstate))<>2*N+1 then dstate=zeros(2*N+1,1),end + //model.dstate=dstate; + model.rpar=rpar; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + win=-1; + clrs=-4; + N=2; + siz=1; + wpos=[-1;-1]; + wdim=[-1;-1]; + xmin=-15; + xmax=15; + ymin=-15; + ymax=+15 + nbr_curves = 1; + + model=scicos_model() + model.sim=list("canimxy",4) + model.in=[1;1] + model.in2=[1;1] + model.intyp=[1;1] + model.evtin=1 + model.rpar=[xmin;xmax;ymin;ymax] + model.ipar=[win;1;N;clrs;siz;0;wpos(:);wdim(:);nbr_curves] + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=[string(nbr_curves); + string(clrs); + string(siz); + string(win); + "[]"; + "[]"; + string(xmin); + string(xmax); + string(ymin); + string(ymax); + string(N)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CANIMXY3D.sci b/macros/Sinks/CANIMXY3D.sci new file mode 100644 index 00000000..bd239ac8 --- /dev/null +++ b/macros/Sinks/CANIMXY3D.sci @@ -0,0 +1,162 @@ +// 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]=CANIMXY3D(job,arg1,arg2) + //Scicos 3D animated visualization block + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,nbr_curves,clrs,siz,win,wpos,wdim,vec_x,vec_y,vec_z,param3ds,N,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Number of curves"; + "color (>0) or mark (<0)"; + "line or mark size"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Xmin and Xmax"; + "Ymin and Ymax"; + "Zmin and Zmax"; + "Alpha and Theta"; + "Buffer size"],.. + list("vec",1,"vec",-1,"vec",-1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + mess=[] + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if size(clrs,"*")<>size(siz,"*") then + mess=[mess;"Colors and Size must have same size";" "] + ok=%f + end + if nbr_curves<=0 then + mess=[mess;"Number of curves cannot be negative or null";" "] + ok=%f + end + if size(clrs,"*")<nbr_curves then + mess=[mess;"You must have at least same size for clrs and the number of curves";" "] + ok=%f + end + if N<1 then + mess=[mess;"Buffer size must be at least 1";" "] + ok=%f + end + if N<2 + for i=1:nbr_curves + if clrs(i)>0 then + mess=[mess;"Buffer size must be at least 2 or Change a color (must be <0)";" "] + ok=%f + end + end + end + if vec_y(1)>=vec_y(2) then + mess=[mess;"Ymax must be higher than Ymin";" "] + ok=%f + end + if vec_x(1)>=vec_x(2) then + mess=[mess;"Xmax must be higher than Xmin";" "] + ok=%f + end + if vec_z(1)>=vec_z(2) then + mess=[mess;"Zmax must be higher than Zmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + in = nbr_curves*ones(3,1); + in2 = ones(3,1); + [model,graphics,ok]=set_io(model,graphics,list([in in2],ones(3,1)),list(),ones(1,1),[]); + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=[vec_x(:);vec_y(:);vec_z(:);param3ds(:)] + size_siz = size(siz,"*"); + ipar=[win;size_siz;N;clrs(:);siz(:);1;wpos(:);wdim(:);nbr_curves] + model.rpar=rpar; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + win=-1; + N=2; + clrs = [1;2;3;4;5;6;7;13] + siz = [1;1;1;1;1;1;1;1] + wpos=[-1;-1]; + wdim=[-1;-1]; + param3ds=[50;280] + vec_x = [-15;15] + vec_y = [-15;15] + vec_z = [-15;15] + nbr_curves = 1; + + model=scicos_model() + model.sim=list("canimxy3d",4) + model.in=[1;1;1] + model.evtin=1 + model.in2=[1;1;1] + model.intyp=[1;1;1] + model.rpar=[vec_x(:);vec_y(:);vec_z(:);param3ds(:)] + model.ipar=[win;8;N;clrs(:);siz(:);8;wpos(:);wdim(:);nbr_curves] + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=[string(nbr_curves); + strcat(string(clrs)," "); + strcat(string(siz)," "); + string(win); + "[]"; + "[]"; + strcat(string(vec_x)," "); + strcat(string(vec_y)," "); + strcat(string(vec_z)," "); + strcat(string(param3ds)," "); + string(N)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CEVENTSCOPE.sci b/macros/Sinks/CEVENTSCOPE.sci new file mode 100644 index 00000000..ce7ae85e --- /dev/null +++ b/macros/Sinks/CEVENTSCOPE.sci @@ -0,0 +1,122 @@ +// 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]=CEVENTSCOPE(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,nclock,clrs,win,wpos,wdim,per,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Number of event inputs"; + "colors c (>0) or mark (<0)"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Refresh period"],.. + list("vec",1,"vec",-1,"vec",1,"vec",-1,"vec",-1,"vec",1),exprs); + nclock=int(nclock) + clrs=int(clrs) + win=int(win) + + if ~ok then + break, + end //user cancel modification + mess=[] + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if nclock<=0 then + mess=[mess;"Block must have at least one input event";" "] + ok=%f + end + if size(clrs,"*")<>nclock then + mess=[mess;"Inputs color c size must be equal to Number of inputs";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if per<=0 then + mess=[mess;"Refresh period must be positive";" "] + ok=%f + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list(),list(),ones(nclock,1),[]) + else + message(["Some specified values are inconsistent:"; + " ";mess]) + end + if ok then + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=per + ipar=[win;1;clrs(:);wpos(:);wdim(:)] + model.rpar=rpar; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nclock=1 + win=-1; + clrs=[1;3;5;7;9;11;13;15]; + wdim=[600;400] + wpos=[-1;-1] + per=30; + + model=scicos_model() + model.sim=list("cevscpe",4) + model.evtin=1 + model.rpar=per + model.ipar=[win;1;clrs(nclock);wpos(:);wdim(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[sci2exp(nclock); + strcat(sci2exp(clrs(nclock))," "); + string(win); + sci2exp([]); + sci2exp(wdim); + string(per)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CFSCOPE.sci b/macros/Sinks/CFSCOPE.sci new file mode 100644 index 00000000..4b482a72 --- /dev/null +++ b/macros/Sinks/CFSCOPE.sci @@ -0,0 +1,141 @@ +// 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]=CFSCOPE(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + + model=arg1.model; + //dstate=model.in + while %t do + [ok,clrs,win,wpos,wdim,ymin,ymax,per,N,wu,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Color (>0) or mark (<0) vector (8 entries)"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Ymin"; + "Ymax"; + "Refresh period"; + "Buffer size" + "Links to view"],.. + list("vec",8,"vec",1,"vec",-1,"vec",-1,"vec",1,.. + "vec",1,"vec",1,"vec",1,"vec",-1),.. + exprs) + if ~ok then + break, + end //user cancel modification + mess=[] + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if per<=0 then + mess=[mess;"Refresh period must be positive";" "] + ok=%f + end + if N<2 then + mess=[mess;"Buffer size must be at least 2";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if wu<0 then + mess=[mess;"Link to view must be positive";" "] + ok=%f + end + if ~ok then + message(["Some specified values are inconsistent:"; + " ";mess]) + end + if ok then + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=[0;ymin;ymax;per] + if size(clrs,"*")>8 then + clrs=clrs(1:8); + end + if size(clrs,"*")<8 then + clrs(8)=0; + end + ipar=[win;1;N;clrs(:);wpos(:);wdim(:);size(wu,"*");wu(:)] + //if prod(size(dstate))<>(8+1)*N+1 then dstate=-eye((8+1)*N+1,1),end + //model.dstate=dstate; + model.rpar=rpar; + model.ipar=ipar + model.firing=[] //compatibility + model.dep_ut=[%t %f] //compatibility + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + win=-1; + wdim=[600;400] + wpos=[-1;-1] + clrs=[1;3;5;7;9;11;13;15]; + N=2; + ymin=-15; + ymax=+15; + per=30; + model=scicos_model() + model.sim=list("cfscope",4) + model.evtin=1 + model.rpar=[0;ymin;ymax;per] + model.ipar=[win;1;N;clrs;wpos;wdim;1;1] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(string(clrs)," "); + string(win); + sci2exp([]); + sci2exp(wdim); + string(ymin); + string(ymax); + string(per); + string(N); + string([1])]; + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CLKOUTV_f.sci b/macros/Sinks/CLKOUTV_f.sci new file mode 100644 index 00000000..d1dd1804 --- /dev/null +++ b/macros/Sinks/CLKOUTV_f.sci @@ -0,0 +1,126 @@ +// 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]=CLKOUTV_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "plot" then + xf=60; + yf=40; + orig=arg1.graphics.orig; + sz=arg1.graphics.sz; + orient=arg1.graphics.flip; + prt=arg1.model.ipar; + pat=xget("pattern"); + xset("pattern",default_color(-1)); + thick=xget("thickness"); + xset("thickness",2); + x=orig(1)+sz(1)*[1/2;1; 1;0;0 ]; + y=orig(2)+sz(2)*[0; 1/3;1;1;1/3]; + xo=orig(1); + yo=orig(2)+sz(2)/3; + + gr_i=arg1.graphics.gr_i; + if type(gr_i)==15 then + coli=gr_i(2); + pcoli=xget("pattern"); + xfpolys(x,y,coli); + xset("pattern",coli); + xstringb(xo,yo,string(prt),sz(1),sz(2)/1.5); + xset("pattern",pcoli); + xstringb(xo,yo,string(prt),sz(1),sz(2)/1.5); + else + xstringb(xo,yo,string(prt),sz(1),sz(2)/1.5); + xpoly(x,y,"lines",1); + end + in= [-1/14 1/7 + 0 0 + 1/14 1/7 + -1/14 1/7]*diag([xf,yf]); + xfpoly(in(:,1)+ones(4,1)*(orig(1)+sz(1)/2),.. + in(:,2)+ones(4,1)*(orig(2)+sz(2)),1); + xset("thickness",thick); + xset("pattern",pat); + + ident = arg1.graphics.id + if ident <> [] & ident <> "" then + font=xget("font"); + xset("font", options.ID(1)(1), options.ID(1)(2)); + rectangle = xstringl(orig(1), orig(2), ident); + w = rectangle(3); + h = rectangle(4); + xstringb(orig(1)+sz(1)/2-w/2, orig(2)-3*h/2 , ident , w, h); + xset("font", font(1), font(2)); + end + x=[];y=[]; + case "getinputs" then + orig=arg1.graphics.orig; + sz=arg1.graphics.sz; + x=orig(1)+sz(1)/2 + y=orig(2)+sz(2) + typ=-ones(x) + case "getoutputs" then + x=[]; + y=[]; + typ=[]; + case "getorigin" then + [x,y]=standard_origin(arg1) + case "set" then + x=arg1; + graphics=arg1.graphics; + model=arg1.model; + exprs=graphics.exprs; + while %t do + [ok,prt,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"),"CLKOUTV_f");" ";gettext("Event output port")],.. + gettext("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 + model.ipar=prt + model.evtin=1 + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + prt=1 + model=scicos_model() + model.sim="output" + model.evtin=1 + model.ipar=prt + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=string(prt) + x=standard_define([1 1],model,exprs," ") + end +endfunction diff --git a/macros/Sinks/CLKOUT_f.sci b/macros/Sinks/CLKOUT_f.sci new file mode 100644 index 00000000..298cfa89 --- /dev/null +++ b/macros/Sinks/CLKOUT_f.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]=CLKOUT_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) //for compatibility + while %t do + [ok,prt,exprs]=scicos_getvalue("Set Event Output block parameters",.. + "Port number",list("vec",1),exprs) + if ~ok then + break, + end + prt=int(prt) + if prt<=0 then + message("Port number must be a positive integer") + else + model.ipar=prt + model.evtin=1 + model.firing=[]//compatibility + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + prt=1 + + model=scicos_model() + model.sim="output" + model.evtin=1 + model.ipar=prt + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=string(prt) + x=standard_define([1 1],model,exprs," ") + end +endfunction diff --git a/macros/Sinks/CMAT3D.sci b/macros/Sinks/CMAT3D.sci new file mode 100644 index 00000000..93cf6cdd --- /dev/null +++ b/macros/Sinks/CMAT3D.sci @@ -0,0 +1,98 @@ +// 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]=CMAT3D(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,vec_x,vec_y,colormap,cmin,cmax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Bounds Vector X (-1 for standard)"; + "Bounds Vector Y (-1 for standard)"; + "ColorMap"; + "Zmin"; + "Zmax"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + mess=[] + if size(vec_x,"*")<>size(vec_y,"*") then + mess=[mess;"Vector X and Vector Y must have the same size";" "] + ok=%f + end + if cmax<=cmin then + mess=[mess;"Error with minimum and maximum value";" "] + ok=%f + end + if ~ok then + message(["Some specified values are inconsistent:";" ";mess]) + end + if ok then + size_x = size(vec_x,"*"); + size_c=size(colormap(:),1); + ipar=[cmin;cmax;size_c;size_x]; + rpar=[colormap(:);vec_x(:);vec_y(:)]; + model.ipar=ipar; + model.rpar=rpar; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model; + break; + end + end + case "define" then + cmin = 0; + cmax = 100; + colormap = jetcolormap(25); + size_c = 25; + x=-1; + y=-1; + size_x = 1; + size_y = 1; + + model=scicos_model() + model.sim=list("cmat3d",4) + model.in=-1 + model.in2=-2 + model.intyp=1 + model.evtin=1 + model.ipar=[cmin;cmax;size_c;size_x;size_y] + model.rpar=[colormap(:);x;y] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(string(x)," "); + strcat(string(y)," "); + string("jetcolormap(25)"); + string(cmin); + string(cmax)]; + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CMATVIEW.sci b/macros/Sinks/CMATVIEW.sci new file mode 100644 index 00000000..d4b476b4 --- /dev/null +++ b/macros/Sinks/CMATVIEW.sci @@ -0,0 +1,90 @@ +// 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]=CMATVIEW(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,colormap,cmin,cmax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["ColorMap"; + "Minimum level range"; + "Maximum level range"],.. + list("vec",-1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + mess=[] + if cmax<=cmin then + mess=[mess;"Error with minimum and maximum value";" "] + ok=%f + end + if ~ok then + message(["Some specified values are inconsistent:";" ";mess]) + end + if ok then + size_c=size(colormap(:),1); + sol=inv([cmin 1;cmax 1])*[1;size_c/3]; + alpha_c = sol(1); + beta_c = sol(2); + ipar=[cmin;cmax;size_c]; + rpar=[alpha_c;beta_c;colormap(:)]; + model.ipar=ipar; + model.rpar=rpar; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + cmin = 0; + cmax = 100; + size_c = 25; + colormap = jetcolormap(size_c); + alpha_c = 0.24 + beta_c = 1 + + model=scicos_model() + model.sim=list("cmatview",4) + model.in=-1 + model.in2=-2 + model.intyp=1 + model.evtin=1 + model.ipar=[cmin;cmax;size_c] + model.rpar=[alpha_c;beta_c;colormap(:)] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string("jetcolormap(25)"); + string(cmin); + string(cmax)]; + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CMSCOPE.sci b/macros/Sinks/CMSCOPE.sci new file mode 100644 index 00000000..3cda4052 --- /dev/null +++ b/macros/Sinks/CMSCOPE.sci @@ -0,0 +1,182 @@ +// 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]=CMSCOPE(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + + + model=arg1.model; + //dstate=model.in + //pause + while %t do + [ok,in,clrs,win,wpos,wdim,ymin,ymax,per,N,heritance,nom,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Input ports sizes"; + "Drawing colors (>0) or mark (<0)"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Ymin vector"; + "Ymax vector"; + "Refresh period"; + "Buffer size"; + "Accept herited events 0/1" + "Name of Scope (label&Id)"],.. + list("vec",-1,"vec",-1,"vec",1,"vec",-1,"vec",-1,.. + "vec","size(%1,''*'')","vec","size(%1,''*'')","vec","size(%1,''*'')",.. + "vec",1,"vec",1,"str",1),exprs) + if ~ok then + break, + end //user cancel modification + mess=[] + if size(in,"*")<=0 then + mess=[mess;"Block must have at least one input port";" "] + ok=%f + end + if min(in)<=0 then + mess=[mess;"Port sizes must be positive";" "] + ok=%f + end + if size(clrs,"*")<sum(in) then + mess=[mess;"Not enough colors defined (at least "+string(sum(in))+")";" "] + ok=%f + end + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number can''t be < -1";" "] + ok=%f + end + if size(per,"*")<>size(ymin,"*") then + mess=[mess;"Size of Refresh Period must equal size of Ymin/Ymax vector";" "] + ok=%f + end + for i=1:1:size(per,"*") + if (per(i)<=0) then + mess=[mess;"Refresh Period must be positive";" "] + ok=%f + end + end + if N<2 then + mess=[mess;"Buffer size must be at least 2";" "] + ok=%f + end + if or(ymin>=ymax) then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if ~or(heritance==[0 1]) then + mess=[mess;"Accept herited events must be 0 or 1";" "] + ok=%f + end + if ~ok then + message(["Some specified values are inconsistent:"; + " ";mess]) + end + if ok then + in = in(:); + a = size(in,1); + in2 = ones(a,1); + [model,graphics,ok]=set_io(model,graphics,list([in in2],ones(a,1)),list(),ones(1-heritance,1),[]); + end + if ok then + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + if ok then + period=per(:)'; + yy=[ymin(:)';ymax(:)'] + rpar=[0;period(:);yy(:)] + clrs=clrs(1:sum(in)) + ipar=[win;size(in,"*");N;wpos(:);wdim(:);in(:);clrs(:);heritance] + //if prod(size(dstate))<>(sum(in)+1)*N+1 then + //dstate=-eye((sum(in)+1)*N+1,1), + //end + model.evtin=ones(1-heritance,1) + model.dstate=[] + //model.dstate=dstate; + model.rpar=rpar; + model.ipar=ipar + model.label=nom; + graphics.id=nom; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + //pause; + break + end + end + end + case "define" then + win=-1; + in=[1;1] + wdim=[-1;-1] + wpos=[-1;-1] + clrs=[1;3;5;7;9;11;13;15]; + N=20; + + ymin=[-1;-5]; + ymax=[1;5]; + per=[30;30]; + yy=[ymin(:)';ymax(:)'] + period=per(:)' + model=scicos_model() + model.sim=list("cmscope",4) + model.in=in + model.in2=[1;1] + model.intyp=[1;1] + model.evtin=1 + model.rpar=[0;period(:);yy(:)] + model.ipar=[win;size(in,"*");N;wpos(:);wdim(:);in(:);clrs(1:sum(in))] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(string(in)," "); + strcat(string(clrs)," "); + string(win); + sci2exp([]); + sci2exp([]); + strcat(string(ymin)," "); + strcat(string(ymax)," "); + strcat(string(per)," "); + string(N); + string(0); + emptystr()]; + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CSCOPE.sci b/macros/Sinks/CSCOPE.sci new file mode 100644 index 00000000..a12515c0 --- /dev/null +++ b/macros/Sinks/CSCOPE.sci @@ -0,0 +1,145 @@ +// 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]=CSCOPE(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + + model=arg1.model; + //dstate=model.in + while %t do + [ok,clrs,win,wpos,wdim,ymin,ymax,per,N,heritance,nom,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Color (>0) or mark (<0) vector (8 entries)"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Ymin"; + "Ymax"; + "Refresh period"; + "Buffer size" + "Accept herited events 0/1" + "Name of Scope (label&Id)"],.. + list("vec",8,"vec",1,"vec",-1,"vec",-1,"vec",1,.. + "vec",1,"vec",1,"vec",1,"vec",1,"str",1),.. + exprs) + if ~ok then + break, + end //user cancel modification + mess=[] + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number can''t be < -1";" "] + ok=%f + end + if per<=0 then + mess=[mess;"Refresh period must be positive";" "] + ok=%f + end + if N<2 then + mess=[mess;"Buffer size must be at least 2";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if ~or(heritance==[0 1]) then + mess=[mess;"Accept herited events must be 0 or 1";" "] + ok=%f + end + if ~ok then + message(["Some specified values are inconsistent:"; + " ";mess]) + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list([-1 1],1),list(),ones(1-heritance,1),[]) + end + + if ok then + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=[0;ymin;ymax;per] + ipar=[win;1;N;clrs(:);wpos(:);wdim(:)] + //if prod(size(dstate))<>(8+1)*N+1 then dstate=-eye((8+1)*N+1,1),end + //model.dstate=[]; + model.rpar=rpar; + model.ipar=ipar + model.evtin=ones(1-heritance,1) + model.label=nom; + graphics.id=nom + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + win=-1; + wdim=[600;400] + wpos=[-1;-1] + clrs=[1;3;5;7;9;11;13;15]; + N=20; + ymin=-15; + ymax=+15; + per=30; + + model=scicos_model() + model.sim=list("cscope",4) + model.in=-1 + model.in2=1 + model.evtin=1 + model.rpar=[0;ymin;ymax;per] + model.ipar=[win;1;N;clrs;wpos;wdim] + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(string(clrs)," "); + string(win); + sci2exp([]); + sci2exp(wdim); + string(ymin); + string(ymax); + string(per); + string(N); + string(0)'; + emptystr()]; //label-id + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CSCOPXY.sci b/macros/Sinks/CSCOPXY.sci new file mode 100644 index 00000000..dd00ae1b --- /dev/null +++ b/macros/Sinks/CSCOPXY.sci @@ -0,0 +1,147 @@ +// 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]=CSCOPXY(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; + while %t do + [ok,nbr_curves,clrs,siz,win,wpos,wdim,xmin,xmax,ymin,ymax,N,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Number of Curves"; + "color (>0) or mark (<0)"; + "line or mark size"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Xmin"; + "Xmax"; + "Ymin"; + "Ymax"; + "Buffer size"],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",-1,"vec",-1,"vec",1,"vec",1,.. + "vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + + mess=[]; + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if nbr_curves<=0 then + mess=[mess;"Number of Curves cannot be negative or null";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if N<1 then + mess=[mess;"Buffer size must be at least 1";" "] + ok=%f + end + if N==1 & clrs>0 then + mess=[mess;"Buffer size must be at least 2";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + in = nbr_curves*ones(2,1); + in2 = ones(2,1); + [model,graphics,ok]=set_io(model,graphics,list([in in2],ones(2,1)),list(),ones(1,1),[]); + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=[xmin;xmax;ymin;ymax] + ipar=[win;1;N;clrs;siz;1;wpos(:);wdim(:);nbr_curves] + //if prod(size(dstate))<>2*N+1 then dstate=-eye(2*N+1,1),end + //model.dstate=dstate; + model.rpar=rpar; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + win=-1; + clrs=4;siz=1 + wdim=[600;400] + wpos=[-1;-1] + N=2; + xmin=-15; + xmax=15; + ymin=-15; + ymax=+15 + nbr_curves = 1; + + model=scicos_model() + model.sim=list("cscopxy",4) + model.in=[1;1] + model.in2=[1;1] + model.intyp=[1;1] + model.evtin=1 + model.rpar=[xmin;xmax;ymin;ymax] + model.ipar=[win;1;N;clrs;siz;1;wpos(:);wdim(:);nbr_curves] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[string(nbr_curves); + sci2exp(clrs); + sci2exp(siz); + string(win); + sci2exp([]); + sci2exp(wdim); + string(xmin); + string(xmax); + string(ymin); + string(ymax); + string(N)]; + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/CSCOPXY3D.sci b/macros/Sinks/CSCOPXY3D.sci new file mode 100644 index 00000000..1deebd53 --- /dev/null +++ b/macros/Sinks/CSCOPXY3D.sci @@ -0,0 +1,157 @@ +// 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]=CSCOPXY3D(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,nbr_curves,clrs,siz,win,wpos,wdim,vec_x,vec_y,vec_z,param3ds,N,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["Number of curves"; + "color (>0) or mark (<0)"; + "Line or Mark Size"; + "Output window number (-1 for automatic)"; + "Output window position"; + "Output window sizes"; + "Xmin and Xmax"; + "Ymin and Ymax"; + "Zmin and Zmax"; + "Alpha and Theta"; + "Buffer size"],.. + list("vec",1,"vec",-1,"vec",-1,"vec",1,"vec",-1,"vec",-1,"vec",2,"vec",2,"vec",2,"vec",2,"vec",1),.. + exprs) + if ~ok then + break, + end //user cancel modification + mess=[]; + if size(wpos,"*")<>0 &size(wpos,"*")<>2 then + mess=[mess;"Window position must be [] or a 2 vector";" "] + ok=%f + end + if size(wdim,"*")<>0 &size(wdim,"*")<>2 then + mess=[mess;"Window dim must be [] or a 2 vector";" "] + ok=%f + end + if size(clrs,"*")<>size(siz,"*") then + mess=[mess;"Colors and Size must have same size";" "] + ok=%f + end + if nbr_curves<=0 then + mess=[mess;"Number of curves cannot be negative or null";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if N<1 then + mess=[mess;"Buffer size must be at least 1";" "] + ok=%f + end + if N<2 + for i=1:size(clrs,"*") + if clrs(i)>0 then + mess=[mess;"Buffer size must be at least 2 or Change a color (must be >0)";" "] + ok=%f + end + end + end + if vec_y(1)>=vec_y(2) then + mess=[mess;"Ymax must be higher than Ymin";" "] + ok=%f + end + if vec_x(1)>=vec_x(2) then + mess=[mess;"Xmax must be higher than Xmin";" "] + ok=%f + end + if vec_z(1)>=vec_z(2) then + mess=[mess;"Zmax must be higher than Zmin";" "] + ok=%f + end + if ok then + in = nbr_curves*ones(3,1); + in2 = ones(3,1); + [model,graphics,ok]=set_io(model,graphics,list([in in2],ones(3,1)),list(),ones(1,1),[]); + if wpos==[] then + wpos=[-1;-1]; + end + if wdim==[] then + wdim=[-1;-1]; + end + rpar=[vec_x(:);vec_y(:);vec_z(:);param3ds(:)] + size_siz = size(siz,"*"); + ipar=[win;size_siz;N;clrs(:);siz(:);1;wpos(:);wdim(:);nbr_curves] + model.rpar=rpar; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + else + message(mess); + end + end + case "define" then + win = -1; + clrs = [1;2;3;4;5;6;7;13] + siz = [1;1;1;1;1;1;1;1] + wdim = [600;400] + wpos = [-1;-1] + N=2; + param3ds=[50;280] + vec_x = [-15;15] + vec_y = [-15;15] + vec_z = [-15;15] + nbr_curves = 1; + + model=scicos_model() + model.sim=list("cscopxy3d",4) + model.in=[1;1;1] + model.in2=[1;1;1] + model.intyp=[1;1;1] + model.evtin=1 + model.rpar=[vec_x(:);vec_y(:);vec_z(:);param3ds(:)] + model.ipar=[win;8;N;clrs(:);siz(:);8;wpos(:);wdim(:);nbr_curves] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[string(nbr_curves); + strcat(string(clrs)," "); + strcat(string(siz)," "); + string(win); + sci2exp([]); + sci2exp(wdim); + strcat(string(vec_x)," "); + strcat(string(vec_y)," "); + strcat(string(vec_z)," "); + strcat(string(param3ds)," "); + string(N)]; + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/OUTIMPL_f.sci b/macros/Sinks/OUTIMPL_f.sci new file mode 100644 index 00000000..cd3a9c65 --- /dev/null +++ b/macros/Sinks/OUTIMPL_f.sci @@ -0,0 +1,77 @@ +// 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]=OUTIMPL_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"),"OUTIMPL_f");" ";gettext("Implicit output port")],.. + gettext("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.in=[-1] + model.in2=[1] + prt=1 + model.sim="outimpl" + model.ipar=[1] + model.blocktype="c" + model.dep_ut=[%f %f] + mo=modelica() + mo.model="PORT" + mo.inputs="n" + model.equations=mo + exprs="1" + gr_i=[] + x=standard_define([1 1],model,exprs,gr_i) + // x.graphics.flip=%f //flip it + x.graphics.in_implicit=["I"] + end +endfunction diff --git a/macros/Sinks/OUT_f.sci b/macros/Sinks/OUT_f.sci new file mode 100644 index 00000000..23ecb20c --- /dev/null +++ b/macros/Sinks/OUT_f.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]=OUT_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 + while %t do + [ok,prt,exprs]=scicos_getvalue([msprintf(gettext("Set %s block parameters"),"OUT_f");" ";gettext("Regular output port")],.. + gettext("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 + model.ipar=prt + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + n=-1 + prt=1 + model=scicos_model() + model.sim="output" + model.in=-1 + model.in2=-2 + model.intyp=-1 + model.ipar=prt + model.blocktype="c" + 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/Sinks/TOWS_c.sci b/macros/Sinks/TOWS_c.sci new file mode 100644 index 00000000..dd43a956 --- /dev/null +++ b/macros/Sinks/TOWS_c.sci @@ -0,0 +1,104 @@ +// Scicos +// +// Copyright (C) INRIA - Alan Layec <alan.layec@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] = TOWS_c(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, nz, varnam, herit, exprs] = scicos_getvalue("Set Xcos buffer block", ... + ["Size of buffer"; + "Scilab variable name"; + "Inherit (no:0, yes:1)"], ... + list("vec", 1, "str", 1, "vec", 1), exprs); + + if ~ok then + break, + end; + + if (nz <= 0) then + message("Size of buffer must be positive"); + ok = %f; + end + + //check for valid name variable + r = %f; + ierr = execstr("r = validvar(varnam)", "errcatch"); + if ~r | ierr <> 0 | length(varnam) > 19 then + message(["Invalid variable name."; "Please choose another variable name."]); + ok = %f; + end + // If varnam already exists, then it must be of type struct (17) with fields "values" and "names". + // Otherwise, it is considered as a protected variable, an error is raised and user will be asked to enter a new name. + execstr("if type("+varnam+") <> 17 | or(fieldnames("+varnam+") <> [""values""; ""time""]) then" + ... + " message([""Protected variable name.""; ""Please choose another variable name.""]);" + ... + " ok = %f;" + ... + " end", "errcatch"); + + if ok then + [model, graphics, ok] = set_io(model, graphics, ... + list([-1, -2], -1), list(), ... + ones(1-herit, 1), []); + if herit == 1 then + model.blocktype = "x"; + else + model.blocktype = "d"; + end + model.ipar = [nz; length(varnam); ascii(varnam)']; + graphics.exprs = exprs; + x.graphics = graphics; + x.model = model; + break + end + end + + case "define" then + nu = -1; + nz = 128; + varnam = "A"; + herit = 0; + + model = scicos_model(); + model.sim = list("tows_c", 4); + model.in = [nu]; + model.in2 = -2; + model.intyp = -1; + model.out = []; + model.evtin = [1]; + model.evtout = []; + model.rpar = []; + model.ipar = [nz; length(varnam); ascii(varnam)']; + model.blocktype = "d"; + model.firing = []; + model.dep_ut = [%f %f]; + gr_i = []; + exprs = [string(nz); string(varnam); string(herit)]; + x = standard_define([4 2], model, exprs, gr_i); + end +endfunction + diff --git a/macros/Sinks/TRASH_f.sci b/macros/Sinks/TRASH_f.sci new file mode 100644 index 00000000..77ef27fc --- /dev/null +++ b/macros/Sinks/TRASH_f.sci @@ -0,0 +1,43 @@ +// 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]=TRASH_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + case "define" then + in=-1 + + model=scicos_model() + model.sim="trash" + model.in=in + model.evtin=1 + 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/Sinks/WFILE_f.sci b/macros/Sinks/WFILE_f.sci new file mode 100644 index 00000000..a15df937 --- /dev/null +++ b/macros/Sinks/WFILE_f.sci @@ -0,0 +1,128 @@ +// 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]=WFILE_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + warnobsolete("WRITEC_f", "6.0.0"); + warnMessage = msprintf(_("Feature %s is obsolete."), "WFILE_f"); + warnAdvise = msprintf(_("Please use %s instead."), "WRITEC_f"); + warnXcosMessage = msprintf("%s %s", warnMessage, warnAdvise); + warnBlockByUID(arg1.model.label, warnXcosMessage); + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + dstate=model.dstate + lunit=dstate(2) + fname=exprs(2) + frmt=exprs(3) + while %t do + [ok,in,fname1,frmt1,N,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "WFILE_f");" "; gettext("Write to output file"); " "; .. + gettext("Write is done on:"); gettext(" - A binary file if no format given"); .. + gettext(" - A formatted text file if a format (Fortran type) is given")], [gettext("Input Size"); gettext("Output File Name"); .. + gettext("Output Format"); gettext("Buffer Size")], list("vec",1,"str",1,"str",1,"vec",1),exprs) + + if ~ok then + break, + end //user cancel modification + in=int(in) + + nin=in + + fname1 = pathconvert(stripblanks(fname1), %f, %t) // File name expansion + frmt1=stripblanks(frmt1) + + if 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 when running"), gettext("End current simulation first.")); + ok=%f + elseif lunit > 0 & fname1 <> fname then + block_parameter_error(gettext("You cannot modify ''Output File Name'' when running."), gettext("End current simulation first.")); + ok=%f + elseif fname1 == "" then + block_parameter_error(gettext("Wrong value for ''Output File Name'' parameter"), gettext("You must provide a filename.")); + ok=%f + //Check if directory exist + elseif fileparts(fname1) ~= "" then + [pa, fn, ex] = fileparts(fname1) + if ~isdir(pa) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Output File Name")), .. + msprintf(gettext("Directory ''%s'' does not exist"), pa )); + ok=%f + end + // 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 value for ''%s'' parameter: %s."), gettext("Input Format"), frmt1), .. + gettext("You must enclose the format''s string between parentheses.")); + ok=%f + elseif N < 2 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer Size"), N), .. + gettext("Must be greater than 1.")); + ok=%f + elseif in <= 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Input Size"), in), .. + gettext("Strictly positive integer expected.")); + ok=%f + end + + if ok then + ipar=[length(fname1);length(frmt1);0;N;_str2code(fname1);_str2code(frmt1)] + if prod(size(dstate))<>(nin+1)*N+2 then + dstate=[-1;lunit;zeros((nin+1)*N,1)] + end + model.in=nin + model.dstate=dstate;model.ipar=ipar + model.dep_ut=[%t %f] //compatibility + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=1; + nin=sum(in) + frmt="(7(e10.3,1x))" + fname="foo" + lunit=0 + N=2; + + model=scicos_model() + model.sim="writef" + model.in=in + model.evtin=1 + model.dstate=[-1;lunit;zeros((nin+1)*N,1)] + model.ipar=[length(fname);length(frmt);0;N;_str2code(fname);_str2code(frmt)] + model.blocktype="d" + model.dep_ut=[%t %f] + + exprs=[sci2exp(in); + fname; + frmt; + string(N)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/WRITEAU_f.sci b/macros/Sinks/WRITEAU_f.sci new file mode 100644 index 00000000..7cfed31c --- /dev/null +++ b/macros/Sinks/WRITEAU_f.sci @@ -0,0 +1,102 @@ +// 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]=WRITEAU_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + ipar=model.ipar; + dstate=model.dstate + lunit=dstate(2) + while %t do + [ok,N,swap,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "WRITEAU_f");" "; .. + gettext("Write ''.au'' sound file on audio device")],[gettext("Buffer Size"); gettext("Swap Mode (0:No, 1:Yes)")], .. + list("vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + + nin=1 + + fname1="/dev/audio" + frmt1="uc " + + if alreadyran & (N <> ipar(5)) then + block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running."), gettext("Buffer Size")), .. + gettext("End current simulation first")); + ok=%f + elseif N < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer Size"), N), .. + gettext("Strictly positive integer expected.")); + ok=%f + end + if 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]")); + ok=%f + end + + if ok then + ipar=[length(fname1);_str2code(frmt1);N;swap;_str2code(fname1)] + if prod(size(dstate))<>(nin+1)*N+2 then + dstate=[-1;lunit;zeros((nin+1)*N,1)] + end + model.in=1 + model.dstate=dstate; + model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + + end + case "define" then + in=1; + nin=sum(in) + frmt="uc " + fname="/dev/audio" + swap=0 + lunit=0 + N=2; + + model=scicos_model() + model.sim=list("writeau",2) + model.in=in + model.evtin=1 + model.dstate=[-1;lunit;zeros((nin+1)*N,1)] + model.ipar=[length(fname);_str2code(frmt);N;swap;_str2code(fname)] + model.blocktype="d" + model.dep_ut=[%t %f] + + exprs=[string(N) + string(swap)] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Sinks/WRITEC_f.sci b/macros/Sinks/WRITEC_f.sci new file mode 100644 index 00000000..c07a52c9 --- /dev/null +++ b/macros/Sinks/WRITEC_f.sci @@ -0,0 +1,134 @@ +// Xcos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2011 Bernard DUJARDIN <bernard.dujardin@scilab.contrib.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]=WRITEC_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + ipar=model.ipar; + dstate=model.dstate + lunit=dstate(2) + fname=exprs(2) + frmt=exprs(3) + while %t do + [ok,in,fname1,frmt1,N,swap,exprs] = scicos_getvalue([msprintf(gettext("Set %s block parameters"), "WRITEC_f");" "; .. + gettext("Write to C binary file")], [gettext("Input Size"); gettext("Output File Name"); .. + gettext("Output Format"); gettext("Buffer Size"); gettext("Swap Mode (0:No, 1:Yes)")], .. + list("vec",1,"str",1,"str",1,"vec",1,"vec",1),exprs) + + if ~ok then + break, + end //user cancel modification + + in=int(in) + nin=in + + 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"] + + if 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,", "))); + ok=%f + elseif alreadyran & fname1 <> fname then + block_parameter_error(msprintf(gettext("You cannot modify ''%s'' when running"), gettext("Input Format")), .. + gettext("End current simulation first.")); + ok=%f + elseif alreadyran & N <> ipar(5) then + block_parameter_error(msprintf(gettext("You cannot modify ''Buffer Size'' when running."), gettext("Buffer Size")), .. + gettext("End current simulation first")); + ok=%f + elseif fname1 == "" then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Output File Name")), gettext("You must provide a filename.")); + //Check if directory exist + elseif fileparts(fname1) ~= "" then + [pa, fn, ex] = fileparts(fname1) + if ~isdir(pa) then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter."), gettext("Output File Name")), .. + msprintf(gettext("Directory ''%s'' does not exist"), pa )); + ok=%f + end + elseif N < 1 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Buffer Size"), N), .. + gettext("Strictly positive integer expected.")); + ok=%f + elseif in <= 0 then + block_parameter_error(msprintf(gettext("Wrong value for ''%s'' parameter: %d."), gettext("Input Size"), in), .. + gettext("Strictly positive integer expected.")); + ok=%f + 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]")); + ok=%f + end + + frmt1=part(frmt1,1:3) + + if ok then + ipar=[length(fname1);_str2code(frmt1);N;swap;_str2code(fname1)] + if prod(size(dstate))<>(nin+1)*N+2 then + dstate=[-1;lunit;zeros((nin+1)*N,1)] + end + model.in=nin + model.dstate=dstate; + model.ipar=ipar + // model.firing=[] //compatibility + // model.dep_ut=[%t %f] //compatibility + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=1; + nin=sum(in) + frmt="c " + fname="foo" + swap=0 + lunit=0 + N=2; + model=scicos_model() + model.sim=list("writec",2) + model.in=in + model.evtin=1 + model.dstate=[-1;lunit;zeros((nin+1)*N,1)] + model.ipar=[length(fname);_str2code(frmt);N;swap;_str2code(fname)] + model.blocktype="d" + model.dep_ut=[%t %f] + + exprs=[sci2exp(in); + fname; + frmt; + string(N) + string(swap)] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction 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 + + + + diff --git a/macros/Threshold/GENERAL_f.sci b/macros/Threshold/GENERAL_f.sci new file mode 100644 index 00000000..8ff3b59d --- /dev/null +++ b/macros/Threshold/GENERAL_f.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]=GENERAL_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + rpar=model.rpar + in=model.in; + out=model.evtout + nin=sum(in) + nout=sum(out) + [ok,in,out,exprs]=scicos_getvalue("Set General Zero-Crossing parameters",.. + ["Input size"; + "Number of event output"],.. + list("vec",1,"vec",1),exprs) + if ok then + [model,graphics,ok]=check_io(model,graphics,in,[],[],ones(out,1)) + if ok then + nout1=out + nin1=in + if nout==nout1 & nin==nin1 then + rp=matrix(rpar,nout,2^(2*nin)); + else + rp=-1*ones(nout1,2^(2*nin1)) + end + n=size(rp,2)/2 + result=x_mdialog("routing matrix",string(1:nout1),.. + string(1:2^(2*nin1)),string(rp(:,:))) + if result<>[] then + rp(1:nout1,1:2*n)=evstr(result) + model.nzcross=in + model.rpar=rp(:) + model.firing=-ones(out,1) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + end + end + end + case "define" then + rpar=[0;0;0;0] + in=1; + out=1; + model=scicos_model() + model.sim=list("zcross",1) + model.nzcross=in + model.in=in + model.evtout=ones(out,1) + model.rpar=[0;0;0;0] + model.blocktype="z" + model.firing=-ones(out,1), + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(in));strcat(sci2exp(out))] + gr_i=[] + x=standard_define([3 2],model,exprs, gr_i) + end +endfunction diff --git a/macros/Threshold/NEGTOPOS_f.sci b/macros/Threshold/NEGTOPOS_f.sci new file mode 100644 index 00000000..9e8257ef --- /dev/null +++ b/macros/Threshold/NEGTOPOS_f.sci @@ -0,0 +1,44 @@ +// 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]=NEGTOPOS_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=-1 //compatibility + case "define" then + model=scicos_model() + model.sim=list("zcross",1) + model.nzcross=1 + model.in=1 + model.evtout=1 + model.rpar=[-1;-1;0;-1] + model.blocktype="z" + model.firing=-1 + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Threshold/POSTONEG_f.sci b/macros/Threshold/POSTONEG_f.sci new file mode 100644 index 00000000..69bb3946 --- /dev/null +++ b/macros/Threshold/POSTONEG_f.sci @@ -0,0 +1,44 @@ +// 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]=POSTONEG_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[-1] //compatibility + case "define" then + rpar=[-1;-1;-1;0] + model=scicos_model() + model.sim=list("zcross",1) + model.nzcross=1 + model.in=1 + model.evtout=1 + model.rpar=[-1;-1;-1;0] + model.blocktype="z" + model.dep_ut=[%t %f] + model.firing=[-1] + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Threshold/ZCROSS_f.sci b/macros/Threshold/ZCROSS_f.sci new file mode 100644 index 00000000..f88dd069 --- /dev/null +++ b/macros/Threshold/ZCROSS_f.sci @@ -0,0 +1,75 @@ +// 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]=ZCROSS_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,in,exprs]=scicos_getvalue(["Set Zero-Crossing parameters";.. + "All surfaces must cross together"],.. + "Input size",list("vec",1),exprs) + if ~ok then + break, + end + in=int(in) + if in<=0 then + message("Block must have at least one input") + else + kk=0 + for jj=1:in + kk=kk+2^(in+jj-1) + end + model.rpar=[-ones(kk,1);zeros(2^(2*in)-kk,1)] + graphics.exprs=exprs + model.in=in + model.nzcross=in + model.firing=-1 //compatibility + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + rpar=[-1;-1;0;0] + in=1 + + model=scicos_model() + model.sim=list("zcross",1) + model.in=in + model.nzcross=in + model.evtout=1 + model.rpar=[-1;-1;0;0] + model.blocktype="z" + model.firing=-1 + model.dep_ut=[%t %f] + + exprs=strcat(sci2exp(in)) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction |