46d4acc4cac5535295aa80cdce4de4aaa4a9112f
[scilab.git] / scilab / modules / scicos_blocks / macros / Electrical / Inductor.sci
1 //  Scicos
2 //
3 // Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 // Copyright (C) 2018 - Samuel GOUGEON
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 //
20 // See the file ../license.txt
21 //
22
23 function [x,y,typ]=Inductor(job,arg1,arg2)
24     // Copyright INRIA
25     x=[];
26     y=[];
27     typ=[];
28     select job
29     case "set" then
30         x=arg1;
31         graphics=arg1.graphics;
32         exprs=graphics.exprs
33         model=arg1.model;
34         while %t do
35             [ok,L,exprs]=scicos_getvalue("Set Inductor block parameter",..
36             "L (H)",list("vec",1),exprs)
37             if ~ok then
38                 break,
39             end
40             model.rpar=L
41             model.equations.parameters(2)=list(L)
42             graphics.exprs=exprs
43
44             // Updating the icon according to the inductance value:
45             v = evstr(exprs(1));
46             if v>=1e-8 & v<1e-5
47                 sv = msprintf("%d\\:n\n",v*1e9)
48             elseif v>=1e-5 & v<1e-2
49                 sv = msprintf("%d\\:\\mu\n",v*1e6)
50             elseif v>=1e-2 & v<10
51                 sv = msprintf("%d\\:m\n",v*1000)
52             elseif v>=10 & v<10000
53                 sv = msprintf("%d\\:\n",v)
54             elseif v>=1e4 & v<1e7
55                 sv = msprintf("%d\\:k\n",v/1000)
56             else
57                 p = floor(log10(v));
58                 v = v/(10^p);
59                 sv = msprintf("%3.1f\\,10^{%d}\\,\n",v,p)
60             end
61             lab = "Inductor;displayedLabel=" + ..
62             "$\mathsf{\,\\\,\\\,\\\,\\\,\\\,\\\,\\\,\,\\\tiny{\!"+sv+" H}}$"
63             graphics.style = lab;
64             x.graphics=graphics;
65
66             x.model=model
67             break
68         end
69     case "define" then
70         model=scicos_model()
71         model.in=[1];
72         model.out=[1];
73         L=1.d-5
74         model.rpar=L
75         model.sim="Inductor"
76         model.blocktype="c"
77         model.dep_ut=[%t %f]
78         mo=modelica();
79         mo.model="Inductor"
80         mo.inputs="p";
81         mo.outputs="n";
82         mo.parameters=list("L",list(L))
83         model.equations=mo;
84         exprs=string(L)
85
86         gr_i=[]
87
88         x=standard_define([2 2],model,exprs,list(gr_i,0))
89         x.graphics.in_implicit=["I"]
90         x.graphics.out_implicit=["I"]
91     end
92 endfunction