%include "ilap_inc" %externalintegerfn route(%string(31) name,%record(port)%arrayname a,b, %integer n,%string(4) lay,%integer twid,tsep,sepn) %externalstring(63)%fnspec itos(%integer n,p) %external %routine %spec die %alias "ILAPDISASTER" (%string (255) mess) %routine %spec fault (%string (255) mess) %integerarray ap(1:n,1:n) %integerarray apl(1:n) %integer i,j,k,l,p,q,x,sep,tws,sx %for p=1,1,n %cycle %if a(p)_wa(p+1)_x %then fault("A ports ".itos(p,0). %c " and ".itos(p+1,0)." too close") %if b(p)_x+b(p)_w+tsep>b(p+1)_x %then fault("B ports ".itos(p,0). %c " and ".itos(p+1,0)." too close") %repeat tws=twid+tsep sep=1 %for p=1,1,n %cycle %if a(p)_x>=b(p)_x %and a(p)_x+a(p)_w<=b(p)_x+b(p)_w %then %c apl(p)=0 %and %continue ;! b port overlaps a port %if a(p)_x=b(p)_x %then %exit ap(p,i)=x i=i+1 %repeat ap(p,i)=b(p)_x apl(p)=i %finish %else %start i=1 %for j=p-1,-1,1 %cycle x=a(j)_x+a(j)_w+i*tws %if x<=b(p)_x+b(p)_w %then %exit ap(p,i)=x i=i+1 %repeat ap(p,i)=b(p)_x+b(p)_w apl(p)=-i %finish %if i>sep %then sep=i %repeat sep=tws*sep-tsep %if sepn>0 %then %start %if sepn0 %then i=a(p)_x %and j=twid %else %c i=a(p)_x+a(p)_w %and j=-twid %and l=-l wirex(i,0,j) ; i=i+j %for q=1,1,l %cycle k=i i=ap(p,q)+j %if i#k %then ax(i) %if q