/* 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. */ /* teb2 Scicos block * Type 4 simulation function ver 1.0 - scilab-3.0 * 9 Novembre 2004 - IRCOM GROUP - Author : A.Layec * 15 Fev 2005 : rajout option sur nbre d'évènement */ /* REVISION HISTORY : * $Log$ */ #include <scicos/scicos_block.h> /* Cette fonction de simulation réalise la comparaison * bit à bit de deux vecteurs d'entiers non signé. * Lorsque qu'un élément des vecteurs diffère, la fonction * cherche quel bit est faux et incrémente son état discret pour * chaque bit faux(flag2), puis elle recopie l'état discret * sur la sortie(flag1) * * Entrée régulière : inptr[0][0..Nu-1] : Vecteur d'entier 1 * inptr[1][0..Nu-1] : Vecteur d'entier 2 * Sortie régulière : outptr[0][0] : Valeur du compteur d'erreur * Entrée évènementielle : à la rigueur(hérit) * Sortie évènementielle : néant * * Paramètres entier : insz[0] : taille des vecteurs d'entrée * ipar[0] : Nombre de bits * ipar[1] : Nombre d'èvenement avant comptage * état discret : z[0] : compteur nb d'erreur * z[1] : compteur evènement */ /*prototype*/ void teb2(scicos_block *block,int flag) { /*déclaration des variables*/ int a,b,c; int i,j; /*Le flag 1 recopie la valeur de z[0] dans outptr[0][0]*/ if(flag == 1) { block->outptr[0][0]=block->z[0]; } /*Le flag 2 réalise la comparaison bit à bit*/ else if(flag == 2) { block->z[1]=block->z[1]+1; /*fprintf(stderr,"z[1]=%d\n",(int)block->z[1]);*/ if((int)block->z[1]>block->ipar[1]) { for(i=0;i<block->insz[0];i++) { a=(int)block->inptr[0][i]; b=(int)block->inptr[1][i]; /*fprintf(stderr,"a=%d, b=%d\n",a,b);*/ c=a^b; if(c!=0) /*si différence entre les éléments i*/ { for(j=0;j<block->ipar[0];j++) { if((1<<j & c)==1<<j) /*comparaison bit à bit*/ { /*fprintf(stderr,"bit %d faux\n",j);*/ block->z[0]++; /*incrémente compteur*/ } } } } } } }