/*--------------------------------------------------------------------------*/ int get_legend_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** legend) { int first_opt = FirstOpt(_pvCtx), kopt; if (pos < first_opt) { int* piAddr = 0; int iType = 0; char* pstData = NULL; getVarAddressFromPosition(_pvCtx, pos, &piAddr); getVarType(_pvCtx, piAddr, &iType); if (iType) { getAllocatedSingleString(_pvCtx, piAddr, &pstData); *legend = pstData; } else { *legend = getDefLegend(); } } else if ((kopt = FindOpt(_pvCtx, "leg", opts)) >= 0) { char* pstData = NULL; getAllocatedSingleString(_pvCtx, opts[kopt].piAddr, &pstData); *legend = pstData; } else { *legend = getDefLegend(); } return 1; }
int sci_sym_set_str_param(char *fname, unsigned long fname_len){ // Error management variable SciErr sciErr1,sciErr2; double status=1.0;//assume error status double num;//to store the value of the double parameter to be set int output;//output return value of the setting of symphony string parameter function int *piAddressVarOne = NULL;//pointer used to access first argument of the function int *piAddressVarTwo=NULL;//pointer used to access second argument of the function char variable_name[100],value[100];//string to hold the name of variable's value to be set and the value to be set is stored in 'value' string char *ptr=variable_name,*valptr=value;//pointer-'ptr' to point to address of the variable name and 'valptr' points to the address of the value to be set to the string parameter CheckInputArgument(pvApiCtx, 2, 2);//Check we have exactly two argument as input or not CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly no argument on output side or not //load address of 1st argument into piAddressVarOne sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); sciErr2 = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); //check whether there is an error or not. if (sciErr1.iErr){ printError(&sciErr1, 0); return 0; } if (sciErr2.iErr){ printError(&sciErr2, 0); return 0; } //read the value in that pointer pointing to variable name int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr); //read the value of the string variable to be set int err2=getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &valptr); //ensure that environment is active if(global_sym_env==NULL){ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n"); } else { output=sym_set_str_param(global_sym_env,ptr,valptr);//symphony function to set the variable name pointed by the ptr pointer to the double value stored in 'value' variable. if(output==FUNCTION_TERMINATED_NORMALLY){ sciprint("setting of string parameter function executed successfully\n"); status=0.0; } else sciprint("Setting of the string parameter was unsuccessfull...check the input values!!\n"); } int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status); if (e){ AssignOutputVariable(pvApiCtx, 1) = 0; return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
/** * retrieve the labels from the command line and store them into labels */ int get_labels_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** labels) { int first_opt = FirstOpt(), kopt; if (pos < first_opt) { int* piAddr = 0; int iType = 0; char* pstData = NULL; getVarAddressFromPosition(_pvCtx, pos, &piAddr); getVarType(_pvCtx, piAddr, &iType); if (iType) { getAllocatedSingleString(_pvCtx, piAddr, &pstData); *labels = pstData; } else { /* jb silvy 03/2006 */ /* do not change the legend if one already exists */ char * pSubWinUID = (char*)getOrCreateDefaultSubwin(); if (sciGetLegendDefined(pSubWinUID)) { *labels = NULL; } else { *labels = getDefLegend(); } } } else if ((kopt = FindOpt("leg", opts))) { int* piAddr = 0; char* pstData = NULL; getVarAddressFromPosition(_pvCtx, kopt, &piAddr); getAllocatedSingleString(_pvCtx, piAddr, &pstData); *labels = pstData; } else { /* jb silvy 03/2006 */ /* do not change the legend if one already exists */ char* pSubWinUID = (char*)getOrCreateDefaultSubwin(); if (sciGetLegendDefined(pSubWinUID)) { *labels = NULL; } else { *labels = getDefLegend(); } } return 1; }
/*--------------------------------------------------------------------------*/ int get_strf_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** strf) { int first_opt = FirstOpt(_pvCtx), kopt; if (pos < first_opt) { int* piAddr = 0; int iType = 0; char* pstData = NULL; getVarAddressFromPosition(_pvCtx, pos, &piAddr); getVarType(_pvCtx, piAddr, &iType); if (iType != 10) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, pos); return 0; } getAllocatedSingleString(_pvCtx, piAddr, &pstData); if ((int)strlen(pstData) != 3) { freeAllocatedSingleString(pstData); Scierror(999, _("%s: Wrong size for input argument #%d: String of %d characters expected.\n"), fname, pos, 3); return 0; } *strf = pstData; } else if ((kopt = FindOpt(_pvCtx, "strf", opts)) >= 0) { char* pstData = NULL; int iType = 0; getVarType(_pvCtx, opts[kopt].piAddr, &iType); if (iType != 10) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, pos); return 0; } getAllocatedSingleString(_pvCtx, opts[kopt].piAddr, &pstData); if ((int)strlen(pstData) != 3) { freeAllocatedSingleString(pstData); Scierror(999, _("%s: Wrong size for input argument #%d: String of %d characters expected.\n"), fname, kopt, 3); return 0; } *strf = pstData; } else { /* def value can be changed */ reinitDefStrfN(); *strf = getDefStrf(); } return 1; }
char * ScilabObjects::getSingleString(int pos, void * pvApiCtx) { SciErr err; int * addr = 0; char * str = 0; err = getVarAddressFromPosition(pvApiCtx, pos, &addr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid String")); } if (!isStringType(pvApiCtx, addr)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A single string expected")); } if (!isScalar(pvApiCtx, addr)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A single String expected")); } if (getAllocatedSingleString(pvApiCtx, addr, &str)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid String")); } return str; }
int sci_deleteNamedVariable(char *fname, unsigned long fname_len) { SciErr sciErr; int iRet = 0; int* piAddr = NULL; char* pstVarName = NULL; CheckRhs(1, 1); CheckLhs(1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName)) { //error return 1; } if (isNamedVarExist(pvApiCtx, pstVarName)) { iRet = deleteNamedVariable(pvApiCtx, pstVarName); } createScalarBoolean(pvApiCtx, Rhs + 1, iRet); AssignOutputVariable(pvApiCtx, 1) = Rhs + 1; return 0; }
int extractVarNameList(int _iStart, int _iEnd, char** _pstNameList) { int iCount = 0; for (int i = _iStart ; i <= _iEnd ; i++) { int* piAddr = NULL; int iType = 0; SciErr sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddr, &_pstNameList[iCount])) { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "export_to_hdf5", i); return 0; } iCount++; } return iCount; }
int sci_sym_get_dbl_param(char *fname, unsigned long fname_len){ // Error management variable SciErr sciErr1; double status=1.0;//assume error status int *piAddressVarOne = NULL;//pointer used to access first argument of the function char variable_name[100];//string to hold the name of variable's value to be retrieved char *ptr=variable_name;//pointer to point to address of the variable name int output;//output parameter for the symphony get_dbl_param function CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not //load address of 1st argument into piAddressVarOne sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); //check whether there is an error or not. if (sciErr1.iErr){ printError(&sciErr1, 0); return 0; } //read the variable name in that pointer pointing to variable name int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr); //ensure that environment is active if(global_sym_env==NULL){ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n"); } else { double a;//local variable to store the value of variable name we want to retrieve output=sym_get_dbl_param(global_sym_env,ptr,&a);//symphony function to get the value of double parameter pointed by ptr pointer and store it in 'a' variable if(output==FUNCTION_TERMINATED_NORMALLY){ sciprint("value of double parameter %s is :: %lf\n",ptr,a); status=1.0; } else{ sciprint("Unable to get the value of the parameter...check the input values!!\n"); status=1.0; } } int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status); if (e){ AssignOutputVariable(pvApiCtx, 1) = 0; return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
/* ========================================================================== */ int sci_bug_11106(char *fname) { int* piAddr = NULL; char pstRet[64]; getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (isStringType(pvApiCtx, piAddr)) { //named check char* pstVar = NULL; getAllocatedSingleString(pvApiCtx, piAddr, &pstVar); if (isNamedListType(pvApiCtx, pstVar)) { sprintf(pstRet, "%s", "isNamedList"); } else if (isNamedTListType(pvApiCtx, pstVar)) { sprintf(pstRet, "%s", "isNamedTList"); } else if (isNamedMListType(pvApiCtx, pstVar)) { sprintf(pstRet, "%s", "isNamedMList"); } else { sprintf(pstRet, "%s", "unmanaged named type"); } FREE(pstVar); } else { if (isListType(pvApiCtx, piAddr)) { sprintf(pstRet, "%s", "isList"); } else if (isTListType(pvApiCtx, piAddr)) { sprintf(pstRet, "%s", "isTList"); } else if (isMListType(pvApiCtx, piAddr)) { sprintf(pstRet, "%s", "isMList"); } else { sprintf(pstRet, "%s", "unmanaged type"); } } createSingleString(pvApiCtx, Rhs + 1, pstRet); LhsVar(1) = Rhs + 1; return 0; }
char *csv_getArgumentAsString(void* _pvCtx, int _iVar, const char *fname, int *iErr) { SciErr sciErr; int *piAddressVar = NULL; int m = 0, n = 0; int iType = 0; char *returnedValue = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar); if (sciErr.iErr) { *iErr = sciErr.iErr; printError(&sciErr, 0); return NULL; } sciErr = getVarType(pvApiCtx, piAddressVar, &iType); if (sciErr.iErr) { *iErr = sciErr.iErr; printError(&sciErr, 0); return NULL; } if (iType != sci_strings) { *iErr = API_ERROR_INVALID_TYPE; Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); return NULL; } *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1); if (*iErr == 0 ) { *iErr = API_ERROR_CHECK_VAR_DIMENSION; Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, _iVar); return NULL; } *iErr = getAllocatedSingleString(pvApiCtx, piAddressVar, &returnedValue); if (*iErr) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return NULL; } return returnedValue; }
char getGenerateMode(void* pvApiCtx, int* _piAddress) { int iRet = 0; char* pstData; iRet = getAllocatedSingleString(pvApiCtx, _piAddress, &pstData); if (iRet) { return -1; } return pstData[0]; }
/*--------------------------------------------------------------------------*/ int sci_xinit(char * fname, void *pvApiCtx) { SciErr err; int * addr = 0; char * path = 0; char * realPath = 0; CheckInputArgument(pvApiCtx, 1, 1); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, addr, &path) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } realPath = expandPathVariable(path); if (realPath) { org_scilab_modules_graphic_export::Driver::setPath(getScilabJavaVM(), realPath); FREE(realPath); } else { Scierror(999, _("%s: Invalid path: %s.\n"), fname, path); return 0; } freeAllocatedSingleString(path); LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int getStackArgumentAsBoolean(void* _pvCtx, int* _piAddr) { if (isScalar(_pvCtx, _piAddr)) { if (isDoubleType(_pvCtx, _piAddr)) { double dbl = 0; getScalarDouble(_pvCtx, _piAddr, &dbl); return ((int)dbl == 0 ? FALSE : TRUE); } else if (isBooleanType(_pvCtx, _piAddr)) { int i = 0; getScalarBoolean(_pvCtx, _piAddr, &i); return (i == 0 ? FALSE : TRUE); } else if (isStringType(_pvCtx, _piAddr)) { int ret = 0; char* pst = NULL; if (getAllocatedSingleString(_pvCtx, _piAddr, &pst)) { return -1; } if (stricmp(pst, "on") == 0) { ret = TRUE; } freeAllocatedSingleString(pst); return ret; } } return -1; }
/*--------------------------------------------------------------------------*/ int sci_zneupd(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrpRVEC = NULL; int* pRVEC = NULL; int* piAddrpHOWMANY = NULL; char* pHOWMANY = NULL; int* piAddrpSELECT = NULL; int* pSELECT = NULL; int* piAddrpBMAT = NULL; char* pBMAT = NULL; int* piAddrpN = NULL; int* pN = NULL; int* piAddrpWHICH = NULL; char* pWHICH = NULL; int* piAddrpNEV = NULL; int* pNEV = NULL; int* piAddrpTOL = NULL; double* pTOL = NULL; int* piAddrpNCV = NULL; int* pNCV = NULL; int* piAddrpIPARAM = NULL; int* pIPARAM = NULL; int* piAddrpIPNTR = NULL; int* pIPNTR = NULL; int* piAddrpRWORK = NULL; double* pRWORK = NULL; int* piAddrpINFO = NULL; int* pINFO = NULL; int* piAddrpD = NULL; doublecomplex* pD = NULL; int* piAddrpZ = NULL; doublecomplex* pZ = NULL; int* piAddrpSIGMA = NULL; doublecomplex* pSIGMA = NULL; int* piAddrpWORKev = NULL; doublecomplex* pWORKev = NULL; int* piAddrpRESID = NULL; doublecomplex* pRESID = NULL; int* piAddrpWORKD = NULL; doublecomplex* pV = NULL; int* piAddrpV = NULL; doublecomplex* pWORKD = NULL; int* piAddrpWORKL = NULL; doublecomplex* pWORKL = NULL; int mRVEC, nRVEC; int mHOWMANY, nHOWMANY; int mSELECT, nSELECT; int D, mD, nD; int Z, mZ, nZ; int mSIGMA, nSIGMA; int mWORKev, nWORKev; int mBMAT, nBMAT; int mN, nN; int mWHICH, nWHICH; int mNEV, nNEV; int mTOL, nTOL; int RESID, mRESID, nRESID; int mNCV, nNCV; int mV, nV; int IPARAM, mIPARAM, nIPARAM; int IPNTR, mIPNTR, nIPNTR; int WORKD, mWORKD, nWORKD; int WORKL, mWORKL, nWORKL; int RWORK, mRWORK, nRWORK; int INFO, mINFO, nINFO; int minlhs = 1, minrhs = 21, maxlhs = 9, maxrhs = 21; int LDZ, LDV, LWORKL; int sizeWORKL = 0; CheckInputArgument(pvApiCtx, minrhs, maxrhs); CheckOutputArgument(pvApiCtx, minlhs, maxlhs); /* VARIABLE = NUMBER */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpRVEC); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpRVEC, &mRVEC, &nRVEC, &pRVEC); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrpSELECT); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpSELECT, &mSELECT, &nSELECT, &pSELECT); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrpD); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 4. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpD, &mD, &nD, &pD); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 4); return 1; } D = 4; sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrpZ); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 5. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpZ, &mZ, &nZ, &pZ); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 5); return 1; } Z = 5; sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddrpSIGMA); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 6. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpSIGMA, &mSIGMA, &nSIGMA, &pSIGMA); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 6); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddrpWORKev); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 7. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpWORKev, &mWORKev, &nWORKev, &pWORKev); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 7); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 9, &piAddrpN); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 9. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpN, &mN, &nN, &pN); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 9); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 11, &piAddrpNEV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 11. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNEV, &mNEV, &nNEV, &pNEV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 11); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 12, &piAddrpTOL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 12. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpTOL, &mTOL, &nTOL, &pTOL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 12); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 13, &piAddrpRESID); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 13. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpRESID, &mRESID, &nRESID, &pRESID); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 13); return 1; } RESID = 13; sciErr = getVarAddressFromPosition(pvApiCtx, 14, &piAddrpNCV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 14. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNCV, &mNCV, &nNCV, &pNCV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 14); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 15, &piAddrpV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 15. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpV, &mV, &nV, &pV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 15); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 16, &piAddrpIPARAM); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 16. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPARAM, &mIPARAM, &nIPARAM, &pIPARAM); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 16); return 1; } IPARAM = 16; sciErr = getVarAddressFromPosition(pvApiCtx, 17, &piAddrpIPNTR); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 17. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPNTR, &mIPNTR, &nIPNTR, &pIPNTR); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 17); return 1; } IPNTR = 17; sciErr = getVarAddressFromPosition(pvApiCtx, 18, &piAddrpWORKD); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 18. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpWORKD, &mWORKD, &nWORKD, &pWORKD); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 18); return 1; } WORKD = 18; sciErr = getVarAddressFromPosition(pvApiCtx, 19, &piAddrpWORKL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 19. sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpWORKL, &mWORKL, &nWORKL, &pWORKL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 19); return 1; } WORKL = 19; sciErr = getVarAddressFromPosition(pvApiCtx, 20, &piAddrpRWORK); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 20. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpRWORK, &mRWORK, &nRWORK, &pRWORK); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 20); return 1; } RWORK = 20; sciErr = getVarAddressFromPosition(pvApiCtx, 21, &piAddrpINFO); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 21. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpINFO, &mINFO, &nINFO, &pINFO); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 21); return 1; } INFO = 21; LWORKL = mWORKL * nWORKL; LDV = Max(1, pN[0]); LDZ = LDV; /* Check some sizes */ if (mIPARAM*nIPARAM != 11) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPARAM", 11); return 1; } if (mIPNTR*nIPNTR != 14) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPNTR", 14); return 1; } if (mRESID*nRESID != pN[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "RESID", pN[0]); return 1; } if (mWORKD * nWORKD < 3 * pN[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKD", 3 * pN[0]); return 1; } if (mSELECT*nSELECT != pNCV[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "SELECT", pNCV[0]); return 1; } if (mD*nD != (pNEV[0] + 1)) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "D", pNEV[0] + 1); return 1; } if ((mZ != pN[0]) || (nZ != pNEV[0])) { Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "Z", pN[0], pNEV[0]); return 1; } if (mWORKev*nWORKev != 2 * pNCV[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKev", 2 * pNCV[0]); return 1; } if ((mV != pN[0]) || (nV != pNCV[0])) { Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "V", pN[0], pNCV[0]); return 1; } sizeWORKL = 3 * pNCV[0] * pNCV[0] + 5 * pNCV[0]; if ((mWORKL * nWORKL < sizeWORKL)) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKL", sizeWORKL); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrpHOWMANY); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrpHOWMANY, &pHOWMANY)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddrpBMAT); if (sciErr.iErr) { freeAllocatedSingleString(pHOWMANY); printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 8. if (getAllocatedSingleString(pvApiCtx, piAddrpBMAT, &pBMAT)) { freeAllocatedSingleString(pHOWMANY); Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 8); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddrpWHICH); if (sciErr.iErr) { freeAllocatedSingleString(pHOWMANY); freeAllocatedSingleString(pBMAT); printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 10. if (getAllocatedSingleString(pvApiCtx, piAddrpWHICH, &pWHICH)) { freeAllocatedSingleString(pHOWMANY); freeAllocatedSingleString(pBMAT); Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 10); return 1; } C2F(zneupd)(pRVEC, pHOWMANY, pSELECT, pD, pZ, &LDZ, pSIGMA, pWORKev, pBMAT, pN, pWHICH, pNEV, pTOL, pRESID, pNCV, pV, &LDV, pIPARAM, pIPNTR, pWORKD, pWORKL, &LWORKL, pRWORK, pINFO); freeAllocatedSingleString(pHOWMANY); freeAllocatedSingleString(pBMAT); freeAllocatedSingleString(pWHICH); if (pINFO[0] < 0) { C2F(errorinfo)("zneupd", pINFO, 6L); return 0; } AssignOutputVariable(pvApiCtx, 1) = D; AssignOutputVariable(pvApiCtx, 2) = Z; AssignOutputVariable(pvApiCtx, 3) = RESID; AssignOutputVariable(pvApiCtx, 4) = IPARAM; AssignOutputVariable(pvApiCtx, 5) = IPNTR; AssignOutputVariable(pvApiCtx, 6) = WORKD; AssignOutputVariable(pvApiCtx, 7) = WORKL; AssignOutputVariable(pvApiCtx, 8) = RWORK; AssignOutputVariable(pvApiCtx, 9) = INFO; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_dnaupd(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrpIDO = NULL; int* pIDO = NULL; int* piAddrpBMAT = NULL; char* pBMAT = NULL; int* piAddrpN = NULL; int* pN = NULL; int* piAddrpWHICH = NULL; char* pWHICH = NULL; int* piAddrpNEV = NULL; int* pNEV = NULL; int* piAddrpTOL = NULL; double* pTOL = NULL; int* piAddrpRESID = NULL; double* pRESID = NULL; int* piAddrpNCV = NULL; int* pNCV = NULL; int* piAddrpV = NULL; double* pV = NULL; int* piAddrpIPARAM = NULL; int* pIPARAM = NULL; int* piAddrpIPNTR = NULL; int* pIPNTR = NULL; int* piAddrpWORKD = NULL; double* pWORKD = NULL; int* piAddrpWORKL = NULL; double* pWORKL = NULL; int* piAddrpINFO = NULL; int* pINFO = NULL; int IDO, mIDO, nIDO; int mN, nN; int mNEV, nNEV; int mTOL, nTOL; int RESID, mRESID, nRESID; int mNCV, nNCV; int V, mV, nV; int IPARAM, mIPARAM, nIPARAM; int IPNTR, mIPNTR, nIPNTR; int WORKD, mWORKD, nWORKD; int WORKL, mWORKL, nWORKL; int INFO, mINFO, nINFO; int minlhs = 1, minrhs = 14, maxlhs = 8, maxrhs = 14; int LDV, LWORKL; int sizeWORKL = 0; /* [IDO,RESID,V,IPARAM,IPNTR,WORKD,WORKL,INFO]=dnaupd... (ID0,BMAT,N,WHICH,NEV,TOL,RESID,NCV,V,IPARAM,IPNTR,WORKD,WORKL,INFO) */ CheckInputArgument(pvApiCtx, minrhs, maxrhs); CheckOutputArgument(pvApiCtx, minlhs, maxlhs); /* VARIABLE = NUMBER */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpIDO); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIDO, &mIDO, &nIDO, &pIDO); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } IDO = 1; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrpN); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpN, &mN, &nN, &pN); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrpNEV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 5. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNEV, &mNEV, &nNEV, &pNEV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 5); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddrpTOL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 6. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpTOL, &mTOL, &nTOL, &pTOL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 6); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddrpRESID); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 7. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpRESID, &mRESID, &nRESID, &pRESID); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 7); return 1; } RESID = 7; sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddrpNCV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 8. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNCV, &mNCV, &nNCV, &pNCV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 8); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 9, &piAddrpV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 9. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpV, &mV, &nV, &pV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 9); return 1; } V = 9; sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddrpIPARAM); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 10. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPARAM, &mIPARAM, &nIPARAM, &pIPARAM); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 10); return 1; } IPARAM = 10; sciErr = getVarAddressFromPosition(pvApiCtx, 11, &piAddrpIPNTR); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 11. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPNTR, &mIPNTR, &nIPNTR, &pIPNTR); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 11); return 1; } IPNTR = 11; sciErr = getVarAddressFromPosition(pvApiCtx, 12, &piAddrpWORKD); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 12. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpWORKD, &mWORKD, &nWORKD, &pWORKD); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 12); return 1; } WORKD = 12; sciErr = getVarAddressFromPosition(pvApiCtx, 13, &piAddrpWORKL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 13. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpWORKL, &mWORKL, &nWORKL, &pWORKL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 13); return 1; } WORKL = 13; sciErr = getVarAddressFromPosition(pvApiCtx, 14, &piAddrpINFO); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 14. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpINFO, &mINFO, &nINFO, &pINFO); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 14); return 1; } INFO = 14; LWORKL = mWORKL * nWORKL; LDV = Max(1, pN[0]); /* Don't call dnaupd if ido == 99 */ if (pIDO[0] == 99) { Scierror(999, _("%s: the computation is already terminated\n"), fname); return 1; } /* Check some sizes */ if (mIPARAM*nIPARAM != 11) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPARAM", 11); return 1; } if (mIPNTR*nIPNTR != 14) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPNTR", 14); return 1; } if (mRESID*nRESID != pN[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "RESID", *(int*)(pN)); return 1; } if ((mV != pN[0]) || (nV != pNCV[0])) { Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "V", *(int*)(pN), *(int*)(pNCV)); return 1; } if (mWORKD * nWORKD < 3 * pN[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKD", 3 * *(int*)(pN)); return 1; } sizeWORKL = 3 * pNCV[0] * pNCV[0] + 6 * pNCV[0]; if (mWORKL * nWORKL < sizeWORKL) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKL", sizeWORKL); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrpBMAT); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrpBMAT, &pBMAT)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrpWHICH); if (sciErr.iErr) { freeAllocatedSingleString(pBMAT); printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 4. if (getAllocatedSingleString(pvApiCtx, piAddrpWHICH, &pWHICH)) { freeAllocatedSingleString(pBMAT); Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 4); return 1; } C2F(dnaupd)(pIDO, pBMAT, pN, pWHICH, pNEV, pTOL, pRESID, pNCV, pV, &LDV, pIPARAM, pIPNTR, pWORKD, pWORKL, &LWORKL, pINFO, 1L, 2L); freeAllocatedSingleString(pBMAT); freeAllocatedSingleString(pWHICH); if (*pINFO < 0) { Scierror(998, _("%s: internal error, info=%d.\n"), fname, *pINFO); return 0; } AssignOutputVariable(pvApiCtx, 1) = IDO; AssignOutputVariable(pvApiCtx, 2) = RESID; AssignOutputVariable(pvApiCtx, 3) = V; AssignOutputVariable(pvApiCtx, 4) = IPARAM; AssignOutputVariable(pvApiCtx, 5) = IPNTR; AssignOutputVariable(pvApiCtx, 6) = WORKD; AssignOutputVariable(pvApiCtx, 7) = WORKL; AssignOutputVariable(pvApiCtx, 8) = INFO; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_fprintfMat(char *fname,unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; int m1 = 0, n1 = 0; int iType1 = 0; int *piAddressVarTwo = NULL; int m2 = 0, n2 = 0; int iType2 = 0; fprintfMatError ierr = FPRINTFMAT_ERROR; char *filename = NULL; char *expandedFilename = NULL; char **textAdded = NULL; char *Format = NULL; double *dValues = NULL; char *separator = NULL; int m4n4 = 0; int i = 0; Nbvars = 0; CheckRhs(1,5); CheckLhs(1,1); if (Rhs >= 3) { int *piAddressVarThree = NULL; int iType3 = 0; int m3 = 0, n3 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType3); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } if (iType3 != sci_strings) { Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3); return 0; } sciErr = getVarDimension(pvApiCtx, piAddressVarThree, &m3, &n3); if ( (m3 != n3) && (n3 != 1) ) { Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &Format)) { Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } } else { Format = strdup(DEFAULT_FPRINTFMAT_FORMAT); } if ( Rhs >= 4 ) { int *piAddressVarFour = NULL; int *lengthStrings = NULL; int iType4 = 0; int m4 = 0, n4 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddressVarFour); if(sciErr.iErr) { if (Format) {FREE(Format); Format = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarFour, &iType4); if(sciErr.iErr) { if (Format) {FREE(Format); Format = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4); return 0; } if (iType4 != sci_strings) { if (Format) {FREE(Format); Format = NULL;} Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 4); return 0; } sciErr = getVarDimension(pvApiCtx, piAddressVarFour, &m4, &n4); if(sciErr.iErr) { if (Format) {FREE(Format); Format = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4); return 0; } if (! ((m4 == 1) || (n4 == 1))) { if (Format) {FREE(Format); Format = NULL;} Scierror(999,_("%s: Wrong size for input argument #%d.\n"), fname, 4); return 0; } lengthStrings = (int*)MALLOC(sizeof(int) * (m4 * n4)); if (lengthStrings == NULL) { if (Format) {FREE(Format); Format = NULL;} Scierror(999,_("%s: Memory allocation error.\n"),fname); return 0; } // get lengthStrings value sciErr = getMatrixOfString(pvApiCtx, piAddressVarFour, &m4, &n4, lengthStrings, NULL); if(sciErr.iErr) { if (Format) {FREE(Format); Format = NULL;} if (lengthStrings) {FREE(lengthStrings); lengthStrings = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4); return 0; } textAdded = (char**)MALLOC(sizeof(char*) * (m4 * n4)); if (textAdded == NULL) { if (Format) {FREE(Format); Format = NULL;} if (lengthStrings) {FREE(lengthStrings); lengthStrings = NULL;} Scierror(999,_("%s: Memory allocation error.\n"),fname); return 0; } for (i = 0; i < (m4 * n4); i++) { textAdded[i] = (char*)MALLOC(sizeof(char) * (lengthStrings[i] + 1)); if (textAdded[i] == NULL) { freeArrayOfString(textAdded, m4 * n4); if (Format) {FREE(Format); Format = NULL;} if (lengthStrings) {FREE(lengthStrings); lengthStrings = NULL;} Scierror(999,_("%s: Memory allocation error.\n"),fname); return 0; } } // get textAdded sciErr = getMatrixOfString(pvApiCtx, piAddressVarFour, &m4, &n4, lengthStrings, textAdded); if (lengthStrings) {FREE(lengthStrings); lengthStrings = NULL;} if(sciErr.iErr) { freeArrayOfString(textAdded, m4 * n4); if (Format) {FREE(Format); Format = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4); return 0; } m4n4 = m4 * n4; } if (Rhs > 4) { int *piAddressVarFive = NULL; int iType5 = 0; int m5 = 0, n5 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddressVarFive); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 5); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarFive, &iType5); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 5); return 0; } if (iType5 != sci_strings) { Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 5); return 0; } sciErr = getVarDimension(pvApiCtx, piAddressVarFive, &m5, &n5); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 5); return 0; } if ( (m5 != n5) && (n5 != 1) ) { Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 5); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarFive, &separator)) { Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } } else { separator = strdup(DEFAULT_FPRINTFMAT_SEPARATOR); } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if(sciErr.iErr) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if(sciErr.iErr) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (iType2 != sci_matrix) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} Scierror(999,_("%s: Wrong type for input argument #%d: Matrix of floating point numbers expected.\n"), fname, 2); return 0; } if (isVarComplex(pvApiCtx, piAddressVarTwo)) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} Scierror(999,_("%s: Wrong type for input argument #%d: Real values expected.\n"), fname, 2); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &dValues); if(sciErr.iErr) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if(sciErr.iErr) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); if(sciErr.iErr) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (iType1 != sci_strings) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); return 0; } sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1); if ( (m1 != n1) && (n1 != 1) ) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &filename)) { if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } expandedFilename = expandPathVariable(filename); ierr = fprintfMat(expandedFilename, Format, separator, dValues, m2, n2,textAdded, m4n4); if (expandedFilename) {FREE(expandedFilename); expandedFilename = NULL;} if (textAdded) freeArrayOfString(textAdded, m4n4); if (Format) {FREE(Format); Format = NULL;} if (separator){FREE(separator); separator = NULL;} switch(ierr) { case FPRINTFMAT_NO_ERROR: { LhsVar(1) = 0; if (filename) {FREE(filename); filename = NULL;} PutLhsVar(); } break; case FPRINTFMAT_FOPEN_ERROR: { Scierror(999,_("%s: can not open file %s.\n"), fname, filename); } break; case FPRINTMAT_FORMAT_ERROR: { Scierror(999,_("%s: Invalid format.\n"), fname); } break; default: case FPRINTFMAT_ERROR: { Scierror(999,_("%s: error.\n"), fname); } break; } if (filename) {FREE(filename); filename = NULL;} return 0; }
int sci_hdf5_listvar_v2(char *fname, int* pvApiCtx) { SciErr sciErr; int *piAddr = NULL; char* pstFile = NULL; int iFile = 0; int iNbItem = 0; VarInfo* pInfo = NULL; const int nbIn = nbInputArgument(pvApiCtx); CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 1, 4); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFile)) { if (pstFile) { FREE(pstFile); } Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1); return 1; } char* pstFileName = expandPathVariable(pstFile); iFile = openHDF5File(pstFileName, 0); if (iFile < 0) { Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile); FREE(pstFileName); FREE(pstFile); return 1; } FREE(pstFileName); FREE(pstFile); //manage version information int iVersion = getSODFormatAttribute(iFile); if (iVersion != SOD_FILE_VERSION) { if (iVersion > SOD_FILE_VERSION) { //can't read file with version newer that me ! closeHDF5File(iFile); Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion); return 1; } else { //call older import functions and exit or ... EXIT ! if (iVersion == 1 || iVersion == -1) { //sciprint("old sci_listvar_in_hdf5_v1\n"); return sci_listvar_in_hdf5_v1(fname, pvApiCtx); } } } iNbItem = getVariableNames(iFile, NULL); if (iNbItem != 0) { char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem); pInfo = (VarInfo*)MALLOC(iNbItem * sizeof(VarInfo)); int b; if (Lhs == 1) { sciprint("Name Type Size Bytes\n"); sciprint("---------------------------------------------------------------\n"); } iNbItem = getVariableNames(iFile, pstVarNameList); for (int i = 0; i < iNbItem; i++) { int iDataSetId = getDataSetIdFromName(iFile, pstVarNameList[i]); if (iDataSetId == 0) { break; } strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName) - 1); pInfo[i].iSize = 0; b = read_data(iDataSetId, 0, NULL, &pInfo[i]) == false; if (b) { break; } if (Lhs == 1) { sciprint("%s\n", pInfo[i].pstInfo); } } freeArrayOfString(pstVarNameList, iNbItem); } else { //no variable returms [] for each Lhs for (int i = 0 ; i < Lhs ; i++) { createEmptyMatrix(pvApiCtx, nbIn + i + 1); AssignOutputVariable(pvApiCtx, i + 1) = nbIn + i + 1; } ReturnArguments(pvApiCtx); return 0; } closeHDF5File(iFile); //1st Lhs char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem); for (int i = 0 ; i < iNbItem ; i++) { pstVarName[i] = pInfo[i].varName; } sciErr = createMatrixOfString(pvApiCtx, nbIn + 1, iNbItem, 1, pstVarName); FREE(pstVarName); if (sciErr.iErr) { FREE(pInfo); printError(&sciErr, 0); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbIn + 1; if (Lhs > 1) { //2nd Lhs double* pdblType; sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 2, iNbItem, 1, &pdblType); if (sciErr.iErr) { printError(&sciErr, 0); FREE(pInfo); return 1; } for (int i = 0 ; i < iNbItem ; i++) { pdblType[i] = pInfo[i].iType; } AssignOutputVariable(pvApiCtx, 2) = nbIn + 2; if (Lhs > 2) { //3rd Lhs int* pList = NULL; sciErr = createList(pvApiCtx, nbIn + 3, iNbItem, &pList); for (int i = 0 ; i < iNbItem ; i++) { double* pdblDims = NULL; allocMatrixOfDoubleInList(pvApiCtx, nbIn + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims); for (int j = 0 ; j < pInfo[i].iDims ; j++) { pdblDims[j] = pInfo[i].piDims[j]; } } AssignOutputVariable(pvApiCtx, 3) = nbIn + 3; } if (Lhs > 3) { //4th Lhs double* pdblSize = NULL; sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 4, iNbItem, 1, &pdblSize); for (int i = 0 ; i < iNbItem ; i++) { pdblSize[i] = pInfo[i].iSize; } AssignOutputVariable(pvApiCtx, 4) = nbIn + 4; } } FREE(pInfo); ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_uigetcolor(char *fname, void* pvApiCtx) { SciErr sciErr; //WARNING ALL NEW DECALRATIONS ARE HERE IF YOUR HAVE MANY FUNCTIONS //IN THE FILE YOU HAVE PROBABLY TO MOVE DECLARATIONS IN GOOD FUNCTIONS int* piAddrredAdr = NULL; double* redAdr = NULL; int* piAddrtitleAdr = NULL; char* titleAdr = NULL; int* piAddrgreenAdr = NULL; double* greenAdr = NULL; int* piAddrblueAdr = NULL; double* blueAdr = NULL; int colorChooserID = 0; int firstColorIndex = 0; int nbRow = 0, nbCol = 0; double *selectedRGB = NULL; CheckInputArgument(pvApiCtx, 0, 4); if ((nbOutputArgument(pvApiCtx) != 1) && (nbOutputArgument(pvApiCtx) != 3)) /* Bad use */ { Scierror(999, _("%s: Wrong number of output arguments: %d or %d expected.\n"), fname, 1, 3); return FALSE; } /* Rhs==1: title or [R, G, B] given */ if (nbInputArgument(pvApiCtx) == 1) { if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrredAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if ((nbRow != 1) || (nbCol != 3)) { Scierror(999, _("%s: Wrong size for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 1, 3); return FALSE; } } else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real or a string expected.\n"), fname, 1); return FALSE; } } /* Title and [R, G, B] given */ if (nbInputArgument(pvApiCtx) == 2) { /* Title */ if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); return FALSE; } /* [R, G, B] */ if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix))) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrredAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } if (nbRow*nbCol != 3) { Scierror(999, _("%s: Wrong size for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 2, 3); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 2, 3); return FALSE; } } /* No title given but colors given with separate values */ if (nbInputArgument(pvApiCtx) == 3) { firstColorIndex = 1; } /* Title and colors given with separate values */ if (nbInputArgument(pvApiCtx) == 4) { firstColorIndex = 2; /* Title */ if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real or a string expected.\n"), fname, 1); return FALSE; } } /* R, G, B given */ if (nbInputArgument(pvApiCtx) >= 3) { /* Default red value */ if ((checkInputArgumentType(pvApiCtx, firstColorIndex, sci_matrix))) { sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex, &piAddrredAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position firstColorIndex. sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex); return 1; } if (nbRow*nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex); return FALSE; } /* Default green value */ if (checkInputArgumentType(pvApiCtx, firstColorIndex + 1, sci_matrix)) { sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex + 1, &piAddrgreenAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position firstColorIndex + 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrgreenAdr, &nbRow, &nbCol, &greenAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex + 1); return 1; } if (nbRow*nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex + 1); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex + 1); return FALSE; } /* Default blue value */ if (checkInputArgumentType(pvApiCtx, firstColorIndex + 2, sci_matrix)) { sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex + 2, &piAddrblueAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position firstColorIndex + 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrblueAdr, &nbRow, &nbCol, &blueAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex + 2); return 1; } if (nbRow*nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex + 2); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex + 2); return FALSE; } } /* Create the Java Object */ colorChooserID = createColorChooser(); /* Title */ if (titleAdr != 0) { setColorChooserTitle(colorChooserID, titleAdr); freeAllocatedSingleString(titleAdr); } /* Default red value */ if (redAdr != 0) { if (greenAdr != 0 ) /* All values given in first input argument */ { setColorChooserDefaultRGBSeparateValues(colorChooserID, (int)redAdr[0], (int)greenAdr[0], (int)blueAdr[0]); } else { setColorChooserDefaultRGB(colorChooserID, redAdr); } } /* Display it and wait for a user input */ colorChooserDisplayAndWait(colorChooserID); /* Return the selected color */ /* Read the user answer */ selectedRGB = getColorChooserSelectedRGB(colorChooserID); if (selectedRGB[0] >= 0) /* The user selected a color */ { nbRow = 1; if (nbOutputArgument(pvApiCtx) == 1) { nbCol = 3; sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, selectedRGB); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } if (nbOutputArgument(pvApiCtx) >= 2) { nbCol = 1; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } redAdr[0] = selectedRGB[0]; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &greenAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } greenAdr[0] = selectedRGB[1]; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &blueAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } blueAdr[0] = selectedRGB[2]; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2; AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3; } } else /* The user canceled */ { nbRow = 0; nbCol = 0; if (nbOutputArgument(pvApiCtx) == 1) { /* Return [] */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } if (nbOutputArgument(pvApiCtx) >= 2) { sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &greenAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &blueAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2; AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3; } } ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_save(char *fname, unsigned long fname_len) { SciErr sciErr; int iOldSave = FALSE; int* piAddr1 = NULL; int iType1 = 0; CheckRhs(1, 100000); CheckLhs(0, 1); //filename or file descriptor sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddr1, &iType1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (iType1 == sci_strings) { int* piAddrI = NULL; int* piAddrI2 = NULL; int iTypeI = 0; int iRowsI = 0; int iColsI = 0; char* pstVarI = NULL; if (Rhs > 1) { int i = 0; for (i = 2 ; i <= Rhs ; i++) { sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrI); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddrI, &iTypeI); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (iTypeI != sci_strings) { iOldSave = TRUE; break; } sciErr = getVarDimension(pvApiCtx, piAddrI, &iRowsI, &iColsI); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (iRowsI != 1 || iColsI != 1) { iOldSave = TRUE; break; } if (getAllocatedSingleString(pvApiCtx, piAddrI, &pstVarI)) { return 1; } if (strcmp(pstVarI, "-append") != 0) { //try to get variable by name sciErr = getVarAddressFromName(pvApiCtx, pstVarI, &piAddrI2); if (sciErr.iErr) { // Try old save because here the input variable can be of type "string" but not a variable name // Ex: a=""; save(filename, a); iOldSave = TRUE; break; } if (piAddrI2 == 0) { iOldSave = TRUE; break; } } freeAllocatedSingleString(pstVarI); } } else { iOldSave = FALSE; } } else { iOldSave = TRUE; } //new save to sod format if (iOldSave == FALSE) { int lw = 0; //call "overload" to prepare data to export_to_hdf5 function. C2F(overload) (&lw, "save", (unsigned long)strlen("save")); } //old save if (iOldSave) { //show warning only for variable save, not for environment. if (getWarningMode() && Rhs > 1) { sciprint(_("%s: Scilab 6 will not support the file format used.\n"), _("Warning")); sciprint(_("%s: Please quote the variable declaration. Example, save('myData.sod',a) becomes save('myData.sod','a').\n"), _("Warning")); sciprint(_("%s: See help('save') for the rational.\n"), _("Warning")); } C2F(intsave)(); } return 0; }
int sci_listvar_in_hdf5_v1(char *fname, int* pvCtx) { SciErr sciErr; int *piAddr = NULL; char* pstFile = NULL; int iFile = 0; int iNbItem = 0; VarInfo_v1* pInfo = NULL; CheckInputArgument(pvCtx, 1, 1); CheckOutputArgument(pvCtx, 1, 4); sciErr = getVarAddressFromPosition(pvCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvCtx, piAddr, &pstFile)) { if (pstFile) { FREE(pstFile); } Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1); return 1; } char* pstFileName = expandPathVariable(pstFile); iFile = openHDF5File(pstFileName, 0); if (iFile < 0) { FREE(pstFileName); Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile); FREE(pstFile); return 1; } FREE(pstFileName); FREE(pstFile); iNbItem = getVariableNames_v1(iFile, NULL); if (iNbItem != 0) { char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem); bool b; pInfo = (VarInfo_v1*)MALLOC(iNbItem * sizeof(VarInfo_v1)); if (nbOutputArgument(pvCtx) == 1) { sciprint("Name Type Size Bytes\n"); sciprint("---------------------------------------------------------------\n"); } iNbItem = getVariableNames_v1(iFile, pstVarNameList); for (int i = 0; i < iNbItem; i++) { int iDataSetId = getDataSetIdFromName_v1(iFile, pstVarNameList[i]); if (iDataSetId == 0) { break; } strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName)); b = read_data_v1(pvCtx, iDataSetId, 0, NULL, &pInfo[i]) == false; closeDataSet_v1(iDataSetId); if (b) { break; } if (nbOutputArgument(pvCtx) == 1) { sciprint("%s\n", pInfo[i].pstInfo); } } freeArrayOfString(pstVarNameList, iNbItem); } else { //no variable returms [] for each Lhs for (int i = 0 ; i < nbOutputArgument(pvCtx) ; i++) { createEmptyMatrix(pvCtx, nbInputArgument(pvCtx) + i + 1); AssignOutputVariable(pvCtx, i + 1) = nbInputArgument(pvCtx) + i + 1; } ReturnArguments(pvCtx); return 0; } closeHDF5File(iFile); //1st Lhs char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem); for (int i = 0 ; i < iNbItem ; i++) { pstVarName[i] = pInfo[i].varName; } sciErr = createMatrixOfString(pvCtx, nbInputArgument(pvCtx) + 1, iNbItem, 1, pstVarName); FREE(pstVarName); if (sciErr.iErr) { FREE(pInfo); printError(&sciErr, 0); return 1; } AssignOutputVariable(pvCtx, 1) = nbInputArgument(pvCtx) + 1; if (nbOutputArgument(pvCtx) > 1) { //2nd Lhs double* pdblType; sciErr = allocMatrixOfDouble(pvCtx, nbInputArgument(pvCtx) + 2, iNbItem, 1, &pdblType); if (sciErr.iErr) { FREE(pInfo); printError(&sciErr, 0); return 1; } for (int i = 0 ; i < iNbItem ; i++) { pdblType[i] = pInfo[i].iType; } AssignOutputVariable(pvCtx, 2) = nbInputArgument(pvCtx) + 2; if (nbOutputArgument(pvCtx) > 2) { //3rd Lhs int* pList = NULL; sciErr = createList(pvCtx, nbInputArgument(pvCtx) + 3, iNbItem, &pList); for (int i = 0 ; i < iNbItem ; i++) { double* pdblDims = NULL; allocMatrixOfDoubleInList(pvCtx, nbInputArgument(pvCtx) + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims); for (int j = 0 ; j < pInfo[i].iDims ; j++) { pdblDims[j] = pInfo[i].piDims[j]; } } AssignOutputVariable(pvCtx, 3) = nbInputArgument(pvCtx) + 3; } if (nbOutputArgument(pvCtx) > 3) { //4th Lhs double* pdblSize; sciErr = allocMatrixOfDouble(pvCtx, nbInputArgument(pvCtx) + 4, iNbItem, 1, &pdblSize); for (int i = 0 ; i < iNbItem ; i++) { pdblSize[i] = pInfo[i].iSize; } AssignOutputVariable(pvCtx, 4) = nbInputArgument(pvCtx) + 4; } } FREE(pInfo); ReturnArguments(pvCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_uicontrol(char *fname, void* pvApiCtx) { SciErr sciErr; int nbRow = 0, nbCol = 0, k = 0; int setStatus = SET_PROPERTY_SUCCEED; int PARENT_NOT_FOUND = -2; int NOT_FOUND = -1; int inputIndex = 0, beginIndex = 0; char *propertyName = NULL; char *styleProperty = NULL; int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**); unsigned long GraphicHandle = 0; int found = 0; /* Does the property exists ? */ int *propertiesValuesIndices = NULL; int iParentType = -1; int *piParentType = &iParentType; int iParentStyle = -1; int *piParentStyle = &iParentStyle; int iParentUID = 0; int iUicontrol = 0; int iCurrentFigure = 0; CheckOutputArgument(pvApiCtx, 0, 1); //init properties index init_property_index(); if (nbInputArgument(pvApiCtx) == 0) { /* Create a pushbutton in current figure */ /* Create a new pushbutton */ GraphicHandle = getHandle(CreateUIControl(NULL)); /* Set current figure as parent */ iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } iUicontrol = getObjectFromHandle(GraphicHandle); setGraphicObjectRelationship(iCurrentFigure, iUicontrol); } else if (nbInputArgument(pvApiCtx) == 1) { /* Create a pushbutton in figure given as parameter */ /* Or give focus to the uicontrol given as parameter */ int* piAddr = NULL; int iType = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isHandleType(pvApiCtx, piAddr) == FALSE && isStringType(pvApiCtx, piAddr) == FALSE) { OverLoad(1); return FALSE; } #if 0 // Allow XML loading else if (isStringType(pvApiCtx, piAddr)) { char* pstXmlfile = NULL; char* pstExpandedPath = NULL; if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstXmlfile)) { freeAllocatedSingleString(pstXmlfile); Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } pstExpandedPath = expandPathVariable(pstXmlfile); freeAllocatedSingleString(pstXmlfile); iUicontrol = xmlload(pstExpandedPath); if (iUicontrol < 1) { Scierror(999, _("%s: can not read file %s.\n"), fname, pstExpandedPath); FREE(pstExpandedPath); return 0; } FREE(pstExpandedPath); GraphicHandle = getHandle(iUicontrol); /* Create return variable */ if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } #endif // Allow XML loading else /* Get parent ID */ { int* piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); if (iParentUID != 0) { getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType == __GO_UICONTROL__) /* Focus management */ { GraphicHandle = (unsigned long)hParent; requestFocus(iParentUID); } else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__) /* PushButton creation */ { /* Create a new pushbutton */ GraphicHandle = getHandle(CreateUIControl(NULL)); iUicontrol = getObjectFromHandle(GraphicHandle); /* First parameter is the parent */ setGraphicObjectRelationship(iParentUID, iUicontrol); setStatus = callSetProperty(pvApiCtx, iUicontrol, &hParent, sci_handles, 1, 1, (char*)propertiesNames[parent_property]); if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure", "Uimenu"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure", "Uimenu"); return FALSE; } } } else { if (!checkInputArgumentType(pvApiCtx, 1, sci_handles) && !checkInputArgumentType(pvApiCtx, 1, sci_strings)) { OverLoad(1); return FALSE; } /* Allocate memory to store the position of properties in uicontrol call */ if ((propertiesValuesIndices = (int*)MALLOC(sizeof(int) * iPropertiesCount)) == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } /* Init all positions to NOT_FOUND */ for (inputIndex = 0; inputIndex < iPropertiesCount; inputIndex++) { propertiesValuesIndices[inputIndex] = NOT_FOUND; /* Property initialized as not found */ } /** * Odd number of input arguments * First input is the parent ID * All event inputs are property names * All odd (except first) inputs are property values */ if (nbInputArgument(pvApiCtx) % 2 == 1) { if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix))) { int* piAddr = NULL; double dblValue = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } if (getScalarDouble(pvApiCtx, piAddr, &dblValue)) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } iParentUID = getFigureFromIndex((int)dblValue); } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } } else /* Get parent ID */ { int* piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); } if (iParentUID == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__) { getGraphicObjectProperty(iParentUID, __GO_STYLE__, jni_int, (void **)&piParentStyle); if (iParentType != __GO_UICONTROL__ || (iParentStyle != __GO_UI_FRAME__ && iParentStyle != __GO_UI_TAB__ && iParentStyle != __GO_UI_LAYER__)) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } } /* First parameter is the parent */ propertiesValuesIndices[parent_property] = 1; // First input parameter which is a property name beginIndex = 2; } /** * Even number of input arguments * All odd inputs are property names * All even inputs are property values */ else { // First input parameter which is a property name beginIndex = 1; } /* Get all properties positions */ for (inputIndex = beginIndex; inputIndex < Rhs; inputIndex = inputIndex + 2) { /* Read property name */ if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex); return FALSE; } else { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &propertyName)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex); return 1; } /* Bug 3031 */ /* We only want to compare propertyName along its length */ /* 'posi' must be matched to 'position' */ found = 0; for (k = 0; k < iPropertiesCount ; k++) { if (strlen(propertyName) <= strlen(propertiesNames[k])) { if (strnicmp(propertyName, propertiesNames[k], strlen(propertyName)) == 0) { propertiesValuesIndices[k] = inputIndex + 1; /* Position of value for property */ found = 1; break; } } } freeAllocatedSingleString(propertyName); if (found == 0) { Scierror(999, _("%s: Unknown property: %s for '%s' handles.\n"), fname, propertyName, "Uicontrol"); return FALSE; } } } if (propertiesValuesIndices[style_property] != NOT_FOUND) /* Style found */ { if ((checkInputArgumentType(pvApiCtx, propertiesValuesIndices[style_property], sci_strings))) { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[style_property], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &styleProperty)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]); return 1; } if (strcmp(styleProperty, "frame") == 0) { //check scrollable property to create a scroll frame instead of normal frame if (propertiesValuesIndices[scrollable_property] != NOT_FOUND) { char* pstScroll = NULL; int iScroll = 0; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[scrollable_property], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isStringType(pvApiCtx, piAddr) == 0 && isBooleanType(pvApiCtx, piAddr) == 0 && isScalar(pvApiCtx, piAddr) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string or boolean expected.\n"), fname, propertiesValuesIndices[scrollable_property]); return 1; } if (isStringType(pvApiCtx, piAddr)) { if (getAllocatedSingleString(pvApiCtx, piAddr, &pstScroll)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]); return 1; } if (strcmp(pstScroll, "on") == 0) { iScroll = 1; } freeAllocatedSingleString(pstScroll); } else { if (getScalarBoolean(pvApiCtx, piAddr, &iScroll)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]); return 1; } } if (iScroll) { freeAllocatedSingleString(styleProperty); styleProperty = os_strdup("framescrollable"); } propertiesValuesIndices[scrollable_property] = NOT_FOUND; } } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]); return FALSE; } } /* Create a new uicontrol */ iUicontrol = CreateUIControl(styleProperty); freeAllocatedSingleString(styleProperty); if (iUicontrol == 0) /* Error in creation */ { Scierror(999, _("%s: Could not create 'Uicontrol' handle.\n"), fname); return FALSE; } GraphicHandle = getHandle(iUicontrol); /* If no parent given then the current figure is the parent */ if (propertiesValuesIndices[parent_property] == NOT_FOUND) { /* Set the parent */ iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } propertiesValuesIndices[parent_property] = PARENT_NOT_FOUND; } /* Read and set all properties */ for (inputIndex = 1; inputIndex < iPropertiesCount; inputIndex++) /* Style has already been set */ { if (propertiesValuesIndices[inputIndex] == PARENT_NOT_FOUND) { //special case for not specified parent //but set relationship at the good moment. setGraphicObjectRelationship(iCurrentFigure, iUicontrol); } else if (propertiesValuesIndices[inputIndex] != NOT_FOUND) { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[inputIndex], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (inputIndex == user_data_property || inputIndex == userdata_property) /* User data settings */ { nbRow = -1; nbCol = -1; setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, 0, 0, 0, (char*)propertiesNames[inputIndex]); } else /* All other properties */ { /* Read property value */ switch (getInputArgumentType(pvApiCtx, propertiesValuesIndices[inputIndex])) { case sci_matrix: { double* pdblValue = NULL; sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &pdblValue); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pdblValue, sci_matrix, nbRow, nbCol, (char*)propertiesNames[inputIndex]); break; } case sci_strings: /* Index for String & TooltipString properties: Can be more than one character string */ if ((inputIndex == string_property) || (inputIndex == tooltipstring_property)) { char** pstValue = NULL; if (getAllocatedMatrixOfString(pvApiCtx, piAddr, &nbRow, &nbCol, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]); freeAllocatedMatrixOfString(nbRow, nbCol, pstValue); } else { char* pstValue = NULL; if (getAllocatedSingleString(pvApiCtx, piAddr, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } nbRow = (int)strlen(pstValue); nbCol = 1; setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]); freeAllocatedSingleString(pstValue); } break; case sci_handles: { long long* pHandles = NULL; sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &nbRow, &nbCol, &pHandles); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pHandles, sci_handles, nbRow, nbCol, (char*)propertiesNames[inputIndex]); break; } case sci_tlist: //constraints and border { setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, sci_tlist, 1, 1, (char*)propertiesNames[inputIndex]); break; } default: setStatus = SET_PROPERTY_ERROR; break; } } if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]); return FALSE; } } } } if (propertiesValuesIndices != NULL && (propertiesValuesIndices[sliderstep_property] == NOT_FOUND && (propertiesValuesIndices[min_property] != NOT_FOUND || propertiesValuesIndices[max_property] != NOT_FOUND))) /* SliderStep property not set */ { /* Set SliderStep property to [1/100*(Max-Min) 1/10*(Max-Min)] */ double maxValue = 0; double* pdblMaxValue = &maxValue; double minValue = 0; double* pdblMinValue = &minValue; double pdblStep[2]; getGraphicObjectProperty(iUicontrol, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue); getGraphicObjectProperty(iUicontrol, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue); pdblStep[0] = 0.01 * (maxValue - minValue); pdblStep[1] = 0.1 * (maxValue - minValue); setGraphicObjectProperty(iUicontrol, __GO_UI_SLIDERSTEP__, pdblStep, jni_double_vector, 2); } if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[position_property] == NOT_FOUND)) /* Position property not set */ { double* pdblPosition = NULL; getGraphicObjectProperty(iUicontrol, __GO_POSITION__, jni_double_vector, (void**) &pdblPosition); setGraphicObjectProperty(iUicontrol, __GO_POSITION__, pdblPosition, jni_double_vector, 4); releaseGraphicObjectProperty(__GO_POSITION__, pdblPosition, jni_double_vector, 4); } if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[visible_property] == NOT_FOUND)) /* Visible property not set */ { /* Force the uicontrol to be visible because is invisible by default in the model (See bug #10346) */ int b = (int)TRUE; setGraphicObjectProperty(iUicontrol, __GO_VISIBLE__, &b, jni_bool, 1); } FREE(propertiesValuesIndices); /* Create return variable */ if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_mgetl(char *fname, unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; int numberOfLinesToRead = -1; Rhs = Max(0, Rhs); CheckRhs(1, 2); CheckLhs(1, 1); if (Rhs == 2) { int *piAddressVarTwo = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if ( isDoubleType(pvApiCtx, piAddressVarTwo) ) { double dValue = 0.; if (!isScalar(pvApiCtx, piAddressVarTwo)) { Scierror(999, _("%s: Wrong size for input argument #%d: Integer expected.\n"), fname, 2); return 0; } if ( getScalarDouble(pvApiCtx, piAddressVarTwo, &dValue) == 0) { numberOfLinesToRead = (int)dValue; } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: Integer expected.\n"), fname, 2); return 0; } } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if ( isStringType(pvApiCtx, piAddressVarOne) || isDoubleType(pvApiCtx, piAddressVarOne) ) { char **wcReadedStrings = NULL; int numberOfLinesReaded = 0; int fileDescriptor = -1; int iErrorMgetl = 0; BOOL bCloseFile = FALSE; if (!isScalar(pvApiCtx, piAddressVarOne)) { Scierror(999, _("%s: Wrong size for input argument #%d: String or logical unit expected.\n"), fname, 1); return 0; } if (isStringType(pvApiCtx, piAddressVarOne)) { char *fileName = NULL; if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &fileName) == 0) { char *expandedFileName = expandPathVariable(fileName); freeAllocatedSingleString(fileName); fileName = NULL; if (IsAlreadyOpenedInScilab(expandedFileName)) { int fd = GetIdFromFilename(expandedFileName); fileDescriptor = fd; if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } bCloseFile = FALSE; } else { #define READ_ONLY_TEXT_MODE "rt" int fd = 0; int f_swap = 0; double res = 0.0; int ierr = 0; C2F(mopen)(&fd, expandedFileName, READ_ONLY_TEXT_MODE, &f_swap, &res, &ierr); bCloseFile = TRUE; switch (ierr) { case MOPEN_NO_ERROR: fileDescriptor = fd; if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } break; case MOPEN_NO_MORE_LOGICAL_UNIT: { Scierror(66, _("%s: Too many files opened!\n"), fname); if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } return 0; } break; case MOPEN_CAN_NOT_OPEN_FILE: { Scierror(999, _("%s: Cannot open file %s.\n"), fname, expandedFileName); if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } return 0; } break; case MOPEN_NO_MORE_MEMORY: { if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } Scierror(999, _("%s: No more memory.\n"), fname); return 0; } break; case MOPEN_INVALID_FILENAME: { Scierror(999, _("%s: invalid filename %s.\n"), fname, expandedFileName); if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } return 0; } break; case MOPEN_INVALID_STATUS: default: { if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } Scierror(999, _("%s: invalid status.\n"), fname); return 0; } break; } } } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else /* double */ { double dValue = 0.; if ( !getScalarDouble(pvApiCtx, piAddressVarOne, &dValue) ) { FILE *fd = NULL; fileDescriptor = (int)dValue; if ((fileDescriptor == STDIN_ID) || (fileDescriptor == STDOUT_ID)) { SciError(244); return 0; } fd = GetFileOpenedInScilab(fileDescriptor); if (fd == NULL) { Scierror(245, _("%s: No input file associated to logical unit %d.\n"), fname, fileDescriptor); return 0; } } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } wcReadedStrings = mgetl(fileDescriptor, numberOfLinesToRead, &numberOfLinesReaded, &iErrorMgetl); if (bCloseFile) { double dErrClose = 0.; C2F(mclose)(&fileDescriptor, &dErrClose); } switch (iErrorMgetl) { case MGETL_NO_ERROR: { if (numberOfLinesReaded == 0) { if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { int m = numberOfLinesReaded; int n = 1; sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, wcReadedStrings); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(17, _("%s: Memory allocation error.\n"), fname); return 0; } } freeArrayOfString(wcReadedStrings, numberOfLinesReaded); wcReadedStrings = NULL; } break; case MGETL_EOF: { if (numberOfLinesReaded == 0) { if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { int m = numberOfLinesReaded; int n = 1; sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, wcReadedStrings); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(17, _("%s: Memory allocation error.\n"), fname); return 0; } freeArrayOfString(wcReadedStrings, numberOfLinesReaded); wcReadedStrings = NULL; } } break; case MGETL_MEMORY_ALLOCATION_ERROR: { if (wcReadedStrings) { freeArrayOfString(wcReadedStrings, numberOfLinesReaded); wcReadedStrings = NULL; } Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } break; case MGETL_ERROR: { if (wcReadedStrings) { freeArrayOfString(wcReadedStrings, numberOfLinesReaded); wcReadedStrings = NULL; } Scierror(999, _("%s: error.\n"), fname); return 0; } break; } LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: Wrong type for input argument #%d: String or logical unit expected.\n"), fname, 1); } return 0; }
/******************************************************************************* Interface for MATIO function called Mat_Open Scilab function name : matfile_open *******************************************************************************/ int sci_matfile_open(char *fname, void* pvApiCtx) { int nbRow = 0, nbCol = 0; mat_t *matfile; int fileIndex = 0; char * filename = NULL; char * optionStr = NULL; int option = 0, var_type; int * filename_addr = NULL, * option_addr = NULL, * version_addr = NULL; char * versionStr = NULL; int version = MAT_FT_MAT5; // By default, use MAtlab 5 files SciErr sciErr; CheckRhs(1, 3); CheckLhs(1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &filename_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, filename_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (var_type == sci_strings) { getAllocatedSingleString(pvApiCtx, filename_addr, &filename); sciErr = getVarDimension(pvApiCtx, filename_addr, &nbRow, &nbCol); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (nbCol != 1) { Scierror(999, _("%s: Wrong size for first input argument: string expected.\n"), fname); freeAllocatedSingleString(filename); return FALSE; } } else { Scierror(999, _("%s: Wrong type for first input argument: string expected.\n"), fname); freeAllocatedSingleString(filename); return FALSE; } if (Rhs >= 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &option_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, option_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (var_type == sci_strings) { getAllocatedSingleString(pvApiCtx, option_addr, &optionStr); sciErr = getVarDimension(pvApiCtx, option_addr, &nbRow, &nbCol); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (nbCol != 1) { Scierror(999, _("%s: Wrong size for second input argument: string expected.\n"), fname); freeAllocatedSingleString(filename); freeAllocatedSingleString(optionStr); return FALSE; } if (strcmp(optionStr, "r") == 0) { option = MAT_ACC_RDONLY; } else if (strcmp(optionStr, "w") == 0) { option = MAT_ACC_RDWR; } else { Scierror(999, _("%s: Wrong value for second input argument: 'r' or 'w' expected.\n"), fname); freeAllocatedSingleString(filename); freeAllocatedSingleString(optionStr); return FALSE; } } else { Scierror(999, _("%s: Wrong type for second input argument: string expected.\n"), fname); freeAllocatedSingleString(filename); freeAllocatedSingleString(optionStr); return FALSE; } } else { /* Default option value */ option = MAT_ACC_RDONLY; } if (Rhs >= 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &version_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, version_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } printf("sci_strings %d %d\n", var_type, sci_strings); if (var_type == sci_strings) { getAllocatedSingleString(pvApiCtx, version_addr, &versionStr); sciErr = getVarDimension(pvApiCtx, version_addr, &nbRow, &nbCol); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 3); freeAllocatedSingleString(filename); freeAllocatedSingleString(optionStr); freeAllocatedSingleString(versionStr); return FALSE; } if (strcmp(versionStr, "7.3") == 0) { version = MAT_FT_MAT73; // Matlab 7.3 file } else { version = MAT_FT_MAT5; // Default, Matlab 5 file } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3); return 0; } } if (option == MAT_ACC_RDWR) // Write, option = "w" { /* create a Matlab 5 or 7.3 file */ matfile = Mat_CreateVer(filename, NULL, version); } else // Read, option = "r" { /* Try to open the file (as a Matlab 5 file) */ matfile = Mat_Open(filename, option); } if (matfile == NULL) /* Opening failed */ { /* Function returns -1 */ fileIndex = -1; } if (matfile != NULL) /* Opening succeed */ { /* Add the file to the manager */ matfile_manager(MATFILEMANAGER_ADDFILE, &fileIndex, &matfile); } /* Return the index */ createScalarDouble(pvApiCtx, Rhs + 1, (double)fileIndex); freeAllocatedSingleString(filename); freeAllocatedSingleString(optionStr); freeAllocatedSingleString(versionStr); LhsVar(1) = Rhs + 1; PutLhsVar(); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_libraryinfo(char *fname,unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; CheckRhs(1,1); CheckLhs(1,2); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isStringType(pvApiCtx, piAddressVarOne)) { char *libraryname = NULL; if (!isScalar(pvApiCtx, piAddressVarOne)) { Scierror(999,_("%s: Wrong size for input argument #%d: String expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &libraryname) == 0) { if (libraryname) { char *pathlibrary = getlibrarypath(libraryname); if (pathlibrary) { int sizemacrosarray = 0; char **macros = getlistmacrosfromlibrary(libraryname, &sizemacrosarray); if (macros) { int m = sizemacrosarray; int n = 1; sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, macros); if(sciErr.iErr) { freeArrayOfString(macros, sizemacrosarray); if (pathlibrary) { FREE(pathlibrary); pathlibrary = NULL; } if (libraryname) { freeAllocatedSingleString(libraryname); libraryname = NULL; } printError(&sciErr, 0); Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } } else { createEmptyMatrix(pvApiCtx, Rhs + 1); } LhsVar(1) = Rhs+1; freeArrayOfString(macros, sizemacrosarray); if (Lhs == 2) { createSingleString(pvApiCtx, Rhs + 2, pathlibrary); LhsVar(2) = Rhs+2; } if (pathlibrary) {FREE(pathlibrary);pathlibrary=NULL;} PutLhsVar(); } else { Scierror(999,_("%s: Invalid library %s.\n"),fname, libraryname); } if (libraryname) { freeAllocatedSingleString(libraryname); libraryname = NULL; } } else { Scierror(999,_("%s: Memory allocation error.\n"), fname); } } else { Scierror(999,_("%s: Memory allocation error.\n"), fname); } } else { Scierror(999,_("%s: Wrong type of input argument #%d: String expected.\n"),fname,1); } return 0; }
/*--------------------------------------------------------------------------*/ int sci_uimenu(char *fname, void *pvApiCtx) { SciErr sciErr; int nbRow = 0, nbCol = 0; int setStatus = SET_PROPERTY_SUCCEED; int inputIndex = 0, beginIndex = 0; char *propertyName = NULL; int iParentUID = 0; unsigned long GraphicHandle = 0; int parentDefined = FALSE; int iCurrentFigure = 0; int iParentType = -1; int *piParentType = &iParentType; /* Create a new menu */ GraphicHandle = getHandle(CreateUimenu()); /* If no nbInputArgument(pvApiCtx) -> current figure is the parent (Ascendant compatibility) */ if (nbInputArgument(pvApiCtx) == 0) { // Set the parent property iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle)); } /** * Odd number of input arguments * First input is the parent ID * All event inputs are property names * All odd (except first) inputs are property values */ if (nbInputArgument(pvApiCtx) % 2 == 1) { if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } else /* Get parent ID */ { int *piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr". if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); if (iParentUID != 0) { getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__ && iParentType != __GO_UIMENU__) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu"); return FALSE; } // Set the parent property callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), &hParent, sci_handles, 1, 1, "parent"); // Set the flag to avoid setting the parent two times parentDefined = TRUE; } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu"); return FALSE; } // First input parameter which is a property name beginIndex = 2; } } /** * Even number of input arguments * All odd inputs are property names * All even inputs are property values */ else { // First input parameter which is a property name beginIndex = 1; } /* Read and set all properties */ for (inputIndex = beginIndex; inputIndex < nbInputArgument(pvApiCtx); inputIndex = inputIndex + 2) { int* piAddrValue = NULL; int* piAddrProperty = NULL; int isUserDataProperty = 0; int iPropertyValuePositionIndex = inputIndex + 1; size_t posStackOrAdr = 0; /* Read property name */ if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex); return FALSE; } else { sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddrProperty); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProperty, &propertyName)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex); return 1; } if (stricmp(propertyName, "parent") == 0) { parentDefined = TRUE; } isUserDataProperty = (stricmp(propertyName, "user_data") == 0) || (stricmp(propertyName, "userdata") == 0); } sciErr = getVarAddressFromPosition(pvApiCtx, iPropertyValuePositionIndex, &piAddrValue); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedSingleString(propertyName); return 1; } if (isUserDataProperty) { nbRow = -1; nbCol = -1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, 0, 0, 0, propertyName); } else { /* Read property value */ switch (getInputArgumentType(pvApiCtx, iPropertyValuePositionIndex)) { case sci_matrix: { double* pdblValue = NULL; sciErr = getMatrixOfDouble(pvApiCtx, piAddrValue, &nbRow, &nbCol, &pdblValue); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, iPropertyValuePositionIndex); freeAllocatedSingleString(propertyName); return 1; } setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pdblValue, sci_matrix, nbRow, nbCol, propertyName); break; } case sci_strings: { char* pstValue = NULL; if (getAllocatedSingleString(pvApiCtx, piAddrValue, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, iPropertyValuePositionIndex); freeAllocatedSingleString(propertyName); return 1; } nbRow = (int)strlen(pstValue); nbCol = 1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pstValue, sci_strings, nbRow, nbCol, propertyName); freeAllocatedSingleString(pstValue); break; } case sci_handles: { long long* phValues = NULL; sciErr = getMatrixOfHandle(pvApiCtx, piAddrValue, &nbRow, &nbCol, &phValues); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, iPropertyValuePositionIndex); freeAllocatedSingleString(propertyName); return 1; } setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), phValues, sci_handles, nbRow, nbCol, propertyName); break; } case sci_list: { getListItemNumber(pvApiCtx, piAddrValue, &nbRow); nbCol = 1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, sci_list, nbRow, nbCol, propertyName); break; } default: { setStatus = SET_PROPERTY_ERROR; break; } } } if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName); freeAllocatedSingleString(propertyName); return FALSE; } freeAllocatedSingleString(propertyName); } /* If the parent is not given, the current figure is set as parent */ if (!parentDefined && (nbInputArgument(pvApiCtx) != 0)) { // Set the parent property iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle)); } /* Create return variable */ nbRow = 1; nbCol = 1; // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr". if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_TCL_UnsetVar(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; int* piAddrl2 = NULL; char* l2 = NULL; static int n1, m1; static int n2, m2; Tcl_Interp *TCLinterpreter = NULL; CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 1, 1); if (checkInputArgumentType(pvApiCtx, 1, sci_strings)) { int paramoutINT = 0; char *VarName = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, &VarName)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1); return 1; } if (!existsGlobalInterp()) { freeAllocatedSingleString(VarName); Scierror(999, _("%s: Error main TCL interpreter not initialized.\n"), fname); return 0; } if (nbInputArgument(pvApiCtx) == 2) { // two arguments given - get a pointer on the slave interpreter if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { freeAllocatedSingleString(VarName); printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { freeAllocatedSingleString(VarName); Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2); return 1; } TCLinterpreter = Tcl_GetSlave(getTclInterp(), (l2)); freeAllocatedSingleString(l2); releaseTclInterp(); if (TCLinterpreter == NULL) { freeAllocatedSingleString(VarName); Scierror(999, _("%s: No such slave interpreter.\n"), fname); return 0; } } else { freeAllocatedSingleString(VarName); Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 2); return 0; } } else { // only one argument given - use the main interpreter TCLinterpreter = getTclInterp(); } paramoutINT = (int)(Tcl_UnsetVar(TCLinterpreter, VarName, TCL_GLOBAL_ONLY) != TCL_ERROR); freeAllocatedSingleString(VarName); if (createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, paramoutINT)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else { releaseTclInterp(); Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } releaseTclInterp(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_delete(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; long long* l1 = NULL; int* piAddrl2 = NULL; char* l2 = NULL; int m1 = 0, n1 = 0, lw = 0; unsigned long hdl = 0; int nb_handles = 0, i = 0, dont_overload = 0; int iObjUID = 0; int iFigureUID = 0; int* piChildrenUID = NULL; int iChildrenCount = 0; int* childrencount = &iChildrenCount; int iHidden = 0; int *piHidden = &iHidden; int iParentUID = 0; int* piParentUID = &iParentUID; int iParentType = -1; int *piParentType = &iParentType; int iObjType = -1; int *piObjType = &iObjType; CheckInputArgument(pvApiCtx, 0, 1); CheckOutputArgument(pvApiCtx, 0, 1); if (nbInputArgument(pvApiCtx) == 0) /* Delete current object */ { iObjUID = getCurrentObject(); if (iObjUID == 0) { //No current object, we can leave AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } hdl = (unsigned long)getHandle(iObjUID); dont_overload = 1; nb_handles = 1; } else { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } switch (getInputArgumentType(pvApiCtx, 1)) { case sci_matrix: { if (isEmptyMatrix(pvApiCtx, piAddrl1)) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 1; } else { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } break; } case sci_handles: /* delete Entity given by a handle */ // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1); /* Gets the Handle passed as argument */ if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } nb_handles = m1 * n1; if (nbInputArgument(pvApiCtx) == 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) /* Gets the command name */ { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2); return 1; } } hdl = (unsigned long) * (l1); /* Puts the value of the Handle to hdl */ break; case sci_strings: /* delete("all") */ CheckInputArgument(pvApiCtx, 1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1); return 1; } if (strcmp((l2), "all") == 0) { int i = 0; int iFigureNumber = sciGetNbFigure(); if (iFigureNumber == 0) { //no graphic windows, we can leave AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } iFigureUID = getCurrentFigure(); getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&childrencount); getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID); for (i = 0; i < childrencount[0]; ++i) { getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden); if (iHidden == 0) { deleteGraphicObject(piChildrenUID[i]); } } /* * Clone a new Axes object using the Axes model which is then * attached to the 'cleaned' Figure. */ cloneAxesModel(iFigureUID); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 1, "all"); return 0; } break; default: // Overload lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); C2F(overload) (&lw, "delete", 6); return 0; } } for (i = 0; i < nb_handles; i++) { int iTemp = 0; if (nbInputArgument(pvApiCtx) != 0) { hdl = (unsigned long) * (l1 + i); /* Puts the value of the Handle to hdl */ } iObjUID = getObjectFromHandle(hdl); if (iObjUID == 0) { Scierror(999, _("%s: The handle is not valid.\n"), fname); return 0; } if (isFigureModel(iObjUID) || isAxesModel(iObjUID)) { Scierror(999, _("This object cannot be deleted.\n")); return 0; } /* Object type */ getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **)&piObjType); if (iObjType == __GO_AXES__) { /* Parent object */ iParentUID = getParentObject(iObjUID); /* Parent type */ getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); } if (iObjType == __GO_LABEL__) { Scierror(999, _("A Label object cannot be deleted.\n")); return 0; } //bug #11485 : duplicate pobjUID before delete it. iTemp = iObjUID; deleteGraphicObject(iObjUID); /* ** All figure must have at least one axe child. ** If the last one is removed, add a new default one. */ if (iObjType == __GO_AXES__ && iParentType == __GO_FIGURE__) { int iChild = 0; int iChildCount = 0; int *piChildCount = &iChildCount; char **pstChildren = NULL; int iChildType = -1; int *piChildType = &iChildType; int iAxesFound = 0; int iDefaultAxes = -1; int *piDefaultAxes = &iDefaultAxes; getGraphicObjectProperty(iParentUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildCount); getGraphicObjectProperty(iParentUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID); getGraphicObjectProperty(iParentUID, __GO_DEFAULT_AXES__, jni_bool, (void **)&piDefaultAxes); for (iChild = 0; iChild < iChildCount; iChild++) { getGraphicObjectProperty(piChildrenUID[iChild], __GO_TYPE__, jni_int, (void **)&piChildType); if (iChildType == __GO_AXES__) { if (getCurrentSubWin() == iTemp) // Current axes has been deleted { setCurrentSubWin(piChildrenUID[iChild]); } iAxesFound = 1; break; } } if (!iAxesFound && iDefaultAxes != 0) { /* * Clone a new Axes object using the Axes model which is then * attached to the newly created Figure. */ cloneAxesModel(iParentUID); } } } if (!dont_overload) { // Overload lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); C2F(overload) (&lw, "delete", 6); } else { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); } if (l2) { freeAllocatedSingleString(l2); } return 0; }
// fann_set_error_log Change where errors are logged to. int sci_fann_set_error_log(char * fname) { int * pi_name_addr = NULL; int res; char * Name = NULL; FILE * log_file = NULL; struct fann_error * result_error = (struct fann_error *)MALLOC(1*sizeof(struct fann_error)); SciErr _sciErr; // Initialisation of the structure result_error->errstr = NULL; result_error->errno_f = FANN_E_NO_ERROR; result_error->error_log = fann_default_error_log; if (Rhs==0) { fann_set_error_log(result_error,NULL); fann_reset_errno(result_error); fann_reset_errstr(result_error); res = createScilabFannErrorStructFromCFannErrorStruct(result_error,NULL,Rhs + 1); LhsVar(1) = Rhs + 1; } else { if ((Rhs!=1)&&(Lhs!=1)) { Scierror(999,"%s: usage log_out = %(filename).\n", fname, fname); return 0; } _sciErr = getVarAddressFromPosition(pvApiCtx, 1, &pi_name_addr); if (_sciErr.iErr) { printError(&_sciErr, 0); return 0; } getAllocatedSingleString(pvApiCtx, pi_name_addr, &Name); log_file = fopen(Name,"w+"); if (log_file == NULL) { Scierror(999,"%s: unable to open the file %s for writing.\n",fname,Name); freeAllocatedSingleString(Name); return 0; } freeAllocatedSingleString(Name); fann_set_error_log(result_error,log_file); fann_reset_errno(result_error); fann_reset_errstr(result_error); res = createScilabFannErrorStructFromCFannErrorStruct(result_error, log_file, Rhs + 1); LhsVar(1) = Rhs + 1; } if (result_error==NULL) { Scierror(999,"%s: unable to create a fann_error structure\n",fname); return 0; } return 0; }
/*--------------------------------------------------------------------------*/ int get_logflags_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** logFlags) { int kopt = 0; int* piAddr = NULL; int iLog = 0; char* pstLog = NULL; if (pos < FirstOpt(_pvCtx)) //input argument */ { //no idea of the real goal of this, how input var can have type == 0 Oo if (getInputArgumentType(_pvCtx, pos) == 0) { *logFlags = getDefLogFlags(); return 1; } getVarAddressFromPosition(_pvCtx, pos, &piAddr); } else if ((kopt = FindOpt(_pvCtx, "logflag", opts)) >= 0)//optional argument { piAddr = opts[kopt].piAddr; } else { //take default value *logFlags = getDefLogFlags(); return 1; } getAllocatedSingleString(_pvCtx, piAddr, &pstLog); iLog = (int)strlen(pstLog); if (iLog != 2 && iLog != 3) { Scierror(999, "%s: Wrong size for input argument #%d: %d or %d expected\n", fname, pos, 2, 3); return 0; } if (iLog == 2) { if ((pstLog[0] != 'l' && pstLog[0] != 'n') || (pstLog[1] != 'l' && pstLog[1] != 'n')) { //Err = pos; SciError(116); return 0; } logFlagsCpy[0] = 'g'; logFlagsCpy[1] = pstLog[0]; logFlagsCpy[2] = pstLog[1]; *logFlags = logFlagsCpy; } else //iLog == 3 { if (((pstLog[0] != 'g') && (pstLog[0] != 'e') && (pstLog[0] != 'o')) || (pstLog[1] != 'l' && pstLog[1] != 'n') || (pstLog[2] != 'l' && pstLog[2] != 'n')) { //Err = pos; SciError(116); return 0; } *logFlags = pstLog; } return 1; }
int ScilabGateway::wrapAsRef(char * fname, const int envId, void * pvApiCtx) { SciErr err; int * tmpvar = 0; int * addr = 0; char * varName = 0; int idObj; if (Rhs == 0) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong number of arguments : more than 1 argument expected.")); } ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccurred(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); CheckOutputArgument(pvApiCtx, Rhs, Rhs); tmpvar = new int[Rhs + 1]; *tmpvar = 0; for (int i = 1; i < Rhs + 1; i++) { err = getVarAddressFromPosition(pvApiCtx, i, &addr); if (err.iErr) { ScilabObjects::removeTemporaryVars(envId, tmpvar); delete[] tmpvar; throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (!isScalar(pvApiCtx, addr) || !isStringType(pvApiCtx, addr)) { ScilabObjects::removeTemporaryVars(envId, tmpvar); delete[] tmpvar; throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Can only wrap as a reference to a named variable")); } if (getAllocatedSingleString(pvApiCtx, addr, &varName)) { ScilabObjects::removeTemporaryVars(envId, tmpvar); delete[] tmpvar; throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } err = getVarAddressFromName(pvApiCtx, varName, &addr); freeAllocatedSingleString(varName); if (err.iErr) { ScilabObjects::removeTemporaryVars(envId, tmpvar); delete[] tmpvar; throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } try { idObj = ScilabObjects::getArgumentId(addr, tmpvar, true, false, envId, pvApiCtx); } catch (ScilabAbstractEnvironmentException & /*e*/) { delete[] tmpvar; throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot wrap argument %d."), i); } try { ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, idObj, envId, pvApiCtx); } catch (ScilabAbstractEnvironmentException & /*e*/) { ScilabObjects::removeTemporaryVars(envId, tmpvar); delete[] tmpvar; throw; } LhsVar(i) = Rhs + i; } // We don't remove tmpvar since it contains id which are put on rhs delete[] tmpvar; PutLhsVar(); return 0; }