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