/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void shift_16_RC(scicos_block *block,int flag) { int i = 0; int mu = GetInPortRows(block,1); int nu = GetInPortCols(block,1); short *u=Getint16InPortPtrs(block,1); short *y=Getint16OutPortPtrs(block,1); int *ipar = GetIparPtrs(block); unsigned short k = (unsigned short)pow(2,16-1); for (i=0;i<mu*nu;i++) { int j = 0; short v = u[i]; for(j=0;j<-ipar[0];j++) { y[i]=v&1; if (y[i]==0) { y[i]=v>>1; y[i]=y[i]&(k-1);} else { y[i]=v>>1; y[i]=(y[i])|(k); } v=y[i]; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void shift_32_LC(scicos_block *block,int flag) { int mu = GetInPortRows(block,1); int nu = GetInPortCols(block,1); long *u = Getint32InPortPtrs(block,1); long *y = Getint32OutPortPtrs(block,1); int *ipar = GetIparPtrs(block); unsigned long k = (unsigned long)pow(2,32-1); int i = 0; for (i=0;i<mu*nu;i++) { int j = 0; long v=u[i]; for(j=0;j<ipar[0];j++) { y[i]=v&k; if (y[i]==0) y[i]=v<<1; else { y[i]=v<<1; y[i]=(y[i])|(1); } v=y[i]; } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void shift_32_RC(scicos_block *block, int flag) { int i = 0, j = 0; int mu = GetInPortRows(block, 1); int nu = GetInPortCols(block, 1); SCSINT32_COP *u = Getint32InPortPtrs(block, 1); SCSINT32_COP *y = Getint32OutPortPtrs(block, 1); int *ipar = GetIparPtrs(block); unsigned long k = (unsigned long)pow(2, 32 - 1); for (i = 0; i < mu * nu; i++) { SCSINT32_COP v = u[i]; for (j = 0; j < -ipar[0]; j++) { y[i] = v & 1; if (y[i] == 0) { y[i] = v >> 1; y[i] = y[i] & (k - 1); } else { y[i] = v >> 1; y[i] = (y[i]) | (k); } v = y[i]; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void matmul_i8n(scicos_block *block,int flag) { if ((flag==1)|(flag==6)) { char *u1,*u2,*y; double C,D; int mu1,nu1,nu2,i,j,l,ji,jl,il; int *ipar; mu1=GetInPortRows(block,1); nu1=GetInPortCols(block,1); nu2=GetInPortCols(block,2); u1=Getint8InPortPtrs(block,1); u2=Getint8InPortPtrs(block,2); y=Getint8OutPortPtrs(block,1); ipar=GetIparPtrs(block); for (l=0;l<nu2;l++) {for(j=0;j<mu1;j++) {D=0; jl=j+l*mu1; for(i=0;i<nu1;i++) {ji=j+i*mu1; il=i+l*nu1; C=(double)(u1[ji])*(double)(u2[il]); D=D + C;} y[jl]=(char)D; } } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void extractz(scicos_block *block,int flag) { double *ur = NULL; double *ui = NULL; double *yr = NULL; double *yi = NULL; int *r = NULL; int nu = 0,mu = 0,nr = 0,i = 0,j = 0,ij = 0,k = 0,nc = 0,nl = 0; mu=GetInPortRows(block,1); nu=GetInPortCols(block,1); nr=GetNipar(block); r=GetIparPtrs(block); ur=GetRealInPortPtrs(block,1); ui=GetImagInPortPtrs(block,1); yr=GetRealOutPortPtrs(block,1); yi=GetImagOutPortPtrs(block,1); nc=r[nr-1]; nl=r[nr-2]; k=0; for (j=0;j<nc;j++) {for (i=0;i<nl;i++) {ij=r[i]-1+(r[nl+j]-1)*mu; *(yr+k)=*(ur+ij); *(yi+k)=*(ui+ij); k++;}} }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void shift_32_LA(scicos_block *block,int flag) { int i = 0; int mu = GetInPortRows(block,1); int nu = GetInPortCols(block,1); long *u = Getint32InPortPtrs(block,1); long *y = Getint32OutPortPtrs(block,1); int *ipar = GetIparPtrs(block); for (i=0;i<mu*nu;i++) y[i]=u[i]<<ipar[0]; }
/*--------------------------------------------------------------------------*/ 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; } } } }
static void end(scicos_block *block) { int * ipar = GetIparPtrs(block); char ledName[10]; MBX * mbx = *(block->work); RT_named_mbx_delete(0, 0, mbx); par_getstr(ledName,ipar,1,ipar[0]); printf("Led %s closed\n",ledName); }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void foriterator(scicos_block *block, int flag) { void *y = NULL, *u = NULL, *z = NULL; int *ipar = NULL; int so = 0; int nin = 0; z = GetOzPtrs(block, 1); so = GetSizeOfOut(block, 1); if (flag == 1) { y = GetOutPortPtrs(block, 1); memcpy(y, z, so); } else if (flag == 2) { ipar = GetIparPtrs(block); if (*ipar == 0) { if (so == 1) { char *inp; inp = (char *)z; *inp = *inp + 1; } else if (so == 2) { short *inp; inp = (short *)z; *inp = *inp + 1; } else if (so == 4) { long *inp; inp = (long *)z; *inp = *inp + 1; } else if (so == 8) { double *inp; inp = (double *)z; *inp = *inp + 1; } } else { nin = GetNin(block); u = GetInPortPtrs(block, nin); memcpy(z, u, so); } } }
/*--------------------------------------------------------------------------*/ 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)); } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void extract_bit_32_MSB0(scicos_block *block,int flag) { int i = 0,maxim = 0; long *y = NULL,*u = NULL,ref = 0,n = 0; int *ipar = NULL; y=Getint32OutPortPtrs(block,1); u=Getint32InPortPtrs(block,1); ipar=GetIparPtrs(block); maxim=32; ref=0; for(i=0;i<*ipar;i++) {n=(long)pow(2,maxim-1-i); ref=ref+n;} *y=(*u)&(ref); }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void extract_bit_8_LSB(scicos_block *block,int flag) { int i = 0,maxim = 0; char *y = NULL,*u = NULL,ref = 0,n = 0; int *ipar = NULL; y=Getint8OutPortPtrs(block,1); u=Getint8InPortPtrs(block,1); ipar=GetIparPtrs(block); maxim=8; ref=0; for(i=0;i<*ipar;i++) {n=(char)pow(2,i); ref=ref+n;} *y=(*u)&(ref); }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void shift_16_LA(scicos_block *block, int flag) { int i = 0; int mu = GetInPortRows(block, 1); int nu = GetInPortCols(block, 1); short *u = Getint16InPortPtrs(block, 1); short *y = Getint16OutPortPtrs(block, 1); int *ipar = GetIparPtrs(block); for (i = 0; i < mu * nu; i++) { y[i] = u[i] << ipar[0]; } }
/*--------------------------------------------------------------------------*/ 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_16_LSB(scicos_block *block, int flag) { int i = 0; short *y = NULL, *u = NULL, ref = 0, n = 0; int *ipar = NULL; y = Getint16OutPortPtrs(block, 1); u = Getint16InPortPtrs(block, 1); ipar = GetIparPtrs(block); ref = 0; for (i = 0; i < *ipar; i++) { n = (short)pow(2, i); ref = ref + n; } *y = (*u) & (ref); }
/*--------------------------------------------------------------------------*/ 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 extract_bit_32_LSB(scicos_block *block, int flag) { int i = 0, maxim = 0; long *y, *u, ref, n; int *ipar; y = Getint32OutPortPtrs(block, 1); u = Getint32InPortPtrs(block, 1); ipar = GetIparPtrs(block); maxim = 32; ref = 0; for (i = 0; i < *ipar; i++) { n = (long)pow(2, (double)i); ref = ref + n; } *y = (*u) & (ref); }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void extract_bit_u32_RB1(scicos_block *block,int flag) { int i = 0,maxim = 0,numb = 0; unsigned long *y = NULL,*u = NULL,ref = 0,n = 0; int *ipar = NULL; y=Getuint32OutPortPtrs(block,1); u=Getuint32InPortPtrs(block,1); ipar=GetIparPtrs(block); maxim=32; ref=0; numb=*(ipar+1)-*ipar+1; for(i=0;i<numb;i++) {n=(unsigned long)pow(2,*ipar+i); ref=ref+n;} *y=(*u)&(ref); *y=*y>>*ipar; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void summation(scicos_block *block, int flag) { int j = 0, k = 0; double *y = GetRealOutPortPtrs(block, 1); int nu = GetInPortRows(block, 1); int mu = GetInPortCols(block, 1); int *ipar = GetIparPtrs(block); if (flag == 1) { if (GetNin(block) == 1) { double *u = GetRealInPortPtrs(block, 1); y[0] = 0.0; for (j = 0; j < nu * mu; j++) { y[0] = y[0] + u[j]; } } else { for (j = 0; j < nu * mu; j++) { y[j] = 0.0; for (k = 0; k < GetNin(block); k++) { double *u = GetRealInPortPtrs(block, k + 1); if (ipar[k] > 0) { y[j] = y[j] + u[j]; } else { y[j] = y[j] - u[j]; } } } } } }
static void init(scicos_block *block) { char ledName[20]; char name[7]; int nch = GetNin(block); int * ipar = GetIparPtrs(block); MBX *mbx; par_getstr(ledName,ipar,1,ipar[0]); rtRegisterLed(ledName,nch); get_a_name(TargetLedMbxID,name); mbx = (MBX *) RT_typed_named_mbx_init(0,0,name,MBX_RTAI_LED_SIZE/sizeof(unsigned int)*sizeof(unsigned int),FIFO_Q); if(mbx == NULL) { fprintf(stderr, "Cannot init mailbox\n"); exit_on_error(); } *(block->work) = mbx; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void summation_i16n(scicos_block *block,int flag) { if((flag==1)|(flag==6)) { int j = 0,k = 0; short *y = Getint16OutPortPtrs(block,1); int nu = GetInPortRows(block,1); int mu = GetInPortCols(block,1); int *ipar=GetIparPtrs(block); int nin = GetNin(block); if (nin==1) { short *u=Getint16InPortPtrs(block,1); y[0]=0; 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++) { short *u=Getint16InPortPtrs(block,k+1); if(ipar[k]>0) { y[j]=y[j]+u[j]; } else { y[j]=y[j]-u[j];} } } } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void matmul_ui32n(scicos_block *block, int flag) { if ((flag == 1) | (flag == 6)) { unsigned long *u1, *u2, *y; double k, C, D, t; int mu1, nu1, nu2, i, j, l, ji, jl, il; int *ipar; mu1 = GetInPortRows(block, 1); nu1 = GetInPortCols(block, 1); nu2 = GetInPortCols(block, 2); u1 = Getuint32InPortPtrs(block, 1); u2 = Getuint32InPortPtrs(block, 2); y = Getuint32OutPortPtrs(block, 1); ipar = GetIparPtrs(block); k = pow(2, 32); for (l = 0; l < nu2; l++) { for (j = 0; j < mu1; j++) { D = 0; jl = j + l * mu1; for (i = 0; i < nu1; i++) { ji = j + i * mu1; il = i + l * nu1; C = (double)(u1[ji]) * (double)(u2[il]); D = D + C; } t = D - (int)(D / (k)) * ((k)); y[jl] = (unsigned long)t; } } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void counter(scicos_block *block, int flag) { double *y = NULL, *z = NULL; int *ipar = NULL; y = GetRealOutPortPtrs(block, 1); z = GetDstate(block); ipar = GetIparPtrs(block); if (flag == 1) { if (*ipar == 1) { *y = *z + *(ipar + 2); } else { *y = *(ipar + 1) - *z; } } else if (flag == 2) { *z = (1 + (int) * z) % (*(ipar + 1) - * (ipar + 2) + 1); } }
/** * Set properties on the figure. * * \param iFigureUID the figure uid * \param block the current block */ static void setFigureSettings(int iFigureUID, scicos_block * block) { int nipar = GetNipar(block); int *ipar = GetIparPtrs(block); int win_pos[2]; int win_dim[2]; win_pos[0] = ipar[(nipar - 1) - 3]; win_pos[1] = ipar[(nipar - 1) - 2]; win_dim[0] = ipar[(nipar - 1) - 1]; win_dim[1] = ipar[nipar - 1]; if (win_pos[0] > 0 && win_pos[1] > 0) { setGraphicObjectProperty(iFigureUID, __GO_POSITION__, &win_pos, jni_int_vector, 2); } if (win_dim[0] > 0 && win_dim[1] > 0) { setGraphicObjectProperty(iFigureUID, __GO_SIZE__, &win_dim, jni_int_vector, 2); } };
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void relational_op_i8(scicos_block *block,int flag) { int k = 0,i = 0; int m = GetInPortRows(block,1); int n = GetInPortCols(block,1); char *u1 = Getint8InPortPtrs(block,1); char *u2 = Getint8InPortPtrs(block,2); char *y = Getint8OutPortPtrs(block,1); int *ipar = GetIparPtrs(block); if (flag==1) { if ((block->ng!=0)&(get_phase_simulation()==2)) { for(i=0;i<m*n;i++) *(y+i)=(char)block->mode[i]-1; } else { for(i=0;i<m*n;i++) y[i]=0; k=ipar[0]; switch(k) { case 0: for(i=0;i<m*n;i++) { if (u1[i]==u2[i]) y[i]=1; } break; case 1: for(i=0;i<m*n;i++) { if (u1[i]!=u2[i]) y[i]=1; } break; case 2: for(i=0;i<m*n;i++) { if (u1[i]<u2[i]) y[i]=1; } break; case 3: for(i=0;i<m*n;i++) { if (u1[i]<=u2[i]) y[i]=1; } break; case 4: for(i=0;i<m*n;i++) { if (u1[i]>u2[i]) y[i]=1; } break; case 5: for(i=0;i<m*n;i++) { if (u1[i]>=u2[i]) y[i]=1; } break; } } } else if (flag==9) { for(i=0;i<m*n;i++) block->g[i]=*(u1+i)-*(u2+i); if (get_phase_simulation()==1) { for(i=0;i<m*n;i++) block->mode[i]=(int)1; k=ipar[0]; switch(k) { case 0: for(i=0;i<m*n;i++) { if (u1[i]==u2[i]) block->mode[i]=(int)2; } break; case 1: for(i=0;i<m*n;i++) { if (u1[i]!=u2[i]) block->mode[i]=(int)2; } break; case 2: for(i=0;i<m*n;i++) { if (u1[i]<u2[i]) block->mode[i]=(int)2; } break; case 3: for(i=0;i<m*n;i++) { if (u1[i]<=u2[i]) block->mode[i]=(int)2; } break; case 4: for(i=0;i<m*n;i++) { if (u1[i]>u2[i]) block->mode[i]=(int)2; } break; case 5: for(i=0;i<m*n;i++) { if (u1[i]>=u2[i]) block->mode[i]=(int)2; } break; } } } }
void sci_zeroOrderHold(scicos_block *block,scicos::enumScicosFlags flag) { // get block data pointers, etc double *_z=GetDstate(block); double *_u1=GetRealInPortPtrs(block,1); double *_u2=GetRealInPortPtrs(block,2); double *_y1=GetRealOutPortPtrs(block,1); int *_ipar=GetIparPtrs(block); int & evtFlag = GetNevIn(block); int & evtPortTime = _ipar[0]; int & evtPortReset = _ipar[1]; // compute flags int evtFlagTime = scicos::evtPortNumToFlag(evtPortTime); int evtFlagReset = scicos::evtPortNumToFlag(evtPortReset); // loop over all rows of data int i,j; int nRows = GetInPortRows(block,1); int nCols = GetInPortCols(block,1); size_t nBytes = sizeof(double)*nRows*nCols; for(i=0; i<nRows; i++) { for(j=0; j<nCols; j++) { if (flag ==scicos::computeOutput || flag ==scicos::reinitialize || flag ==scicos::initialize) memcpy(_y1,_z,nBytes); else if (flag == scicos::updateState) { // bitwise comparison for flag if(evtFlag & evtFlagReset && _u2) { memcpy(_z,_u2,nBytes); } else if(evtFlag & evtFlagTime && _u1) { memcpy(_z,_u1,nBytes); } else { printf("\nunhandled event flat %d\n",evtFlag); printf("\nknown flags:\n"); printf("\ttime flag: %d\n",evtFlagTime); printf("\ttime flag & event flag: %d\n",evtFlagTime & evtFlag); printf("\treset flag: %d\n",evtFlagReset); printf("\treset flag & event flag: %d\n",evtFlagReset & evtFlag); } } else if (flag == scicos::terminate) { } else { char msg[50]; sprintf(msg,"unhandled block flag %d\n",flag); Coserror(msg); } } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void logicalop_i8(scicos_block *block, int flag) { int i, m, n, nin, k, j, l; int *ipar; char *y, *u; m = GetInPortRows(block, 1); n = GetInPortCols(block, 1); y = Getint8OutPortPtrs(block, 1); ipar = GetIparPtrs(block); nin = GetNin(block); k = ipar[0]; switch (k) { case 0: if (nin == 1) { u = Getint8InPortPtrs(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 = Getint8InPortPtrs(block, j); if (u[i] <= 0) { y[i] = 0; break; } } } } else { for (i = 0; i < m * n; i++) { u = Getint8InPortPtrs(block, 1); y[i] = u[i]; for (j = 2; j < nin + 1; j++) { u = Getint8InPortPtrs(block, j); y[i] = (y[i]) & (u[i]); } } } } break; case 1: if (nin == 1) { u = Getint8InPortPtrs(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 = Getint8InPortPtrs(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 = Getint8InPortPtrs(block, j); y[i] = (y[i]) | (u[i]); } } } } break; case 2: if (nin == 1) { u = Getint8InPortPtrs(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 = Getint8InPortPtrs(block, j); if (u[i] <= 0) { y[i] = 1; break; } } } } else { for (i = 0; i < m * n; i++) { u = Getint8InPortPtrs(block, 1); y[i] = u[i]; for (j = 2; j < nin + 1; j++) { u = Getint8InPortPtrs(block, j); y[i] = ((y[i]) & (u[i])); } y[i] = ~y[i]; } } } break; case 3: if (nin == 1) { u = Getint8InPortPtrs(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 = Getint8InPortPtrs(block, j); if (u[i] > 0) { y[i] = 0; break; } } } } else { for (i = 0; i < m * n; i++) { u = Getint8InPortPtrs(block, 1); y[i] = u[i]; for (j = 2; j < nin + 1; j++) { u = Getint8InPortPtrs(block, j); y[i] = ((y[i]) | (u[i])); } y[i] = ~y[i]; } } } break; case 4: if (nin == 1) { u = Getint8InPortPtrs(block, 1); if (ipar[1] == 0) { l = 0; for (i = 0; i < m * n; i++) { if (u[i] > 0) { l = (l + 1) % 2; } } *y = (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 = Getint8InPortPtrs(block, j); if (u[i] > 0) { l = (l + 1) % 2; } } y[i] = (char)l; } } else { for (i = 0; i < m * n; i++) { u = Getint8InPortPtrs(block, 1); y[i] = u[i]; for (j = 2; j < nin + 1; j++) { u = Getint8InPortPtrs(block, j); y[i] = ((y[i]) ^ (u[i])); } } } } break; case 5: u = Getint8InPortPtrs(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; } }
/*--------------------------------------------------------------------------*/ 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;} } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void relational_op_i32(scicos_block *block, int flag) { int k = 0, i = 0; int m = GetInPortRows(block, 1); int n = GetInPortCols(block, 1); long *u1 = Getint32InPortPtrs(block, 1); long *u2 = Getint32InPortPtrs(block, 2); long *y = Getint32OutPortPtrs(block, 1); int *ipar = GetIparPtrs(block); if (flag == 1) { if ((block->ng != 0) & (get_phase_simulation() == 2)) { for (i = 0; i < m * n; i++) { *(y + i) = block->mode[i] - 1; } } else { for (i = 0; i < m * n; i++) { y[i] = 0; } k = ipar[0]; switch (k) { case 0: for (i = 0; i < m * n; i++) { if (u1[i] == u2[i]) { y[i] = 1; } } break; case 1: for (i = 0; i < m * n; i++) { if (u1[i] != u2[i]) { y[i] = 1; } } break; case 2: for (i = 0; i < m * n; i++) { if (u1[i] < u2[i]) { y[i] = 1; } } break; case 3: for (i = 0; i < m * n; i++) { if (u1[i] <= u2[i]) { y[i] = 1; } } break; case 4: for (i = 0; i < m * n; i++) { if (u1[i] > u2[i]) { y[i] = 1; } } break; case 5: for (i = 0; i < m * n; i++) { if (u1[i] >= u2[i]) { y[i] = 1; } } break; } } } else if (flag == 9) { for (i = 0; i < (m * n); i++) { block->g[i] = (double)(*(u1 + i) - * (u2 + i)); } if (get_phase_simulation() == 1) { for (i = 0; i < m * n; i++) { block->mode[i] = (int)1; } k = ipar[0]; switch (k) { case 0: for (i = 0; i < m * n; i++) { if (u1[i] == u2[i]) { block->mode[i] = (int)2; } } break; case 1: for (i = 0; i < m * n; i++) { if (u1[i] != u2[i]) { block->mode[i] = (int)2; } } break; case 2: for (i = 0; i < m * n; i++) { if (u1[i] < u2[i]) { block->mode[i] = (int)2; } } break; case 3: for (i = 0; i < m * n; i++) { if (u1[i] <= u2[i]) { block->mode[i] = (int)2; } } break; case 4: for (i = 0; i < m * n; i++) { if (u1[i] > u2[i]) { block->mode[i] = (int)2; } } break; case 5: for (i = 0; i < m * n; i++) { if (u1[i] >= u2[i]) { block->mode[i] = (int)2; } } break; } } } }