/* 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. */ /* upsmplblk Scicos temporal oversampling and zero insert block * Type 4 simulation function ver 1.0 - scilab-3.0 * 27 mars 2007 Author : - INRIA - A.Layec */ /* REVISION HISTORY : * $Log$ */ #include <scicos/scicos_block.h> #include "modnum_lib.h" /* Entrée régulière : signal à surechantilonner * Sortie régulière : signal suréchantilonné * Entrée évènementielle : néant * Sortie évènementielle : néant * * Paramètres entier : insz[0] : taille du vecteur en entrée * ipar[0] : nombre d'échantillons * ipar[1] : option * 0/1 : traitement séquentiel * 2/3 : traitement vectoriel * 0/2 : pas d'insertion de zéro * 1/3 : insertion zéro * ipar[2] : valeur initiale du numéro échantillons * */ /*prototype*/ void upsmplblk(scicos_block *block,int flag) { /*déclaration des variables*/ double *y; double *u; int i,opt,nu,nech,ny; int mu=1; int *init_c; int *counter; /*Récupération des adresses des ports réguliers*/ y=(double *)block->outptr[0]; u=(double *)block->inptr[0]; /*récupération du nombre d'échantillons*/ nu=block->insz[0]; ny=block->outsz[0]; nech=block->ipar[0]; opt=block->ipar[1]; init_c=&block->ipar[2]; /*initialisation*/ if(flag==4) { /*allocation du tableau pour les compteurs*/ if (((*block->work)=(int *)scicos_malloc(mu*sizeof(int))) == NULL) { set_block_error(-16); return; } /* */ counter=(int *) *block->work; /*appel copyi_c*/ copyi_c(&mu,init_c,counter); } /* Le flag 1 teste la valeur du compteur échantillon * et délivre u[] dans y[] quand le compteur * arrive à la valeur ipar[0] */ else if((flag==1)||(flag==6)) { /* */ counter=(int *) *block->work; /*** vector ***/ if (opt==2||opt==3) { opt=opt-2; /*Appel routine surecht_c*/ surechty_c(&opt,&nu,&mu,&nech,counter,&u[0],&y[0]); } /*** scalar ***/ else if(opt==0) { /*resample*/ for(i=0;i<block->insz[0];i++) y[i]=u[i]; } else if(opt==1) { /*zero inser*/ /*si z[]=ipar[0] y[]=u[]*/ if(counter[0]==nech) { for(i=0;i<block->insz[0];i++) y[i]=u[i]; } /*si z[]!=ipar[0] y[]=0*/ else { for(i=0;i<block->insz[0];i++) y[i]=0; } } } /*calcul des états*/ else if(flag==2) { /* */ counter=(int *) *block->work; /*** vector ***/ if (opt==2||opt==3) { /*appel routine calc_init_c*/ calc_init_c((i=nech*nu,&i), &mu, &nech , counter); } /*** scalar ***/ else if(opt==1) { /*zero inser*/ if(counter[0]==nech) { counter[0]=1; /*RAZ compteur*/ } else { counter[0]++; /*incrémente compteur*/ } } } /*terminaison*/ else if(flag==5) { scicos_free(*block->work); } }