summaryrefslogtreecommitdiff
path: root/modules/string/macros/sci2exp.sci
blob: 37378018eeed378b75b2a32c69bb9a5c25de76dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA -
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt


function t=sci2exp(a,nom,lmax)
    // sci2exp - convert a variable to an expression
    //%SYNTAX
    // t=sci2exp(a [,nam] [,lmax])
    //%PARAMETERS
    //   a  : matrix of scalar or polynomials
    //   nam: character string
    //   t  : vector of string, contains the expression definition
    //   lmax : maximum line lengh (0 for no line length control)
    //%Example
    //  a=[1 2;3 4]
    //  sci2exp(a,'aa')
    //!

    deff("x=String(a)",["x=string(a)"
    "x=strsubst(x,''Nan'',''%nan'')"
    "x=strsubst(x,''Inf'',''%inf'')"
    ])


    [lhs,rhs]=argn(0)
    $ // import global variable $ in sci2exp context for efficiency
    select rhs
    case 1 then
        named=%f
        lmax=0
    case 2 then
        if type(nom)==1 then
            lmax=nom
            named=%f
        else
            named=%t
            lmax=0
        end
    case 3 then
        named=%t
        if type(nom)==1 then
            [lmax,nom]=(nom,lmax)
        end
    end
    dots="..";
    select type(a)
    case 1 then
        t=mat2exp(a,lmax)
    case 2 then
        t=pol2exp(a,lmax)
    case 4 then
        t=log2exp(a,lmax)
    case 5 then
        t=sp2exp(a,lmax)
    case 6 then
        t=sp2exp(a,lmax)
    case 7 then
        t=sp2exp(a,lmax)
    case 8 then
        t=int2exp(a,lmax)
    case 9 then
        t=h2exp(a, lmax)
    case 10 then
        t=str2exp(a,lmax)
    case 13 then
        if named then
            t=fun2string(a,nom)
        else
            t=fun2string(a,"%fun")
        end
        t(1)=part(t(1),10:length(t(1)))
        t($)=[]
        t=sci2exp(t,lmax)
        t(1)="createfun("+t(1)
        t($)=t($)+")"
    case 15 then
        t=list2exp(a,lmax)
    case 16 then
        t=tlist2exp(a,lmax)
    case 17 then
        t=mlist2exp(a,lmax)
    case 11 then
        t=func2exp(a,lmax)
        named=%f
    case 129 then
        t=imp2exp(a,lmax)
    else
        //  execstr('t='+typeof(a)+'2exp(a,lmax)')
        error(msprintf(gettext("%s: This feature has not been implemented: Variable translation of type %s.\n"),"sci2exp",string(type(a))));
    end,
    if named&and(type(a)<>[11 13]) then
        t(1)=nom+" = "+t(1)
    end
endfunction

