* read_csv has the same behavior as in the version 5.3.3 12/9012/10
Sylvestre Ledru [Fri, 14 Sep 2012 12:27:39 +0000 (14:27 +0200)]
* csvRead propose double by default
* update of the documentation

Change-Id: I6cfa91f0260fd25379848d16abde990802219635

13 files changed:
scilab/modules/spreadsheet/Makefile.in
scilab/modules/spreadsheet/help/en_US/csvRead.xml
scilab/modules/spreadsheet/help/en_US/read_csv.xml
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvRead.cpp
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvStringToDouble.cpp
scilab/modules/spreadsheet/sci_gateway/cpp/sci_csvTextScan.cpp
scilab/modules/spreadsheet/src/cpp/stringToComplex.c
scilab/modules/spreadsheet/src/cpp/stringToComplex.h
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8532.dia.ref
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8532.tst
scilab/modules/spreadsheet/tests/nonreg_tests/ticket_745.tst
scilab/modules/spreadsheet/tests/unit_tests/csvRead_vs_read_csv.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvRead_vs_read_csv.tst [new file with mode: 0644]

index 069125d..46c72dc 100644 (file)
@@ -697,12 +697,12 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-bt-int.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-bytedecoders.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-checkCsvWriteFormat.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csv_complex.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvDefault.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvIsnum.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvRead.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csv_strsubst.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csvWrite.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csv_complex.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-csv_strsubst.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-getRange.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-latintoutf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscispreadsheet_algo_la-logger.Plo@am__quote@
index 9293f42..c8bc486 100644 (file)
                 
                 <listitem>
                     <para>a 1-by-1 matrix of strings, the type of the output
-                        <literal>M</literal>. Available values are "string" or "double"
-                        (default).
+                        <literal>M</literal>. Available values are "string" or "double" (by default).
+                    </para>
+                    <para>
+                        Note that <link linkend="read_csv">read_csv</link> has "string" as default.
                     </para>
                 </listitem>
             </varlistentry>
         <revhistory>
             <revision>
                 <revnumber>5.4.0</revnumber>
-                <revremark>Function introduced. Based on the 'csv_readwrite' module.</revremark>
+                <revremark>
+                    Function introduced. Based on the 'csv_readwrite' module. The only difference in the behavior compared to <link linkend="read_csv">read_csv</link> is that csvRead will try to convert value to double by default when read_csv will return value as string. 
+                </revremark>
             </revision>
         </revhistory>
     </refsection>
index 858b54c..d7a8a3e 100644 (file)
         </refpurpose>
     </refnamediv>
     <refsection>
+        <title>Description</title>
+        <para>
+            Unlike <link linkend="csvRead">csvRead</link>, the conversion is set to <literal>string</literal> by default to insure the compatibility with previous versions.
+        </para>
+    </refsection>
+    
+    <refsection>
         <title>History</title>
         <revhistory>
             <revision>
index ae50a34..13fb433 100644 (file)
@@ -13,6 +13,8 @@
  *
  */
 #include <string.h>
+#include <stdio.h>
+
 #include "gw_csv_tools.h"
 #include "api_scilab.h"
 #include "Scierror.h"
@@ -202,7 +204,17 @@ int sci_csvRead(char *fname)
     }
     else
     {
-        conversion = strdup(getCsvDefaultConversion());
+        /* read_csv is using a 'string' conversion while csvRead is doing
+           a 'double' conversion */
+        if (strcmp(fname, "read_csv") == 0)
+        {
+            conversion = (char*)MALLOC((strlen("string") + 1) * sizeof(char));
+            strcpy(conversion, "string");
+        }
+        else
+        {
+            conversion = strdup(getCsvDefaultConversion());
+        }
     }
 
     if (Rhs >= 3)
@@ -374,7 +386,7 @@ int sci_csvRead(char *fname)
                 else /* to double */
                 {
                     stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
-                    csv_complexArray *ptrCsvComplexArray = stringsToCvsComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
+                    csv_complexArray *ptrCsvComplexArray = stringsToCsvComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
 
                     if (ptrCsvComplexArray == NULL)
                     {
index 56b63c2..e75b156 100644 (file)
@@ -58,7 +58,7 @@ int sci_csvStringToDouble(char *fname)
     pStringValues = csv_getArgumentAsMatrixOfString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
     if (iErr) return 0;
 
-    ptrCsvComplexArray = stringsToCvsComplexArray((const char**)pStringValues, m1 * n1, getCsvDefaultDecimal(), bConvertToNan, &ierr);
+    ptrCsvComplexArray = stringsToCsvComplexArray((const char**)pStringValues, m1 * n1, getCsvDefaultDecimal(), bConvertToNan, &ierr);
 
     freeArrayOfString(pStringValues, m1 * n1);
     pStringValues = NULL;
index 072560c..85b962c 100644 (file)
@@ -306,7 +306,7 @@ int sci_csvTextScan(char *fname)
                 else /* to double */
                 {
                     stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
-                    csv_complexArray *ptrCsvComplexArray = stringsToCvsComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
+                    csv_complexArray *ptrCsvComplexArray = stringsToCsvComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
                     if (ptrCsvComplexArray == NULL)
                     {
                         freeCsvResult(result);
index 9663d93..f0839a1 100644 (file)
@@ -49,7 +49,7 @@ static char *leftstring(const char *tx, size_t pos);
 static BOOL is_unit_imaginary (const char *src, double *im);
 static double returnNAN(void);
 /* ========================================================================== */
-csv_complexArray *stringsToCvsComplexArray(const char **pSTRs, int nbElements,
+csv_complexArray *stringsToCsvComplexArray(const char **pSTRs, int nbElements,
         const char *decimal,
         BOOL bConvertByNAN,
         stringToComplexError *ierr)
index 938758d..001f490 100644 (file)
@@ -36,7 +36,7 @@ extern "C" {
                                   BOOL bConvertByNAN,
                                   stringToComplexError *ierr);
 
-    csv_complexArray *stringsToCvsComplexArray(const char **pSTRs, int nbElements,
+    csv_complexArray *stringsToCsvComplexArray(const char **pSTRs, int nbElements,
             const char *decimal,
             BOOL bConvertByNAN,
             stringToComplexError *ierr);
index 2c9f83b..b3c62f7 100644 (file)
@@ -21,7 +21,4 @@ if execstr("B = read_csv(TMPDIR + ""/foo.csv"", ["" "", ""\t""]);", "errcatch")
 msg = lasterror();
 if msg <> msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"), "read_csv", 2) then bugmes();quit;end
 if execstr("B1 = read_csv(TMPDIR + ""/foo.csv"", ""\t"");", "errcatch") <> 0 then bugmes();quit;end
-assert_checkequal(A,B1)
- ans  =
-  T  
+assert_checkequal(A,evstr(B1));
index 7fdd578..cd2d18f 100644 (file)
@@ -24,4 +24,5 @@ msg = lasterror();
 if msg <> msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"), "read_csv", 2) then pause, end
 
 if execstr("B1 = read_csv(TMPDIR + ""/foo.csv"", ""\t"");", "errcatch") <> 0 then pause, end
-assert_checkequal(A,B1)
+assert_checkequal(A,evstr(B1));
+
index 8bc5aba..48a64e4 100644 (file)
@@ -25,4 +25,5 @@ assert_checkequal(x, 1.1000000000000001);
 // Example #2
 A = csvTextScan("1,1000000000000001", " ", ",");
 assert_checkequal(A, 1.1000000000000001);
+
 // =============================================================================
diff --git a/scilab/modules/spreadsheet/tests/unit_tests/csvRead_vs_read_csv.dia.ref b/scilab/modules/spreadsheet/tests/unit_tests/csvRead_vs_read_csv.dia.ref
new file mode 100644 (file)
index 0000000..5569513
--- /dev/null
@@ -0,0 +1,101 @@
+// =============================================================================
+// Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
+// =============================================================================
+// <-- JVM NOT MANDATORY -->
+// =============================================================================
+content = ["a b c d e"; ..
+"1 2 3 4 5"; ..
+"2 3 4 5 6"; ..
+"3 4 5 6 7"; ..
+"4 5 6 7 8"; ..
+"5 6 7 8 9"; ..
+"6 7 8 9 10"]
+ content  =
+!a b c d e   !
+!            !
+!1 2 3 4 5   !
+!            !
+!2 3 4 5 6   !
+!            !
+!3 4 5 6 7   !
+!            !
+!4 5 6 7 8   !
+!            !
+!5 6 7 8 9   !
+!            !
+!6 7 8 9 10  !
+filename=TMPDIR+"/foo.csv";
+mputl(content,filename);
+a=read_csv(filename)
+ a  =
+!a b c d e   !
+!            !
+!1 2 3 4 5   !
+!            !
+!2 3 4 5 6   !
+!            !
+!3 4 5 6 7   !
+!            !
+!4 5 6 7 8   !
+!            !
+!5 6 7 8 9   !
+!            !
+!6 7 8 9 10  !
+b=read_csv(filename,[],[],"string")
+ b  =
+!a b c d e   !
+!            !
+!1 2 3 4 5   !
+!            !
+!2 3 4 5 6   !
+!            !
+!3 4 5 6 7   !
+!            !
+!4 5 6 7 8   !
+!            !
+!5 6 7 8 9   !
+!            !
+!6 7 8 9 10  !
+assert_checkequal(a, b);
+a2=csvRead(filename)
+ a2  =
+    Nan      
+    12345.   
+    23456.   
+    34567.   
+    45678.   
+    56789.   
+    678910.  
+b2=csvRead(filename,[],[],"double")
+ b2  =
+    Nan      
+    12345.   
+    23456.   
+    34567.   
+    45678.   
+    56789.   
+    678910.  
+assert_checkequal(a, b);
+b3=csvRead(filename,[],[],"string")
+ b3  =
+!a b c d e   !
+!            !
+!1 2 3 4 5   !
+!            !
+!2 3 4 5 6   !
+!            !
+!3 4 5 6 7   !
+!            !
+!4 5 6 7 8   !
+!            !
+!5 6 7 8 9   !
+!            !
+!6 7 8 9 10  !
+assert_checkequal(a,b3);
+assert_checkequal(b,b3);
diff --git a/scilab/modules/spreadsheet/tests/unit_tests/csvRead_vs_read_csv.tst b/scilab/modules/spreadsheet/tests/unit_tests/csvRead_vs_read_csv.tst
new file mode 100644 (file)
index 0000000..920be14
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
+// =============================================================================
+// <-- JVM NOT MANDATORY -->
+// =============================================================================
+content = ["a b c d e"; ..
+"1 2 3 4 5"; ..
+"2 3 4 5 6"; ..
+"3 4 5 6 7"; ..
+"4 5 6 7 8"; ..
+"5 6 7 8 9"; ..
+"6 7 8 9 10"]
+filename=TMPDIR+"/foo.csv";
+mputl(content,filename);
+
+a=read_csv(filename)
+b=read_csv(filename,[],[],"string")
+assert_checkequal(a, b);
+
+a2=csvRead(filename)
+b2=csvRead(filename,[],[],"double")
+assert_checkequal(a, b);
+
+b3=csvRead(filename,[],[],"string")
+assert_checkequal(a,b3);
+assert_checkequal(b,b3);
\ No newline at end of file