1
function M=createstruct(index,N)
2
// Authors: S. Steer, F. Delebecque, V. Couvert
4
// Create a struct with field pointed by index equal to N
6
// If index is not a list, creation is done by routines
7
if type(index)==15 then
9
// When only two indexes
10
if size(index)==2 then
12
// Second index is a fieldname
13
if type(index(2))==10 then
15
// First index is a numerical value
16
if type(index(1))==1 then
17
// X(p).f = y -> index=list(p,f)
23
M=mlist(["st","dims",index(2)],int32(Dims));
32
// First index is a list of numerical values
33
elseif type(index(1))==15
34
// X(p,q[,...]).f=z -> index=list(list(p,q[,...]),f)
36
for kDims=1:lstsize(index(1))
37
Dims=[Dims,int32(index(1)(kDims))];
40
for kl=1:prod(double(Dims))
44
M=mlist(["st","dims",index(2)],Dims,Li);
46
// First index is also a fieldname
48
// X.f.g=y -> index=list(f,g)
49
M=mlist(["st","dims",index(1)],int32([1,1]),...
50
mlist(["st","dims",index(2)],int32([1,1]),N));
54
// Second index is a fieldname
56
// X.f(p[,q,...])=y : index=list(f,list(p[,q,...]))
58
if typeof(N)=="st" then // When recursive call of createstruct
59
if type(index(2))==15 then // index=list(f,list(p,q[,...]))
60
Dims=list2vec(index(2))'
61
else // index=list(f,p)
74
z=mlist(getfield(1,N),int32(Dims),z);
78
M=mlist(["st","dims",index(1)],int32([1,1]),z);
82
// Any number of indexes <> 2
85
// Last index is a fieldname -> init struct
86
if type(index($))==10 then
87
M=mlist(["st","dims",index($)],int32([1,1]),N);
89
// Last index is a numerical value or a list of numerical values
90
elseif type(index($))==1 | type(index($))==15 then
92
// If only one index value (happens when recursive calls to createstruct)
93
if size(index)==1 then
94
if typeof(N)=="st" then
95
if type(index($))==15 then
96
Dims=list2vec(index($))'
109
z(kmax)=getfield(3,N)
110
M=mlist(getfield(1,N),int32(Dims),z);
115
// More than one index value
117
if typeof(N)=="st" then
118
if type(index($))==15 then
119
Dims=list2vec(index($))'
132
z(kmax)=getfield(3,N)
133
z=mlist(getfield(1,N),int32(Dims),z);
137
M=mlist(["st","dims",index($-1)],int32([1,1]),z);
142
// This case should not happen (unknown kind of index)
143
error("Not implemented");
145
if index==list() then
148
M=createstruct(index,M);
152
if type(index)==10 then
153
M=mlist(["st","dims",index($)],int32([1,1]),N);
155
error("Not implemented");