/** \fn void cmscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void canimxy3d(scicos_block * block, scicos_flag flag) { char const* pFigureUID; sco_data *sco; int j; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); break; } pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } break; case StateUpdate: pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } appendData(block, block->inptr[0], block->inptr[1], block->inptr[2]); for (j = 0; j < block->insz[0]; j++) { result = pushData(block, j); if (result == FALSE) { Coserror("%s: unable to push some data.", "cscopxy3d"); break; } } break; case Ending: freeScoData(block); break; default: break; } }
/** \fn void cmscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cscopxy3d(scicos_block * block, scicos_flag flag) { int iFigureUID; sco_data *sco; int j; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); } iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); } break; case StateUpdate: iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); break; } appendData(block, GetRealInPortPtrs(block, 1), GetRealInPortPtrs(block, 2), GetRealInPortPtrs(block, 3)); for (j = 0; j < block->insz[0]; j++) { result = pushData(block, j); if (result == FALSE) { Coserror("%s: unable to push some data.", "cscopxy3d"); break; } } break; case Ending: freeScoData(block); break; default: break; } }
/** \fn void cmatview(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cmatview(scicos_block * block, scicos_flag flag) { char const* pFigureUID; double *u; sco_data *sco; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); break; } pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } break; case StateUpdate: pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } u = GetRealInPortPtrs(block, 1); result = pushData(block, u); if (result == FALSE) { Coserror("%s: unable to push some data.", "cmatview"); break; } break; case Ending: freeScoData(block); break; default: break; } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void gainblk_ui16e(scicos_block *block,int flag) { if ((flag==1)|(flag==6)){ int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0; unsigned short *u = NULL,*y = NULL; int mu = 0,ny = 0,my = 0,mo = 0,no = 0; unsigned short *opar = NULL; double k = 0.,D = 0.,C = 0.; mo=GetOparSize(block,1,1); no=GetOparSize(block,1,2); mu=GetInPortRows(block,1); my=GetOutPortRows(block,1); ny=GetOutPortCols(block,1); u=Getuint16InPortPtrs(block,1); y=Getuint16OutPortPtrs(block,1); opar=Getuint16OparPtrs(block,1); k=pow(2,16); if (mo*no==1){ for (i=0;i<ny*mu;++i){ D=(double)(opar[0])*(double)(u[i]); if ((D>=k)|( D<0)) {sciprint(_("overflow error")); set_block_error(-4); return;} else y[i]=(unsigned short)D; } }else{ for (l=0;l<ny;l++) {for (j=0;j<my;j++) {D=0; jl=j+l*my; for (i=0;i<mu;i++) {ji=j+i*my; il=i+l*mu; C=(double)(opar[ji])*(double)(u[il]); D=D + C;} if ((D>=k)|( D<0)) {sciprint(_("overflow error")); set_block_error(-4); return;} else y[jl]=(unsigned short)D; } } } } }
static sco_data *getScoData(scicos_block * block) { sco_data *sco = (sco_data *) * (block->work); if (sco == NULL) { /* * Data allocation */ sco = (sco_data *) MALLOC(sizeof(sco_data)); if (sco == NULL) goto error_handler_sco; sco->scope.cachedFigureUID = NULL; sco->scope.cachedAxeUID = NULL; sco->scope.cachedGrayplotUID = NULL; *(block->work) = sco; } return sco; /* * Error management (out of normal flow) */ error_handler_sco: // allocation error set_block_error(-5); return NULL; }
/*--------------------------------------------------------------------------*/ int sci_coserror(char *fname, unsigned long fname_len) /* renvoi un message erreur */ { /* auxilary variables for dimension and address */ int m1 = 0,n1 = 0; /* dimension of input character string */ int *il_str = NULL; /* address of the description of the input parameter */ int *l_str = NULL; /* address of the data of the input parameter */ int sz_str,ptr_pos = 0; int i = 0, j = 0; int isrun = C2F(cosim).isrun; CheckRhs(1,1); if (!isrun) { Scierror(999,_("%s: scicosim is not running.\n"),fname); } else { il_str = (int *) GetData(1); /* get ptr of integer header of rsh 1 */ /* check for a string */ if(il_str[0] != 10) { Scierror(55,_("%s : First argument must be a string.\n"),fname); C2F(iop).err = 1; return 0; } m1 = il_str[1]; /* number of row */ n1 = il_str[2]; /* number of column */ sprintf(coserr.buf," "); /* Check string matrix */ for (j=0; j < m1*n1; j++) { sz_str = il_str[5+j]-il_str[4+j]; /* store the length of str */ /* get current position in the istk */ if (j==0) { ptr_pos = 5+m1*n1; } else { ptr_pos += il_str[5+j-1]-il_str[4+j-1]; } l_str = &il_str[ptr_pos]; /* get ptr of rsh 1 */ /* codetoascii convertion */ C2F(cha1).buf[0]=' '; C2F(cvstr)(&sz_str,&l_str[0],&C2F(cha1).buf[0],(i=1,&i),sz_str); C2F(cha1).buf[sz_str]='\0'; sprintf(coserr.buf,"%s\n%s",coserr.buf,C2F(cha1).buf); } set_block_error(-5); LhsVar(1) = 0; PutLhsVar(); } return 0; }
static void setErrAndFree(const int flag, types::typed_list out) { set_block_error(flag); for (size_t i = 0; i < out.size(); ++i) { out[i]->killMe(); } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void m_frequ(scicos_block *block, int flag) { double *mat = NULL; double *Dt = NULL; double *off = NULL; SCSINT32_COP *icount = NULL; double t = 0.0; time_counter_t** work = (time_counter_t**) block->work; time_counter_t *counter = NULL; int m = 0; mat = GetRealOparPtrs(block, 1); Dt = GetRealOparPtrs(block, 2); off = GetRealOparPtrs(block, 3); icount = Getint32OparPtrs(block, 4); m = GetOparSize(block, 1, 1); switch (flag) { case 4 : /* the workspace is used to store discrete counter value */ { if ((*work = (time_counter_t*) scicos_malloc(sizeof(time_counter_t) * 2)) == NULL) { set_block_error(-16); return; } counter = *work; *counter = *icount; (*(counter + 1)) = 0; break; } /* event date computation */ case 3 : { counter = *work; t = get_scicos_time(); *counter += (int)mat[*(counter + 1)]; /*increase counter*/ block->evout[(int)mat[*(counter + 1) + m] - 1] = *off + ((double) * counter / (*Dt)) - t; (*(counter + 1))++; *(counter + 1) = *(counter + 1) % m; break; } /* finish */ case 5 : { scicos_free(*work); /*free the workspace*/ break; } default : break; } }
static sco_data *reallocScoData(scicos_block * block, int input, int numberOfPoints) { sco_data *sco = (sco_data *) * (block->work); int i, j; double *ptr; int setLen; int previousNumberOfPoints = sco->internal.maxNumberOfPoints[input]; #ifndef S_SPLINT_S LOG("%s: %s at %d to %d\n", "cmscope", "reallocScoData", input, numberOfPoints); #endif /* !S_SPLINT_S */ for (i = 0; i < block->nin; i++) { for (j = 0; j < block->insz[i]; j++) { ptr = (double *)REALLOC(sco->internal.data[i][j], numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } for (setLen = numberOfPoints - previousNumberOfPoints - 1; setLen >= 0; setLen--) { ptr[previousNumberOfPoints + setLen] = ptr[previousNumberOfPoints - 1]; } sco->internal.data[i][j] = ptr; } } ptr = (double *)REALLOC(sco->internal.time[input], numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } for (setLen = numberOfPoints - previousNumberOfPoints - 1; setLen >= 0; setLen--) { ptr[previousNumberOfPoints + setLen] = ptr[previousNumberOfPoints - 1]; } sco->internal.time[input] = ptr; sco->internal.maxNumberOfPoints[input] = numberOfPoints; return sco; error_handler: freeScoData(block); // allocation error set_block_error(-5); return NULL; }
static sco_data *reallocScoData(scicos_block * block, int input, int numberOfPoints) { sco_data *sco = getScoData(block); double *ptr; int setLen; int previousNumberOfPoints = sco->internal.maxNumberOfPoints[input]; /* * Realloc base pointer */ ptr = (double *)REALLOC(sco->internal.data[2 * input], 3 * numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } for (setLen = numberOfPoints - previousNumberOfPoints - 1; setLen >= 0; setLen--) { ptr[3 * (previousNumberOfPoints + setLen) + 0] = ptr[3 * (previousNumberOfPoints - 1) + 0]; ptr[3 * (previousNumberOfPoints + setLen) + 1] = ptr[3 * (previousNumberOfPoints - 1) + 1]; ptr[3 * (previousNumberOfPoints + setLen) + 2] = ptr[3 * (previousNumberOfPoints - 1) + 2]; } sco->internal.data[2 * input] = ptr; /* * Realloc direction pointer */ ptr = (double *)REALLOC(sco->internal.data[2 * input + 1], 3 * numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } for (setLen = numberOfPoints - previousNumberOfPoints - 1; setLen >= 0; setLen--) { ptr[3 * (previousNumberOfPoints + setLen) + 0] = ptr[3 * (previousNumberOfPoints - 1) + 0]; ptr[3 * (previousNumberOfPoints + setLen) + 1] = ptr[3 * (previousNumberOfPoints - 1) + 1]; ptr[3 * (previousNumberOfPoints + setLen) + 2] = ptr[3 * (previousNumberOfPoints - 1) + 2]; } sco->internal.data[2 * input + 1] = ptr; sco->internal.maxNumberOfPoints[input] = numberOfPoints; return sco; error_handler: freeScoData(block); // allocation error set_block_error(-5); return NULL; }
/* Copyright INRIA * Scicos block simulator * event delay with discrete counter */ SCICOS_BLOCKS_IMPEXP void evtdly4(scicos_block *block, int flag) { double t = 0.; time_counter_t** work = (time_counter_t**) block->work; time_counter_t* i = NULL; switch (flag) { /* init */ case 4 : /* the workspace is used to store discrete counter value */ { if ((*work = (time_counter_t*) scicos_malloc(sizeof(time_counter_t))) == NULL) { set_block_error(-16); return; } i = *work; (*i) = 0; break; } /* event date computation */ case 3 : { double dt; i = *work; t = get_scicos_time(); (*i)++; /*increase counter*/ dt = block->rpar[1] + (*i) * block->rpar[0] - t; /* on event enabled, use the default delay if not scheduled */ if (block->rpar[1] >= 0 && dt < 0) { dt = block->rpar[0]; } block->evout[0] = dt; break; } /* finish */ case 5 : { scicos_free(*work); /*free the workspace*/ break; } default : break; } }
static sco_data *reallocScoData(scicos_block * block, int numberOfPoints) { sco_data *sco = (sco_data *) * (block->work); int i; double *ptr; int setLen; int previousNumberOfPoints = sco->internal.maxNumberOfPoints; int newPoints = numberOfPoints - previousNumberOfPoints; for (i = 0; i < block->insz[0]; i++) { ptr = (double *)REALLOC(sco->internal.coordinates[i], 3 * numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } // memcpy existing Z-axis values (use memmove to handle memory overlapping) memmove(ptr + 2 * numberOfPoints, ptr + 2 * previousNumberOfPoints, previousNumberOfPoints * sizeof(double)); // memcpy existing Y-axis values (use memmove to handle memory overlapping) memmove(ptr + numberOfPoints, ptr + previousNumberOfPoints, previousNumberOfPoints * sizeof(double)); // then set the last points to the last values for Z-axis, Y-axis and X-axis values for (setLen = newPoints - 1; setLen >= 0; setLen--) { ptr[2 * numberOfPoints + previousNumberOfPoints + setLen] = ptr[2 * numberOfPoints + previousNumberOfPoints - 1]; } for (setLen = newPoints - 1; setLen >= 0; setLen--) { ptr[numberOfPoints + previousNumberOfPoints + setLen] = ptr[numberOfPoints + previousNumberOfPoints - 1]; } for (setLen = newPoints - 1; setLen >= 0; setLen--) { ptr[previousNumberOfPoints + setLen] = ptr[previousNumberOfPoints - 1]; } sco->internal.coordinates[i] = ptr; } sco->internal.maxNumberOfPoints = numberOfPoints; return sco; error_handler: freeScoData(block); // allocation error set_block_error(-5); return NULL; }
static BOOL pushData(scicos_block * block, double *data) { char const* pFigureUID; char *pAxeUID; char *pGrayplotUID; BOOL result; int i; int m, n; double alpha, beta; double *scaledData; pFigureUID = getFigure(block); pAxeUID = getAxe(pFigureUID, block); pGrayplotUID = getGrayplot(pAxeUID, block); m = GetInPortSize(block, 1, 1); n = GetInPortSize(block, 1, 2); if (m * n <= 0) { set_block_error(-5); return FALSE; } /* * Scale the data */ alpha = block->rpar[0]; beta = block->rpar[1]; scaledData = (double *)MALLOC(m * n * sizeof(double)); if (scaledData == NULL) { return FALSE; } for (i = 0; i < m * n; i++) { scaledData[i] = floor(alpha * data[i] + beta); } result = setGraphicObjectProperty(pGrayplotUID, __GO_DATA_MODEL_Z__, scaledData, jni_double_vector, m * n); FREE(scaledData); return result; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void edgetrig(scicos_block *block, int flag) { double z = block->z[0], u = block->inptr[0][0]; if (flag == 2 || flag == 6) { block->z[0] = u; } else if (flag == 1) { if (block->ipar[0] != 0) { z = z * block->ipar[0]; u = u * block->ipar[0]; if (((z <= 0) & (u > 0)) || ((z < 0) & (u >= 0))) { block->outptr[0][0] = 1.; } else { block->outptr[0][0] = 0.; } } else /* rising and falling edge */ { if (((z <= 0) & (u > 0)) || ((z < 0) & (u >= 0)) || ((z > 0) & (u <= 0)) || ((z >= 0) & (u < 0))) { block->outptr[0][0] = 1.; } else { block->outptr[0][0] = 0.; } } } else if (flag == 4) { if (block->ng > 0) { set_block_error(-1); scicos_print(_("Trigger block must have discrete time input.")); return; } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void backlash(scicos_block *block,int flag) { double* rw = NULL,t = 0.; if (flag == 4){/* the workspace is used to store previous values */ if ((*block->work= scicos_malloc(sizeof(double)* 4))== NULL ) { set_block_error(-16); return; } rw=*block->work; t=get_scicos_time(); rw[0]=t; rw[1]=t; rw[2]=block->rpar[0]; rw[3]=block->rpar[0]; }else if (flag == 5){ scicos_free(*block->work); }else if (flag == 1) { rw=*block->work; t=get_scicos_time(); if(t>rw[1]) { rw[0]=rw[1]; rw[2]=rw[3]; } rw[1]=t; if(block->inptr[0][0]>rw[2]+block->rpar[1]/2){ rw[3]=block->inptr[0][0]-block->rpar[1]/2; } else if (block->inptr[0][0]<rw[2]-block->rpar[1]/2){ rw[3]=block->inptr[0][0]+block->rpar[1]/2; } else { rw[3]=rw[2]; } block->outptr[0][0]=rw[3]; } else if (flag == 9) { rw=*block->work; t=get_scicos_time(); if(t>rw[1]){ block->g[0] = block->inptr[0][0]-block->rpar[1]/2-rw[3]; block->g[1] = block->inptr[0][0]+block->rpar[1]/2-rw[3]; }else{ block->g[0] = block->inptr[0][0]-block->rpar[1]/2-rw[2]; block->g[1] = block->inptr[0][0]+block->rpar[1]/2-rw[2]; } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void matmul_i32e(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); SCSINT32_COP *u1 = Getint32InPortPtrs(block, 1); SCSINT32_COP *u2 = Getint32InPortPtrs(block, 2); SCSINT32_COP *y = Getint32OutPortPtrs(block, 1); double k = pow(2, 32); int l = 0; for (l = 0; l < nu2; l++) { int j = 0; for (j = 0; j < mu1; j++) { double D = 0.; int i = 0; int jl = j + l * mu1; 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 / 2) - 1)) | (D < -((k / 2)))) { sciprint(_("overflow error")); set_block_error(-4); return; } else { y[jl] = (SCSINT32_COP)(D); } } } } }
/*--------------------------------------------------------------------------*/ 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); } } } } }
/*--------------------------------------------------------------------------*/ int sci_set_blockerror(char *fname, unsigned long fname_len) { int one = 1, l1 = 0; int isrun = C2F(cosim).isrun; CheckRhs(1, 1); if (!isrun) { Scierror(999, _("%s: scicosim is not running.\n"), fname); } else { GetRhsVar(1, MATRIX_OF_INTEGER_DATATYPE, (one = 1, &one), (one = 1, &one), &l1); set_block_error(*istk(l1)); LhsVar(1) = 0; PutLhsVar(); } return 0; }
static void appendData(scicos_block * block, int input, double t) { sco_data *sco = getScoData(block); int maxNumberOfPoints = sco->internal.maxNumberOfPoints[input]; int numberOfPoints = sco->internal.numberOfPoints[input]; int i; int nclk = block->nipar - 6; /* * Handle the case where the t is greater than the data_bounds */ if (t > ((sco->scope.periodCounter + 1) * block->rpar[0])) { sco->scope.periodCounter++; // reset the number of points for all the segs numberOfPoints = 0; for (i = 0; i < nclk; i++) { sco->internal.numberOfPoints[i] = 0; } if (setBounds(block, getAxe(getFigure(block), block), sco->scope.periodCounter) == FALSE) { set_block_error(-5); freeScoData(block); sco = NULL; } } /* * Handle the case where the scope has more points than maxNumberOfPoints */ if (sco != NULL && numberOfPoints >= maxNumberOfPoints) { // on a full scope, re-alloc maxNumberOfPoints = maxNumberOfPoints + DEFAULT_MAX_NUMBER_OF_POINTS; sco = reallocScoData(block, input, maxNumberOfPoints); // reconfigure related graphic objects if (setSegsBuffers(block, maxNumberOfPoints) == FALSE) { set_block_error(-5); freeScoData(block); sco = NULL; } } /* * Update data */ if (sco != NULL) { int setLen; /* * Base pointer */ for (setLen = maxNumberOfPoints - numberOfPoints - 1; setLen >= 0; setLen--) { sco->internal.data[2 * input + 0][3 * (numberOfPoints + setLen) + 0] = t; // x sco->internal.data[2 * input + 0][3 * (numberOfPoints + setLen) + 1] = 0; // y sco->internal.data[2 * input + 0][3 * (numberOfPoints + setLen) + 2] = (double) input; // z } /* * Direction pointer */ for (setLen = maxNumberOfPoints - numberOfPoints - 1; setLen >= 0; setLen--) { sco->internal.data[2 * input + 1][3 * (numberOfPoints + setLen) + 0] = t; // x sco->internal.data[2 * input + 1][3 * (numberOfPoints + setLen) + 1] = 0.8; // y sco->internal.data[2 * input + 1][3 * (numberOfPoints + setLen) + 2] = (double) input; // z } sco->internal.numberOfPoints[input]++; } }
/** \fn void cscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cevscpe(scicos_block * block, scicos_flag flag) { int iFigureUID; double t; int i; int mask; int nclk = block->nipar - 6; sco_data *sco; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); } iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); break; } setSegsBuffers(block, DEFAULT_MAX_NUMBER_OF_POINTS); break; case StateUpdate: iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); break; } t = get_scicos_time(); // select only the masked indexes for (i = 0; i < nclk; i++) { mask = 1 << i; if ((block->nevprt & mask) == mask) { appendData(block, i, t); result = pushData(block, i); if (result == FALSE) { Coserror("%s: unable to push some data.", "cevscpe"); break; } } } break; case Ending: freeScoData(block); break; default: break; } }
static sco_data *getScoData(scicos_block * block) { sco_data *sco = (sco_data *) * (block->work); int i, j; int nclk = block->nipar - 6; if (sco == NULL) { /* * Data allocation */ sco = (sco_data *) MALLOC(sizeof(sco_data)); if (sco == NULL) { goto error_handler_sco; } sco->internal.numberOfPoints = (int *)CALLOC(nclk, sizeof(int)); if (sco->internal.numberOfPoints == NULL) { goto error_handler_numberOfPoints; } sco->internal.maxNumberOfPoints = (int *)MALLOC(nclk * sizeof(int)); if (sco->internal.numberOfPoints == NULL) { goto error_handler_maxNumberOfPoints; } for (i = 0; i < nclk; i++) { sco->internal.maxNumberOfPoints[i] = DEFAULT_MAX_NUMBER_OF_POINTS; } sco->internal.data = (double **)CALLOC(2 * nclk, sizeof(double *)); if (sco->internal.data == NULL) { goto error_handler_data; } for (i = 0; i < nclk; i++) { /* * Alloc base pointer */ sco->internal.data[2 * i + 0] = (double *)CALLOC(3 * DEFAULT_MAX_NUMBER_OF_POINTS, sizeof(double)); if (sco->internal.data[2 * i + 0] == NULL) { goto error_handler_data_i; } /* * Alloc direction pointer */ sco->internal.data[2 * i + 1] = (double *)CALLOC(3 * DEFAULT_MAX_NUMBER_OF_POINTS, sizeof(double)); if (sco->internal.data[2 * i + 1] == NULL) { FREE(sco->internal.data[2 * i + 0]); goto error_handler_data_i; } } sco->scope.periodCounter = 0; sco->scope.cachedFigureUID = 0; sco->scope.cachedAxeUID = 0; sco->scope.cachedSegsUIDs = (int*)CALLOC(nclk, sizeof(int)); if (sco->scope.cachedSegsUIDs == NULL) { goto error_handler_data_i; } *(block->work) = sco; } return sco; /* * Error management (out of normal flow) */ error_handler_data_i: for (j = 0; j < i; j++) { FREE(sco->internal.data[2 * j + 0]); FREE(sco->internal.data[2 * j + 1]); } FREE(sco->internal.data); error_handler_data: FREE(sco->internal.maxNumberOfPoints); error_handler_maxNumberOfPoints: FREE(sco->internal.numberOfPoints); error_handler_numberOfPoints: FREE(sco); error_handler_sco: // allocation error set_block_error(-5); return NULL; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void matz_inv(scicos_block *block,int flag) { double *ur = NULL; double *yr = NULL; double *ui = NULL; double *yi = NULL; int nu = 0; int info = 0; int i = 0; mat_inv_struct *ptr = NULL; nu =GetInPortRows(block,1); ur=GetRealInPortPtrs(block,1); ui=GetImagInPortPtrs(block,1); yr=GetRealOutPortPtrs(block,1); yi=GetImagOutPortPtrs(block,1); /*init : initialization*/ if (flag==4) { if((*(block->work)=(mat_inv_struct*) scicos_malloc(sizeof(mat_inv_struct)))==NULL) { set_block_error(-16); return; } ptr=*(block->work); if((ptr->ipiv=(int*) scicos_malloc(sizeof(int)*nu))==NULL) { set_block_error(-16); scicos_free(ptr); return; } if((ptr->wrk=(double*) scicos_malloc(sizeof(double)*(2*nu*nu)))==NULL) { set_block_error(-16); scicos_free(ptr->ipiv); scicos_free(ptr); return; } if((ptr->LX=(double*) scicos_malloc(sizeof(double)*(2*nu*nu)))==NULL) { set_block_error(-16); scicos_free(ptr->LX); scicos_free(ptr->ipiv); scicos_free(ptr); return; } } /* Terminaison */ else if (flag==5) { ptr=*(block->work); if((ptr->LX)!=NULL) { scicos_free(ptr->ipiv); scicos_free(ptr->LX); scicos_free(ptr->wrk); scicos_free(ptr); return; } } else { ptr=*(block->work); for (i=0;i<(nu*nu);i++) { ptr->LX[2*i]=ur[i]; ptr->LX[2*i+1]=ui[i]; } C2F(zgetrf)(&nu,&nu,ptr->LX,&nu,ptr->ipiv,&info); if (info !=0) { if (flag!=6) {set_block_error(-7); return; } } C2F(zgetri)(&nu,ptr->LX,&nu,ptr->ipiv,ptr->wrk,&nu,&info); for (i=0;i<(nu*nu);i++) { yr[i]=ptr->LX[2*i]; yi[i]=ptr->LX[2*i+1]; } } }
static sco_data *getScoData(scicos_block * block) { sco_data *sco = (sco_data *) * (block->work); int i, j; if (sco == NULL) { /* * Data allocation */ sco = (sco_data *) MALLOC(sizeof(sco_data)); if (sco == NULL) { goto error_handler_sco; } sco->internal.numberOfPoints = 0; sco->internal.maxNumberOfPoints = block->ipar[2]; sco->internal.coordinates = (double **)CALLOC(block->insz[0], sizeof(double *)); if (sco->internal.coordinates == NULL) { goto error_handler_coordinates; } for (i = 0; i < block->insz[0]; i++) { sco->internal.coordinates[i] = (double *)CALLOC(3 * block->ipar[2], sizeof(double)); if (sco->internal.coordinates[i] == NULL) { goto error_handler_coordinates_i; } } sco->scope.cachedFigureUID = NULL; sco->scope.cachedAxeUID = NULL; sco->scope.cachedPolylinesUIDs = (char **)CALLOC(block->insz[0], sizeof(char **)); *(block->work) = sco; } return sco; /* * Error management (out of normal flow) */ error_handler_coordinates_i: for (j = 0; j < i; j++) { FREE(sco->internal.coordinates[i]); } FREE(sco->internal.coordinates); error_handler_coordinates: FREE(sco); error_handler_sco: // allocation error set_block_error(-5); return NULL; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void mat_bksl(scicos_block *block,int flag) { double *u1 = NULL; double *u2 = NULL; double *y = NULL; int mu = 0; int nu1 = 0; int nu2 = 0; int info = 0; int i = 0,l = 0,lw = 0,lu = 0; mat_bksl_struct *ptr = NULL; double rcond = 0., ANORM = 0., EPS = 0.; mu =GetInPortRows(block,1); nu1 =GetInPortCols(block,1); nu2 =GetInPortCols(block,2); u1=GetRealInPortPtrs(block,1); u2=GetRealInPortPtrs(block,2); y=GetRealOutPortPtrs(block,1); l=Max(mu,nu1); lu=Max(4*nu1,Min(mu,nu1)+3*nu1+1); lw=Max(lu,2*Min(mu,nu1)+nu2); /*init : initialization*/ if (flag==4) {if((*(block->work)=(mat_bksl_struct*) scicos_malloc(sizeof(mat_bksl_struct)))==NULL) {set_block_error(-16); return;} ptr=*(block->work); if((ptr->ipiv=(int*) scicos_malloc(sizeof(int)*nu1))==NULL) {set_block_error(-16); scicos_free(ptr); return;} if((ptr->rank=(int*) scicos_malloc(sizeof(int)))==NULL) {set_block_error(-16); scicos_free(ptr->ipiv); scicos_free(ptr); return;} if((ptr->jpvt=(int*) scicos_malloc(sizeof(int)*nu1))==NULL) {set_block_error(-16); scicos_free(ptr->rank); scicos_free(ptr->ipiv); scicos_free(ptr); return;} if((ptr->iwork=(int*) scicos_malloc(sizeof(int)*nu1))==NULL) {set_block_error(-16); scicos_free(ptr->jpvt); scicos_free(ptr->rank); scicos_free(ptr->ipiv); scicos_free(ptr); return;} if((ptr->dwork=(double*) scicos_malloc(sizeof(double)*lw))==NULL) {set_block_error(-16); scicos_free(ptr->iwork); scicos_free(ptr->jpvt); scicos_free(ptr->rank); scicos_free(ptr->ipiv); scicos_free(ptr); return;} if((ptr->LAF=(double*) scicos_malloc(sizeof(double)*(mu*nu1)))==NULL) {set_block_error(-16); scicos_free(ptr->dwork); scicos_free(ptr->iwork); scicos_free(ptr->jpvt); scicos_free(ptr->rank); scicos_free(ptr->ipiv); scicos_free(ptr); return;} if((ptr->LA=(double*) scicos_malloc(sizeof(double)*(mu*nu1)))==NULL) {set_block_error(-16); scicos_free(ptr->LAF); scicos_free(ptr->dwork); scicos_free(ptr->iwork); scicos_free(ptr->jpvt); scicos_free(ptr->rank); scicos_free(ptr->ipiv); scicos_free(ptr); return;} if((ptr->LXB=(double*) scicos_malloc(sizeof(double)*(l*nu2)))==NULL) {set_block_error(-16); scicos_free(ptr->LA); scicos_free(ptr->LAF); scicos_free(ptr->dwork); scicos_free(ptr->iwork); scicos_free(ptr->jpvt); scicos_free(ptr->rank); scicos_free(ptr->ipiv); scicos_free(ptr); return;} } /* Terminaison */ else if (flag==5) {ptr=*(block->work); if(ptr->LXB!=NULL){ scicos_free(ptr->ipiv); scicos_free(ptr->rank); scicos_free(ptr->jpvt); scicos_free(ptr->iwork); scicos_free(ptr->LAF); scicos_free(ptr->LA); scicos_free(ptr->LXB); scicos_free(ptr->dwork); scicos_free(ptr); return;} } else { ptr=*(block->work); EPS=C2F(dlamch)("e",1L); ANORM=C2F(dlange)("1",&mu,&nu1,u1,&mu,ptr->dwork); C2F(dlacpy)("F",&mu,&nu1,u1,&mu,ptr->LA,&mu); if (mu==nu1) {C2F(dlacpy)("F",&mu,&nu1,ptr->LA,&mu,ptr->LAF,&mu); C2F(dgetrf)(&nu1,&nu1,ptr->LAF,&nu1,ptr->ipiv,&info); rcond=0; if (info==0) {C2F(dgecon)("1",&nu1,ptr->LAF,&nu1,&ANORM,&rcond,ptr->dwork,ptr->iwork,&info); if (rcond>pow(EPS,0.5)) {C2F(dlacpy)("F",&nu1,&nu2,u2,&nu1,ptr->LXB,&nu1); C2F(dgetrs)("N",&nu1,&nu2,ptr->LAF,&nu1,ptr->ipiv,ptr->LXB,&nu1,&info); C2F(dlacpy)("F",&nu1,&nu2,ptr->LXB,&nu1,y,&nu1); return; } } } rcond=pow(EPS,0.5); C2F(dlacpy)("F",&mu,&nu2,u2,&mu,ptr->LXB,&l); for (i=0;i<nu1;i++) *(ptr->jpvt+i)=0; C2F(dgelsy1)(&mu,&nu1,&nu2,ptr->LA,&mu,ptr->LXB,&l,ptr->jpvt,&rcond,ptr->rank,ptr->dwork,&lw,&info); if (info!=0) {if (flag!=6) {set_block_error(-7); return; } } C2F(dlacpy)("F",&nu1,&nu2,ptr->LXB,&l,y,&nu1); } }
/*--------------------------------------------------------------------------*/ 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 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; } } } }
/*--------------------------------------------------------------------------*/ void sciblk4(scicos_block *Blocks, int flag) { /*counter and address variable declaration*/ int i = 0, j = 0, k = 0, topsave = 0; int ierr = 0; int kfun = 0; int *header = NULL, ne1 = 0; double *le111 = NULL; int *il_xd = NULL, *il_res = NULL, *il_out = NULL, *il_outptr = NULL; int *il_xprop = NULL; int *il_z = NULL, *il_oz = NULL, *il_ozptr = NULL, *il_x = NULL; int *il_mode = NULL, *il_evout = NULL, *il_g = NULL; double *l_mode = NULL; double *l_xprop = NULL; /* variable for output typed port */ int nout = 0; int nv = 0, mv = 0; int *ptr = NULL, *funtyp = NULL; /* set number of left and right hand side parameters */ int mlhs = 1, mrhs = 2; /* Save Top counter */ topsave = Top; /* Retrieve block number */ kfun = get_block_number(); /* Retrieve funtyp by import structure */ strcpy(C2F(cha1).buf, "funtyp"); ierr = getscicosvarsfromimport(C2F(cha1).buf, (void**)&ptr, &nv, &mv); if (ierr == 0) { goto err; } funtyp = (int *) ptr; /**************************** * create scilab tlist Blocks ****************************/ if ((createblklist(&Blocks[0], &ierr, (i = -1), funtyp[kfun - 1])) == 0) { goto err; } /* * flag * */ C2F(itosci)(&flag, (i = 1, &i), (j = 1, &j)); if (C2F(scierr)() != 0) { goto err; } /********************** * Call scilab function **********************/ C2F(scifunc)(&mlhs, &mrhs); if (C2F(scierr)() != 0) { goto err; } /*************************** * Update C block structure **************************/ /* get header of output variable Blocks of sciblk4 */ header = (int *) stk(*Lstk(Top)); /* switch to appropriate flag */ switch (flag) { /************************** * update continuous state **************************/ case 0 : { if (Blocks[0].nx != 0) { /* 14 - xd */ il_xd = (int *) listentry(header, 14); ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } if ((funtyp[kfun - 1] == 10004) || (funtyp[kfun - 1] == 10005)) { /* 15 - res */ il_res = (int *) listentry(header, 15); ierr = sci2var(il_res, Blocks[0].res, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } } break; /********************** * update output state **********************/ case 1 : { /* 21 - outptr */ if (Blocks[0].nout != 0) { il_out = (int*) listentry(header, 21); nout = il_out[1]; for (j = 0; j < nout; j++) { il_outptr = (int *) listentry(il_out, j + 1); ierr = sci2var(il_outptr, Blocks[0].outptr[j], Blocks[0].outsz[2 * nout + j]); if (ierr != 0) { goto err; } } } } break; /*********************** * update discrete state ***********************/ case 2 : { /* 7 - z */ if (Blocks[0].nz != 0) { il_z = (int *) listentry(header, 7); if (Blocks[0].scsptr > 0) { le111 = (double *) listentry(header, 7); ne1 = header[7 + 2] - header[7 + 1]; C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j)); } else { ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } /* 11 - oz */ if (Blocks[0].noz != 0) { il_oz = (int *) listentry(header, 11); /* C blocks : extract */ if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004)) { for (j = 0; j < Blocks[0].noz; j++) { il_ozptr = (int *) listentry(il_oz, j + 1); if (Blocks[0].oztyp[j] == SCSUNKNOW_N) { ne1 = Blocks[0].ozsz[j]; C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \ (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k)); } else { ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]); if (ierr != 0) { goto err; } } } } /* sci blocks : don't extract */ else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005)) { ne1 = Blocks[0].ozsz[0]; C2F(unsfdcopy)(&ne1, (double *)il_oz, \ (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j)); } } if (Blocks[0].nx != 0) { /* 13 - x */ il_x = (int *) listentry(header, 13); ierr = sci2var(il_x, Blocks[0].x, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } /* 14 - xd */ il_xd = (int *) listentry(header, 14); ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } break; /*************************** * update event output state ***************************/ case 3 : { /* 23 - evout */ il_evout = (int *) listentry(header, 23); ierr = sci2var(il_evout, Blocks[0].evout, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } break; /********************** * state initialisation **********************/ case 4 : { /* 7 - z */ if (Blocks[0].nz != 0) { il_z = (int *) listentry(header, 7); if (Blocks[0].scsptr > 0) { le111 = (double *) listentry(header, 7); ne1 = header[7 + 2] - header[7 + 1]; C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j)); } else { ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } /* 11 - oz */ if (Blocks[0].noz != 0) { il_oz = (int *) listentry(header, 11); /* C blocks : extract */ if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004)) { for (j = 0; j < Blocks[0].noz; j++) { il_ozptr = (int *) listentry(il_oz, j + 1); if (Blocks[0].oztyp[j] == SCSUNKNOW_N) { ne1 = Blocks[0].ozsz[j]; C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \ (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k)); } else { ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]); if (ierr != 0) { goto err; } } } } /* sci blocks : don't extract */ else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005)) { ne1 = Blocks[0].ozsz[0]; C2F(unsfdcopy)(&ne1, (double *)il_oz, \ (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j)); } } if (Blocks[0].nx != 0) { /* 13 - x */ il_x = (int *) listentry(header, 13); ierr = sci2var(il_x, Blocks[0].x, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } /* 14 - xd */ il_xd = (int *) listentry(header, 14); ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } break; /********* * finish *********/ case 5 : { /* 7 - z */ if (Blocks[0].nz != 0) { il_z = (int *) listentry(header, 7); if (Blocks[0].scsptr > 0) { le111 = (double *) listentry(header, 7); ne1 = header[7 + 2] - header[7 + 1]; C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j)); } else { ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } /* 11 - oz */ if (Blocks[0].noz != 0) { il_oz = (int *) listentry(header, 11); /* C blocks : extract */ if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004)) { for (j = 0; j < Blocks[0].noz; j++) { il_ozptr = (int *) listentry(il_oz, j + 1); if (Blocks[0].oztyp[j] == SCSUNKNOW_N) { ne1 = Blocks[0].ozsz[j]; C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \ (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k)); } else { ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]); if (ierr != 0) { goto err; } } } } /* sci blocks : don't extract */ else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005)) { ne1 = Blocks[0].ozsz[0]; C2F(unsfdcopy)(&ne1, (double *)il_oz, \ (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j)); } } } break; /***************************** * output state initialisation *****************************/ case 6 : { /* 7 - z */ if (Blocks[0].nz != 0) { il_z = (int *) listentry(header, 7); if (Blocks[0].scsptr > 0) { le111 = (double *) listentry(header, 7); ne1 = header[7 + 2] - header[7 + 1]; C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j)); } else { ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } /* 11 - oz */ if (Blocks[0].noz != 0) { il_oz = (int *) listentry(header, 11); /* C blocks : extract */ if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004)) { for (j = 0; j < Blocks[0].noz; j++) { il_ozptr = (int *) listentry(il_oz, j + 1); if (Blocks[0].oztyp[j] == SCSUNKNOW_N) { ne1 = Blocks[0].ozsz[j]; C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \ (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k)); } else { ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]); if (ierr != 0) { goto err; } } } } /* sci blocks : don't extract */ else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005)) { ne1 = Blocks[0].ozsz[0]; C2F(unsfdcopy)(&ne1, (double *)il_oz, \ (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j)); } } if (Blocks[0].nx != 0) { /* 13 - x */ il_x = (int *) listentry(header, 13); ierr = sci2var(il_x, Blocks[0].x, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } /* 14 - xd */ il_xd = (int *) listentry(header, 14); ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } /* 21 - outptr */ if (Blocks[0].nout != 0) { il_out = (int *) listentry(header, 21); nout = il_out[1]; for (j = 0; j < nout; j++) { il_outptr = (int *) listentry(il_out, j + 1); ierr = sci2var(il_outptr, Blocks[0].outptr[j], Blocks[0].outsz[2 * nout + j]); if (ierr != 0) { goto err; } } } } break; /******************************************* * define property of continuous time states * (algebraic or differential states) *******************************************/ case 7 : { if (Blocks[0].nx != 0) { /* 40 - x */ il_xprop = (int *) listentry(header, 40); l_xprop = (double *)(il_xprop + 4); for (nv = 0; nv < Blocks[0].nx; nv++) { Blocks[0].xprop[nv] = (int) l_xprop[nv]; } } } break; /**************************** * zero crossing computation ****************************/ case 9 : { /* 33 - g */ il_g = (int *) listentry(header, 33); ierr = sci2var(il_g, Blocks[0].g, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } if (get_phase_simulation() == 1) { /* 39 - mode */ il_mode = (int *) listentry(header, 39); // Alan, 16/10/07 : fix : mode is an int array l_mode = (double *)(il_mode + 4); for (nv = 0; nv < (il_mode[1]*il_mode[2]); nv++) { Blocks[0].mode[nv] = (int) l_mode[nv]; } //ierr=sci2var(il_mode,Blocks[0].mode,SCSINT_N); /* int */ //if (ierr!=0) goto err; } } break; /********************** * Jacobian computation **********************/ case 10 : { if ((funtyp[kfun - 1] == 10004) || (funtyp[kfun - 1] == 10005)) { /* 15 - res */ il_res = (int *) listentry(header, 15); ierr = sci2var(il_res, Blocks[0].res, SCSREAL_N); /* double */ if (ierr != 0) { goto err; } } } break; } /* Restore initial position Top */ Top = topsave; return; /* if error then restore initial position Top * and set_block_error with flag -1 */ err: Top = topsave; if (ierr != 0) /*var2sci or sci2var error*/ { /* Please update me !*/ if (ierr < 1000) /*var2sci error*/ { switch (ierr) { case 1 : Scierror(888, _("%s: error %d. Stack is full.\n"), "var2sci", ierr); break; case 2 : Scierror(888, _("%s: error %d. No more space on the stack for new data.\n"), "var2sci", ierr); break; default : Scierror(888, _("%s: error %d. Undefined error.\n"), "var2sci", ierr); break; } } else /*sci2var error*/ { switch (ierr) { case 1001 : Scierror(888, _("%s: error %d. Only int or double object are accepted.\n"), "sci2var", ierr); break; case 1002 : Scierror(888, _("%s: error %d. Bad double object sub_type.\n"), "sci2var", ierr); break; case 1003 : Scierror(888, _("%s: error %d. Bad int object sub_type.\n"), "sci2var", ierr); break; case 1004 : Scierror(888, _("%s: error %d. A type of a scilab object has changed.\n"), "sci2var", ierr); break; default : Scierror(888, _("%s: error %d. Undefined error.\n"), "sci2var", ierr); break; } } } set_block_error(-1); }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void mat_svd(scicos_block *block, int flag) { double *u = NULL; double *y1 = NULL, *y2 = NULL, *y3 = NULL; int nu = 0, mu = 0; int info = 0; int i = 0, j = 0, ij = 0, ji = 0, ii = 0, lwork = 0; mat_sdv_struct** work = (mat_sdv_struct**) block->work; mat_sdv_struct *ptr = NULL; mu = GetInPortRows(block, 1); nu = GetInPortCols(block, 1); u = GetRealInPortPtrs(block, 1); y1 = GetRealOutPortPtrs(block, 1); y2 = GetRealOutPortPtrs(block, 2); y3 = GetRealOutPortPtrs(block, 3); /* for lapack 3.1 (2006)*/ lwork = Max(3 * Min(mu, nu) + Max(mu, nu), 5 * Min(mu, nu)); lwork = Max(1, lwork); /*init : initialization*/ if (flag == 4) { if ((*work = (mat_sdv_struct*) scicos_malloc(sizeof(mat_sdv_struct))) == NULL) { set_block_error(-16); return; } ptr = *work; if ((ptr->l0 = (double*) scicos_malloc(sizeof(double))) == NULL) { set_block_error(-16); scicos_free(ptr); return; } if ((ptr->LA = (double*) scicos_malloc(sizeof(double) * (mu * nu))) == NULL) { set_block_error(-16); scicos_free(ptr->l0); scicos_free(ptr); return; } if ((ptr->LSV = (double*) scicos_malloc(sizeof(double) * (Min(mu, nu)))) == NULL) { set_block_error(-16); scicos_free(ptr->LA); scicos_free(ptr->l0); scicos_free(ptr); return; } if ((ptr->LVT = (double*) scicos_malloc(sizeof(double) * (nu * nu))) == NULL) { set_block_error(-16); scicos_free(ptr->LSV); scicos_free(ptr->LA); scicos_free(ptr->l0); scicos_free(ptr); return; } if ((ptr->dwork = (double*) scicos_malloc(sizeof(double) * lwork)) == NULL) { set_block_error(-16); scicos_free(ptr->LVT); scicos_free(ptr->LSV); scicos_free(ptr->LA); scicos_free(ptr->l0); scicos_free(ptr); return; } } /* Terminaison */ else if (flag == 5) { ptr = *work; if ((ptr->dwork) != NULL) { scicos_free(ptr->l0); scicos_free(ptr->LA); scicos_free(ptr->LSV); scicos_free(ptr->LVT); scicos_free(ptr->dwork); scicos_free(ptr); return; } } else { ptr = *work; C2F(dlacpy)("F", &mu, &nu, u, &mu, ptr->LA, &mu); C2F(dgesvd)("A", "A", &mu, &nu, ptr->LA, &mu, ptr->LSV, y1, &mu, ptr->LVT, &nu, ptr->dwork, &lwork, &info); if (info != 0) { if (flag != 6) { set_block_error(-7); return; } } *(ptr->l0) = 0; C2F(dlaset)("F", &mu, &nu, ptr->l0, ptr->l0, y2, &mu); for (i = 0; i < Min(mu, nu); i++) { ii = i + i * mu; *(y2 + ii) = *(ptr->LSV + i); } for (j = 0; j < nu; j++) { for (i = j; i < nu; i++) { ij = i + j * nu; ji = j + i * nu; *(y3 + ij) = *(ptr->LVT + ji); *(y3 + ji) = *(ptr->LVT + ij); } } } }
/*--------------------------------------------------------------------------*/ 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;} } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void mat_lu(scicos_block *block, int flag) { double *u = NULL; double *y1 = NULL; double *y2 = NULL; int mu = 0; int nu = 0; int info = 0; int i = 0, j = 0, l = 0, ij = 0, ik = 0; mat_lu_struct *ptr = NULL; mu = GetInPortRows(block, 1); nu = GetInPortCols(block, 1); u = GetRealInPortPtrs(block, 1); y1 = GetRealOutPortPtrs(block, 1); y2 = GetRealOutPortPtrs(block, 2); l = Min(mu, nu); /*init : initialization*/ if (flag == 4) { if ((*(block->work) = (mat_lu_struct*) scicos_malloc(sizeof(mat_lu_struct))) == NULL) { set_block_error(-16); return; } ptr = *(block->work); if ((ptr->ipiv = (int*) scicos_malloc(sizeof(int) * nu)) == NULL) { set_block_error(-16); scicos_free(ptr); return; } if ((ptr->dwork = (double*) scicos_malloc(sizeof(double) * (mu * nu))) == NULL) { set_block_error(-16); scicos_free(ptr->ipiv); scicos_free(ptr); return; } if ((ptr->IL = (double*) scicos_malloc(sizeof(double) * (mu * l))) == NULL) { set_block_error(-16); scicos_free(ptr->dwork); scicos_free(ptr->ipiv); scicos_free(ptr); return; } if ((ptr->IU = (double*) scicos_malloc(sizeof(double) * (l * nu))) == NULL) { set_block_error(-16); scicos_free(ptr->IL); scicos_free(ptr->dwork); scicos_free(ptr->ipiv); scicos_free(ptr); return; } } /* Terminaison */ else if (flag == 5) { ptr = *(block->work); if ((ptr->IU) != NULL) { scicos_free(ptr->ipiv); scicos_free(ptr->dwork); scicos_free(ptr->IL); scicos_free(ptr->IU); scicos_free(ptr); return; } } else { ptr = *(block->work); for (i = 0; i < (mu * nu); i++) { ptr->dwork[i] = u[i]; } C2F(dgetrf)(&mu, &nu, ptr->dwork, &mu, ptr->ipiv, &info); if (info != 0) { if (flag != 6) { set_block_error(-7); return; } } for (j = 0; j < l; j++) { for (i = 0; i < mu; i++) { ij = i + j * mu; if (i == j) { *(y2 + ij) = 1; } else if (i > j) { *(y2 + ij) = *(ptr->dwork + ij); } else { *(y2 + ij) = 0; } } } for (j = 0; j < nu; j++) { for (i = 0; i < l; i++) { ij = i + j * l; ik = i + j * mu; if (i <= j) { *(y1 + ij) = *(ptr->dwork + ik); } else { *(y1 + ij) = 0; } } } } }