int_symb
/* Modnumlib Scicos interfacing function
* Copyright (C) 2009-2011 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.
*/
/* int_symb scicos Symbol Integrator
* Type 4 simulation function ver 1.0 - scilab-3.0
* 22 Décembre 2004 Author : - IRCOM GROUP - A.Layec
*/
/* REVISION HISTORY :
* $Log$
*/
#include <scicos/scicos_block.h>
#include "modnum_lib.h"
/* Entrée régulière : u[0..nu] : vecteur à intégrer
* Sortie régulière : y[0..nu]=integral(u[0..nu]) : vecteur intégré
* Entrée évènementielle : (à la rigueur)
* Sortie évènementielle : néant
*
* Paramètres entier : ipar[0] : Longueur en échantillons du symbole
* ipar[1] : echantillon initial d'integration
* insz[0] : taille du vecteur d'entrée
*
* Paramètres réels : rpar[0] : gain en sortie
*
* Etat discret : z[0] : mémoire valeur intégrée précedente (pour le bout du vecteur)
*
*/
/*work structure of that block*/
typedef struct work_st {
double *y__; /* discrete state of filters */
int *init_c; /* counter state */
} work_struct;
/*prototype*/
void int_symb(scicos_block *block,int flag)
{
/*Déclaration des variables*/
double *y;
double *u;
double *u2;
double step;
int *init_c;
int nu,nech;
int mu=1; /* */
int i;
/*ptr of the struct of that block*/
work_struct *work;
/*Récupération des adresses des ports réguliers*/
y = (double *)block->outptr[0];
u = (double *)block->inptr[0];
/*u2 = (double *)block->inptr[1];*/
/*Récupération du nombre d'échantillons*/
nu = block->insz[0];
step = block->rpar[0];
nech = block->ipar[0];
init_c = &block->ipar[1];
/*get the struct of that block*/
work = (work_struct*) *block->work;
/*initialisation*/
if(flag==4) {
/*allocation*/
if ((work=(work_struct*) scicos_malloc(sizeof(work_struct))) == NULL) {
set_block_error(-16);
return;
}
/*etats cachés pour le calcul des états discrets*/
if ((work->y__=(double*) scicos_malloc(mu*nu*sizeof(double))) == NULL) {
set_block_error(-16);
return;
}
/* compteur échantillons */
if ((work->init_c=(int*) scicos_malloc(mu*sizeof(int))) == NULL) {
set_block_error(-16);
return;
}
/*appel copyi_c*/
copyi_c(&mu,init_c,work->init_c);
/*store my_st in block->work*/
*block->work=(void *)work; /*store my_st in *block->work*/
}
/*calcul des sorties*/
else if(flag==1) {
/*Appel intsymb_c*/
intsymy_c(&nu,&mu,&nech,work->init_c,&step,&u[0],&y[0],&block->z[0]);
}
/*calcul des états*/
else if(flag==2) {
/*Appel intsymb_c*/
intsym_c(&nu,&mu,&nech,work->init_c,&step,&u[0],work->y__,&block->z[0]);
/*calc_init_c(&nu,&mu,&nech,work->init_c);*/
}
/*terminaison*/
else if(flag==5) {
if (work!=NULL) {
scicos_free(work->y__);
scicos_free(work->init_c);
}
scicos_free(work);
}
}