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