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