From cb0d1cd2e23287314a2031dbd9a0eda631354b72 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20DAVID?= Date: Fri, 12 Apr 2013 15:50:56 +0200 Subject: [PATCH] Xcos-Scicos: indent some files before modification Change-Id: Ibffc3f841e89880098dfd6a8d0d5687f5e8c4752 --- scilab/modules/scicos/includes/scicos.h | 1 + .../scicos/macros/scicos_scicos/c_pass2.sci | 4555 ++++++++++---------- .../scicos/macros/scicos_scicos/scicos_model.sci | 61 +- .../scicos/macros/scicos_scicos/scicos_sim.sci | 103 +- .../modules/scicos/sci_gateway/c/sci_model2blk.c | 831 +++- scilab/modules/scicos/sci_gateway/c/sci_scicosim.c | 45 +- scilab/modules/scicos/src/c/createblklist.c | 805 ++-- scilab/modules/scicos/src/c/scicos.c | 1017 ++++- .../modules/scicos_blocks/includes/scicos_block.h | 94 +- .../modules/scicos_blocks/includes/scicos_block4.h | 1 + .../c_computational_functions/C_struct.xml | 1 + 11 files changed, 4388 insertions(+), 3126 deletions(-) diff --git a/scilab/modules/scicos/includes/scicos.h b/scilab/modules/scicos/includes/scicos.h index c5fb3c6..2422ea2 100644 --- a/scilab/modules/scicos/includes/scicos.h +++ b/scilab/modules/scicos/includes/scicos.h @@ -221,3 +221,4 @@ void end_scicos_sim(void); void Coserror(const char *fmt, ...); #endif + diff --git a/scilab/modules/scicos/macros/scicos_scicos/c_pass2.sci b/scilab/modules/scicos/macros/scicos_scicos/c_pass2.sci index ec907bc..2601687 100644 --- a/scilab/modules/scicos/macros/scicos_scicos/c_pass2.sci +++ b/scilab/modules/scicos/macros/scicos_scicos/c_pass2.sci @@ -20,220 +20,220 @@ // function cpr=c_pass2(bllst,connectmat,clkconnect,cor,corinv,flag) -// cor ; correspondance table with initial block ordering -// -// bllst: list with nblk elts where nblk denotes number of blocks. -// Each element must be a list with 16 elements: -// 1- a list containing function name and function type -// 2- vector of number of inputs -// 3- vector of number of ouputs -// 4- vector of number of clock inputs -// 5- vector of number of clock outputs -// 6- vector (column) of continuous initial condition -// 7- vector (column) of discrete initial condition -// 8- vector (column) of real parameters -// 9- vector (column) of integer parameters -// 10- string: 'l' for synchro (ifthenelse,eselect) or 'm' -// (memo) or 'x' for blocks that need to be called during -// integration even in the absence of state (only if with workspace) -// 11- vector of size including -// preprogrammed event firing times (<0 if no firing) -// 12- boolean vector (column): 1:nin entry for dependence on u, -// last on t -// 13- block label -// 14- number of zero crossings -// 15- number of modes -// 16- empty list (equation for modelica blocks) -// -// connectmat: nx4 matrix. Each row contains, in order, the block -// number and the port number of an outgoing scicopath, -// and the block number and the port number of the target -// ingoing scicopath. -// -// clkconnect: same as connectmat but for clock scicopaths. -// -// define some constants - if argn(2) <6 then flag="verbose",end - show_trace=%f - if show_trace then mprintf('c_pass1:\t%f\n', timer()),end - - show_pause=%f; - show_comment=%f; - - if bllst==list() then - messagebox(_('No block can be activated'),"modal","error") - cpr=list() - ok=%f; - return - end - - //correction of clkconnect.. Must be done before - clkconnect(find(clkconnect(:,2)==0),2)=1; - - - - - if exists('%scicos_solver')==0 then %scicos_solver=0,end - - clkptr=1,cliptr=1,typ_l=[], - nblk=size(bllst) - - //take care of the heritage - [bllst,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,dep_u,dep_uptr,dep_t,.. - typ_l,typ_r,typ_m,tblock,typ_cons,typ_zx,ok]=mini_extract_info(bllst,.. - connectmat,clkconnect) - if show_trace then mprintf('c_pass20:\t%f\n', timer()),end - if ~ok then - cpr=list() - return - end - [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk) - - [critev]=critical_events(connectmat,clkconnect,dep_t,typ_r,.. - typ_l,typ_zx,outoin,outoinptr,clkptr) - [clkconnect,exe_cons]=pak_ersi(connectmat,clkconnect,typ_r,.. - typ_l,outoin,outoinptr,tblock,typ_cons,clkptr) - - - [ordclk,ordptr,cord,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,.. - dep_uptr,corinv,clkptr,cliptr,critev,ok]=paksazi2(typ_l,clkconnect,.. - connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) - - if ~ok then - cpr=list() - return - end - - if show_pause then - mprintf('fin de paksazi') - pause - end - - if show_trace then mprintf('c_pass31:\t%f\n', timer()),end - - //extract various info from bllst - [lnksz,lnktyp,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,xptr,zptr,.. - ozptr,typ_mod,rpptr,ipptr,opptr,xc0,xcd0,xd0,oxd0,rpar,.. - ipar,opar,typ_z,typ_x,typ_m,funs,funtyp,initexe,labels,.. - bexe,boptr,blnk,blptr,ok]=extract_info(bllst,connectmat,clkconnect,typ_l); - typ_z0=typ_z; - - - - if ~ok then - messagebox(_('Problem in port size or type.'),"modal","error"); - cpr=list() - return, - end - - if show_trace then mprintf('c_pass41:\t%f\n', timer()),end - - //form a matrix which gives destinations of each block - [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk) - [evoutoin,evoutoinptr]=synch_clkconnect(typ_l,clkconnect) - // - if show_trace then mprintf('c_pass50:\t%f\n', timer()),end - - [execlk_cons]=discard(clkptr,cliptr,clkconnect,exe_cons) - - clkconnect=[];exe_cons=[] - - if show_trace then mprintf('c_pass501:\t%f\n', timer()),end - - // Set execution scheduling tables - [ordclk,iord,oord,zord,typ_z,ok]=scheduler(inpptr,outptr,clkptr,execlk_cons,.. - outoin,outoinptr,evoutoin,evoutoinptr,typ_z,typ_x,typ_l,bexe,boptr,blnk,blptr,.. - ordclk,ordptr,cord,dep_t,dep_u,dep_uptr); - - if ~ok then - cpr=list() - return, - end - - if show_trace then mprintf('c_pass51:\t%f\n', timer()),end - //form scicos arguments - - nb=size(typ_z,'*'); - zcptr=ones(nb+1,1); - modptr=ones(nb+1,1); - - for i=1:nb - zcptr(i+1)=zcptr(i)+typ_z(i) - modptr(i+1)=modptr(i)+sign(typ_z(i))*typ_mod(i); - end - - ztyp=sign(typ_z0) //completement inutile pour simulation - // utiliser pour la generation de code - - if xptr($)==1 & zcptr($)>1 then - mess=msprintf(_('No continuous-time state. Thresholds are ignored; this \n'+.. - 'may be OK if you don''t generate external events with them.\n'+.. - 'If you want to reactivate the thresholds, the you need\n\n'+.. - 'to include a block with continuous-time state in your diagram.\n'+.. - 'You can for example include DUMMY CLSS block (linear palette).')) - messagebox(mess,"modal","error"); - end - - subscr=[] - ncblk=0;nxblk=0;ndblk=0;ndcblk=0; - sim=scicos_sim(funs=funs,xptr=xptr,zptr=zptr,ozptr=ozptr,.. - zcptr=zcptr,inpptr=inpptr,outptr=outptr,.. - inplnk=inplnk,outlnk=outlnk,rpar=rpar,rpptr=rpptr,.. - ipar=ipar,ipptr=ipptr,opar=opar,opptr=opptr,.. - clkptr=clkptr,ordptr=ordptr,execlk=ordclk,.. - ordclk=ordclk,cord=cord,oord=oord,zord=zord,.. - critev=critev(:),nb=nb,ztyp=ztyp,nblk=nblk,.. - ndcblk=ndcblk,subscr=subscr,funtyp=funtyp,.. - iord=iord,labels=labels,modptr=modptr); - - //initialize agenda - [tevts,evtspt,pointi]=init_agenda(initexe,clkptr) - if show_trace then mprintf('c_pass61:\t%f\n', timer()),end - - //mod=0*ones(modptr($)-1,1) - - outtb=list(); - outtb=buildouttb(lnksz,lnktyp); - - iz0=zeros(nb,1); - - if max(funtyp)>10000 &%scicos_solver==0 then - warning(_('Diagram contains implicit blocks, compiling for implicit Solver.')) - %scicos_solver=100 - end - if %scicos_solver==100 then xc0=[xc0;xcd0],end - state=scicos_state() - state.x=xc0 - state.z=xd0 - state.oz=oxd0 - state.iz=iz0 - state.tevts=tevts - state.evtspt=evtspt - state.pointi=pointi - state.outtb=outtb - // state.mod=mod - - cpr=scicos_cpr(state=state,sim=sim,cor=cor,corinv=corinv); - - if show_trace then mprintf('c_pass71:\t%f\n', timer()),end + // cor ; correspondance table with initial block ordering + // + // bllst: list with nblk elts where nblk denotes number of blocks. + // Each element must be a list with 16 elements: + // 1- a list containing function name and function type + // 2- vector of number of inputs + // 3- vector of number of ouputs + // 4- vector of number of clock inputs + // 5- vector of number of clock outputs + // 6- vector (column) of continuous initial condition + // 7- vector (column) of discrete initial condition + // 8- vector (column) of real parameters + // 9- vector (column) of integer parameters + // 10- string: 'l' for synchro (ifthenelse,eselect) or 'm' + // (memo) or 'x' for blocks that need to be called during + // integration even in the absence of state (only if with workspace) + // 11- vector of size including + // preprogrammed event firing times (<0 if no firing) + // 12- boolean vector (column): 1:nin entry for dependence on u, + // last on t + // 13- block label + // 14- number of zero crossings + // 15- number of modes + // 16- empty list (equation for modelica blocks) + // + // connectmat: nx4 matrix. Each row contains, in order, the block + // number and the port number of an outgoing scicopath, + // and the block number and the port number of the target + // ingoing scicopath. + // + // clkconnect: same as connectmat but for clock scicopaths. + // + // define some constants + if argn(2) <6 then flag="verbose",end + show_trace=%f + if show_trace then mprintf("c_pass1:\t%f\n", timer()),end + + show_pause=%f; + show_comment=%f; + + if bllst==list() then + messagebox(_("No block can be activated"),"modal","error") + cpr=list() + ok=%f; + return + end + + //correction of clkconnect.. Must be done before + clkconnect(find(clkconnect(:,2)==0),2)=1; + + + + + if exists("%scicos_solver")==0 then %scicos_solver=0,end + + clkptr=1,cliptr=1,typ_l=[], + nblk=size(bllst) + + //take care of the heritage + [bllst,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,dep_u,dep_uptr,dep_t,.. + typ_l,typ_r,typ_m,tblock,typ_cons,typ_zx,ok]=mini_extract_info(bllst,.. + connectmat,clkconnect) + if show_trace then mprintf("c_pass20:\t%f\n", timer()),end + if ~ok then + cpr=list() + return + end + [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk) + + [critev]=critical_events(connectmat,clkconnect,dep_t,typ_r,.. + typ_l,typ_zx,outoin,outoinptr,clkptr) + [clkconnect,exe_cons]=pak_ersi(connectmat,clkconnect,typ_r,.. + typ_l,outoin,outoinptr,tblock,typ_cons,clkptr) + + + [ordclk,ordptr,cord,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,.. + dep_uptr,corinv,clkptr,cliptr,critev,ok]=paksazi2(typ_l,clkconnect,.. + connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) + + if ~ok then + cpr=list() + return + end + + if show_pause then + mprintf("fin de paksazi") + pause + end + + if show_trace then mprintf("c_pass31:\t%f\n", timer()),end + + //extract various info from bllst + [lnksz,lnktyp,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,xptr,zptr,.. + ozptr,typ_mod,rpptr,ipptr,opptr,xc0,xcd0,xd0,oxd0,rpar,.. + ipar,opar,typ_z,typ_x,typ_m,funs,funtyp,initexe,labels,.. + bexe,boptr,blnk,blptr,ok]=extract_info(bllst,connectmat,clkconnect,typ_l); + typ_z0=typ_z; + + + + if ~ok then + messagebox(_("Problem in port size or type."),"modal","error"); + cpr=list() + return, + end + + if show_trace then mprintf("c_pass41:\t%f\n", timer()),end + + //form a matrix which gives destinations of each block + [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk) + [evoutoin,evoutoinptr]=synch_clkconnect(typ_l,clkconnect) + // + if show_trace then mprintf("c_pass50:\t%f\n", timer()),end + + [execlk_cons]=discard(clkptr,cliptr,clkconnect,exe_cons) + + clkconnect=[];exe_cons=[] + + if show_trace then mprintf("c_pass501:\t%f\n", timer()),end + + // Set execution scheduling tables + [ordclk,iord,oord,zord,typ_z,ok]=scheduler(inpptr,outptr,clkptr,execlk_cons,.. + outoin,outoinptr,evoutoin,evoutoinptr,typ_z,typ_x,typ_l,bexe,boptr,blnk,blptr,.. + ordclk,ordptr,cord,dep_t,dep_u,dep_uptr); + + if ~ok then + cpr=list() + return, + end + + if show_trace then mprintf("c_pass51:\t%f\n", timer()),end + //form scicos arguments + + nb=size(typ_z,"*"); + zcptr=ones(nb+1,1); + modptr=ones(nb+1,1); + + for i=1:nb + zcptr(i+1)=zcptr(i)+typ_z(i) + modptr(i+1)=modptr(i)+sign(typ_z(i))*typ_mod(i); + end + + ztyp=sign(typ_z0) //completement inutile pour simulation + // utiliser pour la generation de code + + if xptr($)==1 & zcptr($)>1 then + mess=msprintf(_("No continuous-time state. Thresholds are ignored; this \n"+.. + "may be OK if you don''t generate external events with them.\n"+.. + "If you want to reactivate the thresholds, the you need\n\n"+.. + "to include a block with continuous-time state in your diagram.\n"+.. + "You can for example include DUMMY CLSS block (linear palette).")) + messagebox(mess,"modal","error"); + end + + subscr=[] + ncblk=0;nxblk=0;ndblk=0;ndcblk=0; + sim=scicos_sim(funs=funs,xptr=xptr,zptr=zptr,ozptr=ozptr,.. + zcptr=zcptr,inpptr=inpptr,outptr=outptr,.. + inplnk=inplnk,outlnk=outlnk,rpar=rpar,rpptr=rpptr,.. + ipar=ipar,ipptr=ipptr,opar=opar,opptr=opptr,.. + clkptr=clkptr,ordptr=ordptr,execlk=ordclk,.. + ordclk=ordclk,cord=cord,oord=oord,zord=zord,.. + critev=critev(:),nb=nb,ztyp=ztyp,nblk=nblk,.. + ndcblk=ndcblk,subscr=subscr,funtyp=funtyp,.. + iord=iord,labels=labels,modptr=modptr); + + //initialize agenda + [tevts,evtspt,pointi]=init_agenda(initexe,clkptr) + if show_trace then mprintf("c_pass61:\t%f\n", timer()),end + + //mod=0*ones(modptr($)-1,1) + + outtb=list(); + outtb=buildouttb(lnksz,lnktyp); + + iz0=zeros(nb,1); + + if max(funtyp)>10000 &%scicos_solver==0 then + warning(_("Diagram contains implicit blocks, compiling for implicit Solver.")) + %scicos_solver=100 + end + if %scicos_solver==100 then xc0=[xc0;xcd0],end + state=scicos_state() + state.x=xc0 + state.z=xd0 + state.oz=oxd0 + state.iz=iz0 + state.tevts=tevts + state.evtspt=evtspt + state.pointi=pointi + state.outtb=outtb + // state.mod=mod + + cpr=scicos_cpr(state=state,sim=sim,cor=cor,corinv=corinv); + + if show_trace then mprintf("c_pass71:\t%f\n", timer()),end endfunction //donne les sources d'activation du sch�ma function [vec_clk]=get_clocks(clkconnect,clkptr) - vec_clk=[] - if (find(clkconnect(:,1)==0) ~=[]) then - //activation continue - vec_clk=[vec_clk;0 0]; - end - for blk=1:size(clkptr,1)-1 - if ~typ_l(blk) then - for port=1:clkptr(blk+1)-clkptr(blk) - vec_clk=[vec_clk; blk port]; - end - end - end + vec_clk=[] + if (find(clkconnect(:,1)==0) ~=[]) then + //activation continue + vec_clk=[vec_clk;0 0]; + end + for blk=1:size(clkptr,1)-1 + if ~typ_l(blk) then + for port=1:clkptr(blk+1)-clkptr(blk) + vec_clk=[vec_clk; blk port]; + end + end + end endfunction @@ -241,484 +241,484 @@ endfunction //insere le vecteur primary dans vec_clk apr�s la ligne comptenant le bloc i function vec_clk0=set_primary_clk(vec_clk,primary,i) - if vec_clk~=[] then - n_vc0=find(vec_clk==i) - n_vc0=n_vc0($) - vec_clk0=vec_clk(1:n_vc0) - vec_clk1=vec_clk(n_vc0+1:size(vec_clk,1)) - for k=1:size(primary,1) - if find(primary(k)==vec_clk0)==[] then - vec_clk0($+1)=primary(k) - end - end - for k=1:size(vec_clk1,1) - if find(vec_clk1(k)==vec_clk0)==[] then - vec_clk0($+1)=vec_clk1(k) - end - end - else - vec_clk0=primary - end + if vec_clk~=[] then + n_vc0=find(vec_clk==i) + n_vc0=n_vc0($) + vec_clk0=vec_clk(1:n_vc0) + vec_clk1=vec_clk(n_vc0+1:size(vec_clk,1)) + for k=1:size(primary,1) + if find(primary(k)==vec_clk0)==[] then + vec_clk0($+1)=primary(k) + end + end + for k=1:size(vec_clk1,1) + if find(vec_clk1(k)==vec_clk0)==[] then + vec_clk0($+1)=vec_clk1(k) + end + end + else + vec_clk0=primary + end endfunction //insere la sous-matrice primary dans vec_clk apr�s la ligne k function vec_clk0=set_primary_clkport(vec_clk,primary,i) - if vec_clk~=[] then - vec_clk0=vec_clk(1:i,:) - vec_clk1=vec_clk(i+1:size(vec_clk,1),:) - for k=1:size(primary,1) - f=find(primary(k,1)==vec_clk0(:,1)) - if f==[] then - vec_clk0=[vec_clk0;primary(k,:)] - end - end - n_vc1=size(vec_clk1,1) - if n_vc1>0 then - for k=1:n_vc1 - f=find(vec_clk1(k,1)==vec_clk0(:,1)) - if f==[] then - vec_clk0=[vec_clk0;vec_clk1(k,:)] - end - end - end - else - vec_clk0=primary - end - + if vec_clk~=[] then + vec_clk0=vec_clk(1:i,:) + vec_clk1=vec_clk(i+1:size(vec_clk,1),:) + for k=1:size(primary,1) + f=find(primary(k,1)==vec_clk0(:,1)) + if f==[] then + vec_clk0=[vec_clk0;primary(k,:)] + end + end + n_vc1=size(vec_clk1,1) + if n_vc1>0 then + for k=1:n_vc1 + f=find(vec_clk1(k,1)==vec_clk0(:,1)) + if f==[] then + vec_clk0=[vec_clk0;vec_clk1(k,:)] + end + end + end + else + vec_clk0=primary + end + endfunction //insere la sous-matrice ordoclk0 dans ordclk apr�s le block k function [ordptr,ordclk,blocs_traites]=set_ordclk(ordclk,.. - ordoclk0,k,j,ordptr,blocs_traites) - if ordoclk0~=[] then - if ordclk==[] then - ordclk=[ordclk;ordoclk0]; - ordptr($+1)=ordptr($)+size(ordoclk0,1); - blocs_traites=[blocs_traites;k] //k - else - m=max(find(blocs_traites==k)) - if j>1 & m~=[] then - ordclk=[ordclk(1:ordptr(m+1)-1,:);ordoclk0;ordclk(ordptr(m+1):$,:)] - ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)] - blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)] - else - ind=find(blocs_traites 1 & find((blocs_traites==k))~=[] then - m=max(find(blocs_traites==k)) - ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)] - blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)] + ordoclk0,k,j,ordptr,blocs_traites) + if ordoclk0~=[] then + if ordclk==[] then + ordclk=[ordclk;ordoclk0]; + ordptr($+1)=ordptr($)+size(ordoclk0,1); + blocs_traites=[blocs_traites;k] //k + else + m=max(find(blocs_traites==k)) + if j>1 & m~=[] then + ordclk=[ordclk(1:ordptr(m+1)-1,:);ordoclk0;ordclk(ordptr(m+1):$,:)] + ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)] + blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)] + else + ind=find(blocs_traites 1 & find((blocs_traites==k))~=[] then + m=max(find(blocs_traites==k)) + ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)] + blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)] + else + ind=find(blocs_traites 0 then - for i=1:n_f - clki1=clkconnect(f(i),1) - clki2=clkconnect(f(i),2) - g=find(clki1==parents(:,1)) - if g==[] | (g~=[] & parents(g,2)~=clki2) then - parents=[parents;clki1,clki2] - end - end - end + f=find(clkconnect(:,3)==blk) + n_f=size(f,2) + if n_f>0 then + for i=1:n_f + clki1=clkconnect(f(i),1) + clki2=clkconnect(f(i),2) + g=find(clki1==parents(:,1)) + if g==[] | (g~=[] & parents(g,2)~=clki2) then + parents=[parents;clki1,clki2] + end + end + end endfunction function [blks,blksptr]=depend_on(connectmat,dep_u,dep_uptr) -// returns the blocks on which depend directly a block - blks=[];blksptr=1 - for i=1:size(dep_uptr,'*')-1 - indport=find(dep_u(dep_uptr(i):dep_uptr(i+1)-1)); - f=[] - for j=indport - f=[f,find(connectmat(:,3)==i&connectmat(:,4)==j)] - end - blkis=unique(connectmat(f,1)) - blks=[blks;blkis] - blksptr=[blksptr;blksptr($)+size(blkis,'*')] - end + // returns the blocks on which depend directly a block + blks=[];blksptr=1 + for i=1:size(dep_uptr,"*")-1 + indport=find(dep_u(dep_uptr(i):dep_uptr(i+1)-1)); + f=[] + for j=indport + f=[f,find(connectmat(:,3)==i&connectmat(:,4)==j)] + end + blkis=unique(connectmat(f,1)) + blks=[blks;blkis] + blksptr=[blksptr;blksptr($)+size(blkis,"*")] + end endfunction function [eblks,eblksptr]=update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,bls) -// updates the blocks activating a block - nb1=size(cliptr,'*') - eblksptr($:nb1)=eblksptr($) - for i=bls - f=find(clkconnect(:,3)==i) - blkis=unique(clkconnect(f,1)) - dblkis=size(blkis,'*')-(eblksptr(i+1)-eblksptr(i)) - Ibef=eblksptr(1):eblksptr(i)-1; - Iaft=eblksptr(i+1):eblksptr($)-1; - eblks=[eblks(Ibef);blkis;eblks(Iaft)] - eblksptr(i+1:$)=eblksptr(i+1:$)+dblkis - end + // updates the blocks activating a block + nb1=size(cliptr,"*") + eblksptr($:nb1)=eblksptr($) + for i=bls + f=find(clkconnect(:,3)==i) + blkis=unique(clkconnect(f,1)) + dblkis=size(blkis,"*")-(eblksptr(i+1)-eblksptr(i)) + Ibef=eblksptr(1):eblksptr(i)-1; + Iaft=eblksptr(i+1):eblksptr($)-1; + eblks=[eblks(Ibef);blkis;eblks(Iaft)] + eblksptr(i+1:$)=eblksptr(i+1:$)+dblkis + end endfunction function [fblks,fblksptr]=update_event_activates(fblks,fblksptr,clkconnect,clkptr,bls) -// returns the blocks activated by a block (assumed typ_l) - nb1=size(cliptr,'*') - fblksptr($:nb1)=fblksptr($) - for i=bls - f=find(clkconnect(:,1)==i) - blkis=unique(clkconnect(f,3)) - dblkis=size(blkis,'*')-(fblksptr(i+1)-fblksptr(i)) - Ibef=fblksptr(1):fblksptr(i)-1; - Iaft=fblksptr(i+1):fblksptr($)-1; - fblks=[fblks(Ibef);blkis;fblks(Iaft)] - fblksptr(i+1:$)=fblksptr(i+1:$)+dblkis - end + // returns the blocks activated by a block (assumed typ_l) + nb1=size(cliptr,"*") + fblksptr($:nb1)=fblksptr($) + for i=bls + f=find(clkconnect(:,1)==i) + blkis=unique(clkconnect(f,3)) + dblkis=size(blkis,"*")-(fblksptr(i+1)-fblksptr(i)) + Ibef=fblksptr(1):fblksptr(i)-1; + Iaft=fblksptr(i+1):fblksptr($)-1; + fblks=[fblks(Ibef);blkis;fblks(Iaft)] + fblksptr(i+1:$)=fblksptr(i+1:$)+dblkis + end endfunction function [eblks,eblksptr]=event_depend_on(clkconnect,cliptr) -// returns the blocks activating a block - eblks=[];eblksptr=1 - for i=1:size(cliptr,'*')-1 - f=find(clkconnect(:,3)==i) - blkis=unique(clkconnect(f,1)) - eblks=[eblks;blkis] - eblksptr=[eblksptr;eblksptr($)+size(blkis,'*')] - end + // returns the blocks activating a block + eblks=[];eblksptr=1 + for i=1:size(cliptr,"*")-1 + f=find(clkconnect(:,3)==i) + blkis=unique(clkconnect(f,1)) + eblks=[eblks;blkis] + eblksptr=[eblksptr;eblksptr($)+size(blkis,"*")] + end endfunction function [fblks,fblksptr]=event_activates(clkconnect,clkptr) -// returns the blocks activated by a block of type typ_l - fblks=[];fblksptr=1 - for i=1:size(typ_l,'*') - if typ_l(i) then - f=find(clkconnect(:,1)==i) - blkis=unique(clkconnect(f,3)) - fblks=[fblks;blkis] - else - blkis=[] + // returns the blocks activated by a block of type typ_l + fblks=[];fblksptr=1 + for i=1:size(typ_l,"*") + if typ_l(i) then + f=find(clkconnect(:,1)==i) + blkis=unique(clkconnect(f,3)) + fblks=[fblks;blkis] + else + blkis=[] + end + fblksptr=[fblksptr;fblksptr($)+size(blkis,"*")] end - fblksptr=[fblksptr;fblksptr($)+size(blkis,'*')] - end endfunction function uni=merge_mat(m1,m2) -// for m1 and m2 with two columns containing >=0 values - uni=[m1;m2] - n=max(uni(:,2))+1; - [j,ind]=unique(uni(:,1)*n+uni(:,2)) - uni=uni(-gsort(-ind),:) + // for m1 and m2 with two columns containing >=0 values + uni=[m1;m2] + n=max(uni(:,2))+1; + [j,ind]=unique(uni(:,1)*n+uni(:,2)) + uni=uni(-gsort(-ind),:) endfunction function [typ_l,clkconnect,connectmat,vbllst,dep_t,dep_u,dep_uptr,.. - corinv,clkptr,cliptr,critev]=duplicate_block(bl,typ_l,clkconnect,.. - connectmat,vbllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) - - nblock=size(typ_l,1)+1 - g=find(clkconnect(:,1)==bl) - if g<> [] then - xx=clkconnect(g,:) - xx(:,1)=nblock - clkconnect=[clkconnect;xx] - end - - g=find(connectmat(:,3)==bl) - xx=connectmat(g,:) - xx(:,3)=nblock*ones(size(xx,1),1) - connectmat=[connectmat;xx] - - typ_l($+1)=%t - critev=[critev;critev(clkptr(bl):clkptr(bl+1)-1)] - vbllst(nblock)=vbllst(bl) - dep_t(nblock)=dep_t(bl) - dep_u=[dep_u;dep_u(dep_uptr(bl))] - dep_uptr($+1)=dep_uptr($)+1 - - corinv(nblock)=corinv(bl) - clkptr(nblock+1)=clkptr(nblock)+clkptr(bl+1)-clkptr(bl) - cliptr(nblock+1)=cliptr(nblock)+cliptr(bl+1)-cliptr(bl) - + corinv,clkptr,cliptr,critev]=duplicate_block(bl,typ_l,clkconnect,.. + connectmat,vbllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) + + nblock=size(typ_l,1)+1 + g=find(clkconnect(:,1)==bl) + if g<> [] then + xx=clkconnect(g,:) + xx(:,1)=nblock + clkconnect=[clkconnect;xx] + end + + g=find(connectmat(:,3)==bl) + xx=connectmat(g,:) + xx(:,3)=nblock*ones(size(xx,1),1) + connectmat=[connectmat;xx] + + typ_l($+1)=%t + critev=[critev;critev(clkptr(bl):clkptr(bl+1)-1)] + vbllst(nblock)=vbllst(bl) + dep_t(nblock)=dep_t(bl) + dep_u=[dep_u;dep_u(dep_uptr(bl))] + dep_uptr($+1)=dep_uptr($)+1 + + corinv(nblock)=corinv(bl) + clkptr(nblock+1)=clkptr(nblock)+clkptr(bl+1)-clkptr(bl) + cliptr(nblock+1)=cliptr(nblock)+cliptr(bl+1)-cliptr(bl) + endfunction function [childs]=get_allchilds(primary,fblks,fblksptr,typ_l) - oldtaille=0 - childs=primary(:)' - taille=size(childs,'*') + oldtaille=0 + childs=primary(:)' + taille=size(childs,"*") - while oldtaille<>taille - oldtaille=taille - for i=childs(typ_l(childs)) - bb=fblks(fblksptr(i):fblksptr(i+1)-1) - childs=union(childs,bb) + while oldtaille<>taille + oldtaille=taille + for i=childs(typ_l(childs)) + bb=fblks(fblksptr(i):fblksptr(i+1)-1) + childs=union(childs,bb) + end + taille=size(childs,"*") end - taille=size(childs,'*') - end endfunction function ok=is_alg_event_loop(typ_l,clkconnect) - clkconnect(find(clkconnect(:,1)==0),:)=[] - lclkconnect=clkconnect(typ_l(clkconnect(:,1))&typ_l(clkconnect(:,3)),[1,3]) - n=size(typ_l,'*') - oldvec=zeros(n,1) - vec(lclkconnect(:,1))=1 - i=0 - ok=%f - while i<=n - i=i+1 - oldvec=vec // not optimal to use large v - vec(lclkconnect(:,2))=vec(lclkconnect(:,1))+1 - if and(vec==oldvec) then - ok=%t - return - end - end + clkconnect(find(clkconnect(:,1)==0),:)=[] + lclkconnect=clkconnect(typ_l(clkconnect(:,1))&typ_l(clkconnect(:,3)),[1,3]) + n=size(typ_l,"*") + oldvec=zeros(n,1) + vec(lclkconnect(:,1))=1 + i=0 + ok=%f + while i<=n + i=i+1 + oldvec=vec // not optimal to use large v + vec(lclkconnect(:,2))=vec(lclkconnect(:,1))+1 + if and(vec==oldvec) then + ok=%t + return + end + end endfunction function [ordclk,ordptr,cord,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev,ok]=paksazi2(typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) - ordclk=[];ordptr=1;cord=[]; - lordclk=list() - - vbllst=1:length(bllst) - - zz=get_clocks(clkconnect,clkptr) - //testing event algebraic loops - ok=is_alg_event_loop(typ_l,clkconnect) - if ~ok then - disp(mprintf("%s: alg_event_loop failed", "c_pass2")); - messagebox(_('Algebraic loop on events.'),"modal","error"); - return - end - - - ok=%t - [fblks,fblksptr]=event_activates(clkconnect,clkptr) - [blks,blksptr]=depend_on(connectmat,dep_u,dep_uptr) - [eblks,eblksptr]=event_depend_on(clkconnect,cliptr) - - - for i=1:size(zz,1) - - nblock=size(typ_l,1); // number of blocks in diagram - - todo=zz(i,:) - while todo<>[] - - blk=todo(1,1);port=todo(1,2); - if blk==0 |find(definedfields(lordclk)==clkptr(blk)+port-1)==[] then - - f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port); - if f<>[] then - primary0=clkconnect(f,3);prt0=clkconnect(f,4) - else - primary0=[] - end - - if show_comment then mprintf("Processing blk " + string(blk) + " port "+... - + string(port) + "\n"),end - - if primary0<>[] then // delete redundant links - [jj,k]=unique(primary0*(1+max(prt0))+prt0) - index=setdiff(1:size(primary0,1),k) - clkconnect(f(index),:)=[] // does not affect e(f)blks - - primary=unique(primary0) - - [balg,vec]=ini_ordo3(primary) - if balg then - disp(mprintf("%s: ini_ordo (3) failed", "c_pass2")); - messagebox(_('Algebraic loop.'),"modal","error"), - ok=%f - return - end - - pvec=vec(primary)+.5*typ_l(primary) // same order typ_l to the right - [mi,In]=gsort(-pvec) - primary=primary(In) - lp=find(typ_l(primary)) - lprimary=primary(lp) - - bouclalg=%f - lp_backw=lp($:-1:1) - for i=lp_backw - for J=primary(i+1:$)' - if intersect(get_allchilds(primary(i)),get_allchilds(J))<>[] then - bouclalg=%t - break - end - end - if bouclalg then break,end - end - - if show_comment&bouclalg then mprintf('found intersect \n'),end - - if ~bouclalg then - [bouclalg,Vec,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,.. - dep_uptr,corinv,clkptr,cliptr,critev]=ini_ordo2(primary,.. - clkconnect,connectmat,bllst,typ_l,dep_t,dep_u,dep_uptr,.. - corinv,clkptr,cliptr,critev) - if bouclalg then - if show_comment then mprintf('found non convergence\n'),pause,end - i=lp(1) // first typ_l - if i==[] then - disp(mprintf("%s: ini_ordo (2) failed", "c_pass2")); - messagebox(_('Algebraic loop.'),"modal","error") - ok=%f - return - end - J=primary(i+1:$) - end - end + ordclk=[];ordptr=1;cord=[]; + lordclk=list() + + vbllst=1:length(bllst) + + zz=get_clocks(clkconnect,clkptr) + //testing event algebraic loops + ok=is_alg_event_loop(typ_l,clkconnect) + if ~ok then + disp(mprintf("%s: alg_event_loop failed", "c_pass2")); + messagebox(_("Algebraic loop on events."),"modal","error"); + return + end + - if bouclalg then - modif=%f - bl=primary(i) - - nout=clkptr(bl+1)-clkptr(bl) - //duplicate bl if it receives other links - f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port&clkconnect(:,3)==bl) - h=find(clkconnect(:,3)==bl) // this is always one - if size(f,2)<>size(h,2) then - nblock=nblock+1 - clkconnect(f,3)=nblock - if show_comment then - mprintf('duplicating pivot'+string(bl)+' to obtain '+string(nblock) + "\n"), + ok=%t + [fblks,fblksptr]=event_activates(clkconnect,clkptr) + [blks,blksptr]=depend_on(connectmat,dep_u,dep_uptr) + [eblks,eblksptr]=event_depend_on(clkconnect,cliptr) + + + for i=1:size(zz,1) + + nblock=size(typ_l,1); // number of blocks in diagram + + todo=zz(i,:) + while todo<>[] + + blk=todo(1,1);port=todo(1,2); + if blk==0 |find(definedfields(lordclk)==clkptr(blk)+port-1)==[] then + + f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port); + if f<>[] then + primary0=clkconnect(f,3);prt0=clkconnect(f,4) + else + primary0=[] end - [typ_l,clkconnect,connectmat,vbllst,dep_t,dep_u,dep_uptr,.. - corinv,clkptr,cliptr,critev]=duplicate_block(bl,typ_l,clkconnect,.. - connectmat,vbllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) - vec(nblock)=vec(bl) - //update pointer - blks_bl=blks(blksptr(bl):blksptr(bl+1)-1) - blks=[blks;blks_bl] - blksptr($+1)=blksptr($)+size(blks_bl,'*') - // - bls=[bl,nblock,fblks(fblksptr(bl):fblksptr(bl+1)-1)'] - [eblks,eblksptr]=.. - update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,bls) - bl=nblock // use new block as pivot - lprimary(i)=bl - end - - for bli=J(:)' - modif=%t - f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port&clkconnect(:,3)==bli) - clkconnect(f,1)=bl - clkconnect(f,2)=1 - xx= clkconnect(f,:) - for jj=2:nout - if show_comment then - mprintf('No block duplication but link between '+string(blk)+.. - ' and '+string(bli)+' replaced with links from '+.. - string(bl)+' to '+string(bli) + "\n"), + + if show_comment then mprintf("Processing blk " + string(blk) + " port "+... + + string(port) + "\n"),end + + if primary0<>[] then // delete redundant links + [jj,k]=unique(primary0*(1+max(prt0))+prt0) + index=setdiff(1:size(primary0,1),k) + clkconnect(f(index),:)=[] // does not affect e(f)blks + + primary=unique(primary0) + + [balg,vec]=ini_ordo3(primary) + if balg then + disp(mprintf("%s: ini_ordo (3) failed", "c_pass2")); + messagebox(_("Algebraic loop."),"modal","error"), + ok=%f + return end - xx(:,2)=jj; - clkconnect=[clkconnect;xx] - end - end - - [eblks,eblksptr]=update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,J(:)') - bls=[blk,bl];bls(find(bls==0))=[];bls=bls(typ_l(bls)); //exclude non typ_l and 0 - [fblks,fblksptr]=update_event_activates(fblks,fblksptr,clkconnect,clkptr,bls) - - // can (must) be done outside the for loop - // [fblks2,fblksptr2]=event_activates(clkconnect,clkptr) - // [eblks2,eblksptr2]=event_depend_on(clkconnect,cliptr) - //but then it must be updated - // if norm(eblksptr-eblksptr2)>0 then mprintf('roro2');pause,end - // if norm(fblksptr-fblksptr2)>0 then mprintf('soso2');pause,end - // if norm(eblks-eblks2)>0 then mprintf('roro');pause,end - // if norm(fblks-fblks2)>0 then mprintf('soso');pause,end - - - if ~modif then messagebox(_('Algebraic loop.'),"modal","error"),ok=%f,return,end - else - primary0=primary0(k); - prt0=prt0(k) - [primary0,prt0]=aggregate(primary0,prt0) - [mi,In]=gsort(-Vec(primary0)) - if blk<>0 then - lordclk(clkptr(blk)+port-1)=[primary0(In),prt0(In)] - - if show_comment then - mprintf('for blk port '+string(blk)+' '+string(port)+.. - ' ordclk is :\n'), disp(lordclk(clkptr(blk)+port-1)), + + pvec=vec(primary)+.5*typ_l(primary) // same order typ_l to the right + [mi,In]=gsort(-pvec) + primary=primary(In) + lp=find(typ_l(primary)) + lprimary=primary(lp) + + bouclalg=%f + lp_backw=lp($:-1:1) + for i=lp_backw + for J=primary(i+1:$)' + if intersect(get_allchilds(primary(i)),get_allchilds(J))<>[] then + bouclalg=%t + break + end + end + if bouclalg then break,end + end + + if show_comment&bouclalg then mprintf("found intersect \n"),end + + if ~bouclalg then + [bouclalg,Vec,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,.. + dep_uptr,corinv,clkptr,cliptr,critev]=ini_ordo2(primary,.. + clkconnect,connectmat,bllst,typ_l,dep_t,dep_u,dep_uptr,.. + corinv,clkptr,cliptr,critev) + if bouclalg then + if show_comment then mprintf("found non convergence\n"),pause,end + i=lp(1) // first typ_l + if i==[] then + disp(mprintf("%s: ini_ordo (2) failed", "c_pass2")); + messagebox(_("Algebraic loop."),"modal","error") + ok=%f + return + end + J=primary(i+1:$) + end + end + + if bouclalg then + modif=%f + bl=primary(i) + + nout=clkptr(bl+1)-clkptr(bl) + //duplicate bl if it receives other links + f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port&clkconnect(:,3)==bl) + h=find(clkconnect(:,3)==bl) // this is always one + if size(f,2)<>size(h,2) then + nblock=nblock+1 + clkconnect(f,3)=nblock + if show_comment then + mprintf("duplicating pivot"+string(bl)+" to obtain "+string(nblock) + "\n"), + end + [typ_l,clkconnect,connectmat,vbllst,dep_t,dep_u,dep_uptr,.. + corinv,clkptr,cliptr,critev]=duplicate_block(bl,typ_l,clkconnect,.. + connectmat,vbllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev) + vec(nblock)=vec(bl) + //update pointer + blks_bl=blks(blksptr(bl):blksptr(bl+1)-1) + blks=[blks;blks_bl] + blksptr($+1)=blksptr($)+size(blks_bl,"*") + // + bls=[bl,nblock,fblks(fblksptr(bl):fblksptr(bl+1)-1)'] + [eblks,eblksptr]=.. + update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,bls) + bl=nblock // use new block as pivot + lprimary(i)=bl + end + + for bli=J(:)' + modif=%t + f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port&clkconnect(:,3)==bli) + clkconnect(f,1)=bl + clkconnect(f,2)=1 + xx= clkconnect(f,:) + for jj=2:nout + if show_comment then + mprintf("No block duplication but link between "+string(blk)+.. + " and "+string(bli)+" replaced with links from "+.. + string(bl)+" to "+string(bli) + "\n"), + end + xx(:,2)=jj; + clkconnect=[clkconnect;xx] + end + end + + [eblks,eblksptr]=update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,J(:)') + bls=[blk,bl];bls(find(bls==0))=[];bls=bls(typ_l(bls)); //exclude non typ_l and 0 + [fblks,fblksptr]=update_event_activates(fblks,fblksptr,clkconnect,clkptr,bls) + + // can (must) be done outside the for loop + // [fblks2,fblksptr2]=event_activates(clkconnect,clkptr) + // [eblks2,eblksptr2]=event_depend_on(clkconnect,cliptr) + //but then it must be updated + // if norm(eblksptr-eblksptr2)>0 then mprintf('roro2');pause,end + // if norm(fblksptr-fblksptr2)>0 then mprintf('soso2');pause,end + // if norm(eblks-eblks2)>0 then mprintf('roro');pause,end + // if norm(fblks-fblks2)>0 then mprintf('soso');pause,end + + + if ~modif then messagebox(_("Algebraic loop."),"modal","error"),ok=%f,return,end + else + primary0=primary0(k); + prt0=prt0(k) + [primary0,prt0]=aggregate(primary0,prt0) + [mi,In]=gsort(-Vec(primary0)) + if blk<>0 then + lordclk(clkptr(blk)+port-1)=[primary0(In),prt0(In)] + + if show_comment then + mprintf("for blk port "+string(blk)+" "+string(port)+.. + " ordclk is :\n"), disp(lordclk(clkptr(blk)+port-1)), + end + else + cord=[primary0(In),prt0(In)] + end + + todo(1,:)=[] + L=[]; + for Bi=lprimary' + C=[1:clkptr(Bi+1)-clkptr(Bi)]' + L=[L;Bi*ones(C),C] + end + todo=merge_mat(todo,L) + end + else + if blk<>0 then + J=clkptr(blk)+port-1 + lordclk(J)=[] + if show_comment then + mprintf("for blk port "+string(blk)+" "+string(port)+.. + " ordclk is"), mprintf(lordclk(J) + "\n"), + end + else + cord=[] + end + + todo(1,:)=[] end - else - cord=[primary0(In),prt0(In)] - end - - todo(1,:)=[] - L=[]; - for Bi=lprimary' - C=[1:clkptr(Bi+1)-clkptr(Bi)]' - L=[L;Bi*ones(C),C] - end - todo=merge_mat(todo,L) - end - else - if blk<>0 then - J=clkptr(blk)+port-1 - lordclk(J)=[] - if show_comment then - mprintf('for blk port '+string(blk)+' '+string(port)+.. - ' ordclk is'), mprintf(lordclk(J) + "\n"), - end - else - cord=[] - end - - todo(1,:)=[] - end - else - todo(1,:)=[] - end - end + else + todo(1,:)=[] + end + end end for J=1:clkptr($)-1 - ordclk=[ordclk;lordclk(J)] - ordptr=[ordptr;ordptr($)+size(lordclk(J),1)] + ordclk=[ordclk;lordclk(J)] + ordptr=[ordptr;ordptr($)+size(lordclk(J),1)] end bllst=list(bllst(vbllst)) @@ -726,785 +726,785 @@ function [ordclk,ordptr,cord,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,dep_u endfunction function [primary0,port0]=aggregate(primary0,port0) -primary=discardprimary([primary0,port0]) // must rewrite -primary0=primary(:,1);port0=primary(:,2) + primary=discardprimary([primary0,port0]) // must rewrite + primary0=primary(:,1);port0=primary(:,2) endfunction function [parents]=get_parents2(parents,blk,port) - k=size(parents,1)+1; - f=find(clkconnect(:,3)==blk) - n_f=size(f,2) - if n_f>0 then - for i=1:n_f - if clkconnect(f(i),4)==port then - clki1=clkconnect(f(i),1) - clki2=clkconnect(f(i),2) - g=find(clki1==parents(:,1)) - if g==[] | (g~=[] & parents(g,2)~=clki2) then - parents(k,1)=clki1 - parents(k,2)=clki2 - k=k+1 - end - end - end - end + k=size(parents,1)+1; + f=find(clkconnect(:,3)==blk) + n_f=size(f,2) + if n_f>0 then + for i=1:n_f + if clkconnect(f(i),4)==port then + clki1=clkconnect(f(i),1) + clki2=clkconnect(f(i),2) + g=find(clki1==parents(:,1)) + if g==[] | (g~=[] & parents(g,2)~=clki2) then + parents(k,1)=clki1 + parents(k,2)=clki2 + k=k+1 + end + end + end + end endfunction //suppression des liens inutiles function [clkconnect,amaj]=find_del_inutile(clkconnect,vec_plus,typ_l) - amaj=[] - for i=1:size(vec_plus,1) - blk=vec_plus(i,1) - port=vec_plus(i,2) - parents=get_parents2([],blk,port) - j=1 - done=%f - n_p=size(parents,1) - while j<=n_p & ~done - par1=parents(j,1) - if par1~=0 & typ_l(par1) then - n_out=clkptr(par1+1)-clkptr(par1) - f=find(par1==parents(:,1)) - if size(f,2)==n_out then - if show_comment then - mprintf('find_del_inutile:') - mprintf('link between blocks '+string(par1)+' and '+string(blk)+.. - ' are deleted\n') - pause - end - [clkconnect]=del_inutile(clkconnect,par1,n_out,blk,port) - done=%t - amaj=[amaj;par1;blk] - end - end - j=j+1 - end - end + amaj=[] + for i=1:size(vec_plus,1) + blk=vec_plus(i,1) + port=vec_plus(i,2) + parents=get_parents2([],blk,port) + j=1 + done=%f + n_p=size(parents,1) + while j<=n_p & ~done + par1=parents(j,1) + if par1~=0 & typ_l(par1) then + n_out=clkptr(par1+1)-clkptr(par1) + f=find(par1==parents(:,1)) + if size(f,2)==n_out then + if show_comment then + mprintf("find_del_inutile:") + mprintf("link between blocks "+string(par1)+" and "+string(blk)+.. + " are deleted\n") + pause + end + [clkconnect]=del_inutile(clkconnect,par1,n_out,blk,port) + done=%t + amaj=[amaj;par1;blk] + end + end + j=j+1 + end + end endfunction function [clkconnect]=del_inutile(clkconnect,blk0,n_out,blk,port) - f=find(clkconnect(:,1)==blk0) - del=[] - for i=1:size(f,2) - if clkconnect(f(i),3)==blk & clkconnect(f(i),4)==port then - del=[del;f(i)] - end - end - clkconnect(del,:)=[] - p=get_parents([],blk0) - n_p=size(p,1) - for i=1:n_p - clkconnect($+1,:)=[p(i,1),p(i,2),blk,port] - end + f=find(clkconnect(:,1)==blk0) + del=[] + for i=1:size(f,2) + if clkconnect(f(i),3)==blk & clkconnect(f(i),4)==port then + del=[del;f(i)] + end + end + clkconnect(del,:)=[] + p=get_parents([],blk0) + n_p=size(p,1) + for i=1:n_p + clkconnect($+1,:)=[p(i,1),p(i,2),blk,port] + end endfunction function blk0=get_father(blk1,vectmp) - gg=find(clkconnect(:,3)==blk1) // parents of blk1 - del=find(clkconnect(gg,1)==0) - gg(del)=[] // remove continuous-time source - // it is inactive - hh=find(vectmp(clkconnect(gg,1))>0) // keep active ones - blk0=unique(clkconnect(gg(hh),1)) // active parent(s) - blk0=blk0(typ_l(blk0)) // can be a vector + gg=find(clkconnect(:,3)==blk1) // parents of blk1 + del=find(clkconnect(gg,1)==0) + gg(del)=[] // remove continuous-time source + // it is inactive + hh=find(vectmp(clkconnect(gg,1))>0) // keep active ones + blk0=unique(clkconnect(gg(hh),1)) // active parent(s) + blk0=blk0(typ_l(blk0)) // can be a vector endfunction function [bouclalg,vec,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,.. - dep_uptr,corinv,clkptr,cliptr,critev]=ini_ordo2(primary,.. - clkconnect,connectmat,bllst,typ_l,dep_t,dep_u,dep_uptr,corinv,clkptr,.. - cliptr,critev) - - n_p=size(primary,1) - - nblock=size(typ_l,1); - //initialisation de vec - //on initialise vec � -1 - vec=-ones(nblock,1) - vec(primary(:,1))=1 - - bouclalg=%f - fromfixe=%f - oldvec2=[] - counter2=0 - - [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary) - - while ~fromfixe - vec=update_vec3(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr) - // - if and(vec==oldvec2) then - fromfixe=%t - else - oldvec2=vec - end - counter2=counter2+1 - if (counter2>n_p+1) then - bouclalg=%t - // mprintf('Algebraic Loop detection.') - break + dep_uptr,corinv,clkptr,cliptr,critev]=ini_ordo2(primary,.. + clkconnect,connectmat,bllst,typ_l,dep_t,dep_u,dep_uptr,corinv,clkptr,.. + cliptr,critev) + + n_p=size(primary,1) + + nblock=size(typ_l,1); + //initialisation de vec + //on initialise vec � -1 + vec=-ones(nblock,1) + vec(primary(:,1))=1 + + bouclalg=%f + fromfixe=%f + oldvec2=[] + counter2=0 + + [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary) + + while ~fromfixe + vec=update_vec3(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr) + // + if and(vec==oldvec2) then + fromfixe=%t + else + oldvec2=vec + end + counter2=counter2+1 + if (counter2>n_p+1) then + bouclalg=%t + // mprintf('Algebraic Loop detection.') + break + end end - end endfunction function [bouclalg,vec]=ini_ordo3(primary) - n_p=size(primary,1) - - nblock=size(typ_l,1); - //initialisation de vec - //on initialise vec � -1 - vec=-ones(nblock,1) - vec(primary(:,1))=0 - - bouclalg=%f - fromfixe=%f - oldvec2=[] - counter2=0 - - [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary) - - while ~fromfixe - vec=update_vec4(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr) - - if and(vec==oldvec2) then - fromfixe=%t - else - oldvec2=vec - end - counter2=counter2+1 - if (counter2>n_p+1) then - bouclalg=%t - // mprintf('Algebraic Loop detection.') - break + n_p=size(primary,1) + + nblock=size(typ_l,1); + //initialisation de vec + //on initialise vec � -1 + vec=-ones(nblock,1) + vec(primary(:,1))=0 + + bouclalg=%f + fromfixe=%f + oldvec2=[] + counter2=0 + + [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary) + + while ~fromfixe + vec=update_vec4(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr) + + if and(vec==oldvec2) then + fromfixe=%t + else + oldvec2=vec + end + counter2=counter2+1 + if (counter2>n_p+1) then + bouclalg=%t + // mprintf('Algebraic Loop detection.') + break + end end - end endfunction function vec=update_vec3(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr) - for i=1:size(wprimptr,'*')-1 - w=wprim(wprimptr(i):wprimptr(i+1)-1) - g0=g0prim(g0primptr(i):g0primptr(i+1)-1) - g=gprim(gprimptr(i):gprimptr(i+1)-1) - // detecting algebraic loops within a single cluster - //mprintf([px,py,size(blks,'*')]) - vec(w)=max(vec(w)) - if (g0 ~= []) then - vec(w(1))=max(vec(w(1)),max(vec(g0))+1) - end - //g=g(find(vec(g)>-1)) //not optimal test max(vec(g)) - if g~=[] then - vec(w)=vec(w)-1 - vec(w)=max(vec(w),max(vec(g)))+1 - end - end + for i=1:size(wprimptr,"*")-1 + w=wprim(wprimptr(i):wprimptr(i+1)-1) + g0=g0prim(g0primptr(i):g0primptr(i+1)-1) + g=gprim(gprimptr(i):gprimptr(i+1)-1) + // detecting algebraic loops within a single cluster + //mprintf([px,py,size(blks,'*')]) + vec(w)=max(vec(w)) + if (g0 ~= []) then + vec(w(1))=max(vec(w(1)),max(vec(g0))+1) + end + //g=g(find(vec(g)>-1)) //not optimal test max(vec(g)) + if g~=[] then + vec(w)=vec(w)-1 + vec(w)=max(vec(w),max(vec(g)))+1 + end + end endfunction function vec=update_vec4(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr) - for i=1:size(wprimptr,'*')-1 - w=wprim(wprimptr(i):wprimptr(i+1)-1) - g0=g0prim(g0primptr(i):g0primptr(i+1)-1) - if g0<>[] then vec(w(1))=max(vec(w(1)),max(vec(g0))), end - vec(w(2:$))=vec(w(1))+1 - end + for i=1:size(wprimptr,"*")-1 + w=wprim(wprimptr(i):wprimptr(i+1)-1) + g0=g0prim(g0primptr(i):g0primptr(i+1)-1) + if g0<>[] then vec(w(1))=max(vec(w(1)),max(vec(g0))), end + vec(w(2:$))=vec(w(1))+1 + end endfunction function [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary) - wprim=[];wprimptr=1 - gprim=[];gprimptr=1 - g0prim=[];g0primptr=1 + wprim=[];wprimptr=1 + gprim=[];gprimptr=1 + g0prim=[];g0primptr=1 - for i=1:size(primary,'*') - w0=primary(i) - if typ_l(w0) then - w=get_allchilds(w0,fblks,fblksptr,typ_l) - j=find(w==w0) - w([1,j])=w([j,1]) // put w0 on top - else - w=w0; - end - wprim=[wprim;w(:)] - wprimptr($+1)=wprimptr($)+size(w,'*') - - px=blksptr(w(1));py=blksptr(w(1)+1)-1 - //mprintf([px,py,size(blks,'*')]) - g0prim=[g0prim;blks(px:py)] - g0primptr($+1)=g0primptr($)+size(px:py,2) - - g=[] - for i1=2:size(w,'*') // 1 is done already - px=blksptr(w(i1));py=blksptr(w(i1)+1)-1 - g=[g;blks(px:py)] - end - gprim=[gprim;g] - gprimptr($+1)=gprimptr($)+size(g,'*') - end + for i=1:size(primary,"*") + w0=primary(i) + if typ_l(w0) then + w=get_allchilds(w0,fblks,fblksptr,typ_l) + j=find(w==w0) + w([1,j])=w([j,1]) // put w0 on top + else + w=w0; + end + wprim=[wprim;w(:)] + wprimptr($+1)=wprimptr($)+size(w,"*") + + px=blksptr(w(1));py=blksptr(w(1)+1)-1 + //mprintf([px,py,size(blks,'*')]) + g0prim=[g0prim;blks(px:py)] + g0primptr($+1)=g0primptr($)+size(px:py,2) + + g=[] + for i1=2:size(w,"*") // 1 is done already + px=blksptr(w(i1));py=blksptr(w(i1)+1)-1 + g=[g;blks(px:py)] + end + gprim=[gprim;g] + gprimptr($+1)=gprimptr($)+size(g,"*") + end endfunction function primary=discardprimary(primary) -// discard - mma=max(primary(:,2))+1 - con=mma*primary(:,1)+primary(:,2) - [junk,ind]=gsort(-con);con=-junk - primary=primary(ind,:) - // discard duplicate calls to the same block port - if size(con,'*')>=2 then - primary(find(con(2:$)-con(1:$-1)==0),:)=[] - end - // group calls to different ports of the same block. - primary=[primary(:,1),2^(primary(:,2)-ones(primary(:,2)))] - primary=int(primary) - con=primary(:,1) - clkconnectjj=[] - if size(con,'*')>=2 then - iini=[find(con(2:$)-con(1:$-1)<>0),size(primary,1)] - else - iini=1 - end - for ii=iini - clkconnectjj=[clkconnectjj;[primary(ii,1),.. - mysum(primary(find(primary(:,1)==primary(ii,1)),2))]] - end - primary=clkconnectjj + // discard + mma=max(primary(:,2))+1 + con=mma*primary(:,1)+primary(:,2) + [junk,ind]=gsort(-con);con=-junk + primary=primary(ind,:) + // discard duplicate calls to the same block port + if size(con,"*")>=2 then + primary(find(con(2:$)-con(1:$-1)==0),:)=[] + end + // group calls to different ports of the same block. + primary=[primary(:,1),2^(primary(:,2)-ones(primary(:,2)))] + primary=int(primary) + con=primary(:,1) + clkconnectjj=[] + if size(con,"*")>=2 then + iini=[find(con(2:$)-con(1:$-1)<>0),size(primary,1)] + else + iini=1 + end + for ii=iini + clkconnectjj=[clkconnectjj;[primary(ii,1),.. + mysum(primary(find(primary(:,1)==primary(ii,1)),2))]] + end + primary=clkconnectjj endfunction function [ordclk,iord,oord,zord,typ_z,ok]=scheduler(inpptr,outptr,clkptr,execlk_cons,.. - outoin,outoinptr,evoutoin,evoutoinptr,typ_z,typ_x,typ_l,bexe,boptr,.. - blnk,blptr,ordclk,ordptr,cord,dep_t,dep_u,dep_uptr); - - nblk=size(typ_x,1) - //compute iord - if execlk_cons<>[] then - vec=-ones(1,nblk) - no_tu_dep=execlk_cons(:,1) - wec=zeros(1,nblk) - wec(no_tu_dep')=execlk_cons(:,2)' - vec(no_tu_dep)=0*no_tu_dep' - [r,ok]=newc_tree2(vec,outoin,outoinptr,dep_u,dep_uptr) - - iord=[r,wec(r)'] - else - iord=[] - end - // - if ~ok then - disp(mprintf("%s: scheduling failed", "c_pass2")); - messagebox(_('Algebraic loop.'),"modal","error"); - iord=[],oord=[],zord=[],critev=[] - return, - end - - n=size(cord,1) - vec=-ones(1,nblk); - vec(cord(:,1))=0; - typp=zeros(typ_l);typp(typ_l)=1 - - ext_cord1=cord; - j=1 - while %t - ii=ext_cord1(j,1) - if typ_l(ii) - for i=[clkptr(ii):clkptr(ii+1)-1] - ext_cord1=[ext_cord1;ordclk([ordptr(i):ordptr(i+1)-1],:)]; - end - end - j=j+1 - if j>size(ext_cord1,1) then break;end - end - // code to replace faulty unique which reorders - yy=ext_cord1(:,1)' - [xx,kkn]=unique(yy); - ext_cord=yy(-gsort(-kkn)) - //ext_cord=unique(ext_cord1(:,1)'); - //for i=ext_cord - // if typ_l(i) then typ_z(i)=clkptr(i+1)-clkptr(i)-1;end - //end // adding zero crossing surfaces to cont. time synchros - - //a supprimer - - [ext_cord_old,ok]=newc_tree3(vec,dep_u,dep_uptr,typp); - - if or(gsort(ext_cord_old)<>gsort(ext_cord)) then pause,end - // - //pour mettre a zero les typ_z qui ne sont pas dans ext_cord - //noter que typ_z contient les tailles des nzcross (peut etre >1) - typ_z(ext_cord)=-typ_z(ext_cord) - typ_z=-min(typ_z,0) - - if ~ok then mprintf('serious bug, report.');pause;end - // ext_cord=ext_cord(n+1:$); - - typ_z_save=typ_z - - fin=0 - while ~fin - fin=1 - for i=ext_cord($:-1:1) - for ii=[outoin(outoinptr(i):outoinptr(i+1)-1,1)',.. - evoutoin(evoutoinptr(i):evoutoinptr(i+1)-1,1)'] - //ii est un block affecte par changement de sortie du - //i-eme block de oord - if typ_z(ii) then - if typ_z(i)==0 then typ_z(i)=1;fin=0;end - end - if typ_x(ii) then - if ~typ_x(i) then typ_x(i)=%t;fin=0;end - end - if typ_z(i)&typ_x(i) then break,end - end - end - end - //supprimer les blocks a supprimer - ind=find(typ_z(cord(:,1))); - zord=cord(ind,:) - ind=find(typ_x(cord(:,1))); - oord=cord(ind,:) - typ_z=typ_z_save - //critev: vecteur indiquant si evenement est important pour tcrit - //Donc les blocks indiques sont des blocks susceptibles de produire - //des discontinuites quand l'evenement se produit - maX=max([ext_cord1(:,2);ordclk(:,2)])+1; - cordX=ext_cord1(:,1)*maX+ext_cord1(:,2); - - // 1: important; 0:non - //n=clkptr(nblk+1)-1 //nb d'evenement - n=size(ordptr,'*')-1 //nb d'evenement - - //a priori tous les evenemets sont non-importants - //critev=zeros(n,1) - for i=1:n - for hh=ordptr(i):ordptr(i+1)-1 - jj= ordclk(hh,1) //block excite par evenement i - //Following line is not correct because of ever active synchros - if or(jj*maX+ordclk(hh,2)==cordX) then - ordclk(hh,2)=-ordclk(hh,2) - end - end - end + outoin,outoinptr,evoutoin,evoutoinptr,typ_z,typ_x,typ_l,bexe,boptr,.. + blnk,blptr,ordclk,ordptr,cord,dep_t,dep_u,dep_uptr); + + nblk=size(typ_x,1) + //compute iord + if execlk_cons<>[] then + vec=-ones(1,nblk) + no_tu_dep=execlk_cons(:,1) + wec=zeros(1,nblk) + wec(no_tu_dep')=execlk_cons(:,2)' + vec(no_tu_dep)=0*no_tu_dep' + [r,ok]=newc_tree2(vec,outoin,outoinptr,dep_u,dep_uptr) + + iord=[r,wec(r)'] + else + iord=[] + end + // + if ~ok then + disp(mprintf("%s: scheduling failed", "c_pass2")); + messagebox(_("Algebraic loop."),"modal","error"); + iord=[],oord=[],zord=[],critev=[] + return, + end + + n=size(cord,1) + vec=-ones(1,nblk); + vec(cord(:,1))=0; + typp=zeros(typ_l);typp(typ_l)=1 + + ext_cord1=cord; + j=1 + while %t + ii=ext_cord1(j,1) + if typ_l(ii) + for i=[clkptr(ii):clkptr(ii+1)-1] + ext_cord1=[ext_cord1;ordclk([ordptr(i):ordptr(i+1)-1],:)]; + end + end + j=j+1 + if j>size(ext_cord1,1) then break;end + end + // code to replace faulty unique which reorders + yy=ext_cord1(:,1)' + [xx,kkn]=unique(yy); + ext_cord=yy(-gsort(-kkn)) + //ext_cord=unique(ext_cord1(:,1)'); + //for i=ext_cord + // if typ_l(i) then typ_z(i)=clkptr(i+1)-clkptr(i)-1;end + //end // adding zero crossing surfaces to cont. time synchros + + //a supprimer + + [ext_cord_old,ok]=newc_tree3(vec,dep_u,dep_uptr,typp); + + if or(gsort(ext_cord_old)<>gsort(ext_cord)) then pause,end + // + //pour mettre a zero les typ_z qui ne sont pas dans ext_cord + //noter que typ_z contient les tailles des nzcross (peut etre >1) + typ_z(ext_cord)=-typ_z(ext_cord) + typ_z=-min(typ_z,0) + + if ~ok then mprintf("serious bug, report.");pause;end + // ext_cord=ext_cord(n+1:$); + + typ_z_save=typ_z + + fin=0 + while ~fin + fin=1 + for i=ext_cord($:-1:1) + for ii=[outoin(outoinptr(i):outoinptr(i+1)-1,1)',.. + evoutoin(evoutoinptr(i):evoutoinptr(i+1)-1,1)'] + //ii est un block affecte par changement de sortie du + //i-eme block de oord + if typ_z(ii) then + if typ_z(i)==0 then typ_z(i)=1;fin=0;end + end + if typ_x(ii) then + if ~typ_x(i) then typ_x(i)=%t;fin=0;end + end + if typ_z(i)&typ_x(i) then break,end + end + end + end + //supprimer les blocks a supprimer + ind=find(typ_z(cord(:,1))); + zord=cord(ind,:) + ind=find(typ_x(cord(:,1))); + oord=cord(ind,:) + typ_z=typ_z_save + //critev: vecteur indiquant si evenement est important pour tcrit + //Donc les blocks indiques sont des blocks susceptibles de produire + //des discontinuites quand l'evenement se produit + maX=max([ext_cord1(:,2);ordclk(:,2)])+1; + cordX=ext_cord1(:,1)*maX+ext_cord1(:,2); + + // 1: important; 0:non + //n=clkptr(nblk+1)-1 //nb d'evenement + n=size(ordptr,"*")-1 //nb d'evenement + + //a priori tous les evenemets sont non-importants + //critev=zeros(n,1) + for i=1:n + for hh=ordptr(i):ordptr(i+1)-1 + jj= ordclk(hh,1) //block excite par evenement i + //Following line is not correct because of ever active synchros + if or(jj*maX+ordclk(hh,2)==cordX) then + ordclk(hh,2)=-ordclk(hh,2) + end + end + end endfunction function [ord,ok]=tree3(vec,dep_ut,typ_l) -//compute blocks execution tree - ok=%t - nb=size(vec,'*') - for j=1:nb+2 - fini=%t - for i=1:nb - if vec(i)==j-1&typ_l(i)<>-1 then - if j==nb+2 then - disp(mprintf("%s: tree (3) failed", "c_pass2")); - messagebox(_('Algebraic loop.'),"modal","error");ok=%f;ord=[];return; - end - if typ_l(i)==1 then - fini=%f; - kk=bexe(boptr(i):boptr(i+1)-1)'; - else - kk=[]; - for ii=blnk(blptr(i):blptr(i+1)-1)' - if vec(ii)>-1 & (dep_ut(ii,1) | (typ_l(ii)==1)) then - fini=%f; - kk=[kk ii]; - end - end - end - vec(kk)=j*ones(kk) ; //mprintf(vec) - end - end - if fini then break;end - end - [k,ord]=gsort(-vec); - ord(find(k==1))=[]; + //compute blocks execution tree + ok=%t + nb=size(vec,"*") + for j=1:nb+2 + fini=%t + for i=1:nb + if vec(i)==j-1&typ_l(i)<>-1 then + if j==nb+2 then + disp(mprintf("%s: tree (3) failed", "c_pass2")); + messagebox(_("Algebraic loop."),"modal","error");ok=%f;ord=[];return; + end + if typ_l(i)==1 then + fini=%f; + kk=bexe(boptr(i):boptr(i+1)-1)'; + else + kk=[]; + for ii=blnk(blptr(i):blptr(i+1)-1)' + if vec(ii)>-1 & (dep_ut(ii,1) | (typ_l(ii)==1)) then + fini=%f; + kk=[kk ii]; + end + end + end + vec(kk)=j*ones(kk) ; //mprintf(vec) + end + end + if fini then break;end + end + [k,ord]=gsort(-vec); + ord(find(k==1))=[]; endfunction function [clkconnectj_cons]=discard(clkptr,cliptr,clkconnect,exe_cons) - if exe_cons<>[] then - clkconnectj=exe_cons - mma=max(clkconnectj(:,2))+1 - con=mma*(clkconnectj(:,1))+clkconnectj(:,2) - [junk,ind]=gsort(-con);con=-junk - clkconnectj=clkconnectj(ind,:) - // discard duplicate calls to the same block port - if size(con,'*')>=2 then - clkconnectj(find(con(2:$)-con(1:$-1)==0),:)=[] - end - // group calls to different ports of the same block. - clkconnectj=[clkconnectj(:,1),2^(clkconnectj(:,2)-ones(clkconnectj(:,2)))] - clkconnectj=int(clkconnectj) - con=clkconnectj(:,1) - clkconnectj_cons=[] - if size(con,'*')>=2 then - iini=[find(con(2:$)-con(1:$-1)<>0),size(clkconnectj,1)] + if exe_cons<>[] then + clkconnectj=exe_cons + mma=max(clkconnectj(:,2))+1 + con=mma*(clkconnectj(:,1))+clkconnectj(:,2) + [junk,ind]=gsort(-con);con=-junk + clkconnectj=clkconnectj(ind,:) + // discard duplicate calls to the same block port + if size(con,"*")>=2 then + clkconnectj(find(con(2:$)-con(1:$-1)==0),:)=[] + end + // group calls to different ports of the same block. + clkconnectj=[clkconnectj(:,1),2^(clkconnectj(:,2)-ones(clkconnectj(:,2)))] + clkconnectj=int(clkconnectj) + con=clkconnectj(:,1) + clkconnectj_cons=[] + if size(con,"*")>=2 then + iini=[find(con(2:$)-con(1:$-1)<>0),size(clkconnectj,1)] + else + iini=1 + end + for ii=iini + clkconnectj_cons=[clkconnectj_cons;[clkconnectj(ii,1),.. + mysum(clkconnectj(find(clkconnectj(:,1)==clkconnectj(ii,1)),2))]] + end else - iini=1 - end - for ii=iini - clkconnectj_cons=[clkconnectj_cons;[clkconnectj(ii,1),.. - mysum(clkconnectj(find(clkconnectj(:,1)==clkconnectj(ii,1)),2))]] + clkconnectj_cons=[] end - else - clkconnectj_cons=[] - end endfunction function a=mysum(b) - if b<>[] then a=sum(b), else a=[], end + if b<>[] then a=sum(b), else a=[], end endfunction function [lnksz,lnktyp,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,xptr,zptr,.. - ozptr,typ_mod,rpptr,ipptr,opptr,xc0,xcd0,xd0,oxd0,rpar,.. - ipar,opar,typ_z,typ_x,typ_m,funs,funtyp,initexe,labels,.. - bexe,boptr,blnk,blptr,ok]=extract_info(bllst,connectmat,clkconnect,typ_l) - - ok=%t - nbl=length(bllst) - clkptr=zeros(nbl+1,1);clkptr(1)=1 - cliptr=clkptr;inpptr=cliptr;outptr=inpptr; - xptr=1;zptr=1;ozptr=1; - rpptr=clkptr;ipptr=clkptr;opptr=clkptr; - // - xc0=[];xcd0=[];xd0=[]; - oxd0=list() - rpar=[];ipar=[]; - opar=list(); - - fff=ones(nbl,1)==1 - typ_z=zeros(nbl,1);typ_x=fff;typ_m=fff;typ_mod=zeros(nbl,1); - - initexe=[]; - funs=list(); - funtyp=zeros(typ_z) - labels=[] - [ok,bllst]=adjust_inout(bllst,connectmat) - if ok then - [ok,bllst]=adjust_typ(bllst,connectmat) - end - - // placed here to make sure nzcross and nmode correctly updated - if ~ok then - lnksz=[],lnktyp=[],inplnk=[],outlnk=[],clkptr=[],cliptr=[],inpptr=[],outptr=[],.. - xptr=[],zptr=[],ozptr=[],rpptr=[],ipptr=[],opptr=[],xc0=[],.. - xcd0=[],xd0=[],oxd0=list(),rpar=[],ipar=[],opar=list(),.. - typ_z=[],typ_x=[],typ_m=[],funs=[],funtyp=[],initexe=[],.. - labels=[],bexe=[],boptr=[],blnk=[],blptr=[] - return; - end - for i=1:nbl - ll=bllst(i) - - if type(ll.sim)==15 then - funs(i)=ll.sim(1) - funtyp(i,1)=ll.sim(2) - else - funs(i)=ll.sim; - funtyp(i,1)=0; - end - if funtyp(i,1)>999&funtyp(i,1)<10000 then - if ~c_link(funs(i)) then - messagebox(msprintf(_('A C or Fortran block is used but not linked.\n'+.. - 'You can save your compiled diagram and load it.\n'+.. - 'This will automatically link the C or Fortran function.')),"modal","error") - end - end - inpnum=ll.in;outnum=ll.out;cinpnum=ll.evtin;coutnum=ll.evtout; - // - inpptr(i+1)=inpptr(i)+size(inpnum,'*') - outptr(i+1)=outptr(i)+size(outnum,'*') - cliptr(i+1)=cliptr(i)+size(cinpnum,'*') - clkptr(i+1)=clkptr(i)+size(coutnum,'*') + ozptr,typ_mod,rpptr,ipptr,opptr,xc0,xcd0,xd0,oxd0,rpar,.. + ipar,opar,typ_z,typ_x,typ_m,funs,funtyp,initexe,labels,.. + bexe,boptr,blnk,blptr,ok]=extract_info(bllst,connectmat,clkconnect,typ_l) + + ok=%t + nbl=length(bllst) + clkptr=zeros(nbl+1,1);clkptr(1)=1 + cliptr=clkptr;inpptr=cliptr;outptr=inpptr; + xptr=1;zptr=1;ozptr=1; + rpptr=clkptr;ipptr=clkptr;opptr=clkptr; // - X0=ll.state(:) - if funtyp(i,1)<10000 then - xcd0=[xcd0;0*X0] - xc0=[xc0;X0] - xptr(i+1)=xptr(i)+size(ll.state,'*') - else - xcd0=[xcd0;X0($/2+1:$)] - xc0=[xc0;X0(1:$/2)] - xptr(i+1)=xptr(i)+size(ll.state,'*')/2 - end + xc0=[];xcd0=[];xd0=[]; + oxd0=list() + rpar=[];ipar=[]; + opar=list(); + + fff=ones(nbl,1)==1 + typ_z=zeros(nbl,1);typ_x=fff;typ_m=fff;typ_mod=zeros(nbl,1); + + initexe=[]; + funs=list(); + funtyp=zeros(typ_z) + labels=[] + [ok,bllst]=adjust_inout(bllst,connectmat) + if ok then + [ok,bllst]=adjust_typ(bllst,connectmat) + end + + // placed here to make sure nzcross and nmode correctly updated + if ~ok then + lnksz=[],lnktyp=[],inplnk=[],outlnk=[],clkptr=[],cliptr=[],inpptr=[],outptr=[],.. + xptr=[],zptr=[],ozptr=[],rpptr=[],ipptr=[],opptr=[],xc0=[],.. + xcd0=[],xd0=[],oxd0=list(),rpar=[],ipar=[],opar=list(),.. + typ_z=[],typ_x=[],typ_m=[],funs=[],funtyp=[],initexe=[],.. + labels=[],bexe=[],boptr=[],blnk=[],blptr=[] + return; + end + for i=1:nbl + ll=bllst(i) + + if type(ll.sim)==15 then + funs(i)=ll.sim(1) + funtyp(i,1)=ll.sim(2) + else + funs(i)=ll.sim; + funtyp(i,1)=0; + end + if funtyp(i,1)>999&funtyp(i,1)<10000 then + if ~c_link(funs(i)) then + messagebox(msprintf(_("A C or Fortran block is used but not linked.\n"+.. + "You can save your compiled diagram and load it.\n"+.. + "This will automatically link the C or Fortran function.")),"modal","error") + end + end + inpnum=ll.in;outnum=ll.out;cinpnum=ll.evtin;coutnum=ll.evtout; + // + inpptr(i+1)=inpptr(i)+size(inpnum,"*") + outptr(i+1)=outptr(i)+size(outnum,"*") + cliptr(i+1)=cliptr(i)+size(cinpnum,"*") + clkptr(i+1)=clkptr(i)+size(coutnum,"*") + // + X0=ll.state(:) + if funtyp(i,1)<10000 then + xcd0=[xcd0;0*X0] + xc0=[xc0;X0] + xptr(i+1)=xptr(i)+size(ll.state,"*") + else + xcd0=[xcd0;X0($/2+1:$)] + xc0=[xc0;X0(1:$/2)] + xptr(i+1)=xptr(i)+size(ll.state,"*")/2 + end - //dstate - if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks - if ll.dstate==[] then xd0k=[]; else xd0k=var2vec(ll.dstate);end - else - xd0k=ll.dstate(:) - end - xd0=[xd0;xd0k] - zptr(i+1)=zptr(i)+size(xd0k,'*') + //dstate + if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks + if ll.dstate==[] then xd0k=[]; else xd0k=var2vec(ll.dstate);end + else + xd0k=ll.dstate(:) + end + xd0=[xd0;xd0k] + zptr(i+1)=zptr(i)+size(xd0k,"*") + + //odstate + if type(ll.odstate)==15 then + if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract + if lstsize(ll.odstate)>0 then + oxd0($+1)=ll.odstate + ozptr(i+1)=ozptr(i)+1; + else + ozptr(i+1)=ozptr(i); + end + elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) |... + (funtyp(i,1)==2004) | (funtyp(i,1)==12004)) //C blocks : extract + ozsz=lstsize(ll.odstate); + if ozsz>0 then + for j=1:ozsz, oxd0($+1)=ll.odstate(j), end; + ozptr(i+1)=ozptr(i)+ozsz; + else + ozptr(i+1)=ozptr(i); + end + else + ozptr(i+1)=ozptr(i); + end + else + //add an error message here please ! + ozptr(i+1)=ozptr(i); + end + + //mod + typ_mod(i)=ll.nmode; + if typ_mod(i)<0 then + messagebox(msprintf(_("Number of modes in block #%d cannot be determined."),i),"modal","error") + ok=%f + end - //odstate - if type(ll.odstate)==15 then - if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract - if lstsize(ll.odstate)>0 then - oxd0($+1)=ll.odstate - ozptr(i+1)=ozptr(i)+1; + //real paramaters + if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks + if ll.rpar==[] then rpark=[]; else rpark=var2vec(ll.rpar);end else - ozptr(i+1)=ozptr(i); - end - elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) |... - (funtyp(i,1)==2004) | (funtyp(i,1)==12004)) //C blocks : extract - ozsz=lstsize(ll.odstate); - if ozsz>0 then - for j=1:ozsz, oxd0($+1)=ll.odstate(j), end; - ozptr(i+1)=ozptr(i)+ozsz; + rpark=ll.rpar(:) + end + rpar=[rpar;rpark] + rpptr(i+1)=rpptr(i)+size(rpark,"*") + + //integer parameters + if type(ll.ipar)==1 then + ipar=[ipar;ll.ipar(:)] + ipptr(i+1)=ipptr(i)+size(ll.ipar,"*") else - ozptr(i+1)=ozptr(i); + ipptr(i+1)=ipptr(i) end - else - ozptr(i+1)=ozptr(i); - end - else - //add an error message here please ! - ozptr(i+1)=ozptr(i); - end - //mod - typ_mod(i)=ll.nmode; - if typ_mod(i)<0 then - messagebox(msprintf(_('Number of modes in block #%d cannot be determined.'),i),"modal","error") - ok=%f - end + //object parameters + if type(ll.opar)==15 then + if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract + if lstsize(ll.opar)>0 then + opar($+1)=ll.opar + opptr(i+1)=opptr(i)+1; + else + opptr(i+1)=opptr(i); + end + elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) |... + (funtyp(i,1)==2004) | (funtyp(i,1)==12004)) then //C blocks : extract + oparsz=lstsize(ll.opar); + if oparsz>0 then + for j=1:oparsz, opar($+1)=ll.opar(j), end; + opptr(i+1)=opptr(i)+oparsz; + else + opptr(i+1)=opptr(i); + end + else + opptr(i+1)=opptr(i); + end + else + //add an error message here please ! + opptr(i+1)=opptr(i); + end - //real paramaters - if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks - if ll.rpar==[] then rpark=[]; else rpark=var2vec(ll.rpar);end - else - rpark=ll.rpar(:) - end - rpar=[rpar;rpark] - rpptr(i+1)=rpptr(i)+size(rpark,'*') + // typ_z(i)=ll.blocktype=='z' + typ_z(i)=ll.nzcross + if typ_z(i)<0 then + messagebox(msprintf(_("Number of zero crossings in block #i cannot be determined."),i),"modal","error") + ok=%f + end + typ_x(i)=ll.state<>[]|ll.blocktype=="x" // some blocks like delay + // need to be in oord even + // without state + + typ_m(i)=ll.blocktype=="m" + // + if ll.evtout<>[] then + ll11=ll.firing + prt=find(ll11>=zeros(ll11)) + nprt=prod(size(prt)) + initexe=[initexe;[i*ones(nprt,1),matrix(prt,nprt,1),matrix(ll11(prt),nprt,1)]]; + end - //integer parameters - if type(ll.ipar)==1 then - ipar=[ipar;ll.ipar(:)] - ipptr(i+1)=ipptr(i)+size(ll.ipar,'*') - else - ipptr(i+1)=ipptr(i) + if type(ll.label)==10 then + labels=[labels;ll.label(1)] + else + labels=[labels;" "] + end end - //object parameters - if type(ll.opar)==15 then - if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract - if lstsize(ll.opar)>0 then - opar($+1)=ll.opar - opptr(i+1)=opptr(i)+1; - else - opptr(i+1)=opptr(i); - end - elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) |... - (funtyp(i,1)==2004) | (funtyp(i,1)==12004)) then //C blocks : extract - oparsz=lstsize(ll.opar); - if oparsz>0 then - for j=1:oparsz, opar($+1)=ll.opar(j), end; - opptr(i+1)=opptr(i)+oparsz; - else - opptr(i+1)=opptr(i); - end - else - opptr(i+1)=opptr(i); - end - else - //add an error message here please ! - opptr(i+1)=opptr(i); + clkconnect=clkconnect(find(clkconnect(:,1)<>0),:); + + con=clkptr(clkconnect(:,1))+clkconnect(:,2)-1; + [junk,ind]=gsort(-con);con=-junk; + clkconnect=clkconnect(ind,:); + // + bclkconnect=clkconnect(:,[1 3]); + boptr=1; + bexe=[]; + for i=1:nbl + r=bclkconnect(find(bclkconnect(:,1)==i),2); + bexe=[bexe;r]; + boptr=[boptr;boptr($)+size(r,1)]; end + // - // typ_z(i)=ll.blocktype=='z' - typ_z(i)=ll.nzcross - if typ_z(i)<0 then - messagebox(msprintf(_('Number of zero crossings in block #i cannot be determined.'),i),"modal","error") - ok=%f + blptr=1; + blnk=[]; + + for i=1:nbl + r=connectmat(find(connectmat(:,1)==i),3:4); + blnk=[blnk;r]; + blptr=[blptr;blptr($)+size(r,1)]; end - typ_x(i)=ll.state<>[]|ll.blocktype=='x' // some blocks like delay - // need to be in oord even - // without state - - typ_m(i)=ll.blocktype=='m' // - if ll.evtout<>[] then - ll11=ll.firing - prt=find(ll11>=zeros(ll11)) - nprt=prod(size(prt)) - initexe=[initexe;[i*ones(nprt,1),matrix(prt,nprt,1),matrix(ll11(prt),nprt,1)]]; + + nlnk=size(connectmat,1) + inplnk=zeros(inpptr($)-1,1);outlnk=zeros(outptr($)-1,1);ptlnk=1; + lnksz=[];lnktyp=[]; + for jj=1:nlnk + ko=outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1) + ki=inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1) + if ko<>0 & ki<>0 then + if ko>ki then + outlnk(outlnk>ko)=outlnk(outlnk>ko)-1 + outlnk(outlnk==ko)=ki + inplnk(inplnk>ko)=inplnk(inplnk>ko)-1 + inplnk(inplnk==ko)=ki + ptlnk=-1+ptlnk + lnksz(ko,1)=[]; + lnksz(ko,2)=[]; + lnktyp(ko) =[]; + elseif ki>ko + outlnk(outlnk>ki)=outlnk(outlnk>ki)-1 + outlnk(outlnk==ki)=ko + inplnk(inplnk>ki)=inplnk(inplnk>ki)-1 + inplnk(inplnk==ki)=ko + ptlnk=-1+ptlnk + lnksz(ki,1)=[]; + lnksz(ki,2)=[]; + lnktyp(ki) =[]; + end + elseif ko<>0 then + inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ko + elseif ki<>0 then + outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ki + else + outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ptlnk + inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ptlnk + lnksz(ptlnk,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)); + lnksz(ptlnk,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)); + lnktyp(ptlnk)=bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)); + ptlnk=1+ptlnk + end end - if type(ll.label)==10 then - labels=[labels;ll.label(1)] - else - labels=[labels;' '] - end - end - - clkconnect=clkconnect(find(clkconnect(:,1)<>0),:); - - con=clkptr(clkconnect(:,1))+clkconnect(:,2)-1; - [junk,ind]=gsort(-con);con=-junk; - clkconnect=clkconnect(ind,:); - // - bclkconnect=clkconnect(:,[1 3]); - boptr=1; - bexe=[]; - for i=1:nbl - r=bclkconnect(find(bclkconnect(:,1)==i),2); - bexe=[bexe;r]; - boptr=[boptr;boptr($)+size(r,1)]; - end - // - - blptr=1; - blnk=[]; - - for i=1:nbl - r=connectmat(find(connectmat(:,1)==i),3:4); - blnk=[blnk;r]; - blptr=[blptr;blptr($)+size(r,1)]; - end - // - - nlnk=size(connectmat,1) - inplnk=zeros(inpptr($)-1,1);outlnk=zeros(outptr($)-1,1);ptlnk=1; - lnksz=[];lnktyp=[]; - for jj=1:nlnk - ko=outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1) - ki=inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1) - if ko<>0 & ki<>0 then - if ko>ki then - outlnk(outlnk>ko)=outlnk(outlnk>ko)-1 - outlnk(outlnk==ko)=ki - inplnk(inplnk>ko)=inplnk(inplnk>ko)-1 - inplnk(inplnk==ko)=ki - ptlnk=-1+ptlnk - lnksz(ko,1)=[]; - lnksz(ko,2)=[]; - lnktyp(ko) =[]; - elseif ki>ko - outlnk(outlnk>ki)=outlnk(outlnk>ki)-1 - outlnk(outlnk==ki)=ko - inplnk(inplnk>ki)=inplnk(inplnk>ki)-1 - inplnk(inplnk==ki)=ko - ptlnk=-1+ptlnk - lnksz(ki,1)=[]; - lnksz(ki,2)=[]; - lnktyp(ki) =[]; - end - elseif ko<>0 then - inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ko - elseif ki<>0 then - outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ki - else - outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ptlnk - inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ptlnk - lnksz(ptlnk,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)); - lnksz(ptlnk,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)); - lnktyp(ptlnk)=bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)); - ptlnk=1+ptlnk - end - end - - //store unconnected outputs, if any, at the end of outtb - unco=find(outlnk==0); - for j=unco - m=max(find(outptr<=j)) - n=j-outptr(m)+1 - nm=bllst(m).out(n) - if nm<1 then - under_connection(corinv(m),n,nm,-1,0,0,1),ok=%f,return, - end - nm2=bllst(m).out2(n) - if nm2<1 then - under_connection(corinv(m),n,nm2,-1,0,0,1),ok=%f,return, - end - lnksz($+1,1)=bllst(m).out(n); - lnksz($,2)=bllst(m).out2(n); - lnktyp($+1)=bllst(m).outtyp(n); - outlnk(j)=max(outlnk)+1 - end - - //store unconnected inputs, if any, at the end of outtb - unco=find(inplnk==0); - for j=unco - m=max(find(inpptr<=j)) - n=j-inpptr(m)+1 - nm=bllst(m).in(n) - if nm<1 then - under_connection(corinv(m),n,nm,-2,0,0,1),ok=%f,return, - end - nm2=bllst(m).in2(n) - if nm2<1 then - under_connection(corinv(m),n,nm2,-2,0,0,1),ok=%f,return, - end - lnksz($+1,1)=bllst(m).in(n); - lnksz($,2)=bllst(m).in2(n); - lnktyp($+1)=bllst(m).intyp(n); - inplnk(j)=max([inplnk;max(outlnk)])+1 - end + //store unconnected outputs, if any, at the end of outtb + unco=find(outlnk==0); + for j=unco + m=max(find(outptr<=j)) + n=j-outptr(m)+1 + nm=bllst(m).out(n) + if nm<1 then + under_connection(corinv(m),n,nm,-1,0,0,1),ok=%f,return, + end + nm2=bllst(m).out2(n) + if nm2<1 then + under_connection(corinv(m),n,nm2,-1,0,0,1),ok=%f,return, + end + lnksz($+1,1)=bllst(m).out(n); + lnksz($,2)=bllst(m).out2(n); + lnktyp($+1)=bllst(m).outtyp(n); + outlnk(j)=max(outlnk)+1 + end + + //store unconnected inputs, if any, at the end of outtb + unco=find(inplnk==0); + for j=unco + m=max(find(inpptr<=j)) + n=j-inpptr(m)+1 + nm=bllst(m).in(n) + if nm<1 then + under_connection(corinv(m),n,nm,-2,0,0,1),ok=%f,return, + end + nm2=bllst(m).in2(n) + if nm2<1 then + under_connection(corinv(m),n,nm2,-2,0,0,1),ok=%f,return, + end + lnksz($+1,1)=bllst(m).in(n); + lnksz($,2)=bllst(m).in2(n); + lnktyp($+1)=bllst(m).intyp(n); + inplnk(j)=max([inplnk;max(outlnk)])+1 + end endfunction function [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk) - outoin=[];outoinptr=1 - nblk=size(inpptr,1)-1 - for i=1:nblk - k=outptr(i):outptr(i+1)-1 - ii=[] - for j=outlnk(k)' - ii=[ii,find(inplnk==j)] - end - outoini=[];jj=0 - for j=ii - m=max(find(inpptr<=j)) - n=j-inpptr(m)+1 - outoini=[outoini;[m,n]] - jj=jj+1 - end - outoinptr=[outoinptr;outoinptr($)+jj] - outoin=[outoin;outoini] - end + outoin=[];outoinptr=1 + nblk=size(inpptr,1)-1 + for i=1:nblk + k=outptr(i):outptr(i+1)-1 + ii=[] + for j=outlnk(k)' + ii=[ii,find(inplnk==j)] + end + outoini=[];jj=0 + for j=ii + m=max(find(inpptr<=j)) + n=j-inpptr(m)+1 + outoini=[outoini;[m,n]] + jj=jj+1 + end + outoinptr=[outoinptr;outoinptr($)+jj] + outoin=[outoin;outoini] + end endfunction function [ord,ok]=tree2(vec,outoin,outoinptr,dep_ut) -//compute blocks execution tree - ok=%t; + //compute blocks execution tree + ok=%t; + + nb=size(vec,"*"); + for j=1:nb+2 + fini=%t + for i=1:nb + if vec(i)==j-1 then + if j==nb+2 then + disp(mprintf("%s: tree (2) failed", "c_pass2")); + messagebox(_("Algebraic loop."),"modal","error");ok=%f;ord=[];return; + end + for k=outoinptr(i):outoinptr(i+1)-1 + ii=outoin(k,1); + //indport=find(dep_u(dep_uptr(ii):dep_uptr(ii+1)-1)==1); + //if (indport ~=[] &vec(ii)>-1) then + if (dep_ut(ii) &vec(ii)>-1) then + fini=%f; + vec(ii)=j; + end + end + end + end + if fini then break;end + end - nb=size(vec,'*'); - for j=1:nb+2 - fini=%t - for i=1:nb - if vec(i)==j-1 then - if j==nb+2 then - disp(mprintf("%s: tree (2) failed", "c_pass2")); - messagebox(_('Algebraic loop.'),"modal","error");ok=%f;ord=[];return; - end - for k=outoinptr(i):outoinptr(i+1)-1 - ii=outoin(k,1); - //indport=find(dep_u(dep_uptr(ii):dep_uptr(ii+1)-1)==1); - //if (indport ~=[] &vec(ii)>-1) then - if (dep_ut(ii) &vec(ii)>-1) then - fini=%f; - vec(ii)=j; - end - end - end - end - if fini then break;end - end - - [k,ord]=gsort(-vec); - ord(find(k==1))=[]; - ord=ord(:) + [k,ord]=gsort(-vec); + ord(find(k==1))=[]; + ord=ord(:) endfunction //adjust_inout : it resolves positive, negative and null size // of in/out port dimensions of connected block. -// If it's not done in a first pass, the second -// pass try to resolve negative or null port -// dimensions by asking user to informed dimensions +// If it's not done in a first pass, the second +// pass try to resolve negative or null port +// dimensions by asking user to informed dimensions // with underconnection function. // It is a fixed point algorithm. // @@ -1543,496 +1543,496 @@ endfunction function [ok,bllst]=adjust_inout(bllst,connectmat) - //Adjust in2/out2, inttyp/outtyp - //in accordance to in/out in bllst - [ko,bllst]=adjust_in2out2(bllst); - if ~ko then ok=%f,return, end //if adjust_in2out2 failed then exit - //adjust_inout with flag ok=%f - - nlnk=size(connectmat,1) //nlnk is the number of link - - //loop on number of block (pass 1 and pass 2) - for hhjj=1:length(bllst)+1 - //%%%%% pass 1 %%%%%// - for hh=1:length(bllst)+1 //second loop on number of block - ok=%t - for jj=1:nlnk //loop on number of link - - //intyp/outtyp are the type of the - //target port and the source port of the observed link - outtyp = bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) - intyp = bllst(connectmat(jj,3)).intyp(connectmat(jj,4)) - //nnin/nnout are the size (two dimensions) of the - //target port and the source port of the observed link - //before adjust - nnout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) - nnout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) - nnin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) - nnin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) - - //This Part is done in adjust_typ - - //check intyp/outtyp -// if intyp<>outtyp then -// if (intyp==1 & outtyp==2) then -// bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=2; -// elseif (intyp==2 & outtyp==1) then -// bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))=2; -// else -// if bllst(connectmat(jj,3)).sim(2)<0 //if-then-else/eselect case -// bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=... -// bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) -// else -// bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),.. -// nnout,outtyp,.. -// corinv(connectmat(jj,3)),connectmat(jj,4),.. -// nnin,intyp,1) -// ok=%f; -// return -// end -// end -// end - - //loop on the two dimensions of source/target port - for ndim=1:2 - //check test source/target sizes - //in case of negatif equal target dimensions - //nin/nout are the size (two dimensions) of the - //target port and the source port of the observed link - nout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) - nout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) - nin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) - nin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) - - //first case : dimension of source and - // target ports are explicitly informed - // informed with positive size - if(nout(1,ndim)>0&nin(1,ndim)>0) then - //if dimension of source and target port doesn't match - //then call bad_connection, set flag ok to false and exit - if nin(1,ndim)<>nout(1,ndim) then - bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),.. - nnout,outtyp,.. - corinv(connectmat(jj,3)),connectmat(jj,4),.. - nnin,intyp) - ok=%f;return - end - - //second case : dimension of source port is - // positive and dimension of - // target port is negative - elseif(nout(1,ndim)>0&nin(1,ndim)<0) then - //find vector of input ports of target block with - //first/second dimension equal to size nin(1,ndim) - //and assign it to nout(1,ndim) - ww=find(bllst(connectmat(jj,3)).in==nin(1,ndim)) - bllst(connectmat(jj,3)).in(ww)=nout(1,ndim) - ww=find(bllst(connectmat(jj,3)).in2==nin(1,ndim)) - bllst(connectmat(jj,3)).in2(ww)=nout(1,ndim) - - //find vector of output ports of target block with - //first/second dimension equal to size nin(1,ndim) - //and assign it to nout(1,ndim) - ww=find(bllst(connectmat(jj,3)).out==nin(1,ndim)) - bllst(connectmat(jj,3)).out(ww)=nout(1,ndim) - ww=find(bllst(connectmat(jj,3)).out2==nin(1,ndim)) - bllst(connectmat(jj,3)).out2(ww)=nout(1,ndim) - - //find vector of output ports of target block with - //ndim dimension equal to zero and sum the ndim - //dimension of all input ports of target block - //to be the new dimension of the ndim dimension - //of the output ports of the target block - if ndim==1 then - ww=find(bllst(connectmat(jj,3)).out==0) - if (ww<>[]&min(bllst(connectmat(jj,3)).in(:))>0) then - bllst(connectmat(jj,3)).out(ww)=sum(bllst(connectmat(jj,3)).in(:)) - end - elseif ndim==2 then - ww=find(bllst(connectmat(jj,3)).out2==0) - if (ww<>[]&min(bllst(connectmat(jj,3)).in2(:))>0) then - bllst(connectmat(jj,3)).out2(ww)=sum(bllst(connectmat(jj,3)).in2(:)) - end - end - - //if nzcross of the target block match with - //the negative dimension nin(1,ndim) then - //adjust it to nout(1,ndim) - if bllst(connectmat(jj,3)).nzcross==nin(1,ndim) then - bllst(connectmat(jj,3)).nzcross=nout(1,ndim) - end - //if nmode of the target block match with - //the negative dimension nin(1,ndim) then - //adjust it to nout(1,ndim) - if bllst(connectmat(jj,3)).nmode==nin(1,ndim) then - bllst(connectmat(jj,3)).nmode=nout(1,ndim) - end - - //third case : dimension of source port is - // negative and dimension of - // target port is positive - elseif(nout(1,ndim)<0&nin(1,ndim)>0) then - //find vector of output ports of source block with - //first/second dimension equal to size nout(1,ndim) - //and assign it to nin(1,ndim) - ww=find(bllst(connectmat(jj,1)).out==nout(1,ndim)) - bllst(connectmat(jj,1)).out(ww)=nin(1,ndim) - ww=find(bllst(connectmat(jj,1)).out2==nout(1,ndim)) - bllst(connectmat(jj,1)).out2(ww)=nin(1,ndim) - - //find vector of input ports of source block with - //first/second dimension equal to size nout(1,ndim) - //and assign it to nin(1,ndim) - ww=find(bllst(connectmat(jj,1)).in==nout(1,ndim)) - bllst(connectmat(jj,1)).in(ww)=nin(1,ndim) - ww=find(bllst(connectmat(jj,1)).in2==nout(1,ndim)) - bllst(connectmat(jj,1)).in2(ww)=nin(1,ndim) - - //find vector of input ports of source block with - //ndim dimension equal to zero and sum the ndim - //dimension of all output ports of source block - //to be the new dimension of the ndim dimension - //of the input ports of the source block - if ndim==1 then - ww=find(bllst(connectmat(jj,1)).in==0) - if (ww<>[]&min(bllst(connectmat(jj,1)).out(:))>0) then - bllst(connectmat(jj,1)).in(ww)=sum(bllst(connectmat(jj,1)).out(:)) - end - elseif ndim==2 then - ww=find(bllst(connectmat(jj,1)).in2==0) - if (ww<>[]&min(bllst(connectmat(jj,1)).out2(:))>0) then - bllst(connectmat(jj,1)).in2(ww)=sum(bllst(connectmat(jj,1)).out2(:)) - end - end - - //if nzcross of the source block match with - //the negative dimension nout(1,ndim) then - //adjust it to nin(1,ndim) - if bllst(connectmat(jj,1)).nzcross==nout(1,ndim) then - bllst(connectmat(jj,1)).nzcross=nin(1,ndim) - end - //if nmode of the source block match with - //the negative dimension nout(1,ndim) then - //adjust it to nin(1,ndim) - if bllst(connectmat(jj,1)).nmode==nout(1,ndim) then - bllst(connectmat(jj,1)).nmode=nin(1,ndim) - end - - //fourth case : a dimension of source port is - // null - elseif(nout(1,ndim)==0) then - //set ww to be the vector of size of the ndim - //dimension of input port of the source block - if ndim==1 then - ww=bllst(connectmat(jj,1)).in(:) - elseif ndim==2 then - ww=bllst(connectmat(jj,1)).in2(:) - end - - //test if all size of the ndim dimension of input - //port of the source block is positive - if min(ww)>0 then - //test if the dimension of the target port - //is positive - if nin(1,ndim)>0 then - - //if the sum of the size of the ndim dimension of the input - //port of the source block is equal to the size of the ndim dimension - //of the target port, then the size of the ndim dimension of the source - //port is equal to nin(1,ndim) - if sum(ww)==nin(1,ndim) then - if ndim==1 then - bllst(connectmat(jj,1)).out(connectmat(jj,2))=nin(1,ndim) - elseif ndim==2 then - bllst(connectmat(jj,1)).out2(connectmat(jj,2))=nin(1,ndim) - end - //else call bad_connection, set flag ok to false and exit - else - bad_connection(corinv(connectmat(jj,1)),0,0,1,-1,0,0,1) - ok=%f;return - end - - //if the ndim dimension of the target port is negative - //then the size of the ndim dimension of the source port - //is equal to the sum of the size of the ndim dimension - //of input ports of source block, and flag ok is set to false + //Adjust in2/out2, inttyp/outtyp + //in accordance to in/out in bllst + [ko,bllst]=adjust_in2out2(bllst); + if ~ko then ok=%f,return, end //if adjust_in2out2 failed then exit + //adjust_inout with flag ok=%f + + nlnk=size(connectmat,1) //nlnk is the number of link + + //loop on number of block (pass 1 and pass 2) + for hhjj=1:length(bllst)+1 + //%%%%% pass 1 %%%%%// + for hh=1:length(bllst)+1 //second loop on number of block + ok=%t + for jj=1:nlnk //loop on number of link + + //intyp/outtyp are the type of the + //target port and the source port of the observed link + outtyp = bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) + intyp = bllst(connectmat(jj,3)).intyp(connectmat(jj,4)) + //nnin/nnout are the size (two dimensions) of the + //target port and the source port of the observed link + //before adjust + nnout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) + nnout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) + nnin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) + nnin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) + + //This Part is done in adjust_typ + + //check intyp/outtyp + // if intyp<>outtyp then + // if (intyp==1 & outtyp==2) then + // bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=2; + // elseif (intyp==2 & outtyp==1) then + // bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))=2; + // else + // if bllst(connectmat(jj,3)).sim(2)<0 //if-then-else/eselect case + // bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=... + // bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) + // else + // bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),.. + // nnout,outtyp,.. + // corinv(connectmat(jj,3)),connectmat(jj,4),.. + // nnin,intyp,1) + // ok=%f; + // return + // end + // end + // end + + //loop on the two dimensions of source/target port + for ndim=1:2 + //check test source/target sizes + //in case of negatif equal target dimensions + //nin/nout are the size (two dimensions) of the + //target port and the source port of the observed link + nout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) + nout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) + nin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) + nin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) + + //first case : dimension of source and + // target ports are explicitly informed + // informed with positive size + if(nout(1,ndim)>0&nin(1,ndim)>0) then + //if dimension of source and target port doesn't match + //then call bad_connection, set flag ok to false and exit + if nin(1,ndim)<>nout(1,ndim) then + bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),.. + nnout,outtyp,.. + corinv(connectmat(jj,3)),connectmat(jj,4),.. + nnin,intyp) + ok=%f;return + end + + //second case : dimension of source port is + // positive and dimension of + // target port is negative + elseif(nout(1,ndim)>0&nin(1,ndim)<0) then + //find vector of input ports of target block with + //first/second dimension equal to size nin(1,ndim) + //and assign it to nout(1,ndim) + ww=find(bllst(connectmat(jj,3)).in==nin(1,ndim)) + bllst(connectmat(jj,3)).in(ww)=nout(1,ndim) + ww=find(bllst(connectmat(jj,3)).in2==nin(1,ndim)) + bllst(connectmat(jj,3)).in2(ww)=nout(1,ndim) + + //find vector of output ports of target block with + //first/second dimension equal to size nin(1,ndim) + //and assign it to nout(1,ndim) + ww=find(bllst(connectmat(jj,3)).out==nin(1,ndim)) + bllst(connectmat(jj,3)).out(ww)=nout(1,ndim) + ww=find(bllst(connectmat(jj,3)).out2==nin(1,ndim)) + bllst(connectmat(jj,3)).out2(ww)=nout(1,ndim) + + //find vector of output ports of target block with + //ndim dimension equal to zero and sum the ndim + //dimension of all input ports of target block + //to be the new dimension of the ndim dimension + //of the output ports of the target block + if ndim==1 then + ww=find(bllst(connectmat(jj,3)).out==0) + if (ww<>[]&min(bllst(connectmat(jj,3)).in(:))>0) then + bllst(connectmat(jj,3)).out(ww)=sum(bllst(connectmat(jj,3)).in(:)) + end + elseif ndim==2 then + ww=find(bllst(connectmat(jj,3)).out2==0) + if (ww<>[]&min(bllst(connectmat(jj,3)).in2(:))>0) then + bllst(connectmat(jj,3)).out2(ww)=sum(bllst(connectmat(jj,3)).in2(:)) + end + end + + //if nzcross of the target block match with + //the negative dimension nin(1,ndim) then + //adjust it to nout(1,ndim) + if bllst(connectmat(jj,3)).nzcross==nin(1,ndim) then + bllst(connectmat(jj,3)).nzcross=nout(1,ndim) + end + //if nmode of the target block match with + //the negative dimension nin(1,ndim) then + //adjust it to nout(1,ndim) + if bllst(connectmat(jj,3)).nmode==nin(1,ndim) then + bllst(connectmat(jj,3)).nmode=nout(1,ndim) + end + + //third case : dimension of source port is + // negative and dimension of + // target port is positive + elseif(nout(1,ndim)<0&nin(1,ndim)>0) then + //find vector of output ports of source block with + //first/second dimension equal to size nout(1,ndim) + //and assign it to nin(1,ndim) + ww=find(bllst(connectmat(jj,1)).out==nout(1,ndim)) + bllst(connectmat(jj,1)).out(ww)=nin(1,ndim) + ww=find(bllst(connectmat(jj,1)).out2==nout(1,ndim)) + bllst(connectmat(jj,1)).out2(ww)=nin(1,ndim) + + //find vector of input ports of source block with + //first/second dimension equal to size nout(1,ndim) + //and assign it to nin(1,ndim) + ww=find(bllst(connectmat(jj,1)).in==nout(1,ndim)) + bllst(connectmat(jj,1)).in(ww)=nin(1,ndim) + ww=find(bllst(connectmat(jj,1)).in2==nout(1,ndim)) + bllst(connectmat(jj,1)).in2(ww)=nin(1,ndim) + + //find vector of input ports of source block with + //ndim dimension equal to zero and sum the ndim + //dimension of all output ports of source block + //to be the new dimension of the ndim dimension + //of the input ports of the source block + if ndim==1 then + ww=find(bllst(connectmat(jj,1)).in==0) + if (ww<>[]&min(bllst(connectmat(jj,1)).out(:))>0) then + bllst(connectmat(jj,1)).in(ww)=sum(bllst(connectmat(jj,1)).out(:)) + end + elseif ndim==2 then + ww=find(bllst(connectmat(jj,1)).in2==0) + if (ww<>[]&min(bllst(connectmat(jj,1)).out2(:))>0) then + bllst(connectmat(jj,1)).in2(ww)=sum(bllst(connectmat(jj,1)).out2(:)) + end + end + + //if nzcross of the source block match with + //the negative dimension nout(1,ndim) then + //adjust it to nin(1,ndim) + if bllst(connectmat(jj,1)).nzcross==nout(1,ndim) then + bllst(connectmat(jj,1)).nzcross=nin(1,ndim) + end + //if nmode of the source block match with + //the negative dimension nout(1,ndim) then + //adjust it to nin(1,ndim) + if bllst(connectmat(jj,1)).nmode==nout(1,ndim) then + bllst(connectmat(jj,1)).nmode=nin(1,ndim) + end + + //fourth case : a dimension of source port is + // null + elseif(nout(1,ndim)==0) then + //set ww to be the vector of size of the ndim + //dimension of input port of the source block + if ndim==1 then + ww=bllst(connectmat(jj,1)).in(:) + elseif ndim==2 then + ww=bllst(connectmat(jj,1)).in2(:) + end + + //test if all size of the ndim dimension of input + //port of the source block is positive + if min(ww)>0 then + //test if the dimension of the target port + //is positive + if nin(1,ndim)>0 then + + //if the sum of the size of the ndim dimension of the input + //port of the source block is equal to the size of the ndim dimension + //of the target port, then the size of the ndim dimension of the source + //port is equal to nin(1,ndim) + if sum(ww)==nin(1,ndim) then + if ndim==1 then + bllst(connectmat(jj,1)).out(connectmat(jj,2))=nin(1,ndim) + elseif ndim==2 then + bllst(connectmat(jj,1)).out2(connectmat(jj,2))=nin(1,ndim) + end + //else call bad_connection, set flag ok to false and exit + else + bad_connection(corinv(connectmat(jj,1)),0,0,1,-1,0,0,1) + ok=%f;return + end + + //if the ndim dimension of the target port is negative + //then the size of the ndim dimension of the source port + //is equal to the sum of the size of the ndim dimension + //of input ports of source block, and flag ok is set to false + else + if ndim==1 then + bllst(connectmat(jj,1)).out(connectmat(jj,2))=sum(ww) + elseif ndim==2 then + bllst(connectmat(jj,1)).out2(connectmat(jj,2))=sum(ww) + end + ok=%f + end + + else + //set nww to be the vector of all negative size of input ports + //of the source block + nww=ww(find(ww<0)) + + //if all negative size have same size and if size of the + //ndim dimension of the target port is positive then assign + //size of the ndim dimension of the source port to nin(1,ndim) + if norm(nww-nww(1),1)==0 & nin(1,ndim)>0 then + if ndim==1 then + bllst(connectmat(jj,1)).out(connectmat(jj,2))=nin(1,ndim) + elseif ndim==2 then + bllst(connectmat(jj,1)).out2(connectmat(jj,2))=nin(1,ndim) + end + + //compute a size to be the difference between the size + //of the ndim dimension of the target block and sum of positive + //size of input ports of the source block divided by the number + //of input ports of source block with same negative size + k=(nin(1,ndim)-sum(ww(find(ww>0))))/size(nww,"*") + + //if this size is a positive integer then assign it + //to the size of the ndim dimension of input ports of the + //source block which have negative size + if k==int(k)&k>0 then + if ndim==1 then + bllst(connectmat(jj,1)).in(find(ww<0))=k + elseif ndim==2 then + bllst(connectmat(jj,1)).in2(find(ww<0))=k + end + //else call bad_connection, set flag ok to false and exit + else + bad_connection(corinv(connectmat(jj,1)),0,0,1,-1,0,0,1) + ok=%f;return + end + + //set flag ok to false + else + ok=%f + end + + end + + //fifth case : a dimension of target port is + // null + elseif(nin(1,ndim)==0) then + //set ww to be the vector of size of the ndim + //dimension of output port of the target block + if ndim==1 then + ww=bllst(connectmat(jj,3)).out(:) + elseif ndim==2 then + ww=bllst(connectmat(jj,3)).out2(:) + end + + //test if all size of the ndim dimension of output + //port of the target block is positive + if min(ww)>0 then + //test if the dimension of the source port + //is positive + if nout(1,ndim)>0 then + + //if the sum of the size of the ndim dimension of the output + //port of the target block is equal to the size of the ndim dimension + //of the source port, then the size of the ndim dimension of the target + //port is equal to nout(1,ndim) + if sum(ww)==nout(1,ndim) then + if ndim==1 then + bllst(connectmat(jj,3)).in(connectmat(jj,4))=nout(1,ndim) + elseif ndim==2 then + bllst(connectmat(jj,3)).in2(connectmat(jj,4))=nout(1,ndim) + end + //else call bad_connection, set flag ok to false and exit + else + bad_connection(corinv(connectmat(jj,3)),0,0,1,-1,0,0,1) + ok=%f;return + end + + //if the ndim dimension of the source port is negative + //then the size of the ndim dimension of the target port + //is equal to the sum of the size of the ndim dimension + //of output ports of target block, and flag ok is set to false + else + if ndim==1 then + bllst(connectmat(jj,3)).in(connectmat(jj,4))=sum(ww) + elseif ndim==2 then + bllst(connectmat(jj,3)).in2(connectmat(jj,4))=sum(ww) + end + ok=%f + end + + else + //set nww to be the vector of all negative size of output ports + //of the target block + nww=ww(find(ww<0)) + + //if all negative size have same size and if size of the + //ndim dimension of the source port is positive then assign + //size of the ndim dimension of the target port to nout(1,ndim) + if norm(nww-nww(1),1)==0 & nout(1,ndim)>0 then + if ndim==1 then + bllst(connectmat(jj,3)).in(connectmat(jj,4))=nout(1,ndim) + elseif ndim==2 then + bllst(connectmat(jj,3)).in2(connectmat(jj,4))=nout(1,ndim) + end + + //compute a size to be the difference between the size + //of the ndim dimension of the source block and sum of positive + //size of output ports of the target block divided by the number + //of output ports of target block with same negative size + k=(nout(1,ndim)-sum(ww(find(ww>0))))/size(nww,"*") + + //if this size is a positive integer then assign it + //to the size of the ndim dimension of output ports of the + //target block which have negative size + if k==int(k)&k>0 then + if ndim==1 then + bllst(connectmat(jj,3)).out(find(ww<0))=k + elseif ndim==2 then + bllst(connectmat(jj,3)).out2(find(ww<0))=k + end + //else call bad_connection, set flag ok to false and exit + else + bad_connection(corinv(connectmat(jj,3)),0,0,1,-1,0,0,1) + ok=%f;return + end + + //set flag ok to false + else + ok=%f + end + + end + + //sixth (& last) case : dimension of both source + // and target port are negatives else - if ndim==1 then - bllst(connectmat(jj,1)).out(connectmat(jj,2))=sum(ww) - elseif ndim==2 then - bllst(connectmat(jj,1)).out2(connectmat(jj,2))=sum(ww) - end - ok=%f + ok=%f //set flag ok to false end - - else - //set nww to be the vector of all negative size of input ports - //of the source block - nww=ww(find(ww<0)) - - //if all negative size have same size and if size of the - //ndim dimension of the target port is positive then assign - //size of the ndim dimension of the source port to nin(1,ndim) - if norm(nww-nww(1),1)==0 & nin(1,ndim)>0 then - if ndim==1 then - bllst(connectmat(jj,1)).out(connectmat(jj,2))=nin(1,ndim) - elseif ndim==2 then - bllst(connectmat(jj,1)).out2(connectmat(jj,2))=nin(1,ndim) - end - - //compute a size to be the difference between the size - //of the ndim dimension of the target block and sum of positive - //size of input ports of the source block divided by the number - //of input ports of source block with same negative size - k=(nin(1,ndim)-sum(ww(find(ww>0))))/size(nww,'*') - - //if this size is a positive integer then assign it - //to the size of the ndim dimension of input ports of the - //source block which have negative size - if k==int(k)&k>0 then - if ndim==1 then - bllst(connectmat(jj,1)).in(find(ww<0))=k - elseif ndim==2 then - bllst(connectmat(jj,1)).in2(find(ww<0))=k - end - //else call bad_connection, set flag ok to false and exit - else - bad_connection(corinv(connectmat(jj,1)),0,0,1,-1,0,0,1) - ok=%f;return - end - - //set flag ok to false - else - ok=%f - end - - end - - //fifth case : a dimension of target port is - // null - elseif(nin(1,ndim)==0) then - //set ww to be the vector of size of the ndim - //dimension of output port of the target block - if ndim==1 then - ww=bllst(connectmat(jj,3)).out(:) - elseif ndim==2 then - ww=bllst(connectmat(jj,3)).out2(:) - end - - //test if all size of the ndim dimension of output - //port of the target block is positive - if min(ww)>0 then - //test if the dimension of the source port - //is positive - if nout(1,ndim)>0 then - - //if the sum of the size of the ndim dimension of the output - //port of the target block is equal to the size of the ndim dimension - //of the source port, then the size of the ndim dimension of the target - //port is equal to nout(1,ndim) - if sum(ww)==nout(1,ndim) then - if ndim==1 then - bllst(connectmat(jj,3)).in(connectmat(jj,4))=nout(1,ndim) - elseif ndim==2 then - bllst(connectmat(jj,3)).in2(connectmat(jj,4))=nout(1,ndim) - end - //else call bad_connection, set flag ok to false and exit - else - bad_connection(corinv(connectmat(jj,3)),0,0,1,-1,0,0,1) - ok=%f;return - end - - //if the ndim dimension of the source port is negative - //then the size of the ndim dimension of the target port - //is equal to the sum of the size of the ndim dimension - //of output ports of target block, and flag ok is set to false - else - if ndim==1 then - bllst(connectmat(jj,3)).in(connectmat(jj,4))=sum(ww) - elseif ndim==2 then - bllst(connectmat(jj,3)).in2(connectmat(jj,4))=sum(ww) - end - ok=%f - end - - else - //set nww to be the vector of all negative size of output ports - //of the target block - nww=ww(find(ww<0)) - - //if all negative size have same size and if size of the - //ndim dimension of the source port is positive then assign - //size of the ndim dimension of the target port to nout(1,ndim) - if norm(nww-nww(1),1)==0 & nout(1,ndim)>0 then - if ndim==1 then - bllst(connectmat(jj,3)).in(connectmat(jj,4))=nout(1,ndim) - elseif ndim==2 then - bllst(connectmat(jj,3)).in2(connectmat(jj,4))=nout(1,ndim) - end - - //compute a size to be the difference between the size - //of the ndim dimension of the source block and sum of positive - //size of output ports of the target block divided by the number - //of output ports of target block with same negative size - k=(nout(1,ndim)-sum(ww(find(ww>0))))/size(nww,'*') - - //if this size is a positive integer then assign it - //to the size of the ndim dimension of output ports of the - //target block which have negative size - if k==int(k)&k>0 then - if ndim==1 then - bllst(connectmat(jj,3)).out(find(ww<0))=k - elseif ndim==2 then - bllst(connectmat(jj,3)).out2(find(ww<0))=k - end - //else call bad_connection, set flag ok to false and exit - else - bad_connection(corinv(connectmat(jj,3)),0,0,1,-1,0,0,1) - ok=%f;return - end - - //set flag ok to false - else - ok=%f - end - - end - - //sixth (& last) case : dimension of both source - // and target port are negatives - else - ok=%f //set flag ok to false - end - end - end - if ok then return, end //if ok is set true then exit adjust_inout - end - //if failed then display message - messagebox(msprintf(_('Not enough information to find port sizes.\n'+.. - 'I try to find the problem.')),"modal","info"); - - //%%%%% pass 2 %%%%%// - //Alan 19/01/07 : Warning : Behavior have changed, To Be more Tested - findflag=%f //set findflag to false - - for jj=1:nlnk //loop on number of block - //nin/nout are the size (two dimensions) of the - //target port and the source port of the observed link - nout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) - nout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) - nin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) - nin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) - - //loop on the two dimensions of source/target port - //only case : target and source ports are both - // negatives or null - if nout(1,1)<=0&nin(1,1)<=0 | nout(1,2)<=0&nin(1,2)<=0 then - findflag=%t; - // - ninnout=under_connection(corinv(connectmat(jj,1)),connectmat(jj,2),nout(1,ndim),.. - corinv(connectmat(jj,3)),connectmat(jj,4),nin(1,ndim),1) - // - if size(ninnout,2) <> 2 then ok=%f;return;end - if ninnout==[] then ok=%f;return;end - if ninnout(1,1)<=0 | ninnout(1,2)<=0 then ok=%f;return;end - // - ww=find(bllst(connectmat(jj,1)).out==nout(1,1)) - bllst(connectmat(jj,1)).out(ww)=ninnout(1,1) - ww=find(bllst(connectmat(jj,1)).out2==nout(1,1)) - bllst(connectmat(jj,1)).out2(ww)=ninnout(1,1) - - ww=find(bllst(connectmat(jj,1)).out==nout(1,2)) - bllst(connectmat(jj,1)).out(ww)=ninnout(1,2) - ww=find(bllst(connectmat(jj,1)).out2==nout(1,2)) - bllst(connectmat(jj,1)).out2(ww)=ninnout(1,2) - // - - if bllst(connectmat(jj,1)).nzcross==nout(1,1) then - bllst(connectmat(jj,1)).nzcross=ninnout(1,1) - end - if bllst(connectmat(jj,1)).nzcross==nout(1,2) then - bllst(connectmat(jj,1)).nzcross=ninnout(1,2) - end - // - if bllst(connectmat(jj,1)).nmode==nout(1,1) then - bllst(connectmat(jj,1)).nmode=ninnout(1,1) - end - if bllst(connectmat(jj,1)).nmode==nout(1,2) then - bllst(connectmat(jj,1)).nmode=ninnout(1,2) - end - // - ww=find(bllst(connectmat(jj,1)).in==nout(1,1)) - bllst(connectmat(jj,1)).in(ww)=ninnout(1,1) - ww=find(bllst(connectmat(jj,1)).in2==nout(1,1)) - bllst(connectmat(jj,1)).in2(ww)=ninnout(1,1) - - ww=find(bllst(connectmat(jj,1)).in==nout(1,2)) - bllst(connectmat(jj,1)).in(ww)=ninnout(1,2) - ww=find(bllst(connectmat(jj,1)).in2==nout(1,2)) - bllst(connectmat(jj,1)).in2(ww)=ninnout(1,2) - // - ww=find(bllst(connectmat(jj,1)).in==0) - if (ww<>[]&min(bllst(connectmat(jj,1)).out(:))>0) then - bllst(connectmat(jj,1)).in(ww)=sum(bllst(connectmat(jj,1)).out) + end end + if ok then return, end //if ok is set true then exit adjust_inout + end + //if failed then display message + messagebox(msprintf(_("Not enough information to find port sizes.\n"+.. + "I try to find the problem.")),"modal","info"); + + //%%%%% pass 2 %%%%%// + //Alan 19/01/07 : Warning : Behavior have changed, To Be more Tested + findflag=%f //set findflag to false + + for jj=1:nlnk //loop on number of block + //nin/nout are the size (two dimensions) of the + //target port and the source port of the observed link + nout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) + nout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) + nin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) + nin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) + + //loop on the two dimensions of source/target port + //only case : target and source ports are both + // negatives or null + if nout(1,1)<=0&nin(1,1)<=0 | nout(1,2)<=0&nin(1,2)<=0 then + findflag=%t; + // + ninnout=under_connection(corinv(connectmat(jj,1)),connectmat(jj,2),nout(1,ndim),.. + corinv(connectmat(jj,3)),connectmat(jj,4),nin(1,ndim),1) + // + if size(ninnout,2) <> 2 then ok=%f;return;end + if ninnout==[] then ok=%f;return;end + if ninnout(1,1)<=0 | ninnout(1,2)<=0 then ok=%f;return;end + // + ww=find(bllst(connectmat(jj,1)).out==nout(1,1)) + bllst(connectmat(jj,1)).out(ww)=ninnout(1,1) + ww=find(bllst(connectmat(jj,1)).out2==nout(1,1)) + bllst(connectmat(jj,1)).out2(ww)=ninnout(1,1) + + ww=find(bllst(connectmat(jj,1)).out==nout(1,2)) + bllst(connectmat(jj,1)).out(ww)=ninnout(1,2) + ww=find(bllst(connectmat(jj,1)).out2==nout(1,2)) + bllst(connectmat(jj,1)).out2(ww)=ninnout(1,2) + // - ww=find(bllst(connectmat(jj,1)).in2==0) - if (ww<>[]&min(bllst(connectmat(jj,1)).out2(:))>0) then - bllst(connectmat(jj,1)).in2(ww)=sum(bllst(connectmat(jj,1)).out2) - end - // - ww=find(bllst(connectmat(jj,3)).in==nin(1,1)) - bllst(connectmat(jj,3)).in(ww)=ninnout(1,1) - ww=find(bllst(connectmat(jj,3)).in2==nin(1,1)) - bllst(connectmat(jj,3)).in2(ww)=ninnout(1,1) - - ww=find(bllst(connectmat(jj,3)).in==nin(1,2)) - bllst(connectmat(jj,3)).in(ww)=ninnout(1,2) - ww=find(bllst(connectmat(jj,3)).in2==nin(1,2)) - bllst(connectmat(jj,3)).in2(ww)=ninnout(1,2) - // - if bllst(connectmat(jj,3)).nzcross==nin(1,1) then - bllst(connectmat(jj,3)).nzcross=ninnout(1,1) - end - if bllst(connectmat(jj,3)).nzcross==nin(1,2) then - bllst(connectmat(jj,3)).nzcross=ninnout(1,2) - end - if bllst(connectmat(jj,3)).nmode==nin(1,1) then - bllst(connectmat(jj,3)).nmode=ninnout(1,1) - end - if bllst(connectmat(jj,3)).nmode==nin(1,2) then - bllst(connectmat(jj,3)).nmode=ninnout(1,2) - end - // - ww=find(bllst(connectmat(jj,3)).out==nin(1,1)) - bllst(connectmat(jj,3)).out(ww)=ninnout(1,1) - ww=find(bllst(connectmat(jj,3)).out2==nin(1,1)) - bllst(connectmat(jj,3)).out2(ww)=ninnout(1,1) - - ww=find(bllst(connectmat(jj,3)).out==nin(1,2)) - bllst(connectmat(jj,3)).out(ww)=ninnout(1,2) - ww=find(bllst(connectmat(jj,3)).out2==nin(1,2)) - bllst(connectmat(jj,3)).out2(ww)=ninnout(1,2) - // - ww=find(bllst(connectmat(jj,3)).out==0) - if (ww<>[]&min(bllst(connectmat(jj,3)).in(:))>0) then - bllst(connectmat(jj,3)).out(ww)=sum(bllst(connectmat(jj,3)).in(:)) - end - ww=find(bllst(connectmat(jj,3)).out2==0) - if (ww<>[]&min(bllst(connectmat(jj,3)).in2(:))>0) then - bllst(connectmat(jj,3)).out2(ww)=sum(bllst(connectmat(jj,3)).in2(:)) + if bllst(connectmat(jj,1)).nzcross==nout(1,1) then + bllst(connectmat(jj,1)).nzcross=ninnout(1,1) + end + if bllst(connectmat(jj,1)).nzcross==nout(1,2) then + bllst(connectmat(jj,1)).nzcross=ninnout(1,2) + end + // + if bllst(connectmat(jj,1)).nmode==nout(1,1) then + bllst(connectmat(jj,1)).nmode=ninnout(1,1) + end + if bllst(connectmat(jj,1)).nmode==nout(1,2) then + bllst(connectmat(jj,1)).nmode=ninnout(1,2) + end + // + ww=find(bllst(connectmat(jj,1)).in==nout(1,1)) + bllst(connectmat(jj,1)).in(ww)=ninnout(1,1) + ww=find(bllst(connectmat(jj,1)).in2==nout(1,1)) + bllst(connectmat(jj,1)).in2(ww)=ninnout(1,1) + + ww=find(bllst(connectmat(jj,1)).in==nout(1,2)) + bllst(connectmat(jj,1)).in(ww)=ninnout(1,2) + ww=find(bllst(connectmat(jj,1)).in2==nout(1,2)) + bllst(connectmat(jj,1)).in2(ww)=ninnout(1,2) + // + ww=find(bllst(connectmat(jj,1)).in==0) + if (ww<>[]&min(bllst(connectmat(jj,1)).out(:))>0) then + bllst(connectmat(jj,1)).in(ww)=sum(bllst(connectmat(jj,1)).out) + end + + ww=find(bllst(connectmat(jj,1)).in2==0) + if (ww<>[]&min(bllst(connectmat(jj,1)).out2(:))>0) then + bllst(connectmat(jj,1)).in2(ww)=sum(bllst(connectmat(jj,1)).out2) + end + // + ww=find(bllst(connectmat(jj,3)).in==nin(1,1)) + bllst(connectmat(jj,3)).in(ww)=ninnout(1,1) + ww=find(bllst(connectmat(jj,3)).in2==nin(1,1)) + bllst(connectmat(jj,3)).in2(ww)=ninnout(1,1) + + ww=find(bllst(connectmat(jj,3)).in==nin(1,2)) + bllst(connectmat(jj,3)).in(ww)=ninnout(1,2) + ww=find(bllst(connectmat(jj,3)).in2==nin(1,2)) + bllst(connectmat(jj,3)).in2(ww)=ninnout(1,2) + // + if bllst(connectmat(jj,3)).nzcross==nin(1,1) then + bllst(connectmat(jj,3)).nzcross=ninnout(1,1) + end + if bllst(connectmat(jj,3)).nzcross==nin(1,2) then + bllst(connectmat(jj,3)).nzcross=ninnout(1,2) + end + if bllst(connectmat(jj,3)).nmode==nin(1,1) then + bllst(connectmat(jj,3)).nmode=ninnout(1,1) + end + if bllst(connectmat(jj,3)).nmode==nin(1,2) then + bllst(connectmat(jj,3)).nmode=ninnout(1,2) + end + // + ww=find(bllst(connectmat(jj,3)).out==nin(1,1)) + bllst(connectmat(jj,3)).out(ww)=ninnout(1,1) + ww=find(bllst(connectmat(jj,3)).out2==nin(1,1)) + bllst(connectmat(jj,3)).out2(ww)=ninnout(1,1) + + ww=find(bllst(connectmat(jj,3)).out==nin(1,2)) + bllst(connectmat(jj,3)).out(ww)=ninnout(1,2) + ww=find(bllst(connectmat(jj,3)).out2==nin(1,2)) + bllst(connectmat(jj,3)).out2(ww)=ninnout(1,2) + // + ww=find(bllst(connectmat(jj,3)).out==0) + if (ww<>[]&min(bllst(connectmat(jj,3)).in(:))>0) then + bllst(connectmat(jj,3)).out(ww)=sum(bllst(connectmat(jj,3)).in(:)) + end + ww=find(bllst(connectmat(jj,3)).out2==0) + if (ww<>[]&min(bllst(connectmat(jj,3)).in2(:))>0) then + bllst(connectmat(jj,3)).out2(ww)=sum(bllst(connectmat(jj,3)).in2(:)) + end end end - end - //if failed then display message - if ~findflag then - messagebox(msprintf(_('I cannot find a link with undetermined size.\n'+.. - 'My guess is that you have a block with unconnected \n'+.. - 'undetermined output ports.')),"modal","error"); - ok=%f;return; - end - end + //if failed then display message + if ~findflag then + messagebox(msprintf(_("I cannot find a link with undetermined size.\n"+.. + "My guess is that you have a block with unconnected \n"+.. + "undetermined output ports.")),"modal","error"); + ok=%f;return; + end + end endfunction function id = getBlockIds(path) @@ -2040,10 +2040,10 @@ function id = getBlockIds(path) // // path: the path in the index form // id: th path in the uid form - + scs_m; // check scs_m access id=[]; - + k = path(:); for i = k b = scs_m.objs(i); @@ -2051,317 +2051,317 @@ function id = getBlockIds(path) id($ + 1) = scs_m.objs(i).doc(1); end if typeof(b.model.rpar) == "diagram" then - scs_m = b.model.rpar; + scs_m = b.model.rpar; end end endfunction //19/01/07, Alan : under_connection show bad link and returns two dimensions now function ninnout=under_connection(path_out,prt_out,nout,path_in,prt_in,nin,flagg) -// alert for badly connected blocks -// path_out : Path of the "from block" in scs_m -// path_in : Path of the "to block" in scs_m -//! - - if path_in==-1 then - msg = ""; - msg = msg + gettext("One of this block output has negative size.
Please check."); - msg = msg + ""; - hilite_path(path_out, msg); - ninnout=0 - return - end + // alert for badly connected blocks + // path_out : Path of the "from block" in scs_m + // path_in : Path of the "to block" in scs_m + //! + + if path_in==-1 then + msg = ""; + msg = msg + gettext("One of this block output has negative size.
Please check."); + msg = msg + ""; + hilite_path(path_out, msg); + ninnout=0 + return + end + + if path_in==-2 then + msg = ""; + msg = msg + gettext("Block input has negative size:"); + msg = msg + "
    "; + msg = msg + "
  • " + msprintf(gettext("Input port %s size is: %s"), string(prt_out), sci2exp(nout)) + "
  • "; + msg = msg + "
