~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/percent/%cblock_e.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function y=%cblock_e(varargin)
 
2
  x=varargin($)
 
3
  dims=[];
 
4
  for k=2:length(x)
 
5
    dims=[dims;size(getfield(k,x))];
 
6
  end
 
7
  m=dims(1,1) // common row number
 
8
  
 
9
  dims=cumsum([1 dims(:,2)']);
 
10
  n=dims($)-1 // number of columns
 
11
  y=mlist('cblock')
 
12
  
 
13
  j=varargin($-1)
 
14
  if type(j)==2|type(j)==129 then 
 
15
    j=horner(j,n)
 
16
  elseif type(j)==4 then
 
17
    j=find(j)
 
18
  elseif and(size(j)==[-1,-1]) then 
 
19
    j=1:n
 
20
  end
 
21
  if length(varargin)==2 then //y=x(i)
 
22
    if m<>1 then 
 
23
      error('Syntax x(j) only allowed for row cblock''s')
 
24
    end
 
25
    i=1
 
26
  else //y=x(i,j)
 
27
    i=varargin(1)
 
28
  end
 
29
 
 
30
  first=%t
 
31
 
 
32
  for k=1:size(j,'*')
 
33
    jk=j(k)
 
34
    I=find(jk>=dims(1:$-1)&jk<dims(2:$))
 
35
    if I>1 then jk=jk-dims(I)+1,end
 
36
    v=getfield(I+1,x)
 
37
    if first then
 
38
      temp=v(i,jk)
 
39
      first=%f
 
40
    else
 
41
      if type(v)==type(temp) then
 
42
        temp=[temp v(i,jk)]
 
43
      else
 
44
        setfield(length(y)+1,temp,y)
 
45
        temp=v(i,jk)
 
46
      end
 
47
    end
 
48
  end
 
49
  if length(y)==1 then
 
50
    y=temp
 
51
  else
 
52
    setfield(length(y)+1,temp,y)
 
53
  end
 
54
  
 
55
endfunction