Exemple #1
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matmul_ui8n(scicos_block *block, int flag)
{
    if ((flag == 1) | (flag == 6))
    {

        int mu1 = GetInPortRows(block, 1);
        int nu1 = GetInPortCols(block, 1);
        int nu2 = GetInPortCols(block, 2);
        unsigned char *u1 = Getuint8InPortPtrs(block, 1);
        unsigned char *u2 = Getuint8InPortPtrs(block, 2);
        unsigned char *y = Getuint8OutPortPtrs(block, 1);

        int l = 0;
        for (l = 0; l < nu2; l++)
        {
            int j = 0;
            for (j = 0; j < mu1; j++)
            {
                double D = 0.;
                int jl = j + l * mu1;
                int i = 0;
                for (i = 0; i < nu1; i++)
                {
                    int ji = j + i * mu1;
                    int il = i + l * nu1;
                    double C = (double)(u1[ji]) * (double)(u2[il]);
                    D = D + C;
                }
                y[jl] = (unsigned char)D;
            }
        }
    }
}
Exemple #2
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matmul_ui8e(scicos_block *block, int flag)
{
    if ((flag == 1) | (flag == 6))
    {
        int mu1 = GetInPortRows(block, 1);
        int nu1 = GetInPortCols(block, 1);
        int nu2 = GetInPortCols(block, 2);
        unsigned char *u1 = Getuint8InPortPtrs(block, 1);
        unsigned char *u2 = Getuint8InPortPtrs(block, 2);
        unsigned char *y = Getuint8OutPortPtrs(block, 1);

        double k = pow(2, 8);
        int l = 0;
        for (l = 0; l < nu2; l++)
        {
            int j = 0;
            for (j = 0; j < mu1; j++)
            {
                double D = 0. ;
                int jl = j + l * mu1;
                int i = 0;
                for (i = 0; i < nu1; i++)
                {
                    int ji = j + i * mu1;
                    int il = i + l * nu1;
                    double C = (double)(u1[ji]) * (double)(u2[il]);
                    D = D + C;
                }
                if ((D > (k - 1)) | (D < 0))
                {
                    sciprint(_("overflow error"));
                    set_block_error(-4);
                    return;
                }
                else
                {
                    y[jl] = (unsigned char)(D);
                }
            }
        }
    }
}
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void extract_bit_u8_MSB1(scicos_block *block,int flag)
{
   int i = 0,maxim = 0;
   unsigned char *y = NULL,*u = NULL,ref = 0,n = 0;
   int *ipar = NULL;
   y=Getuint8OutPortPtrs(block,1);
   u=Getuint8InPortPtrs(block,1);
   ipar=GetIparPtrs(block);
   maxim=8;
   ref=0;
   for(i=0;i<*ipar;i++)
       {n=(unsigned char)pow(2,maxim-1-i);
        ref=ref+n;}
   *y=(*u)&(ref);
   *y=*y>>(maxim-*ipar);
}
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void extract_bit_u8_RB1(scicos_block *block, int flag)
{
    int i = 0, numb = 0;
    unsigned char *y = NULL, *u = NULL, ref = 0, n = 0;
    int *ipar = NULL;
    y = Getuint8OutPortPtrs(block, 1);
    u = Getuint8InPortPtrs(block, 1);
    ipar = GetIparPtrs(block);
    ref = 0;
    numb = *(ipar + 1) - *ipar + 1;
    for (i = 0; i < numb; i++)
    {
        n = (unsigned char)pow(2, *ipar + i);
        ref = ref + n;
    }
    *y = (*u) & (ref);
    *y = *y >> *ipar;
}
Exemple #5
0
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void convert(scicos_block *block,int flag)
{
 int m = 0,n = 0,i = 0;
 int *ipar = NULL;
 double v = 0.,w = 0.,k = 0.;
 
 m=GetInPortRows(block,1);
 n=GetInPortCols(block,1);
 ipar=GetIparPtrs(block);
 
 if ((flag==1)|(flag==6))
    {
     switch (*ipar){
	    case 1:{ 
		   void *u = NULL,*y = NULL;
		   int so;
		   so=GetSizeOfOut(block,1);
     	   u=GetInPortPtrs(block,1);
     	   y=GetOutPortPtrs(block,1);
     	   memcpy(y,u,m*n*so);
     	  break;
			   }
	    case 2:{
		   double *u = NULL;
		   long *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (fabs(w)>k/2-1)
			     {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(long)w;}
		   break;}
	    case 3:{
		   double *u = NULL;
		   short *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (fabs(w)>k/2-1)
			     {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(short)w;}
		   break;}
	    case 4:{
		   double *u = NULL;
		   char *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (fabs(w)>k/2-1)
			     {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(char)w;}
		   break;}
	    case 5:{
		   double *u = NULL;
		   unsigned long *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned long)w;}
		   break;}
	    case 6:{
		   double *u = NULL;
		   unsigned short *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned short)w;}
		   break;}
	    case 7:{
		   double *u = NULL;
		   unsigned char *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned char)w;}
		   break;}
	    case 8:{
		   long *u = NULL;
		   double *y = NULL;
		   u=Getint32InPortPtrs(block,1);
		   y=GetRealOutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) y[i]=(double) u[i];
		   break;}
	    case 9:{
		   long *u = NULL;
		   short *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (fabs(w)>k/2-1)
			     {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(short)w;}
		   break;}
	    case 10:{
		   long *u = NULL;
		   char *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (fabs(w)>k/2-1)
			     {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(char)w;}
		   break;}
	    case 11:{
		   long *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned short)w;}
		   break;}
	    case 12:{
		   long *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned char)w;}
		   break;}
	    case 13:{
		   short *u = NULL;
		   double *y = NULL;
		   u=Getint16InPortPtrs(block,1);
		   y=GetRealOutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) y[i]=(double) u[i];
		   break;}
	    case 14:{
		   short *u = NULL;
		   long *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(long)u[i];}
		   break;}
	    case 15:{
		   short *u = NULL;
		   char *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (fabs(w)>k/2-1)
			     {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(char)w;}
		   break;}
	    case 16:{
		   short *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(unsigned long)u[i];}
		   break;}
	    case 17:{
		   short *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned char)w;}
		   break;}
	    case 18:{
		   char *u = NULL;
		   double *y = NULL;
		   u=Getint8InPortPtrs(block,1);
		   y=GetRealOutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) y[i]=(double) u[i];
		   break;}
	    case 19:{
		   char *u = NULL;
		   long *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(long)u[i];}
		   break;}
	    case 20:{
		   char *u = NULL;
		   short *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(short)u[i];}
		   break;}
	    case 21:{
		   char *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(unsigned long)u[i];}
		   break;}
	    case 22:{
		   char *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(unsigned short)u[i];}
		   break;}
	    case 23:{
		   unsigned long *u = NULL;
		   double *y = NULL;
		   u=Getuint32InPortPtrs(block,1);
		   y=GetRealOutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) y[i]=(double) u[i];
		   break;}
	    case 24:{
		   unsigned long *u = NULL;
		   short *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if ((w)>k/2-1)
			     { w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(short)w;}
		   break;}
	    case 25:{
		   unsigned long *u = NULL;
		   char *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if ((w)>k/2-1)
			     {w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(char)w;}
		   break;}
	    case 26:{
		   unsigned long *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned short)w;}
		   break;}
	    case 27:{
		   unsigned long *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned char)w;}
		   break;}
	    case 28:{
		   unsigned short *u = NULL;
		   double *y = NULL;
		   u=Getuint16InPortPtrs(block,1);
		   y=GetRealOutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) y[i]=(double) u[i];
		   break;}
	    case 29:{
		   unsigned short *u = NULL;
		   long *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(long)u[i];}
		   break;}
	    case 30:{
		   unsigned short *u = NULL;
		   char *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         if (w>k/2-1)
			     {w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
			     }
		         y[i]=(char)w;}
		   break;}
	    case 31:{
		   unsigned short *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(unsigned long)u[i];}
		   break;}
	    case 32:{
		   unsigned short *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {v=(double)u[i];
		         w=v-(double)((int)(v/k))*k;
		         y[i]=(unsigned char)w;}
		   break;}
	    case 33:{
		   unsigned char *u = NULL;
		   double *y = NULL;
		   u=Getuint8InPortPtrs(block,1);
		   y=GetRealOutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) y[i]=(double) u[i];
		   break;}
	    case 34:{
		   unsigned char *u = NULL;
		   long *y = NULL;
	  	   u=Getuint8InPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(long)u[i];}
		   break;}
	    case 35:{
		   unsigned char *u = NULL;
		   short *y = NULL;
	  	   u=Getuint8InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(short)u[i];}
		   break;}
	    case 36:{
		   unsigned char *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getuint8InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(unsigned long)u[i];}
		   break;}
	    case 37:{
		   unsigned char *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getuint8InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {y[i]=(unsigned short)u[i];}
		   break;}
	    case 38:{
		   double *u = NULL;
		   long *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++)
		       {if (u[i]>k/2-1)
		           {y[i]=(long)(k/2-1);}
		        else if (u[i]<-(k/2))
			   {y[i]=-(long)(k/2);}
		        else {y[i]=(long)(u[i]);}
		       }
		   break;}
	    case 39:{
		   double *u = NULL;
		   short *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>k/2-1)
		           {y[i]=(short)(k/2-1);}
		        else if (u[i]<-(k/2))
			   {y[i]=-(short)(k/2);}
		        else {y[i]=(short)(u[i]);}
		       }
		   break;}
	    case 40:{
		   double *u = NULL;
		   char *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>k/2-1)
		           {y[i]=(char)(k/2-1);}
		        else if (u[i]<-(k/2))
			   {y[i]=-(char)(k/2);}
		        else {y[i]=(char)(u[i]);}
		       }
		   break;}
	    case 41:{
		   double *u = NULL;
		   unsigned long *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>=k)
		       	     {y[i]=(unsigned long)(k-1);}
		   	else if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned long)(u[i]);}
		   	}
		   break;}
	    case 42:{
		   double *u = NULL;
		   unsigned short *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>=k)
		       	     {y[i]=(unsigned short)(k-1);}
		   	else if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 43:{
		   double *u = NULL;
		   unsigned char *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>=k)
		       	     {y[i]=(unsigned char)(k-1);}
		   	else if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 44:{
		   long *u = NULL;
		   short *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(long)(k/2-1))
		           {y[i]=(short)(k/2-1);}
		        else if (u[i]<-(long)(k/2))
			   {y[i]=-(short)(k/2);}
		        else {y[i]=(short)(u[i]);}
		       }
		   break;}
	    case 45:{
		   long *u = NULL;
		   char *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(long)(k/2-1))
		           {y[i]=(char)(k/2-1);}
		        else if (u[i]<-(long)(k/2))
			   {y[i]=-(char)(k/2);}
		        else {y[i]=(char)(u[i]);}
		       }
		   break;}
	    case 46:{
		   long *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned long)(u[i]);}
		   	}
		   break;}
	    case 47:{
		   long *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>=(long)(k))
		       	     {y[i]=(unsigned short)(k-1);}
		   	else if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 48:{
		   long *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>=(long)k)
		       	     {y[i]=(unsigned char)(k-1);}
		   	else if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 49:{
		   short *u = NULL;
		   char *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(short)(k/2-1))
		           {y[i]=(char)(k/2-1);}
		        else if (u[i]<-(short)(k/2))
			   {y[i]=-(char)(k/2);}
		        else {y[i]=(char)(u[i]);}
		       }
		   break;}
	    case 50:{
		   short *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]<0)  y[i]=0;
			 else y[i]=(unsigned long)u[i];}
		   break;}
	    case 51:{
		   short *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 52:{
		   short *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>=(short)k)
		       	     {y[i]=(unsigned char)(k-1);}
		   	else if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 53:{
		   char *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
			{if (u[i]<0)  y[i]=0;
			 else y[i]=(unsigned long)u[i];}
		   break;}
	    case 54:{
		   char *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 55:{
		   char *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]<0)
			     {y[i]=0;}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 56:{
		   long *y = NULL;
		   unsigned long *u = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]>(unsigned long)(k/2-1))
			     {y[i]=(long)(k/2-1);}
		   	else {y[i]=(long)(u[i]);}
		   	}
		   break;}
	    case 57:{
		   unsigned long *u = NULL;
		   short *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned long)(k/2-1))
			     {y[i]=(short)(k/2-1);}
		   	else {y[i]=(short)(u[i]);}
		   	}
		   break;}
	    case 58:{
		   unsigned long *u = NULL;
		   char *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned long)(k/2-1))
			     {y[i]=(char)(k/2-1);}
		   	else {y[i]=(char)(u[i]);}
		   	}
		   break;}
	    case 59:{
		   unsigned long *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned long)(k/2-1))
			     {y[i]=(unsigned short)(k/2-1);}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 60:{
		   unsigned long *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned long)(k/2-1))
			     {y[i]=(unsigned char)(k/2-1);}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 61:{
		   unsigned short *u = NULL;
		   short *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned short)(k/2-1))
			     {y[i]=(short)(k/2-1);}
		   	else {y[i]=(short)(u[i]);}
		   	}
		   break;}
	    case 62:{
		   unsigned short *u = NULL;
		   char *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned short)(k/2-1))
			     {y[i]=(char)(k/2-1);}
		   	else {y[i]=(char)(u[i]);}
		   	}
		   break;}
	    case 63:{
		   unsigned short *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned short)(k/2-1))
			     {y[i]=(unsigned char)k/2-1;}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 64:{
		   unsigned char *u = NULL;
		   char *y = NULL;
	  	   u=Getuint8InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(unsigned char)(k/2-1))
			     {y[i]=(char)(k/2-1);}
		   	else {y[i]=(char)(u[i]);}
		   	}
		   break;}
	    case 65:{
		   double *u = NULL;
		   long *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++)
		   {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
		           {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		        else {y[i]=(long)(u[i]);}
		       }
		   break;}
	    case 66:{
		   double *u = NULL;
		   short *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
		           {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		        else {y[i]=(short)(u[i]);}
		       }
		   break;}
	    case 67:{
		   double *u = NULL;
		   char *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
		           {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		        else {y[i]=(char)(u[i]);}
		       }
		   break;}
	    case 68:{
		   double *u = NULL;
		   unsigned long *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>=k) | (u[i]<0))
		           {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned long)(u[i]);}
		   	}
		   break;}
	    case 69:{
		   double *u = NULL;
		   unsigned short *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>=k) | (u[i]<0))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 70:{
		   double *u = NULL;
		   unsigned char *y = NULL;
	  	   u=GetRealInPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>=k) | (u[i]<0))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 71:{
		   long *u = NULL;
		   short *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
		            {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		        else {y[i]=(short)(u[i]);}
		       }
		   break;}
	    case 72:{
		   long *u = NULL;
		   char *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
		            {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		        else {y[i]=(char)(u[i]);}
		       }
		   break;}
	    case 73:{
		   long *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]<0)
			    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned long)(u[i]);}
		   	}
		   break;}
	    case 74:{
		   long *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>=k) | (u[i]<0))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 75:{
		   long *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint32InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>=k) | (u[i]<0))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 76:{
		   short *u = NULL;
		   char *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		        else {y[i]=(char)(u[i]);}
		       }
		   break;}
	    case 77:{
		   short *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]<0)  
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
			 else y[i]=(unsigned long)u[i];}
		   break;}
	    case 78:{
		   short *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]<0)
			    {if (flag==1) 
                                {sciprint(_("overflow error"));
			         set_block_error(-4);
			         return;}}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 79:{
		   short *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint16InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (((u[i]>=k) | (u[i]<0))& (flag==1))
		       	    {if (flag==1) 
                                 {sciprint(_("overflow error"));
			          set_block_error(-4);
			          return;}}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 80:{
		   char *u = NULL;
		   unsigned long *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint32OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
			{if (u[i]<0)
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
			 else y[i]=(unsigned long)u[i];}
		   break;}
	    case 81:{
		   char *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint16OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]<0)
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 82:{
		   char *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getint8InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]<0)
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 83:{
		   long *y = NULL;
		   unsigned long *u = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint32OutPortPtrs(block,1);
		   k=pow(2,32);
		   for (i=0;i<m*n;i++) 
		   	{if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(long)(u[i]);}
		   	}
		   break;}
	    case 84:{
		   unsigned long *u = NULL;
		   short *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(short)(u[i]);}
		   	}
		   break;}
	    case 85:{
		   unsigned long *u = NULL;
		   char *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(char)(u[i]);}
		   	}
		   break;}
	    case 86:{
		   unsigned long *u = NULL;
		   unsigned short *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	       y=Getuint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned short)(u[i]);}
		   	}
		   break;}
	    case 87:{
		   unsigned long *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getuint32InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 88:{
		   unsigned short *u = NULL;
		   short *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getint16OutPortPtrs(block,1);
		   k=pow(2,16);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(short)(u[i]);}
		   	}
		   break;}
	    case 89:{
		   unsigned short *u = NULL;
		   char *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(char)(u[i]);}
		   	}
		   break;}
	    case 90:{
		   unsigned short *u = NULL;
		   unsigned char *y = NULL;
	  	   u=Getuint16InPortPtrs(block,1);
	           y=Getuint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(unsigned char)(u[i]);}
		   	}
		   break;}
	    case 91:{
		   unsigned char *u = NULL;
		   char *y = NULL;
	  	   u=Getuint8InPortPtrs(block,1);
	           y=Getint8OutPortPtrs(block,1);
		   k=pow(2,8);
		   for (i=0;i<m*n;i++) 
		        {if (u[i]>(k/2-1))
		       	    {if (flag==1)
                               {sciprint(_("overflow error"));
			        set_block_error(-4);
			        return;}}
		   	else {y[i]=(char)(u[i]);}
		   	}
		   break;}
	   }
	}
 }
