Пример #1
0
SciErr fillCommonMatrixOfPoly(void* _pvCtx, int* _piAddress, char* _pstVarName, int _iComplex, int _iRows, int _iCols, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg, int* _piTotalLen)
{
    SciErr sciErr;
    sciErr.iErr = 0;
    sciErr.iMsgCount = 0;
    int* piOffset			= NULL;
    int *piVarName		= NULL;
    int iSize					= _iRows * _iCols;

    double *pdblReal	= NULL;
    double *pdblImg		= NULL;

    //header
    _piAddress[0] = sci_poly;
    _piAddress[1] = _iRows;
    _piAddress[2] = _iCols;
    _piAddress[3] = _iComplex;


    //4 for header
    piVarName = _piAddress + 4;//4 for header
    if (strlen(_pstVarName) > 4) //4 characters max
    {
        addErrorMessage(&sciErr, API_ERROR_TOO_LONG_VAR, _("%s: Formal variable name of polynomial can't exceed 4 characters"));
        return sciErr;
    }

    //fill variable name with space ( 40 sergescii )
    piVarName[0] = 40;
    piVarName[1] = 40;
    piVarName[2] = 40;
    piVarName[3] = 40;
    str2code(piVarName, &_pstVarName);

    piOffset = _piAddress + 8; //4 for header and 4 for variable name
    piOffset[0] = 1;
    for (int i = 0 ; i < iSize ; i++)
    {
        piOffset[i + 1] = piOffset[i] + _piNbCoef[i];
    }

    pdblReal = (double*)(piOffset + iSize + 1 + ((iSize + 1) % 2 == 0 ? 0 : 1 ));

    for (int i = 0 ; i < iSize ; i++)
    {
        memcpy(pdblReal + piOffset[i] - 1, _pdblReal[i], _piNbCoef[i] * sizeof(double));
    }

    if (_iComplex == 1)
    {
        pdblImg = pdblReal + piOffset[iSize] - 1;
        for (int i = 0 ; i < iSize ; i++)
        {
            memcpy(pdblImg + piOffset[i] - 1, _pdblImg[i], _piNbCoef[i] * sizeof(double));
        }
    }

    *_piTotalLen = (piOffset[iSize] - 1) * (_iComplex + 1) * 2;
    return sciErr;
}
Пример #2
0
/** 
 * Setup charset conversion.
 * 
 * @param fromcode [in] input charset name (only libjcode accepts NULL)
 * @param tocode [in] output charset name, or NULL when disable conversion
 * 
 * @return 0 on success, -1 on failure.
 */
int
charconv_setup(char *fromcode, char *tocode)
{
  convert_enabled = 0;

  if (fromcode == NULL || tocode == NULL) {
    fprintf(stderr, "Error: charconv_setup: input code or output code not specified\n");
    return -1;
  }

#if defined(HAVE_WINNLS)
  if (str2code(fromcode, &from_cp) == -1) {
    fprintf(stderr, "Error: charconv_setup: unknown codepage specified\n");
    return -1;
  }
  if (str2code(tocode, &to_cp) == -1) {
    fprintf(stderr, "Error: charconv_setup: unknown codepage specified\n");
    return -1;
  }
#elif defined(HAVE_ICONV)
  /* clear already allocated descriptor */
  if (cd != (iconv_t)-1) {
    if (iconv_close(cd) < 0) {
      fprintf(stderr, "Error: charconv_setup: failed to close iconv\n");
      return -1;
    }
    cd = (iconv_t)-1;
  }
  /* allocate conversion descriptor */
  cd = iconv_open(tocode, fromcode);
  if (cd == (iconv_t)-1) {
    /* allocation failed */
    fprintf(stderr, "Error: charconv_setup: unknown charset name in \"%s\" or \"%s\"\n", fromcode, tocode);
    fprintf(stderr, "Error: charconv_setup: do \"iconv --list\" to get the list of available charset names.\n");
    return -1;
  }

#endif

  convert_enabled = 1;

  return(0);
}
Пример #3
0
/*----------------------------------------------------------------------------*/
int sci_str2code(char *fname, unsigned long fname_len)
{
    CheckRhs(1, 1);
    CheckLhs(1, 1);

    if (strcmp(fname, "str2code") == 0)
    {
        if (getWarningMode())
        {
            sciprint(_("%s: Feature %s is obsolete.\n"), _("Warning"), fname);
            sciprint(_("%s: Please use %s instead.\n"), _("Warning"), "ascii");
            sciprint(_("%s: This feature will be permanently removed in Scilab %s\n\n"), _("Warning"), "5.4.1");
        }
    }

    if (VarType(1) == sci_strings)
    {
        char **Input_String = NULL;
        int m1 = 0, n1 = 0;
        int *Output_Matrix = NULL;
        int nbOutput_Matrix = 0;

        GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, &Input_String);

        if ( ( strcmp(Input_String[0], "") == 0 ) || (Input_String[0] == NULL) )
        {
            /* str2code('') returns [] */
            int l = 0;

            freeArrayOfString(Input_String, m1 * n1);

            m1 = 0;
            n1 = 0;
            CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l);
            LhsVar(1) = Rhs + 1 ;
            PutLhsVar();

            return 0;
        }
        else
        {
            if (strlen(Input_String[0]))
            {
                nbOutput_Matrix = (int)strlen(Input_String[0]);
            }
            Output_Matrix = (int*)MALLOC( sizeof(int) * nbOutput_Matrix );
            if (Output_Matrix)
            {
                int i = 0;
                int numRow   = 1 ;
                int outIndex = 0;

                str2code(Output_Matrix, (const char *const *)Input_String);
                freeArrayOfString(Input_String, m1 * n1);

                /* put on scilab stack */
                CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &nbOutput_Matrix, &numRow, &outIndex); /*Output*/
                for ( i = 0 ; i < nbOutput_Matrix ; i++ )
                {
                    stk(outIndex)[i] = (double)Output_Matrix[i] ;
                }

                /* free pointers */
                FREE(Output_Matrix);
                Output_Matrix = NULL;

                LhsVar(1) = Rhs + 1 ;
                PutLhsVar();
            }
            else
            {
                freeArrayOfString(Input_String, m1 * n1);
                Scierror(999, _("%s: No more memory.\n"), fname);
            }
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 1);
    }
    return 0;
}