function t=str2exp(a,lmax)
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)

    [m,n]=size(a),
    dots="."+"."
    t=[];
    quote="''"

    a=strsubst(a,quote,quote+quote)
    dquote=""""
    a=strsubst(a,dquote,dquote+dquote)
    a = strsubst(a, ascii(10), """+ascii(10)+""")
    a=quote(ones(a))+a+quote(ones(a))

    for i=1:m
        x=emptystr();
        for j=1:n,
            y=a(i,j);
            y=dquote+part(y,2:length(y))
            y=part(y,1:length(y)-1)+dquote
            if y=="''''" then y="emptystr()",end
            if lmax==0|length(x($))+length(y)<lmax then
                if j==1 then
                    x=y
                else
                    x($)=x($)+","+y,
                end
            else
                if j>1 then
                    x($)=x($)+","+dots;
                    x($+1)=y
                else
                    x=y
                end
            end
        end
        if i<m then x($)=x($)+";",end
        if lmax>0 then
            t=[t;x]
        else
            t=t+x
        end
    end,
    if lmax>0&sum(length(t))<lmax then
        t=strcat(t)
    end
    if m*n>1 then
        t(1)="["+t(1)
        t($)=t($)+"]"
    end
endfunction

function t=mat2exp(a,lmax)
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    if size(a,"*")==0 then t="[]",return,end
    [m,n]=size(a);
    if m<0 then
        t=mat2exp(a+0);
        if t=="1" then
            t="eye()";
        else
            t="("+t+")*eye()";
        end
        return
    end
    a=String(a);
    dots="."+"."
    t=[];
    if n==1 then
        x=strcat(a,";")
        lx=length(x)
        if lmax==0|lx<lmax then
            t=x;
        else
            ind=strindex(x,";");
            k1=1;l=0;I=[];
            while %t
                if lx-l<lmax|k1>length(ind) then,break,end
                k2=k1-1+max(find(ind(k1:$)<l+lmax))
                I=[I ind(k2)];
                //	t=[t;part(x,l+1:ind(k2))]
                k1=k2+1
                l=ind(k2)
            end
            t=[t;strsplit(x,I)];
        end
    elseif m==1 then
        x=strcat(a,",")
        lx=length(x)
        if lmax==0|lx<lmax then
            t=x;

        else
            ind=strindex(x,",");
            k1=1;l=0;I=[];
            while %t
                if lx-l<lmax|k1>length(ind) then break,end
                k2=k1-1+max(find(ind(k1:$)<l+lmax))
                I=[I ind(k2)];
                //	t=[t;part(x,l+1:ind(k2))+dots]
                k1=k2+1
                l=ind(k2)
            end
            x=strsplit(x,I);x(1:$-1)=x(1:$-1)+dots;
            t=[t;x]
        end
    else
        for i=1:m
            x=strcat(a(i,:),",")
            if i<m then x=x+";",end
            lx=length(x)
            if lmax==0 then
                t=t+x
            elseif lx<lmax then
                t=[t;x]
            else
                ind=strindex(x,",");
                k1=1;l=0;I=[];
                while %t
                    if lx-l<lmax|k1>length(ind) then break,end
                    k2=k1-1+max(find(ind(k1:$)<l+lmax))
                    I=[I ind(k2)];
                    //	  t=[t;part(x,l+1:ind(k2))+dots]
                    k1=k2+1
                    l=ind(k2)
                end
                x=strsplit(x,I);x(1:$-1)=x(1:$-1)+dots;x(2:$)=" "+x(2:$);
                t=[t;x]
            end
        end
    end
    if m*n>1 then
        t(1)="["+t(1)
        t($)=t($)+"]"
    end
endfunction

function t=pol2exp(a,lmax)
    $
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)

    [m,n]=size(a),var=" ";lvar=1
    var=varn(a),lvar=length(var);
    while part(var,lvar)==" " then lvar=lvar-1,end
    var=part(var,1:lvar);
    if m<0 then
        t=pol2exp(a+0)
        t="("+t+")*eye()"
        return
    end
    t=[];
    for i=1:m
        x=emptystr(1)
        for j=1:n,
            v=a(i,j);d=degree(v);
            v=coeff(v);
            k0=1;while (k0<d+1)&(v(k0))==0 then k0=k0+1,end
            y=emptystr(1)
            nul=%t
            for k=k0:(d+1),
                s=String(v(k))
                if s<>"0" then
                    nul=%f
                    if part(s,1)==" " then s=part(s,2:length(s)),end
                    mnm=emptystr(1)
                    if k>0 then
                        mnm=var
                        if k>2 then
                            mnm=mnm+"^"+string(k-1),
                        end
                    end
                    if k>1 then
                        if string(imag(v(k)))<>"0" then s="("+s+")",end
                        if s=="1" then
                            s=mnm
                        elseif s=="-1" then
                            s="-"+mnm
                        else
                            s=s+"*"+mnm
                        end
                        if k>k0&part(s,1)<>"-" then s="+"+s,end
                    end
                    if lmax==0|length(y($))+length(s) <lmax then
                        y($)=y($)+s
                    else
                        y($)=y($)+dots
                        y($+1)=s
                    end
                end
            end
            if nul then y="0*"+var,end
            [ny,my]=size(y)

            if lmax==0|length(x($))+length(y(1))<lmax then
                if j==1 then
                    x=y(1)
                else
                    x($)=x($)+","+y(1),
                end
                if ny>1 then x($+1:$+ny-1)=y(2:ny),end
            else
                if length(x($))==0 then
                    x($:$+ny-1) = y;
                else
                    x($)=x($)+","+dots;
                    x($+1:$+ny)=y
                end
            end
        end
        if i<m then x($)=x($)+";",end
        if lmax>0 then
            t=[t;x]
        else
            t=t+x
        end
    end,
    if lmax>0&sum(length(t))<lmax then
        t=strcat(t)
    end
    if m*n>1 then
        t(1)="["+t(1)
        t($)=t($)+"]"
    end
endfunction

function t=list2exp(l,lmax)
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    dots="."+".";
    t="list("
    n=length(l)
    for k=1:n
        lk=l(k)
        sep=",",if k==1 then sep=emptystr(),end
        if type(lk)==9 then
            t1=h2exp(lk,lmax)
        elseif type(lk)==15 then
            t1=list2exp(lk,lmax)
        elseif type(lk)==16 then
            t1=tlist2exp(lk,lmax)
        elseif type(lk)==17 then
            t1=mlist2exp(lk,lmax)
        else
            t1=sci2exp(lk,lmax)
        end
        if size(t1,"*")==1&(lmax==0|max(length(t1))+length(t($))<lmax) then
            t($)=t($)+sep+t1
        else
            t($)=t($)+sep+dots
            t=[t;t1]
        end
        lk=null()
    end
    t($)=t($)+")"
endfunction

function t=tlist2exp(l,lmax)
    $;
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    dots="."+".";
    t="tlist("
    n=length(l)
    for k=1:n
        lk=l(k)
        sep=",",if k==1 then sep=emptystr(),end
        if type(lk)==15 then
            t1=list2exp(lk,lmax)
        elseif type(lk)==16 then
            t1=tlist2exp(lk,lmax)
        elseif type(lk)==17 then
            t1=mlist2exp(lk,lmax)
        elseif type(lk)==9 then
            t1=h2exp(lk,lmax,1)
        else
            t1=sci2exp(lk,lmax)
        end
        if size(t1,"*")==1&(lmax==0|max(length(t1))+length(t($))<lmax) then
            t($)=t($)+sep+t1
        else
            t($)=t($)+sep+dots
            t=[t;t1]
        end
    end
    t($)=t($)+")"

endfunction

function t=mlist2exp(l,lmax)
    $;
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    dots="."+".";
    t="mlist("
    n=size(definedfields(l),"*")
    for k=1:n
        lk=getfield(k,l)
        sep=",",if k==1 then sep=emptystr(),end
        if type(lk)==15 then
            t1=list2exp(lk,lmax)
        elseif type(lk)==16 then
            t1=tlist2exp(lk,lmax)
        elseif type(lk)==17 then
            t1=mlist2exp(lk,lmax)
        elseif type(lk)==9 then
            t1=h2exp(lk,lmax)
        else
            t1=sci2exp(lk,lmax)
        end
        if size(t1,"*")==1&(lmax==0|max(length(t1))+length(t($))<lmax) then
            t($)=t($)+sep+t1
        else
            t($)=t($)+sep+dots
            t=[t;t1]
        end
    end
    t($)=t($)+")"

endfunction

function t=log2exp(a,lmax)
    $;
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    [m,n]=size(a),
    a1=matrix(a,m*n,1)
    F="%f"
    T="%t"
    a=F(ones(m*n,1))
    k=find(a1);
    if k<>[] then
        a(k)=T(ones(size(k,"*"),1));
    end
    a=matrix(a,m,n);
    dots="."+"."
    t=[];
    for i=1:m
        x=emptystr()
        for j=1:n,
            y=a(i,j);
            if lmax==0|length(x($))+length(y)<lmax then
                if j==1 then
                    x=y
                else
                    x($)=x($)+","+y,
                end
            else
                x($)=x($)+","+dots;
                x($+1)=y
            end
        end
        t=[t;x]
    end,
    if lmax==0|lmax>0&sum(length(t))<lmax then
        t=strcat(t,";")
    end
    if m*n>1 then
        t(1)="["+t(1)
        t($)=t($)+"]"
    end

endfunction

function t=func2exp(a,lmax)
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    [out,in,text]=string(a)
    if out==[] then out=emptystr(),end
    text=str2exp(text,lmax)
    nt=size(text,"*")
    if named then mac=nom,else mac="mac",end
    if nt==1 then
        t="deff(''["+strcat(out,",")+"]="+mac+"("+strcat(in,",")+")'',"+text+")"
    else
        text($)=text($)+")"
        semi=";"
        text(1:$-1)=text(1:$-1)+semi(ones(nt-1,1))'
        t=["deff(''["+strcat(out,",")+"]="+mac+"("+strcat(in,",")+")'',"+text(1)
        text(2:$)]
    end
endfunction

function t=imp2exp(a,lmax)
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    v=[a(1),a(2),a(3)]
    if a(2)==1 then
        t=sci2exp(a(1))+":"+sci2exp(a(3))
    else
        t=sci2exp(a(1))+":"+sci2exp(a(2))+":"+sci2exp(a(3))
    end
endfunction

function t=sp2exp(a,lmax)
    if rhs<2 then lmax=0,end
    [lhs,rhs]=argn(0)
    dots="..";
    [ij,v,mn]=spget(a)
    t=sci2exp(ij,lmax)
    v=sci2exp(v,lmax)
    mn=sci2exp(mn,lmax)

    t(1)="sparse("+t(1)
    if lmax==0|length(t($))+length(v(1))+1<lmax then
        t($)=t($)+","+v(1)
        t=[t;v(2:$)]
    else
        t($)=t($)+","+dots
        t=[t;v]
    end
    if lmax==0|length(t($))+length(mn(1))+1<lmax then
        t($)=t($)+","+mn(1)
        t=[t;mn(2:$)]
    else
        t($)=t($)+","+dots
        t=[t;mn]
    end
    t($)=t($)+")"
endfunction


function t=int2exp(a,lmax)
    it=inttype(a)
    if it>10 then f="uint",else f="int",end
    f=f+string(8*modulo(it,10))
    t=mat2exp(double(a),lmax)
    t(1)=f+"("+t(1)
    t($)=t($)+")"
endfunction


function t=h2exp(a,lmax) //Only for figure and uicontrol
    $;
    if rhs<2 then lmax=0
    end
    [lhs,rhs]=argn(0);


    f1="''parent'', ";
    f2="''children'', ";
    f3="''BackgroundColor'', ";
    f4="''Enable'', ";
    f5="''fontAngle'', ";
    f6="''fontName'', ";
    f7="''fontSize'', ";
    f8="''fontUnits'', ";
    f9="''fontWeight'', ";
    f10="''ForegroundColor'', ";
    f11="''HorizontalAlignment'', ";
    f12="''ListboxTop'', ";
    f13="''Max'', ";
    f14="''Min'', ";
    f15="''Position'', ";
    f16="''Relief'', ";
    f17="''SliderStep'', ";
    f18="''String'', ";
    f19="''Style'', ";
    f20="''TooltipString'', ";
    f21="''Units'', ";
    f22="''Value'', ";
    f23="''VerticalAlignment'', ";
    f24="''Visible'', ";
    f25="''Callback'', ";
    f26="''Callback_Type'', ";
    f27="''Handle_Visible'', ";
    f28="''Userdata'', ";
    f29="''Tag'', ";
    f30="''figure_position'', ";
    f31="''figure_size'', ";
    f32="''axes_size'', ";
    f33="''auto_resize'', ";
    f34="''viewport'', ";
    f35="''figure_name'', ";
    f36="''figure_id'', ";
    f37="''info_message'', ";
    f38="''color_map'', ";
    f40="''pixel_drawing_mode'', ";
    f41="''anti_aliasing'', ";
    f42="''immediate_drawing'', ";
    f43="''background'', ";
    f44="''rotation_style'', ";
    f45="''event_handler'', ";
    f46="''event_handler_enable'', ";
    f47="''resizefcn'', ";
    f48="''closerequestfcn'', ";
    x=[];


    if a.type=="uicontrol"
        f="uicontrol";
        if a.BackgroundColor <> [0.8 0.8 0.8] then
            if type(a.BackgroundColor)==1 then
                f3_strg=String(a.Backgroundcolor);
                f3_strg="["+f3_strg(1)+" "+f3_strg(2)+" "+f3_strg(3)+"]";
                x=x+f3+f3_strg+", ";
            else
                f3_strg=a.BackgroundColor;
                x=x+f3+"''"+f3_strg+"''"+", ";
            end
        end
        if a.Enable <> "on" then x=x+f4+"''"+a.Enable+"''"+", "; end
        if a.fontAngle <> "normal" then x=x+f5+"''"+a.fontAngle+"''"+", "; end
        if a.fontName <> "helvetica" then x=x+f6+"''"+a.fontName+"''"+", "; end
        f7_strg=String(a.fontSize);
        if a.fontSize <> 10 then x=x+f7+f7_strg+", "; end
        if a.fontUnits <> "points" then x=x+f8+"''"+a.fontUnits+"''"+", "; end
        if a.fontWeight <> "normal" then x=x+f9+"''"+a.fontWeight+"''"+", "; end
        if a.foregroundColor <>[0 0 0] then
            if type(a.ForegroundColor)==1 then
                f10_strg=String(a.foregroundColor);
                f10_strg="["+f10_strg(1)+" "+f10_strg(2)+" "+f10_strg(3)+"]";
                x=x+f10+f10_strg+" ,";
            else
                f10_strg=a.ForegroundColor;
                x=x+f10+"''"+f10_strg+"''"+", ";
            end
        end
        if a.HorizontalAlignment <> "center" then x=x+f11+"''"+a.horizontalAlignment+"''"+", "; end
        f12_strg=String(a.ListBoxTop);
        if a.ListBoxTop <>[] then x=x+f12+f12_strg+", "; end
        f13_strg=String(a.Max);
        if a.max<> 1 then x=x+f13+f13_strg+", "; end
        f14_strg=String(a.Min);
        if a.min<> 0 then x=x+f14+f14_strg+", "; end
        if a.Position <>[20 40 40 20] then
            if type(a.Position)==1 then
                f15_strg=String(a.Position);
                f15_strg="["+f15_strg(1)+" "+f15_strg(2)+" "+f15_strg(3)+" "+f15_strg(4)+"]";
                x=x+f15+f15_strg+", ";
            else
                f15_strg=a.Position;
                x=x+f15+"''"+f15_strg+"''"+", ";
            end
        end
        x=x+f16+"''"+a.Relief+"''"+", ";
        f17_strg=String(a.sliderStep); f17_strg="["+f17_strg(1)+" "+f17_strg(2)+"]";
        if a.sliderStep <> [0.01 0.1] then x=x+f17+f17_strg+", "; end
        if a.String <>"" then x=x+f18+"''"+a.String+"''"+" ,"; end
        if a.Style <> "pushbutton" then x=x+f19+"''"+a.Style+"''"+", "; end
        if a.TooltipString <> "" then x=x+f20+"''"+a.TooltipString+"''"+", "; end
        if a.Units <> "pixels" then x=x+f21+"''"+a.Units+"''"+", "; end
        if a.Value<>[] then
            f22_strg=String(a.value);
            f22l=length(a.value);
            for i=1:f22l
                f22_strg=strcat(f22_strg, ",");
                f22_strg="["+f22_strg+"]";
            end
            x=x+f22+", "+f22_strg+", ";
        end
        if a.VerticalAlignment <> "middle" then x=x+f23+"''"+a.VerticalAlignment+"''"+", "; end
        if a.Visible <> "on" then x=x+f24+"''"+a.Visible+"''"+", "; end
        if a.Callback <>"" then x=x+f25+"''"+a.Callback+"''"+" ,"; end
        f26_strg=String(a.Callback_Type);
        if a.Callback_Type <> -1 then x=x+f26+f26_strg+", "; end
        if a.Handle_Visible <> "on" then x=x+f27+"''"+a.Handle_Visible+"''"+", "; end
        if a.Userdata <>[] then
            if type(a.userdata) == 1 then
                f28_strg=mat2exp(a.userdata,0)
            elseif type(a.userdata) == 2 then
                f28_strg=pol2exp(a.userdata,0)
            elseif type(a.userdata) == 4 then
                f28_strg=log2exp(a.userdata,0)
            elseif type(a.userdata) == 5 | type(a.userdata) == 6 | type(a.userdata) == 7 then
                f28_strg=sp2exp(a.userdata,0)
            elseif type(a.userdata) == 8 then
                f28_strg=int2exp(a.userdata,0)
            elseif type(a.userdata) == 9 then
                f28_strg=h2exp(a.userdata,0)
            elseif type(a.userdata) == 10 then
                f28_strg=str2exp(a.userdata,0)
            elseif type(a.userdata) == 11 then
                f28_strg=func2exp(a.userdata,0)
                named=%f
            elseif type(a.userdata) == 13 then
                if named then
                    t=fun2string(a,nom)
                else
                    t=fun2string(a,"%fun")
                end
                t(1)=part(t(1),10:length(t(1)))
                t($)=[]
                t=sci2exp(t,lmax)
                t(1)="createfun("+t(1)
                t($)=t($)+")"
            elseif type(a.userdata) == 15 then
                f28_strg=list2exp(a.userdata);
            elseif type(a.userdata) == 16 then
                f28_strg=tlist2exp(a.userdata,0);
            elseif type(a.userdata) == 17 then
                f28_strg=mlist2exp(a.userdata,0);
            elseif type(a.userdata) == 129 then
                f28_strg=imp2exp(a.userdata,0);
            end
            x=x+f28+f28_strg+", ";
        end
        if a.Tag<>"" then x=x+f29+"''"+a.Tag+"''"+", "; end
        lx=length(x);
        x=part(x,1:lx-2);
        t(1)=f+"("+x;
        t(1)=t(1)+")";
        dots="."+".";
        lt=length(t(1))
        if lt>lmax & lmax<>0 then
            ind=strindex(x,",");
            k1=1;l=0;I=[];
            while %t
                if lt-l<lmax|k1>length(ind) then break,end
                k2=k1-1+max(find(ind(k1:$)<l+lmax))
                I=[I ind(k2)];
                k1=k2+1
                l=ind(k2)
            end
            t=strsplit(t(1),I);
            t(1:$-1)=t(1:$-1)+dots;
        end


    elseif a.type == "Figure" then
        f="figure";
        f30_strg=String(a.figure_position);
        f30_strg="["+f30_strg(1)+" "+f30_strg(2)+"]";
        if a.figure_position <> [] then x=f30+f30_strg+", "; end
        f31_strg=String(a.figure_size);
        f31_strg="["+f31_strg(1)+" "+f31_strg(2)+"]";
        if a.figure_size <> [] then x=x+f31+f31_strg+", "; end
        f32_strg=String(a.axes_size);
        f32_strg="["+f32_strg(1)+" "+f32_strg(2)+"]";
        if a.axes_size <> [] then x=x+f32+f32_strg+", "; end
        if a.auto_resize<>"on" then x=x+f33+"''"+a.auto_resize+"''"+", "; end
        f34_strg=String(a.viewport);
        f34_strg="["+f34_strg(1)+" "+f34_strg(2)+"]";
        if a.viewport <>[0 0] then x=x+f34+f34_strg+", "; end
        if a.figure_name<>"Figure n°%d" then x=x+f35+"''"+a.figure_name+"''"+", ";
        end
        f36_strg=String(a.figure_id);
        x=x+f36+f36_strg+", ";
        if a.info_message<>"" then x=x+f37+"''"+a.info_message+"''"+", "; end
        if a.pixel_drawing_mode <> "copy" then x=x+f40+"''"+a.pixel_drawing_mode+"''"+", "; end
        if a.anti_aliasing <> "off" then x=x+f41+"''"+a.anti_aliasing+"''"+", "; end
        if a.immediate_drawing <>"on" then x=x+f42+"''"+a.immediate_drawing+"''"+", "; end
        f43_strg=String(f43);
        if a.background <> 33 then x=x+f43+f43_strg+", "; end
        if a.visible <> "on" then x=x+f24+"''"+a.visible+"''"+", "; end
        if a.rotation_style <> "unary" then x=x+f44+"''"+a.rotation_style+"''"+", "; end
        if a.event_handler <> "" then x=x+f45+"''"+a.event_handler+"''"+", "; end
        if a.event_handler_enable <> "off" then x=x+f46+"''"+a.event_handler_enable+"''"+", "; end
        if a.userdata <> [] then
            if type(a.userdata) == 1 then
                f47_strg=mat2exp(a.userdata,0)
            elseif type(a.userdata) == 2 then
                f47_strg=pol2exp(a.userdata,0)
            elseif type(a.userdata) == 4 then
                f47_strg=log2exp(a.userdata,0)
            elseif type(a.userdata) == 5 | type(a.userdata) == 6 | type(a.userdata) == 7 then
                f47_strg=sp2exp(a.userdata,0)
            elseif type(a.userdata) == 8 then
                f47_strg=int2exp(a.userdata,0)
            elseif type(a.userdata) == 9 then
                f47_strg=h2exp(a.userdata,0)
            elseif type(a.userdata) == 10 then
                f47_strg=str2exp(a.userdata,0)
            elseif type(a.userdata) == 11 then
                f47_strg=func2exp(a.userdata,0)
                named=%f
            elseif type(a.userdata) == 13 then
                if named then
                    t=fun2string(a,nom)
                else
                    t=fun2string(a,"%fun")
                end
                t(1)=part(t(1),10:length(t(1)))
                t($)=[]
                t=sci2exp(t,lmax)
                t(1)="createfun("+t(1)
                t($)=t($)+")"
            elseif type(a.userdata) == 15 then
                f47_strg=list2exp(a.userdata);
            elseif type(a.userdata) == 16 then
                f47_strg=tlist2exp(a.userdata,0)
            elseif type(a.userdata) == 17 then
                f47_strg=mlist2exp(a.userdata,0)
            elseif type(a.userdata) == 129 then
                f47_strg=imp2exp(a.userdata,0)
            end
            x=x+f28+f47_strg+", ";
        end
        if a.resizefcn <> "" then x=x+f47+"''"+a.resizefcn+"''"+", "; end
        if a.closerequestfcn <> "" then x=x+f48+"''"+a.closerequestfcn+"''"+", "; end
        if a.tag <> "" then x=x+f27+"''"+a.tag+"''"+", "; end
        lx=length(x);
        x=part(x,1:lx-2);
        t(1)=f+"("+x;
        t(1)=t(1)+")";
        dots="."+".";
        lt=length(t(1))
        if lt>lmax & lmax<>0 then
            ind=strindex(x,",");
            k1=1;l=0;I=[];
            while %t
                if lt-l<lmax|k1>length(ind) then break,end
                k2=k1-1+max(find(ind(k1:$)<l+lmax))
                I=[I ind(k2)];
                k1=k2+1
                l=ind(k2)
            end
            t=strsplit(t(1),I);
            t(1:$-1)=t(1:$-1)+dots;
        end
    else
        error(msprintf(gettext("%s: This feature has not been implemented: Variable translation of type %s.\n"),"sci2exp",string(a.type)));
    end

endfunction