1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises
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.
12function y=%cblock_e(varargin)
13    x=varargin($)
14    dims=[];
15    for k=2:length(x)
16        dims=[dims;size(getfield(k,x))];
17    end
18    m=dims(1,1) // common row number
19
20    dims=cumsum([1 dims(:,2)']);
21    n=dims($)-1 // number of columns
22    y=mlist("cblock")
23
24    j=varargin($-1)
25    if type(j)==2|type(j)==129 then
26        j=horner(j,n)
27    elseif type(j)==4 then
28        j=find(j)
29    elseif and(size(j)==[-1,-1]) then
30        j=1:n
31    end
32    if length(varargin)==2 then //y=x(i)
33        if m<>1 then
34            error(msprintf(_("%s: Syntax x(j) only allowed for row cblock''s.\n"),"cblock_e"));
35        end
36        i=1
37    else //y=x(i,j)
38        i=varargin(1)
39    end
40
41    first=%t
42
43    for k=1:size(j,"*")
44        jk=j(k)
45        I=find(jk>=dims(1:$-1)&jk<dims(2:$))
46        if I>1 then jk=jk-dims(I)+1,end
47        v=getfield(I+1,x)
48        if first then
49            temp=v(i,jk)
50            first=%f
51        else
52            if type(v)==type(temp) then
53                temp=[temp v(i,jk)]
54            else
55                y=setfield(length(y)+1,temp,y)
56                temp=v(i,jk)
57            end
58        end
59    end
60    if length(y)==1 then
61        y=temp
62    else
63        y=setfield(length(y)+1,temp,y)
64    end
65
66endfunction
67