Computational routine
eng


noiseblk

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.
 */
 
/* noiseblk Scicos Gaussian random generator block
 * Type 4 simulation function ver 1.0 - scilab-3.0
 * 22 décembre 2004 - IRCOM GROUP - Author : A.Layec
 */

/* REVISION HISTORY :
 * $Log$
 */

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

void noiseblk(scicos_block *block,int flag)
{
  /*Déclaration des variables*/
  double *y1;
  double *y2=NULL;
  int ny,typ;

  /*récupération de l'adresses des ports réguliers*/
  y1=(double *)block->outptr[0];

  /*récupère taille de sortie*/
  ny=block->outsz[0];

  /*récupère le type de générateur*/
  typ=block->ipar[1];

  if(flag==4) {
    srand(block->ipar[0]);

    switch(typ) {
      case 0 : /*Appel noiseblk_c*/
               noiseblkv_c(&ny,&typ,&block->rpar[0],&block->rpar[ny],&y1[0],y2);
               if ((*block->work=scicos_malloc(sizeof(double)*ny))== NULL) {
                 set_block_error(-16);
                 return;
               }
               break;
      case 1 : /*Appel noiseblk_c*/
               noiseblkv_c(&ny,&typ,&block->rpar[0],&block->rpar[ny],y2,&y1[0]);
               if ((*block->work=scicos_malloc(sizeof(double)*ny))== NULL) {
                 set_block_error(-16);
                 return;
               }
               break;
      case 2 : /*récupération de l'adresse de sortie*/
               y2=(double *)block->outptr[1];
               /*Appel noiseblk_c*/
               noiseblkv_c(&ny,&typ,&block->rpar[0],&block->rpar[ny],&y1[0],&y2[0]);
               if ((*block->work=scicos_malloc(sizeof(double)*2*ny))== NULL) {
                 set_block_error(-16);
                 return;
               }
               break;
    }
  }

  else if(flag==2) {
    y1=(double *)*block->work;
    switch(typ) {
      case 0 : /*Appel noiseblk_c*/
               noiseblkv_c(&ny,&typ,&block->rpar[0],&block->rpar[ny],&y1[0],y2);
               break;
      case 1 : /*Appel noiseblk_c*/
               noiseblkv_c(&ny,&typ,&block->rpar[0],&block->rpar[ny],y2,&y1[0]);
               break;
      case 2 : y2=&y1[ny];
               /*Appel noiseblk_c*/
               noiseblkv_c(&ny,&typ,&block->rpar[0],&block->rpar[ny],&y1[0],&y2[0]);
               break;
    }
  }

  else if(flag==1) {
    switch(typ) {
      case 0 :
      case 1 : copyd_c(&ny,(double *)*block->work,y1);
               break;
      case 2 : copyd_c(&ny,(double *)*block->work,y1);
               y1=(double *)*block->work;
               y2=(double *)block->outptr[1];
               copyd_c(&ny,&y1[ny],y2);
               break;
    }
  }

  else if(flag==5) {
    scicos_free(*block->work);
  }
}