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