⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codegeneration_.sci

📁 rtai-3.1-test3的源代码(Real-Time Application Interface )
💻 SCI
📖 第 1 页 / 共 5 页
字号:
function  CodeGeneration_()  Cmenu='Open/Set'  xinfo('Click on a Superblock (without activation output)'+..	' to obtain a coded block ! ')  k=[]  while %t     [btn,xc,yc,win,Cmenu]=cosclick()    if Cmenu<>[] then      %pt=[];break    elseif btn>31 then      Cmenu=%tableau(min(100,btn-31));%pt=[xc;yc];%win=win      if Cmenu==emptystr() then 	Cmenu=[];%pt=[];      end       break    end    k=getobj(scs_m,[xc;yc])    if k<>[] then      if scs_m.objs(k).model.sim(1)=='super' then	disablemenus()	XX=scs_m.objs(k);	[ok,XX]=do_compile_superblock(XX)	enablemenus()	if ok then 	  scs_m.objs(k)=XX	  edited=%t;	  needcompile=4	  Cmenu='Replot';	  break	end           else	message('Generation Code only work for a Superblock ! ')	break      end    end      endendfunctionfunction [ok,Makename]=buildnewblock() // compiles the generated C code and link it with Scilab//Copyright INRIA//Author : Rachid Djenidi  files=[rdnom rdnom+'_void_io']  [fd,ierr]=mopen(rpat+'/'+rdnom+'f.f','r')  if ierr==0 then mclose(fd),files=[files,rdnom+'f'],end    Makename=gen_make(rdnom,files,archname,rpat+'/'+rdnom+'_Makefile')    //unlink if necessary    [a,b]=c_link(rdnom); while a ; ulink(b);[a,b]=c_link(rdnom);end    libn=ilib_compile('lib'+rdnom,Makename)        ierr=execstr('link(libn,rdnom,''c'')','errcatch')    if ierr<>0 then       ok=%f;x_message(['sorry link problem';lasterror()]);      return;    endendfunctionfunction [ok,Makename]=buildstandalone() // compiles the generated C code and link it with Scilab//Copyright INRIA//Author : Rachid Djenidi  files=[rdnom rdnom+'_standalone']  [fd,ierr]=mopen(rpat+'/'+rdnom+'f.f','r')  if ierr==0 then mclose(fd),files=[files,rdnom+'f'],end    Makename=gen_make(rdnom,files,archname,rpat+'/'+rdnom+'_Makefile')  //unlink if necessary  [a,b]=c_link(rdnom); while a ; ulink(b);[a,b]=c_link(rdnom);end  libn=ilib_compile('lib'+rdnom,Makename)          ierr=execstr('link(libn,rdnom,''c'')','errcatch')  if ierr<>0 then     ok=%f;x_message(['sorry link problem';lasterror()]);    return;  end  endfunctionfunction Code=c_make_doit1(cpr)// produces the code for ddoit1 and edoit1//Copyright INRIA//Author : Rachid Djenidi  Code=[make_ddoit1()	make_edoit1()]endfunctionfunction Code=make_ddoit1()//les pointeurs de cpr :  z=cpr.state.z;tevts=cpr.state.tevts;evtspt=cpr.state.evtspt;  pointi=cpr.state.pointi;  funs=cpr.sim.funs;  zptr=cpr.sim.zptr;inpptr=cpr.sim.inpptr;  outptr=cpr.sim.outptr;  funtyp=cpr.sim.funtyp;  ordptr=cpr.sim.ordptr;ordclk=cpr.sim.ordclk;  clkptr=cpr.sim.clkptr;evtspt=cpr.state.evtspt;  sztvec=max(clkptr(2:$)-clkptr(1:$-1))+1;  nZ=size(z,'*')+size(outtb,'*')+nblk   Code=['';	 '/*'+part('-',ones(1,40))+' ddoit1.c */ ';	 'int '	 cformatline(rdnom+'ddoit1( z, zptr, told, tevts, evtspt, nevts, '+..		     'pointi, outptr, clkptr, ordptr, ordclk, nordcl, rpar, '+..		     'ipar, funptr, funtyp, outtb, iwa)',70); 	 '';	 '     double  *z; ';	 '     integer *zptr; ';	 '     double  *told,  *tevts; ';	 ''	 '     integer *evtspt, *nevts, *pointi, *outptr; ';	 '     integer *clkptr, *ordptr, *ordclk, *nordcl; ';	 '     double  *rpar, *outtb; '; 	 '     integer *ipar, *funptr, *funtyp; '; 	 '     integer *iwa; '; 	 '{'; 	 '  /* System generated locals */ '; 	 '  integer ordclk_dim1, ordclk_offset, i2; '; 	 ' '; 	 '  /* Local variables */ '; 	 '  integer flag, keve, kiwa, nport; ';	 '  double  tvec['+string(sztvec)+']; '; 	 '  double  rdouttb['+string(size(outtb,1)+1)+']; ';	 '  double  *args[100]; '; 	 '  integer sz[100]; ';	 '  integer ierr1; '; 	 '  integer nevprt; '; 	 '  integer urg; '; 	 ' '; 	 '  /* Generated constants */'	 '  integer nrd_'+string(0:maxtotal)'+' = '+string(0:maxtotal)'+';';	 '  /* Parameter adjustments */ '; 	 '  --z; '; 	 '  --zptr; '; 	 '  --tevts; '; 	 '  --evtspt; '; 	 '  --outptr; '; 	 '  --clkptr; '; 	 '  --ordptr; '; 	 ''	 '  ordclk_dim1 = *nordcl; '; 	 '  ordclk_offset = ordclk_dim1 + 1; '; 	 '  ordclk -= ordclk_offset; '; 	 '  --rpar; '; 	 '  --ipar; '; 	 '  --funptr; '; 	 '  --funtyp; ';  	 '  --iwa; '; 	 '  --outtb; ';	 ' '; 	 '  /* Function Body */ '; 	 '  kiwa = 0; ';	 '  urg = 1; ']; //////////////////////////////////////////////////  if  szclkIN>=1 then    pointi=clkptr(howclk)-1;    Code($+1)='  *pointi='+string(pointi)+'+ totalnevprt;';  else    pointi=clkptr(howclk)    Code($+1)='  *pointi='+string(pointi)+';';  end  Code=[Code;	'  tevts[*pointi]=*told;'];  Code=[Code;		 '  if (urg > 0) {';	 ' L43:';	cformatline('    '+rdnom+'edoit1(&z[1], &zptr[1], '+..		    'told, &tevts[1], &evtspt[1], nevts, pointi, '+..		    '&outptr[1], &clkptr[1], &ordptr[1],  '+..		    '&ordclk[ordclk_offset], nordcl, &rpar[1], '+..		    '&ipar[1], &funptr[1], &funtyp[1], '+..		    '&(z['+string(size(z,1)+1)+']), &urg, '+..		    '(int *)(z+'+string(size(z,1)+size(outtb,1)+1)+..		    '),&kiwa);',70);	'    if (urg > 0) {';	'      goto L43;';	'    }';	'  }';	'  iwa['+string(clkptr($))+']=kiwa;';	'  return 0;'	' ';	'} /* ddoit1 */';	'  '];endfunctionfunction Code=make_edoit1()    ///////////////////  //les pointeurs de cpr :  z=cpr.state.z;tevts=cpr.state.tevts;evtspt=cpr.state.evtspt;  pointi=cpr.state.pointi;  funs=cpr.sim.funs;  zptr=cpr.sim.zptr;inpptr=cpr.sim.inpptr;  outptr=cpr.sim.outptr;  funtyp=cpr.sim.funtyp;  ordptr=cpr.sim.ordptr;ordclk=cpr.sim.ordclk;  clkptr=cpr.sim.clkptr;;evtspt=cpr.state.evtspt;  sztvec=max(clkptr(2:$)-clkptr(1:$-1))+1;  nZ=size(z,'*')+size(outtb,'*')+nblk   //////////////////////////////////////////////////  maxkeve=size(evtspt,1);    Code=[ '/*'+part('-',ones(1,40))+' edoit1.c */ ';	 'int '	 cformatline(rdnom+'edoit1( z, zptr, told,tevts, evtspt, nevts, '+..		    'pointi,  outptr, clkptr, ordptr, ordclk, nordcl, '+..		    'rpar, ipar, funptr, funtyp, outtb, urg, iwa, kiwa)',70)	'     double  *z; ';	'     integer *zptr; ';	'     double  *told,  *tevts; ';	'     integer *evtspt, *nevts, *pointi, *outptr; ';	'     integer *clkptr, *ordptr, *ordclk, *nordcl; ';	'     double  *rpar, *outtb; ';	'     integer *ipar,  *funptr, *funtyp; ';	'     integer *urg,  *iwa, *kiwa; ';	'{ ';	'  /* System generated locals */ ';	'  integer ordclk_dim1, ordclk_offset, i2; ';	' ';	'  /* Local variables */ ';	'  integer flag, keve, nport; ';	'  integer nord; ';	'  double  tvec['+string(sztvec)+']; '; 	'  double  rdouttb['+string(size(outtb,1)+1)+']; ';	'  double  *args[100]; '; 	'  integer sz[100]; ';	'  integer ierr1, i, nx=0; ';	'  integer ntvec, ntvecm, nevprt; ';	' ';	'  /* Generated constants */'	'  integer nrd_'+string(0:maxtotal)'+' = '+string(0:maxtotal)'+';';	'  /* Parameter adjustments */ ';	'  --z; ';	'  --zptr; ';	'  --tevts; ';	'  --evtspt; ';	'  --outptr; ';	'  --clkptr; ';	'  --ordptr; ';	'  ordclk_dim1 = *nordcl; ';	'  ordclk_offset = ordclk_dim1 + 1; ';	'  ordclk -= ordclk_offset; ';	'  --rpar; ';	'  --ipar; ';	'  --funptr; ';	'  --funtyp; ';	'  --iwa; ';	'  --outtb; ';	' ';	'  /* Function Body */ ';	'  --(*urg); '	'  keve = *pointi; ';	'  *pointi = evtspt[keve]; ';	'  evtspt[keve] = -1; ';	' ';	'  nord = ordptr[keve + 1] - ordptr[keve]; ';	'  if (nord == 0) { ';	'    return 0; ';	'  } ';	'  ++(*kiwa);   ';	'  iwa[*kiwa] = keve;   ';	'  switch(keve) {'];  for keve=1:maxkeve    Code($+1)='  case '+string(keve)+':';    for ii=ordptr(keve):ordptr(keve+1)-1      //***********************************      fun=ordclk(ii,1);      i=fun;      if outptr(fun+1)-outptr(fun)>0  then	nclock=ordclk(ii,2);	Code=[Code;	      '    flag = 1 ;';	      '    nevprt='+string(nclock)+';';	      '   '+wfunclist(i);	      ' ';	      ' '];       end    end    Code($+1)='    break;';  end  Code($+1)='  }  ';  Code($+1)='  ';  Code($+1)='  switch(keve) {';  for keve=1:maxkeve    Code($+1)='  case '+string(keve)+':';    for ii=ordptr(keve):ordptr(keve+1)-1      //***********************************      fun=ordclk(ii,1);      i=fun;      nevprt=ordclk(ii,2);      ntvec=clkptr(fun+1)-clkptr(fun);      if ntvec >0  & funs(fun) <> 'bidon' then	nxx=lnkptr(inplnk(inpptr(fun)));	if funtyp(fun)==-1 then	  Code=[Code;		'    if (outtb['+string(nxx)+']>0) {';		'      ntvecm=1;';		'    }';		'    else {';		'      ntvecm=2;';		'    }']	elseif funtyp(fun)==-2 then	  Code=[Code;		'    ntvecm=(integer)outtb['+string(nxx)+'];';		'    if(ntvecm>'+string(ntvec)+'){ntvecm='+string(ntvec)+';}';		'    if(ntvecm<1){ntvecm=1;}']	else	  message('Block '+fun+' has funtyp '+string(funtyp(fun))+': not allowed')	end		Code=[Code;	      '     ++(*urg);';	      '     i2 = ntvecm + clkptr['+string(fun)+'] - 1;';	      '     C2F(putevs)(&tevts[1], &evtspt[1],nevts,pointi, told, &i2, &ierr1); ';	      '     if (ierr1 != 0) return 3;']      end    end    Code($+1)='    break;';  end  Code=[Code;	'  }  ';	'  return 0;'	'} /* edoit1 */      '];endfunctionfunction Code=c_make_doit2(cpr);//procuces the code for ddoit2 //Copyright INRIA//Author : Rachid Djenidi/////////////////////les pointeurs de cpr :  z=cpr.state.z;tevts=cpr.state.tevts;evtspt=cpr.state.evtspt;  pointi=cpr.state.pointi;  funs=cpr.sim.funs;  zptr=cpr.sim.zptr;inpptr=cpr.sim.inpptr;  outptr=cpr.sim.outptr;  funtyp=cpr.sim.funtyp;  ordptr=cpr.sim.ordptr;ordclk=cpr.sim.ordclk;  clkptr=cpr.sim.clkptr;evtspt=cpr.state.evtspt;  sztvec=max(clkptr(2:$)-clkptr(1:$-1))+1;  nZ=size(z,'*')+size(outtb,'*')+nblk   Code=['';	'/*'+part('-',ones(1,40))+' ddoit2 */ ';	'int '	cformatline(rdnom+'ddoit2( z, zptr, told, tevts, evtspt, nevts, '+..		    'pointi, outptr, clkptr, ordptr, ordclk, nordcl, rpar,  '+..		    'ipar, funptr, funtyp, outtb, iwa)',70);  	''; 	'     double  *z; '; 	'     integer *zptr; '; 	'     double  *told,  *tevts; '; 	'     integer *evtspt, *nevts, *pointi, *outptr; '; 	'     integer *clkptr, *ordptr, *ordclk, *nordcl; '; 	'     double  *rpar, *outtb; '; 	'     integer *ipar, *funptr, *funtyp; '; 	'     integer *iwa; '; 	'{ '; 	'  /* System generated locals */ '; 	'  integer  i1, i; '; 	' '; 	'  /* Local variables */ '; 	'  integer flag, keve, kiwa, nport; '; 	'  double  tvec['+string(sztvec)+']; '; 	'  double  rdouttb['+string(size(outtb,1)+1)+']; ';	'  double  *args[100]; '; 	'  integer sz[100]; ';	'  integer ntvec; '; 	'  integer nevprt; '; 	' '; 	'  /* Generated constants */'	'  integer nrd_'+string(0:maxtotal)'+' = '+string(0:maxtotal)'+';';		'    /* Parameter adjustments */ '; 	'  --z; '; 	'  --zptr; '; 	'  --tevts; '; 	'  --evtspt; '; 	'  --outptr; '; 	'  --clkptr; '; 	'  --ordptr; '; 	'  --rpar; '; 	'  --ipar; '; 	'  --funptr; '; 	'  --funtyp; '; 	'  --iwa; '; 	'  --outtb; ';	' '; 	'  /* Function Body */ '; 	' '	'  /*update continuous and discrete states on event */';	'  kiwa = iwa['+string(clkptr($))+'];';	'  if (kiwa == 0) {';	'    return 0 ;';	'  }';	'  i1 = kiwa;';	'  for (i = 1; i <= i1; ++i) {';	'    keve = iwa[i];';	'    switch(keve) {'];  maxkeve=size(evtspt,1);  for keve=1:maxkeve    Code($+1)='    case '+string(keve)+':';    for ii=ordptr(keve):ordptr(keve+1)-1      //***********************************      fun=ordclk(ii,1);      i=fun;      //Actuator blocks have to be called even if they have no discrete      //state      is_act=or(i==act)      if (zptr(i+1)-zptr(i))>0|is_act  then	//  Code($+1)='/*     .     If continuous state jumps, do cold restart */';	Code=[Code	      '    flag = 2;';	      '    nevprt='+string(ordclk(ii,2))+';';	      '   '+wfunclist(i);];      end      end       Code($+1)='    break;';  end  Code=[Code	'    }'; //switch	'  }';	'  return 0;'	'} /* ddoit2 */'];endfunctionfunction Code=c_make_endi(cpr)//Copyright INRIA//Author : Rachid Djenidi/////////////////////les pointeurs de cpr :z=cpr.state.z;tevts=cpr.state.tevts;evtspt=cpr.state.evtspt;pointi=cpr.state.pointi;funs=cpr.sim.funs;zptr=cpr.sim.zptr;inpptr=cpr.sim.inpptr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -