vcoevt
/* Modnumlib Scicos interfacing function
* Copyright (C) 2009 Alan Layec
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* vcoevt Scicos Time transition calculator block
* Type 4 simulation function ver 1.1 - scilab-3
* 7 Avril 2004 - IRCOM GROUP - Author : A.Layec
* 21 Novembre 2004 : rajout option ipar[0]
* 10 janvier 2005 : passage au type 4
*/
/* REVISION HISTORY :
* $Log$
*/
#include "scicos_block.h"
/* Cette fonction réalise le calcul approximé de la date d'évenement
* correspondant au passage du signal d'entrée aux valeurs rpar[1]
* (rpar[1]*u2[0] si ipar[0]=1).
* Rmq : L'entrée est considérée strictement croissante et monotone.
*
* entrées régulières : u1[0] : wot+phi(t)
* u2[0] : entrée dynamique(rapport de division)
* sortie régulière : néant
* entrée d'évenement : Pas de calcul : Tsampl
* sortie d'évenement : date du passage à rpar[1] (ou rpar[1]*u2[0])
* paramètre entier : ipar[0] : 0 : passage aux valeurs rpar[1]
* 1 : passage aux valeurs rpar[1]*u2[0]
* paramètres réels : rpar[0] : Tsampl
* rpar[1] : valeur de passage en radian
* état discret : z[0] : u(k-1)
* z[1] : valeur de u à la date de passage
*/
/*prototype*/
void vcoevt(scicos_block *block,int flag)
{
/*déclaration des variables*/
double *u1;
double v; /*valeur de passage*/
/*Récupération des adresses des ports d'entrées*/
u1=(double *)block->inptr[0];
/*Test si entrée 2*/
if (block->ipar[0]==1)
{
/*déclaration*/
double *u2;
/*récupération adresse*/
u2=(double *)block->inptr[1];
v=block->rpar[1]*u2[0];
}
else v=block->rpar[1];
/*le flag 3 calcul la date de transition*/
if(flag==3)
{
/*Test si la valeur est >=rpar[1]*/
if((u1[0]-block->z[1])>=v)
{
/*Calcul la date par extrapolation*/
/*tvec[0] = *t + (((z[1]+v)-z[0])*rpar[0])/(u1[0]-z[0]);*/
block->evout[0]=(((block->z[1]+v)-block->z[0])*block->rpar[0])/(u1[0]-block->z[0]);
/*mémorise valeur à la date*/
block->z[1] = block->z[1] + v;
}
/*mémorise u*/
block->z[0]=u1[0];
}
}