#include "scicos_block.h"#include <math.h>Include dependency graph for ratelimiter.c:

Go to the source code of this file.
Functions | |
| void | ratelimiter (scicos_block *block, int flag) |
| void ratelimiter | ( | scicos_block * | block, | |
| int | flag | |||
| ) |
Definition at line 4 of file ratelimiter.c.
References do_cold_restart(), get_phase_simulation(), get_scicos_time(), scicos_block::inptr, NULL, scicos_block::outptr, rate, scicos_block::rpar, scicos_free(), scicos_malloc(), set_block_error(), t, and scicos_block::work.
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 }
Here is the call graph for this function:

1.5.1