Exemple #1
0
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void gainblk_ui16e(scicos_block *block,int flag)
{
 if ((flag==1)|(flag==6)){
  int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0;
  unsigned short *u = NULL,*y = NULL;
  int mu = 0,ny = 0,my = 0,mo = 0,no = 0;
  unsigned short *opar = NULL;
  double k = 0.,D = 0.,C = 0.;

  mo=GetOparSize(block,1,1);
  no=GetOparSize(block,1,2);
  mu=GetInPortRows(block,1);
  my=GetOutPortRows(block,1);
  ny=GetOutPortCols(block,1);
  u=Getuint16InPortPtrs(block,1);
  y=Getuint16OutPortPtrs(block,1);
  opar=Getuint16OparPtrs(block,1);

  k=pow(2,16);
  if (mo*no==1){
    for (i=0;i<ny*mu;++i){
     D=(double)(opar[0])*(double)(u[i]);
     if ((D>=k)|( D<0))
	{sciprint(_("overflow error"));
	 set_block_error(-4);
	 return;}
     else y[i]=(unsigned short)D;
    }
  }else{
     for (l=0;l<ny;l++)
	 {for (j=0;j<my;j++)
	      {D=0;
			 jl=j+l*my;
	       for (i=0;i<mu;i++)
		   {ji=j+i*my;
		    
		    il=i+l*mu;
		    C=(double)(opar[ji])*(double)(u[il]);
		    D=D + C;}
		    if ((D>=k)|( D<0))
			{sciprint(_("overflow error"));
			 set_block_error(-4);
			 return;}
		    else y[jl]=(unsigned short)D;
		  }
	     }
  }
 }
}
Exemple #2
0
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void gainblk_i16n(scicos_block *block,int flag)
{
 if ((flag==1)|(flag==6)){
  int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0;
  short *u = NULL,*y = NULL;
  int mu = 0,ny = 0,my = 0,mo = 0,no = 0;
  short *opar = NULL;
  double k = 0.,D = 0.,C = 0.,t = 0.;

  mo=GetOparSize(block,1,1);
  no=GetOparSize(block,1,2);
  mu=GetInPortRows(block,1);
  my=GetOutPortRows(block,1);
  ny=GetOutPortCols(block,1);
  u=Getint16InPortPtrs(block,1);
  y=Getint16OutPortPtrs(block,1);
  opar=Getint16OparPtrs(block,1);
  k=pow(2,16);
  if (mo*no==1){
    for (i=0;i<ny*mu;++i){
     D=(double)(opar[0])*(double)(u[i]);
     t=D-(double)((int)(D/(k)))*((k));
     if ((t>=k/2)|(-(t)>=k/2))
	 {if (t>=0) (t)=(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));
	  else (t)=-(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));}
     y[i]=(short)t;
    }
  }else{
     for (l=0;l<ny;l++)
	 {for (j=0;j<my;j++)
	      {D=0;
	       jl=j+l*my;
	       for (i=0;i<mu;i++)
		   {ji=j+i*my;
		    
		    il=i+l*mu;
		    C=(double)(opar[ji])*(double)(u[il]);
		    D=D + C;}
		    t=D-(double)((int)(D/(k)))*((k));
		    if ((t>=k/2)|(-(t)>=k/2))
		       {if (t>=0) (t)=(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));
			else (t)=-(-((k/2))+fabs(t-(double)((int)((t)/((k/2))))*((k/2))));}
		    y[jl]=(short)t;
		  }
	     }
  }
 }
}
Exemple #3
0
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void gainblk_i32s(scicos_block *block,int flag)
{
 if ((flag==1)|(flag==6)){
  int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0;
  long *u = NULL,*y = NULL;
  int mu = 0,ny = 0,my = 0,mo = 0,no = 0;
  long *opar = NULL;
  double k = 0.,D = 0.,C = 0.;

  mo=GetOparSize(block,1,1);
  no=GetOparSize(block,1,2);
  mu=GetInPortRows(block,1);
  my=GetOutPortRows(block,1);
  ny=GetOutPortCols(block,1);
  u=Getint32InPortPtrs(block,1);
  y=Getint32OutPortPtrs(block,1);
  opar=Getint32OparPtrs(block,1);

  k=pow(2,32)/2;
  if (mo*no==1){
    for (i=0;i<ny*mu;++i){
     D=(double)(opar[0])*(double)(u[i]);
     if (D>=k)  D=k-1;
     else if (D<-k) D=-k;
     y[i]=(long)D;
    }
  }else{
     for (l=0;l<ny;l++)
	 {for (j=0;j<my;j++)
	      {D=0;
	       jl=j+l*my;
	       for (i=0;i<mu;i++)
		   {ji=j+i*my;
		    
		    il=i+l*mu;
		    C=(double)(opar[ji])*(double)(u[il]);
		    D=D + C;}
		    if (D>=k)  D=k-1;
		    else if (D<-k) D=-k;
		    y[jl]=(long)D;
		  }
	     }
  }
 }
}
Exemple #4
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void m_frequ(scicos_block *block, int flag)
{
    double *mat = NULL;
    double *Dt = NULL;
    double *off = NULL;
    SCSINT32_COP *icount = NULL;
    double t = 0.0;
    time_counter_t** work = (time_counter_t**) block->work;
    time_counter_t *counter = NULL;
    int m = 0;
    mat = GetRealOparPtrs(block, 1);
    Dt = GetRealOparPtrs(block, 2);
    off = GetRealOparPtrs(block, 3);
    icount = Getint32OparPtrs(block, 4);
    m = GetOparSize(block, 1, 1);

    switch (flag)
    {

        case 4 :   /* the workspace is used to store discrete counter value */
        {
            if ((*work = (time_counter_t*) scicos_malloc(sizeof(time_counter_t) * 2)) == NULL)
            {
                set_block_error(-16);
                return;
            }
            counter = *work;
            *counter = *icount;
            (*(counter + 1)) = 0;
            break;
        }

        /* event date computation */
        case 3  :
        {
            counter = *work;
            t = get_scicos_time();
            *counter += (int)mat[*(counter + 1)]; /*increase counter*/
            block->evout[(int)mat[*(counter + 1) + m] - 1] = *off + ((double) * counter / (*Dt)) - t;
            (*(counter + 1))++;
            *(counter + 1) = *(counter + 1) % m;
            break;
        }

        /* finish */
        case 5  :
        {
            scicos_free(*work); /*free the workspace*/
            break;
        }

        default :
            break;
    }
}
Exemple #5
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void logic(scicos_block *block, int flag)
{
    char *u = NULL, *y = NULL;
    char inp, num;
    int i  = 0, nin = 0, nout = 0, mo = 0;
    char *opar = NULL;
    nin = GetNin(block);
    nout = GetNout(block);
    opar = Getint8OparPtrs(block, 1);
    mo = GetOparSize(block, 1, 1);
    if (flag == 1)
    {
        num = 0;
        for (i = 0; i < nin; i++)
        {
            u = Getint8InPortPtrs(block, i + 1);
            inp = *u;
            if (inp > 0)
            {
                inp = 1;
            }
            else
            {
                inp = 0;
            }
            inp = inp << i;
            num = num + inp;
        }
        for (i = 0; i < nout; i++)
        {
            y = Getint8OutPortPtrs(block, i + 1);
            *y = *(opar + num + i * mo);
        }
    }
    if (flag == 6)
    {
        u = Getint8InPortPtrs(block, 1);
        for (i = 0; i < nout; i++)
        {
            y = Getint8OutPortPtrs(block, i + 1);
            *y = *u;
        }
    }
}