csvRead does not take parameter 'range' into account if parameter 'header' is given
Reported by scilab
test.csv (68 bytes, application/vnd.ms-excel)
Test file
BUG DESCRIPTION:
----------------
The parameter 'range' is not taken into account if the parameter 'header' is given.
It is caused by a wrong parameter evaluation in source file sci_csvRead.c
The parameter 'range' is only evaluated if parameter 'header' is missing, thus only 7 parameters are given.
Another problem is an inconsisty of documentation and behaviour of parameter 'range' (see Scilab Help >> Spreadsheet > csvRead)
According to documentation the default value shall be [], but if it's used an error occurs.
ERROR LOG:
----------
HOW TO REPRODUCE THE BUG:
-------------------------
Use the attached file 'test.csv' for testing.
test.csv:
0, 1, 2, 3, 4
5, 6, 7, 8, 9
10, 11, 12, 13, 14
Test of parameter 'header' to omit first line [ok]:
-->csvRead('test.csv',[],[],'double',[],[],[],1)
ans =
5. 6. 7. 8. 9.
10. 11. 12. 13. 14.
Test of parameter 'range' to get only a subset of values [ok]:
-->csvRead('test.csv',[],[],'double',[],[],[2 1 2 3])
ans =
5. 6. 7.
Test of combination of parameter 'range' and 'header' [failed].
No range taken into account.
-->csvRead('test.csv',[],[],'double',[],[],[2 1 2 3],1)
ans =
5. 6. 7. 8. 9.
10. 11. 12. 13. 14.
Test of default value [] for parameter 'range' [failed]:
-->csvRead('test.csv',[],[],'double',[],[],[])
!--error 999
csvRead: Wrong size for input argument #7: Four entries expected.
I guess this is not found so far, beacuse the parameter is not evaluated when header parameter is given.
OTHER INFORMATION:
------------------
The main problem is caused by sci_csvRead.c, line 80
Wrong code:
if (Rhs == 7)
{
int m7 = 0, n7 = 0;
Correct code:
if (Rhs >= 7)
{
int m7 = 0, n7 = 0;
The second problem (default value not usable) may be fixed by a better input parameter handling.
Sorry, I'm not familiar with the API but the approach may work. I think the developer knows likely better solutions.
if (Rhs >= 7)
{
if !(csv_isEmpty(pvApiCtx, 7)) {
int m7 = 0, n7 = 0;
... // old code
}
}