//-------------------------------------------------------------------------------------------------------- int createScilabFannErrorStructFromCFannErrorStruct(struct fann_error* ann, FILE * log_file, unsigned int StackPos) { int * pi_extra_addr = NULL; SciErr _sciErr; //The struct field names static char * fieldnames[] = {"fannerrorlist", "file"}; _sciErr = createMList(pvApiCtx, StackPos, 2, &pi_extra_addr); if (_sciErr.iErr) { printError(&_sciErr, 0); return -1; } _sciErr = createMatrixOfStringInList(pvApiCtx, StackPos, pi_extra_addr, 1, 2, 1, fieldnames); if (_sciErr.iErr) { printError(&_sciErr, 0); return -1; } _sciErr = createPointerInList(pvApiCtx, StackPos, pi_extra_addr, 2, log_file); if (_sciErr.iErr) { printError(&_sciErr, 0); return -1; } return 0; }
//-------------------------------------------------------------------------------------------------------- int createScilabFannTrainDataStructFromCFannTrainDataStruct(struct fann_train_data* ann_data, unsigned int StackPos) { int * pi_extra_addr = NULL; SciErr _sciErr; //The struct field names static char * fieldnames[] = {"fanntraindatalist", "fann_train_data"}; _sciErr = createMList(pvApiCtx, StackPos, 2, &pi_extra_addr); if (_sciErr.iErr) { printError(&_sciErr, -1); return 0; } _sciErr = createMatrixOfStringInList(pvApiCtx, StackPos, pi_extra_addr, 1, 2, 1, fieldnames); if (_sciErr.iErr) { printError(&_sciErr, -1); return 0; } _sciErr = createPointerInList(pvApiCtx, StackPos, pi_extra_addr, 2, ann_data); if (_sciErr.iErr) { printError(&_sciErr, -1); return 0; } return 0; }
/*--------------------------------------------------------------------------*/ int createXMLObjectAtPos(int type, int pos, int id, void* pvApiCtx) { const char **fields = NULL; int *mlistaddr = NULL; SciErr err; switch (type) { case XMLDOCUMENT: fields = _XMLDoc; break; case XMLELEMENT: fields = _XMLElem; break; case XMLATTRIBUTE: fields = _XMLAttr; break; case XMLNAMESPACE: fields = _XMLNs; break; case XMLLIST: fields = _XMLList; break; case XMLNOTHANDLED: fields = _XMLNotHandled; break; case XMLSET: fields = _XMLSet; break; case XMLVALID: fields = _XMLValid; break; default: Scierror(999, _("Unknown tag.\n")); return 0; } err = createMList(pvApiCtx, pos, 2, &mlistaddr); if (err.iErr) { printError(&err, 0); return 0; } err = createMatrixOfStringInList(pvApiCtx, pos, mlistaddr, 1, 1, 2, fields); if (err.iErr) { printError(&err, 0); return 0; } err = createMatrixOfInteger32InList(pvApiCtx, pos, mlistaddr, 2, 1, 1, &id); if (err.iErr) { printError(&err, 0); return 0; } return 1; }
void ScilabObjects::createEnvironmentObjectAtPos(int type, int pos, int id, const int envId, void * pvApiCtx) { const char ** fields = 0; int * mlistaddr = 0; SciErr err; if (envId < 0) { throw ScilabAbstractEnvironmentException("Invalid environment"); } switch (type) { case EXTERNAL_OBJECT: fields = static_cast<const char **>(_EOBJ); break; case EXTERNAL_CLASS: fields = static_cast<const char **>(_ECLASS); break; case EXTERNAL_VOID: fields = static_cast<const char **>(_EVOID); break; default : fields = static_cast<const char **>(_EOBJ); break; } err = createMList(pvApiCtx, pos, FIELDS_LENGTH, &mlistaddr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory")); } err = createMatrixOfStringInList(pvApiCtx, pos, mlistaddr, 1, 1, FIELDS_LENGTH, fields); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory")); } err = createMatrixOfInteger32InList(pvApiCtx, pos, mlistaddr, EXTERNAL_ENV_ID_POSITION, 1, 1, &envId); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory")); } err = createMatrixOfInteger32InList(pvApiCtx, pos, mlistaddr, EXTERNAL_OBJ_ID_POSITION, 1, 1, &id); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot allocate memory")); } }
int * H5DataConverter::getHypermatrix(void * pvApiCtx, const int position, const int ndims, const hsize_t * dims) { static const char * hypermat[3] = {"hm", "dims", "entries"}; int * list = 0; SciErr err = createMList(pvApiCtx, position, 3, &list); if (err.iErr) { throw H5Exception(__LINE__, __FILE__, _("Cannot create an hypermatrix on the stack")); } err = createMatrixOfStringInList(pvApiCtx, position, list, 1, 1, 3, hypermat); if (err.iErr) { throw H5Exception(__LINE__, __FILE__, _("Cannot create an hypermatrix on the stack")); } if (sizeof(int) == sizeof(hsize_t)) { err = createMatrixOfInteger32InList(pvApiCtx, position, list, 2, 1, ndims, (int *)dims); if (err.iErr) { throw H5Exception(__LINE__, __FILE__, _("Cannot create an hypermatrix on the stack")); } } else { int * _dims = 0; err = allocMatrixOfInteger32InList(pvApiCtx, position, list, 2, 1, ndims, &_dims); if (err.iErr) { throw H5Exception(__LINE__, __FILE__, _("Cannot create an hypermatrix on the stack")); } for (int i = 0; i < ndims; i++) { _dims[i] = (int)dims[i]; } } return list; }
int CreateCellVariable(int iVar, matvar_t *matVariable, int * parent, int item_position) { static const char *fieldNames[] = {"ce", "dims","entries"}; int nbFields = 3; int K = 0; int prodDims = 0; int valueIndex = 0, type; int * cell_addr = NULL; int * cell_entry_addr = NULL; matvar_t ** allData = NULL; SciErr _SciErr; /* Returned mlist initialization */ if (parent==NULL) { _SciErr = createMList(pvApiCtx, iVar, nbFields, &cell_addr); MATIO_ERROR; } else { _SciErr = createMListInList(pvApiCtx, iVar, parent, item_position, nbFields, &cell_addr); MATIO_ERROR; } /* FIRST LIST ENTRY: fieldnames */ _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, cell_addr, 1, 1, nbFields, (char **)fieldNames); MATIO_ERROR; /* SECOND LIST ENTRY: Dimensions (int32 type) */ if(matVariable->rank==2) /* Two dimensions */ { _SciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, cell_addr, 2, 1, matVariable->rank, matVariable->dims); MATIO_ERROR; } else /* 3 or more dimensions -> Scilab HyperMatrix */ { type = I_INT32; CreateHyperMatrixVariable(iVar, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &type, &matVariable->rank, matVariable->dims, matVariable->data, NULL, cell_addr, 2); } /* ALL OTHER ENTRIES: Fields data */ prodDims = 1; for (K=0; K<matVariable->rank; K++) { prodDims *= matVariable->dims[K]; } allData = (matvar_t**) (matVariable->data); if (prodDims == 1) /* Scalar cell */ { /* Create list entry in the stack */ if (!CreateMatlabVariable(iVar, allData[0], cell_addr, 3)) /* Could not Create Variable */ { sciprint("Do not know how to read a variable of class %d.\n", allData[0]->class_type); } } else { _SciErr = createListInList(pvApiCtx, iVar, cell_addr, 3, prodDims, &cell_entry_addr); MATIO_ERROR; for (valueIndex = 0; valueIndex < prodDims; valueIndex++) { /* Create list entry in the stack */ if (!CreateMatlabVariable(iVar, allData[valueIndex], cell_entry_addr, valueIndex+1)) /* Could not Create Variable */ { sciprint("Do not know how to read a variable of class %d.\n", allData[valueIndex]->class_type); } } } return TRUE; }
int CreateStructVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * parent, int item_position) { char **fieldNames = NULL; int nbFields = 0; int fieldIndex = 0; int K = 0; int prodDims = 0; int valueIndex = 0; matvar_t *fieldMatVar = NULL; matvar_t ** allData = NULL; int * cell_addr = NULL; int * cell_entry_addr = NULL; int type; SciErr sciErr; int *piDims = NULL; int i = 0; /* Fields of the struct */ nbFields = 2; /* "st" "dims" */ nbFields += Mat_VarGetNumberOfFields(matVariable); fieldNames = (char**) MALLOC(sizeof(char*) * nbFields); if (fieldNames == NULL) { Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable"); return FALSE; } fieldNames[0] = strdup("st"); if (fieldNames[0] == NULL) { Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable"); return FALSE; } fieldNames[1] = strdup("dims"); if (fieldNames[1] == NULL) { Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable"); return FALSE; } for (fieldIndex = 1; fieldIndex < nbFields - 1; fieldIndex++) { fieldMatVar = Mat_VarGetStructField(matVariable, &fieldIndex, MAT_BY_INDEX, 0); fieldNames[fieldIndex + 1] = strdup(fieldMatVar->name); if (fieldNames[fieldIndex + 1] == NULL) { Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable"); return FALSE; } } /* Returned mlist initialization */ if (parent == NULL) { sciErr = createMList(pvApiCtx, iVar, nbFields, &cell_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } else { sciErr = createMListInList(pvApiCtx, iVar, parent, item_position, nbFields, &cell_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } /* FIRST LIST ENTRY: fieldnames */ sciErr = createMatrixOfStringInList(pvApiCtx, iVar, cell_addr, 1, 1, nbFields, fieldNames); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } /* SECOND LIST ENTRY: Dimensions (int32 type) */ if (nbFields == 2) /* Empty struct must have size 0x0 in Scilab */ { matVariable->dims[0] = 0; matVariable->dims[1] = 0; } piDims = (int *) MALLOC(matVariable->rank * sizeof(int)); for (i = 0 ; i < matVariable->rank ; ++i) { piDims[i] = (int)matVariable->dims[i]; } if (matVariable->rank == 2) /* Two dimensions */ { sciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, cell_addr, 2, 1, matVariable->rank, piDims); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } else /* 3 or more dimensions -> Scilab HyperMatrix */ { type = I_INT32; CreateHyperMatrixVariable(pvApiCtx, iVar, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &type, &matVariable->rank, piDims, (double*)matVariable->data, NULL, cell_addr, 2); } FREE(piDims); /* ALL OTHER ENTRIES: Fields data */ prodDims = 1; for (K = 0; K < matVariable->rank; K++) { prodDims *= (int)matVariable->dims[K]; } allData = (matvar_t**) (matVariable->data); if (prodDims == 1) /* Scalar struct */ { for (fieldIndex = 0; fieldIndex < nbFields - 2; fieldIndex++) { /* Create list entry in the stack */ if (!CreateMatlabVariable(pvApiCtx, iVar, allData[fieldIndex], cell_addr, fieldIndex + 3)) /* Could not Create Variable */ { if (allData[fieldIndex]->class_type != 0) /* class is 0 for not initialized fields */ { sciprint("Do not know how to read a variable of class %d.\n", allData[fieldIndex]->class_type); } } } } else { for (fieldIndex = 0; fieldIndex < nbFields - 2; fieldIndex++) { sciErr = createListInList(pvApiCtx, iVar, cell_addr, fieldIndex + 3, prodDims, &cell_entry_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } for (valueIndex = 0; valueIndex < prodDims; valueIndex++) { /* Create list entry in the stack */ if (!CreateMatlabVariable(pvApiCtx, iVar, allData[(fieldIndex) + (nbFields - 2)*valueIndex], cell_entry_addr, valueIndex + 1)) /* Could not Create Variable */ { if (allData[(fieldIndex) + (nbFields - 2)*valueIndex]->class_type != 0) /* class is 0 for not initialized fields */ { sciprint("Do not know how to read a variable of class %d.\n", allData[(fieldIndex) + (nbFields - 2)*valueIndex]->class_type); } } } } } freeArrayOfString(fieldNames, nbFields); return TRUE; }