File: sci_struct.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (74 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download | duplicates (2)
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
function [tree]=sci_struct(tree)
// Copyright INRIA
// M2SCI function
// Conversion function for Matlab struct()
// Input: tree = Matlab funcall tree
// Ouput: tree = Scilab equivalent for tree
// V.C.

tree.lhs(1).type=Type(Struct,Unknown)

// Dims...
dims=tree.rhs(2).dims
for k=4:2:rhs
  for l=1:lstsize(dims)
    if tree.rhs(k).dims(l)==Unknown then
      dims(l)=Unknown
    else
      if dims(l)<>Unknown then
	if dims(l)<tree.rhs(k).dims(l) then
	  dims(l)=tree.rhs(k).dims(l)
	end
      end
    end
      
  end
end

tree.lhs(1).dims=dims

// Update contents
dims=[0 0]
allnotcells=%T
for k=1:2:rhs
  allnotcells=allnotcells & tree.rhs(k+1).vtype<>Cell
end
if allnotcells then
  dims=[1 1]
  tree.lhs(1).dims=list(1,1)
else
  for k=1:2:rhs
    if tree.rhs(k+1).vtype==Cell then
      if double(tree.rhs(k+1).dims(1))>dims(1) then
	dims(1)=double(tree.rhs(k+1).dims(1))
      end
      if double(tree.rhs(k+1).dims(2))>dims(2) then
	dims(2)=double(tree.rhs(k+1).dims(2))
      end
    end
  end
end

for k=1:2:rhs
  dim1=dims(1)
  dim2=dims(2)
  for kd1=1:dims(1)
    for kd2=1:dims(2)
      if tree.rhs(k+1).vtype==Cell then
	
	if tree.rhs(k+1).dims(1)*tree.rhs(k+1).dims(2)<>1 then
	  tree.lhs(1).contents.index($+1)=list(list(Cste(kd1),Cste(kd2)),tree.rhs(k))
	  tree.lhs(1).contents.data($+1)=get_contents_infer(tree.rhs(k+1),list(list(Cste(kd1),Cste(kd2)),Cste("entries")))
	else
	  tree.lhs(1).contents.index($+1)=list(list(Cste(kd1),Cste(kd2)),tree.rhs(k))
	  tree.lhs(1).contents.data($+1)=get_contents_infer(tree.rhs(k+1),list(list(Cste(1),Cste(1)),Cste("entries")))
	end
      
      else
	tree.lhs(1).contents.index($+1)=list(list(Cste(1),Cste(1)),tree.rhs(k))
	tree.lhs(1).contents.data($+1)=tree.rhs(k+1).infer
      end
    end
  end
end
endfunction