int get_list_info(void* _pvCtx, int _iRhs, int* _piParent, int *_piAddr, int _iItemPos) { SciErr sciErr; int i; int iRet = 0; int iItem = 0; int* piChild = NULL; sciErr = getListItemNumber(_pvCtx, _piAddr, &iItem); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciprint("(%d)\n", iItem); for (i = 0 ; i < iItem ; i++) { sciErr = getListItemAddress(_pvCtx, _piAddr, i + 1, &piChild); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } iTab++; iRet = get_info(_pvCtx, _iRhs, _piAddr, piChild, i + 1); iTab--; } return 0;; }
static bool export_list(int _iH5File, int *_piVar, char* _pstName, int _iVarType) { int iRet = 0; bool bReturn = false; int iItemNumber = 0; SciErr sciErr = getListItemNumber(pvApiCtx, _piVar, &iItemNumber); if (sciErr.iErr) { printError(&sciErr, 0); return false; } //create groupe name char* pstGroupName = createGroupName(_pstName); char pstMsg[256]; sprintf(pstMsg, "list (%d)", iItemNumber); print_type(pstMsg); iLevel++; //open list void *pvList = openList(_iH5File, pstGroupName, iItemNumber); for (int i = 0 ; i < iItemNumber ; i++) { int *piNewVar = NULL; getListItemAddress(pvApiCtx, _piVar, i + 1, &piNewVar);//1 indexed char* pstPathName = createPathName(pstGroupName, i); if (piNewVar == NULL) { //undefined item bReturn = export_undefined(_iH5File, piNewVar, pstPathName); } else { bReturn = export_data(_iH5File, piNewVar, pstPathName); } iRet = addItemInList(_iH5File, pvList, i, pstPathName); FREE(pstPathName); if (bReturn == false || iRet) { return false; } } iLevel--; closeList(_iH5File, pvList, _pstName, iItemNumber, _iVarType); FREE(pstGroupName); //close list return true; }
static int sci_OpenCL_getArgs(Kernel<ModeDefinition<OpenCL> >* ker, int* lstptr, int argnum, char *fname) { SciErr sciErr; int* ptr_child = NULL; int rowsM = 0, colsM = 0; double *MM = NULL; int iType = 0; double d = 0; int* n = NULL; void* dptr = NULL; PointerOpenCL* gmat = NULL; try { for (int i = 0; i < argnum; ++i) { sciErr = getListItemAddress(pvApiCtx, lstptr, i + 1, &ptr_child); if (sciErr.iErr) { throw sciErr; } sciErr = getVarType(pvApiCtx, ptr_child, &iType); if (sciErr.iErr) { throw sciErr; } switch (iType) { case sci_pointer: { sciErr = getPointer(pvApiCtx, ptr_child, (void**)&dptr); if (sciErr.iErr) { throw sciErr; } gmat = (PointerOpenCL*)dptr; if (gmat->getGpuType() != GpuPointer::OpenCLType) { throw "Bad pointer type. Make sure that is a openCL pointer."; } ker->pass_argument(gmat->getGpuPtr()); break; } case sci_matrix: { sciErr = getMatrixOfDouble(pvApiCtx, ptr_child, &rowsM, &colsM, &MM); if (sciErr.iErr) { throw sciErr; } d = MM[0]; ker->pass_argument<double>(d); break; } case sci_ints: { sciErr = getMatrixOfInteger32(pvApiCtx, ptr_child, &rowsM, &colsM, &n); if (sciErr.iErr) { throw sciErr; } ker->pass_argument<int>(n[0]); break; } default: break; } } } catch (const char* str) { Scierror(999, "%s: %s\n", fname, str); } catch (SciErr E) { printError(&E, 0); } return 0; }
matvar_t *GetIntegerVariable(void *pvApiCtx, int iVar, const char *name, int * parent, int item_position) { int rank = 0; size_t *pszDims = NULL; int *piDims = NULL; matvar_t *createdVar = NULL; int * var_addr = NULL; int i; int var_type; int integerType; SciErr sciErr; char * tmp_int8 = NULL; short * tmp_int16 = NULL; int * tmp_int32 = NULL; int * item_addr = NULL; unsigned char * tmp_uint8 = NULL; unsigned short * tmp_uint16 = NULL; unsigned int * tmp_uint32 = NULL; #ifdef __SCILAB_INT64__ long long * tmp_int64 = NULL; unsigned long long * tmp_uint64 = NULL; #endif if (parent == NULL) { sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, var_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } else { sciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, item_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } if (var_type == sci_ints) /* 2-D array */ { rank = 2; if ((pszDims = (size_t*)MALLOC(sizeof(size_t) * rank)) == NULL) { Scierror(999, _("%s: No more memory.\n"), "GetIntegerVariable"); return NULL; } if ((piDims = (int*)MALLOC(sizeof(int) * rank)) == NULL) { Scierror(999, _("%s: No more memory.\n"), "GetIntegerVariable"); return NULL; } if (parent == NULL) { sciErr = getMatrixOfIntegerPrecision(pvApiCtx, var_addr, &integerType); } else { sciErr = getMatrixOfIntegerPrecision(pvApiCtx, item_addr, &integerType); } switch (integerType) { case SCI_INT8: /* INT8 */ if (parent == NULL) { sciErr = getMatrixOfInteger8(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_int8); } else { sciErr = getMatrixOfInteger8InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_int8); } for (i = 0; i < rank; i++) { pszDims[i] = piDims[i]; } createdVar = Mat_VarCreate(name, MAT_C_INT8, MAT_T_INT8, rank, pszDims, tmp_int8, 0); break; case SCI_INT16: /* INT16 */ if (parent == NULL) { sciErr = getMatrixOfInteger16(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_int16); } else { sciErr = getMatrixOfInteger16InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_int16); } for (i = 0; i < rank; i++) { pszDims[i] = piDims[i]; } createdVar = Mat_VarCreate(name, MAT_C_INT16, MAT_T_INT16, rank, pszDims, tmp_int16, 0); break; case SCI_INT32: /* INT32 */ if (parent == NULL) { sciErr = getMatrixOfInteger32(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_int32); } else { sciErr = getMatrixOfInteger32InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_int32); } for (i = 0; i < rank; i++) { pszDims[i] = piDims[i]; } createdVar = Mat_VarCreate(name, MAT_C_INT32, MAT_T_INT32, rank, pszDims, tmp_int32, 0); break; case SCI_UINT8: /* UINT8 */ if (parent == NULL) { sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_uint8); } else { sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_uint8); } for (i = 0; i < rank; i++) { pszDims[i] = piDims[i]; } createdVar = Mat_VarCreate(name, MAT_C_UINT8, MAT_T_UINT8, rank, pszDims, tmp_uint8, 0); break; case SCI_UINT16: /* UINT16 */ if (parent == NULL) { sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_uint16); } else { sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_uint16); } for (i = 0; i < rank; i++) { pszDims[i] = piDims[i]; } createdVar = Mat_VarCreate(name, MAT_C_UINT16, MAT_T_UINT16, rank, pszDims, tmp_uint16, 0); break; case SCI_UINT32: /* UINT32 */ if (parent == NULL) { sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_uint32); } else { sciErr = getMatrixOfUnsignedInteger32InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_uint32); } for (i = 0; i < rank; i++) { pszDims[i] = piDims[i]; } createdVar = Mat_VarCreate(name, MAT_C_UINT32, MAT_T_UINT32, rank, pszDims, tmp_uint32, 0); break; default: createdVar = NULL; break; } } else { Scierror(999, _("%s: Wrong type for first input argument: Integer matrix expected.\n"), "GetIntegerVariable"); } FREE(pszDims); FREE(piDims); return createdVar; }
/*------------------------------------------------------------------------*/ int set_layout_options_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol) { //[] or tlist if (valueType == sci_matrix) { return clearLayoutOptions(iObjUID); } else { SciErr sciErr; int i = 0; int* piAddrList = (int*)_pvData; int* piAddr = NULL; int iRows = 0; int iCols = 0; char** pstField = NULL; char* pstType = NULL; sciErr = getListItemAddress(_pvCtx, piAddrList, 1, &piAddr); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } if (getAllocatedMatrixOfString(_pvCtx, piAddr, &iRows, &iCols, &pstField)) { return SET_PROPERTY_ERROR; } pstType = pstField[0]; //depend of kind of tlist if (strcmp(pstType, "OptNoLayout") == 0) { return clearLayoutOptions(iObjUID); } else if (strcmp(pstType, "OptBorder") == 0) { //arg2 -> double 1x2 -> int 1*2 int* piAddr2 = NULL; int iRows2 = 0; int iCols2 = 0; double* pdblPadding = NULL; int piPadding[2]; sciErr = getListItemAddress(_pvCtx, piAddrList, 2, &piAddr2); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } sciErr = getMatrixOfDouble(_pvCtx, piAddr2, &iRows2, &iCols2, &pdblPadding); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } piPadding[0] = (int)pdblPadding[0]; piPadding[1] = (int)pdblPadding[1]; setGraphicObjectProperty(iObjUID, __GO_BORDER_OPT_PADDING__, piPadding, jni_int_vector, 2); } else if (strcmp(pstType, "OptGrid") == 0) { //arg2 -> double 1x2 -> int 1*2 //arg3 -> double 1x2 -> int 1*2 int* piAddr2 = NULL; int iRows2 = 0; int iCols2 = 0; double* pdblGrid = NULL; int piGrid[2]; int* piAddr3 = NULL; int iRows3 = 0; int iCols3 = 0; double* pdblPadding = NULL; int piPadding[2]; sciErr = getListItemAddress(_pvCtx, piAddrList, 2, &piAddr2); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } sciErr = getMatrixOfDouble(_pvCtx, piAddr2, &iRows2, &iCols2, &pdblGrid); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } sciErr = getListItemAddress(_pvCtx, piAddrList, 3, &piAddr3); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } sciErr = getMatrixOfDouble(_pvCtx, piAddr3, &iRows3, &iCols3, &pdblPadding); if (sciErr.iErr) { return SET_PROPERTY_ERROR; } piGrid[0] = (int)pdblGrid[0]; piGrid[1] = (int)pdblGrid[1]; piPadding[0] = (int)pdblPadding[0]; piPadding[1] = (int)pdblPadding[1]; setGraphicObjectProperty(iObjUID, __GO_GRID_OPT_GRID__, piGrid, jni_int_vector, 2); setGraphicObjectProperty(iObjUID, __GO_GRID_OPT_PADDING__, piPadding, jni_int_vector, 2); } else if (strcmp(pstType, "OptGridBag") == 0) { return clearLayoutOptions(iObjUID); } else { freeAllocatedMatrixOfString(iRows, iCols, pstField); return SET_PROPERTY_ERROR; } freeAllocatedMatrixOfString(iRows, iCols, pstField); } return SET_PROPERTY_SUCCEED; }
/*--------------------------------------------------------------------------*/ int sci_param3d1(char *fname, void *pvApiCtx) { SciErr sciErr; int izcol = 0, isfac = 0; double *zcol = NULL; static double ebox_def [6] = { 0, 1, 0, 1, 0, 1}; double *ebox = ebox_def; static int iflag_def[3] = {1, 2, 4}; int iflag[3] , *ifl = NULL; double alpha_def = 35.0 , theta_def = 45.0; double *alpha = &alpha_def, *theta = &theta_def; int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0; int m3n = 0, n3n = 0, m3l = 0; static rhs_opts opts[] = { { -1, "alpha", -1, 0, 0, NULL}, { -1, "ebox", -1, 0, 0, NULL}, { -1, "flag", -1, 0, 0, NULL}, { -1, "leg", -1, 0, 0, NULL}, { -1, "theta", -1, 0, 0, NULL}, { -1, NULL, -1, 0, 0, NULL} }; char * labels = NULL; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddr3 = NULL; int* piAddr31 = NULL; int* piAddr32 = NULL; double* l1 = NULL; double* l2 = NULL; double* l3 = NULL; double* l3n = NULL; if (nbInputArgument(pvApiCtx) <= 0) { sci_demo(fname, pvApiCtx); return 0; } CheckInputArgument(pvApiCtx, 3, 8); if (getOptionals(pvApiCtx, fname, opts) == 0) { ReturnArguments(pvApiCtx); return 0; } if (FirstOpt(pvApiCtx) < 4) { Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4); return (0); } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &l1); /* x */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); printError(&sciErr, 0); return 1; } if (m1 == 1 && n1 > 1) { m1 = n1; n1 = 1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &m2, &n2, &l2); /* y */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); printError(&sciErr, 0); return 1; } if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1; } if (m1 * n1 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } //CheckSameDims if (m1 != m2 || n1 != n2) { Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1); return 1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } switch (getInputArgumentType(pvApiCtx, 3)) { case 1 : izcol = 0; // Retrieve a matrix of double at position 3. // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int l3". sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } break; case 15 : izcol = 1; /* z = list(z,colors) */ sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } if (m3l != 2) { Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"), fname, 2, m3l, 2); return 0; } sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } zcol = (l3n); if (m3n * n3n != n3) { Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, 3, n3); return 0; } break; default : OverLoad(3); return 0; } if (m3 == 1 && n3 > 1) { m3 = n3; n3 = 1; } //CheckSameDims if (m1 != m3 || n1 != n3) { Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1); return 1; } GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts); GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts); GetLabels(pvApiCtx, fname, 6, opts, &labels); iflag_def[1] = 8; ifl = &(iflag_def[1]); GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &ifl, 2, opts); iflag[0] = iflag_def[0]; iflag[1] = ifl[0]; iflag[2] = ifl[1]; GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts); if (m1 == 1 && n1 > 1) { m1 = n1; n1 = 1; } getOrCreateDefaultSubwin(); /* NG beg */ isfac = -1; Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m1, &n1, theta, alpha, labels, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04*/ AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
matvar_t *GetCharVariable(int iVar, const char *name, int * parent, int item_position) { char * dataAdr = NULL; int rank = 0, i = 0, j = 0; int *dims = NULL; matvar_t *createdVar = NULL; int* piLen = NULL; char** pstData = NULL; char* pstMatData = NULL; int * piAddr = NULL; int * item_addr = NULL; int var_type; int saveDim = 0; /* Used to save old dimension before restoring it */ SciErr sciErr; if (parent==NULL) { sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddr); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } sciErr = getVarType(pvApiCtx, piAddr, &var_type); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } } else { sciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } sciErr = getVarType(pvApiCtx, item_addr, &var_type); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } } if(var_type == sci_strings) /* 2-D array */ { rank = 2; if ((dims = (int*)MALLOC(sizeof(int) * rank)) == NULL) { Scierror(999, _("%s: No more memory.\n"), "GetCharVariable"); return NULL; } if (parent==NULL) { // First call to retrieve dimensions sciErr = getMatrixOfString(pvApiCtx, piAddr, &dims[0], &dims[1], NULL, NULL); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } piLen = (int *)MALLOC(dims[0] * dims[1] * sizeof(int)); // Second call to retrieve length of each string sciErr = getMatrixOfString(pvApiCtx, piAddr, &dims[0], &dims[1], piLen, NULL); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } pstData = (char**)MALLOC(sizeof(char*) * dims[0] * dims[1]); for(i = 0 ; i < dims[0] * dims[1] ; i++) { pstData[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1)); //+ 1 for null termination } // Third call to retrieve data sciErr = getMatrixOfString(pvApiCtx, piAddr, &dims[0], &dims[1], piLen, pstData); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } dataAdr = strdup(pstData[0]); } else { // First call to retrieve dimensions sciErr = getMatrixOfStringInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], NULL, NULL); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } piLen = (int *)MALLOC(dims[0] * dims[1] * sizeof(int)); // Second call to retrieve length of each string sciErr = getMatrixOfStringInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], piLen, NULL); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } pstData = (char**)MALLOC(sizeof(char*) * dims[0] * dims[1]); for(i = 0 ; i < dims[0] * dims[1] ; i++) { pstData[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1)); //+ 1 for null termination } // Third call to retrieve data sciErr = getMatrixOfStringInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], piLen, pstData); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } dataAdr = strdup(pstData[0]); } if (dims[0] == 0) /* Empty character string */ { createdVar = Mat_VarCreate(name, MAT_C_CHAR, MAT_T_UINT8, rank, dims, pstData[0], 0); } else if (dims[0]*dims[1] == 1) /* Scalar character string */ { saveDim = dims[1]; dims[1] = piLen[0]; createdVar = Mat_VarCreate(name, MAT_C_CHAR, MAT_T_UINT8, rank, dims, pstData[0], 0); dims[1] = saveDim; } else /* More than one character string -> save as a Cell */ { if (dims[0] == 1) { /* TODO: Should be saved as a cell */ Scierror(999, _("%s: Row array of strings saving is not implemented.\n"), "GetCharVariable"); freeArrayOfString(pstData, dims[0]*dims[1]); FREE(dims); FREE(dataAdr); FREE(piLen); return NULL; } else if (dims[1] == 1) { /* Check that all strings have the same length */ for (i = 0 ; i < dims[0] ; i++) { if (piLen[0] != piLen[i]) { /* TODO: Should be saved as a cell */ Scierror(999, _("%s: Column array of strings with different lengths saving is not implemented.\n"), "GetCharVariable"); freeArrayOfString(pstData, dims[0]*dims[1]); FREE(dims); FREE(dataAdr); FREE(piLen); return NULL; } } /* Reorder characters */ pstMatData = (char*)MALLOC(sizeof(char) * dims[0] * piLen[0]); for (i = 0 ; i < dims[0] ; i++) { for (j = 0 ; j < piLen[0] ; j++) { pstMatData[i+j*dims[0]] = pstData[i][j]; } } /* Save the variable */ saveDim = dims[1]; dims[1] = piLen[0]; createdVar = Mat_VarCreate(name, MAT_C_CHAR, MAT_T_UINT8, rank, dims, pstMatData, 0); dims[1] = saveDim; freeArrayOfString(pstData, dims[0]*dims[1]); /* FREE now because dimensions are changed just below */ FREE(pstMatData); FREE(dims); FREE(dataAdr); FREE(piLen); } else { /* TODO: Should be saved as a cell */ Scierror(999, _("%s: 2D array of strings saving is not implemented.\n"), "GetCharVariable"); freeArrayOfString(pstData, dims[0]*dims[1]); FREE(dims); FREE(dataAdr); FREE(piLen); return NULL; } } } else { Scierror(999, _("%s: Wrong type for first input argument: String matrix expected.\n"), "GetCharVariable"); freeArrayOfString(pstData, dims[0]*dims[1]); FREE(dims); FREE(dataAdr); FREE(piLen); return NULL; } return createdVar; }
int ScilabGateway::invoke_lu(char * fname, const int envId, void * pvApiCtx) { SciErr err; int typ = 0; int * addr = 0; int * listaddr = 0; int len = 0; int * tmpvar = 0; int idObj = 0; int * args = 0; int * child = 0; char * methName = 0; int * eId; int row, col; int * ret = 0; int nbArgs = 0; std::vector<int> torem; CheckInputArgument(pvApiCtx, 4, 4); err = getVarAddressFromPosition(pvApiCtx, 4, &listaddr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } err = getVarType(pvApiCtx, listaddr, &typ); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (typ != sci_list) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A List expected."), 4); } err = getListItemNumber(pvApiCtx, listaddr, &len); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } // Get the environment id err = getVarAddressFromPosition(pvApiCtx, 2, &addr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } err = getVarType(pvApiCtx, addr, &typ); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (typ != sci_ints) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 2); } else { int prec; err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (prec != SCI_INT32) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 2); } err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, &eId); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } } ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(*eId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccurred(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); // Get the object id err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } err = getVarType(pvApiCtx, addr, &typ); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (typ != sci_ints) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 1); } else { int prec; int * id; err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (prec != SCI_INT32) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 1); } err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, &id); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } idObj = *id; } if (idObj == 0) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot invoke on null object."), __FILE__, __LINE__); } tmpvar = new int[len + 1]; *tmpvar = 0; args = new int[len]; nbArgs = len; for (int i = 0; i < len; i++) { err = getListItemAddress(pvApiCtx, listaddr, i + 1, &child); if (err.iErr) { delete[] args; ScilabObjects::removeTemporaryVars(*eId, tmpvar); delete[] tmpvar; throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } try { args[i] = ScilabObjects::getArgumentId(child, tmpvar, false, false, *eId, pvApiCtx); } catch (ScilabAbstractEnvironmentException & e) { delete[] args; delete[] tmpvar; throw; } if (args[i] == VOID_OBJECT) { nbArgs = 0; } } try { methName = ScilabObjects::getSingleString(3, pvApiCtx); } catch (ScilabAbstractEnvironmentException & e) { delete[] args; ScilabObjects::removeTemporaryVars(*eId, tmpvar); delete[] tmpvar; throw; } try { ret = env.invoke(idObj, methName, args, nbArgs); } catch (std::exception & e) { delete[] args; ScilabObjects::removeTemporaryVars(*eId, tmpvar); delete[] tmpvar; freeAllocatedSingleString(methName); throw; } delete[] args; ScilabObjects::removeTemporaryVars(*eId, tmpvar); delete[] tmpvar; freeAllocatedSingleString(methName); if (!ret || *ret <= 0 || (*ret == 1 && ret[1] == VOID_OBJECT)) { if (ret) { delete[] ret; } PutLhsVar(); return 0; } torem.reserve(*ret); for (int i = 1; i <= *ret; i++) { if (!ScilabObjects::unwrap(ret[i], Rhs + i, *eId, pvApiCtx)) { try { ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, ret[i], *eId, pvApiCtx); } catch (ScilabAbstractEnvironmentException & e) { if (!torem.empty()) { env.removeobject(&(torem[0]), torem.size()); } env.removeobject(ret + 1, *ret); delete[] ret; throw; } } else { torem.push_back(ret[i]); } LhsVar(i) = Rhs + i; } if (!torem.empty()) { env.removeobject(&(torem[0]), torem.size()); } delete[] ret; PutLhsVar(); return 0; }
matvar_t *GetStructVariable(int iVar, const char *name, int matfile_version, char **fieldNames, int nbFields, int * parent, int item_position) { int fieldIndex = 0; int valueIndex = 0; int K = 0; int prodDims = 1; matvar_t *dimensionsVariable = NULL; matvar_t **structEntries = NULL; int * var_addr = NULL; int * list_addr = NULL; SciErr sciErr; if (parent==NULL) { sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr); } else { sciErr = getListItemAddress(pvApiCtx, parent, item_position, &var_addr); } if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } /* FIRST LIST ENTRY: fieldnames --> NO NEED TO BE READ */ /* SECOND LIST ENTRY: dimensions */ /* Second input argument = "data" beacause we do not need to give the format because this variable is just temp */ dimensionsVariable = GetMatlabVariable(iVar, "data", 0, var_addr, 2); /* Total number of entries */ for (K=0; K<dimensionsVariable->rank; K++) { prodDims *= ((int *)dimensionsVariable->data)[K]; } /* OTHERS LIST ENTRIES: ALL STRUCT VALUES */ if ((structEntries = (matvar_t **) MALLOC (sizeof(matvar_t*)*(prodDims*(nbFields-2)+1))) == NULL) { Scierror(999, _("%s: No more memory.\n"), "GetStructVariable"); freeArrayOfString(fieldNames, nbFields); return NULL; } for (K = 0; K < prodDims*(nbFields-2)+1; K++) { structEntries[K] = NULL; } if (prodDims == 1) /* Scalar struct array */ { for (fieldIndex = 2; fieldIndex < nbFields; fieldIndex++) { structEntries[fieldIndex - 2] = GetMatlabVariable(iVar ,fieldNames[fieldIndex], matfile_version, var_addr, fieldIndex+1); } } else { /* All the values of each field are stored in a list */ /* Read all entries */ for (fieldIndex = 2; fieldIndex < nbFields; fieldIndex++) { sciErr = getListInList(pvApiCtx, var_addr, fieldIndex+1, &list_addr); if(sciErr.iErr) { printError(&sciErr, 0); return NULL; } for (valueIndex = 0; valueIndex < prodDims; valueIndex++) { structEntries[(fieldIndex-1) + (nbFields-2)*valueIndex] = GetMatlabVariable(iVar ,fieldNames[fieldIndex], matfile_version, list_addr, valueIndex+1); } } } return Mat_VarCreate(name, MAT_C_STRUCT, MAT_T_STRUCT, dimensionsVariable->rank, dimensionsVariable->data, structEntries, 0); }
matvar_t *GetMatlabVariable(void *pvApiCtx, int iVar, const char *name, int matfile_version, int * parent, int item_position) { int * var_addr = NULL; int var_type; SciErr sciErr; matvar_t * tmp_res = NULL; if (parent == NULL) { sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr); if (sciErr.iErr) { printError(&sciErr, 0); return NULL; } sciErr = getVarType(pvApiCtx, var_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return NULL; } } else { sciErr = getListItemAddress(pvApiCtx, parent, item_position, &var_addr); if (sciErr.iErr) { printError(&sciErr, 0); return NULL; } sciErr = getVarType(pvApiCtx, var_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return NULL; } } switch (var_type) { case sci_matrix: tmp_res = GetDoubleVariable(pvApiCtx, iVar, name, matfile_version, parent, item_position); break; case sci_strings: tmp_res = GetCharVariable(pvApiCtx, iVar, name, parent, item_position); break; case sci_ints: tmp_res = GetIntegerVariable(pvApiCtx, iVar, name, parent, item_position); break; case sci_mlist: /* Only cells structs and hypermatrices are managed */ if (isCell(pvApiCtx, var_addr)) { tmp_res = GetCellVariable(pvApiCtx, iVar, name, matfile_version, parent, item_position); } else if (isStruct(pvApiCtx, var_addr)) { tmp_res = GetStructVariable(pvApiCtx, iVar, name, matfile_version, parent, item_position); } else { if (item_position > 0) { tmp_res = GetMlistVariable(pvApiCtx, iVar, name, matfile_version, parent, item_position); } else { tmp_res = GetMlistVariable(pvApiCtx, iVar, name, matfile_version, parent, -1); } } break; case sci_sparse: if (item_position > 0) { tmp_res = GetSparseVariable(pvApiCtx, iVar, name, parent, item_position); } else { tmp_res = GetSparseVariable(pvApiCtx, iVar, name, parent, -1); } break; default: sciprint("Do not known how to get variable of type %d\n", var_type); tmp_res = NULL; } return tmp_res; }
/*--------------------------------------------------------------------------*/ int sci_plot3d(char * fname, unsigned long fname_len) { SciErr sciErr; static double ebox_def [6] = { 0, 1, 0, 1, 0, 1}; double *ebox = ebox_def; static int iflag_def[3] = {2, 2, 4}; int *iflag = iflag_def; double alpha_def = 35.0 , theta_def = 45.0; double *alpha = &alpha_def, *theta = &theta_def; int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0; int m3n = 0, n3n = 0, m3l = 0; int izcol = 0, isfac = 0; double *zcol = NULL; static rhs_opts opts[] = { { -1, "alpha", -1, 0, 0, NULL}, { -1, "ebox", -1, 0, 0, NULL}, { -1, "flag", -1, 0, 0, NULL}, { -1, "leg", -1, 0, 0, NULL}, { -1, "theta", -1, 0, 0, NULL}, { -1, NULL, -1, 0, 0, NULL} }; char * legend = NULL; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddr3 = NULL; int* piAddr31 = NULL; int* piAddr32 = NULL; double* l1 = NULL; double* l2 = NULL; double* l3 = NULL; double* l3n = NULL; /* ** This overload the function to call demo script ** the demo script is called %_<fname> */ if (nbInputArgument(pvApiCtx) <= 0) { sci_demo(fname, fname_len); return 0; } CheckInputArgument(pvApiCtx, 3, 8); if (getOptionals(pvApiCtx, fname, opts) == 0) { ReturnArguments(pvApiCtx); return 0; } if (FirstOpt() < 4) { Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4); return -1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &l1); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1); printError(&sciErr, 0); return 1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &m2, &n2, &l2); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2); printError(&sciErr, 0); return 1; } if (m1 * n1 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (nbInputArgument(pvApiCtx) >= 3) { /* third argument can be a matrix z or a list list(z,zcol) */ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } switch (getInputArgumentType(pvApiCtx, 3)) { case sci_matrix : //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } izcol = 0; break; case sci_list : izcol = 1; /* z = list(z,colors) */ sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } if (m3l != 2) { Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"), fname, 2, m3l, 2); return 1; } sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } zcol = (l3n); if (m3n * n3n != n3 && m3n * n3n != m3 * n3) { Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d expected.\n"), fname, 3, n3, m3 * n3); return 1; } /* * Added by E Segre 4/5/2000. In the case where zcol is a * matrix of the same size as z, we set izcol to 2. This * value is later transmitted to the C2F(fac3dg) routine, * which has been modified to do the interpolated shading * (see the file SCI/modules/graphics/src/c/Plo3d.c */ if (m3n * n3n == m3 * n3) { izcol = 2 ; } break; default : OverLoad(3); return 0; } } iflag_def[1] = 8; GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts); GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts); GetLabels(pvApiCtx, fname, 6, opts, &legend); GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &iflag, 3, opts); GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts); if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1) { if (! (m1 == m2 && m2 == m3 && n1 == n2 && n2 == n3)) { Scierror(999, _("%s: Wrong value for input arguments #%d, #%d and #%d: Incompatible length.\n"), fname, 1, 2, 3); return 1; } } else { if (m2 * n2 != n3) { Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 2, 3); return 1; } if (m1 * n1 != m3) { Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 1, 3); return 1; } if (m1 * n1 <= 1 || m2 * n2 <= 1) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: %s expected.\n"), fname, 2, 3, ">= 2"); return 1; } } if (m1 * n1 == 0 || m2 * n2 == 0 || m3 * n3 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } getOrCreateDefaultSubwin(); /******************** 24/05/2002 ********************/ if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1) /* NG beg */ { isfac = 1; } else { isfac = 0; } Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m3, &n3, theta, alpha, legend, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04 and 19.03.04*/ AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }