// ============================================================================= int csv_isEmpty(void* _pvCtx, int _iVar) { SciErr sciErr; int *piAddressVar = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar); if (sciErr.iErr) { printError(&sciErr, 0); if (sciErr.iErr) { return 0; } } return isEmptyMatrix(pvApiCtx, piAddressVar); }
/*--------------------------------------------------------------------------*/ 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; }
// ============================================================================= char *csv_getArgumentAsStringWithEmptyManagement(void* _pvCtx, int _iVar, const char *fname, const char *defaultValue, int *iErr) { SciErr sciErr; char *returnedValue = NULL; int *piAddressVar = NULL; int iType = 0; int m = 0, n = 0; sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar); if (sciErr.iErr) { printError(&sciErr, 0); *iErr = sciErr.iErr; return NULL; } sciErr = getVarType(pvApiCtx, piAddressVar, &iType); if (sciErr.iErr) { printError(&sciErr, 0); *iErr = sciErr.iErr; return NULL; } if (iType != sci_strings) { if (isEmptyMatrix(pvApiCtx, piAddressVar)) { /* [] equals default value */ if (defaultValue) { *iErr = 0; returnedValue = strdup(defaultValue); } else { *iErr = 0; returnedValue = NULL; } } else { *iErr = API_ERROR_INVALID_TYPE; Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, _iVar); return NULL; } } else { *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; }
int hypermatIntExample(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddr = NULL; int iType = 0; int iRet = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (isEmptyMatrix(pvApiCtx, piAddr)) { iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1); if (iRet) { return iRet; } AssignOutputVariable(pvApiCtx, 1) = 0; } else if (isHypermatType(pvApiCtx, piAddr)) { int * dims = NULL; int ndims; void * data = NULL; int htype = 0; int precision; sciErr = getHypermatType(pvApiCtx, piAddr, &htype); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } if (htype == sci_ints) { sciErr = getHypermatOfIntegerPrecision(pvApiCtx, piAddr, &precision); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } switch (precision) { case SCI_INT8: sciErr = getHypermatOfInteger8(pvApiCtx, piAddr, &dims, &ndims, (char*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const char*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_UINT8: sciErr = getHypermatOfUnsignedInteger8(pvApiCtx, piAddr, &dims, &ndims, (unsigned char*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfUnsignedInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned char*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_INT16: sciErr = getHypermatOfInteger16(pvApiCtx, piAddr, &dims, &ndims, (short*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const short*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_UINT16: sciErr = getHypermatOfUnsignedInteger16(pvApiCtx, piAddr, &dims, &ndims, (unsigned short*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfUnsignedInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned short*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_INT32: sciErr = getHypermatOfInteger32(pvApiCtx, piAddr, &dims, &ndims, (int*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const int*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_UINT32: sciErr = getHypermatOfUnsignedInteger32(pvApiCtx, piAddr, &dims, &ndims, (unsigned int*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfUnsignedInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned int*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_INT64: sciErr = getHypermatOfInteger64(pvApiCtx, piAddr, &dims, &ndims, (long long*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfInteger64(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const long long*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; case SCI_UINT64: sciErr = getHypermatOfUnsignedInteger64(pvApiCtx, piAddr, &dims, &ndims, (unsigned long long*)&data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfUnsignedInteger64(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned long long*)data); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } break; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: An integer expected.\n"), fname, 1); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } return 0; }
/*--------------------------------------------------------------------------*/ int sci_dec2base(char *fname, unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; int *piAddressVarTwo = NULL; int m = 0, n = 0; double *dValues = NULL; char **convertedValues = NULL; unsigned int iBaseUsed = 0; double dBaseUsed = 0.; unsigned int nbDigits = 0; error_convertbase err = ERROR_CONVERTBASE_NOK; CheckRhs(2, 3); CheckLhs(1, 1); if (Rhs == 3) { double dParamThree = 0.; unsigned int iParamThree = 0; int *piAddressVarThree = NULL; 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; } if (!isDoubleType(pvApiCtx, piAddressVarThree)) { Scierror(999,_("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 3); return 0; } if (!isScalar(pvApiCtx, piAddressVarThree)) { Scierror(999,_("%s: Wrong size for input argument #%d: A scalar integer value expected.\n"), fname, 3); return 0; } if (getScalarDouble(pvApiCtx, piAddressVarThree, &dParamThree) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } iParamThree = (unsigned int)dParamThree; if (dParamThree != (double)iParamThree) { Scierror(999,_("%s: Wrong value for input argument #%d: A integer value expected.\n"), fname, 3); return 0; } nbDigits = iParamThree; } 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)) { Scierror(999,_("%s: Wrong type for input argument #%d: A integer value expected.\n"), fname, 2); return 0; } if (!isScalar(pvApiCtx, piAddressVarTwo)) { Scierror(999,_("%s: Wrong size for input argument #%d.\n"), fname, 2); return 0; } if (getScalarDouble(pvApiCtx, piAddressVarTwo, &dBaseUsed) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } iBaseUsed = (unsigned int)dBaseUsed; if (dBaseUsed != (double)iBaseUsed) { Scierror(999, _("%s: Wrong value for input argument #%d: A integer value expected.\n"), fname, 2); return 0; } if ((iBaseUsed < 2) && (iBaseUsed > 36)) { Scierror(999, _("%s: Wrong value for input argument #%d: Must be between %d and %d."), fname, 2, 2, 36); 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 (isEmptyMatrix(pvApiCtx, piAddressVarOne)) { if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } else { LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; } } if (!isDoubleType(pvApiCtx, piAddressVarOne)) { Scierror(999,_("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), fname, 1); return 0; } if (isVarComplex(pvApiCtx, piAddressVarOne)) { Scierror(999,_("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), fname, 1); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m, &n , &dValues); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } convertedValues = (char **)MALLOC(sizeof(char*) * (m *n)); if (convertedValues == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } convertedValues = convertMatrixOfDec2Base(dValues, m * n, iBaseUsed, nbDigits, &err); if ((err != ERROR_CONVERTBASE_OK) || (convertedValues == NULL)) { freeArrayOfString(convertedValues, m * n); convertedValues = NULL; switch (err) { case ERROR_CONVERTBASE_NOT_INTEGER_VALUE: Scierror(999, _("%s: Wrong value for input argument #%d: Must be between 0 and 2^52.\n"), fname, 1); return 0; case ERROR_CONVERTBASE_NOT_IN_INTERVAL: Scierror(999,_("%s: Wrong value(s) for input argument #%d: A matrix of positive integer values expected.\n"), fname, 1); return 0; case ERROR_CONVERTBASE_ALLOCATION: Scierror(999, _("%s: No more memory.\n"), fname); return 0; case ERROR_CONVERTBASE_NOK: default: Scierror(999, _("%s: Wrong value for input argument #%d: cannot convert value(s).\n"), fname, 1); return 0; } } sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, convertedValues); freeArrayOfString(convertedValues, m * n); convertedValues = NULL; if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_archive_compress(char *fname, unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; char *pStVarOne = NULL; char *pStVarOneExpanded = NULL; int *piAddressVarTwo = NULL; char **pStVarTwo = NULL; int m1 = 0; int n1 = 0; int i = 0; int *piAddressVarThree = NULL; char *pStVarThree = NULL; char **file_list = NULL; /* Check Input & Output parameters */ CheckRhs(3, 3); CheckLhs(1, 2); int result = 0; int *error = 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) == 0 || isScalar(pvApiCtx, piAddressVarOne) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isDoubleType(pvApiCtx, piAddressVarTwo)) { if (isEmptyMatrix(pvApiCtx, piAddressVarTwo)) { if (createEmptyMatrix(pvApiCtx, Rhs + 2)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; } if (isStringType(pvApiCtx, piAddressVarTwo) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 2); return 0; } if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarTwo, &m1, &n1, &pStVarTwo)) { freeAllocatedMatrixOfString(m1, n1, pStVarTwo); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 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; } if (isStringType(pvApiCtx, piAddressVarThree) == 0 || isScalar(pvApiCtx, piAddressVarThree) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &pStVarOne)) { if (pStVarOne) { freeAllocatedSingleWideString(pStVarOne); } Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &pStVarThree)) { if (pStVarThree) { freeAllocatedSingleWideString(pStVarThree); } freeAllocatedSingleString(pStVarOne); freeAllocatedSingleString(pStVarTwo); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } int size = 0; while(i < (m1*n1)) { size++; if(file_list!=NULL) { file_list = (char**)REALLOC(file_list,sizeof(char*)*(size)); } else { file_list = (char**)MALLOC(sizeof(char*)*(size)); } file_list[size-1] = (char*)MALLOC(sizeof(char)*512); strcpy(file_list[size-1],expandPathVariable(pStVarTwo[i])); i++; } i = 0; if(strlen(pStVarThree)>2) { Scierror(999, _("%s: Sorry unrecognised format type.\n"), fname); return 0; } while(i<strlen(pStVarThree)) { if(pStVarThree[i]!='Z' && pStVarThree[i]!='j' && pStVarThree[i]!='y' && pStVarThree[i]!='z') { Scierror(999, _("%s: Sorry unrecognised format type.\n"), fname); return 0; } i++; } result = archive_compress(pStVarOne,file_list,size,pStVarThree,&error); if(error == 1) { Scierror(999, _("%s: Sorry the file could not be opened.\n"), fname); return 0; } if(error == 2) { Scierror(999, _("%s: Sorry the file header could not be read\n"), fname); return 0; } if(error == 3) { Scierror(999, _("%s: Sorry the file header could not be written.\n"), fname); return 0; } freeAllocatedSingleString(pStVarOne); freeAllocatedSingleString(pStVarTwo); createScalarInteger32(pvApiCtx, Rhs + 1, result); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_getdate(char *fname, unsigned long fname_len) { SciErr sciErr; Rhs = Max(Rhs, 0); CheckRhs(0, 1) ; CheckLhs(0, 1) ; if (Rhs == 0) { int iErr = 0; double *dDate = getCurrentDateAsDoubleVector(&iErr); if (iErr) { Scierror(999, _("%s: An error occurred.\n"), fname); if (dDate) { FREE(dDate); dDate = NULL; } return 0; } if (dDate) { sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, NB_ELEMNT_ARRAY_GETDATE, dDate); FREE(dDate); dDate = NULL; if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else /* Rhs == 1 */ { int *piAddressVarOne = NULL; 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)) { if (isScalar(pvApiCtx, piAddressVarOne)) { double dTime = 0.; char *pStr = NULL; if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &pStr) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } if (strcmp(pStr, "s") != 0) { freeAllocatedSingleString(pStr); pStr = NULL; Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 1, "s"); return 0; } freeAllocatedSingleString(pStr); pStr = NULL; dTime = getCurrentDateAsUnixTimeConvention(); if (createScalarDouble(pvApiCtx, Rhs + 1, dTime) != 0) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1); return 0; } } else if (isDoubleType(pvApiCtx, piAddressVarOne)) { if (isEmptyMatrix(pvApiCtx, piAddressVarOne)) { if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else if (!isVarComplex(pvApiCtx, piAddressVarOne)) { int iErr = 0; double *dValues = NULL; double *dResults = NULL; int m = 0, n = 0; int nbElements = 0; int i = 0; sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m, &n, &dValues); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } nbElements = m * n; for (i = 0; i < nbElements; i++) { if (dValues[i] < 0.) { Scierror(999, _("%s: Wrong value for input argument #%d: Must be > %d.\n"), fname, 1, 0); return 0; } } dResults = getConvertedDateAsMatrixOfDouble(dValues, nbElements, &iErr); if (iErr == 2) { FREE(dResults); Scierror(999, _("%s: An error occurred.\n"), fname); return 0; } if (dResults == NULL) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, nbElements, NB_ELEMNT_ARRAY_GETDATE, dResults); FREE(dResults); dResults = NULL; if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Scierror(999, _("%s: Wrong value for input argument #%d: A real expected.\n"), fname, 1); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: Integer or '%s' expected.\n"), fname, 1, "s"); return 0; } } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
int hypermatExample(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddr = NULL; int iType = 0; int iRet = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (isEmptyMatrix(pvApiCtx, piAddr)) { iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1); if (iRet) { return iRet; } AssignOutputVariable(pvApiCtx, 1) = 0; } else if (isHypermatType(pvApiCtx, piAddr)) { int * dims = NULL; int ndims; double* pdblReal = NULL; double* pdblImg = NULL; if (isHypermatComplex(pvApiCtx, piAddr)) { sciErr = getComplexHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal, &pdblImg); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createComplexHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal, pdblImg); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } } else { sciErr = getHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } return 0; }