summaryrefslogtreecommitdiff
path: root/modules/m2sci/macros/percent/%rc2sci.sci
blob: 451ab030fce49aac58f5e81d546885dc77b98ed8 (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
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ???? - INRIA - Scilab
//
// 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 [tree]=%rc2sci(tree)

    // Make a 'row' with many columns

    if tree.operands(1).vtype==Cell then
        tree=%rc_cell2sci(tree)
        return
    end

    colnb=size(tree.operands)
    row=list()
    rowsize=[]
    colsize=[]
    typ=Double

    realcols=0
    complexcols=0

    for k=1:colnb
        rk=tree.operands(k)
        row(k)=rk
        if rk.vtype==String then
            typ=String
        end
        rowsize=[rowsize tree.operands(k).dims(1)]
        colsize=[colsize tree.operands(k).dims(2)]
        if rk.property==Complex then
            complexcols=complexcols+1
        end
        if rk.property==Real then
            realcols=realcols+1
        end
    end

    if realcols==colnb then
        prop=Real
    elseif complexcols<>0 then
        prop=Complex
    else
        prop=Unknown
    end

    undef=find(rowsize==-1)
    void=find(rowsize==0)
    rowsize([undef void])=[]
    if rowsize==[] then
        if undef<>[] then
            sr=-1
        else
            sr=0
        end
    else
        [w,k]=min(length(rowsize))
        sr=rowsize(k)
    end

    if typ<>String then
        if find(colsize==-1)==[] then
            w=colsize(1)
            for k=2:colnb
                w=w+colsize(k)
            end
            sc=w
        else
            sc=-1
        end

        tree.out(1).dims=list(sr,sc)
        tree.out(1).type=Type(rk.vtype,prop)
    else
        if find(colsize==-1)==[] then
            w=colsize(1)
            for k=2:colnb
                w=w+colsize(k)
            end
            sc=w
        else
            sc=-1
        end

        tree.out(1).dims=list(sr,sc)
        tree.out(1).type=Type(String,Real)
        tree=Operation("+",tree.operands,tree.out)
    end
    tree.out(1).contents=Contents()
endfunction