int int_imread(char * fname) { int mR, nR, lR; IplImage * pImage; CheckRhs(1, 1); CheckLhs(1, 1); GetRhsVar(1, "c", &mR, &nR, &lR); // fix default mode for compatibility with previous version of SIVP pImage = cvLoadImage(cstk(lR), 1); /* if load image failed */ if(pImage == NULL) { Scierror(999, "%s: Can not open file %s.\r\n", fname, cstk(lR)); return -1; } IplImg2Mat(pImage, 2); LhsVar(1) = 2; cvReleaseImage(&pImage); return 0; }
/* * 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 get_legend_arg(char *fname,int pos,rhs_opts opts[], char ** legend ) { int m,n,l,first_opt=FirstOpt(),kopt; if (pos < first_opt) { if (VarType(pos)) { GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l); *legend = cstk(l); } else { *legend = getDefLegend() ; } } else if ((kopt=FindOpt("leg",opts))) { GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l); *legend = cstk(l); } else { *legend = getDefLegend() ; } return 1; }
/*--------------------------------------------------------------------------*/ int cdfpoiI(char* fname, unsigned long l) { int m1 = 0, n1 = 0, l1 = 0, mS = 0, nS = 0, lS = 0, i = 0; double *S = NULL; Nbvars = 0; CheckRhs(3, 4); CheckLhs(1, 2); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); if ( strcmp(cstk(l1), "PQ") == 0) { static int callpos[4] = {2, 3, 0, 1}; GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &mS, &nS, &lS); S = stk(lS); for (i = 0; i < mS * nS; ++i) if (S[i] == S[i] && S[i] + 1 != S[i]) // NaN and Inf will be handled in the program if ((int) S[i] - S[i] != 0) { Scierror(999, _("%s: Wrong value for input argument #%d: A matrix of integer value expected.\n"), fname, 2); return 0; } CdfBase(fname, 2, 2, callpos, "PQ", _("S and Xlam"), 1, C2F(cdfpoi), cdfpoiErr); } else if ( strcmp(cstk(l1), "S") == 0) { static int callpos[4] = {1, 2, 3, 0}; CdfBase(fname, 3, 1, callpos, "S", _("Xlam,P and Q"), 2, C2F(cdfpoi), cdfpoiErr); } else if ( strcmp(cstk(l1), "Xlam") == 0) { static int callpos[4] = {0, 1, 2, 3}; GetRhsVar(4, MATRIX_OF_DOUBLE_DATATYPE, &mS, &nS, &lS); S = stk(lS); for (i = 0; i < mS * nS; ++i) if (S[i] == S[i] && S[i] + 1 != S[i]) // NaN and Inf will be handled in the program if ((int) S[i] - S[i] != 0) { Scierror(999, _("%s: Wrong value for input argument #%d: A matrix of integer value expected.\n"), fname, 4); return 0; } CdfBase(fname, 3, 1, callpos, "Xlam", _("P,Q and S"), 3, C2F(cdfpoi), cdfpoiErr); } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s' or '%s' expected.\n"), fname, 1, "PQ", "S", "Xlam"); } return 0; }
/** * retrieve the labels from the command line and store them into labels */ int get_labels_arg(char *fname, int pos, rhs_opts opts[], char ** labels) { int m,n,l,first_opt=FirstOpt(),kopt; if (pos < first_opt) { if (VarType(pos)) { GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l); *labels = cstk(l); } else { /* jb silvy 03/2006 */ /* do not change the legend if one already exists */ char * pSubWinUID = getOrCreateDefaultSubwin(); if (sciGetLegendDefined(pSubWinUID)) { *labels = NULL; } else { *labels = getDefLegend(); } } } else if ((kopt=FindOpt("leg",opts))) { GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l); *labels = cstk(l); } else { /* jb silvy 03/2006 */ /* do not change the legend if one already exists */ char* pSubWinUID = getOrCreateDefaultSubwin(); if (sciGetLegendDefined(pSubWinUID)) { *labels = NULL; } else { *labels = getDefLegend(); } } return 1; }
/*--------------------------------------------------------------------------*/ int sci_deletefile(char *fname,unsigned long fname_len) { CheckRhs(1,1); CheckLhs(1,1); if (GetType(1) == sci_strings) { int m1,n1,l1; char *VarName=NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); /* Bug 3089 */ VarName = cstk(l1); n1=1; if ( deleteafile(VarName) ) { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(TRUE); } else { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(FALSE); } LhsVar(1)=Rhs+1; PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument: A string expected.\n"),fname); } return 0; }
/*--------------------------------------------------------------------------*/ int sci_getsystemmetrics(char *fname, unsigned long l) { char *param = NULL; int nIndex = -1; int m1 = 0; int n1 = 0; int l1 = 0; CheckRhs(1, 1); if (GetType(1) != sci_strings) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); param = cstk(l1); nIndex = getnIndexFromString(param); if ( nIndex > -1 ) { int one = 1; CreateVar(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &one, &one, &l1); *istk(l1) = GetSystemMetrics(nIndex); LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: Wrong value for input argument: %s.\n"), fname, _("see help")); } return 0; }
/*--------------------------------------------------------------------------*/ int sci_xname(char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0, l1 = 0; char *pstCurrentFigure = NULL; CheckRhs(1, 1); CheckLhs(1, 1); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); pstCurrentFigure = getCurrentFigure(); if (pstCurrentFigure == NULL) { pstCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectProperty(pstCurrentFigure, __GO_NAME__, cstk(l1), jni_string, 1); LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_loadfftwlibrary(char *fname,unsigned long fname_len) { static int l1,n1,m1; char *FFTWLibname=NULL; CheckRhs(1,1); if (GetType(1) == sci_strings) { GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); FFTWLibname=cstk(l1); setfftwlibname(FFTWLibname); n1=1; if ( LoadFFTWLibrary(FFTWLibname) ) { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(TRUE); } else { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(FALSE); } LhsVar(1)=Rhs+1; PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1); } return(0); }
/*-------------------------------------------------------------------------------------*/ static int sci_strcat_rhs_one_is_a_matrix(char *fname) { /* strcat([],'A') returns an empty string matrix */ double *Input_String_One = NULL; int Row_One = 0, Col_One = 0; GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &Row_One, &Col_One, &Input_String_One); /* check that we have [] */ if ((Row_One == 0) && (Col_One == 0)) { int one = 1; int len = (int)strlen(EMPTY_CHAR); int outIndex = 0; CreateVar(Rhs + 1, STRING_DATATYPE, &len, &one, &outIndex); strcpy(cstk(outIndex), EMPTY_CHAR); LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings or empty real matrix expected.\n"), fname, 1); } return 0; }
/*------------------------------------------------------------------------*/ int sci_grep(char *fname, unsigned long fname_len) { CheckRhs(2, 3); CheckLhs(1, 2); if (VarType(1) == sci_matrix) { int m1 = 0, n1 = 0; char **Str = NULL; GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &Str); if ((m1 == 0) && (n1 == 0)) { int l = 0; CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; } } if (Rhs == 3) { if (VarType(3) == sci_strings) { char typ = 'd'; /*default */ int m3 = 0, n3 = 0, l3 = 0; GetRhsVar(3, STRING_DATATYPE, &m3, &n3, &l3); if (m3 * n3 != 0) { typ = cstk(l3)[0]; } if (typ == 'r') { sci_grep_common(fname, TRUE); } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 3, "s"); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 3); return 0; } } else /* Rhs == 2 */ { sci_grep_common(fname, FALSE); } return 0; }
/*--------------------------------------------------------------------------*/ int sci_system_setproperty(char *fname,unsigned long fname_len) { Rhs = Max(Rhs,0); CheckRhs(2,2); CheckLhs(1,1); if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) ) { static int m1,n1=0,l1=0; static int m2,n2=0,l2=0; char *propertyName = NULL; char *propertyValue = NULL; char *previousValue = NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); propertyName = cstk(l1); GetRhsVar(2,STRING_DATATYPE,&m2,&n2,&l2); propertyValue = cstk(l2); previousValue = system_setproperty(propertyName,propertyValue); if (previousValue) { n1=1; CreateVarFromPtr(Rhs+1,STRING_DATATYPE,(m1=(int)strlen(propertyValue), &m1),&n1,&previousValue); } else { n1 = 0; m1 = 0; l1 = 0; CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE,&n1,&m1,&l1); } LhsVar(1)=Rhs+1; if (previousValue) {FREE(previousValue); previousValue = NULL;} PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument #%d or #%d: String expected.\n"),fname, 1, 2); } return 0; }
/*--------------------------------------------------------------------------*/ int get_strf_arg(char *fname,int pos,rhs_opts opts[], char ** strf ) { int m,n,l,first_opt=FirstOpt(),kopt; if (pos < first_opt) { if (VarType(pos)) { GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l); if ( m * n != 3 ) { Scierror(999,_("%s: Wrong size for input argument #%d: String of %d characters expected.\n"),fname,pos, 3); return 0; } *strf = cstk(l); } else { /* def value can be changed */ reinitDefStrf() ; *strf = getDefStrf() ; } } else if ((kopt=FindOpt("strf",opts))) { GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l); if (m * n != 3) { Scierror(999,_("%s: Wrong size for input argument #%d: String of %d characters expected.\n"),fname,kopt,3); return 0; } *strf = cstk(l); } else { /* def value can be changed */ reinitDefStrfN() ; *strf = getDefStrf() ; } return 1; }
/*--------------------------------------------------------------------------*/ int sciReturnChar(void* _pvCtx, char value) { int nbRow = 1 ; int nbCol = 1 ; int outIndex = 0 ; CreateVar(Rhs+1,STRING_DATATYPE,&nbRow,&nbCol,&outIndex); strncpy(cstk(outIndex), &value , 1); return 0 ; }
/*--------------------------------------------------------------------------*/ int sciReturnString(void* _pvCtx, const char * value) { int numRow = 1 ; int numCol = (int)strlen(value); int outIndex = 0 ; CreateVar(Rhs+1,STRING_DATATYPE,&numRow,&numCol,&outIndex); strncpy(cstk(outIndex),value, numCol); return 0 ; }
/*--------------------------------------------------------------------------*/ int C2F(sci_clearfun)(char *fname, unsigned long fname_len) { static int l1 = 0, n1 = 0, m1 = 0; int *Status = NULL; CheckRhs(1, 1); CheckLhs(1, 1); if (GetType(1) == sci_strings) { char *VarName = NULL; int id[nsiz]; int zero = 0; int fptr = 0; int job = 0; GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); VarName = cstk(l1); Status = (int*)MALLOC(sizeof(int)); C2F(cvname)(id, VarName, &zero, (unsigned long)strlen(VarName)); job = SCI_HFUNCTIONS_FIND; /* Find function & returns fptr value */ C2F(funtab)(id, &fptr, &job, "NULL_NAME", 0); if (fptr != 0) { job = SCI_HFUNCTIONS_DELETE; /* delete function entry */ C2F(funtab)(id, &fptr, &job, "NULL_NAME", 0); *Status = TRUE; } else /* fptr = 0 function doesn't exist */ { *Status = FALSE; } m1 = 1; n1 = 1; CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &Status); LhsVar(1) = Rhs + 1; if (Status) { FREE(Status); Status = NULL; } PutLhsVar(); } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } return 0; }
/*--------------------------------------------------------------------------*/ int sci_winopen(char *fname, unsigned long l) { int m1 = 0, n1 = 0, l1 = 0; CheckRhs(1, 1); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); if (winopen(cstk(l1))) { LhsVar(1) = 0; } else { Scierror(999, _("%s: Cannot open file %s.\n"), fname, cstk(l1)); return 0; } PutLhsVar(); return 0; }
int sci_create_list(char * fname) { int m_list_out, n_list_out; int m_var1, n_var1, l_var1, l_list_var1; int m_var2, n_var2, l_var2, l_list_var2; int m_mlist, n_mlist, l_mlist; // The labels of our mlist static const char * ListLabels [] = {"mylist", "var1", "var2"}; // First, we create the variables using a classical way // The size of the Scilab variables m_var1 = 1; n_var1 = strlen("a string") + 1; // a null terminated string m_var2 = 2; n_var2 = 2; // A 2x2 double matrix m_mlist = 3; n_mlist = 1; // A mlist with 3 elements // Creation of the Scilab variables // A('var1') CreateVar(1, "c", &m_var1, &n_var1, &l_var1); // A('var2') CreateVar(2, "d", &m_var2, &n_var2, &l_var2); // A CreateVar(3, "m", &m_mlist, &n_mlist, &l_mlist); // We store values in the create variables // The matrix will be stored in A('var2') *stk(l_var2 + 0) = 1; *stk(l_var2 + 1) = 2; *stk(l_var2 + 2) = 3; *stk(l_var2 + 3) = 4; // The string will be stored in A('var1') strncpy(cstk(l_var1), "a string\0", n_var1); m_list_out = 3; n_list_out = 1; // now, affect the variable to the mlist // The labels (it corresponds to A = mlist(['mylist','var1','var2'], ... CreateListVarFromPtr(3, 1, "S", &m_list_out, &n_list_out, ListLabels); // The value stored in A('var1') (it corresponds to A = ...,'a string', ... CreateListVarFrom(3, 2, "c", &m_var1, &n_var1, &l_list_var1, &l_var1); // The value stored in A('var2') (it corresponds to A = ...,[1 2,3 4]); CreateListVarFrom(3, 3, "d", &m_var2, &n_var2, &l_list_var2, &l_var2); // We return only the mlist which has been created at position 3 LhsVar(1) = 3; return 0; }
SipExport int sip_setenv_int(char *fname) { int rname,cname,pname, rval,cval,pval, minlhs=1, maxlhs=1, minrhs=2, maxrhs=2; CheckRhs(minrhs,maxrhs); CheckLhs(minlhs,maxlhs); GetRhsVar(1, "c", &rname, &cname, &pname); GetRhsVar(2, "c", &rval, &cval, &pval); if ( setenv(cstk(pname), cstk(pval), 0) == -1 ) { sip_error("environment is already full"); return false; } LhsVar(1)=0; return true; }
/*--------------------------------------------------------------------------*/ 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; }
/*--------------------------------------------------------------------------*/ int cdfnorI(char* fname, unsigned long l) { int m1 = 0, n1 = 0, l1 = 0; 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}; CdfBase(fname, 3, 2, callpos, "PQ", _("X,Mean and Std"), 1, C2F(cdfnor), cdfnorErr); } else if ( strcmp(cstk(l1), "X") == 0) { static int callpos[5] = {2, 3, 4, 0, 1}; CdfBase(fname, 4, 1, callpos, "X", _("Mean,Std,P and Q"), 2, C2F(cdfnor), cdfnorErr); } else if ( strcmp(cstk(l1), "Mean") == 0) { static int callpos[5] = {1, 2, 3, 4, 0}; CdfBase(fname, 4, 1, callpos, "Mean", _("Std,P,Q and X"), 3, C2F(cdfnor), cdfnorErr); } else if ( strcmp(cstk(l1), "Std") == 0) { static int callpos[5] = {0, 1, 2, 3, 4}; CdfBase(fname, 4, 1, callpos, "Std", _("P,Q,X and Mean"), 4, C2F(cdfnor), cdfnorErr); } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s' or '%s' expected.\n"), fname, 1, "PQ", "X", "Mean", "Std"); } return 0; }
/*--------------------------------------------------------------------------*/ int cdfbetI(char* fname, unsigned long l) { int minrhs = 5, maxrhs = 6, minlhs = 1, maxlhs = 2, m1 = 0, n1 = 0, l1 = 0; Nbvars = 0; CheckRhs(minrhs, maxrhs); CheckLhs(minlhs, maxlhs); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); if ( strcmp(cstk(l1), "PQ") == 0) { static int callpos[6] = {4, 5, 0, 1, 2, 3}; CdfBase(fname, 4, 2, callpos, "PQ", _("X,Y,A and B"), 1, C2F(cdfbet), cdfbetErr); } else if ( strcmp(cstk(l1), "XY") == 0) { static int callpos[6] = {2, 3, 4, 5, 0, 1}; CdfBase(fname, 4, 2, callpos, "XY", _("A,B,P and Q"), 2, C2F(cdfbet), cdfbetErr); } else if ( strcmp(cstk(l1), "A") == 0) { static int callpos[6] = {1, 2, 3, 4, 5, 0}; CdfBase(fname, 5, 1, callpos, "A", _("B,P,Q,X and Y"), 3, C2F(cdfbet), cdfbetErr); } else if ( strcmp(cstk(l1), "B") == 0) { static int callpos[6] = {0, 1, 2, 3, 4, 5}; CdfBase(fname, 5, 1, callpos, "B", _("P,Q,X,Y and A"), 4, C2F(cdfbet), cdfbetErr); } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s' or '%s' expected.\n"), fname, 1, "PQ", "XY", "A", "B"); } return 0; }
/*--------------------------------------------------------------------------*/ int cdfbinI(char* fname,unsigned long l) { int m1 = 0, n1 = 0, l1 = 0; Nbvars = 0; CheckRhs(5,6); CheckLhs(1,2); GetRhsVar(1,STRING_DATATYPE, &m1, &n1, &l1); if ( strcmp(cstk(l1),"PQ")==0) { static int callpos[6] = {4,5,0,1,2,3}; CdfBase(fname,4,2,callpos,"PQ",_("S,Xn,Pr and Ompr"),1,C2F(cdfbin), cdfbinErr); } else if ( strcmp(cstk(l1),"S")==0) { static int callpos[6] = {3,4,5,0,1,2}; CdfBase(fname,5,1,callpos,"S",_("Xn,Pr,Ompr,P and Q"),2,C2F(cdfbin), cdfbinErr); } else if ( strcmp(cstk(l1),"Xn")==0) { static int callpos[6] = {2,3,4,5,0,1}; CdfBase(fname,5,1,callpos,"Xn",_("Pr,OMPr,P,Q and S"),3,C2F(cdfbin), cdfbinErr); } else if ( strcmp(cstk(l1),"PrOmpr")==0) { static int callpos[6] = {0,1,2,3,4,5}; CdfBase(fname,4,2,callpos,"PrOmpr",_("P,Q,S and Xn"),4,C2F(cdfbin), cdfbinErr); } else { Scierror(999,_("%s: Wrong value for input argument #%d: '%s', '%s', '%s' or '%s' expected.\n"),fname,1,"PQ","S","Xn","PrOmpr"); } return 0; }
/* * sets SIP verbosity level * TODO * - even in quiet mode, all function should output useful * info/debug/error codes in a global variable (sip_ans_msg) */ SipExport int sip_set_verbose_int(char *fname) { int rname,cname,pname, rout,cout, minlhs=1, maxlhs=1, minrhs=0, maxrhs=1; char *prev; CheckRhs(minrhs,maxrhs); CheckLhs(minlhs,maxlhs); /* print previous value */ switch (sip_verbose) { case SIP_WORDY: prev = "wordy"; break; case SIP_QUIET: prev = "quiet"; break; default: sip_error("BUG: internal variable has invalid value (please report)"); break; } cout = 1; rout = strlen(prev); CreateVarFromPtr(2, "c", &rout, &cout, &prev); if (Rhs == 0) /* toggle previous value */ sip_verbose = (sip_verbose == SIP_QUIET) ? SIP_WORDY : SIP_QUIET; else { /* set new value */ GetRhsVar(1, "c", &rname, &cname, &pname); if (cname == 1 && *cstk(pname) == 'q') sip_verbose = SIP_QUIET; else sip_verbose = SIP_WORDY; } LhsVar(1)=2; return true; }
int intpower (char *fname) { int ainf, asup, op, n; int sa[2], flag[1]; int cinf, csup, f; int ma, na; int r, s, v, w; int p, q, t, u; CheckRhs (4, 4); CheckLhs (2, 3); GetRhsVar (1, "d", &na, &ma, &ainf); GetRhsVar (2, "d", &na, &ma, &asup); GetRhsVar (3, "c", &t, &u, &op); GetRhsVar (4, "i", &p, &q, &n); r = na; s = ma; v = 1; w = 1; CreateVar (5, "d", &r, &s, &cinf); CreateVar (6, "d", &r, &s, &csup); CreateVar (7, "i", &v, &w, &f); sa[0] = na; sa[1] = ma; power (stk (ainf), stk (asup), sa, *cstk (op), istk (n), stk (cinf), stk (csup), flag); *istk (f) = flag[0]; LhsVar (1) = 5; LhsVar (2) = 6; LhsVar (3) = 7; return 0; }
int intunary (char *fname) { int ainf, asup, op; int sa[2], flag[1]; int cinf, csup, f; int ma, na; int r, s; int t, u, v, w; CheckRhs (3, 3); CheckLhs (2, 3); GetRhsVar (1, "d", &na, &ma, &ainf); GetRhsVar (2, "d", &na, &ma, &asup); GetRhsVar (3, "c", &t, &u, &op); r = na; s = ma; v = 1; w = 1; CreateVar (4, "d", &r, &s, &cinf); CreateVar (5, "d", &r, &s, &csup); CreateVar (6, "i", &v, &w, &f); sa[0] = na; sa[1] = ma; unary (stk (ainf), stk (asup), sa, *cstk (op), stk (cinf), stk (csup), flag); *istk (f) = flag[0]; LhsVar (1) = 4; LhsVar (2) = 5; LhsVar (3) = 6; return 0; }
/*--------------------------------------------------------------------------*/ int sci_removedir(char *fname,unsigned long l) { CheckRhs(1,1); CheckLhs(0,1); if (GetType(1) == sci_strings) { BOOL bOK = FALSE; int m1 = 0, n1 = 0, l1 = 0; char *expandedpath = NULL; char *VarName = NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); VarName = cstk(l1); expandedpath = expandPathVariable(VarName); if (expandedpath) { if ( isdir(expandedpath) ) { bOK = removedir(expandedpath); } FREE(expandedpath); expandedpath = NULL; } m1 = 1; n1 = 1; CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &m1, &n1 ,&l1); *istk(l1) = bOK; LhsVar(1)=Rhs+1; PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument: A string expected.\n"), fname); } return 0; }
int sci_view(char *fname) { static int l1, m1, n1, l2, m2, n2, m3, n3, l3; static int minlhs=1, maxlhs=3, minrhs=3, maxrhs=3; /* Check number of inputs (rhs=3) and outputs (lhs=3) */ CheckRhs(minrhs,maxrhs) ; CheckLhs(minlhs,maxlhs) ; /* Get X (1 ,double), Y (2, int) and C (3, string) */ GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); GetRhsVar(2,MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); GetRhsVar(3,STRING_DATATYPE, &m3, &n3, &l3); /* Call display function stk(l1)->X (double), istk(l2)->Y (int), cstk(l3)->Z (char) */ displ(stk(l1), m1, n1, istk(l2), m2, n2, cstk(l3), m3, n3); /* Return variables */ LhsVar(1) = 1; LhsVar(2) = 2; LhsVar(3) = 3; return 0; }
/*--------------------------------------------------------------------------*/ int sci_findfiles(char *fname, unsigned long fname_len) { static int l1 = 0, n1 = 0, m1 = 0; char *pathextented = NULL; char *path = NULL; char *filespec = NULL; char **FilesList = NULL; int sizeListReturned = 0; Rhs = Max(Rhs, 0); CheckRhs(0, 2); CheckLhs(0, 1); switch (Rhs) { default: case 0: { int ierr = 0; path = scigetcwd(&ierr); if (ierr) { Scierror(999, _("%s: Error while trying to retrieve the name of the current directory.\n"), fname); return 0; } else { filespec = strdup(DEFAULT_FILESPEC); } } break; case 1: { if (GetType(1) == sci_strings) { GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); path = strdup(cstk(l1)); filespec = strdup(DEFAULT_FILESPEC); } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } } break; case 2: { if ((GetType(1) == sci_strings) && (GetType(2) == sci_strings)) { GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); path = strdup(cstk(l1)); GetRhsVar(2, STRING_DATATYPE, &m1, &n1, &l1); filespec = strdup(cstk(l1)); } else { Scierror(999, _("%s: Wrong type for input arguments: Strings expected.\n"), fname); return 0; } } break; } pathextented = expandPathVariable(path); if (path) { FREE(path); path = NULL; } FilesList = findfiles(pathextented, filespec, &sizeListReturned, FALSE); if (pathextented) { FREE(pathextented); pathextented = NULL; } if (filespec) { FREE(filespec); filespec = NULL; } if (FilesList) { int ncol = 0, nrow = 0; ncol = 1; nrow = sizeListReturned; CreateVarFromPtr(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &nrow, &ncol, FilesList); LhsVar(1) = Rhs + 1; } else { n1 = 0; m1 = 0; l1 = 0; CreateVarFromPtr(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &n1, &m1, &l1); LhsVar(1) = Rhs + 1; } freeArrayOfString(FilesList, sizeListReturned); PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_mcisendstring(char *fname, unsigned long l) { int m1, n1, l1; char *Output = NULL; int *BoolOutput = NULL; int *CodeOutput = NULL; CheckRhs(1, 1); CheckLhs(1, 3); if (GetType(1) == sci_strings) { MCIERROR Error; char *MCICommand = NULL; char ReturnString[2048]; GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); MCICommand = cstk(l1); Error = mciSendString(MCICommand, (LPSTR)ReturnString, sizeof(ReturnString), NULL); BoolOutput = (int*)MALLOC(sizeof(int)); CodeOutput = (int*)MALLOC(sizeof(int)); *BoolOutput = (int)0; *CodeOutput = (int)Error; if (Error) { char ErrorText[128]; *BoolOutput = (int)FALSE; if ( mciGetErrorString(Error, ErrorText, sizeof(ErrorText)) == FALSE ) { wsprintf(ErrorText, "%s", "Unknown MCI error"); } Output = strdup(ErrorText); } else { *BoolOutput = (int)TRUE; Output = strdup("OK"); } n1 = 1; if ( Lhs == 1 ) { CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &BoolOutput); LhsVar(1) = Rhs + 1; } else if ( Lhs == 2 ) { CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &BoolOutput); LhsVar(1) = Rhs + 1; CreateVarFromPtr(Rhs + 2, MATRIX_OF_INTEGER_DATATYPE, &n1, &n1, &CodeOutput); LhsVar(2) = Rhs + 2; } else /* Lhs == 3 */ { CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &BoolOutput); LhsVar(1) = Rhs + 1; CreateVarFromPtr(Rhs + 2, MATRIX_OF_INTEGER_DATATYPE, &n1, &n1, &CodeOutput); LhsVar(2) = Rhs + 2; m1 = (int)strlen(Output); CreateVarFromPtr(Rhs + 3, STRING_DATATYPE, &m1, &n1, &Output); LhsVar(3) = Rhs + 3; } if (Output) { FREE(Output); Output = NULL; } if (BoolOutput) { FREE(BoolOutput); BoolOutput = NULL; } if (CodeOutput) { FREE(CodeOutput); Output = NULL; } PutLhsVar(); return 0; } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } }