int readCommonSparseComplexMatrix_v1(int _iDatasetId, int _iComplex, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos,
                                     double *_pdblReal, double *_pdblImg)
{
    hid_t obj = 0;
    hobj_ref_t pRef[3] = {0};
    herr_t status;

    /*
    * Read the data.
    */
    status = H5Dread(_iDatasetId, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pRef);
    if (status < 0)
    {
        return -1;
    }

    //read Row data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[0]);
    status = readInteger32Matrix_v1(obj, 1, _iRows, _piNbItemRow);
    if (status < 0)
    {
        return -1;
    }

    //read cols data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[1]);
    status = readInteger32Matrix_v1(obj, 1, _iNbItem, _piColPos);
    if (status < 0)
    {
        return -1;
    }

    //read sparse data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[2]);

    if (_iComplex)
    {
        status = readDoubleComplexMatrix_v1(obj, 1, _iNbItem, _pdblReal, _pdblImg);
    }
    else
    {
        status = readDoubleMatrix_v1(obj, 1, _iNbItem, _pdblReal);
    }

    if (status < 0)
    {
        return -1;
    }

    return 0;
}
static int readComplexPoly_v1(int _iDatasetId, int *_piNbCoef, double **_pdblReal, double **_pdblImg)
{
    int iRows = 0;
    int iCols = 0;

    //Get the datatype and its size.
    getDatasetDims_v1(_iDatasetId, &iRows, &iCols);

    //Allocate space for string data.
    *_piNbCoef = iRows * iCols;
    *_pdblReal = (double *)MALLOC(*_piNbCoef * sizeof(double));
    *_pdblImg = (double *)MALLOC(*_piNbCoef * sizeof(double));

    //Read the data and return result.
    return readDoubleComplexMatrix_v1(_iDatasetId, 1, *_piNbCoef, *_pdblReal, *_pdblImg);
}
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;
}