/*------------------------------------------------------------*/
static int first_example(void)
{
    void* pvApiCtx = NULL;
    static double A[] = {1, 2, 3, 4};
    int mA = 2, nA = 2;
    static double b[] = {4, 5};
    int mb = 2, nb = 1;
    printf("\nExample 1:\n");
    printf("Some simple computations\n");

    /* Create Scilab matrices A and b */
    createNamedMatrixOfDouble(pvApiCtx, "A", mA, mA, A);
    createNamedMatrixOfDouble(pvApiCtx, "b", mb, nb, b);

    SendScilabJob("disp('A=');");
    SendScilabJob("disp(A);");
    SendScilabJob("disp('b=');");
    SendScilabJob("disp(b);");
    SendScilabJob("disp('x=A\\b');");

    if ( SendScilabJob("A,b,x=A\\b;") != 0)
    {
        fprintf(stdout, "Error occurred during scilab execution (SendScilabJob)\n");
    }
    else
    {
        double *cxtmp = NULL;
        int m, n, lp, i;

        /* Get m and n */
        getNamedVarDimension(pvApiCtx, "x", &m, &n);

        cxtmp = (double*)malloc((m * n) * sizeof(double));

        readNamedMatrixOfDouble(pvApiCtx, "x", &m, &n, cxtmp);

        for (i = 0; i < m * n; i++)
        {
            fprintf(stdout, "x[%d] = %5.2f\n", i, cxtmp[i]);
        }

        if (cxtmp)
        {
            free(cxtmp);
            cxtmp = NULL;
        }
    }
    return 0;
}
Exemple #2
0
SciErr createCommonNamedMatrixOfPoly(void* _pvCtx, const char* _pstName, char* _pstVarName, int _iComplex, int _iRows, int _iCols, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg)
{
    SciErr sciErr;
    sciErr.iErr = 0;
    sciErr.iMsgCount = 0;
    int iVarID[nsiz];
    int iSaveRhs    = Rhs;
    int iSaveTop    = Top;
    int *piAddr     = NULL;
    int iTotalLen   = 0;

    //return named empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        double dblReal = 0;
        sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix");
        }
        return sciErr;
    }

    if (!checkNamedVarFormat(_pvCtx, _pstName))
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createCommonNamedMatrixOfPoly");
        return sciErr;
    }

    C2F(str2name)(_pstName, iVarID, (unsigned long)strlen(_pstName));
    Top = Top + Nbvars + 1;

    getNewVarAddressFromPosition(_pvCtx, Top, &piAddr);

    //write matrix information
    sciErr = fillCommonMatrixOfPoly(_pvCtx, piAddr, _pstVarName, _iComplex, _iRows, _iCols, _piNbCoef, _pdblReal, _pdblImg, &iTotalLen);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_POLY, _("%s: Unable to create %s named \"%s\""), _iComplex ? "createNamedComplexMatrixOfPoly" : "createNamedMatrixOfPoly", _("matrix of double"), _pstName);
        return sciErr;
    }


    //update "variable index"
    updateLstk(Top, *Lstk(Top) + 4, iTotalLen);

    Rhs = 0;
    //Add name in stack reference list
    createNamedVariable(iVarID);

    Top = iSaveTop;
    Rhs = iSaveRhs;

    return sciErr;
}
Exemple #3
0
int putDouble(char *variableName, double *variable, int nbRow, int nbCol)
{
    SciErr sciErr;

    sciErr = createNamedMatrixOfDouble(NULL, variableName, nbRow, nbCol, variable);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return -1;
    }
    return 0;
}
/*--------------------------------------------------------------------------*/
SciErr createNamedMatrixOfWideString(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const wchar_t* const* _pwstStrings)
{
    SciErr sciErr = sciErrInit();
    char **pStrings = NULL;

    // check variable name
    if (checkNamedVarFormat(_pvCtx, _pstName) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Invalid variable name: %s."), "createNamedMatrixOfWideString", _pstName);
        return sciErr;
    }

    //return named empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        double dblReal = 0;
        sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix");
        }
        return sciErr;
    }

    types::String* pS = new types::String(_iRows, _iCols);
    if (pS == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name: %s."), "createNamedMatrixOfWideString", _pstName);
        return sciErr;
    }

    for (int i = 0 ; i < pS->getSize() ; i++)
    {
        pS->set(i, _pwstStrings[i]);
    }

    wchar_t* pwstName = to_wide_string(_pstName);
    symbol::Context* ctx = symbol::Context::getInstance();
    symbol::Symbol sym = symbol::Symbol(pwstName);
    FREE(pwstName);
    if (ctx->isprotected(sym) == false)
    {
        ctx->put(sym, pS);
    }
    else
    {
        delete pS;
        addErrorMessage(&sciErr, API_ERROR_REDEFINE_PERMANENT_VAR, _("Redefining permanent variable.\n"));
    }
    return sciErr;
}
Exemple #5
0
/*--------------------------------------------------------------------------*/
int createNamedEmptyMatrix(void *_pvCtx, const char *_pstName)
{
    double dblOne = 0;

    SciErr sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblOne);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    return 0;
}
void putScilabVariable(char * name, char ** lines, int rows, int cols)
{
    SciErr sciErr;

    if (rows != 0 && cols != 0)
    {
        sciErr = createNamedMatrixOfString(pvApiCtx, name, rows, cols, lines);
    }
    else
    {
        sciErr = createNamedMatrixOfDouble(pvApiCtx, name, 0, 0, NULL);
    }

    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
    }
}
/*------------------------------------------------------------*/
int main(void)
{
#ifdef _MSC_VER
    if ( StartScilab(NULL, NULL, 0) == FALSE )
#else
    if ( StartScilab(getenv("SCI"), NULL, 0) == FALSE )
#endif
    {
        fprintf(stderr,"Error while calling StartScilab\n");
        return -1;
    }

    /******************************** WRITE ****************************/

    /*
    * Write a line matrix into Scilab
    * A=[ 1 3 3 2 ];
    */
    {
        double A[] = {1,3,3,2};   /* Declare the matrix */
        int rowA = 1, colA = 4; /* Size of the matrix */
        char variableName[] = "A";
        SciErr sciErr;

        /*
        * Write it into Scilab's memory 
        */
        sciErr = createNamedMatrixOfDouble(pvApiCtx,variableName,rowA,colA, A);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /*
        * Prior to Scilab 5.2:
        * C2F(cwritemat)(variableName, &rowA, &colA, A,strlen(variableName));
        */

        printf("Display from Scilab of A:\n");
        SendScilabJob("disp(A);"); /* Display A */
    }

    /* 
    * Write a matrix into Scilab
    * B=[1 4 2 3; 
    *    3 9 8 2 ]
    * Note that it is done column by column
    */ 
    {
        double B[] = {1,3,4,9,2,8,3,2};   /* Declare the matrix */
        int rowB = 2, colB = 4; /* Size of the matrix */
        char variableNameB[] = "B";
        SciErr sciErr;

        /*
        * Write it into Scilab's memory 
        */
        sciErr = createNamedMatrixOfDouble(pvApiCtx,variableNameB,rowB,colB, B);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /*
        * Prior to Scilab 5.2:
        * C2F(cwritemat)(variableNameB, &rowB, &colB, B, strlen(variableNameB));
        */

        printf("\n");
        printf("Display from Scilab of B:\n");
        SendScilabJob("disp(B);"); /* Display B */
    }	

    /******************************** READ ****************************/

    /* Load the previously set variable A */
    {
        int rowA_ = 0,colA_ = 0,lp = 0;
        int i = 0, j = 0;
        double *matrixOfDouble = NULL;

        char variableToBeRetrieved[]="A";
        SciErr sciErr;

        /* First, retrieve the size of the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, NULL);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * 	C2F(cmatptr)(variableToBeRetrieved, &rowA_, &colA_, &lp, strlen(variableToBeRetrieved));
        */


        /* Alloc the memory */
        matrixOfDouble=(double*)malloc((rowA_*colA_)*sizeof(double));

        /* Load the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, matrixOfDouble);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * C2F(creadmat)(variableToBeRetrieved,&rowA_,&colA_,matrixOfDouble,strlen(variableToBeRetrieved) );
        */

        printf("\n");
        printf("Display from A (size: %d, %d):\n", rowA_, colA_);
        for(i=0; i < rowA_*colA_; i++)
        {
            fprintf(stdout,"A[%d] = %5.2f\n",i,matrixOfDouble[i]);
        }

        if (matrixOfDouble) 
        {
            free(matrixOfDouble);
            matrixOfDouble=NULL;
        }
    }


    /* Load the previously set variable B */
    {
        int rowB_ = 0, colB_ = 0, lp_ = 0;
        double *matrixOfDoubleB = NULL;
        int i = 0, j = 0;

        char variableToBeRetrievedB[] = "B";
        SciErr sciErr;

        /* First, retrieve the size of the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, NULL);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * C2F(cmatptr)(variableToBeRetrievedB, &rowB_, &colB_, &lp_, strlen(variableToBeRetrievedB));
        */


        /* Alloc the memory */
        matrixOfDoubleB = (double*)malloc((rowB_*colB_)*sizeof(double));

        /* Load the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, matrixOfDoubleB);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * C2F(creadmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfDoubleB,strlen(variableToBeRetrievedB) );
        */


        printf("\n");
        printf("Display from B raw (size: %d, %d):\n",rowB_, colB_);
        for(i=0; i < rowB_*colB_; i++)
        {
            /* Display the raw matrix */
            fprintf(stdout,"B[%d] = %5.2f\n",i,matrixOfDoubleB[i]);
        }

        printf("\n");
        printf("Display from B formated (size: %d, %d):\n",rowB_, colB_);
        for(j = 0 ; j < rowB_ ; j++)
        {
            for(i = 0 ; i < colB_ ; i++)
            {
                /* Display the formated matrix ... the way the user
                * expect */
                printf("%5.2f ",matrixOfDoubleB[i * rowB_ + j]);
            }
            printf("\n"); /* New row of the matrix */
        }

        if (matrixOfDoubleB) 
        {
            free(matrixOfDoubleB);
            matrixOfDoubleB=NULL;
        }
    }


    if ( TerminateScilab(NULL) == FALSE ) {
        fprintf(stderr,"Error while calling TerminateScilab\n");
        return -2;
    }		
}
SciErr createNamedBooleanSparseMatrix(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, int _iNbItem, const int* _piNbItemRow, const int* _piColPos)
{
	SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0;
	int iVarID[nsiz];
	int iSaveRhs        = Rhs;
	int iSaveTop        = Top;
	int iPos            = 0;

	int* piAddr         = NULL;
	int* piNbItemRow    = NULL;
	int* piColPos       = NULL;

    //return named empty matrix
    if(_iRows == 0 && _iCols == 0)
    {
        double dblReal = 0;
        sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix");
        }
        return sciErr;
    }

    if (!checkNamedVarFormat(_pvCtx, _pstName))
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createNamedBooleanSparseMatrix");
        return sciErr;
    }

	C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName));
	Top = Top + Nbvars + 1;

	int iMemSize = (int)( ( (double)iPos / 2) + 0.5);
	int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(Top));
	if (iMemSize > iFreeSpace)
	{
		addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize);
		return sciErr;
	}

	getNewVarAddressFromPosition(_pvCtx, Top, &piAddr);
	sciErr = fillBooleanSparseMatrix(_pvCtx, piAddr, _iRows, _iCols, _iNbItem, &piNbItemRow, &piColPos);
	if(sciErr.iErr)
	{
		addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_BOOLEAN_SPARSE, _("%s: Unable to create %s named \"%s\""), "createNamedBooleanSparseMatrix", _("boolean sparse matrix"), _pstName);
		return sciErr;
	}

	memcpy(piNbItemRow, _piNbItemRow, _iRows * sizeof(int));
	memcpy(piColPos, _piColPos, _iNbItem * sizeof(int));

	iPos	= 5;//4 for header + 1 for NbItem
	iPos += _iRows + _iNbItem;

	//update "variable index"
	updateLstk(Top, *Lstk(Top) + iPos, 0);

	Rhs = 0;
	//Add name in stack reference list
	createNamedVariable(iVarID);

	Top = iSaveTop;
  Rhs = iSaveRhs;

	return sciErr;
}
Exemple #9
0
SciErr createNamedMatrixOfBoolean(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const int* _piBool)
{
	SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0;
	int iVarID[nsiz];
	int iSaveRhs			= Rhs;
	int iSaveTop			= Top;
	int* piBool				= NULL;
	int *piAddr				= NULL;

    //return named empty matrix
    if(_iRows == 0 && _iCols == 0)
    {
        double dblReal = 0;
        sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix");
        }
        return sciErr;
    }

    if (!checkNamedVarFormat(_pvCtx, _pstName))
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createNamedMatrixOfBoolean");
        return sciErr;
    }

	C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName));
	Top = Top + Nbvars + 1;

	int iMemSize = (int)(((double)(_iRows * _iCols) / 2) + 2);
	int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top)));
	if (iMemSize > iFreeSpace)
	{
		addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize);
		return sciErr;
	}

	getNewVarAddressFromPosition(_pvCtx, Top, &piAddr);

	//write matrix information
	sciErr = fillMatrixOfBoolean(_pvCtx, piAddr, _iRows, _iCols, &piBool);
	if(sciErr.iErr)
	{
		addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_BOOLEAN, _("%s: Unable to create %s named \"%s\""), "createNamedMatrixOfBoolean", _("matrix of boolean"), _pstName);
		return sciErr;
	}

	//copy data in stack
	memcpy(piBool, _piBool, sizeof(int) * _iRows * _iCols);

	updateLstk(Top, *Lstk(Top) + sadr(3), (_iRows * _iCols) / (sizeof(double)/sizeof(int)));

	Rhs = 0;
	//Add name in stack reference list
	createNamedVariable(iVarID);

	Top = iSaveTop;
	Rhs = iSaveRhs;
	return sciErr;
}
SciErr createCommonNamedSparseMatrix(void* _pvCtx, const char* _pstName, int _iComplex, int _iRows, int _iCols, int _iNbItem, const int* _piNbItemRow, const int* _piColPos, const double* _pdblReal, const double* _pdblImg)
{
	SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0;
	int iVarID[nsiz];
  	int iSaveRhs        = Rhs;
	int iSaveTop        = Top;
	int iTotalSize      = 0;
	int iPos            = 0;

	int* piAddr         = NULL;
	int* piNbItemRow    = NULL;
	int* piColPos       = NULL;
	int iOne            = 1;
	double* pdblReal    = NULL;
	double* pdblImg     = NULL;

    //return named empty matrix
    if(_iRows == 0 && _iCols == 0)
    {
        double dblReal = 0;
        sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix");
        }
        return sciErr;
    }

    if (!checkNamedVarFormat(_pvCtx, _pstName))
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createCommonNamedSparseMatrix");
        return sciErr;
    }

	C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName));
	Top = Top + Nbvars + 1;

	//header + offset
	int iMemSize = (5 + _iRows + _iNbItem + !((_iRows + _iNbItem) % 2)) / 2;
	//+ items size
	iMemSize += _iNbItem * (_iComplex + 1); 
	int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top)));
	if (iMemSize > iFreeSpace)
	{
		addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize);
		return sciErr;
	}

	getNewVarAddressFromPosition(_pvCtx, Top, &piAddr);

	sciErr = fillCommonSparseMatrix(_pvCtx, piAddr, _iComplex, _iRows, _iCols, _iNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg, &iTotalSize);
	if(sciErr.iErr)
	{
		addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_SPARSE, _("%s: Unable to create %s named \"%s\""), _iComplex ? "createNamedComplexSparseMatrix" : "createNamedSparseMatrix", _("sparse matrix"), _pstName);
		return sciErr;
	}

	memcpy(piNbItemRow, _piNbItemRow, _iRows * sizeof(int));
	memcpy(piColPos, _piColPos, _iNbItem * sizeof(int));
	C2F(dcopy)(&_iNbItem, const_cast<double*>(_pdblReal), &iOne, pdblReal, &iOne);
	if(_iComplex)
	{
		C2F(dcopy)(&_iNbItem, const_cast<double*>(_pdblImg), &iOne, pdblImg, &iOne);
	}

	iPos	= 5;//4 for header + 1 for NbItem
	iPos += _iRows + _iNbItem;

	//update "variable index"
	updateLstk(Top, *Lstk(Top) + iPos, iTotalSize);

	Rhs = 0;
	//Add name in stack reference list
	createNamedVariable(iVarID);

	Top = iSaveTop;
    Rhs = iSaveRhs;

	return sciErr;

}
static bool import_double(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    SciErr sciErr;
    int iRet = 0;
    double *pdblReal = NULL;
    double *pdblImg = NULL;
    int iDims = 0;
    int* piDims = NULL;
    int iComplex = 0;
    int iSize = 0;

    iRet = getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL);
    if (iRet < 0)
    {
        return false;
    }

    if (iDims)
    {
        if (iDims > 2)
        {
            //hypermatrix
            return false;
        }

        piDims = (int*)MALLOC(sizeof(int) * iDims);
        iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);

        if (iSize > 0)
        {
            pdblReal = (double *)MALLOC(iSize * sizeof(double));

            if (iComplex)
            {
                pdblImg = (double *)MALLOC(iSize * sizeof(double));
                iRet = readDoubleComplexMatrix(_iDatasetId, pdblReal, pdblImg);
            }
            else
            {
                iRet = readDoubleMatrix(_iDatasetId, pdblReal);
            }

            //to be sure ti have 2 dims
            if (iDims == 1)
            {
                FREE(piDims);
                piDims = (int*)MALLOC(sizeof(int) * 2);
                piDims[0] = 1;
                piDims[1] = iSize;
            }
        }
    }

    if (iDims == 0 || iSize == 0) //empty matrix
    {
        if (piDims)
        {
            FREE(piDims);
        }

        /*bug 7224 : to close dataset */
        iRet = readEmptyMatrix(_iDatasetId);
        if (iRet)
        {
            return false;
        }

        // Hack to sure that piDims will not be null at line 372.
        iDims = 2;
        piDims = (int*)MALLOC(sizeof(int) * iDims);
        memset(piDims, 0, sizeof(int) * iDims);
        pdblReal = (double*)MALLOC(sizeof(double) * 1);
        pdblReal[0] = 0;
        iComplex = 0;
    }

    if (_piAddress == NULL)
    {
        if (iComplex)
        {
            sciErr = createNamedComplexMatrixOfDouble(pvCtx, _pstVarname, piDims[0], piDims[1], pdblReal, pdblImg);
        }
        else
        {
            sciErr = createNamedMatrixOfDouble(pvCtx, _pstVarname, piDims[0], piDims[1], pdblReal);
        }
    }
    else //if not null this variable is in a list
    {
        if (iComplex)
        {
            sciErr = createComplexMatrixOfDoubleInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pdblReal, pdblImg);
        }
        else
        {
            sciErr = createMatrixOfDoubleInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pdblReal);
        }
    }

    FREE(piDims);
    FREE(pdblReal);
    if (iComplex)
    {
        FREE(pdblImg);
    }

    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return false;
    }

    return true;
}
static bool import_double_v1(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    double *pdblReal = NULL;
    double *pdblImg = NULL;
    int iRows = 0;
    int iCols = 0;
    int iComplex = 0;
    SciErr sciErr;

#ifdef TIME_DEBUG
    LARGE_INTEGER iStart, iEnd, iFreq;

    QueryPerformanceFrequency(&iFreq);
    QueryPerformanceCounter(&iStart);
#endif

    iRet = getDatasetDims_v1(_iDatasetId, &iRows, &iCols);
    iComplex = isComplexData_v1(_iDatasetId);
    if (iRet)
    {
        return false;
    }

    if (iRows * iCols != 0)
    {
        if (iComplex)
        {
            pdblReal = (double *)MALLOC(iRows * iCols * sizeof(double));
            pdblImg = (double *)MALLOC(iRows * iCols * sizeof(double));
            iRet = readDoubleComplexMatrix_v1(_iDatasetId, iRows, iCols, pdblReal, pdblImg);
        }
        else
        {
            pdblReal = (double *)MALLOC(iRows * iCols * sizeof(double));
            iRet = readDoubleMatrix_v1(_iDatasetId, iRows, iCols, pdblReal);
        }

        if (iRet)
        {
            FREE(pdblReal);
            if (iComplex)
            {
                FREE(pdblImg);
            }

            return false;
        }
    }
    else
    {
        /*bug 7224 : to close dataset */
        iRet = readEmptyMatrix_v1(_iDatasetId);
        if (iRet)
        {
            return false;
        }

        pdblReal = (double*)MALLOC(sizeof(double) * 1);
        pdblReal[0] = 0;
        iComplex = 0;
    }

    if (_piAddress == NULL)
    {
        if (iComplex)
        {
            sciErr = createNamedComplexMatrixOfDouble(pvCtx, _pstVarname, iRows, iCols, pdblReal, pdblImg);
        }
        else
        {
            sciErr = createNamedMatrixOfDouble(pvCtx, _pstVarname, iRows, iCols, pdblReal);
        }
    }
    else                        //if not null this variable is in a list
    {
        if (iComplex)
        {
            sciErr = createComplexMatrixOfDoubleInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pdblReal, pdblImg);
        }
        else
        {
            sciErr = createMatrixOfDoubleInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pdblReal);
        }
    }

    FREE(pdblReal);
    if (iComplex)
    {
        FREE(pdblImg);
    }

    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return false;
    }

#ifdef PRINT_DEBUG
    char pstMsg[512];

    sprintf(pstMsg, "double_%d (%d x %d)", _iItemPos, iRows, iCols);
    print_tree(pstMsg);
#endif

#ifdef TIME_DEBUG
    QueryPerformanceCounter(&iEnd);
    double dblTime = ((iEnd.QuadPart - iStart.QuadPart) * 1000.0) / iFreq.QuadPart;

    printf("Total Double : %0.3f ms\n\n", dblTime);
#endif

    return true;
}