"; + msg = msg + ""; + hilite_path(path_out, msg); + ninnout=0 + return + end + + // different use case (Unable to report on a non opened diagram) + if isdef("Code_gene_run") then + messagebox([gettext("Unable to report an error into a SuperBlock"); gettext("Please compile the diagram to report the error.")], "Compilation error", "error", "modal"); + ninnout=0 + return + end - if path_in==-2 then - msg = ""; - msg = msg + gettext("Block input has negative size:"); - msg = msg + "
    "; - msg = msg + "
  • " + msprintf(gettext("Input port %s size is: %s"), string(prt_out), sci2exp(nout)) + "
  • "; - msg = msg + "
"; - msg = msg + ""; - hilite_path(path_out, msg); - ninnout=0 - return - end - -// different use case (Unable to report on a non opened diagram) - if isdef('Code_gene_run') then - messagebox([gettext("Unable to report an error into a SuperBlock"); gettext("Please compile the diagram to report the error.")], "Compilation error", "error", "modal"); - ninnout=0 - return - end - - msg = ""; - if flagg==1 then - msg = msg + gettext("Please update the diagram to avoid this warning.
Block output port has a non-determined size:"); - msg = msg + "
    "; - msg = msg + "
  • " + msprintf(gettext("Output port %s size is: %s"), string(prt_out), sci2exp(nout)) + "
  • "; - msg = msg + "
  • " + msprintf(gettext("Input port %s size is: %s"), string(prt_in), sci2exp(nin)) + "
  • "; - else - msg = msg + gettext("Please update the diagram to avoid this warning.
    Block output port has a non-determined type:"); - msg = msg + "
      "; - msg = msg + "
    • " + msprintf(gettext("Output port %s type."), string(prt_out)) + "
    • "; - msg = msg + "
    • " + msprintf(gettext("Input port %s type."), string(prt_in)) + "
    • "; - end - msg = msg + "
    "; - msg = msg + ""; - hilite_path(path_out, msg) - - if or(path_in<>path_out) then msg = ""; if flagg==1 then - msg = msg + gettext("Please update the diagram to avoid this warning.
    Block input port has a non-determined size:"); - msg = msg + "
      "; - msg = msg + "
    • " + msprintf(gettext("Output port %s size is: %s"), string(prt_out), sci2exp(nout)) + "
    • "; - msg = msg + "
    • " + msprintf(gettext("Input port %s size is: %s"), string(prt_in), sci2exp(nin)) + "
    • "; + msg = msg + gettext("Please update the diagram to avoid this warning.
      Block output port has a non-determined size:"); + msg = msg + "
        "; + msg = msg + "
      • " + msprintf(gettext("Output port %s size is: %s"), string(prt_out), sci2exp(nout)) + "
      • "; + msg = msg + "
      • " + msprintf(gettext("Input port %s size is: %s"), string(prt_in), sci2exp(nin)) + "
      • "; else - msg = msg + gettext("Please update the diagram to avoid this warning.
        Block input port has a non-determined type:"); - msg = msg + "
          "; - msg = msg + "
        • " + msprintf(gettext("Output port %s type."), string(prt_out)) + "
        • "; - msg = msg + "
        • " + msprintf(gettext("Input port %s type."), string(prt_in)) + "
        • "; + msg = msg + gettext("Please update the diagram to avoid this warning.
          Block output port has a non-determined type:"); + msg = msg + "
            "; + msg = msg + "
          • " + msprintf(gettext("Output port %s type."), string(prt_out)) + "
          • "; + msg = msg + "
          • " + msprintf(gettext("Input port %s type."), string(prt_in)) + "
          • "; end msg = msg + "
          "; msg = msg + ""; - hilite_path(path_in, msg) - end - - mess=msprintf(_('Highlighted block(s) have connected ports \n'+.. - 'with sizes that cannot be determined by the context.\n'+.. - 'What is the size of this link?')) - - if flagg==1 then - ninnout=evstr(dialog(mess,'[1,1]')) - else - ninnout=evstr(dialog(mess,'1')) - end + hilite_path(path_out, msg) + + if or(path_in<>path_out) then + msg = ""; + if flagg==1 then + msg = msg + gettext("Please update the diagram to avoid this warning.
          Block input port has a non-determined size:"); + msg = msg + "
            "; + msg = msg + "
          • " + msprintf(gettext("Output port %s size is: %s"), string(prt_out), sci2exp(nout)) + "
          • "; + msg = msg + "
          • " + msprintf(gettext("Input port %s size is: %s"), string(prt_in), sci2exp(nin)) + "
          • "; + else + msg = msg + gettext("Please update the diagram to avoid this warning.
            Block input port has a non-determined type:"); + msg = msg + "
              "; + msg = msg + "
            • " + msprintf(gettext("Output port %s type."), string(prt_out)) + "
            • "; + msg = msg + "
            • " + msprintf(gettext("Input port %s type."), string(prt_in)) + "
            • "; + end + msg = msg + "
            "; + msg = msg + ""; + hilite_path(path_in, msg) + end + + mess=msprintf(_("Highlighted block(s) have connected ports \n"+.. + "with sizes that cannot be determined by the context.\n"+.. + "What is the size of this link?")) + + if flagg==1 then + ninnout=evstr(dialog(mess,"[1,1]")) + else + ninnout=evstr(dialog(mess,"1")) + end endfunction function [clkconnect,exe_cons]=pak_ersi(connectmat,clkconnect,.. - typ_r,typ_l,outoin,outoinptr,tblock,typ_cons,clkptr) - - //add every event to the time event because time includes all events - all_out=[] - for k=1:size(clkptr,1)-1 - if ~typ_l(k) then - kk=[1:(clkptr(k+1)-clkptr(k))]' - all_out=[all_out;[k*ones(kk),kk]] - end - end - all_out=[all_out;[0,0]] - - //add time event if needed - ind=find(tblock) - ind=ind(:) - for k=ind' - clkconnect=[clkconnect;[all_out,ones(all_out)*[k,0;0,0]]] - end - if show_trace then mprintf('c_pass4444:\t%f\n', timer()),end - ind1=find(typ_cons) - ind=[ind;ind1(:)] - exe_cons=[ind,zeros(ind)] - - vec=-ones(1,nblk); - vec(ind)=0 - [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r) - - exe_cons=[exe_cons;r] - - if show_trace then mprintf('c_pass4445:\t%f\n', timer()),end - - [clkr,clkc]=size(clkconnect); - mm=max(clkconnect(:,2))+1; - cll=clkconnect(:,1)*mm+clkconnect(:,2); - [cll,ind]=gsort(-cll); - clkconnect=clkconnect(ind,:); - if cll<>[] then mcll=max(-cll)+1, else mcll=1;end - cll=[-1;-cll;mcll]; - ii=find(cll(2:$)-cll(1:$-1)<>0) - - for k=1:size(ii,'*')-1 - oo=[ii(k):ii(k+1)-1] + typ_r,typ_l,outoin,outoinptr,tblock,typ_cons,clkptr) + + //add every event to the time event because time includes all events + all_out=[] + for k=1:size(clkptr,1)-1 + if ~typ_l(k) then + kk=[1:(clkptr(k+1)-clkptr(k))]' + all_out=[all_out;[k*ones(kk),kk]] + end + end + all_out=[all_out;[0,0]] + + //add time event if needed + ind=find(tblock) + ind=ind(:) + for k=ind' + clkconnect=[clkconnect;[all_out,ones(all_out)*[k,0;0,0]]] + end + if show_trace then mprintf("c_pass4444:\t%f\n", timer()),end + ind1=find(typ_cons) + ind=[ind;ind1(:)] + exe_cons=[ind,zeros(ind)] + vec=-ones(1,nblk); - vec(clkconnect(oo,3))=0 + vec(ind)=0 [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r) - m=size(r,1) - r=[clkconnect(ii(k),1)*ones(m,1),clkconnect(ii(k),2)*ones(m,1),r] - clkconnect=[clkconnect;r] - end - // temporary fix to take care of conditional blocks inherting from - // constants: make these blocks always active - - ind=setdiff(find(typ_l),clkconnect(:,3)) - ind=ind(:) - for k=ind' - clkconnect=[clkconnect;[all_out,ones(all_out)*[k,0;0,0]]] - end - // end of temoprary fix - if show_trace then mprintf('c_pass4446:\t%f\n', timer()),end + + exe_cons=[exe_cons;r] + + if show_trace then mprintf("c_pass4445:\t%f\n", timer()),end + + [clkr,clkc]=size(clkconnect); + mm=max(clkconnect(:,2))+1; + cll=clkconnect(:,1)*mm+clkconnect(:,2); + [cll,ind]=gsort(-cll); + clkconnect=clkconnect(ind,:); + if cll<>[] then mcll=max(-cll)+1, else mcll=1;end + cll=[-1;-cll;mcll]; + ii=find(cll(2:$)-cll(1:$-1)<>0) + + for k=1:size(ii,"*")-1 + oo=[ii(k):ii(k+1)-1] + vec=-ones(1,nblk); + vec(clkconnect(oo,3))=0 + [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r) + m=size(r,1) + r=[clkconnect(ii(k),1)*ones(m,1),clkconnect(ii(k),2)*ones(m,1),r] + clkconnect=[clkconnect;r] + end + // temporary fix to take care of conditional blocks inherting from + // constants: make these blocks always active + + ind=setdiff(find(typ_l),clkconnect(:,3)) + ind=ind(:) + for k=ind' + clkconnect=[clkconnect;[all_out,ones(all_out)*[k,0;0,0]]] + end + // end of temoprary fix + if show_trace then mprintf("c_pass4446:\t%f\n", timer()),end endfunction function [r,ok]=tree4(vec,outoin,outoinptr,typ_r) -//compute blocks which inherit - ok=%t; - nb=size(vec,'*'); - r=[]; - for j=1:nb-1 - fini=%t - for i=1:nb - if vec(i)==j-1 then - for k=outoinptr(i):outoinptr(i+1)-1 - ii=outoin(k,1); - if (vec(ii)>-1)|typ_r(ii) then - fini=%f; - vec(ii)=j; - end - if typ_r(ii) then - r=[r;outoin(k,:)] - end - end - end - end - if fini then break;end - end + //compute blocks which inherit + ok=%t; + nb=size(vec,"*"); + r=[]; + for j=1:nb-1 + fini=%t + for i=1:nb + if vec(i)==j-1 then + for k=outoinptr(i):outoinptr(i+1)-1 + ii=outoin(k,1); + if (vec(ii)>-1)|typ_r(ii) then + fini=%f; + vec(ii)=j; + end + if typ_r(ii) then + r=[r;outoin(k,:)] + end + end + end + end + if fini then break;end + end endfunction function [bllst,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,dep_u,dep_uptr,dep_t,.. - typ_l,typ_r,typ_m,tblock,typ_cons,typ_zx,ok]=mini_extract_info(bllst,.. - connectmat,clkconnect) - ok=%t - nbl=length(bllst) - clkptr=zeros(nbl+1,1);clkptr(1)=1 - cliptr=clkptr;inpptr=cliptr;outptr=inpptr; - fff=ones(nbl,1)==1 - typ_l=fff;typ_r=fff;typ_cons=fff;typ_m=fff;typ_zx=fff; - dep_t=ones(nbl,1)==1; - dep_u=[];dep_uptr=1; - tblock=fff - //tblock=[] // specifies blocks that must be connected to time event. - // - for i=1:nbl - ll=bllst(i) - if (ll.state==[]&ll.nzcross==0) then typ_zx(i)=%f;end - inpnum=ll.in;outnum=ll.out;cinpnum=ll.evtin;coutnum=ll.evtout; - // - if cinpnum==[] then - // this block inherits - //ok=%f - - typ_r(i)=~ll.dep_ut($) - tblock(i)=ll.dep_ut($) - //if block depends on time but has no event input port - if ~ll.dep_ut($) then - //inherits from the inputs - cinpnum=ones(inpnum) - bllst(i).evtin=cinpnum //XXXXXXXXXXXXXXXXXXXXX - end - // - else - tblock(i)=ll.dep_ut($);typ_r(i)=%f - end - inpptr(i+1)=inpptr(i)+size(inpnum,'*') - outptr(i+1)=outptr(i)+size(outnum,'*') - cliptr(i+1)=cliptr(i)+size(cinpnum,'*') - clkptr(i+1)=clkptr(i)+size(coutnum,'*') + typ_l,typ_r,typ_m,tblock,typ_cons,typ_zx,ok]=mini_extract_info(bllst,.. + connectmat,clkconnect) + ok=%t + nbl=length(bllst) + clkptr=zeros(nbl+1,1);clkptr(1)=1 + cliptr=clkptr;inpptr=cliptr;outptr=inpptr; + fff=ones(nbl,1)==1 + typ_l=fff;typ_r=fff;typ_cons=fff;typ_m=fff;typ_zx=fff; + dep_t=ones(nbl,1)==1; + dep_u=[];dep_uptr=1; + tblock=fff + //tblock=[] // specifies blocks that must be connected to time event. // + for i=1:nbl + ll=bllst(i) + if (ll.state==[]&ll.nzcross==0) then typ_zx(i)=%f;end + inpnum=ll.in;outnum=ll.out;cinpnum=ll.evtin;coutnum=ll.evtout; + // + if cinpnum==[] then + // this block inherits + //ok=%f + + typ_r(i)=~ll.dep_ut($) + tblock(i)=ll.dep_ut($) + //if block depends on time but has no event input port + if ~ll.dep_ut($) then + //inherits from the inputs + cinpnum=ones(inpnum) + bllst(i).evtin=cinpnum //XXXXXXXXXXXXXXXXXXXXX + end + // + else + tblock(i)=ll.dep_ut($);typ_r(i)=%f + end + inpptr(i+1)=inpptr(i)+size(inpnum,"*") + outptr(i+1)=outptr(i)+size(outnum,"*") + cliptr(i+1)=cliptr(i)+size(cinpnum,"*") + clkptr(i+1)=clkptr(i)+size(coutnum,"*") + // + + typ_l(i)=ll.blocktype=="l";typ_m(i)=ll.blocktype=="m"; + typ_cons(i)=cinpnum==[]&inpnum==[]&~ll.dep_ut($) + //test of the dep_ut size + sizenin=size(ll.in,"*"); + if (size(ll.dep_ut,"*") <> 2) then + if ( size(ll.dep_ut(1:$-1),"*") <> sizenin) then + messagebox(msprintf(_("the dep_ut size of the %s block is not correct.\n"+.. + "It should be a colon vector of size %d."),.. + ll.sim(1),sizenin+1),"modal","error"); + ok=%f; + end + end - typ_l(i)=ll.blocktype=='l';typ_m(i)=ll.blocktype=='m'; - typ_cons(i)=cinpnum==[]&inpnum==[]&~ll.dep_ut($) -//test of the dep_ut size - sizenin=size(ll.in,'*'); - if (size(ll.dep_ut,'*') <> 2) then - if ( size(ll.dep_ut(1:$-1),'*') <> sizenin) then - messagebox(msprintf(_('the dep_ut size of the %s block is not correct.\n'+.. - 'It should be a colon vector of size %d.'),.. - ll.sim(1),sizenin+1),"modal","error"); - ok=%f; - end - end - - dep_t(i)=ll.dep_ut($); - - if (size(ll.dep_ut,'*') == 2) then - if (sizenin == 1) then - dep_u($+1)=ll.dep_ut(1); - dep_uptr($+1)=dep_uptr($)+1; - elseif (sizenin > 1) then - dep_u=[dep_u;ones(sizenin,1)==1*ll.dep_ut(1)]; - dep_uptr($+1)=dep_uptr($)+sizenin; - else - dep_uptr($+1)=dep_uptr($); - end - else - dep_u_i=ll.dep_ut(1:$-1); - dep_u=[dep_u;dep_u_i(:)]; - dep_uptr($+1)=dep_uptr($)+sizenin; - end - - // - end - if show_trace then mprintf('c_pass22222222:\t%f\n', timer()),end //' - nlnk=size(connectmat,1) - inplnk=zeros(inpptr($)-1,1);outlnk=zeros(outptr($)-1,1);ptlnk=1; - - for jj=1:nlnk - ko=outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1) - ki=inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1) - if ko<>0 & ki<>0 then - if ko>ki then - outlnk(outlnk>ko)=outlnk(outlnk>ko)-1 - outlnk(outlnk==ko)=ki - inplnk(inplnk>ko)=inplnk(inplnk>ko)-1 - inplnk(inplnk==ko)=ki - ptlnk=-1+ptlnk - elseif ki>ko - outlnk(outlnk>ki)=outlnk(outlnk>ki)-1 - outlnk(outlnk==ki)=ko - inplnk(inplnk>ki)=inplnk(inplnk>ki)-1 - inplnk(inplnk==ki)=ko - ptlnk=-1+ptlnk - end - elseif ko<>0 then - inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ko - elseif ki<>0 then - outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ki - else - outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ptlnk - inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ptlnk - ptlnk=1+ptlnk + dep_t(i)=ll.dep_ut($); + + if (size(ll.dep_ut,"*") == 2) then + if (sizenin == 1) then + dep_u($+1)=ll.dep_ut(1); + dep_uptr($+1)=dep_uptr($)+1; + elseif (sizenin > 1) then + dep_u=[dep_u;ones(sizenin,1)==1*ll.dep_ut(1)]; + dep_uptr($+1)=dep_uptr($)+sizenin; + else + dep_uptr($+1)=dep_uptr($); + end + else + dep_u_i=ll.dep_ut(1:$-1); + dep_u=[dep_u;dep_u_i(:)]; + dep_uptr($+1)=dep_uptr($)+sizenin; + end + + // + end + if show_trace then mprintf("c_pass22222222:\t%f\n", timer()),end //' + nlnk=size(connectmat,1) + inplnk=zeros(inpptr($)-1,1);outlnk=zeros(outptr($)-1,1);ptlnk=1; + + for jj=1:nlnk + ko=outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1) + ki=inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1) + if ko<>0 & ki<>0 then + if ko>ki then + outlnk(outlnk>ko)=outlnk(outlnk>ko)-1 + outlnk(outlnk==ko)=ki + inplnk(inplnk>ko)=inplnk(inplnk>ko)-1 + inplnk(inplnk==ko)=ki + ptlnk=-1+ptlnk + elseif ki>ko + outlnk(outlnk>ki)=outlnk(outlnk>ki)-1 + outlnk(outlnk==ki)=ko + inplnk(inplnk>ki)=inplnk(inplnk>ki)-1 + inplnk(inplnk==ki)=ko + ptlnk=-1+ptlnk + end + elseif ko<>0 then + inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ko + elseif ki<>0 then + outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ki + else + outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ptlnk + inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ptlnk + ptlnk=1+ptlnk + end end - end - //store unconnected outputs, if any, at the end of outtb - for unco=find(outlnk==0); - outlnk(unco)=max(outlnk)+1 - end + //store unconnected outputs, if any, at the end of outtb + for unco=find(outlnk==0); + outlnk(unco)=max(outlnk)+1 + end - //store unconnected inputs, if any, at the end of outtb - for unco=find(inplnk==0); - inplnk(unco)=max([inplnk;max(outlnk)])+1 - end + //store unconnected inputs, if any, at the end of outtb + for unco=find(inplnk==0); + inplnk(unco)=max([inplnk;max(outlnk)])+1 + end endfunction function [evoutoin,evoutoinptr]=synch_clkconnect(typ_l,clkconnect) - nblk=size(typ_l,'*') - evoutoin=[];evoutoinptr=1 - for i=1:nblk - if typ_l(i) then - dd=clkconnect(clkconnect(:,1)==i,3) - else - dd=[] - end - evoutoin=[evoutoin;dd] - evoutoinptr=[evoutoinptr;evoutoinptr($)+size(dd,'*')] - end + nblk=size(typ_l,"*") + evoutoin=[];evoutoinptr=1 + for i=1:nblk + if typ_l(i) then + dd=clkconnect(clkconnect(:,1)==i,3) + else + dd=[] + end + evoutoin=[evoutoin;dd] + evoutoinptr=[evoutoinptr;evoutoinptr($)+size(dd,"*")] + end endfunction function clkconnect=cleanup(clkconnect) - mm=max(clkconnect)+1 - cc=clkconnect(:,4)+mm*clkconnect(:,3)+clkconnect(:,2)*mm^2+.. - clkconnect(:,1)*mm^3 - [cc1,ind]=gsort(-cc) - clkconnect=clkconnect(ind,:) - ind=find(cc1(2:$)-cc1(1:$-1)==0) - clkconnect(ind,:)=[] + mm=max(clkconnect)+1 + cc=clkconnect(:,4)+mm*clkconnect(:,3)+clkconnect(:,2)*mm^2+.. + clkconnect(:,1)*mm^3 + [cc1,ind]=gsort(-cc) + clkconnect=clkconnect(ind,:) + ind=find(cc1(2:$)-cc1(1:$-1)==0) + clkconnect(ind,:)=[] endfunction //function mat=cleanup1(mat) @@ -2374,108 +2374,108 @@ endfunction //endfunction function vec=intersection(vec1,vec2) - vec=[] - for i=1:size(vec1,1) - if find(vec1(i)==vec2)~=[] then - vec=[vec;vec1(i)] + vec=[] + for i=1:size(vec1,1) + if find(vec1(i)==vec2)~=[] then + vec=[vec;vec1(i)] + end end - end endfunction function [r,ok]=newc_tree2(vec,outoin,outoinptr,dep_u,dep_uptr) - dd=zeros(dep_u);dd(dep_u)=1; - [r,ok2]=ctree2(vec,outoin,outoinptr,dd,dep_uptr) - ok=ok2==1 + dd=zeros(dep_u);dd(dep_u)=1; + [r,ok2]=ctree2(vec,outoin,outoinptr,dd,dep_uptr) + ok=ok2==1 endfunction function [r,ok]=new_tree2(vec,outoin,outoinptr,dep_u,dep_uptr) - dd=zeros(dep_u);dd(dep_u)=1; - [r,ok2]=sci_tree2(vec,outoin,outoinptr,dd) - ok=ok2==1 + dd=zeros(dep_u);dd(dep_u)=1; + [r,ok2]=sci_tree2(vec,outoin,outoinptr,dd) + ok=ok2==1 endfunction function [r,ok]=new_tree3(vec,dep_ut,typ_l) - dd=zeros(dep_ut);dd(dep_ut)=1; - [r2,ok2]=sci_tree3(vec,dd,typ_l,bexe,boptr,blnk,blptr) - r=r2' - ok=ok2==1 + dd=zeros(dep_ut);dd(dep_ut)=1; + [r2,ok2]=sci_tree3(vec,dd,typ_l,bexe,boptr,blnk,blptr) + r=r2' + ok=ok2==1 endfunction function [r,ok]=newc_tree3(vec,dep_u,dep_uptr,typ_l) - dd=zeros(dep_u);dd(dep_u)=1; - [r2,ok2]=ctree3(vec,dd,dep_uptr,typ_l,bexe,boptr,blnk,blptr) - r=r2' - ok=ok2==1 + dd=zeros(dep_u);dd(dep_u)=1; + [r2,ok2]=ctree3(vec,dd,dep_uptr,typ_l,bexe,boptr,blnk,blptr) + r=r2' + ok=ok2==1 endfunction function [r,ok]=new_tree4(vec,outoin,outoinptr,typ_r) - nd=zeros(size(vec,'*'),(max(outoin(:,2))+1)); - ddd=zeros(typ_r);ddd(typ_r)=1; - [r1,r2]=sci_tree4(vec,outoin,outoinptr,nd,ddd) - r=[r1',r2'] - ok=%t + nd=zeros(size(vec,"*"),(max(outoin(:,2))+1)); + ddd=zeros(typ_r);ddd(typ_r)=1; + [r1,r2]=sci_tree4(vec,outoin,outoinptr,nd,ddd) + r=[r1',r2'] + ok=%t endfunction function [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r) - nd=zeros(size(vec,'*'),(max(outoin(:,2))+1)); - ddd=zeros(typ_r);ddd(typ_r)=1; - [r1,r2]=ctree4(vec,outoin,outoinptr,nd,ddd) - r=[r1',r2'] - ok=%t + nd=zeros(size(vec,"*"),(max(outoin(:,2))+1)); + ddd=zeros(typ_r);ddd(typ_r)=1; + [r1,r2]=ctree4(vec,outoin,outoinptr,nd,ddd) + r=[r1',r2'] + ok=%t endfunction function [critev]=critical_events(connectmat,clkconnect,dep_t,typ_r,.. - typ_l,typ_zx,outoin,outoinptr,clkptr) - - typ_c=typ_l<>typ_l; - typ_r=typ_r|dep_t - - done1=%f - while ~done1 - done1=%t - [clkr,clkc]=size(clkconnect); - mm=max(clkconnect)+1; + typ_l,typ_zx,outoin,outoinptr,clkptr) + + typ_c=typ_l<>typ_l; + typ_r=typ_r|dep_t + + done1=%f + while ~done1 + done1=%t + [clkr,clkc]=size(clkconnect); + mm=max(clkconnect)+1; + + cll=clkconnect(:,1)*mm+clkconnect(:,2); + [cll,ind]=gsort(-cll); + clkconnect=clkconnect(ind,:); + cll=[-1;-cll;mm]; + ii=find(cll(2:$)-cll(1:$-1)<>0) + + for k=1:size(ii,"*")-1 + oo=[ii(k):ii(k+1)-1] + vec=-ones(1,nblk); + vec(clkconnect(oo,3))=0 + [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r) + + m=size(r,1) + r=[clkconnect(ii(k),1)*ones(m,1),clkconnect(ii(k),2)*ones(m,1),r] + clkconnect=[clkconnect;r] + end - cll=clkconnect(:,1)*mm+clkconnect(:,2); - [cll,ind]=gsort(-cll); - clkconnect=clkconnect(ind,:); - cll=[-1;-cll;mm]; - ii=find(cll(2:$)-cll(1:$-1)<>0) - - for k=1:size(ii,'*')-1 - oo=[ii(k):ii(k+1)-1] - vec=-ones(1,nblk); - vec(clkconnect(oo,3))=0 - [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r) - - m=size(r,1) - r=[clkconnect(ii(k),1)*ones(m,1),clkconnect(ii(k),2)*ones(m,1),r] - clkconnect=[clkconnect;r] - end - - done=%f; - while ~done - done=%t; - for jj=find(typ_l&(~typ_c)); - if ~or(jj==clkconnect(:,3)) then - typ_r(clkconnect(find(jj==clkconnect(:,1)),3))=%t - clkconnect(find(jj==clkconnect(:,1)),:)=[]; - typ_c(jj)=%t; - done1=%f - done=%f - end - end - end - end - critev=zeros(clkptr($)-1,1); - for bb=1:size(clkptr,1)-1 - for i=clkptr(bb):clkptr(bb+1)-1 - if or(typ_zx(clkconnect(find((clkconnect(:,1)==bb)&.. - (clkconnect(:,2)==i-clkptr(bb)+1)),3))) then - critev(i)=1 - end - end - end + done=%f; + while ~done + done=%t; + for jj=find(typ_l&(~typ_c)); + if ~or(jj==clkconnect(:,3)) then + typ_r(clkconnect(find(jj==clkconnect(:,1)),3))=%t + clkconnect(find(jj==clkconnect(:,1)),:)=[]; + typ_c(jj)=%t; + done1=%f + done=%f + end + end + end + end + critev=zeros(clkptr($)-1,1); + for bb=1:size(clkptr,1)-1 + for i=clkptr(bb):clkptr(bb+1)-1 + if or(typ_zx(clkconnect(find((clkconnect(:,1)==bb)&.. + (clkconnect(:,2)==i-clkptr(bb)+1)),3))) then + critev(i)=1 + end + end + end endfunction // adjust_typ: It resolves positives and negatives port types. @@ -2484,131 +2484,132 @@ endfunction function [ok,bllst]=adjust_typ(bllst,connectmat) -for i=1:length(bllst) - if size(bllst(i).in,1)<>size(bllst(i).intyp,2) then - bllst(i).intyp=bllst(i).intyp(1)*ones(size(bllst(i).in,1),1); - end - if size(bllst(i).out,1)<>size(bllst(i).outtyp,2) then - bllst(i).outtyp=bllst(i).outtyp(1)*ones(size(bllst(i).out,1),1); - end -end -nlnk=size(connectmat,1) -for hhjj=1:length(bllst)+1 - for hh=1:length(bllst)+1 - ok=%t - for jj=1:nlnk - nnout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) - nnout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) - nnin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) - nnin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) - outtyp = bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) - intyp = bllst(connectmat(jj,3)).intyp(connectmat(jj,4)) - - //first case : types of source and - // target ports are explicitly informed - // with positive types - if (intyp>0 & outtyp>0) then - //if types of source and target port doesn't match and aren't double and complex - //then call bad_connection, set flag ok to false and exit - - if intyp<>outtyp then - if (intyp==1 & outtyp==2) then - bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=2; - elseif (intyp==2 & outtyp==1) then - bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))=2; - else - bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),.. - nnout,outtyp,.. - corinv(connectmat(jj,3)),connectmat(jj,4),.. - nnin,intyp,1) - ok=%f; - return - end - end - - //second case : type of source port is - // positive and type of - // target port is negative - elseif(outtyp>0&intyp<0) then - //find vector of input ports of target block with - //type equal to intyp - //and assign it to outtyp - ww=find(bllst(connectmat(jj,3)).intyp==intyp) - bllst(connectmat(jj,3)).intyp(ww)=outtyp - - //find vector of output ports of target block with - //type equal to intyp - //and assign it to outtyp - ww=find(bllst(connectmat(jj,3)).outtyp==intyp) - bllst(connectmat(jj,3)).outtyp(ww)=outtyp - - //third case : type of source port is - // negative and type of - // target port is positive - elseif(outtyp<0&intyp>0) then - //find vector of output ports of source block with - //type equal to outtyp - //and assign it to intyp - ww=find(bllst(connectmat(jj,1)).outtyp==outtyp) - bllst(connectmat(jj,1)).outtyp(ww)=intyp - - //find vector of input ports of source block with - //type equal to size outtyp - //and assign it to intyp - ww=find(bllst(connectmat(jj,1)).intyp==outtyp) - bllst(connectmat(jj,1)).intyp(ww)=intyp - - - //fourth (& last) case : type of both source - // and target port are negatives - else - ok=%f //set flag ok to false - end - end - if ok then return, end //if ok is set true then exit adjust_typ - end - //if failed then display message - messagebox(msprintf(_('Not enough information to find port type.\n'+.. - 'I will try to find the problem.')),"modal","info"); - findflag=%f - for jj=1:nlnk - nouttyp=bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) - nintyp=bllst(connectmat(jj,3)).intyp(connectmat(jj,4)) - - //loop on the two dimensions of source/target port - //only case : target and source ports are both - // negatives or null - if nouttyp<=0 & nintyp<=0 then - findflag=%t; - // - inouttyp=under_connection(corinv(connectmat(jj,1)),connectmat(jj,2),nouttyp,.. - corinv(connectmat(jj,3)),connectmat(jj,4),nintyp,2) - // - if inouttyp<1|inouttyp>8 then ok=%f;return;end - // - ww=find(bllst(connectmat(jj,1)).outtyp==nouttyp) - bllst(connectmat(jj,1)).outtyp(ww)=inouttyp - - // - ww=find(bllst(connectmat(jj,1)).intyp==nouttyp) - bllst(connectmat(jj,1)).intyp(ww)=inouttyp - - ww=find(bllst(connectmat(jj,3)).intyp==nintyp) - bllst(connectmat(jj,3)).intyp(ww)=inouttyp - // - ww=find(bllst(connectmat(jj,3)).outtyp==nintyp) - bllst(connectmat(jj,3)).outtyp(ww)=inouttyp - - // - end - end - //if failed then display message - if ~findflag then - messagebox(msprintf(_('I cannot find a link with undetermined size.\n'+.. - 'My guess is that you have a block with unconnected \n'+.. - 'undetermined types.')),"modal","error"); - ok=%f;return; - end -end + for i=1:length(bllst) + if size(bllst(i).in,1)<>size(bllst(i).intyp,2) then + bllst(i).intyp=bllst(i).intyp(1)*ones(size(bllst(i).in,1),1); + end + if size(bllst(i).out,1)<>size(bllst(i).outtyp,2) then + bllst(i).outtyp=bllst(i).outtyp(1)*ones(size(bllst(i).out,1),1); + end + end + nlnk=size(connectmat,1) + for hhjj=1:length(bllst)+1 + for hh=1:length(bllst)+1 + ok=%t + for jj=1:nlnk + nnout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2)) + nnout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2)) + nnin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4)) + nnin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4)) + outtyp = bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) + intyp = bllst(connectmat(jj,3)).intyp(connectmat(jj,4)) + + //first case : types of source and + // target ports are explicitly informed + // with positive types + if (intyp>0 & outtyp>0) then + //if types of source and target port doesn't match and aren't double and complex + //then call bad_connection, set flag ok to false and exit + + if intyp<>outtyp then + if (intyp==1 & outtyp==2) then + bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=2; + elseif (intyp==2 & outtyp==1) then + bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))=2; + else + bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),.. + nnout,outtyp,.. + corinv(connectmat(jj,3)),connectmat(jj,4),.. + nnin,intyp,1) + ok=%f; + return + end + end + + //second case : type of source port is + // positive and type of + // target port is negative + elseif(outtyp>0&intyp<0) then + //find vector of input ports of target block with + //type equal to intyp + //and assign it to outtyp + ww=find(bllst(connectmat(jj,3)).intyp==intyp) + bllst(connectmat(jj,3)).intyp(ww)=outtyp + + //find vector of output ports of target block with + //type equal to intyp + //and assign it to outtyp + ww=find(bllst(connectmat(jj,3)).outtyp==intyp) + bllst(connectmat(jj,3)).outtyp(ww)=outtyp + + //third case : type of source port is + // negative and type of + // target port is positive + elseif(outtyp<0&intyp>0) then + //find vector of output ports of source block with + //type equal to outtyp + //and assign it to intyp + ww=find(bllst(connectmat(jj,1)).outtyp==outtyp) + bllst(connectmat(jj,1)).outtyp(ww)=intyp + + //find vector of input ports of source block with + //type equal to size outtyp + //and assign it to intyp + ww=find(bllst(connectmat(jj,1)).intyp==outtyp) + bllst(connectmat(jj,1)).intyp(ww)=intyp + + + //fourth (& last) case : type of both source + // and target port are negatives + else + ok=%f //set flag ok to false + end + end + if ok then return, end //if ok is set true then exit adjust_typ + end + //if failed then display message + messagebox(msprintf(_("Not enough information to find port type.\n"+.. + "I will try to find the problem.")),"modal","info"); + findflag=%f + for jj=1:nlnk + nouttyp=bllst(connectmat(jj,1)).outtyp(connectmat(jj,2)) + nintyp=bllst(connectmat(jj,3)).intyp(connectmat(jj,4)) + + //loop on the two dimensions of source/target port + //only case : target and source ports are both + // negatives or null + if nouttyp<=0 & nintyp<=0 then + findflag=%t; + // + inouttyp=under_connection(corinv(connectmat(jj,1)),connectmat(jj,2),nouttyp,.. + corinv(connectmat(jj,3)),connectmat(jj,4),nintyp,2) + // + if inouttyp<1|inouttyp>8 then ok=%f;return;end + // + ww=find(bllst(connectmat(jj,1)).outtyp==nouttyp) + bllst(connectmat(jj,1)).outtyp(ww)=inouttyp + + // + ww=find(bllst(connectmat(jj,1)).intyp==nouttyp) + bllst(connectmat(jj,1)).intyp(ww)=inouttyp + + ww=find(bllst(connectmat(jj,3)).intyp==nintyp) + bllst(connectmat(jj,3)).intyp(ww)=inouttyp + // + ww=find(bllst(connectmat(jj,3)).outtyp==nintyp) + bllst(connectmat(jj,3)).outtyp(ww)=inouttyp + + // + end + end + //if failed then display message + if ~findflag then + messagebox(msprintf(_("I cannot find a link with undetermined size.\n"+.. + "My guess is that you have a block with unconnected \n"+.. + "undetermined types.")),"modal","error"); + ok=%f;return; + end + end endfunction + diff --git a/scilab/modules/scicos/macros/scicos_scicos/scicos_model.sci b/scilab/modules/scicos/macros/scicos_scicos/scicos_model.sci index 21496ad..f4a4fd2 100644 --- a/scilab/modules/scicos/macros/scicos_scicos/scicos_model.sci +++ b/scilab/modules/scicos/macros/scicos_scicos/scicos_model.sci @@ -20,36 +20,37 @@ // function model=scicos_model(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,... - v17,v18,v19,v20,v21,v22,v23,v24,v25,v26) + v17,v18,v19,v20,v21,v22,v23,v24,v25,v26) - //initialisation de model mlist - if exists('sim','local')==0 then sim='',end - if exists('in','local')==0 then in=[],end - if exists('in2','local')==0 then in2=[],end - if exists('intyp','local')==0 then intyp=1,end - if exists('out','local')==0 then out=[],end - if exists('out2','local')==0 then out2=[],end - if exists('outtyp','local')==0 then outtyp=1,end - if exists('evtin','local')==0 then evtin=[],end - if exists('evtout','local')==0 then evtout=[],end - if exists('state','local')==0 then state=[],end - if exists('dstate','local')==0 then dstate=[],end - if exists('odstate','local')==0 then odstate=list(),end - if exists('opar','local')==0 then opar=list(),end - if exists('rpar','local')==0 then rpar=[],end - if exists('ipar','local')==0 then ipar=[],end - if exists('blocktype','local')==0 then blocktype='c',end - if exists('firing','local')==0 then firing=[],end - if exists('dep_ut','local')==0 then dep_ut=[%f %f],end - if exists('label','local')==0 then label='',end - if exists('nzcross','local')==0 then nzcross=0,end - if exists('nmode','local')==0 then nmode=0,end - if exists('equations','local')==0 then equations=list(),end + //initialisation de model mlist + if exists("sim","local")==0 then sim="",end + if exists("in","local")==0 then in=[],end + if exists("in2","local")==0 then in2=[],end + if exists("intyp","local")==0 then intyp=1,end + if exists("out","local")==0 then out=[],end + if exists("out2","local")==0 then out2=[],end + if exists("outtyp","local")==0 then outtyp=1,end + if exists("evtin","local")==0 then evtin=[],end + if exists("evtout","local")==0 then evtout=[],end + if exists("state","local")==0 then state=[],end + if exists("dstate","local")==0 then dstate=[],end + if exists("odstate","local")==0 then odstate=list(),end + if exists("opar","local")==0 then opar=list(),end + if exists("rpar","local")==0 then rpar=[],end + if exists("ipar","local")==0 then ipar=[],end + if exists("blocktype","local")==0 then blocktype="c",end + if exists("firing","local")==0 then firing=[],end + if exists("dep_ut","local")==0 then dep_ut=[%f %f],end + if exists("label","local")==0 then label="",end + if exists("nzcross","local")==0 then nzcross=0,end + if exists("nmode","local")==0 then nmode=0,end + if exists("equations","local")==0 then equations=list(),end - model=mlist(['model','sim','in','in2','intyp','out','out2','outtyp',... - 'evtin','evtout','state','dstate','odstate','rpar','ipar','opar',... - 'blocktype','firing','dep_ut','label','nzcross',.. - 'nmode','equations'],.. - sim,in,in2,intyp,out,out2,outtyp,evtin,evtout,state,dstate,odstate,.. - rpar,ipar,opar,blocktype,firing,dep_ut,label,nzcross,nmode,equations) + model=mlist(["model","sim","in","in2","intyp","out","out2","outtyp",... + "evtin","evtout","state","dstate","odstate","rpar","ipar","opar",... + "blocktype","firing","dep_ut","label","nzcross",.. + "nmode","equations"],.. + sim,in,in2,intyp,out,out2,outtyp,evtin,evtout,state,dstate,odstate,.. + rpar,ipar,opar,blocktype,firing,dep_ut,label,nzcross,nmode,equations) endfunction + diff --git a/scilab/modules/scicos/macros/scicos_scicos/scicos_sim.sci b/scilab/modules/scicos/macros/scicos_scicos/scicos_sim.sci index 04132bc..9376ed1 100644 --- a/scilab/modules/scicos/macros/scicos_scicos/scicos_sim.sci +++ b/scilab/modules/scicos/macros/scicos_scicos/scicos_sim.sci @@ -20,55 +20,56 @@ // function sim=scicos_sim(v1,v2,v3,v4,v5,.. - v6,v7,v8,v9,v10,.. - v11,v12,v13,v14,v15,.. - v16,v17,v18,v19,v20,.. - v21,v22,v23,v24,v25,.. - v26,v27,v28,v29,v30,.. - v31,v32,v33,v34,v35,.. - v36,v37,v38,v39,v40) - if exists('funs','local')==0 then funs=[],end - if exists('xptr','local')==0 then xptr=[],end - if exists('zptr','local')==0 then zptr=[],end - if exists('ozptr','local')==0 then ozptr=[],end - if exists('zcptr','local')==0 then zcptr=[],end - if exists('inpptr','local')==0 then inpptr=[],end - if exists('outptr','local')==0 then outptr=[],end - if exists('inplnk','local')==0 then inplnk=[],end - if exists('outlnk','local')==0 then outlnk=[],end - if exists('rpar','local')==0 then rpar=[],end - if exists('rpptr','local')==0 then rpptr=[],end - if exists('ipar','local')==0 then ipar=[],end - if exists('ipptr','local')==0 then ipptr=[],end - if exists('opar','local')==0 then opar=list(),end - if exists('opptr','local')==0 then opptr=[],end - if exists('clkptr','local')==0 then clkptr=[],end - if exists('ordptr','local')==0 then ordptr=[],end - if exists('execlk','local')==0 then execlk=[],end - if exists('ordclk','local')==0 then ordclk=[],end - if exists('cord','local')==0 then cord=[],end - if exists('oord','local')==0 then oord=[],end - if exists('zord','local')==0 then zord=[],end - if exists('critev','local')==0 then critev=[],end - if exists('nb','local')==0 then nb=[],end - if exists('ztyp','local')==0 then ztyp=[],end - if exists('nblk','local')==0 then nblk=[],end - if exists('ndcblk','local')==0 then ndcblk=[],end - if exists('subscr','local')==0 then subscr=[],end - if exists('funtyp','local')==0 then funtyp=[],end - if exists('iord','local')==0 then iord=[],end - if exists('labels','local')==0 then labels=[],end - if exists('modptr','local')==0 then modptr=[],end - sim=tlist(['scs','funs','xptr','zptr','ozptr',.. - 'zcptr','inpptr','outptr','inplnk','outlnk','rpar',.. - 'rpptr','ipar','ipptr','opar','opptr',.. - 'clkptr','ordptr','execlk','ordclk','cord','oord','zord',.. - 'critev','nb','ztyp','nblk','ndcblk','subscr','funtyp',.. - 'iord','labels','modptr'],.. - funs,xptr,zptr,ozptr,zcptr,inpptr,.. - outptr,inplnk,outlnk,rpar,rpptr,ipar,ipptr,.. - opar,opptr,clkptr,ordptr,.. - execlk,ordclk,cord,oord,zord,.. - critev,nb,ztyp,nblk,ndcblk,.. - subscr,funtyp,iord,labels,modptr) + v6,v7,v8,v9,v10,.. + v11,v12,v13,v14,v15,.. + v16,v17,v18,v19,v20,.. + v21,v22,v23,v24,v25,.. + v26,v27,v28,v29,v30,.. + v31,v32,v33,v34,v35,.. + v36,v37,v38,v39,v40) + if exists("funs","local")==0 then funs=[],end + if exists("xptr","local")==0 then xptr=[],end + if exists("zptr","local")==0 then zptr=[],end + if exists("ozptr","local")==0 then ozptr=[],end + if exists("zcptr","local")==0 then zcptr=[],end + if exists("inpptr","local")==0 then inpptr=[],end + if exists("outptr","local")==0 then outptr=[],end + if exists("inplnk","local")==0 then inplnk=[],end + if exists("outlnk","local")==0 then outlnk=[],end + if exists("rpar","local")==0 then rpar=[],end + if exists("rpptr","local")==0 then rpptr=[],end + if exists("ipar","local")==0 then ipar=[],end + if exists("ipptr","local")==0 then ipptr=[],end + if exists("opar","local")==0 then opar=list(),end + if exists("opptr","local")==0 then opptr=[],end + if exists("clkptr","local")==0 then clkptr=[],end + if exists("ordptr","local")==0 then ordptr=[],end + if exists("execlk","local")==0 then execlk=[],end + if exists("ordclk","local")==0 then ordclk=[],end + if exists("cord","local")==0 then cord=[],end + if exists("oord","local")==0 then oord=[],end + if exists("zord","local")==0 then zord=[],end + if exists("critev","local")==0 then critev=[],end + if exists("nb","local")==0 then nb=[],end + if exists("ztyp","local")==0 then ztyp=[],end + if exists("nblk","local")==0 then nblk=[],end + if exists("ndcblk","local")==0 then ndcblk=[],end + if exists("subscr","local")==0 then subscr=[],end + if exists("funtyp","local")==0 then funtyp=[],end + if exists("iord","local")==0 then iord=[],end + if exists("labels","local")==0 then labels=[],end + if exists("modptr","local")==0 then modptr=[],end + sim=tlist(["scs","funs","xptr","zptr","ozptr",.. + "zcptr","inpptr","outptr","inplnk","outlnk","rpar",.. + "rpptr","ipar","ipptr","opar","opptr",.. + "clkptr","ordptr","execlk","ordclk","cord","oord","zord",.. + "critev","nb","ztyp","nblk","ndcblk","subscr","funtyp",.. + "iord","labels","modptr"],.. + funs,xptr,zptr,ozptr,zcptr,inpptr,.. + outptr,inplnk,outlnk,rpar,rpptr,ipar,ipptr,.. + opar,opptr,clkptr,ordptr,.. + execlk,ordclk,cord,oord,zord,.. + critev,nb,ztyp,nblk,ndcblk,.. + subscr,funtyp,iord,labels,modptr) endfunction + diff --git a/scilab/modules/scicos/sci_gateway/c/sci_model2blk.c b/scilab/modules/scicos/sci_gateway/c/sci_model2blk.c index cfb6360..f7333d6 100644 --- a/scilab/modules/scicos/sci_gateway/c/sci_model2blk.c +++ b/scilab/modules/scicos/sci_gateway/c/sci_model2blk.c @@ -185,13 +185,19 @@ int sci_model2blk(char *fname, unsigned long fname_len) C2F(cha1).buf[len_str] = '\0'; /* search fun ptr of the comput func in the scilab func table */ ifun = C2F(funnum)(C2F(cha1).buf); - if (ifun > 0) lfunpt = ifun; + if (ifun > 0) + { + lfunpt = ifun; + } else { C2F(namstr)(id, &il_sim[6], &len_str, (j = 0, &j)); C2F(com).fin = 0; C2F(funs)(id); - if ((C2F(com).fun == -1) | (C2F(com).fun == -2)) lfunpt = -*Lstk(C2F(com).fin); + if ((C2F(com).fun == -1) | (C2F(com).fun == -2)) + { + lfunpt = -*Lstk(C2F(com).fin); + } else { lfunpt = 0; @@ -265,7 +271,7 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.nin = mh * nh; Block.insz = NULL; Block.inptr = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { /* check value of in */ for (i = 0; i < Block.nin; i++) @@ -331,15 +337,42 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.insz[i] = (int) * ((double *)(&ilh[4]) + i); Block.insz[Block.nin + i] = (int) * ((double *)(&ilh2[4]) + i); type = *((double *)(&ilh3[4]) + i); - if (type == 1) Block.insz[2 * Block.nin + i] = 10; - else if (type == 2) Block.insz[2 * Block.nin + i] = 11; - else if (type == 3) Block.insz[2 * Block.nin + i] = 84; - else if (type == 4) Block.insz[2 * Block.nin + i] = 82; - else if (type == 5) Block.insz[2 * Block.nin + i] = 81; - else if (type == 6) Block.insz[2 * Block.nin + i] = 814; - else if (type == 7) Block.insz[2 * Block.nin + i] = 812; - else if (type == 8) Block.insz[2 * Block.nin + i] = 811; - else Block.insz[2 * Block.nin + i] = 10; + if (type == 1) + { + Block.insz[2 * Block.nin + i] = 10; + } + else if (type == 2) + { + Block.insz[2 * Block.nin + i] = 11; + } + else if (type == 3) + { + Block.insz[2 * Block.nin + i] = 84; + } + else if (type == 4) + { + Block.insz[2 * Block.nin + i] = 82; + } + else if (type == 5) + { + Block.insz[2 * Block.nin + i] = 81; + } + else if (type == 6) + { + Block.insz[2 * Block.nin + i] = 814; + } + else if (type == 7) + { + Block.insz[2 * Block.nin + i] = 812; + } + else if (type == 8) + { + Block.insz[2 * Block.nin + i] = 811; + } + else + { + Block.insz[2 * Block.nin + i] = 10; + } } } else @@ -359,7 +392,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) case 10 : if ((Block.inptr[i] = (double *) MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(double))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -375,7 +411,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (double *) \ MALLOC(2 * Block.insz[i] * Block.insz[Block.nin + i] * sizeof(double))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -391,7 +430,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (long *) \ MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(long))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -407,7 +449,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (short *) \ MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(short))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -423,7 +468,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (char *) \ MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(char))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -439,7 +487,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (unsigned long *) \ MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(unsigned long))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -455,7 +506,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (unsigned short *) \ MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(unsigned short))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -471,7 +525,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.inptr[i] = (unsigned char *) \ MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(unsigned char))) == NULL) { - for (j = 0; j < i; j++) FREE(Block.inptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -496,7 +553,7 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.nout = mh * nh; Block.outsz = NULL; Block.outptr = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { /* check value of out */ for (i = 0; i < Block.nout; i++) @@ -505,7 +562,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) { Scierror(888, _("%s : Undetermined Size. out(%d)=%d. Please adjust your model.\n"), \ fname, i + 1, (int)(*((double *)(&ilh[4]) + i))); - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); return 0; @@ -515,7 +575,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outsz = (int *) MALLOC(Block.nout * 3 * sizeof(int))) == NULL) { Scierror(888, _("%s : Allocation error.\n"), fname); - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); return 0; @@ -524,7 +587,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr = (void **) MALLOC(Block.nout * sizeof(void *))) == NULL) { FREE(Block.outsz); - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -542,7 +608,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) { Scierror(888, _("%s : Undetermined Size. out2(%d)=%d. Please adjust your model.\n"), \ fname, i + 1, (int)(*((double *)(&ilh2[4]) + i))); - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.insz); FREE(Block.inptr); FREE(Block.outptr); @@ -576,15 +645,42 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.outsz[i] = (int) * ((double *)(&ilh[4]) + i); Block.outsz[Block.nout + i] = (int) * ((double *)(&ilh2[4]) + i); type = *((double *)(&ilh3[4]) + i); - if (type == 1) Block.outsz[2 * Block.nout + i] = 10; - else if (type == 2) Block.outsz[2 * Block.nout + i] = 11; - else if (type == 3) Block.outsz[2 * Block.nout + i] = 84; - else if (type == 4) Block.outsz[2 * Block.nout + i] = 82; - else if (type == 5) Block.outsz[2 * Block.nout + i] = 81; - else if (type == 6) Block.outsz[2 * Block.nout + i] = 814; - else if (type == 7) Block.outsz[2 * Block.nout + i] = 812; - else if (type == 8) Block.outsz[2 * Block.nout + i] = 811; - else Block.outsz[2 * Block.nout + i] = 10; + if (type == 1) + { + Block.outsz[2 * Block.nout + i] = 10; + } + else if (type == 2) + { + Block.outsz[2 * Block.nout + i] = 11; + } + else if (type == 3) + { + Block.outsz[2 * Block.nout + i] = 84; + } + else if (type == 4) + { + Block.outsz[2 * Block.nout + i] = 82; + } + else if (type == 5) + { + Block.outsz[2 * Block.nout + i] = 81; + } + else if (type == 6) + { + Block.outsz[2 * Block.nout + i] = 814; + } + else if (type == 7) + { + Block.outsz[2 * Block.nout + i] = 812; + } + else if (type == 8) + { + Block.outsz[2 * Block.nout + i] = 811; + } + else + { + Block.outsz[2 * Block.nout + i] = 10; + } } } else @@ -604,10 +700,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (double *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -623,10 +725,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (double *) \ MALLOC(2 * Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -642,10 +750,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (long *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(long))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -661,10 +775,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (short *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(short))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -680,10 +800,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (char *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -699,10 +825,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (unsigned long *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(unsigned long))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -718,10 +850,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (unsigned short *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(unsigned short))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -737,10 +875,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.outptr[i] = (unsigned char *) \ MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(unsigned char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < i; j++) FREE(Block.outptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -767,14 +911,20 @@ int sci_model2blk(char *fname, unsigned long fname_len) nh = ilh[2]; Block.nevout = mh * nh; Block.evout = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { if ((Block.evout = (double *) MALLOC(Block.nevout * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -811,15 +961,21 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.xprop = NULL; Block.xd = NULL; Block.res = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { /* x */ if ((Block.x = (double *) MALLOC(Block.nx * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -835,10 +991,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) /* xd */ if ((Block.xd = (double *) MALLOC(Block.nx * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -854,10 +1016,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) /* xprop */ if ((Block.xprop = (int *) MALLOC(Block.nx * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -875,10 +1043,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) /*if (blktyp>10000) {*/ if ((Block.res = (double *) MALLOC(Block.nx * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -905,14 +1079,20 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.nz = mh * nh; Block.z = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { if ((Block.z = (double *) MALLOC(Block.nz * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -940,14 +1120,20 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.ozsz = NULL; Block.oztyp = NULL; Block.ozptr = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { if ((Block.ozsz = (int *) MALLOC(2 * Block.noz * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -962,10 +1148,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.oztyp = (int *) MALLOC(Block.noz * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -981,10 +1173,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.ozptr = (void **) MALLOC(Block.noz * sizeof(void *))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1013,10 +1211,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 10; if ((Block.ozptr[i] = (double *) MALLOC(mh2 * nh2 * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1027,7 +1231,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1042,10 +1249,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 11; if ((Block.ozptr[i] = (double *) MALLOC(2 * mh2 * nh2 * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1056,7 +1269,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1074,10 +1290,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 84; if ((Block.ozptr[i] = (long *) MALLOC(mh2 * nh2 * sizeof(long))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1088,7 +1310,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1103,10 +1328,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 82; if ((Block.ozptr[i] = (short *) MALLOC(mh2 * nh2 * sizeof(short))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1117,7 +1348,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1132,10 +1366,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 81; if ((Block.ozptr[i] = (char *) MALLOC(mh2 * nh2 * sizeof(char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1146,7 +1386,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1161,10 +1404,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 814; if ((Block.ozptr[i] = (unsigned long *) MALLOC(mh2 * nh2 * sizeof(unsigned long))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1175,7 +1424,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1190,10 +1442,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 812; if ((Block.ozptr[i] = (unsigned short *) MALLOC(mh2 * nh2 * sizeof(unsigned short))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1204,7 +1462,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1219,10 +1480,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oztyp[i] = 811; if ((Block.ozptr[i] = (unsigned char *) MALLOC(mh2 * nh2 * sizeof(unsigned char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1233,7 +1500,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < i; j++) FREE(Block.ozptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1255,14 +1525,20 @@ int sci_model2blk(char *fname, unsigned long fname_len) nh = ilh[2]; Block.nrpar = mh * nh; Block.rpar = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { if ((Block.rpar = (double *) MALLOC(Block.nrpar * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1273,7 +1549,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1291,14 +1570,20 @@ int sci_model2blk(char *fname, unsigned long fname_len) nh = ilh[2]; Block.nipar = mh * nh; Block.ipar = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { if ((Block.ipar = (int *) MALLOC(Block.nipar * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1309,7 +1594,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); Scierror(888, _("%s : Allocation error.\n"), fname); return 0; @@ -1331,14 +1619,20 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.oparsz = NULL; Block.opartyp = NULL; Block.oparptr = NULL; - if (mh*nh != 0) + if (mh * nh != 0) { if ((Block.oparsz = (int *) MALLOC(2 * Block.nopar * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1349,7 +1643,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -1358,10 +1655,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.opartyp = (int *) MALLOC(Block.nopar * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1372,7 +1675,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); @@ -1382,10 +1688,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) if ((Block.oparptr = (void **) MALLOC(Block.nopar * sizeof(void *))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1396,7 +1708,10 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); @@ -1419,10 +1734,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 10; if ((Block.oparptr[i] = (double *) MALLOC(mh2 * nh2 * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1433,12 +1754,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1453,10 +1780,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 11; if ((Block.oparptr[i] = (double *) MALLOC(2 * mh2 * nh2 * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1467,12 +1800,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1491,10 +1830,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 84; if ((Block.oparptr[i] = (long *) MALLOC(mh2 * nh2 * sizeof(long))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1505,12 +1850,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1525,10 +1876,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 82; if ((Block.oparptr[i] = (short *) MALLOC(mh2 * nh2 * sizeof(short))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1539,12 +1896,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1559,10 +1922,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 81; if ((Block.oparptr[i] = (char *) MALLOC(mh2 * nh2 * sizeof(char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1573,12 +1942,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1593,10 +1968,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 814; if ((Block.oparptr[i] = (unsigned long *) MALLOC(mh2 * nh2 * sizeof(unsigned long))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1607,12 +1988,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1627,10 +2014,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 812; if ((Block.oparptr[i] = (unsigned short *) MALLOC(mh2 * nh2 * sizeof(unsigned short))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1641,12 +2034,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1661,10 +2060,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) Block.opartyp[i] = 811; if ((Block.oparptr[i] = (unsigned char *) MALLOC(mh2 * nh2 * sizeof(unsigned char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1675,12 +2080,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < i; j++) FREE(Block.oparptr[j]); + for (j = 0; j < i; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1701,17 +2112,23 @@ int sci_model2blk(char *fname, unsigned long fname_len) mh = ilh[1]; nh = ilh[2]; Block.label = ""; - if (mh*nh != 0) + if (mh * nh != 0) { len_str = ilh[5] - 1; if (len_str != 0) { if ((Block.label = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1722,12 +2139,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]); + for (j = 0; j < Block.nopar; j++) + { + FREE(Block.oparptr[j]); + } Scierror(888, _("%s : Allocation error.\n"), fname); return 0; } @@ -1749,10 +2172,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) { if ((Block.g = (double *) MALLOC(Block.ng * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1763,12 +2192,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]); + for (j = 0; j < Block.nopar; j++) + { + FREE(Block.oparptr[j]); + } FREE(Block.label); Scierror(888, _("%s : Allocation error.\n"), fname); return 0; @@ -1780,10 +2215,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) } if ((Block.jroot = (int *) MALLOC(Block.ng * sizeof(int))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1794,12 +2235,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]); + for (j = 0; j < Block.nopar; j++) + { + FREE(Block.oparptr[j]); + } FREE(Block.label); FREE(Block.g); Scierror(888, _("%s : Allocation error.\n"), fname); @@ -1824,10 +2271,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) { if ((Block.mode = (int *) MALLOC(Block.nmode * sizeof(double))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1838,12 +2291,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]); + for (j = 0; j < Block.nopar; j++) + { + FREE(Block.oparptr[j]); + } FREE(Block.label); FREE(Block.g); FREE(Block.jroot); @@ -1860,10 +2319,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) /* work */ if ((Block.work = (void **) MALLOC(sizeof(void *))) == NULL) { - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1874,12 +2339,18 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]); + for (j = 0; j < Block.nopar; j++) + { + FREE(Block.oparptr[j]); + } FREE(Block.label); FREE(Block.g); FREE(Block.jroot); @@ -1893,10 +2364,16 @@ int sci_model2blk(char *fname, unsigned long fname_len) ierr = createblklist(&Block, &ierr, -1, Block.type); - for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]); + for (j = 0; j < Block.nin; j++) + { + FREE(Block.inptr[j]); + } FREE(Block.inptr); FREE(Block.insz); - for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]); + for (j = 0; j < Block.nout; j++) + { + FREE(Block.outptr[j]); + } FREE(Block.outptr); FREE(Block.outsz); FREE(Block.evout); @@ -1906,13 +2383,22 @@ int sci_model2blk(char *fname, unsigned long fname_len) FREE(Block.z); FREE(Block.ozsz); FREE(Block.oztyp); - for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]); + for (j = 0; j < Block.noz; j++) + { + FREE(Block.ozptr[j]); + } FREE(Block.rpar); FREE(Block.ipar); FREE(Block.oparsz); FREE(Block.opartyp); - for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]); - if (len_str != 0) FREE(Block.label); + for (j = 0; j < Block.nopar; j++) + { + FREE(Block.oparptr[j]); + } + if (len_str != 0) + { + FREE(Block.label); + } FREE(Block.g); FREE(Block.jroot); FREE(Block.mode); @@ -1925,3 +2411,4 @@ int sci_model2blk(char *fname, unsigned long fname_len) return 0; } /*--------------------------------------------------------------------------*/ + diff --git a/scilab/modules/scicos/sci_gateway/c/sci_scicosim.c b/scilab/modules/scicos/sci_gateway/c/sci_scicosim.c index 9781154..8986d37 100644 --- a/scilab/modules/scicos/sci_gateway/c/sci_scicosim.c +++ b/scilab/modules/scicos/sci_gateway/c/sci_scicosim.c @@ -544,7 +544,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_xptr = (int *) (listentry(il_sim, 3)); m_xptr = il_sim_xptr[1]; n_xptr = il_sim_xptr[2]; - if (m_xptr*n_xptr == 0) + if (m_xptr * n_xptr == 0) { l_sim_xptr = NULL; } @@ -570,7 +570,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_zptr = (int *) (listentry(il_sim, 4)); m_zptr = il_sim_zptr[1]; n_zptr = il_sim_zptr[2]; - if (m_zptr*n_zptr == 0) + if (m_zptr * n_zptr == 0) { l_sim_zptr = NULL; } @@ -597,7 +597,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_ozptr = (int *) (listentry(il_sim, 5)); m_ozptr = il_sim_ozptr[1]; n_ozptr = il_sim_ozptr[2]; - if (m_ozptr*n_ozptr == 0) + if (m_ozptr * n_ozptr == 0) { l_sim_ozptr = NULL; } @@ -625,7 +625,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_zcptr = (int *) (listentry(il_sim, 6)); m_zcptr = il_sim_zcptr[1]; n_zcptr = il_sim_zcptr[2]; - if (m_zcptr*n_zcptr == 0) + if (m_zcptr * n_zcptr == 0) { l_sim_zcptr = NULL; } @@ -654,7 +654,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_inpptr = (int *) (listentry(il_sim, 7)); m_inpptr = il_sim_inpptr[1]; n_inpptr = il_sim_inpptr[2]; - if (m_inpptr*n_inpptr == 0) + if (m_inpptr * n_inpptr == 0) { l_sim_inpptr = NULL; } @@ -684,7 +684,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_outptr = (int *) (listentry(il_sim, 8)); m_outptr = il_sim_outptr[1]; n_outptr = il_sim_outptr[2]; - if (m_outptr*n_outptr == 0) + if (m_outptr * n_outptr == 0) { l_sim_outptr = NULL; } @@ -715,7 +715,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_inplnk = (int *) (listentry(il_sim, 9)); m_inplnk = il_sim_inplnk[1]; n_inplnk = il_sim_inplnk[2]; - if (m_inplnk*n_inplnk == 0) + if (m_inplnk * n_inplnk == 0) { l_sim_inplnk = NULL; } @@ -747,7 +747,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_outlnk = (int *) (listentry(il_sim, 10)); m_outlnk = il_sim_outlnk[1]; n_outlnk = il_sim_outlnk[2]; - if (m_outlnk*n_outlnk == 0) + if (m_outlnk * n_outlnk == 0) { l_sim_outlnk = NULL; } @@ -780,7 +780,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_rpar = (int *) (listentry(il_sim, 11)); m_rpar = il_sim_rpar[1]; n_rpar = il_sim_rpar[2]; - if (m_rpar*n_rpar == 0) + if (m_rpar * n_rpar == 0) { l_sim_rpar = NULL; } @@ -793,7 +793,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_rpptr = (int *) (listentry(il_sim, 12)); m_rpptr = il_sim_rpptr[1]; n_rpptr = il_sim_rpptr[2]; - if (m_rpptr*n_rpptr == 0) + if (m_rpptr * n_rpptr == 0) { l_sim_rpptr = NULL; } @@ -827,7 +827,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_ipar = (int *) (listentry(il_sim, 13)); m_ipar = il_sim_ipar[1]; n_ipar = il_sim_ipar[2]; - if (m_ipar*n_ipar == 0) + if (m_ipar * n_ipar == 0) { l_sim_ipar = NULL; } @@ -862,7 +862,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_ipptr = (int *) (listentry(il_sim, 14)); m_ipptr = il_sim_ipptr[1]; n_ipptr = il_sim_ipptr[2]; - if (m_ipptr*n_ipptr == 0) + if (m_ipptr * n_ipptr == 0) { l_sim_ipptr = NULL; } @@ -921,7 +921,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_opptr = (int *) (listentry(il_sim, 16)); m_opptr = il_sim_opptr[1]; n_opptr = il_sim_opptr[2]; - if (m_opptr*n_opptr == 0) + if (m_opptr * n_opptr == 0) { l_sim_opptr = NULL; } @@ -958,7 +958,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_clkptr = (int *) (listentry(il_sim, 17)); m_clkptr = il_sim_clkptr[1]; n_clkptr = il_sim_clkptr[2]; - if (m_clkptr*n_clkptr == 0) + if (m_clkptr * n_clkptr == 0) { l_sim_clkptr = NULL; } @@ -1029,7 +1029,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_execlk = (int *) (listentry(il_sim, 19)); m_execlk = il_sim_execlk[1]; n_execlk = il_sim_execlk[2]; - if (m_execlk*n_execlk == 0) + if (m_execlk * n_execlk == 0) { l_sim_execlk = NULL; } @@ -1069,7 +1069,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_ordclk = (int *) (listentry(il_sim, 20)); m_ordclk = il_sim_ordclk[1]; n_ordclk = il_sim_ordclk[2]; - if (m_ordclk*n_ordclk == 0) + if (m_ordclk * n_ordclk == 0) { l_sim_ordclk = NULL; } @@ -1110,7 +1110,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_cord = (int *) (listentry(il_sim, 21)); m_cord = il_sim_cord[1]; n_cord = il_sim_cord[2]; - if (m_cord*n_cord == 0) + if (m_cord * n_cord == 0) { l_sim_cord = NULL; } @@ -1152,7 +1152,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_oord = (int *) (listentry(il_sim, 22)); m_oord = il_sim_oord[1]; n_oord = il_sim_oord[2]; - if (m_oord*n_oord == 0) + if (m_oord * n_oord == 0) { l_sim_oord = NULL; } @@ -1195,7 +1195,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_zord = (int *) (listentry(il_sim, 23)); m_zord = il_sim_zord[1]; n_zord = il_sim_zord[2]; - if (m_zord*n_zord == 0) + if (m_zord * n_zord == 0) { l_sim_zord = NULL; } @@ -1239,7 +1239,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_critev = (int *) (listentry(il_sim, 24)); m_critev = il_sim_critev[1]; n_critev = il_sim_critev[2]; - if (m_critev*n_critev == 0) + if (m_critev * n_critev == 0) { l_sim_critev = NULL; } @@ -1451,7 +1451,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_subscr = (int *) (listentry(il_sim, 29)); m_subscr = il_sim_subscr[1]; n_subscr = il_sim_subscr[2]; - if (m_subscr*n_subscr == 0) + if (m_subscr * n_subscr == 0) { l_sim_subscr = NULL; } @@ -1545,7 +1545,7 @@ int sci_scicosim(char *fname, unsigned long fname_len) il_sim_iord = (int *) (listentry(il_sim, 31)); m_iord = il_sim_iord[1]; n_iord = il_sim_iord[2]; - if (m_iord*n_iord == 0) + if (m_iord * n_iord == 0) { l_sim_iord = NULL; } @@ -2660,3 +2660,4 @@ int sci_scicosim(char *fname, unsigned long fname_len) return 0; } /*--------------------------------------------------------------------------*/ + diff --git a/scilab/modules/scicos/src/c/createblklist.c b/scilab/modules/scicos/src/c/createblklist.c index f6b6b30..09fe18e1 100644 --- a/scilab/modules/scicos/src/c/createblklist.c +++ b/scilab/modules/scicos/src/c/createblklist.c @@ -26,336 +26,491 @@ #include "var2sci.h" #include "MALLOC.h" /*--------------------------------------------------------------------------*/ -extern void str2sci(char** x,int n,int m); /* core/src/c/str2sci.h */ +extern void str2sci(char** x, int n, int m); /* core/src/c/str2sci.h */ extern void C2F(itosci)(); extern void C2F(dtosci)(); extern int C2F(scierr)(); extern void C2F(vvtosci)(); -extern int C2F(mktlist)(); +extern int C2F(mktlist)(); /*--------------------------------------------------------------------------*/ int createblklist(scicos_block *Blocks, int *ierr, int flag_imp, int funtyp) { - /*local variable declaration*/ - int j,k; - int nu,mu,ny,my; - int u_typ,y_typ; - int oz_typ,opar_typ; - - /*variable used when imp_flag>=0*/ - int nv,mv; /* length of data */ - int nblk,ng; /* to store number of blocks and number of zero cross. */ - void *ptr; /* ptr for data comming from import structure */ - int *ptr_int; /* ptr to store ptr on integer */ - double *ptr_double; /* ptr to store ptr on double */ - int *xptr=NULL; /* to retrieve xptr by import and zcptr of scicos_blocks */ - int *zcptr=NULL; - double *x=NULL; /* ptr for x, xd and g for scicos_blocks */ - double *xd=NULL; - double *g=NULL; - - /* set length of block list -please update me- */ - static int nblklst=40; - /* set string of first element of scilab Blocks tlist -please update me- */ - static char *str_blklst[]={ "scicos_block", "nevprt" , "funpt" , "type" , - "scsptr" , "nz" , "z" , "noz" , - "ozsz" , "oztyp" , "oz" , "nx" , - "x" , "xd" , "res" , "nin" , - "insz" , "inptr" , "nout" , "outsz" , - "outptr" , "nevout" , "evout" , "nrpar" , - "rpar" , "nipar" , "ipar" , "nopar" , - "oparsz" , "opartyp" , "opar" , "ng" , - "g" , "ztyp" , "jroot" , "label" , - "work" , "nmode" , "mode" , "xprop"}; - - /* char ptr for str2sci - see below - */ - char **str1; - - /* set nblk, x, xd ptr coming from import strucuture, - * if flag_imp >=0 - */ - if (flag_imp>=0) - { - /*retrieve nblk by import structure*/ - strcpy(C2F(cha1).buf,"nblk"); - *ierr=getscicosvarsfromimport(C2F(cha1).buf,&ptr,&nv,&mv); - if (*ierr==0) return 0; - ptr_int = (int *) ptr; - nblk = *ptr_int; - - /* retrieve ng by import structure */ - strcpy(C2F(cha1).buf,"ng"); - *ierr=getscicosvarsfromimport(C2F(cha1).buf,&ptr,&nv,&mv); - ptr_int = (int *) ptr; /* cast void* ptr to int* ptr */ - ng = *ptr_int; - - /*retrieve xptr by import structure*/ - strcpy(C2F(cha1).buf,"xptr"); - *ierr=getscicosvarsfromimport(C2F(cha1).buf,&ptr,&nv,&mv); - if (*ierr==0) return 0; - ptr_int = (int *) ptr; - xptr = ptr_int; - - /*retrieve zcptr by import structure*/ - strcpy(C2F(cha1).buf,"zcptr"); - *ierr=getscicosvarsfromimport(C2F(cha1).buf,&ptr,&nv,&mv); - ptr_int = (int *) ptr; - zcptr = ptr_int; - - /*retrieve x and xd by import structure*/ - strcpy(C2F(cha1).buf,"x"); - *ierr=getscicosvarsfromimport(C2F(cha1).buf,&ptr,&nv,&mv); - if (*ierr==0) return 0; - ptr_double = (double *) ptr; - x = ptr_double; - xd = &x[xptr[nblk]-1]; - - /*retrieve g by import structure*/ - strcpy(C2F(cha1).buf,"g"); - *ierr=getscicosvarsfromimport(C2F(cha1).buf,&ptr,&nv,&mv); - ptr_double = (double *) ptr; - g = ptr_double; - } - - /**************************** - * create scilab tlist Blocks - ****************************/ - /* 1 - scicos_block */ - str2sci(str_blklst,1,nblklst); - - /* 2 - nevprt */ - C2F(itosci)(&Blocks[0].nevprt,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 3 - funpt */ - if (sizeof(voidg) >= sizeof(double)) - { - // store N double values as the function pointer value - j = sizeof(voidg) / sizeof(double); - } - else - { - // push at least one double - j = 1; - } - C2F(dtosci)(&Blocks[0].funpt, &j, (k = 1, &k)); - - /* 4 - type */ - C2F(itosci)(&Blocks[0].type,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 5 - scsptr */ - C2F(itosci)(&Blocks[0].scsptr,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 6 - nz */ - C2F(itosci)(&Blocks[0].nz,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 7 - z */ - if(Blocks[0].scsptr>0) - { - C2F(vvtosci)(Blocks[0].z,&Blocks[0].nz); - if (C2F(scierr)()!=0) return 0; - } - else - { - *ierr=var2sci(Blocks[0].z,Blocks[0].nz,1,SCSREAL_N); - if (*ierr!=0) return 0; - } - - /* 8 - noz */ - C2F(itosci)(&Blocks[0].noz,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 9 - ozsz */ - C2F(itosci)(Blocks[0].ozsz,(j=Blocks[0].noz,&j),(k=2,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 10 - oztyp */ - C2F(itosci)(Blocks[0].oztyp,(j=Blocks[0].noz,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 11 - oz */ - for (k=0;k=0) *ierr=var2sci(&x[xptr[flag_imp]-1],Blocks[0].nx,1,SCSREAL_N); - else *ierr=var2sci(Blocks[0].x,Blocks[0].nx,1,SCSREAL_N); - if (*ierr!=0) return 0; - - /* 14 - xd */ - if (flag_imp>=0) *ierr=var2sci(&xd[xptr[flag_imp]-1],Blocks[0].nx,1,SCSREAL_N); - else *ierr=var2sci(Blocks[0].xd,Blocks[0].nx,1,SCSREAL_N); - if (*ierr!=0) return 0; - - /* 15 - res */ - *ierr=var2sci(Blocks[0].res,Blocks[0].nx,1,SCSREAL_N); - if (*ierr!=0) return 0; - - /* 16 - nin */ - C2F(itosci)(&Blocks[0].nin,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 17 - insz */ - C2F(itosci)(Blocks[0].insz,(j=3*Blocks[0].nin,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 18 - inptr */ - for (k=0;k0) - { - C2F(vvtosci)(Blocks[0].rpar,&Blocks[0].nrpar); - if (C2F(scierr)()!=0) return 0; - } - else - { - *ierr=var2sci(Blocks[0].rpar,Blocks[0].nrpar,1,SCSREAL_N); - if (*ierr!=0) return 0; - } - - /* 26 - nipar */ - C2F(itosci)(&Blocks[0].nipar,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 27 - ipar */ - C2F(itosci)(Blocks[0].ipar,(j=Blocks[0].nipar,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 28 - nopar */ - C2F(itosci)(&Blocks[0].nopar,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 29 - oparsz */ - C2F(itosci)(Blocks[0].oparsz,(j=Blocks[0].nopar,&j),(k=2,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 30 - opartyp */ - C2F(itosci)(Blocks[0].opartyp,(j=Blocks[0].nopar,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 31 - opar */ - for (k=0;k=0) *ierr=var2sci(&g[zcptr[flag_imp]-1],Blocks[0].ng,1,SCSREAL_N); - else *ierr=var2sci(Blocks[0].g,Blocks[0].ng,1,SCSREAL_N); - if (*ierr!=0) return 0; - - /* 34 - ztyp */ - C2F(itosci)(&Blocks[0].ztyp,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 35 - jroot */ - C2F(itosci)(Blocks[0].jroot,(j=Blocks[0].ng,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 36 - label */ - if ((str1=MALLOC(sizeof(char*))) ==NULL ) return 0; - if ((str1[0]=MALLOC(sizeof(char)*(strlen(Blocks[0].label)+1))) ==NULL ) - { - FREE(str1); - return 0; - } - (str1[0])[strlen(Blocks[0].label)]='\0'; - strncpy(str1[0],Blocks[0].label,strlen(Blocks[0].label)); - str2sci(str1,1,1); - FREE(str1[0]); - FREE(str1); - if (C2F(scierr)()!=0) return 0; - - /* 37 - work*/ - C2F(itosci)(&Blocks[0].work,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 38 - nmode*/ - C2F(itosci)(&Blocks[0].nmode,(j=1,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 39 - mode */ - C2F(itosci)(Blocks[0].mode,(j=Blocks[0].nmode,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - /* 40 - xprop */ - C2F(itosci)(Blocks[0].xprop,(j=Blocks[0].nx,&j),(k=1,&k)); - if (C2F(scierr)()!=0) return 0; - - C2F(mktlist)(&nblklst); /*create Blocks list*/ - if (C2F(scierr)()!=0) return 0; - - /*return 1 if succeeded */ - return 1; + /*local variable declaration*/ + int j, k; + int nu, mu, ny, my; + int u_typ, y_typ; + int oz_typ, opar_typ; + + /*variable used when imp_flag>=0*/ + int nv, mv; /* length of data */ + int nblk, ng; /* to store number of blocks and number of zero cross. */ + void *ptr; /* ptr for data comming from import structure */ + int *ptr_int; /* ptr to store ptr on integer */ + double *ptr_double; /* ptr to store ptr on double */ + int *xptr = NULL; /* to retrieve xptr by import and zcptr of scicos_blocks */ + int *zcptr = NULL; + double *x = NULL; /* ptr for x, xd and g for scicos_blocks */ + double *xd = NULL; + double *g = NULL; + + /* set length of block list -please update me- */ + static int nblklst = 40; + /* set string of first element of scilab Blocks tlist -please update me- */ + static char *str_blklst[] = { "scicos_block", "nevprt" , "funpt" , "type" , + "scsptr" , "nz" , "z" , "noz" , + "ozsz" , "oztyp" , "oz" , "nx" , + "x" , "xd" , "res" , "nin" , + "insz" , "inptr" , "nout" , "outsz" , + "outptr" , "nevout" , "evout" , "nrpar" , + "rpar" , "nipar" , "ipar" , "nopar" , + "oparsz" , "opartyp" , "opar" , "ng" , + "g" , "ztyp" , "jroot" , "label" , + "work" , "nmode" , "mode" , "xprop" + }; + + /* char ptr for str2sci - see below - */ + char **str1; + + /* set nblk, x, xd ptr coming from import strucuture, + * if flag_imp >=0 + */ + if (flag_imp >= 0) + { + /*retrieve nblk by import structure*/ + strcpy(C2F(cha1).buf, "nblk"); + *ierr = getscicosvarsfromimport(C2F(cha1).buf, &ptr, &nv, &mv); + if (*ierr == 0) + { + return 0; + } + ptr_int = (int *) ptr; + nblk = *ptr_int; + + /* retrieve ng by import structure */ + strcpy(C2F(cha1).buf, "ng"); + *ierr = getscicosvarsfromimport(C2F(cha1).buf, &ptr, &nv, &mv); + ptr_int = (int *) ptr; /* cast void* ptr to int* ptr */ + ng = *ptr_int; + + /*retrieve xptr by import structure*/ + strcpy(C2F(cha1).buf, "xptr"); + *ierr = getscicosvarsfromimport(C2F(cha1).buf, &ptr, &nv, &mv); + if (*ierr == 0) + { + return 0; + } + ptr_int = (int *) ptr; + xptr = ptr_int; + + /*retrieve zcptr by import structure*/ + strcpy(C2F(cha1).buf, "zcptr"); + *ierr = getscicosvarsfromimport(C2F(cha1).buf, &ptr, &nv, &mv); + ptr_int = (int *) ptr; + zcptr = ptr_int; + + /*retrieve x and xd by import structure*/ + strcpy(C2F(cha1).buf, "x"); + *ierr = getscicosvarsfromimport(C2F(cha1).buf, &ptr, &nv, &mv); + if (*ierr == 0) + { + return 0; + } + ptr_double = (double *) ptr; + x = ptr_double; + xd = &x[xptr[nblk] - 1]; + + /*retrieve g by import structure*/ + strcpy(C2F(cha1).buf, "g"); + *ierr = getscicosvarsfromimport(C2F(cha1).buf, &ptr, &nv, &mv); + ptr_double = (double *) ptr; + g = ptr_double; + } + + /**************************** + * create scilab tlist Blocks + ****************************/ + /* 1 - scicos_block */ + str2sci(str_blklst, 1, nblklst); + + /* 2 - nevprt */ + C2F(itosci)(&Blocks[0].nevprt, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 3 - funpt */ + if (sizeof(voidg) >= sizeof(double)) + { + // store N double values as the function pointer value + j = sizeof(voidg) / sizeof(double); + } + else + { + // push at least one double + j = 1; + } + C2F(dtosci)(&Blocks[0].funpt, &j, (k = 1, &k)); + + /* 4 - type */ + C2F(itosci)(&Blocks[0].type, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 5 - scsptr */ + C2F(itosci)(&Blocks[0].scsptr, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 6 - nz */ + C2F(itosci)(&Blocks[0].nz, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 7 - z */ + if (Blocks[0].scsptr > 0) + { + C2F(vvtosci)(Blocks[0].z, &Blocks[0].nz); + if (C2F(scierr)() != 0) + { + return 0; + } + } + else + { + *ierr = var2sci(Blocks[0].z, Blocks[0].nz, 1, SCSREAL_N); + if (*ierr != 0) + { + return 0; + } + } + + /* 8 - noz */ + C2F(itosci)(&Blocks[0].noz, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 9 - ozsz */ + C2F(itosci)(Blocks[0].ozsz, (j = Blocks[0].noz, &j), (k = 2, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 10 - oztyp */ + C2F(itosci)(Blocks[0].oztyp, (j = Blocks[0].noz, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 11 - oz */ + for (k = 0; k < Blocks[0].noz; k++) + { + nu = Blocks[0].ozsz[k]; /* retrieve number of rows */ + mu = Blocks[0].ozsz[Blocks[0].noz + k]; /* retrieve number of cols */ + oz_typ = Blocks[0].oztyp[k]; /* retrieve type */ + *ierr = var2sci(Blocks[0].ozptr[k], nu, mu, oz_typ); + if (*ierr != 0) + { + return 0; + } + } + /* if C blocks or null size then concatenate in a single list */ + if ((funtyp == 4) || (Blocks[0].noz == 0)) + { + C2F(mklist)(&Blocks[0].noz); /*create oz list*/ + } + + /* 12 - nx */ + C2F(itosci)(&Blocks[0].nx, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 13 - x */ + if (flag_imp >= 0) + { + *ierr = var2sci(&x[xptr[flag_imp] - 1], Blocks[0].nx, 1, SCSREAL_N); + } + else + { + *ierr = var2sci(Blocks[0].x, Blocks[0].nx, 1, SCSREAL_N); + } + if (*ierr != 0) + { + return 0; + } + + /* 14 - xd */ + if (flag_imp >= 0) + { + *ierr = var2sci(&xd[xptr[flag_imp] - 1], Blocks[0].nx, 1, SCSREAL_N); + } + else + { + *ierr = var2sci(Blocks[0].xd, Blocks[0].nx, 1, SCSREAL_N); + } + if (*ierr != 0) + { + return 0; + } + + /* 15 - res */ + *ierr = var2sci(Blocks[0].res, Blocks[0].nx, 1, SCSREAL_N); + if (*ierr != 0) + { + return 0; + } + + /* 16 - nin */ + C2F(itosci)(&Blocks[0].nin, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 17 - insz */ + C2F(itosci)(Blocks[0].insz, (j = 3 * Blocks[0].nin, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 18 - inptr */ + for (k = 0; k < Blocks[0].nin; k++) + { + nu = Blocks[0].insz[k]; /* retrieve number of rows */ + mu = Blocks[0].insz[Blocks[0].nin + k]; /* retrieve number of cols */ + u_typ = Blocks[0].insz[2 * Blocks[0].nin + k]; /* retrieve type */ + *ierr = var2sci(Blocks[0].inptr[k], nu, mu, u_typ); + if (*ierr != 0) + { + return 0; + } + } + C2F(mklist)(&Blocks[0].nin); /*create inptr list*/ + + /* 19 - nout */ + C2F(itosci)(&Blocks[0].nout, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 20 - outsz */ + C2F(itosci)(Blocks[0].outsz, (j = 3 * Blocks[0].nout, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 21 - outptr */ + for (k = 0; k < Blocks[0].nout; k++) + { + ny = Blocks[0].outsz[k]; /* retrieve number of rows */ + my = Blocks[0].outsz[Blocks[0].nout + k]; /* retrieve number of cols */ + y_typ = Blocks[0].outsz[2 * Blocks[0].nout + k]; /* retrieve type */ + *ierr = var2sci(Blocks[0].outptr[k], ny, my, y_typ); + if (*ierr != 0) + { + return 0; + } + } + C2F(mklist)(&Blocks[0].nout); /*create outptr list*/ + + /* 22 - nevout */ + C2F(itosci)(&Blocks[0].nevout, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 23 - evout */ + *ierr = var2sci(Blocks[0].evout, Blocks[0].nevout, 1, SCSREAL_N); + if (*ierr != 0) + { + return 0; + } + + /* 24 - nrpar */ + C2F(itosci)(&Blocks[0].nrpar, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 25 - rpar */ + if (Blocks[0].scsptr > 0) + { + C2F(vvtosci)(Blocks[0].rpar, &Blocks[0].nrpar); + if (C2F(scierr)() != 0) + { + return 0; + } + } + else + { + *ierr = var2sci(Blocks[0].rpar, Blocks[0].nrpar, 1, SCSREAL_N); + if (*ierr != 0) + { + return 0; + } + } + + /* 26 - nipar */ + C2F(itosci)(&Blocks[0].nipar, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 27 - ipar */ + C2F(itosci)(Blocks[0].ipar, (j = Blocks[0].nipar, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 28 - nopar */ + C2F(itosci)(&Blocks[0].nopar, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 29 - oparsz */ + C2F(itosci)(Blocks[0].oparsz, (j = Blocks[0].nopar, &j), (k = 2, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 30 - opartyp */ + C2F(itosci)(Blocks[0].opartyp, (j = Blocks[0].nopar, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 31 - opar */ + for (k = 0; k < Blocks[0].nopar; k++) + { + nu = Blocks[0].oparsz[k]; /* retrieve number of rows */ + mu = Blocks[0].oparsz[Blocks[0].nopar + k]; /* retrieve number of cols */ + opar_typ = Blocks[0].opartyp[k]; /* retrieve type */ + *ierr = var2sci(Blocks[0].oparptr[k], nu, mu, opar_typ); + if (*ierr != 0) + { + return 0; + } + } + /* if C blocks or null size then concatenate in a single list */ + if ((funtyp == 4) || (Blocks[0].nopar == 0)) + { + C2F(mklist)(&Blocks[0].nopar); /*create opar list*/ + } + + /* 32 - ng */ + C2F(itosci)(&Blocks[0].ng, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 33 - g */ + if (flag_imp >= 0) + { + *ierr = var2sci(&g[zcptr[flag_imp] - 1], Blocks[0].ng, 1, SCSREAL_N); + } + else + { + *ierr = var2sci(Blocks[0].g, Blocks[0].ng, 1, SCSREAL_N); + } + if (*ierr != 0) + { + return 0; + } + + /* 34 - ztyp */ + C2F(itosci)(&Blocks[0].ztyp, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 35 - jroot */ + C2F(itosci)(Blocks[0].jroot, (j = Blocks[0].ng, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 36 - label */ + if ((str1 = MALLOC(sizeof(char*))) == NULL ) + { + return 0; + } + if ((str1[0] = MALLOC(sizeof(char) * (strlen(Blocks[0].label) + 1))) == NULL ) + { + FREE(str1); + return 0; + } + (str1[0])[strlen(Blocks[0].label)] = '\0'; + strncpy(str1[0], Blocks[0].label, strlen(Blocks[0].label)); + str2sci(str1, 1, 1); + FREE(str1[0]); + FREE(str1); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 37 - work*/ + C2F(itosci)(&Blocks[0].work, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 38 - nmode*/ + C2F(itosci)(&Blocks[0].nmode, (j = 1, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 39 - mode */ + C2F(itosci)(Blocks[0].mode, (j = Blocks[0].nmode, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + /* 40 - xprop */ + C2F(itosci)(Blocks[0].xprop, (j = Blocks[0].nx, &j), (k = 1, &k)); + if (C2F(scierr)() != 0) + { + return 0; + } + + C2F(mktlist)(&nblklst); /*create Blocks list*/ + if (C2F(scierr)() != 0) + { + return 0; + } + + /*return 1 if succeeded */ + return 1; } -/*--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ + diff --git a/scilab/modules/scicos/src/c/scicos.c b/scilab/modules/scicos/src/c/scicos.c index 32a3a39..d714bef 100644 --- a/scilab/modules/scicos/src/c/scicos.c +++ b/scilab/modules/scicos/src/c/scicos.c @@ -445,7 +445,10 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__, if ((mod = MALLOC(sizeof(int) * nmod)) == NULL ) { *ierr = 5; - if (nx > 0) FREE(xprop); + if (nx > 0) + { + FREE(xprop); + } return 0; } } @@ -454,8 +457,14 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__, if ((g = MALLOC(sizeof(double) * ng)) == NULL ) { *ierr = 5; - if (nmod > 0) FREE(mod); - if (nx > 0) FREE(xprop); + if (nmod > 0) + { + FREE(mod); + } + if (nx > 0) + { + FREE(xprop); + } return 0; } } @@ -467,9 +476,18 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__, if ((Blocks = MALLOC(sizeof(scicos_block) * nblk)) == NULL ) { *ierr = 5; - if (nx > 0) FREE(xprop); - if (nmod > 0) FREE(mod); - if (ng > 0) FREE(g); + if (nx > 0) + { + FREE(xprop); + } + if (nmod > 0) + { + FREE(mod); + } + if (ng > 0) + { + FREE(g); + } return 0; } @@ -808,7 +826,8 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__, { /* integration */ - switch (C2F(cmsolver).solver) { + switch (C2F(cmsolver).solver) + { case 0: // LSodar - Dynamic / Dynamic case 1: // CVode - BDF / Newton case 2: // CVode - BDF / Functional @@ -862,7 +881,10 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__, { zdoit(t0, x, x + nx, W); /* updating modes as a function of state values; this was necessary in iGUI*/ } - for (jj = 0; jj < nx; jj++) W[jj] = 0.0; + for (jj = 0; jj < nx; jj++) + { + W[jj] = 0.0; + } C2F(ierode).iero = 0; *ierr = 0; if (C2F(cmsolver).solver < 100) @@ -1035,7 +1057,10 @@ static void cosini(double *told) *ierr = 5 - flag__; kfune = C2F(curblk).kfun; } - if ((Jacobian_Flag == 1) && (AJacobian_block == 0)) AJacobian_block = C2F(curblk).kfun; + if ((Jacobian_Flag == 1) && (AJacobian_block == 0)) + { + AJacobian_block = C2F(curblk).kfun; + } } } if (*ierr != 0) @@ -1119,7 +1144,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbdptr[kk] != (SCSREAL_COP)outtbd[curouttbd + kk]) goto L30; + if (outtbdptr[kk] != (SCSREAL_COP)outtbd[curouttbd + kk]) + { + goto L30; + } } curouttbd += sszz; break; @@ -1129,7 +1157,10 @@ static void cosini(double *told) sszz = 2 * outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbdptr[kk] != (SCSCOMPLEX_COP)outtbd[curouttbd + kk]) goto L30; + if (outtbdptr[kk] != (SCSCOMPLEX_COP)outtbd[curouttbd + kk]) + { + goto L30; + } } curouttbd += sszz; break; @@ -1139,7 +1170,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbcptr[kk] != (SCSINT8_COP)outtbc[curouttbc + kk]) goto L30; + if (outtbcptr[kk] != (SCSINT8_COP)outtbc[curouttbc + kk]) + { + goto L30; + } } curouttbc += sszz; break; @@ -1149,7 +1183,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbsptr[kk] != (SCSINT16_COP)outtbs[curouttbs + kk]) goto L30; + if (outtbsptr[kk] != (SCSINT16_COP)outtbs[curouttbs + kk]) + { + goto L30; + } } curouttbs += sszz; break; @@ -1159,7 +1196,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtblptr[kk] != (SCSINT32_COP)outtbl[curouttbl + kk]) goto L30; + if (outtblptr[kk] != (SCSINT32_COP)outtbl[curouttbl + kk]) + { + goto L30; + } } curouttbl += sszz; break; @@ -1169,7 +1209,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbucptr[kk] != (SCSUINT8_COP)outtbuc[curouttbuc + kk]) goto L30; + if (outtbucptr[kk] != (SCSUINT8_COP)outtbuc[curouttbuc + kk]) + { + goto L30; + } } curouttbuc += sszz; break; @@ -1179,7 +1222,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbusptr[kk] != (SCSUINT16_COP)outtbus[curouttbus + kk]) goto L30; + if (outtbusptr[kk] != (SCSUINT16_COP)outtbus[curouttbus + kk]) + { + goto L30; + } } curouttbus += sszz; break; @@ -1189,7 +1235,10 @@ static void cosini(double *told) sszz = outtbsz[jj] * outtbsz[jj + nlnk]; for (kk = 0; kk < sszz; kk++) { - if (outtbulptr[kk] != (SCSUINT32_COP)outtbul[curouttbul + kk]) goto L30; + if (outtbulptr[kk] != (SCSUINT32_COP)outtbul[curouttbul + kk]) + { + goto L30; + } } curouttbul += sszz; break; @@ -1231,42 +1280,60 @@ L30: case SCSINT8_N : outtbcptr = (SCSINT8_COP *)outtbptr[ii]; /*int8*/ sszz = outtbsz[ii] * outtbsz[ii + nlnk]; - for (kk = 0; kk < sszz; kk++) outtbc[curouttbc + kk] = (SCSINT8_COP)outtbcptr[kk]; + for (kk = 0; kk < sszz; kk++) + { + outtbc[curouttbc + kk] = (SCSINT8_COP)outtbcptr[kk]; + } curouttbc += sszz; break; case SCSINT16_N : outtbsptr = (SCSINT16_COP *)outtbptr[ii]; /*int16*/ sszz = outtbsz[ii] * outtbsz[ii + nlnk]; - for (kk = 0; kk < sszz; kk++) outtbs[curouttbs + kk] = (SCSINT16_COP)outtbsptr[kk]; + for (kk = 0; kk < sszz; kk++) + { + outtbs[curouttbs + kk] = (SCSINT16_COP)outtbsptr[kk]; + } curouttbs += sszz; break; case SCSINT32_N : outtblptr = (SCSINT32_COP *)outtbptr[ii]; /*int32*/ sszz = outtbsz[ii] * outtbsz[ii + nlnk]; - for (kk = 0; kk < sszz; kk++) outtbl[curouttbl + kk] = (SCSINT32_COP)outtblptr[kk]; + for (kk = 0; kk < sszz; kk++) + { + outtbl[curouttbl + kk] = (SCSINT32_COP)outtblptr[kk]; + } curouttbl += sszz; break; case SCSUINT8_N : outtbucptr = (SCSUINT8_COP *)outtbptr[ii]; /*uint8*/ sszz = outtbsz[ii] * outtbsz[ii + nlnk]; - for (kk = 0; kk < sszz; kk++) outtbuc[curouttbuc + kk] = (SCSUINT8_COP)outtbucptr[kk]; + for (kk = 0; kk < sszz; kk++) + { + outtbuc[curouttbuc + kk] = (SCSUINT8_COP)outtbucptr[kk]; + } curouttbuc += sszz; break; case SCSUINT16_N : outtbusptr = (SCSUINT16_COP *)outtbptr[ii]; /*uint16*/ sszz = outtbsz[ii] * outtbsz[ii + nlnk]; - for (kk = 0; kk < sszz; kk++) outtbus[curouttbus + kk] = (SCSUINT16_COP)outtbusptr[kk]; + for (kk = 0; kk < sszz; kk++) + { + outtbus[curouttbus + kk] = (SCSUINT16_COP)outtbusptr[kk]; + } curouttbus += sszz; break; case SCSUINT32_N : outtbulptr = (SCSUINT32_COP *)outtbptr[ii]; /*uint32*/ sszz = outtbsz[ii] * outtbsz[ii + nlnk]; - for (kk = 0; kk < sszz; kk++) outtbul[curouttbul + kk] = (SCSUINT32_COP)outtbulptr[kk]; + for (kk = 0; kk < sszz; kk++) + { + outtbul[curouttbul + kk] = (SCSUINT32_COP)outtbulptr[kk]; + } curouttbul += sszz; break; @@ -1317,7 +1384,8 @@ static void cossim(double *told) /* Generic flags for stop mode */ int ODE_NORMAL = 1; /* ODE_NORMAL = CV_NORMAL = LS_NORMAL = 1 */ int ODE_ONE_STEP = 2; /* ODE_ONE_STEP = CV_ONE_STEP = LS_ONE_STEP = 2 */ - switch (C2F(cmsolver).solver) { + switch (C2F(cmsolver).solver) + { case 0: // LSodar ODE = &LSodar; ODEReInit = &LSodarReInit; @@ -1356,7 +1424,9 @@ static void cossim(double *told) } for ( jj = 0 ; jj < ng ; jj++ ) + { jroot[jj] = 0 ; + } zcros = NULL; if (ng != 0) @@ -1364,7 +1434,10 @@ static void cossim(double *told) if ((zcros = MALLOC(sizeof(int) * ng)) == NULL ) { *ierr = 10000; - if (ng > 0) FREE(jroot); + if (ng > 0) + { + FREE(jroot); + } return; } } @@ -1378,8 +1451,14 @@ static void cossim(double *told) if (check_flag((void *)y, "N_VNewEmpty_Serial", 0)) { *ierr = 10000; - if (ng > 0) FREE(jroot); - if (ng > 0) FREE(zcros); + if (ng > 0) + { + FREE(jroot); + } + if (ng > 0) + { + FREE(zcros); + } return; } @@ -1434,7 +1513,9 @@ static void cossim(double *told) flag = LSodarSetErrHandlerFn(ode_mem, SundialsErrHandler, NULL); } else - flag = CVodeSetErrHandlerFn(ode_mem, SundialsErrHandler, NULL); + { + flag = CVodeSetErrHandlerFn(ode_mem, SundialsErrHandler, NULL); + } if (check_flag(&flag, "CVodeSetErrHandlerFn", 1)) { *ierr = 300 + (-flag); @@ -1447,7 +1528,9 @@ static void cossim(double *told) flag = LSodarInit (ode_mem, simblklsodar, T0, y); } else - flag = CVodeInit (ode_mem, simblk, T0, y); + { + flag = CVodeInit (ode_mem, simblk, T0, y); + } if (check_flag(&flag, "CVodeInit", 1)) { *ierr = 300 + (-flag); @@ -1468,7 +1551,9 @@ static void cossim(double *told) flag = LSodarRootInit(ode_mem, ng, grblklsodar); } else - flag = CVodeRootInit(ode_mem, ng, grblk); + { + flag = CVodeRootInit(ode_mem, ng, grblk); + } if (check_flag(&flag, "CVodeRootInit", 1)) { *ierr = 300 + (-flag); @@ -1477,8 +1562,10 @@ static void cossim(double *told) } if (C2F(cmsolver).solver != 0) - /* Call CVDense to specify the CVDENSE dense linear solver */ - flag = CVDense(ode_mem, *neq); + /* Call CVDense to specify the CVDENSE dense linear solver */ + { + flag = CVDense(ode_mem, *neq); + } if (check_flag(&flag, "CVDense", 1)) { *ierr = 300 + (-flag); @@ -1545,8 +1632,14 @@ static void cossim(double *told) return; } for (jj = 0; jj < ng; ++jj) - if (g[jj] >= 0) jroot[jj] = 5; - else jroot[jj] = -5; + if (g[jj] >= 0) + { + jroot[jj] = 5; + } + else + { + jroot[jj] = -5; + } } /*--discrete zero crossings----dzero--------------------*/ @@ -1562,7 +1655,10 @@ static void cossim(double *told) } if (C2F(coshlt).halt != 0) { - if (C2F(coshlt).halt == 2) *told = *tf; /* end simulation */ + if (C2F(coshlt).halt == 2) + { + *told = *tf; /* end simulation */ + } C2F(coshlt).halt = 0; freeall; return; @@ -1697,7 +1793,10 @@ L30: Discrete_Jump = 1; jroot[jj] = -1; } - else jroot[jj] = 0; + else + { + jroot[jj] = 0; + } } } /*--discrete zero crossings----dzero--------------------*/ @@ -1732,14 +1831,18 @@ L30: if (flag >= 0) { if ((C2F(cosdebug).cosd >= 1) && (C2F(cosdebug).cosd != 3)) + { sciprint(_("****SUNDIALS.Cvode reached: %f\n"), *told); + } hot = 1; cnt = 0; } else if ( flag == CV_TOO_MUCH_WORK || flag == CV_CONV_FAILURE || flag == CV_ERR_FAILURE) { if ((C2F(cosdebug).cosd >= 1) && (C2F(cosdebug).cosd != 3)) + { sciprint(_("****SUNDIALS.Cvode: too much work at time=%g (stiff region, change RTOL and ATOL)\n"), *told); + } hot = 0; cnt++; if (cnt > 5) @@ -1751,7 +1854,10 @@ L30: } else { - if (flag < 0) *ierr = 300 + (-flag); /* raising errors due to internal errors, otherwise error due to flagr*/ + if (flag < 0) + { + *ierr = 300 + (-flag); /* raising errors due to internal errors, otherwise error due to flagr*/ + } freeall; return; } @@ -1981,7 +2087,8 @@ static void cossimdaskr(double *told) /* Generic flag for stop mode */ int DAE_NORMAL = 1; /* IDA_NORMAL = 1 */ int DAE_ONE_STEP = 2; /* IDA_ONE_STEP = 2 */ - switch (C2F(cmsolver).solver) { + switch (C2F(cmsolver).solver) + { case 100: // IDA DAESolve = &IDASolve; DAEReInit = &IDAReInit; @@ -2010,7 +2117,10 @@ static void cossimdaskr(double *told) return; } } - for ( jj = 0 ; jj < ng ; jj++ ) jroot[jj] = 0 ; + for ( jj = 0 ; jj < ng ; jj++ ) + { + jroot[jj] = 0 ; + } zcros = NULL; if (ng != 0) @@ -2018,7 +2128,10 @@ static void cossimdaskr(double *told) if ((zcros = MALLOC(sizeof(int) * ng)) == NULL ) { *ierr = 10000; - if (ng != 0) FREE(jroot); + if (ng != 0) + { + FREE(jroot); + } return; } } @@ -2029,8 +2142,14 @@ static void cossimdaskr(double *told) if ((Mode_save = MALLOC(sizeof(int) * nmod)) == NULL ) { *ierr = 10000; - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } return; } } @@ -2044,9 +2163,18 @@ static void cossimdaskr(double *told) yy = N_VNewEmpty_Serial(*neq); if (check_flag((void *)yy, "N_VNew_Serial", 0)) { - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } } NV_DATA_S(yy) = x; @@ -2054,10 +2182,22 @@ static void cossimdaskr(double *told) yp = N_VNewEmpty_Serial(*neq); if (check_flag((void *)yp, "N_VNew_Serial", 0)) { - if (*neq > 0) N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } NV_DATA_S(yp) = xd; @@ -2067,11 +2207,26 @@ static void cossimdaskr(double *told) if (check_flag((void *)IDx, "N_VNew_Serial", 0)) { *ierr = 10000; - if (*neq > 0) N_VDestroy_Serial(yp); - if (*neq > 0) N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } @@ -2080,43 +2235,107 @@ static void cossimdaskr(double *told) dae_mem = IDACreate(); if (check_flag((void *)dae_mem, "IDACreate", 0)) { - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } copy_IDA_mem = (IDAMem) dae_mem; if (C2F(cmsolver).solver == 100) - flag = IDASetErrHandlerFn(dae_mem, SundialsErrHandler, NULL); + { + flag = IDASetErrHandlerFn(dae_mem, SundialsErrHandler, NULL); + } if (check_flag(&flag, "IDASetErrHandlerFn", 1)) { *ierr = 200 + (-flag); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } if (C2F(cmsolver).solver == 100) - flag = IDAInit(dae_mem, simblkdaskr, T0, yy, yp); + { + flag = IDAInit(dae_mem, simblkdaskr, T0, yy, yp); + } if (check_flag(&flag, "IDAInit", 1)) { *ierr = 200 + (-flag); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } @@ -2124,43 +2343,110 @@ static void cossimdaskr(double *told) if (check_flag(&flag, "IDASStolerances", 1)) { *ierr = 200 + (-flag); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } if (C2F(cmsolver).solver == 100) - flag = IDARootInit(dae_mem, ng, grblkdaskr); + { + flag = IDARootInit(dae_mem, ng, grblkdaskr); + } if (check_flag(&flag, "IDARootInit", 1)) { *ierr = 200 + (-flag); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } if (C2F(cmsolver).solver == 100) - flag = IDADense(dae_mem, *neq); + { + flag = IDADense(dae_mem, *neq); + } if (check_flag(&flag, "IDADense", 1)) { *ierr = 200 + (-flag); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } @@ -2168,13 +2454,34 @@ static void cossimdaskr(double *told) if ((data = (UserData) MALLOC(sizeof(*data))) == NULL) { *ierr = 10000; - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } data->dae_mem = dae_mem; @@ -2187,29 +2494,80 @@ static void cossimdaskr(double *told) if (check_flag((void *)data->ewt, "N_VNew_Serial", 0)) { *ierr = 200 + (-flag); - if (*neq > 0)FREE(data); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0) + { + FREE(data); + } + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } if ( ng > 0 ) { if ((data->gwork = (double *) MALLOC(ng * sizeof(double))) == NULL) { - if (*neq > 0)N_VDestroy_Serial(data->ewt); - if (*neq > 0)FREE(data); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if (*neq > 0) + { + N_VDestroy_Serial(data->ewt); + } + if (*neq > 0) + { + FREE(data); + } + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } return; } } @@ -2232,22 +2590,54 @@ static void cossimdaskr(double *told) if ((data->rwork = (double *) MALLOC(Jactaille * sizeof(double))) == NULL) { - if ( ng > 0 )FREE(data->gwork); - if (*neq > 0)N_VDestroy_Serial(data->ewt); - if (*neq > 0)FREE(data); - if (*neq > 0)if (C2F(cmsolver).solver == 100) IDAFree(&dae_mem); - if (*neq > 0)N_VDestroy_Serial(IDx); - if (*neq > 0)N_VDestroy_Serial(yp); - if (*neq > 0)N_VDestroy_Serial(yy); - if (ng != 0) FREE(jroot); - if (ng != 0) FREE(zcros); - if (nmod != 0) FREE(Mode_save); + if ( ng > 0 ) + { + FREE(data->gwork); + } + if (*neq > 0) + { + N_VDestroy_Serial(data->ewt); + } + if (*neq > 0) + { + FREE(data); + } + if (*neq > 0)if (C2F(cmsolver).solver == 100) + { + IDAFree(&dae_mem); + } + if (*neq > 0) + { + N_VDestroy_Serial(IDx); + } + if (*neq > 0) + { + N_VDestroy_Serial(yp); + } + if (*neq > 0) + { + N_VDestroy_Serial(yy); + } + if (ng != 0) + { + FREE(jroot); + } + if (ng != 0) + { + FREE(zcros); + } + if (nmod != 0) + { + FREE(Mode_save); + } *ierr = 10000; return; } if (C2F(cmsolver).solver == 100) - flag = IDADlsSetDenseJacFn(dae_mem, Jacobians); + { + flag = IDADlsSetDenseJacFn(dae_mem, Jacobians); + } if (check_flag(&flag, "IDADlsSetDenseJacFn", 1)) { *ierr = 200 + (-flag); @@ -2278,7 +2668,9 @@ static void cossimdaskr(double *told) maxnj = 100; /* setting the maximum number of Jacobian evaluations during a Newton step */ if (C2F(cmsolver).solver == 100) - flag = IDASetMaxNumJacsIC(dae_mem, maxnj); + { + flag = IDASetMaxNumJacsIC(dae_mem, maxnj); + } if (check_flag(&flag, "IDASetMaxNumJacsIC", 1)) { *ierr = 200 + (-flag); @@ -2288,7 +2680,9 @@ static void cossimdaskr(double *told) maxnit = 10; /* setting the maximum number of Newton iterations in any attempt to solve CIC */ if (C2F(cmsolver).solver == 100) - flag = IDASetMaxNumItersIC(dae_mem, maxnit); + { + flag = IDASetMaxNumItersIC(dae_mem, maxnit); + } if (check_flag(&flag, "IDASetMaxNumItersIC", 1)) { *ierr = 200 + (-flag); @@ -2298,7 +2692,9 @@ static void cossimdaskr(double *told) /* setting the maximum number of steps in an integration interval */ if (C2F(cmsolver).solver == 100) - flag = IDASetMaxNumSteps(dae_mem, 2000); + { + flag = IDASetMaxNumSteps(dae_mem, 2000); + } if (check_flag(&flag, "IDASetMaxNumSteps", 1)) { *ierr = 200 + (-flag); @@ -2362,8 +2758,14 @@ static void cossimdaskr(double *told) return; } for (jj = 0; jj < ng; ++jj) - if (g[jj] >= 0) jroot[jj] = 5; - else jroot[jj] = -5; + if (g[jj] >= 0) + { + jroot[jj] = 5; + } + else + { + jroot[jj] = -5; + } } /* main loop on time */ while (*told < *tf) @@ -2377,7 +2779,10 @@ static void cossimdaskr(double *told) } if (C2F(coshlt).halt != 0) { - if (C2F(coshlt).halt == 2) *told = *tf; /* end simulation */ + if (C2F(coshlt).halt == 2) + { + *told = *tf; /* end simulation */ + } C2F(coshlt).halt = 0; freeallx; return; @@ -2484,8 +2889,14 @@ L30: } for (jj = 0; jj < *neq; jj++) { - if (xprop[jj] == 1) scicos_xproperty[jj] = ONE; - if (xprop[jj] == -1) scicos_xproperty[jj] = ZERO; + if (xprop[jj] == 1) + { + scicos_xproperty[jj] = ONE; + } + if (xprop[jj] == -1) + { + scicos_xproperty[jj] = ZERO; + } } /* CI=0.0;CJ=100.0; // for functions Get_Jacobian_ci and Get_Jacobian_cj Jacobians(*neq, (realtype) (*told), yy, yp, bidon, (realtype) CJ, data, TJacque, tempv1, tempv2, tempv3); @@ -2508,7 +2919,9 @@ L30: /* printf("\n"); for(jj=0;jj<*neq;jj++) { printf("x%d=%g ",jj,scicos_xproperty[jj]); }*/ if (C2F(cmsolver).solver == 100) - flag = IDASetId(dae_mem, IDx); + { + flag = IDASetId(dae_mem, IDx); + } if (check_flag(&flag, "IDASetId", 1)) { *ierr = 200 + (-flag); @@ -2555,7 +2968,10 @@ L30: } if (C2F(coshlt).halt != 0) { - if (C2F(coshlt).halt == 2) *told = *tf; /* end simulation */ + if (C2F(coshlt).halt == 2) + { + *told = *tf; /* end simulation */ + } C2F(coshlt).halt = 0; freeallx; return; @@ -2575,11 +2991,15 @@ L30: // the initial conditons y0 and yp0 do not satisfy the DAE if (C2F(cmsolver).solver == 100) - flagr = IDACalcIC(dae_mem, IDA_YA_YDP_INIT, (realtype)(t)); + { + flagr = IDACalcIC(dae_mem, IDA_YA_YDP_INIT, (realtype)(t)); + } phase = 1; if (C2F(cmsolver).solver == 100) - flag = IDAGetConsistentIC(dae_mem, yy, yp); /* PHI->YY */ + { + flag = IDAGetConsistentIC(dae_mem, yy, yp); /* PHI->YY */ + } if (*ierr > 5) /* *ierr>5 => singularity in block */ { @@ -2634,13 +3054,19 @@ L30: { /* IDASetMaxNumStepsIC(mem,10); */ /* maxnh (def=5) */ if (C2F(cmsolver).solver == 100) - IDASetMaxNumJacsIC(dae_mem, 10); /* maxnj 100 (def=4)*/ + { + IDASetMaxNumJacsIC(dae_mem, 10); /* maxnj 100 (def=4)*/ + } /* IDASetMaxNumItersIC(mem,100000); */ /* maxnit in IDANewtonIC (def=10) */ if (C2F(cmsolver).solver == 100) - IDASetLineSearchOffIC(dae_mem, TRUE); /* (def=false) */ + { + IDASetLineSearchOffIC(dae_mem, TRUE); /* (def=false) */ + } /* IDASetNonlinConvCoefIC(mem,1.01);*/ /* (def=0.01-0.33*/ if (C2F(cmsolver).solver == 100) - flag = IDASetMaxNumItersIC(dae_mem, 1000); + { + flag = IDASetMaxNumItersIC(dae_mem, 1000); + } if (check_flag(&flag, "IDASetMaxNumItersIC", 1)) { *ierr = 200 + (-flag); @@ -2657,10 +3083,14 @@ L30: phase = 1; copy_IDA_mem->ida_kk = 1; if (C2F(cmsolver).solver == 100) - flagr = IDACalcIC(dae_mem, IDA_YA_YDP_INIT, (realtype)(t)); + { + flagr = IDACalcIC(dae_mem, IDA_YA_YDP_INIT, (realtype)(t)); + } phase = 1; if (C2F(cmsolver).solver == 100) - flag = IDAGetConsistentIC(dae_mem, yy, yp); /* PHI->YY */ + { + flag = IDAGetConsistentIC(dae_mem, yy, yp); /* PHI->YY */ + } if ((flagr < 0) || (*ierr > 5)) /* *ierr>5 => singularity in block */ { *ierr = 23; @@ -2706,7 +3136,10 @@ L30: Discrete_Jump = 1; jroot[jj] = -1; } - else jroot[jj] = 0; + else + { + jroot[jj] = 0; + } } } @@ -2729,14 +3162,18 @@ L30: if (flagr >= 0) { if ((C2F(cosdebug).cosd >= 1) && (C2F(cosdebug).cosd != 3)) + { sciprint(_("****SUNDIALS.Ida reached: %f\n"), *told); + } hot = 1; cnt = 0; } else if ( flagr == IDA_TOO_MUCH_WORK || flagr == IDA_CONV_FAIL || flagr == IDA_ERR_FAIL) { if ((C2F(cosdebug).cosd >= 1) && (C2F(cosdebug).cosd != 3)) + { sciprint(_("**** SUNDIALS.Ida: too much work at time=%g (stiff region, change RTOL and ATOL)\n"), *told); + } hot = 0; cnt++; if (cnt > 5) @@ -2748,7 +3185,10 @@ L30: } else { - if (flagr < 0) *ierr = 200 + (-flagr); /* raising errors due to internal errors, otherwise error due to flagr*/ + if (flagr < 0) + { + *ierr = 200 + (-flagr); /* raising errors due to internal errors, otherwise error due to flagr*/ + } freeallx; return; } @@ -2872,8 +3312,14 @@ L30: } for (j = 0; j < *neq; j++) /* Adjust xprop for IDx */ { - if (xprop[j] == 1) scicos_xproperty[j] = ONE; - if (xprop[j] == -1) scicos_xproperty[j] = ZERO; + if (xprop[j] == 1) + { + scicos_xproperty[j] = ONE; + } + if (xprop[j] == -1) + { + scicos_xproperty[j] = ZERO; + } } } } @@ -2891,7 +3337,10 @@ L30: if (C2F(coshlt).halt != 0) { - if (C2F(coshlt).halt == 2) *told = *tf; /* end simulation */ + if (C2F(coshlt).halt == 2) + { + *told = *tf; /* end simulation */ + } C2F(coshlt).halt = 0; freeallx; return; @@ -3028,7 +3477,10 @@ void callf(double *t, scicos_block *block, scicos_flag *flag) /* debug block is never called */ /*if (kf==(debug_block+1)) return;*/ - if (block->type == 99) return; + if (block->type == 99) + { + return; + } /* flag 7 implicit initialization */ flagi = (int) * flag; @@ -3049,9 +3501,15 @@ void callf(double *t, scicos_block *block, scicos_flag *flag) } if (debug_block > -1) { - if (cosd != 3) sciprint(_("Entering the block \n")); + if (cosd != 3) + { + sciprint(_("Entering the block \n")); + } call_debug_scicos(block, flag, flagi, debug_block); - if (*flag < 0) return; /* error in debug block */ + if (*flag < 0) + { + return; /* error in debug block */ + } } } @@ -3455,8 +3913,14 @@ void callf(double *t, scicos_block *block, scicos_flag *flag) { if (debug_block > -1) { - if (*flag < 0) return; /* error in block */ - if (cosd != 3) sciprint(_("Leaving block %d \n"), C2F(curblk).kfun); + if (*flag < 0) + { + return; /* error in block */ + } + if (cosd != 3) + { + sciprint(_("Leaving block %d \n"), C2F(curblk).kfun); + } call_debug_scicos(block, flag, flagi, debug_block); /*call_debug_scicos(flag,kf,flagi,debug_block);*/ } @@ -3507,7 +3971,10 @@ static void call_debug_scicos(scicos_block *block, scicos_flag *flag, int flagi, } } - if (*flag < 0) sciprint(_("Error in the Debug block \n")); + if (*flag < 0) + { + sciprint(_("Error in the Debug block \n")); + } } /* call_debug_scicos */ /*--------------------------------------------------------------------------*/ /* simblk */ @@ -3520,7 +3987,10 @@ static int simblk(realtype t, N_Vector yy, N_Vector yp, void *f_data) x = (double *) NV_DATA_S(yy); xd = (double *) NV_DATA_S(yp); - for (i = 0; i < *neq; i++) xd[i] = 0; /* à la place de "C2F(dset)(neq, &c_b14,xcdot , &c__1);"*/ + for (i = 0; i < *neq; i++) + { + xd[i] = 0; /* à la place de "C2F(dset)(neq, &c_b14,xcdot , &c__1);"*/ + } C2F(ierode).iero = 0; *ierr = 0; odoit(&tx, x, xd, xd); @@ -3538,7 +4008,10 @@ static int simblk(realtype t, N_Vector yy, N_Vector yp, void *f_data) break; } } - if (nantest == 1) return 349; /* recoverable error; */ + if (nantest == 1) + { + return 349; /* recoverable error; */ + } } return (abs(*ierr)); /* ierr>0 recoverable error; ierr>0 unrecoverable error; ierr=0: ok*/ @@ -3569,7 +4042,10 @@ static int grblk(realtype t, N_Vector yy, realtype *gout, void *g_data) nantest = 1; break; } /* NaN checking */ - if (nantest == 1) return 350; /* recoverable error; */ + if (nantest == 1) + { + return 350; /* recoverable error; */ + } } C2F(ierode).iero = *ierr; @@ -3582,9 +4058,12 @@ static int simblklsodar(int * nequations, realtype * tOld, realtype * actual, re double tx = 0.; int i = 0, nantest = 0; - tx = (double) *tOld; + tx = (double) * tOld; - for (i = 0; i < *nequations; ++i) res[i] = 0; /* à la place de "C2F(dset)(neq, &c_b14,xcdot , &c__1);"*/ + for (i = 0; i < *nequations; ++i) + { + res[i] = 0; /* à la place de "C2F(dset)(neq, &c_b14,xcdot , &c__1);"*/ + } C2F(ierode).iero = 0; *ierr = 0; odoit(&tx, actual, res, res); @@ -3602,7 +4081,10 @@ static int simblklsodar(int * nequations, realtype * tOld, realtype * actual, re break; } } - if (nantest == 1) return 349; /* recoverable error; */ + if (nantest == 1) + { + return 349; /* recoverable error; */ + } } return (abs(*ierr)); /* ierr>0 recoverable error; ierr>0 unrecoverable error; ierr=0: ok*/ @@ -3615,7 +4097,7 @@ static int grblklsodar(int * nequations, realtype * tOld, realtype * actual, int double tx = 0.; int jj = 0, nantest = 0; - tx = (double) *tOld; + tx = (double) * tOld; C2F(ierode).iero = 0; *ierr = 0; @@ -3632,7 +4114,10 @@ static int grblklsodar(int * nequations, realtype * tOld, realtype * actual, int nantest = 1; break; } /* NaN checking */ - if (nantest == 1) return 350; /* recoverable error; */ + if (nantest == 1) + { + return 350; /* recoverable error; */ + } } C2F(ierode).iero = *ierr; @@ -3680,10 +4165,14 @@ static int simblkdaskr(realtype tres, N_Vector yy, N_Vector yp, N_Vector resval, alpha = ZERO; for (jj = 0; jj < qlast; jj++) + { alpha = alpha - ONE / (jj + 1); + } if (hh != 0) // CJ=-alpha/hh; // For function Get_Jacobian_cj + { CJJ = -alpha / hh; + } else { *ierr = 217; @@ -3711,7 +4200,10 @@ static int simblkdaskr(realtype tres, N_Vector yy, N_Vector yp, N_Vector resval, nantest = 1; break; } - if (nantest == 1) return 257; /* recoverable error; */ + if (nantest == 1) + { + return 257; /* recoverable error; */ + } } return (abs(*ierr)); /* ierr>0 recoverable error; ierr>0 unrecoverable error; ierr=0: ok*/ @@ -4885,7 +5377,10 @@ void Jdoit(double *told, double *xt, double *xtd, double *residual, int *job) flag = 0; if (((*job == 1) && (scs_imp->oord[ii] == AJacobian_block)) || (*job != 1)) { - if (*job == 1) flag = 10; + if (*job == 1) + { + flag = 10; + } /* continuous state */ if (scs_imp->blocks[*kf - 1].nx > 0) { @@ -4919,7 +5414,10 @@ void Jdoit(double *told, double *xt, double *xtd, double *residual, int *job) flag = 0; if (((*job == 1) && (scs_imp->oord[ii - 1] == AJacobian_block)) || (*job != 1)) { - if (*job == 1) flag = 10; + if (*job == 1) + { + flag = 10; + } /* continuous state */ if (scs_imp->blocks[*kf - 1].nx > 0) { @@ -5340,11 +5838,20 @@ static void FREE_blocks() } FREE(Blocks); - if (nx > 0) FREE(xprop); + if (nx > 0) + { + FREE(xprop); + } - if (nmod > 0) FREE(mod); + if (nmod > 0) + { + FREE(mod); + } - if (ng > 0) FREE(g); + if (ng > 0) + { + FREE(g); + } return; } /* FREE_blocks */ @@ -5356,13 +5863,19 @@ int C2F(funnum)(char * fname) int loc = -1; while ( tabsim[i].name != (char *) NULL) { - if ( strcmp(fname, tabsim[i].name) == 0 ) return(i + 1); + if ( strcmp(fname, tabsim[i].name) == 0 ) + { + return(i + 1); + } i++; } ln = (int)strlen(fname); C2F(iislink)(fname, &loc); C2F(iislink)(fname, &loc); - if (loc >= 0) return(ntabsim + (int)loc + 1); + if (loc >= 0) + { + return(ntabsim + (int)loc + 1); + } return(0); }/* funnum */ /*--------------------------------------------------------------------------*/ @@ -5609,21 +6122,29 @@ static int Jacobians(long int Neq, realtype tt, realtype cj, N_Vector yy, /* read residuals;*/ job = 0; Jdoit(&ttx, xc, xcdot, residual, &job); - if (*ierr < 0) return -1; + if (*ierr < 0) + { + return -1; + } /* "residual" already contains the current residual, so the first call to Jdoit can be remoevd*/ for (i = 0; i < m; i++) for (j = 0; j < ni; j++) + { Kx[j + i * ni] = u[j][0]; + } for (i = 0; i < m; i++) { xi = xc[i]; xpi = xcdot[i]; inc = MAX( srur * MAX( ABS(xi), ABS(hh * xpi)), ONE / ewt_data[i] ); - if (hh * xpi < ZERO) inc = -inc; + if (hh * xpi < ZERO) + { + inc = -inc; + } inc = (xi + inc) - xi; /* if (CI==0) { @@ -5640,12 +6161,19 @@ static int Jacobians(long int Neq, realtype tt, realtype cj, N_Vector yy, del=SQUR[0]*Max(a,b); */ job = 0; /* read residuals */ Jdoit(&ttx, xc, xcdot, ERR2, &job); - if (*ierr < 0) return -1; + if (*ierr < 0) + { + return -1; + } inc_inv = ONE / inc; for (j = 0; j < m; j++) + { Hx[m * i + j] = (ERR2[j] - residual[j]) * inc_inv; + } for (j = 0; j < ni; j++) + { Kx[j + i * ni] = (u[j][0] - Kx[j + i * ni]) * inc_inv; + } xc[i] = xi; xcdot[i] = xpi; } @@ -5669,7 +6197,9 @@ static int Jacobians(long int Neq, realtype tt, realtype cj, N_Vector yy, Jdoit(&ttx, xc, xcdot, ERR1, &job); for (i = 0; i < no; i++) for (j = 0; j < ni; j++) + { Ku[j + i * ni] = u[j][0]; + } for (i = 0; i < no; i++) { @@ -5681,18 +6211,28 @@ static int Jacobians(long int Neq, realtype tt, realtype cj, N_Vector yy, y[i][0] += inc; job = 2; /* applying y[i][0] to the output of imp block*/ Jdoit(&ttx, xc, xcdot, ERR2, &job); - if (*ierr < 0) return -1; + if (*ierr < 0) + { + return -1; + } inc_inv = ONE / inc; for (j = 0; j < m; j++) + { Hu[m * i + j] = (ERR2[j] - ERR1[j]) * inc_inv; + } for (j = 0; j < ni; j++) + { Ku[j + i * ni] = (u[j][0] - Ku[j + i * ni]) * inc_inv; + } y[i][0] = ysave; } /*----------------------------------------------*/ job = 1; /* read jacobian through flag=10; */ Jdoit(&ttx, xc, xcdot, &Fx[-m], &job);/* Filling up the FX:Fu:Gx:Gu*/ - if (*block_error != 0) sciprint(_("\n error in Jacobian")); + if (*block_error != 0) + { + sciprint(_("\n error in Jacobian")); + } /*-------------------------------------------------*/ Multp(Fu, Ku, RX, nx, ni, ni, no); @@ -5757,7 +6297,9 @@ static void Multp(double *A, double *B, double *R, int ra, int rb, int ca, int c { R[i + ra * j] = 0.0; for (k = 0; k < ca; k++) + { R[i + ra * j] += A[i + k * ra] * B[k + j * rb]; + } } return; } @@ -5768,7 +6310,10 @@ int read_xml_initial_states(int nvar, const char * xmlfile, char **ids, double * int result = 0, i = 0; double vr = 0.; - if (nvar == 0) return 0; + if (nvar == 0) + { + return 0; + } result = 0; for (i = 0; i < nvar; i++) { @@ -5778,7 +6323,10 @@ int read_xml_initial_states(int nvar, const char * xmlfile, char **ids, double * break; } } - if (result == 0) return 0; + if (result == 0) + { + return 0; + } model = ezxml_parse_file(xmlfile); @@ -5793,7 +6341,10 @@ int read_xml_initial_states(int nvar, const char * xmlfile, char **ids, double * { vr = 0.0; result = read_id(&elements, ids[i], &vr); - if (result == 1) svars[i] = vr; + if (result == 1) + { + svars[i] = vr; + } } ezxml_free(model); return 0; @@ -5804,7 +6355,10 @@ static int read_id(ezxml_t *elements, char *id, double *value) char V1[100], V2[100]; int ok = 0, i = 0, ln = 0; - if (strcmp(id, "") == 0) return 0; + if (strcmp(id, "") == 0) + { + return 0; + } ok = search_in_child(elements, id, V1); if (ok == 0 ) { @@ -5818,12 +6372,18 @@ static int read_id(ezxml_t *elements, char *id, double *value) ln = (int)(strlen(V1)); if (ln > 2) { - for (i = 1; i <= ln - 2; i++) V2[i - 1] = V1[i]; + for (i = 1; i <= ln - 2; i++) + { + V2[i - 1] = V1[i]; + } V2[ln - 2] = '\0'; ok = read_id(elements, V2, value); return ok; } - else return 0; + else + { + return 0; + } } else { @@ -5870,7 +6430,10 @@ int write_xml_states(int nvar, const char * xmlfile, char **ids, double *x) char *s = NULL; char **xv = NULL; - if (nvar == 0) return 0; + if (nvar == 0) + { + return 0; + } result = 0; for (i = 0; i < nvar; i++) { @@ -5880,7 +6443,10 @@ int write_xml_states(int nvar, const char * xmlfile, char **ids, double *x) break; } } - if (result == 0) return 0; + if (result == 0) + { + return 0; + } xv = MALLOC(nvar * sizeof(char*)); for (i = 0; i < nvar; i++) @@ -5905,7 +6471,10 @@ int write_xml_states(int nvar, const char * xmlfile, char **ids, double *x) for (i = 0; i < nvar; i++) { - if (strcmp(ids[i], "") == 0) continue; + if (strcmp(ids[i], "") == 0) + { + continue; + } result = write_in_child(&elements, ids[i], xv[i]); if (result == 0 ) { @@ -5955,7 +6524,9 @@ int rho_(double *a, double *L, double *x, double *rho, double *rpar, int *ipar) fx_(x, rho); for (i = 0; i < N; i++) + { rho[i] += (-1 + *L) * a[i]; + } return 0; } /*--------------------------------------------------------------------------*/ @@ -5969,7 +6540,9 @@ int rhojac_(double *a, double *lambda, double *x, double *jac, int *col, doubl if (*col == 1) { for (j = 0; j < N; j++) + { jac[j] = a[j]; + } } else { @@ -5989,7 +6562,9 @@ int rhojac_(double *a, double *lambda, double *x, double *jac, int *col, doubl inc_inv = 1.0 / inc; for (j = 0; j < N; j++) + { jac[j] = (jac[j] - work[j]) * inc_inv; + } x[*col - 2] = xi; FREE(work); @@ -6030,7 +6605,9 @@ int C2F(hfjac)(double *x, double *jac, int *col) inc_inv = ONE / inc; for (j = 0; j < N; j++) + { jac[j] = (jac[j] - work[j]) * inc_inv; + } x[*col - 1] = xi; @@ -6050,7 +6627,10 @@ int simblkKinsol(N_Vector yy, N_Vector resval, void *rdata) residual = (double *) NV_DATA_S(resval); data = (UserData) rdata; xcdot = xc; - if (phase == 1) if ( ng > 0 && nmod > 0 ) zdoit(&t, xc, xcdot, g); + if (phase == 1) if ( ng > 0 && nmod > 0 ) + { + zdoit(&t, xc, xcdot, g); + } *ierr = 0; C2F(ierode).iero = 0; @@ -6101,7 +6681,10 @@ static int CallKinsol(double *told) double ratio = 0.; N = *neq; - if (N <= 0) return 0; + if (N <= 0) + { + return 0; + } reltol = (realtype) rtol; abstol = (realtype) Atol; @@ -6174,8 +6757,14 @@ static int CallKinsol(double *told) fsdata[j] = 1; } /*========================================================*/ - if (PH == 2) PH = 1; - else PH = 2; /* remind that PH is a static variable*/ + if (PH == 2) + { + PH = 1; + } + else + { + PH = 2; /* remind that PH is a static variable*/ + } status = -1; N_iters = 10 + nmod * 3; @@ -6200,14 +6789,29 @@ static int CallKinsol(double *told) ratio = 0.3; for ( j = 0; j < N; j++) { - if (x[j] == 0) ysdata[j] += 1 * ratio; - else ysdata[j] += ratio / fabs(x[j]); - if (fsdata[j] == 0) fsdata[j] = 1; - else fsdata[j] = 1 / fabs(fsdata[j]); + if (x[j] == 0) + { + ysdata[j] += 1 * ratio; + } + else + { + ysdata[j] += ratio / fabs(x[j]); + } + if (fsdata[j] == 0) + { + fsdata[j] = 1; + } + else + { + fsdata[j] = 1 / fabs(fsdata[j]); + } ysdata[j] /= ratio + 1; } status = KINSol(kin_mem, y, strategy, yscale, fscale);/* Calling the Newton Solver */ - if (status >= 0) break; + if (status >= 0) + { + break; + } /* Serge Steer 29/06/2009 */ while (ismenu()) //** if the user has done something, do the actions { @@ -6254,13 +6858,19 @@ static int CallKinsol(double *told) } } - if (Mode_change == 0 && status >= 0 ) break; /*Successful termination*/ + if (Mode_change == 0 && status >= 0 ) + { + break; /*Successful termination*/ + } } else { /* calling with phase=1*/ - if (status >= 0) break; + if (status >= 0) + { + break; + } } } /* end of the loop for mode fixing*/ @@ -6274,3 +6884,4 @@ static int CallKinsol(double *told) return status; } /* CallKinSol_ */ /*--------------------------------------------------------------------------*/ + diff --git a/scilab/modules/scicos_blocks/includes/scicos_block.h b/scilab/modules/scicos_blocks/includes/scicos_block.h index 5e78db1..3f92ec2 100644 --- a/scilab/modules/scicos_blocks/includes/scicos_block.h +++ b/scilab/modules/scicos_blocks/includes/scicos_block.h @@ -26,50 +26,51 @@ #ifndef NULL #define NULL 0 -#endif +#endif typedef void (*voidg)(); -typedef struct { - int nevprt; - voidg funpt ; - int type; - int scsptr; - int nz; - double *z; - int noz; - int *ozsz; - int *oztyp; - void **ozptr; - int nx; - double *x; - double *xd; - double *res; - int *xprop; - int nin; - int *insz; - double **inptr; - int nout; - int *outsz; - double **outptr; - int nevout; - double *evout; - int nrpar; - double *rpar; - int nipar; - int *ipar; - int nopar; - int *oparsz; - int *opartyp; - void **oparptr; - int ng; - double *g; - int ztyp; - int *jroot; - char *label; - void **work; - int nmode; - int *mode; -} scicos_block; +typedef struct +{ + int nevprt; + voidg funpt ; + int type; + int scsptr; + int nz; + double *z; + int noz; + int *ozsz; + int *oztyp; + void **ozptr; + int nx; + double *x; + double *xd; + double *res; + int *xprop; + int nin; + int *insz; + double **inptr; + int nout; + int *outsz; + double **outptr; + int nevout; + double *evout; + int nrpar; + double *rpar; + int nipar; + int *ipar; + int nopar; + int *oparsz; + int *opartyp; + void **oparptr; + int ng; + double *g; + int ztyp; + int *jroot; + char *label; + void **work; + int nmode; + int *mode; +} scicos_block; void do_cold_restart(); @@ -87,10 +88,11 @@ void Set_Jacobian_flag(int flag); int Convert_number (char *, double *); void homotopy(double *); int hfjac_(double *, double *, int *); -int rhojac_(double *, double *,double *,double *, int *, double *,int *); -int rho_( double *, double *,double *,double *,double *, int *); +int rhojac_(double *, double *, double *, double *, int *, double *, int *); +int rho_( double *, double *, double *, double *, double *, int *); int fx_( double *, double *); -int read_xml_initial_states(int nvar,const char * xmlfile, char **ids, double *svars); -int write_xml_states(int,const char *, char **, double *); +int read_xml_initial_states(int nvar, const char * xmlfile, char **ids, double *svars); +int write_xml_states(int, const char *, char **, double *); #endif /* __SCICOS_BLOCK_H__ */ + diff --git a/scilab/modules/scicos_blocks/includes/scicos_block4.h b/scilab/modules/scicos_blocks/includes/scicos_block4.h index 033e41e..53fb6b7 100644 --- a/scilab/modules/scicos_blocks/includes/scicos_block4.h +++ b/scilab/modules/scicos_blocks/includes/scicos_block4.h @@ -669,3 +669,4 @@ typedef enum #define GetLabelPtrs(blk) (blk->label) #endif /* __SCICOS_BLOCK_H__ */ + diff --git a/scilab/modules/xcos/help/en_US/programming_scicos_blocks/c_computational_functions/C_struct.xml b/scilab/modules/xcos/help/en_US/programming_scicos_blocks/c_computational_functions/C_struct.xml index 542900c..d8567c0 100644 --- a/scilab/modules/xcos/help/en_US/programming_scicos_blocks/c_computational_functions/C_struct.xml +++ b/scilab/modules/xcos/help/en_US/programming_scicos_blocks/c_computational_functions/C_struct.xml @@ -1707,3 +1707,4 @@ scicos_free(*work); + -- 1.7.9.5