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

📄 rtaicodegen_.sci

📁 rtai-3.1-test3的源代码(Real-Time Application Interface )
💻 SCI
📖 第 1 页 / 共 5 页
字号:
ordptr=cpr.sim.ordptr;ordclk=cpr.sim.ordclk;clkptr=cpr.sim.clkptr;evtspt=cpr.state.evtspt;sztvec=max(clkptr(2:$)-clkptr(1:$-1))+1;Code=[	'/*'+part('-',ones(1,40))+' endi */ '; 	'/* file_end.c */ ';	'/* Subroutine */ int ';	rdnom+'_endi( z, zptr, told, ';	'    tevts, evtspt, nevts, pointi, outptr, '; 	'    clkptr, ordptr, ordclk, nordcl,  '; 	'    rpar, ipar, funptr, funtyp, outtb, iwa) ';  	''; 	'     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; '; 	'{ '; 	'  /* Local variables */ '; 	'  integer flag; '; 	'  double  tvec['+string(sztvec)+']; '; 	'  double  rdouttb['+string(size(outtb,1)+1)+']; ';	'  double  *args[100]; '; 	'  integer sz[100]; ';	'  integer nport; '; 	'  integer ntvec; '; 	'  integer nevprt=0; '; 	' '; 	'  /* 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 */ ';  	''	'  /*     ending  subroutine */';	'  flag=5 ;'];for i=1:size(wfunclist)  Code=[Code;	'';	'  '+wfunclist(i);	'';];end   Code=[Code;      '  return 0;'      '} /* ending */';      ''];endfunctionfunction Code=c_make_initi(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;  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;  Code=['/*'+part('-',ones(1,40))+' initi */ ';	'int '	rdnom+'_initi( z, zptr, told, tevts, evtspt, nevts, pointi, outptr,'; 	'	clkptr, ordptr, ordclk, nordcl, rpar, ipar, funptr, funtyp, '	'    outtb, iwa) ';  	''; 	'     /*Block initialization (flag=4)*/'	'     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; '; 	'{ '; 	' '; 	'  /* Local variables */ '; 	'  integer flag; '; 	'  double  tvec['+string(sztvec)+']; '; 	'  double  rdouttb['+string(size(outtb,1)+1)+']; ';	'  double  *args[100]; '; 	'  integer sz[100]; ';	'  integer nport; '; 	'  integer ntvec; '; 	'  integer nevprt=0; '; 	' '; 	'  /* 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 */ ';  	'  ';	'  flag=4 ;'];  for i=1:size(wfunclist)    Code=[Code	  '  '+wfunclist(i);	  '  '];  end     Code=[Code	'  return 0;'	'} /* '+rdnom+'_initi */'];endfunctionfunction Code=c_make_outtb()//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;  iord=cpr.sim.iord;niord=size(iord,1);  sztvec=max(clkptr(2:$)-clkptr(1:$-1))+1;  Code=['/*'+part('-',ones(1,40))+' outtbini */ ';	'int '	rdnom+'_outtb( z, zptr, told, tevts, evtspt, nevts, pointi, outptr,'; 	'	clkptr, ordptr, ordclk, nordcl, rpar, ipar, funptr, funtyp, '	'    outtb, iwa) ';  	''; 	'     /*Constants propagation*/'	'     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; '; 	'{ '; 	' '; 	'  /* Local variables */ '; 	'  integer flag; '; 	'  double  tvec['+string(sztvec)+']; '; 	'  double  rdouttb['+string(size(outtb,1)+1)+']; ';	'  double  *args[100]; '; 	'  integer sz[100]; ';	'  integer nport; '; 	'  integer ntvec; '; 	'  integer nevprt=0; '; 	' '; 	'  /* 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 */ ';  	'  ';	'  flag=1 ;'];    for i=iord(:,1)'    if (outptr(i+1)-outptr(i))>0 then      Code=[Code	    '  '+wfunclist(i);]    end  end     Code=[Code	'  return 0;'	'} /* '+rdnom+'_outtb */'];endfunctionfunction [Code,actt,proto]=call_actuator(i)    nin=inpptr(i+1)-inpptr(i); ///* number of input ports */  nout=outptr(i+1)-outptr(i); ///* number of output ports */   if funtyp(i)==0 then    if nin==0 then      uk=0;      nuk=0;      Code=+'args[0]=&(outtb[1]);';    else      lprt=inplnk(inpptr(i));      uk=lnkptr(lprt);      nuk=(lnkptr(lprt+1))-uk;      Code='args[0]=&(outtb['+string(uk)+']);';    end  end    //pour la fonction gui ont a : num de bloc l'adresse dans  //nouveau  z et la taille du port  actt=[i uk nuk bllst(i).ipar]    Code=[Code;	 'nport = '+string(nbact)+';';	 rdnom+'_actuator(&flag, &nport, &nevprt, told, '+..	 '(double *)args[0], &nrd_'+string(nuk)+');'];  proto='void '+rdnom+'_actuator(int *flag, int *nport, int *nevprt, double *t,"+...	" double *u, int *nu);"  proto=cformatline(proto,70);endfunctionfunction [Code,proto]=call_block(i) //Copyright INRIA//Author : Rachid Djenidi   nx=xptr(i+1)-xptr(i);  nz=zptr(i+1)-zptr(i);  nrpar=rpptr(i+1)-rpptr(i);  nipar=ipptr(i+1)-ipptr(i);  nin=inpptr(i+1)-inpptr(i); ///* number of input ports */  nout=outptr(i+1)-outptr(i); ///* number of output ports */  fun=funs(i);     //l'adresse du pointeur de ipar  if nipar<>0 then ipar=ipptr(i);else ipar=1;end    //l'adresse du pointeur de rpar  if nrpar<>0 then rpar=rpptr(i);else rpar=1; end  //l'adresse du pointeur de z   if nz<>0 then z=zptr(i);else z=1;end  //l'adresse du pointeur de x  if nx<>0 then x=xptr(i);else x=1;end  //  [Code,proto]=callf(i);endfunctionfunction [Code,proto]=callf(i)//Generates the code associated with the call to the simulation function //of one original block  //Copyright INRIA//Author : Rachid Djenidi  Code=[];proto=''  ftyp=funtyp(i)  if ftyp<0 then return,end  if ftyp>2000 then ftyp=ftyp-2000,end  if ftyp>1000 then ftyp=ftyp-1000,end    //******************************************  //Generate c code for input output arguments  //******************************************  if ftyp==0 then    if nin>1 then      for k=1:nin	lprt=inplnk(inpptr(i)-1+k);	uk=lnkptr(lprt);	nuk=(lnkptr(lprt+1))-uk;	Code($+1)='rdouttb['+string(k-1)+']=outtb['+string(uk)+'];';      end      Code($+1)='args[0]=&(rdouttb[0]);';    elseif nin==0      uk=0;      nuk=0;      Code($+1)=+'args[0]=&(outtb[1]);';    else      lprt=inplnk(inpptr(i));      uk=lnkptr(lprt);      nuk=(lnkptr(lprt+1))-uk;      Code($+1)='args[0]=&(outtb['+string(uk)+']);';    end    if nout>1 then      for k=1:nout	lprt=outlnk(outptr(i)-1+k);	yk=lnkptr(lprt);	nyk=(lnkptr(lprt+1))-yk;	Code($+1)='rdouttb['+string(k+nin-1)+']=outtb['+..	    string(yk)+'];';      end      Code($+1)='args[1]=&(rdouttb['+string(nin)+']);';    elseif nout==0      yk=0;      nyk=0;      Code($+1)=+'args[1]=&(outtb[1]);';    else      lprt=outlnk(outptr(i));      yk=lnkptr(lprt);      nyk=(lnkptr(lprt+1))-yk;      Code($+1)='args[1]=&(outtb['+string(yk)+']);';    end  elseif ftyp==1    if nin>=1 then      for k=1:nin	lprt=inplnk(inpptr(i)-1+k);	uk=lnkptr(lprt);	nuk=(lnkptr(lprt+1))-uk;      end    end    if nout>=1 then      for k=1:nout	lprt=outlnk(outptr(i)-1+k);	yk=lnkptr(lprt);	nyk=(lnkptr(lprt+1))-yk;      end    end  elseif ftyp==2    for k=1:nin      lprt=inplnk(inpptr(i)-1+k);      uk=lnkptr(lprt)-1;      nuk=(lnkptr(lprt+1))-uk;      Code=[Code	    'args['+string(k-1)+'] = &(outtb['+string(uk+1)+']);';	    'sz['+string(k-1)+'] = '+string(nuk-1)+';'];    end    for k=1:nout      lprt=outlnk(outptr(i)-1+k);      yk=lnkptr(lprt)-1;      nyk=(lnkptr(lprt+1))-yk;      Code=[Code	    'args['+string(k+nin-1)+'] = &(outtb['+string(yk+1)+']);';	    'sz['+string(k+nin-1)+'] = '+string(nyk-1)+';'];    end  end  //************************  //generate the call itself  //************************  if ftyp==0 | ftyp==1 then    CodeC='C2F(' +fun+')(&flag, &nevprt,told, &(w['+..	  string(x)+']), &(x['+string(x)+']), &nrd_'+string(nx)+..	  ', &(z['+string(z)+']), &nrd_'+string(nz)+', '+..	  'tvec, &ntvec, &(rpar['+string(rpar)+']), &nrd_'+..	  string(nrpar)+', &(ipar['+..	  string(ipar)+']), &nrd_'+string(nipar);    proto='void '+"C2F(" +string(fun)+")(int *flag, int *nevprt, double *told,"+...	  " double *xd, double *x, int *nx, double *z, int *nz, double *tvec,"+...	  " int *ntvec, double *rpar, int *nrpar,int *ipar,int *nipar"    if ftyp==0 then      CodeC=CodeC+', (double *)args[0], &nrd_'+string(nuk)+..	    ', (double *)args[1], &nrd_'+string(nyk)+');';       proto=proto+", double *u, int *nu, double *y, int *ny);"    elseif ftyp==1      if nin>=1 then	for k=1:nin	  lprt=inplnk(inpptr(i)-1+k);	  uk=lnkptr(lprt);	  CodeC=CodeC+', &(outtb['+string(uk)+']), &nrd_'+string(nuk);	  proto=proto+", double *u"+string(k)+", int *nu"+string(k)	end      end      if nout>=1 then	for k=1:nout	  lprt=outlnk(outptr(i)-1+k);	  yk=lnkptr(lprt);	  CodeC=CodeC+', &(outtb['+string(yk)+']), &nrd_'+string(nyk);	  proto=proto+", double *y"+string(k)+", int *ny"+string(k)	end      end      CodeC=CodeC+');';       proto=proto+');'    end  elseif ftyp==2     CodeC=fun+'(&flag, &nevprt, told,&(w['+string(x)+..	 ']), &(x['+string(x)+']), &nrd_'+string(nx);    CodeC=CodeC+', &(z['+string(z)+']),&nrd_'+string(nz)+..	 ', tvec, &ntvec, &(rpar['+string(rpar)+']), &nrd_'+..       string(nrpar)+',&(ipar['+string(ipar)+'])';    CodeC=CodeC+', &nrd_'+string(nipar)+', &(args[0]), &(sz[0]), &nrd_'+..       string(nin)+',&(args['+string(nin)+']),&(sz['+string(nin)+..	 ']),&nrd_'+string(nout)+');';        proto='void '+fun+"(int *flag, int *nevprt,double *told,"+...	  " double *xd, double *x, int *nx, double *z, int *nz, double *tvec, "+...	  " int *ntvec, double *rpar, int *nrpar, int *ipar, int *nipar, "+...	  " double **inptr, int* insz, int *nin, double **outptr,int"+...	  " *outsz, int *nout);"   end  //  Code=[Code;cformatline(CodeC,70);' ']  proto=cformatline(proto,70);endfunctionfunction [Code,capt,proto]=call_sensor(i)    nin=inpptr(i+1)-inpptr(i); ///* number of input ports */  nout=outptr(i+1)-outptr(i); ///* number of output ports */    //declaration des I/O des blocs de type 1  if funtyp(i)==0 then    if nout==0 then      yk=0;      nyk=0;      Code=+'args[1]=&(outtb[1]);';    else      lprt=outlnk(outptr(i));      yk=lnkptr(lprt);      nyk=(lnkptr(lprt+1))-yk;      Code='args[1]=&(outtb['+string(yk)+']);';    end  end  capt=[i yk nyk bllst(i).ipar]  Code=[Code;	 'nport = '+string(nbcap)+';'; 	 rdnom+'_sensor(&flag, &nport, &nevprt, '+..	 'told, (double *)args[1], &nrd_'+string(nyk)+');'];  proto='void '+rdnom+'_sensor(int *flag, int *nport, int *nevprt, double *t,"+...	" double *y, int *ny);"  proto=cformatline(proto,70);endfunctionfunction t1=cformatline(t ,l)//utilitary fonction used to format long C instruction

⌨️ 快捷键说明

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