ratelimiter.c

Go to the documentation of this file.
00001 #include "scicos_block.h"
00002 #include <math.h>
00003 
00004 void ratelimiter(scicos_block *block,int flag)
00005 {/*  rpar[0]=rising rate limit, rpar[1]=falling rate limit */
00006   double* pw,rate,t;
00007   if (flag == 4){/* the workspace is used to store previous values */
00008     if ((*block->work=
00009          scicos_malloc(sizeof(double)*4))== NULL ) {
00010       set_block_error(-16);
00011       return;
00012     }
00013     pw=*block->work; 
00014     pw[0]=0.0;
00015     pw[1]=0.0;
00016     pw[2]=0.0;
00017     pw[3]=0.0;
00018   }else  if (flag == 5){
00019     scicos_free(*block->work);
00020   } else if (flag==1) {
00021     if (get_phase_simulation()==1) do_cold_restart();
00022     pw=*block->work; 
00023     t=get_scicos_time();
00024     if(t>pw[2]){
00025       pw[0]=pw[2];
00026       pw[1]=pw[3];
00027       rate=(block->inptr[0][0]-pw[1])/(t-pw[0]);
00028     }
00029     else if(t<=pw[2]){
00030       if(t>pw[0]){
00031         rate=(block->inptr[0][0]-pw[1])/(t-pw[0]);
00032       }else{
00033         rate=0.0;
00034       }
00035     }
00036     if(rate>block->rpar[0]){
00037       block->outptr[0][0]=(t-pw[0])*block->rpar[0]+pw[1];
00038     } else if(rate<block->rpar[1]){
00039       block->outptr[0][0]=(t-pw[0])*block->rpar[1]+pw[1];
00040     }else{
00041       block->outptr[0][0]=block->inptr[0][0];
00042     }
00043     pw[2]=t;
00044     pw[3]=block->outptr[0][0];
00045   }
00046 }

Generated on Sun Mar 4 15:03:59 2007 for Scilab [trunk] by  doxygen 1.5.1