bf795a66678d6f58787b7f4bb5c35ad1872193ce
[scilab.git] / scilab / modules / scicos / macros / scicos_scicos / cos2cosf.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function ierr = cos2cosf(u,scs_m,count)
23
24     //write scilab instructions whose evaluation
25     //returns the  value of scicos data structure scs_m.
26     //in the opened file associated with logical unit u
27
28     [lhs,rhs]=argn(0)
29     ierr=0;
30     if rhs<3 then
31         count=0,
32         lname="scs_m"
33     else
34         count=count+1
35         lname="scs_m_"+string(count)
36     end
37
38     lmax=80;
39
40     //////////////////
41     txt=[];
42
43     //version
44     txt=[txt;"version="""+get_scicos_version()+""",.."];
45
46     //scicos_params
47     tt=[];
48     fields=getfield(1,scs_m.props);
49     for i=1:lstsize(scs_m.props)-1
50         field_nam=fields(i+1);
51         if field_nam=="title" then field_nam="Title", end
52         tt2=sci2exp(getfield(i+1,scs_m.props),lmax);
53         tt2(1)=field_nam+"="+tt2(1);
54         if i<>lstsize(scs_m.props)-1 then
55             tt2($)=tt2($)+",";
56         end
57         tt=[tt;tt2];
58     end
59
60     tt=my_strcat(tt);
61     txt=[txt;
62     "props=scicos_params(..";
63     "      "+tt(1)];
64     for i=2:size(tt,1)
65         txt=[txt;"      "+tt(i)];
66     end
67     txt($)=txt($)+")";
68
69     //scicos_diagram
70     txt=["scicos_diagram(..";txt];
71     txt($)=txt($)+")";
72
73     //final work
74     txt(1)=lname+"="+txt(1);
75     bl1=" ";
76     for i=2:size(txt,1)
77         txt(i)=part(bl1,1:length(lname)+1)+txt(i);
78     end
79     //////////////////
80
81     ierr=execstr("write(u,txt,''(a)'')","errcatch");
82     if ierr<>0 then return, end;
83
84     t=[];
85
86     for k=1:lstsize(scs_m.objs)
87
88         o=scs_m.objs(k)
89         if typeof(o)=="Block" then
90             lhs=lname+".objs("+string(k)+")="
91
92             if o.model.sim=="super"| o.model.sim=="csuper"| o.model.sim(1)=="asuper" then  //Super blocks
93                 cos2cosf(u,o.model.rpar,count);//model.rpar
94             end
95             //////////////////
96             txt=[];
97
98             //gui
99             tt=sci2exp(o.gui);
100             txt=[txt;"gui="+tt(1)];
101             for i=2:size(tt,1)
102                 txt=[txt;"         "+tt(i)];
103             end
104             txt($)=txt($)+",..";
105
106             //scicos_graphics
107             tt=[];
108             fields=getfield(1,o.graphics);
109             for i=1:lstsize(o.graphics)-1
110                 field_nam=fields(i+1);
111                 tt2=sci2exp(getfield(i+1,o.graphics),lmax);
112                 tt2(1)=field_nam+"="+tt2(1);
113                 if i<>lstsize(o.graphics)-1 then
114                     tt2($)=tt2($)+",";
115                 end
116                 tt=[tt;tt2];
117             end
118
119             tt=my_strcat(tt);
120             txt=[txt;
121             "graphics=scicos_graphics(..";
122             "         "+tt(1)];
123             for i=2:size(tt,1)
124                 txt=[txt;"         "+tt(i)];
125             end
126             txt($)=txt($)+"),..";
127
128             //scicos_model
129             tt=[];
130             fields=getfield(1,o.model);
131             for i=1:lstsize(o.model)-1
132                 field_nam=fields(i+1);
133                 if field_nam=="rpar"&(o.model.sim=="super"| o.model.sim=="csuper"| o.model.sim(1)=="asuper") then
134                     tt2="scs_m_"+string(count+1);
135                 else
136                     tt2=sci2exp(getfield(i+1,o.model),lmax);
137                 end
138                 tt2(1)=field_nam+"="+tt2(1);
139                 if i<>lstsize(o.model)-1 then
140                     tt2($)=tt2($)+",";
141                 end
142                 tt=[tt;tt2];
143             end
144
145             tt=my_strcat(tt);
146             txt=[txt;
147             "model=scicos_model(..";
148             "         "+tt(1)];
149             for i=2:size(tt,1)
150                 txt=[txt;"         "+tt(i)];
151             end
152             txt($)=txt($)+"),..";
153
154             //doc
155             tt=sci2exp(o.doc,50);
156             txt=[txt;"doc="+tt(1)];
157             for i=2:size(tt,1)
158                 txt=[txt;"         "+tt(i)];
159             end
160
161             //scicos_block
162             txt=["scicos_block(..";txt];
163             txt($)=txt($)+")";
164
165             //final work
166             txt(1)=lhs+txt(1);
167             bl1=" ";
168             for i=2:size(txt,1)
169                 txt(i)=part(bl1,1:length(lhs))+txt(i);
170             end
171             write(u,txt,"(a)");
172             ///////////////
173         else //link
174             lhs=lname+".objs("+string(k)+")="
175             if typeof(o)=="Link" then
176                 //scicos_link
177                 tt=[];
178                 txt=[];
179                 fields=getfield(1,o);
180                 for i=1:lstsize(o)-1
181                     field_nam=fields(i+1);
182                     tt2=sci2exp(getfield(i+1,o),lmax);
183                     tt2(1)=field_nam+"="+tt2(1);
184                     if i<>lstsize(o)-1 then
185                         tt2($)=tt2($)+",";
186                     end
187                     tt=[tt;tt2];
188                 end
189
190                 tt=my_strcat(tt);
191                 txt=[txt;
192                 "scicos_link(..";
193                 "  "+tt(1)];
194                 for i=2:size(tt,1)
195                     txt=[txt;"  "+tt(i)];
196                 end
197                 txt($)=txt($)+")";
198
199                 //final work
200                 txt(1)=lhs+txt(1);
201                 bl1=" ";
202                 for i=2:size(txt,1)
203                     txt(i)=part(bl1,1:length(lhs))+txt(i);
204                 end
205                 write(u,txt,"(a)");
206
207             else // ??
208                 // Alan : JESAISPASIYADAUTRESOBJS
209                 // QUEDESBLOCKSETDESLINKSDANSSCICOS
210                 // ALORSJELAISSELEVIEUCODE
211                 t=[]
212                 t1=sci2exp(o,lmax-length(lhs))
213                 n1=size(t1,1)
214                 bl1=" ";bl1=part(bl1,1:length(lhs))
215                 t=[t;lhs+t1(1);bl1(ones(n1-1,1))+t1(2:$)]
216                 write(u,t,"(a)");
217             end
218         end
219     end
220
221 endfunction
222
223 function txt_out=my_strcat(txt)
224     txt_out=[]
225     for i=1:size(txt,1)
226         txt_out(i)=txt(i);
227         if length(txt_out(i))<>0 then
228             if part(txt_out(i),length(txt_out(i)))=="," then
229                 txt_out(i)=txt_out(i)+"..";
230             end
231         end
232     end
233 endfunction