int sci_sym_solve(char *fname, unsigned long fname_len){ int status=0; //check whether we have no input and one output argument or not CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument // Check environment if(global_sym_env==NULL) sciprint("Error: Symphony environment is not initialized.\n"); else {// There is an environment opened double time_limit = -1.0; status = sym_get_dbl_param(global_sym_env,"time_limit",&time_limit); if (status == FUNCTION_TERMINATED_NORMALLY) { if ( time_limit < 0.0 ) sciprint("\nNote: There is no limit on time.\n"); else sciprint("\nNote: Time limit has been set to %lf.\n",time_limit); status=process_ret_val(sym_solve(global_sym_env));// Call function } else { sciprint("\nUnable to read time limit.\n"); status = 1; //Error state } } // Return result to scilab return returnDoubleToScilab(status); }
int printError(SciErr* _psciErr, int _iLastMsg) { if (_psciErr->iErr == 0) { return 0; } SciStoreError(_psciErr->iErr); if (getPromptMode() != PROMPTMODE_SILENT && getSilentError() == VERBOSE_ERROR) { if (_iLastMsg) { sciprint(_("API Error:\n")); sciprint(_("\tin %s\n"), _psciErr->pstMsg[0]); } else { sciprint(_("API Error:\n")); for (int i = _psciErr->iMsgCount - 1; i >= 0; i--) { sciprint(_("\tin %s\n"), _psciErr->pstMsg[i]); } } } sciErrClean(_psciErr); return 0; }
/*--------------------------------------------------------------------------*/ void C2F(mget) (int *fd, double *res, int *n, char *type, int *ierr) { int nc, swap2; FILE *fa; nc = (int)strlen(type); *ierr = 0; if (nc == 0) { sciprint(_("%s: Wrong size for input argument #%d: Non-empty string expected.\n"), "mput", 4, type); *ierr = 2; return; } fa = GetFileOpenedInScilab(*fd); if (fa) { swap2 = GetSwapStatus(*fd); mget2(fa, swap2, res, *n, type, ierr); if (*ierr > 0) { sciprint(_("%s: Wrong value for input argument #%d: Format not recognized.\n"), "mget", 4); } } else { sciprint(_("%s: No input file associated to logical unit %d.\n"), "mget", *fd); *ierr = 3; } }
int printError(SciErr* _psciErr, int _iLastMsg) { int iMode = getExecMode(); if(_psciErr->iErr == 0) { return 0; } SciStoreError(_psciErr->iErr); if(iMode == SILENT_EXEC_MODE) { return 0; } if(_iLastMsg) { sciprint(_("API Error:\n")); sciprint(_("\tin %s\n"), _psciErr->pstMsg[0]); } else { sciprint(_("API Error:\n")); // for(int i = 0 ; i < _psciErr->iMsgCount ;i++) for(int i = _psciErr->iMsgCount - 1 ; i >= 0 ; i--) { // if(i == 0) sciprint(_("\tin %s\n"), _psciErr->pstMsg[i]); } } return 0; }
/*--------------------------------------------------------------------------*/ void C2F(mtell) (int *fd, double *offset, int *err) { FILE *fa= GetFileOpenedInScilab(*fd); if ( fa == (FILE *) 0 ) { char *filename = GetFileNameOpenedInScilab(*fd); if (filename) { sciprint(_("%s: Error while opening, reading or writing '%s'.\n"),"mtell",filename); } else { sciprint(_("%s: Error while opening, reading or writing.\n"),"mtell"); } *err=1; return; } *err = 0; #ifdef _MSC_VER #if _WIN64 *offset = (double) _ftelli64(fa) ; #else *offset = (double) ftell(fa) ; #endif #else *offset = (double) ftell(fa) ; #endif }
/*--------------------------------------------------------------------------*/ void C2F(mput) (int *fd, double *res, int *n, char *type, int *ierr) { *ierr = 0; if (strlen(type) == 0) { if (getWarningMode()) { sciprint(_("%s: Wrong size for input argument #%d ('%s'): Non-empty string expected.\n"), "mput", 4, type); } *ierr = 2; return; } types::File *pFile = FileManager::getFile(*fd); if (pFile && pFile->getFiledesc()) { mput2(pFile->getFiledesc(), pFile->getFileSwap(), res, *n, type, ierr); if (*ierr > 0) { if (getWarningMode()) { sciprint(_("%s: Wrong value for input argument #%d ('%s'): Format not recognized.\n"), "mput", 4, type); } } } else { if (getWarningMode()) { sciprint(_("%s: No input file associated to logical unit %d.\n"), "mput", *fd); } *ierr = 3; } }
/* * hand written interface * Interface for cdfchn * Non-central Chi-Square */ int cdfchnI(char* fname, unsigned long l) { int m1 = 0, n1 = 0, l1 = 0, mDf = 0, nDf = 0, lDf = 0, i = 0; double *Df = NULL; Nbvars = 0; CheckRhs(4, 5); CheckLhs(1, 2); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); if ( strcmp(cstk(l1), "PQ") == 0) { static int callpos[5] = {3, 4, 0, 1, 2}; GetRhsVar(3, MATRIX_OF_DOUBLE_DATATYPE, &mDf, &nDf, &lDf); Df = stk(lDf); for (i = 0; i < mDf * nDf; ++i) if ((int) Df[i] - Df[i] != 0) { sciprint(_("%s: Warning: using non integer values for argument #%d may lead to incorrect results.\n"), fname, 3); } CdfBase(fname, 3, 2, callpos, "PQ", _("X,Df and Pnonc"), 1, C2F(cdfchn), cdfchnErr); } else if ( strcmp(cstk(l1), "X") == 0) { static int callpos[5] = {2, 3, 4, 0, 1}; GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &mDf, &nDf, &lDf); Df = stk(lDf); for (i = 0; i < mDf * nDf; ++i) if ((int) Df[i] - Df[i] != 0) { sciprint(_("%s: Warning: using non integer values for argument #%d may lead to incorrect results.\n"), fname, 2); } CdfBase(fname, 4, 1, callpos, "X", _("Df,Pnonc,P and Q"), 2, C2F(cdfchn), cdfchnErr); } else if ( strcmp(cstk(l1), "Df") == 0) { static int callpos[5] = {1, 2, 3, 4, 0}; CdfBase(fname, 4, 1, callpos, "Df", _("Pnonc,P,Q and X"), 3, C2F(cdfchn), cdfchnErr); } else if ( strcmp(cstk(l1), "Pnonc") == 0) { static int callpos[5] = {0, 1, 2, 3, 4}; GetRhsVar(5, MATRIX_OF_DOUBLE_DATATYPE, &mDf, &nDf, &lDf); Df = stk(lDf); for (i = 0; i < mDf * nDf; ++i) if ((int) Df[i] - Df[i] != 0) { sciprint(_("%s: Warning: using non integer values for argument #%d may lead to incorrect results.\n"), fname, 5); } CdfBase(fname, 4, 1, callpos, "Pnonc", _("P,Q,X and Df"), 4, C2F(cdfchn), cdfchnErr); } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s' or '%s' expected.\n"), fname, 1, "PQ", "X", "Df", "Pnonc"); } return 0; }
int sci_sym_getObjSense(char *fname){ //error management variable SciErr sciErr; int iRet; //data declarations int objSense; //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 give output iRet=sym_get_obj_sense(global_sym_env,&objSense); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has a problem been loaded?\n"); return 1; } if(objSense==1) sciprint("Symphony has been set to minimize the objective.\n"); else sciprint("Symphony has been set to maximize the objective.\n"); if(returnDoubleToScilab(objSense)) return 1; return 0; }
/* ========================================================================== */ int sci_gpuDeviceMemInfo(char *fname) { #ifdef WITH_CUDA if(isGpuInit()) { if (useCuda()) { size_t free = 0, total = 0; cuMemGetInfo(&free,&total); double freeMem = (double)free; createScalarDouble(pvApiCtx, Rhs + 1, freeMem); } else { double zero = 0.; createScalarDouble(pvApiCtx, Rhs + 1, zero); sciprint("not implemented with OpenCL.\n"); } LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999,"%s","gpu is not initialised. Please launch gpuInit() before use this function.\n"); } #else sciprint("not implemented with OpenCL.\n"); #endif return 0; }
/* Function that initializes the symphony environment * Returns 1 on success , 0 on failure */ int sci_sym_open(char *fname, unsigned long fname_len){ // Error management variable SciErr sciErr; double status=0; //check whether we have no input and one output argument or not CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument //check environment if(global_sym_env!=NULL){ sciprint("Warning: Symphony environment is already initialized.\n"); }else{ global_sym_env = sym_open_environment();//open an environment if (!global_sym_env) sciprint("Error: Unable to create symphony environment.\n"); else{ status=1; //sciprint("Symphony environment is created successfully. Please run 'sym_close()' to close.\n"); //create useful variables for user createNamedScalarDouble(pvApiCtx,"sym_minimize",1); createNamedScalarDouble(pvApiCtx,"sym_maximize",-1); } } /*write satus of function (success-1 or failure-0) as output argument to scilab*/ if(returnDoubleToScilab(status)) return 1; return 0; }
int read_sparse(char *fname, unsigned long fname_len) { SciErr sciErr; int i, j, k; int* piAddr = NULL; int iRows = 0; int iCols = 0; int iNbItem = 0; int* piNbItemRow = NULL; int* piColPos = NULL; double* pdblReal = NULL; double* pdblImg = NULL; CheckInputArgument(pvApiCtx, 1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (isVarComplex(pvApiCtx, piAddr)) { sciErr = getComplexSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg); } else { sciErr = getSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos, &pdblReal); } if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciprint("Sparse %d item(s)\n", iNbItem); k = 0; for (i = 0 ; i < iRows ; i++) { for (j = 0 ; j < piNbItemRow[i] ; j++) { sciprint("(%d,%d) = %f", i + 1, piColPos[k], pdblReal[k]); if (isVarComplex(pvApiCtx, piAddr)) { sciprint(" %+fi", pdblImg[k]); } sciprint("\n"); k++; } } //assign allocated variables to Lhs position AssignOutputVariable(pvApiCtx, 1) = 0; 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; }
static int DeleteDirectory(char *refcstrRootDirectory) { DIR *dir; struct dirent *ent; dir = opendir(refcstrRootDirectory) ; if (dir == NULL) { sciprint(_("Warning: Error while opening %s: %s\n"), refcstrRootDirectory, strerror(errno)); return -1; } while ((ent = readdir(dir)) != NULL) { char *filename = NULL; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { continue ; } filename = MALLOC(sizeof(char) * (strlen(refcstrRootDirectory) + 1 + strlen(ent->d_name) + 1 + 1)) ; sprintf(filename, "%s/%s", refcstrRootDirectory, ent->d_name); if (isdir(filename)) { /* Delete recursively */ DeleteDirectory(filename); if (filename) { FREE(filename); filename = NULL; } } else { /* Not a directory... It must be a file (at least, I hope it is a file */ if (remove(filename) != 0) { sciprint(_("Warning: Could not remove file %s: %s\n"), filename, strerror(errno)); } if (filename) { FREE(filename); filename = NULL; } } } if (rmdir(refcstrRootDirectory) != 0) { sciprint(_("Warning: Could not remove directory %s: %s\n"), refcstrRootDirectory, strerror(errno)); } if (dir) { FREE(dir); dir = NULL; } return 0; }
int sci_sym_setVarBound(char *fname){ //error management variable SciErr sciErr; int iRet; //data declarations int *varAddress,varIndex,numVars; double inputDouble,newBound; bool isLower; //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,2,2) ; CheckOutputArgument(pvApiCtx,1,1) ; //get argument 1: index of variable whose bound is to be changed if(getUIntFromScilab(1,&varIndex)) return 1; iRet=sym_get_num_cols(global_sym_env,&numVars); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has a problem been loaded?\n"); return 1; }else if(varIndex>=numVars){ Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1); return 1; } //get argument 2: new bound if(getDoubleFromScilab(2,&newBound)) return 1; //decide which function to execute isLower=(strcmp(fname,"sym_setVarLower")==0); if(isLower) iRet=sym_set_col_lower(global_sym_env,varIndex,newBound); else iRet=sym_set_col_upper(global_sym_env,varIndex,newBound); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has a problem been loaded?\n"); return 1; }else{ sciprint("Bound successfully changed.\n"); } //code to give output if(return0toScilab()) return 1; return 0; }
/*---------------------------------------------------------------------------*/ int Sci_dlsym(char *ename, int ishared, char *strf) { DynLibHandle hd1 = NULL; int ish = Min(Max(0, ishared), ENTRYMAX - 1); char enamebuf[MAXNAME]; if ( strf[0] == 'f' ) { Underscores(1, ename, enamebuf); } else { Underscores(0, ename, enamebuf); } /* lookup the address of the function to be called */ if ( NEpoints == ENTRYMAX ) { return -1; } if ( hd[ish].ok == FALSE ) { return -3; } /** entry was previously loaded **/ if ( SearchFandS(ename, ish) >= 0 ) { sciprint(_("Entry name %s.\n"), ename); return -4; } else { hd1 = (DynLibHandle)hd[ish].shl; EP[NEpoints].epoint = (function) GetDynLibFuncPtr (hd1, enamebuf); if ( EP[NEpoints].epoint == NULL ) { if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT) { sciprint(_("%s is not an entry point.\n"), enamebuf); } return -5; } else { /* we don't add the _ in the table */ if (debug) { sciprint(_("Linking %s.\n"), ename); } strncpy(EP[NEpoints].name, ename, MAXNAME); EP[NEpoints].Nshared = ish; NEpoints++; } } return 0; }
void print_type(char* _pstType) { #ifdef PRINT_DEBUG for (int i = 0 ; i < iLevel ; i++) { sciprint("\t"); } sciprint("%s\n", _pstType); #endif }
int sci_sym_setObjSense(char *fname){ //error management variable SciErr sciErr; int iRet; //data declarations int *varAddress; double objSense; //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,1,1) ; CheckOutputArgument(pvApiCtx,1,1) ; //code to process input sciErr = getVarAddressFromPosition(pvApiCtx, 1, &varAddress); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) ) { Scierror(999, "Wrong type for input argument #1:\nEither 1 (sym_minimize) or -1 (sym_maximize) is expected.\n"); return 1; } iRet = getScalarDouble(pvApiCtx, varAddress, &objSense); if(iRet || (objSense!=-1 && objSense!=1)) { Scierror(999, "Wrong type for input argument #1:\nEither 1 (sym_minimize) or -1 (sym_maximize) is expected.\n"); return 1; } iRet=sym_set_obj_sense(global_sym_env,objSense); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured.\n"); return 1; }else{ if(objSense==1) sciprint("The solver has been set to minimize the objective.\n"); else sciprint("The solver has been set to maximize the objective.\n"); } //code to give output if(return0toScilab()) return 1; return 0; }
int get_info(void* _pvCtx, int _iRhs, int* _piParent, int *_piAddr, int _iItemPos) { SciErr sciErr; int iRet = 0; int iType = 0; sciErr = getVarType(_pvCtx, _piAddr, &iType); switch (iType) { case sci_matrix : iRet = get_double_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_poly : iRet = get_poly_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_boolean : iRet = get_boolean_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_sparse : iRet = get_sparse_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_boolean_sparse : iRet = get_bsparse_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_ints : iRet = get_integer_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_strings : iRet = get_string_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_list : insert_indent(); sciprint("List "); iRet = get_list_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_tlist : insert_indent(); sciprint("TList "); iRet = get_list_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_mlist : insert_indent(); sciprint("MList "); iRet = get_list_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; case sci_pointer : iRet = get_pointer_info(_pvCtx, _iRhs, _piParent, _piAddr, _iItemPos); break; default : insert_indent(); sciprint("Unknown type\n"); return 1; } return iRet; }
int sci_sym_setObjCoeff(char *fname){ //error management variable SciErr sciErr; int iRet; //data declarations int *varAddress,varIndex,numVars; double inputDouble,newCoeff; //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,2,2) ; CheckOutputArgument(pvApiCtx,1,1) ; //get argument 1: index of variable whose coefficient is to be changed if(getUIntFromScilab(1,&varIndex)) return 1; iRet=sym_get_num_cols(global_sym_env,&numVars); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has a problem been loaded?\n"); return 1; }else if(varIndex>=numVars){ Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1); return 1; } //get argument 2: new coefficient if(getDoubleFromScilab(2,&newCoeff)) return 1; iRet=sym_set_obj_coeff(global_sym_env,varIndex,newCoeff); if(iRet==FUNCTION_TERMINATED_ABNORMALLY){ Scierror(999, "An error occured. Has a problem been loaded?\n"); return 1; }else{ sciprint("Coefficient successfully changed.\n"); } //code to give output if(return0toScilab()) return 1; return 0; }
/*--------------------------------------------------------------------------*/ int sci_oemtochar(char *fname, unsigned long l) { int l1 = 0, n1 = 0, m1 = 0; char *Output = NULL; if (getWarningMode()) { sciprint(_("%s: Feature %s is obsolete.\n"), _("Warning"), fname); sciprint(_("%s: This feature will be permanently removed in Scilab %s\n\n"), _("Warning"), "5.4.1"); } CheckRhs(1, 1); CheckLhs(0, 1); if (GetType(1) == sci_strings) { char *OEMstring = NULL; GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); OEMstring = cstk(l1); Output = (char*)MALLOC((strlen(OEMstring) + 1) * sizeof(char)); if (getScilabMode() == SCILAB_STD) { OemToChar(OEMstring, Output); } else { wsprintf(Output, "%s", OEMstring); } } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } n1 = 1; m1 = (int)strlen(Output); CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &Output); if (Output) { FREE(Output); Output = NULL; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ void banner(void) { sciprint("%s\n", line); centerPrint(SCI_VERSION_STRING); sciprint("\n\n"); centerPrint(_("Scilab Enterprises\n")); centerPrint(_("Copyright (c) 2011-2012 (Scilab Enterprises)\n")); centerPrint(_("Copyright (c) 1989-2012 (INRIA)\n")); centerPrint(_("Copyright (c) 1989-2007 (ENPC)\n")); sciprint("%s\n", line); }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void gainblk_ui16e(scicos_block *block,int flag) { if ((flag==1)|(flag==6)){ int i = 0,j = 0,l = 0,ji = 0,jl = 0,il = 0; unsigned short *u = NULL,*y = NULL; int mu = 0,ny = 0,my = 0,mo = 0,no = 0; unsigned short *opar = NULL; double k = 0.,D = 0.,C = 0.; mo=GetOparSize(block,1,1); no=GetOparSize(block,1,2); mu=GetInPortRows(block,1); my=GetOutPortRows(block,1); ny=GetOutPortCols(block,1); u=Getuint16InPortPtrs(block,1); y=Getuint16OutPortPtrs(block,1); opar=Getuint16OparPtrs(block,1); k=pow(2,16); if (mo*no==1){ for (i=0;i<ny*mu;++i){ D=(double)(opar[0])*(double)(u[i]); if ((D>=k)|( D<0)) {sciprint(_("overflow error")); set_block_error(-4); return;} else y[i]=(unsigned short)D; } }else{ for (l=0;l<ny;l++) {for (j=0;j<my;j++) {D=0; jl=j+l*my; for (i=0;i<mu;i++) {ji=j+i*my; il=i+l*mu; C=(double)(opar[ji])*(double)(u[il]); D=D + C;} if ((D>=k)|( D<0)) {sciprint(_("overflow error")); set_block_error(-4); return;} else y[jl]=(unsigned short)D; } } } } }
/*--------------------------------------------------------------------------*/ int sci_iswaitingforinput(char *fname, unsigned long fname_len) { BOOL res = FALSE; int un = 1, outIndex = 0; Rhs = Max(Rhs, 0); CheckRhs(0, 1); CheckLhs(0, 1); if (getScilabMode() == SCILAB_STD) { res = ConsoleIsWaitingForInput(); } else { sciprint(_("%s: Not implemented in this mode.\n"), fname); } CreateVar(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &un, &un, &outIndex); *istk(outIndex) = res; LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
// ============================================================================= static int getNumbersOfColumnsInLines(const char **lines, int sizelines, const char *separator) { int previousNbColumns = 0; int NbColumns = 0; BOOL firstLine = TRUE; if (lines) { int i = 0; for (i = 0; i < sizelines; i++) { NbColumns = getNumbersOfColumnsInLine(lines[i], separator); if (firstLine) { previousNbColumns = NbColumns; firstLine = FALSE; } else { if (previousNbColumns != NbColumns) { if (getWarningMode()) { sciprint(_("%s: Inconsistency found in the columns. At line %d, found %d columns while the previous had %d.\n"), _("Warning"), i + 1, NbColumns, previousNbColumns); } return 0; } } } } return NbColumns; }
//both basic and advanced loader use this code static int commonCodePart1() { //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 if(checkNumArgs()==0) return 1; //get input 1: number of variables if(getUIntFromScilab(1,&numVars)) return 1; //get input 2: number of constraints if(getUIntFromScilab(2,&numConstr)) return 1; //allocate and prepare some arrays isIntVar=new char[numVars]; //is the variable constrained to be an integer? conType=new char[numConstr]; //char representing constraint type conRange=new double[numConstr]; //range of each constraint conRHS=new double[numConstr]; //RHS to be given to Symphony return 0; }
int InertiaInterface(char *fname) { static int ndof = NDOF; static int n, nbis; static int q, M; /* Define minls=1, maxlhs, minrhs, maxrhs */ static int minlhs = 1, minrhs = 1, maxlhs = 1, maxrhs = 1; /* Check rhs and lhs */ CheckRhs(minrhs, maxrhs) ; CheckLhs(minlhs, maxlhs) ; GetRhsVar(1, "d", &n, &nbis, &q); if (n * nbis != NDOF) { sciprint("Wrong size!\r\n"); Error(999); return 0; } CreateVar(2, "d", &ndof, &ndof, &M); Inertia(stk(M), stk(q)); LhsVar(1) = 2; return 0; }
/*--------------------------------------------------------------------------*/ int C2F(scigmem) (int *n, int *ptr) { #ifdef USE_DYNAMIC_STACK return scimem64(ptr, *n, TRUE); #else register char *p1 = NULL; if (*n > 0) { /* add 1 for alignment problems */ /* YC: Same comment as above */ p1 = (char *)SCISTACKMALLOC((unsigned)sizeof(double) * (*n + 1 + 2)); if (p1 != NULL) { the_gps = the_gp; the_gp = p1; /* add 1 for alignment problems */ *ptr = ((int)(the_gp - (char *)C2F(stack).Stk)) / sizeof(double) + 1; } else { if (the_gp == NULL) { sciprint(_("No space to allocate Scilab stack.\n")); exit(1); } *ptr = 0; } } return (0); #endif }
/*------------------------------------------------------------------------*/ void C2F(setprlev)( int *pause) { if ( *pause == 0 ) { sprintf(Sci_Prompt, SCIPROMPT); } else if ( *pause > 0 ) { if (dispWarningLevelPrompt) { if (getWarningMode()) { sciprint(_("Type '%s' or '%s' to return to standard level prompt.\n\n"), "resume", "abort"); dispWarningLevelPrompt = FALSE; } } sprintf(Sci_Prompt, SCIPROMPT_INTERRUPT, *pause); // bug 5513 // when we change prompt to a pause level, we change also temp. prompt SetTemporaryPrompt(Sci_Prompt); } else { sprintf(Sci_Prompt, SCIPROMPT_PAUSE); // bug 5513 // when we change prompt to halt level, we change also temp. prompt SetTemporaryPrompt(Sci_Prompt); } }
/* * m y P r i n t f */ returnValue myPrintf( const char* s ) { #ifndef __SUPPRESSANYOUTPUT__ if ( s == 0 ) return RET_INVALID_ARGUMENTS; #ifdef __MATLAB__ mexPrintf( s ); #else #ifdef __SCILAB__ sciprint( s ); #else FILE* outputfile = getGlobalMessageHandler( )->getOutputFile( ); if ( outputfile == 0 ) return THROWERROR( RET_NO_GLOBAL_MESSAGE_OUTPUTFILE ); fprintf( outputfile, "%s", s ); #endif /* __SCILAB__ */ #endif /* __MATLAB__ */ #endif /* __SUPPRESSANYOUTPUT__ */ return SUCCESSFUL_RETURN; }