Computational routine
eng


noiseraylblk

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.
 */
 
/* noiseraylblk Scicos Rayleigh random generator block
 * Type 4 simulation function ver 1.0 - scilab-4.1.2
 * 2 décembre 2007 - INRIA - Author : A.Layec
 */

/* REVISION HISTORY :
 * $Log$
 */

#include "modnum_lib.h"
#include "scicos_block4.h"

void noiseraylblk(scicos_block *block,int flag)
{
  /*Déclaration des variables*/
  double *y;
  double *z;
  int ny;
  int my;
  int i;
  double sig;

  /*récupération de l'adresses des ports réguliers*/
  y=GetOutPortPtrs(block,1);

  /*récupère tailles de sortie*/
  ny=GetOutPortRows(block,1);
  my=GetOutPortCols(block,1);

  /*récupère le paramètre de générateur*/
  sig=block->rpar[0];

  if(flag==4) {
   /* initialise generateur de nombre aléatoire */
   srand((unsigned int)block->ipar[0]);

   if ((*block->work=scicos_malloc(sizeof(double)*my*ny))== NULL) {
     set_block_error(-16);
     return;
   }

   /*Appel rnoise_c*/
   rnoise_c(&ny,&my,&sig,y);
  }

  else if(flag==2)  {
   z=*block->work;

   /*Appel rnoise_c*/
   rnoise_c(&ny,&my,&sig,z);
  }

  else if(flag==1)  {
   /*Appel copyd_c*/
   copyd_c((i=(ny*my),&i),z,y);
  }

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

}