Computational routine
eng


corrblk title

File content


/* 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.
 */
 
/* corrblk Scicos discrete correlation block
 * Type 4 simulation function ver 1.0 - scicoslab 4.3
 * 1er Juin 2009 - INRIA - Author : A.Layec
 */

/* REVISION HISTORY :
 * $Log$
 */

#include <scicos/scicos_block4.h>
#include "modnum_lib.h"

/* work struct for that block */
typedef struct {
  SCSREAL_COP *mean_1;
  SCSREAL_COP *mean_2;
} wrk_struct ;

/* Cette fonction réalise la corrélation discrète de 2 vecteurs.
 *
 * Entrées régulières : u_1[0..mu*nu-1] : vecteur 1 d'entrée de taille nu*mu
 * Entrées régulières : u_2[0..mu*nu-1] : vecteur 2 d'entrée de taille nu*mu
 * sorties régulières : y[0..mu*lag-1]  : vecteur de sortie de taille mu*lag
 *
 * paramètres entiers : typ : type de la correlation.
 *                            si typ=1 alors les moyennes des vecteurs
 *                            d'entrée sont automatiquement calculées
 */

/*prototype*/
void corrblk(scicos_block *block,int flag)
{
  /*déclaration*/
  SCSREAL_COP *y;
  SCSREAL_COP *u_1,*u_2;
  int nu,mu;
  int lag;
  int *typ;
  int i;

  /* the struct ptr of that block */
  wrk_struct *ptr;

  /*récupération de l'adresse des ports réguliers*/
  u_1 = GetRealInPortPtrs(block,1);
  u_2 = GetRealInPortPtrs(block,2);
  y   = GetRealOutPortPtrs(block,1);

  /*récupération de la taille des ports réguliers*/
  nu  = GetInPortRows(block,1);
  mu  = GetInPortCols(block,1);
  lag = GetOutPortRows(block,1);

  /*récupération des paramtères*/
  typ = GetIparPtrs(block);

  /*Le flag 4 initialise*/
  if(flag==4) {
    if((*(block->work)=(wrk_struct*) scicos_malloc(sizeof(wrk_struct)))==NULL) {
      set_block_error(-16);
      return;
    }

    ptr         = *(block->work);
    ptr->mean_1 = NULL;
    ptr->mean_2 = NULL;

    if((ptr->mean_1=(SCSREAL_COP *) \
         scicos_malloc(mu*sizeof(SCSREAL_COP)))==NULL) {
      set_block_error(-16);
      scicos_free(ptr);
      *(block->work) = NULL;
      return;
    }
    if((ptr->mean_2=(SCSREAL_COP *) \
         scicos_malloc(mu*sizeof(SCSREAL_COP)))==NULL) {
      set_block_error(-16);
      scicos_free(ptr);
      *(block->work) = NULL;
      return;
    }

    /* initialisation des moyennes */
    for(i=0;i<mu;i++) {
      ptr->mean_1[i]=0.;
      ptr->mean_2[i]=0.;
    }
  }
  /*Le flag 1 calcule y*/
  else if(flag==1) {
    /* récupération du ptr du work */
    ptr         = *(block->work);

    /* appel corr_c */
    corr_c(&nu,&mu,typ,&lag,ptr->mean_1,ptr->mean_2,u_1,u_2,y);
  }
  /*Le flag 5 termine*/
  else if(flag==5) {
    /* récupération du ptr du work */
    ptr = *(block->work);

    scicos_free(ptr->mean_1);
    scicos_free(ptr->mean_2);
    scicos_free(ptr);
  }

}