ca83c5787f82ae4716b7cbd77dc3b1afd3461ef1
[scilab.git] / scilab / modules / string / macros / sci2exp.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA -
3 // Copyright (C) 2016 - Samuel GOUGEON
4 //
5 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 //
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
13
14 function t=sci2exp(a,nom,lmax)
15     // sci2exp - convert a variable to an expression
16     //%SYNTAX
17     // t=sci2exp(a [,nam] [,lmax])
18     //%PARAMETERS
19     //   a  : matrix of scalar or polynomials
20     //   nam: character string
21     //   t  : vector of string, contains the expression definition
22     //   lmax : maximum line lengh (0 for no line length control)
23     //%Example
24     //  a=[1 2;3 4]
25     //  sci2exp(a,'aa')
26     //!
27
28     deff("x=String(a)",["x=string(a)"
29     "x=strsubst(x,''Nan'',''%nan'')"
30     "x=strsubst(x,''Inf'',''%inf'')"
31     ])
32
33
34     [lhs,rhs]=argn(0)
35     $ // import global variable $ in sci2exp context for efficiency
36     select rhs
37     case 1 then
38         named=%f
39         lmax=0
40     case 2 then
41         if type(nom)==1 then
42             lmax=nom
43             named=%f
44         else
45             named=%t
46             lmax=0
47         end
48     case 3 then
49         named=%t
50         if type(nom)==1 then
51             [lmax,nom]=(nom,lmax)
52         end
53     end
54     dots="..";
55     select type(a)
56     case 1 then
57         t=mat2exp(a,lmax)
58     case 2 then
59         t=pol2exp(a,lmax)
60     case 4 then
61         t=log2exp(a,lmax)
62     case 5 then
63         t=sp2exp(a,lmax)
64     case 6 then
65         t=sp2exp(a,lmax)
66     case 7 then
67         t=sp2exp(a,lmax)
68     case 8 then
69         t=int2exp(a,lmax)
70     case 9 then
71         t=h2exp(a, lmax)
72     case 10 then
73         t=str2exp(a,lmax)
74     case 13 then
75         tree=macr2tree(a);
76         strfun=tree2code(tree);
77         name="%fun";
78         if named then
79             name=nom;
80         end
81         idx=strindex(strfun(1), "=");
82         idx2=strindex(part(strfun(1), idx:$), "(") + idx - 1;
83         str=part(strfun(1), 1:idx) + " "+ name + part(strfun(1), idx2:length(strfun(1)));
84         strfun(1)=str;
85         strfun($)=[];
86         t=strfun;
87         t(1)=part(t(1),10:length(t(1)))
88         t($)=[]
89         t=sci2exp(t,lmax)
90         t(1)="createfun("+t(1)
91         t($)=t($)+")"
92     case 15 then
93         t=list2exp(a,lmax)
94     case 16 then
95         t=tlist2exp(a,lmax)
96     case 17 then
97         t=mlist2exp(a,lmax)
98     case 129 then
99         t=imp2exp(a,lmax)
100     else
101         //  execstr('t='+typeof(a)+'2exp(a,lmax)')
102         error(msprintf(gettext("%s: This feature has not been implemented: Variable translation of type %s.\n"),"sci2exp",string(type(a))));
103     end,
104     if named&and(type(a)<>13) then
105         t(1)=nom+" = "+t(1)
106     end
107 endfunction
108
109 function t=str2exp(a,lmax)
110     if rhs<2 then lmax=0,end
111     [lhs,rhs]=argn(0)
112
113     [m,n]=size(a),
114     dots="."+"."
115     t="";
116     quote="''"
117
118     a=strsubst(a,quote,quote+quote)
119     dquote=""""
120     a=strsubst(a,dquote,dquote+dquote)
121     a = strsubst(a, ascii(10), """+ascii(10)+""")
122     a=quote(ones(a))+a+quote(ones(a))
123
124     for i=1:m
125         x=emptystr();
126         for j=1:n,
127             y=a(i,j);
128             y=dquote+part(y,2:length(y))
129             y=part(y,1:length(y)-1)+dquote
130             if y=="''''" then y="emptystr()",end
131             if lmax==0|length(x($))+length(y)<lmax then
132                 if j==1 then
133                     x=y
134                 else
135                     x($)=x($)+","+y,
136                 end
137             else
138                 if j>1 then
139                     x($)=x($)+","+dots;
140                     x($+1)=y
141                 else
142                     x=y
143                 end
144             end
145         end
146         if i<m then x($)=x($)+";",end
147         if lmax>0 then
148             t=[t;x]
149         else
150             t=t+x
151         end
152     end,
153     if lmax>0&sum(length(t))<lmax then
154         t=strcat(t)
155     end
156     if m*n>1 then
157         t(1)="["+t(1)
158         t($)=t($)+"]"
159     end
160 endfunction
161
162 function t=mat2exp(a,lmax)
163     if rhs<2 then lmax=0,end
164     [lhs,rhs]=argn(0)
165     if size(a,"*")==0 then t="[]",return,end
166     [m,n]=size(a);
167     if m<0 then
168         t=mat2exp(a+0);
169         if t=="1" then
170             t="eye()";
171         else
172             t="("+t+")*eye()";
173         end
174         return
175     end
176     a=String(a);
177     dots="."+"."
178     t="";
179     if n==1 then
180         x=strcat(a,";")
181         lx=length(x)
182         if lmax==0|lx<lmax then
183             t=x;
184         else
185             ind=strindex(x,";");
186             k1=1;l=0;I=[];
187             while %t
188                 if lx-l<lmax|k1>length(ind) then,break,end
189                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
190                 I=[I ind(k2)];
191                 //      t=[t;part(x,l+1:ind(k2))]
192                 k1=k2+1
193                 l=ind(k2)
194             end
195             t=[t;strsplit(x,I)];
196         end
197     elseif m==1 then
198         x=strcat(a,",")
199         lx=length(x)
200         if lmax==0|lx<lmax then
201             t=x;
202
203         else
204             ind=strindex(x,",");
205             k1=1;l=0;I=[];
206             while %t
207                 if lx-l<lmax|k1>length(ind) then break,end
208                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
209                 I=[I ind(k2)];
210                 //      t=[t;part(x,l+1:ind(k2))+dots]
211                 k1=k2+1
212                 l=ind(k2)
213             end
214             x=strsplit(x,I);x(1:$-1)=x(1:$-1)+dots;
215             t=[t;x]
216         end
217     else
218         for i=1:m
219             x=strcat(a(i,:),",")
220             if i<m then x=x+";",end
221             lx=length(x)
222             if lmax==0 then
223                 t=t+x
224             elseif lx<lmax then
225                 t=[t;x]
226             else
227                 ind=strindex(x,",");
228                 k1=1;l=0;I=[];
229                 while %t
230                     if lx-l<lmax|k1>length(ind) then break,end
231                     k2=k1-1+max(find(ind(k1:$)<l+lmax))
232                     I=[I ind(k2)];
233                     //    t=[t;part(x,l+1:ind(k2))+dots]
234                     k1=k2+1
235                     l=ind(k2)
236                 end
237                 x=strsplit(x,I);x(1:$-1)=x(1:$-1)+dots;x(2:$)=" "+x(2:$);
238                 t=[t;x]
239             end
240         end
241     end
242     if m*n>1 then
243         t(1)="["+t(1)
244         t($)=t($)+"]"
245     end
246 endfunction
247
248 function t=pol2exp(a,lmax)
249     $
250     if rhs<2 then lmax = 0, end
251     [lhs,rhs] = argn(0)
252
253     [m,n]=size(a),var=" ";lvar=1
254     var=varn(a),lvar=length(var);
255     while part(var,lvar)==" " then lvar=lvar-1,end
256     var=part(var,1:lvar);
257     if m<0 then
258         t=pol2exp(a+0)
259         t="("+t+")*eye()"
260         return
261     end
262     t=[];
263     for i=1:m
264         x=emptystr(1)
265         for j=1:n,
266             v=a(i,j);d=degree(v);
267             v=coeff(v);
268             k0=1;while (k0<d+1)&(v(k0))==0 then k0=k0+1,end
269             y=emptystr(1)
270             nul=%t
271             for k=k0:(d+1),
272                 s=String(v(k))
273                 if s<>"0" then
274                     nul=%f
275                     if part(s,1)==" " then s=part(s,2:length(s)),end
276                     mnm=emptystr(1)
277                     if k>0 then
278                         mnm=var
279                         if k>2 then
280                             mnm=mnm+"^"+string(k-1),
281                         end
282                     end
283                     if k>1 then
284                         if string(imag(v(k)))<>"0" then s="("+s+")",end
285                         if s=="1" then
286                             s=mnm
287                         elseif s=="-1" then
288                             s="-"+mnm
289                         else
290                             s=s+"*"+mnm
291                         end
292                         if k>k0&part(s,1)<>"-" then s="+"+s,end
293                     end
294                     if lmax==0|length(y($))+length(s) <lmax then
295                         y($)=y($)+s
296                     else
297                         y($)=y($)+dots
298                         y($+1)=s
299                     end
300                 end
301             end
302             if nul then y="0*"+var,end
303             [ny,my]=size(y)
304
305             if lmax==0|length(x($))+length(y(1))<lmax then
306                 if j==1 then
307                     x=y(1)
308                 else
309                     x($)=x($)+","+y(1),
310                 end
311                 if ny>1 then x($+1:$+ny-1)=y(2:ny),end
312             else
313                 if length(x($))==0 then
314                     x($:$+ny-1) = y;
315                 else
316                     x($)=x($)+","+dots;
317                     x($+1:$+ny)=y
318                 end
319             end
320         end
321         if i<m then x($)=x($)+";",end
322         if lmax>0 | t==[] then
323             t=[t;x]
324         else
325             t=t+x
326         end
327     end,
328     if lmax>0&sum(length(t))<lmax then
329         t=strcat(t)
330     end
331     if m*n>1 then
332         t(1)="["+t(1)
333         t($)=t($)+"]"
334     end
335 endfunction
336
337 function t = glist2exp(listType, l,lmax)
338     [lhs,rhs] = argn(0)
339     if rhs<3 then lmax = 0, end
340     dots = "."+".";
341     t = listType+"("
342     for k = 1:length(l)
343         sep = ",", if k==1 then sep = "", end
344         clear lk
345         if listType ~= "mlist"
346             lk = l(k)
347         else
348             lk = getfield(k,l)
349         end
350         if ~isdef("lk","local")
351             t1=""
352         else
353             if type(lk)==9 then
354                 t1 = h2exp(lk,lmax)
355             elseif type(lk)==15 then
356                 t1 = list2exp(lk,lmax)
357             elseif type(lk)==16 then
358                 t1 = tlist2exp(lk,lmax)
359             elseif type(lk)==17 then
360                 t1 = mlist2exp(lk,lmax)
361             elseif type(lk)==128 then
362                 t1 = mlist2exp(user2mlist(lk),lmax)
363             else
364                 t1 = sci2exp(lk,lmax)
365             end
366         end
367         if size(t1,"*")==1&(lmax==0|max(length(t1))+length(t($))<lmax) then
368             t($) = t($)+sep+t1
369         else
370             t($) = t($)+sep+dots
371             t = [t; t1]
372         end
373     end
374     t($) = t($)+")"
375 endfunction
376
377 function t = list2exp(l, lmax)
378     t = glist2exp("list", l, lmax)
379 endfunction
380 function t = tlist2exp(l, lmax)
381     t = glist2exp("tlist", l, lmax)
382 endfunction
383 function t = mlist2exp(l, lmax)
384     t = glist2exp("mlist", l, lmax)
385 endfunction
386
387 function t=log2exp(a,lmax)
388     $;
389     if rhs<2 then lmax = 0, end
390     [lhs,rhs] = argn(0)
391     [m,n]=size(a),
392     a1=matrix(a,m*n,1)
393     F="%f"
394     T="%t"
395     a=F(ones(m*n,1))
396     k=find(a1);
397     if k<>[] then
398         a(k)=T(ones(size(k,"*"),1));
399     end
400     a=matrix(a,m,n);
401     dots="."+"."
402     t=[];
403     for i=1:m
404         x=emptystr()
405         for j=1:n,
406             y=a(i,j);
407             if lmax==0|length(x($))+length(y)<lmax then
408                 if j==1 then
409                     x=y
410                 else
411                     x($)=x($)+","+y,
412                 end
413             else
414                 x($)=x($)+","+dots;
415                 x($+1)=y
416             end
417         end
418         t=[t;x]
419     end,
420     if lmax==0|lmax>0&sum(length(t))<lmax then
421         t=strcat(t,";")
422     end
423     if m*n>1 then
424         t(1)="["+t(1)
425         t($)=t($)+"]"
426     end
427
428 endfunction
429
430 function t=func2exp(a,lmax)
431     if rhs<2 then lmax=0,end
432     [lhs,rhs]=argn(0)
433     [out,in,text]=string(a)
434     if out==[] then out=emptystr(),end
435     text=str2exp(text,lmax)
436     nt=size(text,"*")
437     if named then mac=nom,else mac="mac",end
438     if nt==1 then
439         t="deff(''["+strcat(out,",")+"]="+mac+"("+strcat(in,",")+")'',"+text+")"
440     else
441         text($)=text($)+")"
442         semi=";"
443         text(1:$-1)=text(1:$-1)+semi(ones(nt-1,1))'
444         t=["deff(''["+strcat(out,",")+"]="+mac+"("+strcat(in,",")+")'',"+text(1)
445         text(2:$)]
446     end
447 endfunction
448
449 function t=imp2exp(a,lmax)
450     if rhs<2 then lmax=0,end
451     [lhs,rhs]=argn(0)
452     v=[a(1),a(2),a(3)]
453     if a(2)==1 then
454         t=sci2exp(a(1))+":"+sci2exp(a(3))
455     else
456         t=sci2exp(a(1))+":"+sci2exp(a(2))+":"+sci2exp(a(3))
457     end
458 endfunction
459
460 function t=sp2exp(a,lmax)
461     if rhs<2 then lmax=0,end
462     [lhs,rhs]=argn(0)
463     dots="..";
464     [ij,v,mn]=spget(a)
465     t=sci2exp(ij,lmax)
466     v=sci2exp(v,lmax)
467     mn=sci2exp(mn,lmax)
468
469     t(1)="sparse("+t(1)
470     if lmax==0|length(t($))+length(v(1))+1<lmax then
471         t($)=t($)+","+v(1)
472         t=[t;v(2:$)]
473     else
474         t($)=t($)+","+dots
475         t=[t;v]
476     end
477     if lmax==0|length(t($))+length(mn(1))+1<lmax then
478         t($)=t($)+","+mn(1)
479         t=[t;mn(2:$)]
480     else
481         t($)=t($)+","+dots
482         t=[t;mn]
483     end
484     t($)=t($)+")"
485 endfunction
486
487
488 function t=int2exp(a,lmax)
489     it=inttype(a)
490     if it>10 then f="uint",else f="int",end
491     f=f+string(8*modulo(it,10))
492     t=mat2exp(double(a),lmax)
493     t(1)=f+"("+t(1)
494     t($)=t($)+")"
495 endfunction
496
497
498 function t=h2exp(a,lmax) //Only for figure and uicontrol
499     $;
500     if rhs<2 then lmax=0
501     end
502     [lhs,rhs]=argn(0);
503
504
505     f1="''parent'', ";
506     f2="''children'', ";
507     f3="''BackgroundColor'', ";
508     f4="''Enable'', ";
509     f5="''fontAngle'', ";
510     f6="''fontName'', ";
511     f7="''fontSize'', ";
512     f8="''fontUnits'', ";
513     f9="''fontWeight'', ";
514     f10="''ForegroundColor'', ";
515     f11="''HorizontalAlignment'', ";
516     f12="''ListboxTop'', ";
517     f13="''Max'', ";
518     f14="''Min'', ";
519     f15="''Position'', ";
520     f16="''Relief'', ";
521     f17="''SliderStep'', ";
522     f18="''String'', ";
523     f19="''Style'', ";
524     f20="''TooltipString'', ";
525     f21="''Units'', ";
526     f22="''Value'', ";
527     f23="''VerticalAlignment'', ";
528     f24="''Visible'', ";
529     f25="''Callback'', ";
530     f26="''Callback_Type'', ";
531     f27="''Handle_Visible'', ";
532     f28="''Userdata'', ";
533     f29="''Tag'', ";
534     f30="''figure_position'', ";
535     f31="''figure_size'', ";
536     f32="''axes_size'', ";
537     f33="''auto_resize'', ";
538     f34="''viewport'', ";
539     f35="''figure_name'', ";
540     f36="''figure_id'', ";
541     f37="''info_message'', ";
542     f38="''color_map'', ";
543     f40="''pixel_drawing_mode'', ";
544     f41="''anti_aliasing'', ";
545     f42="''immediate_drawing'', ";
546     f43="''background'', ";
547     f44="''rotation_style'', ";
548     f45="''event_handler'', ";
549     f46="''event_handler_enable'', ";
550     f47="''resizefcn'', ";
551     f48="''closerequestfcn'', ";
552     x="";
553
554
555     if a.type=="uicontrol"
556         f="uicontrol";
557         if a.BackgroundColor <> [0.8 0.8 0.8] then
558             if type(a.BackgroundColor)==1 then
559                 f3_strg=String(a.Backgroundcolor);
560                 f3_strg="["+f3_strg(1)+" "+f3_strg(2)+" "+f3_strg(3)+"]";
561                 x=x+f3+f3_strg+", ";
562             else
563                 f3_strg=a.BackgroundColor;
564                 x=x+f3+"''"+f3_strg+"''"+", ";
565             end
566         end
567         if a.Enable <> "on" then x=x+f4+"''"+a.Enable+"''"+", "; end
568         if a.fontAngle <> "normal" then x=x+f5+"''"+a.fontAngle+"''"+", "; end
569         if a.fontName <> "helvetica" then x=x+f6+"''"+a.fontName+"''"+", "; end
570         f7_strg=String(a.fontSize);
571         if a.fontSize <> 10 then x=x+f7+f7_strg+", "; end
572         if a.fontUnits <> "points" then x=x+f8+"''"+a.fontUnits+"''"+", "; end
573         if a.fontWeight <> "normal" then x=x+f9+"''"+a.fontWeight+"''"+", "; end
574         if a.foregroundColor <>[0 0 0] then
575             if type(a.ForegroundColor)==1 then
576                 f10_strg=String(a.foregroundColor);
577                 f10_strg="["+f10_strg(1)+" "+f10_strg(2)+" "+f10_strg(3)+"]";
578                 x=x+f10+f10_strg+" ,";
579             else
580                 f10_strg=a.ForegroundColor;
581                 x=x+f10+"''"+f10_strg+"''"+", ";
582             end
583         end
584         if a.HorizontalAlignment <> "center" then x=x+f11+"''"+a.horizontalAlignment+"''"+", "; end
585         f12_strg=String(a.ListBoxTop);
586         if a.ListBoxTop <>[] then x=x+f12+f12_strg+", "; end
587         f13_strg=String(a.Max);
588         if a.max<> 1 then x=x+f13+f13_strg+", "; end
589         f14_strg=String(a.Min);
590         if a.min<> 0 then x=x+f14+f14_strg+", "; end
591         if a.Position <>[20 40 40 20] then
592             if type(a.Position)==1 then
593                 f15_strg=String(a.Position);
594                 f15_strg="["+f15_strg(1)+" "+f15_strg(2)+" "+f15_strg(3)+" "+f15_strg(4)+"]";
595                 x=x+f15+f15_strg+", ";
596             else
597                 f15_strg=a.Position;
598                 x=x+f15+"''"+f15_strg+"''"+", ";
599             end
600         end
601         x=x+f16+"''"+a.Relief+"''"+", ";
602         f17_strg=String(a.sliderStep); f17_strg="["+f17_strg(1)+" "+f17_strg(2)+"]";
603         if a.sliderStep <> [0.01 0.1] then x=x+f17+f17_strg+", "; end
604         if a.String <>"" then
605             if isempty(a.String)
606                 x = x + f18 + "'''' ,";
607             else
608                 x=x+f18+"''"+a.String+"''"+" ,";
609             end
610         end
611         if a.Style <> "pushbutton" then x=x+f19+"''"+a.Style+"''"+", "; end
612         if a.TooltipString <> "" then x=x+f20+"''"+a.TooltipString+"''"+", "; end
613         if a.Units <> "pixels" then x=x+f21+"''"+a.Units+"''"+", "; end
614         if a.Value<>[] then
615             f22_strg=String(a.value);
616             f22l=length(a.value);
617             for i=1:f22l
618                 f22_strg=strcat(f22_strg, ",");
619                 f22_strg="["+f22_strg+"]";
620             end
621             x=x+f22+", "+f22_strg+", ";
622         end
623         if a.VerticalAlignment <> "middle" then x=x+f23+"''"+a.VerticalAlignment+"''"+", "; end
624         if a.Visible <> "on" then x=x+f24+"''"+a.Visible+"''"+", "; end
625         if a.Callback <>"" then x=x+f25+"''"+a.Callback+"''"+" ,"; end
626         f26_strg=String(a.Callback_Type);
627         if a.Callback_Type <> -1 then x=x+f26+f26_strg+", "; end
628         if a.Handle_Visible <> "on" then x=x+f27+"''"+a.Handle_Visible+"''"+", "; end
629         if a.Userdata <>[] then
630             if type(a.userdata) == 1 then
631                 f28_strg=mat2exp(a.userdata,0)
632             elseif type(a.userdata) == 2 then
633                 f28_strg=pol2exp(a.userdata,0)
634             elseif type(a.userdata) == 4 then
635                 f28_strg=log2exp(a.userdata,0)
636             elseif type(a.userdata) == 5 | type(a.userdata) == 6 | type(a.userdata) == 7 then
637                 f28_strg=sp2exp(a.userdata,0)
638             elseif type(a.userdata) == 8 then
639                 f28_strg=int2exp(a.userdata,0)
640             elseif type(a.userdata) == 9 then
641                 f28_strg=h2exp(a.userdata,0)
642             elseif type(a.userdata) == 10 then
643                 f28_strg=str2exp(a.userdata,0)
644             elseif type(a.userdata) == 13 then
645                 if named then
646                     f28_strg=sci2exp(a.userdata,nom)
647                 else
648                     f28_strg=sci2exp(a.userdata,"%fun")
649                 end
650             elseif type(a.userdata) == 15 then
651                 f28_strg=list2exp(a.userdata);
652             elseif type(a.userdata) == 16 then
653                 f28_strg=tlist2exp(a.userdata,0);
654             elseif type(a.userdata) == 17 then
655                 f28_strg=mlist2exp(a.userdata,0);
656             elseif type(a.userdata) == 129 then
657                 f28_strg=imp2exp(a.userdata,0);
658             end
659             x=x+f28+f28_strg+", ";
660         end
661         if a.Tag<>"" then x=x+f29+"''"+a.Tag+"''"+", "; end
662         lx=length(x);
663         x=part(x,1:lx-2);
664         t(1)=f+"("+x;
665         t(1)=t(1)+")";
666         dots="."+".";
667         lt=length(t(1))
668         if lt>lmax & lmax<>0 then
669             ind=strindex(x,",");
670             k1=1;l=0;I=[];
671             while %t
672                 if lt-l<lmax|k1>length(ind) then break,end
673                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
674                 I=[I ind(k2)];
675                 k1=k2+1
676                 l=ind(k2)
677             end
678             t=strsplit(t(1),I);
679             t(1:$-1)=t(1:$-1)+dots;
680         end
681
682
683     elseif a.type == "Figure" then
684         f="figure";
685         f30_strg=String(a.figure_position);
686         f30_strg="["+f30_strg(1)+" "+f30_strg(2)+"]";
687         if a.figure_position <> [] then x=f30+f30_strg+", "; end
688         f31_strg=String(a.figure_size);
689         f31_strg="["+f31_strg(1)+" "+f31_strg(2)+"]";
690         if a.figure_size <> [] then x=x+f31+f31_strg+", "; end
691         f32_strg=String(a.axes_size);
692         f32_strg="["+f32_strg(1)+" "+f32_strg(2)+"]";
693         if a.axes_size <> [] then x=x+f32+f32_strg+", "; end
694         if a.auto_resize<>"on" then x=x+f33+"''"+a.auto_resize+"''"+", "; end
695         f34_strg=String(a.viewport);
696         f34_strg="["+f34_strg(1)+" "+f34_strg(2)+"]";
697         if a.viewport <>[0 0] then x=x+f34+f34_strg+", "; end
698         if a.figure_name<>"Figure n°%d" then x=x+f35+"''"+a.figure_name+"''"+", ";
699         end
700         f36_strg=String(a.figure_id);
701         x=x+f36+f36_strg+", ";
702         if a.info_message<>"" then x=x+f37+"''"+a.info_message+"''"+", "; end
703         if a.pixel_drawing_mode <> "copy" then x=x+f40+"''"+a.pixel_drawing_mode+"''"+", "; end
704         if a.anti_aliasing <> "off" then x=x+f41+"''"+a.anti_aliasing+"''"+", "; end
705         if a.immediate_drawing <>"on" then x=x+f42+"''"+a.immediate_drawing+"''"+", "; end
706         f43_strg=String(f43);
707         if a.background <> 33 then x=x+f43+f43_strg+", "; end
708         if a.visible <> "on" then x=x+f24+"''"+a.visible+"''"+", "; end
709         if a.rotation_style <> "unary" then x=x+f44+"''"+a.rotation_style+"''"+", "; end
710         if a.event_handler <> "" then x=x+f45+"''"+a.event_handler+"''"+", "; end
711         if a.event_handler_enable <> "off" then x=x+f46+"''"+a.event_handler_enable+"''"+", "; end
712         if a.userdata <> [] then
713             if type(a.userdata) == 1 then
714                 f47_strg=mat2exp(a.userdata,0)
715             elseif type(a.userdata) == 2 then
716                 f47_strg=pol2exp(a.userdata,0)
717             elseif type(a.userdata) == 4 then
718                 f47_strg=log2exp(a.userdata,0)
719             elseif type(a.userdata) == 5 | type(a.userdata) == 6 | type(a.userdata) == 7 then
720                 f47_strg=sp2exp(a.userdata,0)
721             elseif type(a.userdata) == 8 then
722                 f47_strg=int2exp(a.userdata,0)
723             elseif type(a.userdata) == 9 then
724                 f47_strg=h2exp(a.userdata,0)
725             elseif type(a.userdata) == 10 then
726                 f47_strg=str2exp(a.userdata,0)
727             elseif type(a.userdata) == 13 then
728                 if named then
729                     f47_strg=sci2exp(a.userdata,nom)
730                 else
731                     f47_strg=sci2exp(a.userdata,"%fun")
732                 end
733             elseif type(a.userdata) == 15 then
734                 f47_strg=list2exp(a.userdata);
735             elseif type(a.userdata) == 16 then
736                 f47_strg=tlist2exp(a.userdata,0)
737             elseif type(a.userdata) == 17 then
738                 f47_strg=mlist2exp(a.userdata,0)
739             elseif type(a.userdata) == 129 then
740                 f47_strg=imp2exp(a.userdata,0)
741             end
742             x=x+f28+f47_strg+", ";
743         end
744         if a.resizefcn <> "" then x=x+f47+"''"+a.resizefcn+"''"+", "; end
745         if a.closerequestfcn <> "" then x=x+f48+"''"+a.closerequestfcn+"''"+", "; end
746         if a.tag <> "" then x=x+f27+"''"+a.tag+"''"+", "; end
747         lx=length(x);
748         x=part(x,1:lx-2);
749         t(1)=f+"("+x;
750         t(1)=t(1)+")";
751         dots="."+".";
752         lt=length(t(1))
753         if lt>lmax & lmax<>0 then
754             ind=strindex(x,",");
755             k1=1;l=0;I=[];
756             while %t
757                 if lt-l<lmax|k1>length(ind) then break,end
758                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
759                 I=[I ind(k2)];
760                 k1=k2+1
761                 l=ind(k2)
762             end
763             t=strsplit(t(1),I);
764             t(1:$-1)=t(1:$-1)+dots;
765         end
766     else
767         error(msprintf(gettext("%s: This feature has not been implemented: Variable translation of type %s.\n"),"sci2exp",string(a.type)));
768     end
769
770 endfunction
771
772 function ml = user2mlist(u)
773
774     fn = getfield(1, u);
775     ml = mlist(fn);
776
777     for k=1:size(fn,"*")
778         ml(k) = eval("u."+fn(k));
779     end
780
781 endfunction