Exemple #6
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matbyscal_e(scicos_block *block, int flag)
{
    if (flag == 1)
    {
        int i = 0;
        double v = 0.;
        int ut = GetInType(block, 1);
        int mu = GetOutPortRows(block, 1);
        int nu = GetOutPortCols(block, 1);
        double *rpar = GetRparPtrs(block);

        switch (ut)
        {
            case SCSINT32_N :
            {

                long *u1 = Getint32InPortPtrs(block, 1);
                long *u2 = Getint32InPortPtrs(block, 2);
                long *y1 = Getint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (long)v;
                    }
                }
                break;
            }

            case SCSINT16_N :
            {

                short *u1 = Getint16InPortPtrs(block, 1);
                short *u2 = Getint16InPortPtrs(block, 2);
                short *y1 = Getint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (short)v;
                    }
                }
                break;
            }

            case SCSINT8_N :
            {

                char *u1 = Getint8InPortPtrs(block, 1);
                char *u2 = Getint8InPortPtrs(block, 2);
                char *y1 = Getint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (char)v;
                    }
                }
                break;
            }

            case SCSUINT32_N :
            {

                unsigned long *u1 = Getuint32InPortPtrs(block, 1);
                unsigned long *u2 = Getuint32InPortPtrs(block, 2);
                unsigned long *y1 = Getuint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (unsigned long)v;
                    }
                }
                break;
            }

            case SCSUINT16_N :
            {

                unsigned short *u1 = Getuint16InPortPtrs(block, 1);
                unsigned short *u2 = Getuint16InPortPtrs(block, 2);
                unsigned short *y1 = Getuint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (unsigned short)v;
                    }
                }
                break;
            }

            case SCSUINT8_N :
            {

                unsigned char *u1 = Getuint8InPortPtrs(block, 1);
                unsigned char *u2 = Getuint8InPortPtrs(block, 2);
                unsigned char *y1 = Getuint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[0];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (unsigned char)v;
                    }
                }
                break;
            }

            default :
            {
                set_block_error(-4);
                return;
            }
        }
    }

}
Exemple #7
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void gainblk_ui8n(scicos_block *block, int flag)
{
    if ((flag == 1) | (flag == 6))
    {
        int i = 0, j = 0, l = 0, ji = 0, jl = 0, il = 0;
        unsigned char *u = NULL, *y = NULL;
        int mu = 0, ny = 0, my = 0, mo = 0, no = 0;
        unsigned char *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 = Getuint8InPortPtrs(block, 1);
        y = Getuint8OutPortPtrs(block, 1);
        opar = Getuint8OparPtrs(block, 1);

        k = pow(2, 8);
        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] = (unsigned char)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] = (unsigned char)t;
                }
            }
        }
    }
}
Exemple #8
0
/*--------------------------------------------------------------------------*/ 
SCICOS_BLOCKS_IMPEXP void matmul2_m(scicos_block *block,int flag)
{
	if (flag==1){
		int i = 0;
		int ut=GetInType(block,1);
		int mu=GetOutPortRows(block,1);
		int nu=GetOutPortCols(block,1);
		switch (ut)
		{
		case SCSREAL_N :{
			
			double *u1=GetRealInPortPtrs(block,1);
			double *u2=GetRealInPortPtrs(block,2);
			double *y1=GetRealOutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSINT32_N :{
			long *u1=Getint32InPortPtrs(block,1);
			long *u2=Getint32InPortPtrs(block,2);
			long *y1=Getint32OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSINT16_N :{
			
			short *u1=Getint16InPortPtrs(block,1);
			short *u2=Getint16InPortPtrs(block,2);
			short *y1=Getint16OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSINT8_N :{
			
			char *u1=Getint8InPortPtrs(block,1);
			char *u2=Getint8InPortPtrs(block,2);
			char *y1=Getint8OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSUINT32_N :{
			
			unsigned long *u1=Getuint32InPortPtrs(block,1);
			unsigned long *u2=Getuint32InPortPtrs(block,2);
			unsigned long *y1=Getuint32OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSUINT16_N :{
			
			unsigned short *u1=Getuint16InPortPtrs(block,1);
			unsigned short *u2=Getuint16InPortPtrs(block,2);
			unsigned short *y1=Getuint16OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSUINT8_N :{
			
			unsigned char *u1=Getuint8InPortPtrs(block,1);
			unsigned char *u2=Getuint8InPortPtrs(block,2);
			unsigned char *y1=Getuint8OutPortPtrs(block,1);
			matmul2(y1,u1,u2,mu,nu);
			break;}

		case SCSCOMPLEX_N :{
			double *u1r=GetRealInPortPtrs(block,1);
			double *u2r=GetRealInPortPtrs(block,2);
			double *y1r=GetRealOutPortPtrs(block,1);
			double *u1i=GetImagInPortPtrs(block,1);
			double *u2i=GetImagInPortPtrs(block,2);
			double *y1i=GetImagOutPortPtrs(block,1);
			for (i=0;i<mu*nu;i++) 
			{y1r[i]=(u1r[i]*u2r[i])-(u1i[i]*u2i[i]);
			y1i[i]=(u1r[i]*u2i[i])+(u1i[i]*u2r[i]);}
			break;}

		default :{
			set_block_error(-4); 
			return;} 
		} 
	}

}
Exemple #9
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matmul2_e(scicos_block *block, int flag)
{
    if (flag == 1)
    {
        int i = 0;
        double v = 0.;
        int ut = GetInType(block, 1);
        int mu = GetOutPortRows(block, 1);
        int nu = GetOutPortCols(block, 1);
        double *rpar = GetRparPtrs(block);

        switch (ut)
        {
            case SCSINT32_N :
            {

                SCSINT32_COP *u1 = Getint32InPortPtrs(block, 1);
                SCSINT32_COP *u2 = Getint32InPortPtrs(block, 2);
                SCSINT32_COP *y1 = Getint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT32_COP)v;
                    }
                }
                break;
            }

            case SCSINT16_N :
            {

                SCSINT16_COP *u1 = Getint16InPortPtrs(block, 1);
                SCSINT16_COP *u2 = Getint16InPortPtrs(block, 2);
                SCSINT16_COP *y1 = Getint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSINT16_COP)v;
                    }
                }
                break;
            }

            case SCSINT8_N :
            {

                SCSINT8_COP *u1 = Getint8InPortPtrs(block, 1);
                SCSINT8_COP *u2 = Getint8InPortPtrs(block, 2);
                SCSINT8_COP *y1 = Getint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSINT8_COP)v;
                    }
                }
                break;
            }

            case SCSUINT32_N :
            {

                SCSUINT32_COP *u1 = Getuint32InPortPtrs(block, 1);
                SCSUINT32_COP *u2 = Getuint32InPortPtrs(block, 2);
                SCSUINT32_COP *y1 = Getuint32OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT32_COP)v;
                    }
                }
                break;
            }

            case SCSUINT16_N :
            {

                SCSUINT16_COP *u1 = Getuint16InPortPtrs(block, 1);
                SCSUINT16_COP *u2 = Getuint16InPortPtrs(block, 2);
                SCSUINT16_COP *y1 = Getuint16OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT16_COP)v;
                    }
                }
                break;
            }

            case SCSUINT8_N :
            {

                SCSUINT8_COP *u1 = Getuint8InPortPtrs(block, 1);
                SCSUINT8_COP *u2 = Getuint8InPortPtrs(block, 2);
                SCSUINT8_COP *y1 = Getuint8OutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    v = (double)u1[i] * (double)u2[i];
                    if ((v < rpar[0]) | (v > rpar[1]))
                    {
                        sciprint(_("overflow error"));
                        set_block_error(-4);
                        return;
                    }
                    else
                    {
                        y1[i] = (SCSUINT8_COP)v;
                    }
                }
                break;
            }

            default :
            {
                set_block_error(-4);
                return;
            }
        }
    }
}
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void logicalop_ui8(scicos_block *block, int flag)
{
    int i = 0, m = 0, n = 0, nin = 0, k = 0, j = 0, l = 0;
    int *ipar = NULL;
    unsigned char *y = NULL, *u = NULL;

    m = GetInPortRows(block, 1);
    n = GetInPortCols(block, 1);
    y = Getuint8OutPortPtrs(block, 1);
    ipar = GetIparPtrs(block);
    nin = GetNin(block);
    k = ipar[0];
    switch (k)
    {
        case 0:
            if (nin == 1)
            {
                u = Getuint8InPortPtrs(block, 1);
                if (ipar[1] == 0)
                {
                    *y = 1;
                    for (i = 0; i < m * n; i++)
                    {
                        if (u[i] <= 0)
                        {
                            *y = 0;
                            break;
                        }
                    }
                }
                else
                {
                    *y = u[0];
                    for (i = 1; i < m * n; i++)
                    {
                        *y = (*y) & (u[i]);
                    }
                }
            }
            else
            {
                if (ipar[1] == 0)
                {
                    for (i = 0; i < m * n; i++)
                    {
                        y[i] = 1;
                        for (j = 1; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            if (u[i] <= 0)
                            {
                                y[i] = 0;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (i = 0; i < m * n; i++)
                    {
                        u = Getuint8InPortPtrs(block, 1);
                        y[i] = u[i];
                        for (j = 2; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            y[i] = (y[i]) & (u[i]);
                        }
                    }
                }
            }
            break;
        case 1:
            if (nin == 1)
            {
                u = Getuint8InPortPtrs(block, 1);
                *y = 0;
                if (ipar[1] == 0)
                {
                    for (i = 0; i < m * n; i++)
                    {
                        if (u[i] > 0)
                        {
                            *y = 1;
                            break;
                        }
                    }
                }
                else
                {
                    for (i = 0; i < m * n; i++)
                    {
                        *y = (*y) | (u[i]);
                    }
                }
            }
            else
            {
                if (ipar[1] == 0)
                {
                    for (i = 0; i < m * n; i++)
                    {
                        y[i] = 0;
                        for (j = 1; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            if (u[i] > 0)
                            {
                                y[i] = 1;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (i = 0; i < m * n; i++)
                    {
                        y[i] = 0;
                        for (j = 1; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            y[i] = (y[i]) | (u[i]);
                        }
                    }
                }
            }
            break;
        case 2:
            if (nin == 1)
            {
                u = Getuint8InPortPtrs(block, 1);
                if (ipar[1] == 0)
                {
                    *y = 0;
                    for (i = 0; i < m * n; i++)
                    {
                        if (u[i] <= 0)
                        {
                            *y = 1;
                            break;
                        }
                    }
                }
                else
                {
                    *y = u[0];
                    for (i = 1; i < m * n; i++)
                    {
                        *y = ((*y) & (u[i]));
                    }
                    *y = ~*y;
                }
            }
            else
            {
                if (ipar[1] == 0)
                {
                    for (i = 0; i < m * n; i++)
                    {
                        y[i] = 0;
                        for (j = 1; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            if (u[i] <= 0)
                            {
                                y[i] = 1;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (i = 0; i < m * n; i++)
                    {
                        u = Getuint8InPortPtrs(block, 1);
                        y[i] = u[i];
                        for (j = 2; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            y[i] = ((y[i]) & (u[i]));
                        }
                        y[i] = ~y[i];
                    }
                }
            }
            break;
        case 3:
            if (nin == 1)
            {
                u = Getuint8InPortPtrs(block, 1);
                if (ipar[1] == 0)
                {
                    *y = 1;
                    for (i = 0; i < m * n; i++)
                    {
                        if (u[i] > 0)
                        {
                            *y = 0;
                            break;
                        }
                    }
                }
                else
                {
                    *y = 0;
                    for (i = 0; i < m * n; i++)
                    {
                        *y = ((*y) | (u[i]));
                    }
                    *y = ~*y;
                }
            }
            else
            {
                if (ipar[1] == 0)
                {
                    for (i = 0; i < m * n; i++)
                    {
                        y[i] = 1;
                        for (j = 1; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            if (u[i] > 0)
                            {
                                y[i] = 0;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (i = 0; i < m * n; i++)
                    {
                        u = Getuint8InPortPtrs(block, 1);
                        y[i] = u[i];
                        for (j = 2; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            y[i] = ((y[i]) | (u[i]));
                        }
                        y[i] = ~y[i];
                    }
                }
            }
            break;
        case 4:
            if (nin == 1)
            {
                u = Getuint8InPortPtrs(block, 1);
                if (ipar[1] == 0)
                {
                    l = 0;
                    for (i = 0; i < m * n; i++)
                    {
                        if (u[i] > 0)
                        {
                            l = (l + 1) % 2;
                        }
                    }
                    *y = (unsigned char)l;
                }
                else
                {
                    *y = u[0];
                    for (i = 1; i < m * n; i++)
                    {
                        *y = ((*y) ^ (u[i]));
                    }
                }
            }
            else
            {
                if (ipar[1] == 0)
                {
                    for (i = 0; i < m * n; i++)
                    {
                        l = 0;
                        for (j = 1; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            if (u[i] > 0)
                            {
                                l = (l + 1) % 2;
                            }
                        }
                        y[i] = (unsigned char)l;
                    }
                }
                else
                {
                    for (i = 0; i < m * n; i++)
                    {
                        u = Getuint8InPortPtrs(block, 1);
                        y[i] = u[i];
                        for (j = 2; j < nin + 1; j++)
                        {
                            u = Getuint8InPortPtrs(block, j);
                            y[i] = ((y[i]) ^ (u[i]));
                        }
                    }
                }
            }
            break;
        case 5:
            u = Getuint8InPortPtrs(block, 1);
            if (ipar[1] == 0)
            {
                for (i = 0; i < m * n; i++)
                {
                    if (u[i] > 0)
                    {
                        y[i] = 0;
                    }
                    else
                    {
                        y[i] = 1;
                    }
                }
            }
            else
            {
                for (i = 0; i < m * n; i++)
                {
                    y[i] = ~(u[i]);
                }
            }
            break;
    }
}
Exemple #11
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void summation_ui8s(scicos_block *block, int flag)
{
    if ((flag == 1) | (flag == 6))
    {
        int j = 0, k = 0;
        int nu = 0, mu = 0, nin = 0;
        unsigned char *y = NULL;
        int *ipar = NULL;
        double v = 0., l = 0.;
        double *rpar = NULL;
        unsigned char *u = NULL;

        y = Getuint8OutPortPtrs(block, 1);
        nu = GetInPortRows(block, 1);
        mu = GetInPortCols(block, 1);
        ipar = GetIparPtrs(block);
        rpar = GetRparPtrs(block);
        nin = GetNin(block);
        l = pow(2, 8);

        if (nin == 1)
        {
            v = 0;
            u = Getuint8InPortPtrs(block, 1);
            for (j = 0; j < nu * mu; j++)
            {
                v = v + (double)u[j];
            }
            if (v >= l)
            {
                v = l - 1;
            }
            else if (v < 0)
            {
                v = 0;
            }
            y[0] = (unsigned char)v;
        }
        else
        {
            for (j = 0; j < nu * mu; j++)
            {
                v = 0;
                for (k = 0; k < nin; k++)
                {
                    u = Getuint8InPortPtrs(block, k + 1);
                    if (ipar[k] > 0)
                    {
                        v = v + (double)u[j];
                    }
                    else
                    {
                        v = v - (double)u[j];
                    }
                }
                if (v >= l)
                {
                    v = l - 1;
                }
                else if (v < 0)
                {
                    v = 0;
                }
                y[j] = (unsigned char)v;
            }
        }
    }
}
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void summation_ui8e(scicos_block *block, int flag)
{
    if ((flag == 1) | (flag == 6))
    {
        int j = 0, k = 0;
        int nu = 0, mu = 0, nin = 0;
        unsigned char *y = NULL;
        int *ipar = NULL;
        double v = 0. , l = 0.;
        unsigned char *u = NULL;

        y = Getuint8OutPortPtrs(block, 1);
        nu = GetInPortRows(block, 1);
        mu = GetInPortCols(block, 1);
        ipar = GetIparPtrs(block);
        nin = GetNin(block);
        l = pow(2, 8);

        if (nin == 1)
        {
            v = 0;
            u = Getuint8InPortPtrs(block, 1);
            for (j = 0; j < nu * mu; j++)
            {
                v = v + (double)u[j];
            }
            if ((v >= l) | (v < 0))
            {
                scicos_print(_("overflow error"));
                set_block_error(-4);
                return;
            }
            else
            {
                y[0] = (unsigned char)v;
            }
        }
        else
        {
            for (j = 0; j < nu * mu; j++)
            {
                v = 0;
                for (k = 0; k < nin; k++)
                {
                    u = Getuint8InPortPtrs(block, k + 1);
                    if (ipar[k] > 0)
                    {
                        v = v + (double)u[j];
                    }
                    else
                    {
                        v = v - (double)u[j];
                    }
                }
                if ((v >= l) | (v < 0))
                {
                    scicos_print(_("overflow error"));
                    set_block_error(-4);
                    return;
                }
                else
                {
                    y[j] = (unsigned char)v;
                }
            }
        }
    }
}