/** * This function returns the rank of a process within the specified communicator. */ int sci_mpi_comm_rank(char *fname, void* pvApiCtx) { int comm_rank = -1; CheckInputArgument(pvApiCtx, 0, 1); // Check the parameters of the function ... Here 0 or 1 CheckOutputArgument(pvApiCtx, 1, 1); // The output of the function (1 parameter) // return the communicator from optional argument "comm" // if no optional "comm" is given, return MPI_COMM_WORLD MPI_Comm comm = getOptionalComm(pvApiCtx); if (comm == NULL) { Scierror(999, _("%s: Wrong type for input argument #%s: An MPI communicator expected.\n"), fname, "comm"); return 0; } if (comm != MPI_COMM_NULL) { MPI_Comm_rank(comm, &comm_rank); } if (createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, (double)comm_rank)) { Scierror(999, _("%s: Unable to create variable.\n"), fname); return 0; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_displayhistory(char *fname, unsigned long fname_len) { displayScilabHistory(); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
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; }
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_getlookandfeel(char *fname, void* pvApiCtx) { CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0; try { lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM()); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str()); return 1; } if (lnf) { static int n1 = 0, m1 = 0; char *look = lnf->getCurrentLookAndFeel(); if (look) { m1 = (int)strlen(look); n1 = 1; if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, look)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (look) { delete[]look; look = NULL; } delete lnf; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else { delete lnf; Scierror(999, _("%s: An error occurred: %s.\n"), fname, _("Impossible to get current look and feel")); return 1; } } else { Scierror(999, _("%s: No more memory.\n"), fname); return 1; } return 0; }
/*--------------------------------------------------------------------------*/ int sci_TCL_DoOneEvent (char *fname, void* pvApiCtx) { CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); // wait for events and invoke event handlers Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_fftw_forget_wisdom(char *fname, void* pvApiCtx) { CheckInputArgument(pvApiCtx, 0, 0); FreeFFTWPlan(getSci_Backward_Plan()); FreeFFTWPlan(getSci_Forward_Plan()); call_fftw_forget_wisdom(); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
int sci_sym_getRowActivity(char *fname){ //error management variable SciErr sciErr; int iRet; //data declarations int numConstr; double *rowAct; //ensure that environment is active if(global_sym_env==NULL){ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n"); return 1; } //code to check arguments and get them CheckInputArgument(pvApiCtx,0,0) ; CheckOutputArgument(pvApiCtx,1,1) ; //code to process input iRet=sym_get_num_rows(global_sym_env,&numConstr); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has the problem been solved? Is the problem feasible?\n"); return 1; } rowAct=new double[numConstr]; iRet=sym_get_row_activity(global_sym_env,rowAct); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has the problem been solved? Is the problem feasible?\n"); delete[] rowAct; return 1; } //code to give output sciErr=createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,numConstr,1,rowAct); if (sciErr.iErr) { printError(&sciErr, 0); delete[] rowAct; return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1; ReturnArguments(pvApiCtx); delete[] rowAct; return 0; }
int sci_mpi_init(char *fname, void* pvApiCtx) { int flag; CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); mpi_init_internal(); MPI_Initialized(&flag); if (!flag) { /* MPI Not yet initialized */ MPI_Init(NULL, NULL); MPI_Comm_create_errhandler(MPIErrHandler, &errhdl); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int C2F(sci_getscilabmode)(char *fname, unsigned long fname_len) { int n1 = 0, m1 = 0; char *output = NULL ; int iRet = 0; SciErr sciErr; CheckInputArgument(pvApiCtx, 0, 0) ; CheckOutputArgument(pvApiCtx, 1, 1) ; switch (getScilabMode()) { case SCILAB_API: default : output = strdup("API"); break; case SCILAB_STD: output = strdup("STD"); break; case SCILAB_NW: output = strdup("NW"); break; case SCILAB_NWNI: output = strdup("NWNI"); break; } /* Create the string matrix as return of the function */ iRet = createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output); free(output); // Data have been copied into Scilab memory if (iRet) { freeAllocatedSingleString(output); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
int sci_mpi_finalize(char *fname, void* pvApiCtx) { int iRet = 0; CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); mpi_finalize_internal(); iRet = MPI_Finalize(); if (iRet != MPI_SUCCESS) { char error_string[MPI_MAX_ERROR_STRING]; int length_of_error_string; MPI_Error_string(iRet, error_string, &length_of_error_string); Scierror(999, _("%s: Could not finalize the MPI instance: %s\n"), fname, error_string); return 0; } // TODO: catch les erreurs AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
//This function is for loading a mps file to symphony int sci_sym_set_defaults(char *fname, unsigned long fname_len){ double status=1.0;//assume error status int *piAddressVarOne = NULL;//pointer used to access argument of the function int output=0;//out parameter for the setting of default values function CheckInputArgument(pvApiCtx, 0, 0);//Check we no argument as input or not CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not //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_defaults(global_sym_env);//setting all environment variables and parameters in this symphony environment passed to their default values if(output==FUNCTION_TERMINATED_ABNORMALLY) { status=1.0;//function did not invoke successfully sciprint("Function terminated abnormally,didnot execute"); } else if(output==FUNCTION_TERMINATED_NORMALLY) { status=0.0;//no error in executing the function sciprint("Function executed successfully"); } } 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_drawlater(char * fname, void* pvApiCtx) { int iFalse = (int)FALSE; int iParentFigureUID = 0; int* piParentFigureUID = &iParentFigureUID; int iSubwinUID = 0; int iCurChildUID = 0; int iType = -1; int *piType = &iType; CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 0, 1); if (nbInputArgument(pvApiCtx) <= 0) { iSubwinUID = getOrCreateDefaultSubwin(); if (iSubwinUID != 0) { // Look for top level figure iCurChildUID = iSubwinUID; do { iParentFigureUID = getParentObject(iCurChildUID); getGraphicObjectProperty(iParentFigureUID, __GO_TYPE__, jni_int, (void **)&piType); iCurChildUID = iParentFigureUID; } while (iParentFigureUID != 0 && iType != __GO_FIGURE__); if (iParentFigureUID != 0) { setGraphicObjectProperty(iParentFigureUID, __GO_IMMEDIATE_DRAWING__, &iFalse, jni_bool, 1); } } } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ static int xlfont_no_rhs(char * fname) { SciErr sciErr; int m1 = 0, n1 = 0; int nbElements = 0; char **fontsname = getInstalledFontsName(&nbElements); m1 = 1; n1 = nbElements; sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, (const char * const*)fontsname); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } freeArrayOfString(fontsname, nbElements); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_fftwlibraryisloaded(char *fname, void* pvApiCtx) { int iErr; if ( IsLoadedFFTW() ) { iErr = createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1); // true } else { iErr = createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 0); // false } if (iErr) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return iErr; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); 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_plot2d(char* fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; double* lt = NULL; int iTypel1 = 0; int iTypel2 = 0; int lw = 0; int m1 = 0, n1 = 0, m2 = 0, n2 = 0; int test = 0, i = 0, j = 0, iskip = 0; int frame_def = 8; int *frame = &frame_def; int axes_def = 1; int *axes = &axes_def; /* F.Leray 18.05.04 : log. case test*/ int size_x = 0, size_y = 0; char dataflag = 0; char* logFlags = NULL; int* style = NULL; double* rect = NULL; char* strf = NULL; char* legend = NULL; int* nax = NULL; BOOL flagNax = FALSE; char strfl[4]; BOOL freeStrf = FALSE; rhs_opts opts[] = { { -1, "axesflag", -1, 0, 0, NULL}, { -1, "frameflag", -1, 0, 0, NULL}, { -1, "leg", -1, 0, 0, NULL}, { -1, "logflag", -1, 0, 0, NULL}, { -1, "nax", -1, 0, 0, NULL}, { -1, "rect", -1, 0, 0, NULL}, { -1, "strf", -1, 0, 0, NULL}, { -1, "style", -1, 0, 0, NULL}, { -1, NULL, -1, 0, 0, NULL} }; if (nbInputArgument(pvApiCtx) == 0) { sci_demo(fname, pvApiCtx); return 0; } CheckInputArgument(pvApiCtx, 1, 9); iskip = 0; if (getOptionals(pvApiCtx, fname, opts) == 0) { ReturnArguments(pvApiCtx); return 0; } if (checkInputArgumentType(pvApiCtx, 1, sci_strings)) { /* logflags */ GetLogflags(pvApiCtx, fname, 1, opts, &logFlags); iskip = 1; } if (FirstOpt(pvApiCtx) == 2 + iskip) /** plot2d([loglags,] y, <opt_args>); **/ { sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddrl2, &iTypel2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // the argument can be a matrix of doubles or other // If it is not a matrix of doubles, call overload if (iTypel2 == sci_matrix) { // Retrieve a matrix of double at position 1 + iskip. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1 + iskip); return 1; } } else { OverLoad(1); return 0; } if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1; } m1 = m2; n1 = n2; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (i = 0; i < m2 ; ++i) { for (j = 0 ; j < n2 ; ++j) { *(l1 + i + m2 * j) = (double) i + 1; } } } else if (FirstOpt(pvApiCtx) >= 3 + iskip) /** plot2d([loglags,] x, y[, style [,...]]); **/ { /* x */ sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddrl1, &iTypel1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // x can be a matrix of doubles or other // If x is not a matrix of doubles, call overload if (iTypel1 == sci_matrix) { // Retrieve a matrix of double at position 1 + iskip. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1 + iskip); return 1; } } else { OverLoad(1); return 0; } /* y */ sciErr = getVarAddressFromPosition(pvApiCtx, 2 + iskip, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddrl2, &iTypel2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // y can be a matrix of doubles or other // If y is not a matrix of doubles, call overload if (iTypel2 == sci_matrix) { // Retrieve a matrix of double at position 1 + iskip. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2 + iskip); return 1; } } else { OverLoad(2); return 0; } test = (m1 * n1 == 0) || ((m1 == 1 || n1 == 1) && (m2 == 1 || n2 == 1) && (m1 * n1 == m2 * n2)) || ((m1 == m2) && (n1 == n2)) || ((m1 == 1 && n1 == m2) || (n1 == 1 && m1 == m2)); //CheckDimProp if (!test) { Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname); return 1; } if (m1 * n1 == 0) { /* default x=1:n */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, <); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1; } for (i = 0; i < m2 ; ++i) { for (j = 0 ; j < n2 ; ++j) { *(lt + i + m2 * j) = (double) i + 1; } } m1 = m2; n1 = n2; l1 = lt; } else if ((m1 == 1 || n1 == 1) && (m2 != 1 && n2 != 1)) { /* a single x vector for mutiple columns for y */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, <); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (i = 0; i < m2 ; ++i) { for (j = 0 ; j < n2 ; ++j) { *(lt + i + m2 * j) = *(l1 + i); } } m1 = m2; n1 = n2; l1 = lt; } else if ((m1 == 1 && n1 == 1) && (n2 != 1)) { /* a single y row vector for a single x */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n2, <); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (j = 0 ; j < n2 ; ++j) { lt[j] = *l1; } n1 = n2; l1 = lt; } else { if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1; } if (m1 == 1 && n1 > 1) { m1 = n1; n1 = 1; } } } else { Scierror(999, _("%s: Wrong number of mandatory input arguments. At least %d expected.\n"), fname, 1); return 0; } if (n1 == -1 || n2 == -1 || m1 == -1 || m2 == -1) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); /* @TODO : detail error */ return 0; } sciGetStyle(pvApiCtx, fname, 3 + iskip, n1, opts, &style); GetStrf(pvApiCtx, fname, 4 + iskip, opts, &strf); GetLegend(pvApiCtx, fname, 5 + iskip, opts, &legend); GetRect(pvApiCtx, fname, 6 + iskip, opts, &rect); GetNax(pvApiCtx, 7 + iskip, opts, &nax, &flagNax); if (iskip == 0) { GetLogflags(pvApiCtx, fname, 8, opts, &logFlags); } freeStrf = !isDefStrf(strf); // Check strf [0-1][0-8][0-5] if (!isDefStrf(strf) && (strlen(strf) != 3 || strf[0] < '0' || strf[0] > '1' || strf[1] < '0' || strf[1] > '8' || strf[2] < '0' || strf[2] > '5')) { Scierror(999, _("%s: Wrong value for strf option: %s.\n"), fname, strf); if (freeStrf) { freeAllocatedSingleString(strf); } return -1; } if (isDefStrf(strf)) { strcpy(strfl, DEFSTRFN); strf = strfl; if (!isDefRect(rect)) { strfl[1] = '7'; } if (!isDefLegend(legend)) { strfl[0] = '1'; } GetOptionalIntArg(pvApiCtx, fname, 9, "frameflag", &frame, 1, opts); if (frame != &frame_def) { if (*frame >= 0 && *frame <= 8) { strfl[1] = (char)(*frame + 48); } else { Scierror(999, _("%s: Wrong value for frameflag option.\n"), fname); if (freeStrf) { freeAllocatedSingleString(strf); } return -1; } } GetOptionalIntArg(pvApiCtx, fname, 9, "axesflag", &axes, 1, opts); if (axes != &axes_def) { if ((*axes >= 0 && *axes <= 5) || *axes == 9) { strfl[2] = (char)(*axes + 48); } else { Scierror(999, _("%s: Wrong value for axesflag option.\n"), fname); if (freeStrf) { freeAllocatedSingleString(strf); } return -1; } } } /* Make a test on log. mode : available or not depending on the bounds set by Rect arg. or xmin/xmax : Rect case : - if the min bound is strictly posivite, we can use log. mode - if not, send error message x/y min/max case: - we find the first strictly positive min bound in Plo2dn.c ?? */ switch (strf[1]) { case '0': /* no computation, the plot use the previous (or default) scale */ break; case '1' : case '3' : case '5' : case '7': /* based on Rect arg */ if (rect[0] > rect[2] || rect[1] > rect[3]) { if (freeStrf) { freeAllocatedSingleString(strf); } Scierror(999, _("%s: Impossible status min > max in x or y rect data.\n"), fname); return -1; } if (rect[0] <= 0. && logFlags[1] == 'l') /* xmin */ { if (freeStrf) { freeAllocatedSingleString(strf); } Scierror(999, _("%s: Bounds on x axis must be strictly positive to use logarithmic mode.\n"), fname); return -1; } if (rect[1] <= 0. && logFlags[2] == 'l') /* ymin */ { if (freeStrf) { freeAllocatedSingleString(strf); } Scierror(999, _("%s: Bounds on y axis must be strictly positive to use logarithmic mode.\n"), fname); return -1; } break; case '2' : case '4' : case '6' : case '8': case '9': /* computed from the x/y min/max */ if ((int)strlen(logFlags) < 1) { dataflag = 'g'; } else { dataflag = logFlags[0]; } switch (dataflag) { case 'e' : size_x = (m1 != 0) ? 2 : 0; break; case 'o' : size_x = m1; break; case 'g' : default : size_x = (n1 * m1); break; } if (size_x != 0) { if (logFlags[1] == 'l' && sciFindStPosMin((l1), size_x) <= 0.0) { if (freeStrf) { freeAllocatedSingleString(strf); } Scierror(999, _("%s: At least one x data must be strictly positive to compute the bounds and use logarithmic mode.\n"), fname); return -1; } } size_y = (n1 * m1); if (size_y != 0) { if (logFlags[2] == 'l' && sciFindStPosMin((l2), size_y) <= 0.0) { if (freeStrf) { freeAllocatedSingleString(strf); } Scierror(999, _("%s: At least one y data must be strictly positive to compute the bounds and use logarithmic mode\n"), fname); return -1; } } break; } // open a figure if none already exists getOrCreateDefaultSubwin(); Objplot2d (1, logFlags, (l1), (l2), &n1, &m1, style, strf, legend, rect, nax, flagNax); // Allocated by sciGetStyle (get_style_arg function in GetCommandArg.c) FREE(style); if (freeStrf) { freeAllocatedSingleString(strf); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
int sci_umf_lufact(char* fname, void* pvApiCtx) { SciErr sciErr; int stat = 0; SciSparse AA; CcsSparse A; int mA = 0; // rows int nA = 0; // cols int iNbItem = 0; int* piNbItemRow = NULL; int* piColPos = NULL; double* pdblSpReal = NULL; double* pdblSpImg = NULL; /* umfpack stuff */ double* Control = NULL; double* Info = NULL; void* Symbolic = NULL; void* Numeric = NULL; int* piAddr1 = NULL; int iComplex = 0; int iType1 = 0; /* Check numbers of input/output arguments */ CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 1, 1); /* get A the sparse matrix to factorize */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } /* check if the first argument is a sparse matrix */ sciErr = getVarType(pvApiCtx, piAddr1, &iType1); if (sciErr.iErr || iType1 != sci_sparse) { printError(&sciErr, 0); Scierror(999, _("%s: Wrong type for input argument #%d: A sparse matrix expected.\n"), fname, 1); return 1; } if (isVarComplex(pvApiCtx, piAddr1)) { iComplex = 1; sciErr = getComplexSparseMatrix(pvApiCtx, piAddr1, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal, &pdblSpImg); } else { sciErr = getSparseMatrix(pvApiCtx, piAddr1, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal); } if (sciErr.iErr) { FREE(piNbItemRow); FREE(piColPos); FREE(pdblSpReal); if (pdblSpImg) { FREE(pdblSpImg); } printError(&sciErr, 0); return 1; } // fill struct sparse AA.m = mA; AA.n = nA; AA.it = iComplex; AA.nel = iNbItem; AA.mnel = piNbItemRow; AA.icol = piColPos; AA.R = pdblSpReal; AA.I = pdblSpImg; if (nA <= 0 || mA <= 0) { FREE(piNbItemRow); FREE(piColPos); FREE(pdblSpReal); if (pdblSpImg) { FREE(pdblSpImg); } Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 1); return 1; } SciSparseToCcsSparse(&AA, &A); FREE(piNbItemRow); FREE(piColPos); FREE(pdblSpReal); if (pdblSpImg) { FREE(pdblSpImg); } /* symbolic factorization */ if (A.it == 1) { stat = umfpack_zi_symbolic(nA, mA, A.p, A.irow, A.R, A.I, &Symbolic, Control, Info); } else { stat = umfpack_di_symbolic(nA, mA, A.p, A.irow, A.R, &Symbolic, Control, Info); } if (stat != UMFPACK_OK) { freeCcsSparse(A); Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("symbolic factorization"), UmfErrorMes(stat)); return 1; } /* numeric factorization */ if (A.it == 1) { stat = umfpack_zi_numeric(A.p, A.irow, A.R, A.I, Symbolic, &Numeric, Control, Info); } else { stat = umfpack_di_numeric(A.p, A.irow, A.R, Symbolic, &Numeric, Control, Info); } if (A.it == 1) { umfpack_zi_free_symbolic(&Symbolic); } else { umfpack_di_free_symbolic(&Symbolic); } if ( stat != UMFPACK_OK && stat != UMFPACK_WARNING_singular_matrix ) { freeCcsSparse(A); Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("symbolic factorization"), UmfErrorMes(stat)); return 1; } if ( stat == UMFPACK_WARNING_singular_matrix && mA == nA ) { if (getWarningMode()) { Sciwarning("\n%s:%s\n", _("Warning"), _("The (square) matrix appears to be singular.")); } } /* add the pointer in the list ListNumeric */ if (! AddAdrToList(Numeric, A.it, &ListNumeric)) { /* AddAdrToList return 0 if malloc have failed : as it is just for storing 2 pointers this is unlikely to occurs but ... */ if (A.it == 1) { umfpack_zi_free_numeric(&Numeric); } else { umfpack_di_free_numeric(&Numeric); } freeCcsSparse(A); Scierror(999, _("%s: An error occurred: %s\n"), fname, _("no place to store the LU pointer in ListNumeric.")); return 1; } freeCcsSparse(A); /* create the scilab object to store the pointer onto the LU factors */ sciErr = createPointer(pvApiCtx, 2, Numeric); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } /* return the pointer */ AssignOutputVariable(pvApiCtx, 1) = 2; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xgrid(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl = NULL; double* l = NULL; int color[] = {0, 0, 0}; /* Default color */ double thickness[] = { -1, -1, -1}; int style[] = {3, 3, 3}; int m = 0, n = 0, mn = 0; int i; int iObjUID = 0; CheckInputArgument(pvApiCtx, 0, 3); if (nbInputArgument(pvApiCtx) >= 1) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl, &m, &n, &l); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } mn = m * n; if (mn == 0 || mn > 3) { Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar or a row vector expected.\n"), fname, 1); return 1; } if (mn == 1) { color[0] = (int) l[0]; color[1] = color[0]; color[2] = color[0]; } else { for (i = 0; i < mn; i++) { color[i] = (int) l[i]; } } } iObjUID = getOrCreateDefaultSubwin(); setGraphicObjectProperty(iObjUID, __GO_X_AXIS_GRID_COLOR__, color, jni_int, 1); setGraphicObjectProperty(iObjUID, __GO_Y_AXIS_GRID_COLOR__, color + 1, jni_int, 1); setGraphicObjectProperty(iObjUID, __GO_Z_AXIS_GRID_COLOR__, color + 2, jni_int, 1); if (nbInputArgument(pvApiCtx) >= 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl, &m, &n, &l); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } mn = m * n; if (mn == 0 || mn > 3) { Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar or a row vector expected.\n"), fname, 2); return 1; } if (mn == 1) { thickness[0] = l[0]; thickness[1] = l[0]; thickness[2] = l[0]; } else { for (i = 0; i < mn; i++) { thickness[i] = l[i]; } } setGraphicObjectProperty(iObjUID, __GO_X_AXIS_GRID_THICKNESS__, thickness, jni_double, 1); setGraphicObjectProperty(iObjUID, __GO_Y_AXIS_GRID_THICKNESS__, thickness + 1, jni_double, 1); setGraphicObjectProperty(iObjUID, __GO_Z_AXIS_GRID_THICKNESS__, thickness + 2, jni_double, 1); } if (nbInputArgument(pvApiCtx) == 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrl); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl, &m, &n, &l); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); return 1; } mn = m * n; if (mn == 0 || mn > 3) { Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar or a row vector expected.\n"), fname, 3); return 1; } if (mn == 1) { style[0] = (int) l[0]; style[1] = style[0]; style[2] = style[0]; } else { for (i = 0; i < mn; i++) { style[i] = (int) l[i]; } } setGraphicObjectProperty(iObjUID, __GO_X_AXIS_GRID_STYLE__, style, jni_int, 1); setGraphicObjectProperty(iObjUID, __GO_Y_AXIS_GRID_STYLE__, style + 1, jni_int, 1); setGraphicObjectProperty(iObjUID, __GO_Z_AXIS_GRID_STYLE__, style + 2, jni_int, 1); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); 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_contour2di(char * fname, void* pvApiCtx) { SciErr sciErr; int flagx = 0, nz = 10; /* default number of level curves : 10 */ int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0; double* hl1 = NULL; double* hl2 = NULL; double* znz = NULL; int ix4, i = 0, un = 1; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddr3 = NULL; int* piAddr4 = NULL; double* l1 = NULL; double* l2 = NULL; double* l3 = NULL; double* l4 = NULL; int* l5 = NULL; CheckInputArgument(pvApiCtx, 4, 4); CheckOutputArgument(pvApiCtx, 2, 2); //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &l1); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); printError(&sciErr, 0); return 1; } //CheckVector if (m1 != 1 && n1 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 1); return 1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &m2, &n2, &l2); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); printError(&sciErr, 0); return 1; } //CheckVector if (m2 != 1 && n2 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 2); return 1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } if (m3 * n3 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (m3 == 1 || n3 == 1) { Scierror(999, _("%s: Wrong type for input argument #%d: Matrix expected.\n"), fname, 3); return 1; } //CheckDimProp if (m1 * n1 != m3) { Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname); return 1; } //CheckDimProp if (m2 * n2 != n3) { Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname); return 1; } /* number of level curves */ //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 4. sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &m4, &n4, &l4); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 4); printError(&sciErr, 0); return 1; } if (m4 * n4 == 1) { flagx = 0; nz = Max(1, (int) * (l4)); znz = (l4); } else { flagx = 1; nz = m4 * n4; znz = (l4); } ix4 = Max(nz, 2); sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, 5, un, ix4, &l5); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (i = 0 ; i < ix4 ; ++i) { l5[i] = i + 1; } if (nz == 1) { l5[1] = 1; } if (C2F(contourif)(l1, l2, l3, &m3, &n3, &flagx, &nz, znz, l5) != 0) { /* Something wrong happened */ return -1; } C2F(getconts)(&hl1, &hl2, &m1, &n1); if (n1 == 0) { sciErr = allocMatrixOfDouble(pvApiCtx, 6, n1, n1, &hl1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDouble(pvApiCtx, 7, n1, n1, &hl2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } } else { sciErr = createMatrixOfDouble(pvApiCtx, 6, m1, n1, hl1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = createMatrixOfDouble(pvApiCtx, 7, m1, n1, hl2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } } AssignOutputVariable(pvApiCtx, 1) = 6; AssignOutputVariable(pvApiCtx, 2) = 7; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xrects(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddr2 = NULL; int* l2 = NULL; int m1 = 0, n1 = 0, m2 = 0, n2 = 0; long hdl = 0; int i = 0; int iSubwinUID = 0; int foreground = 0; int *piForeground = &foreground; int iCompoundUID = 0; CheckInputArgument(pvApiCtx, 1, 2); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if (m1 != 4) { Scierror(999, _("%s: Wrong size for input argument #%d: %s expected.\n"), fname, 1, "(4,n)"); return 0; } if (nbInputArgument(pvApiCtx) == 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } //CheckVector if (m2 != 1 && n2 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 2); return 1; } if (m2 * n2 != n1) { Scierror(999, _("%s: Incompatible length for input arguments #%d and #%d.\n"), fname, 1, 2); return 0; } } else { m2 = 1; n2 = n1; sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, 2, m2, n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (i = 0; i < n2; ++i) { l2[i] = 0; } } iSubwinUID = getOrCreateDefaultSubwin(); // Create compound. iCompoundUID = createGraphicObject(__GO_COMPOUND__); /* Sets the parent-child relationship for the Compound */ setGraphicObjectRelationship(iSubwinUID, iCompoundUID); /** Get Subwin line color */ getGraphicObjectProperty(iSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeground); for (i = 0; i < n1; ++i) { /* j = (i==0) ? 0 : 1; */ if (l2[i] == 0) { /** fil(i) = 0 rectangle i is drawn using the current line style (or color).**/ /* color setting is done now */ Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3), &foreground, NULL, FALSE, TRUE, &hdl); } else { if (l2[i] < 0) { /** fil(i) < 0 rectangle i is drawn using the line style (or color) **/ int tmp = - (*(int*)(l2 + i)); Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3), &tmp, NULL, FALSE, TRUE, &hdl); } else { /** fil(i) > 0 rectangle i is filled using the pattern (or color) **/ Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3), NULL, l2 + i, TRUE, FALSE, &hdl); } } // Add newly created object to Compound setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl)); } /** make Compound current object **/ setCurrentObject(iCompoundUID); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); 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_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_xfarcs(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddr2 = NULL; int* l2 = NULL; int m1 = 0, n1 = 0; int m2 = 0, n2 = 0; long hdl = 0; int iCurrentSubWin = 0; int i = 0; double angle1 = 0.0; double angle2 = 0.0; CheckInputArgument(pvApiCtx, 1, 2); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if (m1 != 6) { Scierror(999, _("%s: Wrong size for input argument #%d: %s expected.\n"), fname, 1, "(6,n)"); return 0; } if (nbInputArgument(pvApiCtx) == 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } //CheckVector if (m2 != 1 && n2 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 2); return 1; } if (n1 != m2 * n2) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); return 0; } } else { m2 = 1; n2 = n1; sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, 2, m2, n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (i = 0; i < n2; ++i) { *((int*)(l2 + i)) = i + 1; } } iCurrentSubWin = getOrCreateDefaultSubwin(); for (i = 0; i < n1; ++i) { angle1 = DEG2RAD(*(l1 + (6 * i) + 4) / 64.0); angle2 = DEG2RAD(*(l1 + (6 * i) + 5) / 64.0); Objarc(&angle1, &angle2, (l1 + (6 * i)), (l1 + (6 * i) + 1), (l1 + (6 * i) + 2), (l1 + (6 * i) + 3), (int*)(l2 + i), (int*)(l2 + i), TRUE, FALSE, &hdl); } /** Construct Compound and make it current object **/ { int o = createCompoundSeq(iCurrentSubWin, n1); setCurrentObject(o); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); 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; }
/*--------------------------------------------------------------------------*/ int sci_xfpolys(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; int* piAddr3 = NULL; int* l3 = NULL; int m1 = 0, n1 = 0; int m2 = 0, n2 = 0; int m3 = 0, n3 = 0; int mn2 = 0; int v1 = 0; /* v1 is the flag used for flat (v1==1) or interpolated (v1==2) shading */ int i = 0; long hdl = 0; char *pstSubWinUID = NULL; char *pstFigureUID = NULL; char *pstCompoundUID = NULL; int iSubWinForeground = 0; int iImmediateDrawing = 0; int *piImmediateDrawing = &iImmediateDrawing; int iFalse = 0; int iColorMapSize = 0; int* piColorMapSize = &iColorMapSize; int iForeGround = 0; int* piForeGround = &iForeGround; int iVisible = 0; int *piVisible = &iVisible; CheckInputArgument(pvApiCtx, 2, 3); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); 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, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2); return 1; } //CheckSameDims if (m1 != m2 || n1 != n2) { Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1); return 1; } mn2 = m2 * n2; if (mn2 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (nbInputArgument(pvApiCtx) == 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr3, &m3, &n3, &l3); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3); return 1; } if (m3 * n3 == m1 * n1) { //CheckSameDims if (m1 != m3 || n1 != n3) { Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1); return 1; } v1 = 2; /* interpolated shading */ if (m3 != 3 && m3 != 4) { Scierror(999, _("%s: Interpolated shading only works for polygons of size %d or %d\n"), fname, 3, 4); return 0; } } else { //CheckVector if (m3 != 1 && n3 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 3); return 1; } //CheckDimProp if (m3 * n3 != n2) { Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname); return 1; } v1 = 1; /* flat shading */ } } else { int un = 1, ix = 0; sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, 3, un, n2, &l3); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (ix = 0; ix < n2; ++ix) { *(int*)(l3 + ix) = 0; } m3 = n3 = 1; } pstSubWinUID = (char*)getOrCreateDefaultSubwin(); getGraphicObjectProperty(pstSubWinUID, __GO_PARENT__, jni_string, (void**)&pstFigureUID); getGraphicObjectProperty(pstFigureUID, __GO_IMMEDIATE_DRAWING__, jni_bool, (void **)&piImmediateDrawing); setGraphicObjectProperty(pstFigureUID, __GO_IMMEDIATE_DRAWING__, &iFalse, jni_bool, 1); //get color map size getGraphicObjectProperty(pstFigureUID, __GO_COLORMAP_SIZE__, jni_int, (void**)&piColorMapSize); //get current foreground color getGraphicObjectProperty(pstSubWinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeGround); // Create compound. pstCompoundUID = createGraphicObject(__GO_COMPOUND__); setGraphicObjectProperty(pstCompoundUID, __GO_VISIBLE__, &iFalse, jni_bool, 1); /* Sets the parent-child relationship for the Compound */ setGraphicObjectRelationship(pstSubWinUID, pstCompoundUID); for (i = 0; i < n1; ++i) { if (m3 == 1 || n3 == 1) /* color vector specified */ { if (*(int*)(l3 + i) == 0) { if (iForeGround == -1) { iSubWinForeground = iColorMapSize + 1; } else if (iForeGround == -2) { iSubWinForeground = iColorMapSize + 2; } else { iSubWinForeground = iForeGround; } Objpoly((l1 + (i * m1)), (l2 + (i * m1)), m1, 1, iSubWinForeground, &hdl); } else { Objfpoly((l1 + (i * m1)), (l2 + (i * m1)), m1, (int*)(l3 + i), &hdl, v1); } } else /* we have a color matrix used for interpolated shading : one color per vertex */ { Objfpoly((l1 + (i * m1)), (l2 + (i * m1)), m1, (int*)(l3 + i * m3), &hdl, v1); } // Add newly created object to Compound setGraphicObjectRelationship(pstCompoundUID, getObjectFromHandle(hdl)); } setCurrentObject(pstCompoundUID); setGraphicObjectProperty(pstFigureUID, __GO_IMMEDIATE_DRAWING__, &piImmediateDrawing, jni_bool, 1); getGraphicObjectProperty(pstFigureUID, __GO_VISIBLE__, jni_bool, (void **)&piVisible); setGraphicObjectProperty(pstCompoundUID, __GO_VISIBLE__, &iVisible, jni_bool, 1); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/* Set fftw wisdom * * Scilab Syntax : * -->set_fftw_wisdom(txt); * * Input : a scilab string matrix * * Output : Nothing or an error messsage if * wisdom can't be read by fftw * */ int sci_set_fftw_wisdom(char *fname, void* pvApiCtx) { SciErr sciErr; char **Str1 = NULL; char *Str = NULL; int m1 = 0, n1 = 0; int len = 0, k = 0; int j = 0; int i = 0; int* piAddr1 = NULL; int* piLen = NULL; if (withMKL()) { Scierror(999, _("%s: MKL fftw library does not implement wisdom functions yet.\n"), fname); return 0; } CheckInputArgument(pvApiCtx, 1, 1); //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isStringType(pvApiCtx, piAddr1) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 1; } //fisrt call to retrieve dimensions sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, NULL, NULL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } piLen = (int*)MALLOC(sizeof(int) * m1 * n1); //second call to retrieve length of each string sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, NULL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } Str1 = (char**)MALLOC(sizeof(char*) * m1 * n1); for (i = 0 ; i < m1 * n1 ; i++) { Str1[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination } //third call to retrieve data sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, Str1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } for (j = 0; j < m1 * n1; j++) { len += (int)strlen(Str1[j]) + 1; if (Str) { Str = (char *)REALLOC(Str, sizeof(char) * (len)); } else { Str = (char *)MALLOC(sizeof(char) * (len)); } if (Str == NULL) { freeArrayOfString(Str1, m1 * n1); Scierror(999, _("%s: Cannot allocate more memory.\n"), fname); return 1; } for (i = 0; i < (int)strlen(Str1[j]); i++) { Str[k + i] = Str1[j][i]; } Str[k + strlen(Str1[j])] = '\n'; k += (int)strlen(Str1[j]) + 1; } Str[k - 1] = '\0'; freeArrayOfString(Str1, m1 * n1); if (!(call_fftw_import_wisdom_from_string(Str))) { FREE(Str); Str = NULL; Scierror(999, _("%s: Wrong value for input argument #%d: a valid wisdom expected.\n"), fname, 1); return 1; } FREE(Str); Str = NULL; AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/* Return text of fftw wisdom * * Scilab Calling sequence : * -->tt=get_fftw_wisdom(); * * Input : Nothing * * Output : a scilab string matrix * */ int sci_get_fftw_wisdom(char *fname, void* pvApiCtx) { int n1 = 0, i = 0, j = 0; char *Str = NULL; char **Str1 = NULL; CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 0, 1); if ((Str = call_fftw_export_wisdom_to_string()) == NULL) { Scierror(999, _("%s: MKL fftw library does not implement wisdom functions yet.\n"), fname); return 1; } n1 = 0; j = 0; if (Str) { int lenStr = (int)strlen(Str); for (i = 0; i < lenStr; i++) { if (Str[i] == '\n') { int len = 0; int k = 0; n1++; if (Str1) { Str1 = (char **)REALLOC(Str1, sizeof(char *) * n1); } else { Str1 = (char **)MALLOC(sizeof(char *) * n1); } if (Str1 == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); if (Str) { // According to the FFTW documentation we should free Str // string but doing makes Scilab crash!? //free(Str); } return 1; } len = i - j; if ((Str1[n1 - 1] = (char *)MALLOC(sizeof(char) * (len + 1))) == NULL) { freeArrayOfString(Str1, n1 - 1); if (Str) { // According to the FFTW documentation we should free Str // string but doing makes Scilab crash!? //free(Str); } Scierror(999, _("%s: No more memory.\n"), fname); return 1; } for (k = 0; k < len; k++) { Str1[n1 - 1][k] = Str[k + j]; } Str1[n1 - 1][len] = '\0'; j = i + 1; } } } n1++; if (Str1) { Str1 = (char **)REALLOC(Str1, sizeof(char *) * n1); } else { Str1 = (char **)MALLOC(sizeof(char *) * n1); } if (Str1 == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); if (Str) { // According to the FFTW documentation we should free Str // string but doing makes Scilab crash!? //free(Str); } return 1; } if ((Str1[n1 - 1] = (char *)MALLOC(sizeof(char))) == NULL) { freeArrayOfString(Str1, n1 - 1); if (Str) { // According to the FFTW documentation we should free Str // string but doing makes Scilab crash!? //free(Str); } Scierror(999, _("%s: No more memory.\n"), fname); return 1; } Str1[n1 - 1][0] = '\0'; createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, n1, 1, Str1); freeArrayOfString(Str1, n1); if (Str) { // According to the FFTW documentation we should free Str // string but doing makes Scilab crash!? //free(Str); } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }