2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - 2012 - INRIA - Allan CORNET
4 * Copyright (C) 2011 - INRIA - Michael Baudin
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 * This code is also published under the GPL v3 license.
16 #include "gw_csv_tools.h"
17 #include "api_scilab.h"
21 #include "localization.h"
23 #include "freeArrayOfString.h"
26 #include "strdup_windows.h"
28 #include "stringToComplex.h"
29 #include "csvDefault.h"
30 #include "gw_csv_helpers.h"
31 #include "csv_complex.h"
32 // =============================================================================
33 int sci_csvStringToDouble(char *fname)
38 char **pStringValues = NULL;
40 BOOL bConvertToNan = TRUE;
42 csv_complexArray *ptrCsvComplexArray = NULL;
43 stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
54 bConvertToNan = (BOOL)csv_getArgumentAsScalarBoolean(pvApiCtx, 2, fname, &iErr);
58 pStringValues = csv_getArgumentAsMatrixOfString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
61 ptrCsvComplexArray = stringsToCsvComplexArray((const char**)pStringValues, m1 * n1, getCsvDefaultDecimal(), bConvertToNan, &ierr);
63 freeArrayOfString(pStringValues, m1 * n1);
66 if (ptrCsvComplexArray == NULL)
70 case STRINGTOCOMPLEX_NOT_A_NUMBER:
71 case STRINGTOCOMPLEX_ERROR:
72 Scierror(999, _("%s: can not convert data.\n"), fname);
76 Scierror(999, _("%s: Memory allocation error.\n"), fname);
83 case STRINGTOCOMPLEX_NOT_A_NUMBER:
84 case STRINGTOCOMPLEX_NO_ERROR:
86 if (ptrCsvComplexArray->isComplex)
88 sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
92 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, ptrCsvComplexArray->realPart);
94 freeCsvComplexArray(ptrCsvComplexArray);
95 ptrCsvComplexArray = NULL;
99 case STRINGTOCOMPLEX_MEMORY_ALLOCATION:
101 Scierror(999, _("%s: Memory allocation error.\n"), fname);
105 case STRINGTOCOMPLEX_ERROR:
107 Scierror(999, _("%s: can not convert data.\n"), fname);
113 printError(&sciErr, 0);
123 // =============================================================================