/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void summation_ui16s(scicos_block *block,int flag) { if((flag==1)|(flag==6)) { int j = 0,k = 0; int nu = 0,mu = 0,nin = 0; unsigned short *y = NULL; int *ipar = NULL; double v = 0.,l = 0.; double *rpar = NULL; unsigned short *u = NULL; y = Getuint16OutPortPtrs(block,1); nu = GetInPortRows(block,1); mu = GetInPortCols(block,1); ipar = GetIparPtrs(block); rpar = GetRparPtrs(block); nin = GetNin(block); l = pow(2,16); if (nin==1) { v=0; u=Getuint16InPortPtrs(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 short)v; } else { for (j=0;j<nu*mu;j++) { v=0; for (k=0;k<nin;k++) { u=Getuint16InPortPtrs(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 short)v; } } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void summation_i32s(scicos_block *block,int flag) { if((flag==1)|(flag==6)) { int j = 0,k = 0; int nu = 0,mu = 0,nin = 0; long *y = NULL; int *ipar = NULL; double v = 0.,l = 0.; double *rpar = NULL; long *u = NULL; y = Getint32OutPortPtrs(block,1); nu = GetInPortRows(block,1); mu = GetInPortCols(block,1); ipar = GetIparPtrs(block); rpar = GetRparPtrs(block); nin = GetNin(block); l = pow(2,32)/2; if (nin==1) { v=0; u=Getint32InPortPtrs(block,1); for (j=0;j<nu*mu;j++) { v=v+(double)u[j]; } if (v>=l) v=l-1; else if (v<-l) v=-l; y[0]=(long)v; } else { for (j=0;j<nu*mu;j++) { v=0; for (k=0;k<nin;k++) { u=Getint32InPortPtrs(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<-l) v=-l; y[j]=(long)v; } } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void rndblk_m(scicos_block *block, int flag) { double *y = NULL; double *rpar = NULL; double *z = NULL; int *ipar = NULL; int ny = 0, my = 0, i = 0, iy = 0; double sr = 0., si = 0., tl = 0; my = GetOutPortRows(block, 1); ny = GetOutPortCols(block, 1); ipar = GetIparPtrs(block); rpar = GetRparPtrs(block); y = GetRealOutPortPtrs(block, 1); z = GetDstate(block); if (flag == 2 || flag == 4) { if (ipar[0] == 0) { iy = (int)z[0]; for (i = 0; i < my * ny; i++) { *(z + i + 1) = C2F(urand)(&iy); } } else { iy = (int)z[0]; for (i = 0; i < my * ny; i++) { do { sr = 2.0 * C2F(urand)(&iy) - 1.0; si = 2.0 * C2F(urand)(&iy) - 1.0; tl = sr * sr + si * si; } while (tl > 1.0); z[i + 1] = sr * (sqrt(-2.0 * log(tl) / tl)); } } *(z) = iy; } if (flag == 1 || flag == 6) { for (i = 0; i < my * ny; i++) { *(y + i) = *(rpar + i) + (*(rpar + i + my * ny)) * (*(z + i + 1)); } } }
static void inout(scicos_block *block) { double w,pi=3.1415927; double t = get_scicos_time(); double * rpar = GetRparPtrs(block); double *y = block->outptr[0]; if (t<rpar[4]) y[0]=0.0; else { w=2*pi*rpar[1]*(t-rpar[4])-rpar[2]; y[0]=rpar[0]*sin(w)+rpar[3]; } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void summation_ui32n(scicos_block *block,int flag) { if((flag==1)|(flag==6)) { int j = 0,k = 0; int nu = 0,mu = 0,nin = 0; unsigned long *y = NULL; int *ipar = NULL; double *rpar = NULL; unsigned long *u = NULL; y=Getuint32OutPortPtrs(block,1); nu=GetInPortRows(block,1); mu=GetInPortCols(block,1); ipar=GetIparPtrs(block); rpar=GetRparPtrs(block); nin=GetNin(block); if (nin==1) { y[0]=0; u=Getuint32InPortPtrs(block,1); for (j=0;j<nu*mu;j++) { y[0]=y[0]+u[j]; } } else { for (j=0;j<nu*mu;j++) { y[j]=0; for (k=0;k<nin;k++) { u=Getuint32InPortPtrs(block,k+1); if(ipar[k]>0) { y[j]=y[j]+u[j]; } else { y[j]=y[j]-u[j];} } } } } }
/*--------------------------------------------------------------------------*/ 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; } } } }
/*--------------------------------------------------------------------------*/ 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 summation_ui32e(scicos_block *block, int flag) { if ((flag == 1) | (flag == 6)) { int j = 0, k = 0; int nu = 0, mu = 0, nin = 0; SCSUINT32_COP *y = NULL; int *ipar = NULL; double v = 0., l = 0.; double *rpar = NULL; SCSUINT32_COP *u = NULL; y = Getuint32OutPortPtrs(block, 1); nu = GetInPortRows(block, 1); mu = GetInPortCols(block, 1); ipar = GetIparPtrs(block); rpar = GetRparPtrs(block); nin = GetNin(block); l = pow(2, 32); if (nin == 1) { v = 0; u = Getuint32InPortPtrs(block, 1); for (j = 0; j < nu * mu; j++) { v = v + (double)u[j]; } if ((v >= l) | (v < 0)) { sciprint(_("overflow error")); set_block_error(-4); return; } else { y[0] = (SCSUINT32_COP)v; } } else { for (j = 0; j < nu * mu; j++) { v = 0; for (k = 0; k < nin; k++) { u = Getuint32InPortPtrs(block, k + 1); if (ipar[k] > 0) { v = v + (double)u[j]; } else { v = v - (double)u[j]; } } if ((v >= l) | (v < 0)) { sciprint(_("overflow error")); set_block_error(-4); return; } else { y[j] = (SCSUINT32_COP)v; } } } } }