/* 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. */ /* z_buf41 Scicos discrete memory block * Type 4 simulation function ver 1.0 - scilab-3.0 * 31 mars 2007 - INRIA - Author : A.Layec * Révision */ /* REVISION HISTORY : * $Log$ */ #include "machine.h" #include "scicos_block.h" #ifdef __STDC__ extern int Scierror __PARAMS((int iv,char *fmt,...)); #else extern int Scierror __PARAMS(()); #endif /* Cette fonction de simulation est un buffer * qui mémorise la valeur de son entrée régulière * dans le vecteur des états discrets z * * entrée régulière : u[0..nu-1] * sortie régulière : néant * entrée évènementielle : Date de déclenchement * sortie évènementielle : néant * * état discret : z[0] : compteur * z[1..ipar[0]] : mot mémoire * * paramètre entier : ipar[0] : taille du mot mémoire * ipar[1] : avec valeur événement * (0: no, 1:yes) */ /*prototype*/ void z_buf41(scicos_block *block,int flag) { /*déclaration des variables*/ int i,j,k; int evt; int m; /*récupère la taille du buffer*/ m=block->ipar[0]; /*récupère option with_evt*/ evt = block->ipar[1]; /*init*/ if(flag==4) { /* vérifie que la taille des entrées est < à * la taille du buffer */ if (block->insz[0]>block->ipar[0]) { Scierror(888,"Size of input is greater than the buffer size.\n"); set_block_error(-3); return; } } /*seulement sur flag 2*/ else if(flag==2) { /*récupère valeur du compteur échantillons*/ j=(int)block->z[0]; /*Test valeur compteur échantillons*/ if (j+block->insz[0]<m) { if(evt==1) { /*met en mémoire la(les) valeur(s) du port réguliers + date*/ for(i=0;i<block->insz[0];i++) { block->z[1+j+i]=get_scicos_time(); } /*pour chaque entrée*/ for(k=0;k<block->nin;k++) { for(i=0;i<block->insz[0];i++) { block->z[k*m+1+m+j+i]=block->inptr[k][i]; } } } else { /*met en mémoire la(les) valeur(s) du port réguliers*/ /*pour chaque entrée*/ for(k=0;k<block->nin;k++) { for(i=0;i<block->insz[0];i++) { block->z[k*m+1+j+i]=block->inptr[k][i]; } } } /*incrémente compteur échantillons*/ j=j+block->insz[0]; } else { if(evt==1) { /*met en mémoire à la fin du buffer + date*/ for(i=0;i<m-j;i++) { block->z[1+j+i]=get_scicos_time(); } /*pour chaque entrée*/ for(k=0;k<block->nin;k++) { for(i=0;i<m-j;i++) { block->z[k*m+1+m+j+i]=block->inptr[k][i]; } } /*met en mémoire au début du buffer + date*/ for(i=m-j;i<block->insz[0];i++) { block->z[1+j+i-m]=get_scicos_time(); } /*pour chaque entrée*/ for(k=0;k<block->nin;k++) { for(i=m-j;i<block->insz[0];i++) { block->z[k*m+1+m+j+i-m]=block->inptr[k][i]; } } } else { /*pour chaque entrée*/ for(k=0;k<block->nin;k++) { /*met en mémoire à la fin du buffer*/ for(i=0;i<m-j;i++) { block->z[k*m+1+j+i]=block->inptr[k][i]; } /*met en mémoire au début du buffer*/ for(i=m-j;i<block->insz[0];i++) { block->z[k*m+1+j+i-m]=block->inptr[k][i]; } } } /*met à jour compteur échantillons*/ j=block->insz[0]-m+j; } /*mémorise compteur dans z[n+1]*/ block->z[0]=(double)j; } }