File: adjust.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (124 lines) | stat: -rw-r--r-- 2,788 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function [ok,bllst]=adjust(bllst,inpptr,outptr,inplnk,outlnk)
//
// Copyright INRIA
[outoin,outoinptr]=connmat(inpptr,outptr,inplnk,outlnk)
//
for hh=1:length(bllst)
  ok=%t
  for blkout=1:length(bllst)
    for portout=1:outptr(blkout+1)-outptr(blkout)
      jj=outptr(blkout)+portout-1
      for kk=outoinptr(jj):outoinptr(jj+1)-1
	blkin=outoin(kk,1);portin=outoin(kk,2)
	//
	nout=bllst(blkout)(3)(portout);nin=bllst(blkin)(2)(portin)
	if (nout>0&nin>0) then
	  if nin<>nout then
	    bad_connection(corinv(blkout),portout,nout,corinv(blkin),portin,nin)
	    ok=%f;return
	  end
	elseif (nout>0&nin<0) then 
	  ww=find(bllst(blkin)(2)==nin)
	  if ww<>[] then
	    bllst(blkin)(2)(ww)=nout
	  end
	  ww=find(bllst(blkin)(3)==nin)
	  if ww<>[] then  
	    bllst(blkin)(3)(ww)=nout
	  end
	elseif (nin>0&nout<0) then 
	  ww=find(bllst(blkout)(3)==nout)
	  if ww<>[] then
	    bllst(blkout)(3)(ww)=nin
	  end
	  ww=find(bllst(blkout)(2)==nout)
	  if ww<>[] then
	    bllst(blkout)(2)(ww)=nin
	  end
	elseif (nin==0) then
	  ww=bllst(blkin)(3)(:)
	  if mini(ww)>0 then 
	    if nout>0 then
	      if sum(ww)==nout then
		bllst(blkin)(2)(portin)=nout
	      else
		bad_connection(corinv(blkin))
		ok=%f;return
	      end
	    else
	      bllst(blkin)(2)(portin)=sum(ww)
	      ok=%f
	    end
	  else      
	    nww=ww(find(ww<0))
	    if norm(nww-nww(1),1)==0 & nout>0 then
	      bllst(blkin)(2)(portin)=nout
	      k=(nout-sum(ww(find(ww>0))))/size(nww,'*')
	      if k==int(k) then
		bllst(blkin)(3)(find(ww<0))=k
	      else
		bad_connection(corinv(blkin))
		ok=%f;return
	      end
	    else
	      ok=%f
	    end
	  end
	elseif (nout==0) then
	  ww=bllst(blkout)(2)(:)
	  if mini(ww)>0 then 
	    if nin>0 then
	      if sum(ww)==nin then
		bllst(blkout)(3)(portout)=nin
	      else
		bad_connection(corinv(blkout))
		ok=%f;return
	      end
	    else
	      bllst(blkout)(3)(portout)=sum(ww)
	      ok=%f
	    end
	  else      
	    nww=ww(find(ww<0))
	    if norm(nww-nww(1),1)==0 & nin>0 then
	      bllst(blkout)(3)(portout)=nin
	      k=(nout-sum(ww(find(ww>0))))/size(nww,'*')
	      if k==int(k) then
		bllst(blkout)(2)(find(ww<0))=k
	      else
		bad_connection(corinv(blkout))
		ok=%f;return
	      end
	    else
	      ok=%f
	    end
	  end	
	else
	  //case where both are negative
	  ok=%f
	end
      end
    end
  end
  if ok then return, end
end
message('Not enough information to determine port sizes');  
ok=%f

function [outoin,outoinptr]=connmat(inpptr,outptr,inplnk,outlnk)
outoin=[];outoinptr=1
for k=1:outptr($)-1
  ii=[]
  for j=outlnk(k)
    ii=[ii;find(inplnk==j)]
  end
  outoini=[];jj=0
  for j=ii
    m=maxi(find(inpptr<=j))
    n=j-inpptr(m)+1
    outoini=[outoini;[m,n]]
    jj=jj+1
  end
  outoinptr=[outoinptr;outoinptr($)+jj]
  outoin=[outoin;outoini]
end