[scilab] fix build: matio update and pkcon usage
Clément David
davidcl at fedoraproject.org
Mon Jul 23 20:30:34 UTC 2012
commit 5566bc9872176871419d203c98c9d6cc01d293f4
Author: Clément DAVID <davidcl at fedoraproject.org>
Date: Mon Jul 23 22:29:36 2012 +0200
fix build: matio update and pkcon usage
0001-Port-to-matio-1.5.patch | 2628 +++++++++++++++++++++++++++
0002-Use-pkcon-to-install-doc-package.patch | 27 +
scilab-matio.patch | 11 -
scilab.spec | 12 +-
4 files changed, 2664 insertions(+), 14 deletions(-)
---
diff --git a/0001-Port-to-matio-1.5.patch b/0001-Port-to-matio-1.5.patch
new file mode 100644
index 0000000..d78e79d
--- /dev/null
+++ b/0001-Port-to-matio-1.5.patch
@@ -0,0 +1,2628 @@
+From 726857aebf0bae1c8251e97885ae68ff6d8010a2 Mon Sep 17 00:00:00 2001
+From: Sylvestre Ledru <sylvestre.ledru at scilab-enterprises.com>
+Date: Mon, 12 Mar 2012 13:31:38 +0100
+Subject: [PATCH 1/2] Port to matio 1.5
+
+Change-Id: Ib15dd089e6172ebb84f5f3b6dbd93741cba0db53
+---
+ scilab/configure | 17 +-
+ scilab/configure.ac | 2 +-
+ scilab/modules/core/includes/machine.h.in | 3 -
+ .../matio/sci_gateway/c/sci_matfile_listvar.c | 198 ++++----
+ .../modules/matio/sci_gateway/c/sci_matfile_open.c | 239 +++++-----
+ .../matio/sci_gateway/c/sci_matfile_varwrite.c | 211 +++++----
+ scilab/modules/matio/src/c/CreateCharVariable.c | 146 +++---
+ scilab/modules/matio/src/c/CreateDoubleVariable.c | 80 ++--
+ scilab/modules/matio/src/c/CreateSparseVariable.c | 291 ++++++------
+ scilab/modules/matio/src/c/CreateStructVariable.c | 169 ++++----
+ scilab/modules/matio/src/c/GetDoubleVariable.c | 134 +++---
+ scilab/modules/matio/src/c/GetSparseVariable.c | 505 ++++++++++----------
+ scilab/modules/matio/src/c/matfile_manager.c | 103 ++--
+ 13 files changed, 1071 insertions(+), 1027 deletions(-)
+
+diff --git a/scilab/configure b/scilab/configure
+index 96e1734..63675d4 100755
+--- a/scilab/configure
++++ b/scilab/configure
+@@ -24818,13 +24818,12 @@ fi
+ CFLAGS="$CFLAGS $MATIO_CFLAGS"
+ LIBS="$LIBS $MATIO_LIBS"
+
+- for ac_header in matio.h matioConfig.h
++ for ac_header in matio.h
+ do :
+- as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+-ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
++ ac_fn_c_check_header_mongrel "$LINENO" "matio.h" "ac_cv_header_matio_h" "$ac_includes_default"
++if test "x$ac_cv_header_matio_h" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+-#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
++#define HAVE_MATIO_H 1
+ _ACEOF
+
+ else
+@@ -24965,7 +24964,7 @@ $as_echo_n "checking saxon... " >&6; }
+ export ac_java_classpath="$jar_resolved:$ac_java_classpath"
+
+ cat << \EOF > conftest.java
+-// #line 24968 "configure"
++// #line 24967 "configure"
+ import com.icl.saxon.Loader;
+
+ public class conftest {
+@@ -25061,7 +25060,7 @@ $as_echo_n "checking jlatexmath-fop... " >&6; }
+ export ac_java_classpath="$jar_resolved:$ac_java_classpath"
+
+ cat << \EOF > conftest.java
+-// #line 25064 "configure"
++// #line 25063 "configure"
+ import org.scilab.forge.jlatexmath.fop.JLaTeXMathObj;
+
+ public class conftest {
+@@ -31360,7 +31359,7 @@ else
+ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+ lt_status=$lt_dlunknown
+ cat > conftest.$ac_ext <<_LT_EOF
+-#line 31363 "configure"
++#line 31362 "configure"
+ #include "confdefs.h"
+
+ #if HAVE_DLFCN_H
+@@ -31466,7 +31465,7 @@ else
+ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+ lt_status=$lt_dlunknown
+ cat > conftest.$ac_ext <<_LT_EOF
+-#line 31469 "configure"
++#line 31468 "configure"
+ #include "confdefs.h"
+
+ #if HAVE_DLFCN_H
+diff --git a/scilab/configure.ac b/scilab/configure.ac
+index 3a83f58..46ed5d6 100644
+--- a/scilab/configure.ac
++++ b/scilab/configure.ac
+@@ -1580,7 +1580,7 @@ if test "$with_matio" != no; then
+ CFLAGS="$CFLAGS $MATIO_CFLAGS"
+ LIBS="$LIBS $MATIO_LIBS"
+
+- AC_CHECK_HEADERS([matio.h matioConfig.h], [],
++ AC_CHECK_HEADERS([matio.h], [],
+ [AC_MSG_ERROR([Invalid MATIO_CFLAGS returned by pkg-config. Try to define MATIO_CFLAGS.])])
+ AC_CHECK_LIB([matio], [Mat_Open], [],
+ [AC_MSG_ERROR([Invalid MATIO_LIBS returned by pkg-config. Try to define MATIO_LIBS.])])
+diff --git a/scilab/modules/core/includes/machine.h.in b/scilab/modules/core/includes/machine.h.in
+index 997a645..643c043 100644
+--- a/scilab/modules/core/includes/machine.h.in
++++ b/scilab/modules/core/includes/machine.h.in
+@@ -176,9 +176,6 @@
+ /* Define to 1 if you have the <malloc.h> header file. */
+ #undef HAVE_MALLOC_H
+
+-/* Define to 1 if you have the <matioConfig.h> header file. */
+-#undef HAVE_MATIOCONFIG_H
+-
+ /* Define to 1 if you have the <matio.h> header file. */
+ #undef HAVE_MATIO_H
+
+diff --git a/scilab/modules/matio/sci_gateway/c/sci_matfile_listvar.c b/scilab/modules/matio/sci_gateway/c/sci_matfile_listvar.c
+index 992d799..6ef4368 100644
+--- a/scilab/modules/matio/sci_gateway/c/sci_matfile_listvar.c
++++ b/scilab/modules/matio/sci_gateway/c/sci_matfile_listvar.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -30,110 +30,116 @@
+ return 0; \
+ }
+
+-int sci_matfile_listvar(char *fname,unsigned long fname_len)
++int sci_matfile_listvar(char *fname, unsigned long fname_len)
+ {
+- int nbRow = 0, nbCol = 0;
+- mat_t *matfile = NULL;
+- matvar_t *matvar = NULL;
+- int fileIndex = 0;
+- char **varnames = NULL;
+- double *varclasses = NULL;
+- double *vartypes = NULL;
+- int nbvar = 0, var_type;
+- int * fd_addr = NULL;
+- double tmp_dbl;
+- SciErr _SciErr;
+-
+- CheckRhs(1, 1);
+- CheckLhs(1, 3);
+-
+- /* First Rhs is the index of the file to read */
+-
+- _SciErr = getVarAddressFromPosition(pvApiCtx, 1, &fd_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, fd_addr, &var_type); MATIO_ERROR;
+-
+- if (var_type == sci_matrix)
++ int nbRow = 0, nbCol = 0;
++ mat_t *matfile = NULL;
++ matvar_t *matvar = NULL;
++ int fileIndex = 0;
++ char **varnames = NULL;
++ double *varclasses = NULL;
++ double *vartypes = NULL;
++ int nbvar = 0, var_type;
++ int * fd_addr = NULL;
++ double tmp_dbl;
++ SciErr _SciErr;
++
++ CheckRhs(1, 1);
++ CheckLhs(1, 3);
++
++ /* First Rhs is the index of the file to read */
++
++ _SciErr = getVarAddressFromPosition(pvApiCtx, 1, &fd_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, fd_addr, &var_type);
++ MATIO_ERROR;
++
++ if (var_type == sci_matrix)
+ {
+- getScalarDouble(pvApiCtx, fd_addr, &tmp_dbl);
+- if (!isScalar(pvApiCtx, fd_addr))
+- {
+- Scierror(999, _("%s: Wrong size for first input argument: Single double expected.\n"), fname);
+- return FALSE;
+- }
+- fileIndex = (int)tmp_dbl;
++ getScalarDouble(pvApiCtx, fd_addr, &tmp_dbl);
++ if (!isScalar(pvApiCtx, fd_addr))
++ {
++ Scierror(999, _("%s: Wrong size for first input argument: Single double expected.\n"), fname);
++ return FALSE;
++ }
++ fileIndex = (int)tmp_dbl;
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for first input argument: Double expected.\n"), fname);
+- return FALSE;
++ Scierror(999, _("%s: Wrong type for first input argument: Double expected.\n"), fname);
++ return FALSE;
+ }
+-
+- /* Gets the corresponding matfile */
+- matfile_manager(MATFILEMANAGER_GETFILE, &fileIndex, &matfile);
+-
+- /* Back to the beginning of the file */
+- if (Mat_Rewind(matfile) != 0)
++
++ /* Gets the corresponding matfile */
++ matfile_manager(MATFILEMANAGER_GETFILE, &fileIndex, &matfile);
++
++ /* Back to the beginning of the file */
++ if (Mat_Rewind(matfile) != 0)
+ {
+- Scierror(999, _("%s: Could not rewind the file %s.\n"), "matfile_listvar", matfile->filename);
+- return FALSE;
++ Scierror(999, _("%s: Could not rewind the file %s.\n"), "matfile_listvar", ""); /* TODO update this: was matfile->filename */
++ return FALSE;
+ }
+-
+- matvar = Mat_VarReadNext(matfile);
+- while (matvar != NULL && matvar->name != NULL)
++
++ matvar = Mat_VarReadNext(matfile);
++ while (matvar != NULL && matvar->name != NULL)
+ {
+- nbvar++;
+- varnames = (char**) REALLOC(varnames, nbvar*sizeof(char*));
+- if (varnames == NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
+- return FALSE;
+- }
+- varnames[nbvar-1] = strdup(matvar->name);
+- varclasses = (double*) REALLOC(varclasses, nbvar*sizeof(double));
+- if (varnames == NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
+- return FALSE;
+- }
+- varclasses[nbvar-1] = (double) matvar->class_type;
+- vartypes = (double*) REALLOC(vartypes, nbvar*sizeof(double));
+- if (varnames == NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
+- return FALSE;
+- }
+- vartypes[nbvar-1] = (double) matvar->data_type;
+-
+- Mat_VarFree(matvar);
+- matvar = Mat_VarReadNext(matfile);
++ nbvar++;
++ varnames = (char**) REALLOC(varnames, nbvar * sizeof(char*));
++ if (varnames == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
++ return FALSE;
++ }
++ varnames[nbvar - 1] = strdup(matvar->name);
++ varclasses = (double*) REALLOC(varclasses, nbvar * sizeof(double));
++ if (varnames == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
++ return FALSE;
++ }
++ varclasses[nbvar - 1] = (double) matvar->class_type;
++ vartypes = (double*) REALLOC(vartypes, nbvar * sizeof(double));
++ if (varnames == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
++ return FALSE;
++ }
++ vartypes[nbvar - 1] = (double) matvar->data_type;
++
++ Mat_VarFree(matvar);
++ matvar = Mat_VarReadNext(matfile);
+ }
+-
+- Mat_VarFree(matvar);
+-
+- /* Return the variable names list */
+- nbRow = nbvar; nbCol = 1;
+- _SciErr = createMatrixOfString(pvApiCtx, Rhs+1, nbRow, nbCol, varnames); MATIO_ERROR;
+- LhsVar(1) = Rhs+1;
+-
+- /* Return the variable classes */
+- if (Lhs >= 2)
++
++ Mat_VarFree(matvar);
++
++ /* Return the variable names list */
++ nbRow = nbvar;
++ nbCol = 1;
++ _SciErr = createMatrixOfString(pvApiCtx, Rhs + 1, nbRow, nbCol, varnames);
++ MATIO_ERROR;
++ LhsVar(1) = Rhs + 1;
++
++ /* Return the variable classes */
++ if (Lhs >= 2)
+ {
+- _SciErr = createMatrixOfDouble(pvApiCtx, Rhs+2, nbRow, nbCol, varclasses); MATIO_ERROR;
+- LhsVar(2) = Rhs+2;
++ _SciErr = createMatrixOfDouble(pvApiCtx, Rhs + 2, nbRow, nbCol, varclasses);
++ MATIO_ERROR;
++ LhsVar(2) = Rhs + 2;
+ }
+-
+- /* Return the variable types */
+- if (Lhs >= 3)
++
++ /* Return the variable types */
++ if (Lhs >= 3)
+ {
+- _SciErr = createMatrixOfDouble(pvApiCtx, Rhs+3, nbRow, nbCol, vartypes); MATIO_ERROR;
+- LhsVar(3) = Rhs+3;
++ _SciErr = createMatrixOfDouble(pvApiCtx, Rhs + 3, nbRow, nbCol, vartypes);
++ MATIO_ERROR;
++ LhsVar(3) = Rhs + 3;
+ }
+-
+- freeArrayOfString(varnames, nbvar);
+- FREE(varclasses);
+- FREE(vartypes);
+-
+- PutLhsVar();
+-
+- return TRUE;
++
++ freeArrayOfString(varnames, nbvar);
++ FREE(varclasses);
++ FREE(vartypes);
++
++ PutLhsVar();
++
++ return TRUE;
+ }
+diff --git a/scilab/modules/matio/sci_gateway/c/sci_matfile_open.c b/scilab/modules/matio/sci_gateway/c/sci_matfile_open.c
+index efa956f..a13a554 100644
+--- a/scilab/modules/matio/sci_gateway/c/sci_matfile_open.c
++++ b/scilab/modules/matio/sci_gateway/c/sci_matfile_open.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -30,131 +30,136 @@
+ Interface for MATIO function called Mat_Open
+ Scilab function name : matfile_open
+ *******************************************************************************/
+-int sci_matfile_open(char *fname,unsigned long fname_len)
++int sci_matfile_open(char *fname, unsigned long fname_len)
+ {
+- int nbRow = 0, nbCol = 0;
+- mat_t *matfile;
+- int fileIndex = 0;
+- char * filename = NULL;
+- char * optionStr = NULL;
+- int option = 0, var_type;
+- int * filename_addr = NULL, * option_addr = NULL;
+- SciErr _SciErr;
+-
+- CheckRhs(1, 2);
+- CheckLhs(1, 1);
+-
+- _SciErr = getVarAddressFromPosition(pvApiCtx, 1, &filename_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, filename_addr, &var_type); MATIO_ERROR;
+-
+- if (var_type == sci_strings)
++ int nbRow = 0, nbCol = 0;
++ mat_t *matfile;
++ int fileIndex = 0;
++ char * filename = NULL;
++ char * optionStr = NULL;
++ int option = 0, var_type;
++ int * filename_addr = NULL, * option_addr = NULL;
++ SciErr _SciErr;
++
++ CheckRhs(1, 2);
++ CheckLhs(1, 1);
++
++ _SciErr = getVarAddressFromPosition(pvApiCtx, 1, &filename_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, filename_addr, &var_type);
++ MATIO_ERROR;
++
++ if (var_type == sci_strings)
+ {
+- getAllocatedSingleString(pvApiCtx, filename_addr, &filename);
+- _SciErr = getVarDimension(pvApiCtx, filename_addr, &nbRow, &nbCol);
+- MATIO_ERROR;
+-
+- if (nbCol != 1)
+- {
+- Scierror(999, _("%s: Wrong size for first input argument: Single string expected.\n"), fname);
+-
+- freeAllocatedSingleString(filename);
+-
+- return FALSE;
+- }
++ getAllocatedSingleString(pvApiCtx, filename_addr, &filename);
++ _SciErr = getVarDimension(pvApiCtx, filename_addr, &nbRow, &nbCol);
++ MATIO_ERROR;
++
++ if (nbCol != 1)
++ {
++ Scierror(999, _("%s: Wrong size for first input argument: Single string expected.\n"), fname);
++
++ freeAllocatedSingleString(filename);
++
++ return FALSE;
++ }
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for first input argument: Single string expected.\n"), fname);
+-
+- freeAllocatedSingleString(filename);
+-
+- return FALSE;
++ Scierror(999, _("%s: Wrong type for first input argument: Single string expected.\n"), fname);
++
++ freeAllocatedSingleString(filename);
++
++ return FALSE;
+ }
+-
+- if (Rhs == 2)
++
++ if (Rhs == 2)
+ {
+- _SciErr = getVarAddressFromPosition(pvApiCtx, 2, &option_addr); MATIO_ERROR;
+-
+- _SciErr = getVarType(pvApiCtx, option_addr, &var_type); MATIO_ERROR;
+-
+- if (var_type == sci_strings)
+- {
+- getAllocatedSingleString(pvApiCtx, option_addr, &optionStr);
+- _SciErr = getVarDimension(pvApiCtx, option_addr, &nbRow, &nbCol); MATIO_ERROR;
+-
+- if (nbCol != 1)
+- {
+- Scierror(999, _("%s: Wrong size for second input argument: Single string expected.\n"), fname);
+-
+- freeAllocatedSingleString(filename);
+- freeAllocatedSingleString(optionStr);
+-
+- return FALSE;
+- }
+-
+- if (strcmp(optionStr, "r")==0)
+- {
+- option = MAT_ACC_RDONLY;
+- }
+- else if (strcmp(optionStr, "w")==0)
+- {
+- option = 0; // MAT_ACC_RDWR option will be used for append mode
+- }
+- else
+- {
+- Scierror(999, _("%s: Wrong value for second input argument: 'r' or 'w' expected.\n"), fname);
+-
+- freeAllocatedSingleString(filename);
+- freeAllocatedSingleString(optionStr);
+-
+- return FALSE;
+- }
+- }
+- else
+- {
+- Scierror(999, _("%s: Wrong type for second input argument: Single string expected.\n"), fname);
+-
+- freeAllocatedSingleString(filename);
+- freeAllocatedSingleString(optionStr);
+-
+- return FALSE;
+- }
++ _SciErr = getVarAddressFromPosition(pvApiCtx, 2, &option_addr);
++ MATIO_ERROR;
++
++ _SciErr = getVarType(pvApiCtx, option_addr, &var_type);
++ MATIO_ERROR;
++
++ if (var_type == sci_strings)
++ {
++ getAllocatedSingleString(pvApiCtx, option_addr, &optionStr);
++ _SciErr = getVarDimension(pvApiCtx, option_addr, &nbRow, &nbCol);
++ MATIO_ERROR;
++
++ if (nbCol != 1)
++ {
++ Scierror(999, _("%s: Wrong size for second input argument: Single string expected.\n"), fname);
++
++ freeAllocatedSingleString(filename);
++ freeAllocatedSingleString(optionStr);
++
++ return FALSE;
++ }
++
++ if (strcmp(optionStr, "r") == 0)
++ {
++ option = MAT_ACC_RDONLY;
++ }
++ else if (strcmp(optionStr, "w") == 0)
++ {
++ option = MAT_ACC_RDWR; // MAT_ACC_RDWR option will be used for append mode
++ }
++ else
++ {
++ Scierror(999, _("%s: Wrong value for second input argument: 'r' or 'w' expected.\n"), fname);
++
++ freeAllocatedSingleString(filename);
++ freeAllocatedSingleString(optionStr);
++
++ return FALSE;
++ }
++ }
++ else
++ {
++ Scierror(999, _("%s: Wrong type for second input argument: Single string expected.\n"), fname);
++
++ freeAllocatedSingleString(filename);
++ freeAllocatedSingleString(optionStr);
++
++ return FALSE;
++ }
+ }
+- else
++ else
+ {
+- /* Default option value */
+- option = MAT_ACC_RDONLY;
++ /* Default option value */
++ option = MAT_ACC_RDONLY;
+ }
+-
+- /* Try to open the file (as a Matlab 5 file) */
+- matfile = Mat_Open(filename, option);
+-
+- if(matfile==NULL) /* Opening failed */
++
++ /* Try to open the file (as a Matlab 5 file) */
++ matfile = Mat_Open(filename, option);
++
++ if (matfile == NULL) /* Opening failed */
+ {
+- /* Try to open the file (as a Matlab 4 file) */
+- matfile = Mat_Open(filename, option | MAT_FT_MAT4);
+-
+- if(matfile==NULL) /* Opening failed */
+- {
+- /* Function returns -1 */
+- fileIndex = -1;
+- }
++ /* Try to open the file (as a Matlab 4 file) */
++ matfile = Mat_Open(filename, option | MAT_FT_MAT4);
++
++ if (matfile == NULL) /* Opening failed */
++ {
++ /* Function returns -1 */
++ fileIndex = -1;
++ }
+ }
+-
+- if (matfile != NULL) /* Opening succeed */
++
++ if (matfile != NULL) /* Opening succeed */
+ {
+- /* Add the file to the manager */
+- matfile_manager(MATFILEMANAGER_ADDFILE, &fileIndex, &matfile);
++ /* Add the file to the manager */
++ matfile_manager(MATFILEMANAGER_ADDFILE, &fileIndex, &matfile);
+ }
+-
+- /* Return the index */
+- createScalarDouble(pvApiCtx, Rhs+1, (double)fileIndex);
+-
+- freeAllocatedSingleString(filename);
+- freeAllocatedSingleString(optionStr);
+-
+- LhsVar(1) = Rhs+1;
+- PutLhsVar();
+-
+- return TRUE;
++
++ /* Return the index */
++ createScalarDouble(pvApiCtx, Rhs + 1, (double)fileIndex);
++
++ freeAllocatedSingleString(filename);
++ freeAllocatedSingleString(optionStr);
++
++ LhsVar(1) = Rhs + 1;
++ PutLhsVar();
++
++ return TRUE;
+ }
+diff --git a/scilab/modules/matio/sci_gateway/c/sci_matfile_varwrite.c b/scilab/modules/matio/sci_gateway/c/sci_matfile_varwrite.c
+index 19e4d09..64fd78a 100644
+--- a/scilab/modules/matio/sci_gateway/c/sci_matfile_varwrite.c
++++ b/scilab/modules/matio/sci_gateway/c/sci_matfile_varwrite.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -25,117 +25,126 @@
+ return 0; \
+ }
+
+-enum matfile_errors {
+- NO_MORE_VARIABLES = -1,
+- UNKNOWN_VARIABLE_TYPE = 0
++enum matfile_errors
++{
++ NO_MORE_VARIABLES = -1,
++ UNKNOWN_VARIABLE_TYPE = 0
+ };
+
+-int sci_matfile_varwrite(char *fname,unsigned long fname_len)
++int sci_matfile_varwrite(char *fname, unsigned long fname_len)
+ {
+- int nbRow = 0, nbCol = 0;
+- mat_t *matfile = NULL;
+- matvar_t *matvar = NULL;
+- int fileIndex = 0;
+- char *varname = NULL;
+- int flag = 0;
+- int compressionFlag = 0;
+- int var_type;
+- int * fd_addr = NULL, * name_addr = NULL, * cp_flag_addr = NULL;
+- double tmp_dbl;
+- SciErr _SciErr;
+-
+- CheckRhs(4, 4);
+- CheckLhs(1, 1);
+-
+- /* Input argument is the index of the file to write */
+-
+- _SciErr = getVarAddressFromPosition(pvApiCtx, 1, &fd_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, fd_addr, &var_type); MATIO_ERROR;
+-
+- if (var_type == sci_matrix)
++ int nbRow = 0, nbCol = 0;
++ mat_t *matfile = NULL;
++ matvar_t *matvar = NULL;
++ int fileIndex = 0;
++ char *varname = NULL;
++ int flag = 0;
++ int compressionFlag = 0;
++ int var_type;
++ int * fd_addr = NULL, * name_addr = NULL, * cp_flag_addr = NULL;
++ double tmp_dbl;
++ SciErr _SciErr;
++
++ CheckRhs(4, 4);
++ CheckLhs(1, 1);
++
++ /* Input argument is the index of the file to write */
++
++ _SciErr = getVarAddressFromPosition(pvApiCtx, 1, &fd_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, fd_addr, &var_type);
++ MATIO_ERROR;
++
++ if (var_type == sci_matrix)
+ {
+- getScalarDouble(pvApiCtx, fd_addr, &tmp_dbl);
+- if (!isScalar(pvApiCtx, fd_addr))
+- {
+- Scierror(999, _("%s: Wrong size for first input argument: Single double expected.\n"), fname);
+- return FALSE;
+- }
+- fileIndex = (int)tmp_dbl;
++ getScalarDouble(pvApiCtx, fd_addr, &tmp_dbl);
++ if (!isScalar(pvApiCtx, fd_addr))
++ {
++ Scierror(999, _("%s: Wrong size for first input argument: Single double expected.\n"), fname);
++ return FALSE;
++ }
++ fileIndex = (int)tmp_dbl;
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for first input argument: Double expected.\n"), fname);
+- return FALSE;
++ Scierror(999, _("%s: Wrong type for first input argument: Double expected.\n"), fname);
++ return FALSE;
+ }
+-
+- /* Gets the corresponding matfile */
+- matfile_manager(MATFILEMANAGER_GETFILE, &fileIndex, &matfile);
+-
+- /* Second argument is the variable name */
+-
+- _SciErr = getVarAddressFromPosition(pvApiCtx, 2, &name_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, name_addr, &var_type); MATIO_ERROR;
+-
+- if (var_type == sci_strings)
++
++ /* Gets the corresponding matfile */
++ matfile_manager(MATFILEMANAGER_GETFILE, &fileIndex, &matfile);
++
++ /* Second argument is the variable name */
++
++ _SciErr = getVarAddressFromPosition(pvApiCtx, 2, &name_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, name_addr, &var_type);
++ MATIO_ERROR;
++
++ if (var_type == sci_strings)
+ {
+- getAllocatedSingleString(pvApiCtx, name_addr, &varname);
+- _SciErr = getVarDimension(pvApiCtx, name_addr, &nbRow, &nbCol); MATIO_ERROR;
+- if (nbCol != 1)
+- {
+- Scierror(999, _("%s: Wrong size for second input argument: Single string expected.\n"), fname);
+-
+- freeAllocatedSingleString(varname);
+-
+- return FALSE;
+- }
++ getAllocatedSingleString(pvApiCtx, name_addr, &varname);
++ _SciErr = getVarDimension(pvApiCtx, name_addr, &nbRow, &nbCol);
++ MATIO_ERROR;
++ if (nbCol != 1)
++ {
++ Scierror(999, _("%s: Wrong size for second input argument: Single string expected.\n"), fname);
++
++ freeAllocatedSingleString(varname);
++
++ return FALSE;
++ }
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for second input argument: Single string expected.\n"), fname);
+-
+- freeAllocatedSingleString(varname);
+-
+- return FALSE;
++ Scierror(999, _("%s: Wrong type for second input argument: Single string expected.\n"), fname);
++
++ freeAllocatedSingleString(varname);
++
++ return FALSE;
+ }
+-
+- /* Third argument is the variable data */
+- matvar = GetMatlabVariable(3, varname, matfile->version, NULL, -1);
+-
+- /* Fourth argument is the compression flag */
+-
+- _SciErr = getVarAddressFromPosition(pvApiCtx, 4, &cp_flag_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, cp_flag_addr, &var_type); MATIO_ERROR;
+-
+- if (var_type == sci_boolean)
++
++ /* Third argument is the variable data */
++ /* TODO update this NULL */
++ matvar = GetMatlabVariable(3, varname, NULL, NULL, -1);
++
++ /* Fourth argument is the compression flag */
++
++ _SciErr = getVarAddressFromPosition(pvApiCtx, 4, &cp_flag_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, cp_flag_addr, &var_type);
++ MATIO_ERROR;
++
++ if (var_type == sci_boolean)
+ {
+- getScalarBoolean(pvApiCtx, cp_flag_addr, &compressionFlag);
+- if (!isScalar(pvApiCtx, cp_flag_addr))
+- {
+- Scierror(999, _("%s: Wrong size for fourth input argument: Single boolean expected.\n"), fname);
+-
+- freeAllocatedSingleString(varname);
+-
+- return FALSE;
+- }
++ getScalarBoolean(pvApiCtx, cp_flag_addr, &compressionFlag);
++ if (!isScalar(pvApiCtx, cp_flag_addr))
++ {
++ Scierror(999, _("%s: Wrong size for fourth input argument: Single boolean expected.\n"), fname);
++
++ freeAllocatedSingleString(varname);
++
++ return FALSE;
++ }
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for fourth input argument: Single boolean expected.\n"), fname);
+-
+- freeAllocatedSingleString(varname);
+-
+- return FALSE;
++ Scierror(999, _("%s: Wrong type for fourth input argument: Single boolean expected.\n"), fname);
++
++ freeAllocatedSingleString(varname);
++
++ return FALSE;
+ }
+-
+- flag = Mat_VarWrite(matfile, matvar, compressionFlag);
+-
+- /* Return execution flag */
+- var_type = (flag==0);
+- createScalarBoolean(pvApiCtx, Rhs+1, var_type);
+-
+- freeAllocatedSingleString(varname);
+- LhsVar(1) = Rhs+1;
+- PutLhsVar();
+-
+- return TRUE;
++
++ flag = Mat_VarWrite(matfile, matvar, compressionFlag);
++
++ /* Return execution flag */
++ var_type = (flag == 0);
++ createScalarBoolean(pvApiCtx, Rhs + 1, var_type);
++
++ freeAllocatedSingleString(varname);
++ LhsVar(1) = Rhs + 1;
++ PutLhsVar();
++
++ return TRUE;
+ }
+diff --git a/scilab/modules/matio/src/c/CreateCharVariable.c b/scilab/modules/matio/src/c/CreateCharVariable.c
+index c51e76c..f727644 100644
+--- a/scilab/modules/matio/src/c/CreateCharVariable.c
++++ b/scilab/modules/matio/src/c/CreateCharVariable.c
+@@ -30,86 +30,90 @@
+
+ int CreateCharVariable(int iVar, matvar_t *matVariable, int * parent, int item_position)
+ {
+- int nbRow = 0, nbCol = 0;
+- char **charData = NULL;
+- int K = 0, L = 0;
+- SciErr _SciErr;
++ int nbRow = 0, nbCol = 0;
++ char **charData = NULL;
++ int K = 0, L = 0;
++ SciErr _SciErr;
+
+- if(matVariable->rank==2) /* 2-D array */
++ if (matVariable->rank == 2) /* 2-D array */
+ {
+- nbRow = matVariable->dims[0];
+- nbCol = nbRow==0 ? 0 : 1; /* In Scilab empty string has size 0x0 */
++ nbRow = matVariable->dims[0];
++ nbCol = nbRow == 0 ? 0 : 1; /* In Scilab empty string has size 0x0 */
+
+- if (nbRow != 0)
+- {
+- charData = (char**) MALLOC(sizeof(char*) * nbRow);
+- if (charData==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable");
+- return FALSE;
+- }
+- }
++ if (nbRow != 0)
++ {
++ charData = (char**) MALLOC(sizeof(char*) * nbRow);
++ if (charData == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable");
++ return FALSE;
++ }
++ }
+
+- for (K=0; K<nbRow; K++)
+- {
+- charData[K] = (char*) MALLOC(sizeof(char*) * (matVariable->dims[1] + 1));
+- if (charData[K]==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable");
+- return FALSE;
+- }
+- }
++ for (K = 0; K < nbRow; K++)
++ {
++ charData[K] = (char*) MALLOC(sizeof(char*) * (matVariable->dims[1] + 1));
++ if (charData[K] == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable");
++ return FALSE;
++ }
++ }
+
+- /* Fill items: data in Matlab file is stored columnwise */
+- for(K=0; K<matVariable->dims[0]; K++) /* Loop over items */
+- {
+- for(L=0; L<matVariable->dims[1]; L++) /* Loop over chars */
+- {
+- if (matVariable->fp->version != MAT_FT_MAT4) /* MAT_FT_MAT4 format ==> data is a char* pointer */
+- {
+- charData[K][L] = ((char *)matVariable->data)[L*matVariable->dims[0]+K];
+- }
+- else /* MAT_FT_MAT4 format ==> data is a double* pointer */
+- {
+- charData[K][L] = (char) ((double *)matVariable->data)[L*matVariable->dims[0]+K];
+- }
+- }
+- charData[K][L] = '\0';
+- }
++ /* Fill items: data in Matlab file is stored columnwise */
++ for (K = 0; K < matVariable->dims[0]; K++) /* Loop over items */
++ {
++ for (L = 0; L < matVariable->dims[1]; L++) /* Loop over chars */
++ {
++ /* TODO was: matVariable->fp->version */
++ if ( 0x0100 != MAT_FT_MAT4) /* MAT_FT_MAT4 format ==> data is a char* pointer */
++ {
++ charData[K][L] = ((char *)matVariable->data)[L * matVariable->dims[0] + K];
++ }
++ else /* MAT_FT_MAT4 format ==> data is a double* pointer */
++ {
++ charData[K][L] = (char) ((double *)matVariable->data)[L * matVariable->dims[0] + K];
++ }
++ }
++ charData[K][L] = '\0';
++ }
+
+- if (nbRow*nbCol != 0)
+- {
+- if (parent==NULL)
+- {
+- _SciErr = createMatrixOfString(pvApiCtx, iVar, nbRow, nbCol, charData); MATIO_ERROR;
+- }
+- else
+- {
+- _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, charData); MATIO_ERROR;
+- }
+- }
+- else /* Empty character string */
+- {
+- if (parent==NULL)
+- {
+- createSingleString(pvApiCtx, iVar, "\0");
+- }
+- else
+- {
+- char ** tmp_char = (char **)MALLOC(sizeof(char *));
+- tmp_char[0] = strdup("\0");
+- _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, parent, item_position, 1, 1, tmp_char); MATIO_ERROR;
+- freeArrayOfString(tmp_char, 1);
+- }
+- }
++ if (nbRow*nbCol != 0)
++ {
++ if (parent == NULL)
++ {
++ _SciErr = createMatrixOfString(pvApiCtx, iVar, nbRow, nbCol, charData);
++ MATIO_ERROR;
++ }
++ else
++ {
++ _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, charData);
++ MATIO_ERROR;
++ }
++ }
++ else /* Empty character string */
++ {
++ if (parent == NULL)
++ {
++ createSingleString(pvApiCtx, iVar, "\0");
++ }
++ else
++ {
++ char ** tmp_char = (char **)MALLOC(sizeof(char *));
++ tmp_char[0] = strdup("\0");
++ _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, parent, item_position, 1, 1, tmp_char);
++ MATIO_ERROR;
++ freeArrayOfString(tmp_char, 1);
++ }
++ }
+
+- freeArrayOfString(charData,nbRow*nbCol);
++ freeArrayOfString(charData, nbRow * nbCol);
+ }
+- else /* Multi-dimension array -> Scilab HyperMatrix */
++ else /* Multi-dimension array -> Scilab HyperMatrix */
+ {
+- Scierror(999, _("%s: N-D arrays of chars not implemented.\n"), "CreateCharVariable");
+- return FALSE;
++ Scierror(999, _("%s: N-D arrays of chars not implemented.\n"), "CreateCharVariable");
++ return FALSE;
+ }
+
+- return TRUE;
++ return TRUE;
+ }
+diff --git a/scilab/modules/matio/src/c/CreateDoubleVariable.c b/scilab/modules/matio/src/c/CreateDoubleVariable.c
+index 37a0edf..00bc988 100644
+--- a/scilab/modules/matio/src/c/CreateDoubleVariable.c
++++ b/scilab/modules/matio/src/c/CreateDoubleVariable.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -22,53 +22,55 @@
+
+ int CreateDoubleVariable(int iVar, matvar_t *matVariable, int * parent, int item_position)
+ {
+- int nbRow = 0, nbCol = 0;
+- struct ComplexSplit *mat5ComplexData = NULL;
+- SciErr _SciErr;
++ int nbRow = 0, nbCol = 0;
++ struct mat_complex_split_t *mat5ComplexData = NULL;
++ SciErr _SciErr;
+
+- if(matVariable->rank==2) /* 2-D array */
++ if (matVariable->rank == 2) /* 2-D array */
+ {
+- nbRow = matVariable->dims[0];
+- nbCol = matVariable->dims[1];
+- if (matVariable->isComplex == 0)
++ nbRow = matVariable->dims[0];
++ nbCol = matVariable->dims[1];
++ if (matVariable->isComplex == 0)
+ {
+- if (parent==NULL)
+- {
+- _SciErr = createMatrixOfDouble(pvApiCtx, iVar, nbRow, nbCol, matVariable->data); MATIO_ERROR;
+- }
+- else
+- {
+- _SciErr = createMatrixOfDoubleInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, matVariable->data); MATIO_ERROR;
+- }
++ if (parent == NULL)
++ {
++ _SciErr = createMatrixOfDouble(pvApiCtx, iVar, nbRow, nbCol, matVariable->data);
++ MATIO_ERROR;
++ }
++ else
++ {
++ _SciErr = createMatrixOfDoubleInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, matVariable->data);
++ MATIO_ERROR;
++ }
+ }
+- else
++ else
+ {
+- /* Since MATIO 1.3.2 data is a ComplexSplit for MAT4 and MAT5 formats */
+- mat5ComplexData = matVariable->data;
+- if (parent==NULL)
+- {
+- _SciErr = createComplexMatrixOfDouble(pvApiCtx, iVar, nbRow, nbCol, mat5ComplexData->Re, mat5ComplexData->Im);
+- }
+- else
+- {
+- _SciErr = createComplexMatrixOfDoubleInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol,
+- mat5ComplexData->Re, mat5ComplexData->Im);
+- }
++ /* Since MATIO 1.3.2 data is a ComplexSplit for MAT4 and MAT5 formats */
++ mat5ComplexData = matVariable->data;
++ if (parent == NULL)
++ {
++ _SciErr = createComplexMatrixOfDouble(pvApiCtx, iVar, nbRow, nbCol, mat5ComplexData->Re, mat5ComplexData->Im);
++ }
++ else
++ {
++ _SciErr = createComplexMatrixOfDoubleInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol,
++ mat5ComplexData->Re, mat5ComplexData->Im);
++ }
+ }
+ }
+- else /* Multi-dimension array -> Scilab HyperMatrix */
++ else /* Multi-dimension array -> Scilab HyperMatrix */
+ {
+- if (matVariable->isComplex == 0)
++ if (matVariable->isComplex == 0)
+ {
+- CreateHyperMatrixVariable(iVar, MATRIX_OF_DOUBLE_DATATYPE, &matVariable->isComplex, &matVariable->rank,
+- matVariable->dims, matVariable->data, NULL, parent, item_position);
++ CreateHyperMatrixVariable(iVar, MATRIX_OF_DOUBLE_DATATYPE, &matVariable->isComplex, &matVariable->rank,
++ matVariable->dims, matVariable->data, NULL, parent, item_position);
+ }
+- else
++ else
+ {
+- mat5ComplexData = matVariable->data;
+- CreateHyperMatrixVariable(iVar, MATRIX_OF_DOUBLE_DATATYPE, &matVariable->isComplex, &matVariable->rank,
+- matVariable->dims, mat5ComplexData->Re, mat5ComplexData->Im, parent, item_position);
++ mat5ComplexData = matVariable->data;
++ CreateHyperMatrixVariable(iVar, MATRIX_OF_DOUBLE_DATATYPE, &matVariable->isComplex, &matVariable->rank,
++ matVariable->dims, mat5ComplexData->Re, mat5ComplexData->Im, parent, item_position);
+ }
+ }
+- return TRUE;
++ return TRUE;
+ }
+diff --git a/scilab/modules/matio/src/c/CreateSparseVariable.c b/scilab/modules/matio/src/c/CreateSparseVariable.c
+index ee4c2c4..90e44ee 100644
+--- a/scilab/modules/matio/src/c/CreateSparseVariable.c
++++ b/scilab/modules/matio/src/c/CreateSparseVariable.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -27,188 +27,191 @@
+ }
+
+ /* Defined in SCI/modules/sparse/src/fortran/spt.f */
+-extern int C2F(spt)(int *m, int *n, int *nel, int *it, int *workArray,
+- double *A_R, double *A_I, int *A_mnel, int *A_icol,
+- double *At_R, double *At_I, int *At_mnel, int *At_icol);
+-
++extern int C2F(spt)(int *m, int *n, int *nel, int *it, int *workArray,
++ double *A_R, double *A_I, int *A_mnel, int *A_icol,
++ double *At_R, double *At_I, int *At_mnel, int *At_icol);
++
+ int CreateSparseVariable(int iVar, matvar_t *matVariable, int * parent, int item_position)
+ {
+- int K = 0;
+- sparse_t *sparseData = NULL;
+- SciSparse *scilabSparse = NULL;
+- SciSparse *scilabSparseT = NULL; /* Transpose */
+- int *colIndexes = NULL;
+- int *rowIndexes = NULL;
+- int *workArray = NULL;
+- struct ComplexSplit *complexData = NULL;
+- SciErr _SciErr;
+-
+- sparseData = (sparse_t*) matVariable->data;
+-
+- scilabSparse = (SciSparse*) MALLOC(sizeof(SciSparse));
+- if (scilabSparse==NULL)
++ int K = 0;
++ mat_sparse_t *sparseData = NULL;
++ SciSparse *scilabSparse = NULL;
++ SciSparse *scilabSparseT = NULL; /* Transpose */
++ int *colIndexes = NULL;
++ int *rowIndexes = NULL;
++ int *workArray = NULL;
++ struct mat_complex_split_t *complexData = NULL;
++ SciErr _SciErr;
++
++ sparseData = (mat_sparse_t*) matVariable->data;
++
++ scilabSparse = (SciSparse*) MALLOC(sizeof(SciSparse));
++ if (scilabSparse == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
+ }
+
+- /* Computes column indexes from Matlab indexes */
+- if (sparseData->njc > 1)
++ /* Computes column indexes from Matlab indexes */
++ if (sparseData->njc > 1)
+ {
+- colIndexes = (int*) MALLOC(sizeof(int) * (sparseData->njc-1));
+- if (colIndexes==NULL)
++ colIndexes = (int*) MALLOC(sizeof(int) * (sparseData->njc - 1));
++ if (colIndexes == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
+ }
+-
+- for (K=0; K<sparseData->njc-1; K++)
++
++ for (K = 0; K < sparseData->njc - 1; K++)
+ {
+- colIndexes[K] = sparseData->jc[K+1] - sparseData->jc[K];
++ colIndexes[K] = sparseData->jc[K + 1] - sparseData->jc[K];
+ }
+ }
+
+- /* Computes row indexes from Matlab indexes */
+- rowIndexes = (int*) MALLOC(sizeof(int) * sparseData->nir);
+- if (rowIndexes==NULL)
++ /* Computes row indexes from Matlab indexes */
++ rowIndexes = (int*) MALLOC(sizeof(int) * sparseData->nir);
++ if (rowIndexes == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
+ }
+
+- for (K=0; K<sparseData->nir; K++)
++ for (K = 0; K < sparseData->nir; K++)
+ {
+- rowIndexes[K] = sparseData->ir[K] + 1;
++ rowIndexes[K] = sparseData->ir[K] + 1;
+ }
+
+- /* Create sparse matrix to be transposed */
+- scilabSparse->m = matVariable->dims[1];
+- scilabSparse->n = matVariable->dims[0];
+- scilabSparse->it = matVariable->isComplex;
+- scilabSparse->nel = sparseData->ndata;
+- scilabSparse->mnel = colIndexes;
+- scilabSparse->icol = rowIndexes;
++ /* Create sparse matrix to be transposed */
++ scilabSparse->m = matVariable->dims[1];
++ scilabSparse->n = matVariable->dims[0];
++ scilabSparse->it = matVariable->isComplex;
++ scilabSparse->nel = sparseData->ndata;
++ scilabSparse->mnel = colIndexes;
++ scilabSparse->icol = rowIndexes;
+
+- if (scilabSparse->it == 0)
++ if (scilabSparse->it == 0)
+ {
+- scilabSparse->R = (double*) sparseData->data;
+- scilabSparse->I = NULL;
++ scilabSparse->R = (double*) sparseData->data;
++ scilabSparse->I = NULL;
+ }
+- else
++ else
+ {
+- complexData = (struct ComplexSplit *) sparseData->data;
+- scilabSparse->R = (double *) complexData->Re;
+- scilabSparse->I = (double *) complexData->Im;
++ complexData = (struct mat_complex_split_t *) sparseData->data;
++ scilabSparse->R = (double *) complexData->Re;
++ scilabSparse->I = (double *) complexData->Im;
+ }
+
+- /* Create transpose */
+- scilabSparseT = (SciSparse*) MALLOC(sizeof(SciSparse));
+- if (scilabSparseT==NULL)
++ /* Create transpose */
++ scilabSparseT = (SciSparse*) MALLOC(sizeof(SciSparse));
++ if (scilabSparseT == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
+ }
+
+- scilabSparseT->m = scilabSparse->n;
+- scilabSparseT->n = scilabSparse->m;
+- scilabSparseT->it = scilabSparse->it;
+- scilabSparseT->nel = scilabSparse->nel;
++ scilabSparseT->m = scilabSparse->n;
++ scilabSparseT->n = scilabSparse->m;
++ scilabSparseT->it = scilabSparse->it;
++ scilabSparseT->nel = scilabSparse->nel;
++
++ if (scilabSparseT->m == 0)
++ {
++ workArray = (int*) MALLOC(sizeof(int));
++ }
++ else
++ {
++ workArray = (int*) MALLOC(sizeof(int) * scilabSparseT->m);
++ }
+
+- if (scilabSparseT->m == 0)
++ if (workArray == NULL)
+ {
+- workArray = (int*) MALLOC(sizeof(int));
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
+ }
+- else
++
++ if (scilabSparseT->m != 0)
+ {
+- workArray = (int*) MALLOC(sizeof(int) * scilabSparseT->m);
++ scilabSparseT->mnel = (int*) MALLOC(sizeof(int) * scilabSparseT->m);
++ if (scilabSparseT->mnel == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
++ }
+ }
+
+- if (workArray==NULL)
++ if (scilabSparseT->nel != 0)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
++ scilabSparseT->icol = (int*) MALLOC(sizeof(int) * scilabSparseT->nel);
++ if (scilabSparseT->icol == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
++ }
+ }
+
+- if (scilabSparseT->m != 0) {
+- scilabSparseT->mnel = (int*) MALLOC(sizeof(int) * scilabSparseT->m);
+- if (scilabSparseT->mnel==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
+- }
+- }
++ if (scilabSparseT->nel != 0)
++ {
++ scilabSparseT->R = (double*) MALLOC(sizeof(double) * scilabSparseT->nel);
++ if (scilabSparseT->R == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
++ }
++ }
+
+- if (scilabSparseT->nel != 0) {
+- scilabSparseT->icol = (int*) MALLOC(sizeof(int) * scilabSparseT->nel);
+- if (scilabSparseT->icol==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
+- }
+- }
++ if (scilabSparseT->it)
++ {
++ scilabSparseT->I = (double*) MALLOC(sizeof(double) * scilabSparseT->nel);
++ if (scilabSparseT->I == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
++ return FALSE;
++ }
++ }
+
+- if (scilabSparseT->nel != 0) {
+- scilabSparseT->R = (double*) MALLOC(sizeof(double) * scilabSparseT->nel);
+- if (scilabSparseT->R==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
+- }
+- }
++ C2F(spt)(&scilabSparse->m, &scilabSparse->n, &scilabSparse->nel, &scilabSparse->it, workArray,
++ scilabSparse->R, scilabSparse->I, scilabSparse->mnel, scilabSparse->icol,
++ scilabSparseT->R, scilabSparseT->I, scilabSparseT->mnel, scilabSparseT->icol);
+
+- if (scilabSparseT->it)
++ if (scilabSparse->it)
++ {
++ if (parent == NULL)
++ {
++ _SciErr = createComplexSparseMatrix(pvApiCtx, iVar, scilabSparse->m, scilabSparse->n, scilabSparse->nel,
++ scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R, scilabSparseT->I);
++ }
++ else
++ {
++ _SciErr = createComplexSparseMatrixInList(pvApiCtx, iVar, parent, item_position,
++ scilabSparse->m, scilabSparse->n, scilabSparse->nel,
++ scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R, scilabSparseT->I);
++ }
++ }
++ else
+ {
+- scilabSparseT->I = (double*) MALLOC(sizeof(double) * scilabSparseT->nel);
+- if (scilabSparseT->I==NULL)
++ if (parent == NULL)
++ {
++ _SciErr = createSparseMatrix(pvApiCtx, iVar, scilabSparseT->m, scilabSparseT->n, scilabSparseT->nel,
++ scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R);
++ }
++ else
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+- return FALSE;
++ _SciErr = createSparseMatrixInList(pvApiCtx, iVar, parent, item_position,
++ scilabSparseT->m, scilabSparseT->n, scilabSparseT->nel,
++ scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R);
+ }
+ }
+-
+- C2F(spt)(&scilabSparse->m, &scilabSparse->n, &scilabSparse->nel, &scilabSparse->it, workArray,
+- scilabSparse->R, scilabSparse->I, scilabSparse->mnel, scilabSparse->icol,
+- scilabSparseT->R, scilabSparseT->I, scilabSparseT->mnel, scilabSparseT->icol);
+-
+- if (scilabSparse->it)
+- {
+- if (parent==NULL)
+- {
+- _SciErr = createComplexSparseMatrix(pvApiCtx, iVar, scilabSparse->m, scilabSparse->n, scilabSparse->nel,
+- scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R, scilabSparseT->I);
+- }
+- else
+- {
+- _SciErr = createComplexSparseMatrixInList(pvApiCtx, iVar, parent, item_position,
+- scilabSparse->m, scilabSparse->n, scilabSparse->nel,
+- scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R, scilabSparseT->I);
+- }
+- }
+- else
+- {
+- if (parent==NULL)
+- {
+- _SciErr = createSparseMatrix(pvApiCtx, iVar, scilabSparseT->m, scilabSparseT->n, scilabSparseT->nel,
+- scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R);
+- }
+- else
+- {
+- _SciErr = createSparseMatrixInList(pvApiCtx, iVar, parent, item_position,
+- scilabSparseT->m, scilabSparseT->n, scilabSparseT->nel,
+- scilabSparseT->mnel, scilabSparseT->icol, scilabSparseT->R);
+- }
+- }
+-
+- /* Free all arrays */
+- if (scilabSparse != NULL) FREE(scilabSparse);
+- if (colIndexes != NULL) FREE(colIndexes);
+- if (rowIndexes != NULL) FREE(rowIndexes);
+- if (workArray != NULL) FREE(workArray);
+- if (scilabSparseT->m != 0) FREE(scilabSparseT->mnel);
+- if (scilabSparseT->nel != 0) FREE(scilabSparseT->icol);
+- if (scilabSparseT->nel != 0) FREE(scilabSparseT->R);
+- if ((scilabSparseT->nel != 0) && (scilabSparseT->it != 0)) FREE(scilabSparseT->I);
+- if (scilabSparseT != NULL) FREE(scilabSparseT);
+-
+- return TRUE;
++
++ /* Free all arrays */
++ if (scilabSparse != NULL) FREE(scilabSparse);
++ if (colIndexes != NULL) FREE(colIndexes);
++ if (rowIndexes != NULL) FREE(rowIndexes);
++ if (workArray != NULL) FREE(workArray);
++ if (scilabSparseT->m != 0) FREE(scilabSparseT->mnel);
++ if (scilabSparseT->nel != 0) FREE(scilabSparseT->icol);
++ if (scilabSparseT->nel != 0) FREE(scilabSparseT->R);
++ if ((scilabSparseT->nel != 0) && (scilabSparseT->it != 0)) FREE(scilabSparseT->I);
++ if (scilabSparseT != NULL) FREE(scilabSparseT);
++
++ return TRUE;
+ }
+diff --git a/scilab/modules/matio/src/c/CreateStructVariable.c b/scilab/modules/matio/src/c/CreateStructVariable.c
+index f6dc231..497e61a 100644
+--- a/scilab/modules/matio/src/c/CreateStructVariable.c
++++ b/scilab/modules/matio/src/c/CreateStructVariable.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -31,131 +31,136 @@
+
+ int CreateStructVariable(int iVar, matvar_t *matVariable, int * parent, int item_position)
+ {
+- char **fieldNames = NULL;
+- int nbFields = 0;
+- int fieldIndex = 0;
+- int K = 0;
+- int prodDims = 0;
+- int valueIndex = 0;
+- matvar_t *fieldMatVar = NULL;
+- matvar_t ** allData = NULL;
+- int * cell_addr = NULL;
+- int * cell_entry_addr = NULL;
+- int type;
+- SciErr _SciErr;
+-
+- /* Fields of the struct */
+- nbFields = 2; /* "st" "dims" */
+- nbFields += Mat_VarGetNumberOfFields(matVariable);
+-
+- fieldNames = (char**) MALLOC(sizeof(char*) * nbFields);
+- if (fieldNames==NULL)
++ char **fieldNames = NULL;
++ int nbFields = 0;
++ int fieldIndex = 0;
++ int K = 0;
++ int prodDims = 0;
++ int valueIndex = 0;
++ matvar_t *fieldMatVar = NULL;
++ matvar_t ** allData = NULL;
++ int * cell_addr = NULL;
++ int * cell_entry_addr = NULL;
++ int type;
++ SciErr _SciErr;
++
++ /* Fields of the struct */
++ nbFields = 2; /* "st" "dims" */
++ nbFields += Mat_VarGetNumberOfFields(matVariable);
++
++ fieldNames = (char**) MALLOC(sizeof(char*) * nbFields);
++ if (fieldNames == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
++ return FALSE;
+ }
+-
+- fieldNames[0] = strdup("st");
+- if (fieldNames[0]==NULL)
++
++ fieldNames[0] = strdup("st");
++ if (fieldNames[0] == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
++ return FALSE;
+ }
+- fieldNames[1] = strdup("dims");
+- if (fieldNames[1]==NULL)
++ fieldNames[1] = strdup("dims");
++ if (fieldNames[1] == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
++ return FALSE;
+ }
+-
+- for (fieldIndex = 1; fieldIndex < nbFields - 1; fieldIndex++)
++
++ for (fieldIndex = 1; fieldIndex < nbFields - 1; fieldIndex++)
+ {
+- fieldMatVar = Mat_VarGetStructField(matVariable, &fieldIndex, BY_INDEX, 0);
+- fieldNames[fieldIndex + 1] = strdup(fieldMatVar->name);
+- if (fieldNames[fieldIndex + 1]==NULL)
++ fieldMatVar = Mat_VarGetStructField(matVariable, &fieldIndex, MAT_BY_INDEX, 0);
++ fieldNames[fieldIndex + 1] = strdup(fieldMatVar->name);
++ if (fieldNames[fieldIndex + 1] == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "CreateStructVariable");
++ return FALSE;
+ }
+ }
+-
+- /* Returned mlist initialization */
+- if (parent==NULL)
++
++ /* Returned mlist initialization */
++ if (parent == NULL)
+ {
+- _SciErr = createMList(pvApiCtx, iVar, nbFields, &cell_addr); MATIO_ERROR;
++ _SciErr = createMList(pvApiCtx, iVar, nbFields, &cell_addr);
++ MATIO_ERROR;
+ }
+- else
++ else
+ {
+- _SciErr = createMListInList(pvApiCtx, iVar, parent, item_position, nbFields, &cell_addr); MATIO_ERROR;
++ _SciErr = createMListInList(pvApiCtx, iVar, parent, item_position, nbFields, &cell_addr);
++ MATIO_ERROR;
+ }
+
+- /* FIRST LIST ENTRY: fieldnames */
+- _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, cell_addr, 1, 1, nbFields, fieldNames); MATIO_ERROR;
+-
+- /* SECOND LIST ENTRY: Dimensions (int32 type) */
+- if (nbFields==2) /* Empty struct must have size 0x0 in Scilab */
++ /* FIRST LIST ENTRY: fieldnames */
++ _SciErr = createMatrixOfStringInList(pvApiCtx, iVar, cell_addr, 1, 1, nbFields, fieldNames);
++ MATIO_ERROR;
++
++ /* SECOND LIST ENTRY: Dimensions (int32 type) */
++ if (nbFields == 2) /* Empty struct must have size 0x0 in Scilab */
+ {
+- matVariable->dims[0] = 0;
+- matVariable->dims[1] = 0;
++ matVariable->dims[0] = 0;
++ matVariable->dims[1] = 0;
+ }
+
+- if(matVariable->rank==2) /* Two dimensions */
++ if (matVariable->rank == 2) /* Two dimensions */
+ {
+- _SciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, cell_addr, 2, 1, matVariable->rank, matVariable->dims); MATIO_ERROR;
++ _SciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, cell_addr, 2, 1, matVariable->rank, matVariable->dims);
++ MATIO_ERROR;
+ }
+- else /* 3 or more dimensions -> Scilab HyperMatrix */
++ else /* 3 or more dimensions -> Scilab HyperMatrix */
+ {
+- type = I_INT32;
+- CreateHyperMatrixVariable(iVar, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,
+- &type, &matVariable->rank, matVariable->dims, matVariable->data,
+- NULL, cell_addr, 2);
++ type = I_INT32;
++ CreateHyperMatrixVariable(iVar, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,
++ &type, &matVariable->rank, matVariable->dims, matVariable->data,
++ NULL, cell_addr, 2);
+ }
+
+- /* ALL OTHER ENTRIES: Fields data */
+- prodDims = 1;
+- for (K=0; K<matVariable->rank; K++)
++ /* ALL OTHER ENTRIES: Fields data */
++ prodDims = 1;
++ for (K = 0; K < matVariable->rank; K++)
+ {
+- prodDims *= matVariable->dims[K];
++ prodDims *= matVariable->dims[K];
+ }
+
+- allData = (matvar_t**) (matVariable->data);
++ allData = (matvar_t**) (matVariable->data);
+
+- if (prodDims == 1) /* Scalar struct */
++ if (prodDims == 1) /* Scalar struct */
+ {
+- for (fieldIndex = 0; fieldIndex < nbFields - 2; fieldIndex++)
++ for (fieldIndex = 0; fieldIndex < nbFields - 2; fieldIndex++)
+ {
+- /* Create list entry in the stack */
+- if (!CreateMatlabVariable(iVar, allData[fieldIndex], cell_addr, fieldIndex+3)) /* Could not Create Variable */
++ /* Create list entry in the stack */
++ if (!CreateMatlabVariable(iVar, allData[fieldIndex], cell_addr, fieldIndex + 3)) /* Could not Create Variable */
+ {
+- if (allData[fieldIndex]->class_type != 0) /* class is 0 for not initialized fields */
++ if (allData[fieldIndex]->class_type != 0) /* class is 0 for not initialized fields */
+ {
+- sciprint("Do not know how to read a variable of class %d.\n", allData[fieldIndex]->class_type);
++ sciprint("Do not know how to read a variable of class %d.\n", allData[fieldIndex]->class_type);
+ }
+ }
+ }
+ }
+- else
++ else
+ {
+- for (fieldIndex = 0; fieldIndex < nbFields - 2; fieldIndex++)
++ for (fieldIndex = 0; fieldIndex < nbFields - 2; fieldIndex++)
+ {
+- _SciErr = createListInList(pvApiCtx, iVar, cell_addr, fieldIndex+3, prodDims, &cell_entry_addr); MATIO_ERROR;
+-
+- for (valueIndex = 0; valueIndex < prodDims; valueIndex++)
++ _SciErr = createListInList(pvApiCtx, iVar, cell_addr, fieldIndex + 3, prodDims, &cell_entry_addr);
++ MATIO_ERROR;
++
++ for (valueIndex = 0; valueIndex < prodDims; valueIndex++)
+ {
+- /* Create list entry in the stack */
+- if (!CreateMatlabVariable(iVar, allData[(fieldIndex) + (nbFields-2)*valueIndex], cell_entry_addr, valueIndex+1)) /* Could not Create Variable */
++ /* Create list entry in the stack */
++ if (!CreateMatlabVariable(iVar, allData[(fieldIndex) + (nbFields - 2)*valueIndex], cell_entry_addr, valueIndex + 1)) /* Could not Create Variable */
+ {
+- if (allData[(fieldIndex) + (nbFields-2)*valueIndex]->class_type != 0) /* class is 0 for not initialized fields */
++ if (allData[(fieldIndex) + (nbFields - 2)*valueIndex]->class_type != 0) /* class is 0 for not initialized fields */
+ {
+- sciprint("Do not know how to read a variable of class %d.\n", allData[(fieldIndex) + (nbFields-2)*valueIndex]->class_type);
++ sciprint("Do not know how to read a variable of class %d.\n", allData[(fieldIndex) + (nbFields - 2)*valueIndex]->class_type);
+ }
+ }
+ }
+ }
+ }
+
+- freeArrayOfString(fieldNames, nbFields);
++ freeArrayOfString(fieldNames, nbFields);
+
+- return TRUE;
++ return TRUE;
+ }
+
+diff --git a/scilab/modules/matio/src/c/GetDoubleVariable.c b/scilab/modules/matio/src/c/GetDoubleVariable.c
+index 2fdc009..d70640f 100644
+--- a/scilab/modules/matio/src/c/GetDoubleVariable.c
++++ b/scilab/modules/matio/src/c/GetDoubleVariable.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -23,89 +23,97 @@
+
+ matvar_t * GetDoubleVariable(int iVar, const char* name, int matfile_version, int * parent, int item_position)
+ {
+- double * realDataAdr = NULL, * complexDataAdr = NULL;
+- int rank = 0;
+- int *dims = NULL;
+- int isComplex = 0;
+- struct ComplexSplit mat5ComplexData;
+- matvar_t *createdVar = NULL;
+- int * var_addr = NULL;
+- int * item_addr = NULL;
+- int var_type;
+- SciErr _SciErr;
++ double * realDataAdr = NULL, * complexDataAdr = NULL;
++ int rank = 0;
++ int *dims = NULL;
++ int isComplex = 0;
++ struct mat_complex_split_t mat5ComplexData;
++ matvar_t *createdVar = NULL;
++ int * var_addr = NULL;
++ int * item_addr = NULL;
++ int var_type;
++ SciErr _SciErr;
+
+- if (parent==NULL)
++ if (parent == NULL)
+ {
+- _SciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, var_addr, &var_type); MATIO_ERROR;
+- isComplex = isVarComplex(pvApiCtx, var_addr);
++ _SciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, var_addr, &var_type);
++ MATIO_ERROR;
++ isComplex = isVarComplex(pvApiCtx, var_addr);
+ }
+- else
++ else
+ {
+- _SciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, item_addr, &var_type); MATIO_ERROR;
+- isComplex = isVarComplex(pvApiCtx, item_addr);
++ _SciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, item_addr, &var_type);
++ MATIO_ERROR;
++ isComplex = isVarComplex(pvApiCtx, item_addr);
+ }
+
+- if(var_type == sci_matrix) /* 2-D array */
++ if (var_type == sci_matrix) /* 2-D array */
+ {
+- rank = 2;
+- if ((dims = (int*)MALLOC(sizeof(int)*rank)) == NULL)
++ rank = 2;
++ if ((dims = (int*)MALLOC(sizeof(int) * rank)) == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetDoubleVariable");
+- return NULL;
++ Scierror(999, _("%s: No more memory.\n"), "GetDoubleVariable");
++ return NULL;
+ }
+
+
+- if (isComplex)
+- {
+- if (parent==NULL)
+- {
+- _SciErr = getComplexMatrixOfDouble(pvApiCtx, var_addr, &dims[0], &dims[1], &realDataAdr, &complexDataAdr); MATIO_ERROR;
+- }
+- else
+- {
+- _SciErr = getComplexMatrixOfDoubleInList(pvApiCtx, parent, item_position, &dims[0], &dims[1],
+- &realDataAdr, &complexDataAdr); MATIO_ERROR;
+- }
+- }
+- else
+- {
+- if (parent==NULL)
+- {
+- _SciErr = getMatrixOfDouble(pvApiCtx, var_addr, &dims[0], &dims[1], &realDataAdr); MATIO_ERROR;
+- }
+- else
+- {
+- _SciErr = getMatrixOfDoubleInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], &realDataAdr); MATIO_ERROR;
+- }
+- }
++ if (isComplex)
++ {
++ if (parent == NULL)
++ {
++ _SciErr = getComplexMatrixOfDouble(pvApiCtx, var_addr, &dims[0], &dims[1], &realDataAdr, &complexDataAdr);
++ MATIO_ERROR;
++ }
++ else
++ {
++ _SciErr = getComplexMatrixOfDoubleInList(pvApiCtx, parent, item_position, &dims[0], &dims[1],
++ &realDataAdr, &complexDataAdr);
++ MATIO_ERROR;
++ }
++ }
++ else
++ {
++ if (parent == NULL)
++ {
++ _SciErr = getMatrixOfDouble(pvApiCtx, var_addr, &dims[0], &dims[1], &realDataAdr);
++ MATIO_ERROR;
++ }
++ else
++ {
++ _SciErr = getMatrixOfDoubleInList(pvApiCtx, parent, item_position, &dims[0], &dims[1], &realDataAdr);
++ MATIO_ERROR;
++ }
++ }
+
+- if (isComplex==0)
++ if (isComplex == 0)
+ {
+- createdVar = Mat_VarCreate(name, MAT_C_DOUBLE, MAT_T_DOUBLE, rank, dims, realDataAdr, 0);
++ createdVar = Mat_VarCreate(name, MAT_C_DOUBLE, MAT_T_DOUBLE, rank, dims, realDataAdr, 0);
+ }
+- else
++ else
+ {
+- if(matfile_version==MAT_FT_MAT4) /* MATLAB4: data is a table of value */
++ if (matfile_version == MAT_FT_MAT4) /* MATLAB4: data is a table of value */
+ {
+- createdVar = Mat_VarCreate(name, MAT_C_DOUBLE, MAT_T_DOUBLE, rank, dims, realDataAdr, MAT_F_COMPLEX);
++ createdVar = Mat_VarCreate(name, MAT_C_DOUBLE, MAT_T_DOUBLE, rank, dims, realDataAdr, MAT_F_COMPLEX);
+ }
+- else /* MATLAB5 file: data is a ComplexSplit */
++ else /* MATLAB5 file: data is a mat_complex_split_t */
+ {
+- mat5ComplexData.Re = realDataAdr;
+- mat5ComplexData.Im = complexDataAdr;
+- createdVar = Mat_VarCreate(name, MAT_C_DOUBLE, MAT_T_DOUBLE, rank, dims, &mat5ComplexData, MAT_F_COMPLEX);
++ mat5ComplexData.Re = realDataAdr;
++ mat5ComplexData.Im = complexDataAdr;
++ createdVar = Mat_VarCreate(name, MAT_C_DOUBLE, MAT_T_DOUBLE, rank, dims, &mat5ComplexData, MAT_F_COMPLEX);
+ }
+- createdVar->isComplex = 1;
++ createdVar->isComplex = 1;
+ }
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for first input argument: Double matrix expected.\n"), "GetDoubleVariable");
++ Scierror(999, _("%s: Wrong type for first input argument: Double matrix expected.\n"), "GetDoubleVariable");
+ }
+
+- FREE(dims);
++ FREE(dims);
+
+- return createdVar;
++ return createdVar;
+ }
+diff --git a/scilab/modules/matio/src/c/GetSparseVariable.c b/scilab/modules/matio/src/c/GetSparseVariable.c
+index b391f98..f45204c 100644
+--- a/scilab/modules/matio/src/c/GetSparseVariable.c
++++ b/scilab/modules/matio/src/c/GetSparseVariable.c
+@@ -1,11 +1,11 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
+- *
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -22,297 +22,302 @@
+
+ matvar_t *GetSparseVariable(int iVar, const char *name, int * parent, int item_position)
+ {
+- int K = 0;
+- int rank = 0;
+- int *dims = NULL;
+- double *data = NULL;
+- matvar_t *createdVar = NULL;
+- sparse_t *sparseData = NULL;
+- SciSparse scilabSparse;
+- int *colIndexes = NULL;
+- int *rowIndexes = NULL;
+- int * var_addr = NULL;
+- int * item_addr = NULL;
+- int var_type;
+- SciErr _SciErr;
+-
+- if (parent==NULL)
++ int K = 0;
++ int rank = 0;
++ int *dims = NULL;
++ double *data = NULL;
++ matvar_t *createdVar = NULL;
++ mat_sparse_t *sparseData = NULL;
++ SciSparse scilabSparse;
++ int *colIndexes = NULL;
++ int *rowIndexes = NULL;
++ int * var_addr = NULL;
++ int * item_addr = NULL;
++ int var_type;
++ SciErr _SciErr;
++
++ if (parent == NULL)
+ {
+- _SciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, var_addr, &var_type); MATIO_ERROR;
++ _SciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, var_addr, &var_type);
++ MATIO_ERROR;
+ }
+- else
++ else
+ {
+- _SciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr); MATIO_ERROR;
+- _SciErr = getVarType(pvApiCtx, item_addr, &var_type); MATIO_ERROR;
++ _SciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr);
++ MATIO_ERROR;
++ _SciErr = getVarType(pvApiCtx, item_addr, &var_type);
++ MATIO_ERROR;
+ }
+
+- if (var_type == sci_sparse)
++ if (var_type == sci_sparse)
+ {
+- sparseData = (sparse_t*) MALLOC(sizeof(sparse_t));
+- if (sparseData==NULL)
++ sparseData = (mat_sparse_t*) MALLOC(sizeof(mat_sparse_t));
++ if (sparseData == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++ return FALSE;
+ }
+-
+- rank = 2;
+- if ((dims = (int*) MALLOC (sizeof(int) * rank)) == NULL)
++
++ rank = 2;
++ if ((dims = (int*) MALLOC (sizeof(int) * rank)) == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+- return NULL;
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++ return NULL;
+ }
+
+- if (isVarComplex(pvApiCtx, var_addr))
+- {
+- if (parent==NULL)
+- {
+- getAllocatedComplexSparseMatrix(pvApiCtx, var_addr, &dims[1], &dims[0],
+- &scilabSparse.nel, &scilabSparse.mnel,
+- &scilabSparse.icol, &scilabSparse.R,
+- &scilabSparse.I);
+- }
+- else
+- {
+- _SciErr = getSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
+- &scilabSparse.nel, NULL, NULL, NULL);
+- scilabSparse.mnel = (int *)MALLOC(dims[1]*sizeof(int));
+- if (scilabSparse.mnel==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+-
+- return FALSE;
+- }
+- scilabSparse.icol = (int *)MALLOC(scilabSparse.nel*sizeof(int));
+- if (scilabSparse.icol==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+- FREE(scilabSparse.icol);
+-
+- return FALSE;
+- }
+- scilabSparse.R = (double *)MALLOC(scilabSparse.nel*sizeof(double));
+- if (scilabSparse.R==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+- FREE(scilabSparse.icol);
+- FREE(scilabSparse.R);
+-
+- return FALSE;
+- }
+- scilabSparse.I = (double *)MALLOC(scilabSparse.nel*sizeof(double));
+- if (scilabSparse.I==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+- FREE(scilabSparse.icol);
+- FREE(scilabSparse.R);
+- FREE(scilabSparse.I);
+-
+- return FALSE;
+- }
+- _SciErr = getComplexSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
+- &scilabSparse.nel, &scilabSparse.mnel,
+- &scilabSparse.icol, &scilabSparse.R, &scilabSparse.I);
+- }
+-
+- scilabSparse.it = 1;
+-
+- }
+- else
+- {
+- if (parent==NULL)
+- {
+- getAllocatedSparseMatrix(pvApiCtx, var_addr, &dims[1], &dims[0],
+- &scilabSparse.nel, &scilabSparse.mnel,
+- &scilabSparse.icol, &scilabSparse.R);
+- }
+- else
+- {
+- _SciErr = getSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
+- &scilabSparse.nel, NULL, NULL, NULL);
+- scilabSparse.mnel = (int *)MALLOC(dims[1]*sizeof(int));
+- if (scilabSparse.mnel==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+-
+- return FALSE;
+- }
+- scilabSparse.icol = (int *)MALLOC(scilabSparse.nel*sizeof(int));
+- if (scilabSparse.icol==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+- FREE(scilabSparse.icol);
+-
+- return FALSE;
+- }
+- scilabSparse.R = (double *)MALLOC(scilabSparse.nel*sizeof(double));
+- if (scilabSparse.R==NULL)
+- {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- FREE(scilabSparse.mnel);
+- FREE(scilabSparse.icol);
+- FREE(scilabSparse.R);
+-
+- return FALSE;
+- }
+- _SciErr = getSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
+- &scilabSparse.nel, &scilabSparse.mnel,
+- &scilabSparse.icol, &scilabSparse.R);
+- }
+-
+- scilabSparse.it = 0;
+- }
+-
+- scilabSparse.m = dims[1];
+- scilabSparse.n = dims[0];
+-
+- /* colIndexes = (int*) MALLOC(sizeof(int) * (scilabSparse.nel + 1)); */
+- colIndexes = (int*) MALLOC(sizeof(int) * (scilabSparse.m + 1));
+- if (colIndexes==NULL)
++ if (isVarComplex(pvApiCtx, var_addr))
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- if (scilabSparse.it)
+- {
+- freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
+- }
+- else
+- {
+- freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
+- }
+-
+- return FALSE;
++ if (parent == NULL)
++ {
++ getAllocatedComplexSparseMatrix(pvApiCtx, var_addr, &dims[1], &dims[0],
++ &scilabSparse.nel, &scilabSparse.mnel,
++ &scilabSparse.icol, &scilabSparse.R,
++ &scilabSparse.I);
++ }
++ else
++ {
++ _SciErr = getSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
++ &scilabSparse.nel, NULL, NULL, NULL);
++ scilabSparse.mnel = (int *)MALLOC(dims[1] * sizeof(int));
++ if (scilabSparse.mnel == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++
++ return FALSE;
++ }
++ scilabSparse.icol = (int *)MALLOC(scilabSparse.nel * sizeof(int));
++ if (scilabSparse.icol == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++ FREE(scilabSparse.icol);
++
++ return FALSE;
++ }
++ scilabSparse.R = (double *)MALLOC(scilabSparse.nel * sizeof(double));
++ if (scilabSparse.R == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++ FREE(scilabSparse.icol);
++ FREE(scilabSparse.R);
++
++ return FALSE;
++ }
++ scilabSparse.I = (double *)MALLOC(scilabSparse.nel * sizeof(double));
++ if (scilabSparse.I == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++ FREE(scilabSparse.icol);
++ FREE(scilabSparse.R);
++ FREE(scilabSparse.I);
++
++ return FALSE;
++ }
++ _SciErr = getComplexSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
++ &scilabSparse.nel, &scilabSparse.mnel,
++ &scilabSparse.icol, &scilabSparse.R, &scilabSparse.I);
++ }
++
++ scilabSparse.it = 1;
++
+ }
+-
+- colIndexes[0] = 0;
+- /* for (K=0; K<scilabSparse.nel; K++) */
+- for (K=0; K<scilabSparse.m; K++)
++ else
+ {
+- colIndexes[K+1] = colIndexes[K] + scilabSparse.mnel[K];
++ if (parent == NULL)
++ {
++ getAllocatedSparseMatrix(pvApiCtx, var_addr, &dims[1], &dims[0],
++ &scilabSparse.nel, &scilabSparse.mnel,
++ &scilabSparse.icol, &scilabSparse.R);
++ }
++ else
++ {
++ _SciErr = getSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
++ &scilabSparse.nel, NULL, NULL, NULL);
++ scilabSparse.mnel = (int *)MALLOC(dims[1] * sizeof(int));
++ if (scilabSparse.mnel == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++
++ return FALSE;
++ }
++ scilabSparse.icol = (int *)MALLOC(scilabSparse.nel * sizeof(int));
++ if (scilabSparse.icol == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++ FREE(scilabSparse.icol);
++
++ return FALSE;
++ }
++ scilabSparse.R = (double *)MALLOC(scilabSparse.nel * sizeof(double));
++ if (scilabSparse.R == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ FREE(scilabSparse.mnel);
++ FREE(scilabSparse.icol);
++ FREE(scilabSparse.R);
++
++ return FALSE;
++ }
++ _SciErr = getSparseMatrixInList(pvApiCtx, parent, item_position, &dims[1], &dims[0],
++ &scilabSparse.nel, &scilabSparse.mnel,
++ &scilabSparse.icol, &scilabSparse.R);
++ }
++
++ scilabSparse.it = 0;
+ }
+-
+- rowIndexes = (int*) MALLOC(sizeof(int) * scilabSparse.nel);
+- if (rowIndexes==NULL)
++
++ scilabSparse.m = dims[1];
++ scilabSparse.n = dims[0];
++
++ /* colIndexes = (int*) MALLOC(sizeof(int) * (scilabSparse.nel + 1)); */
++ colIndexes = (int*) MALLOC(sizeof(int) * (scilabSparse.m + 1));
++ if (colIndexes == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- if (scilabSparse.it)
+- {
+- freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
+- }
+- else
+- {
+- freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
+- }
+-
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ if (scilabSparse.it)
++ {
++ freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
++ }
++ else
++ {
++ freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
++ }
++
++ return FALSE;
+ }
+-
+- for (K=0; K<scilabSparse.nel; K++)
++
++ colIndexes[0] = 0;
++ /* for (K=0; K<scilabSparse.nel; K++) */
++ for (K = 0; K < scilabSparse.m; K++)
++ {
++ colIndexes[K + 1] = colIndexes[K] + scilabSparse.mnel[K];
++ }
++
++ rowIndexes = (int*) MALLOC(sizeof(int) * scilabSparse.nel);
++ if (rowIndexes == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ if (scilabSparse.it)
++ {
++ freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
++ }
++ else
++ {
++ freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
++ }
++
++ return FALSE;
++ }
++
++ for (K = 0; K < scilabSparse.nel; K++)
+ {
+- rowIndexes[K] = scilabSparse.icol[K] - 1;
++ rowIndexes[K] = scilabSparse.icol[K] - 1;
+ }
+
+- if (scilabSparse.it==0) /* Real sparse */
++ if (scilabSparse.it == 0) /* Real sparse */
+ {
+- if ((data = (double*) MALLOC(sizeof(double) * scilabSparse.nel)) == NULL)
++ if ((data = (double*) MALLOC(sizeof(double) * scilabSparse.nel)) == NULL)
++ {
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ if (scilabSparse.it)
++ {
++ freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
++ }
++ else
++ {
++ freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
++ }
++
++ return 0;
++ }
++
++ for (K = 0; K < scilabSparse.nel; K++)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- if (scilabSparse.it)
+- {
+- freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
+- }
+- else
+- {
+- freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
+- }
+-
+- return 0;
+- }
+-
+- for(K = 0; K < scilabSparse.nel; K++)
+- {
+- data[K] = scilabSparse.R[K];
+- }
++ data[K] = scilabSparse.R[K];
++ }
+ }
+- else
++ else
+ {
+- if ((data = (double*) MALLOC(2 * sizeof(double) * scilabSparse.nel)) == NULL)
++ if ((data = (double*) MALLOC(2 * sizeof(double) * scilabSparse.nel)) == NULL)
+ {
+- Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
+-
+- if (scilabSparse.it)
+- {
+- freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
+- }
+- else
+- {
+- freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
+- }
+-
+- return FALSE;
++ Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
++
++ if (scilabSparse.it)
++ {
++ freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
++ }
++ else
++ {
++ freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
++ }
++
++ return FALSE;
+ }
+
+- for(K = 0; K < scilabSparse.nel; K++)
++ for (K = 0; K < scilabSparse.nel; K++)
+ {
+- data[K] = scilabSparse.R[K];
++ data[K] = scilabSparse.R[K];
+ }
+
+- for(K = 0; K < scilabSparse.nel; K++)
++ for (K = 0; K < scilabSparse.nel; K++)
+ {
+- data[K + scilabSparse.nel] = scilabSparse.I[K];
++ data[K + scilabSparse.nel] = scilabSparse.I[K];
+ }
+ }
+
+- /* Create Matlab Sparse matrix data */
+- sparseData->nzmax = scilabSparse.nel;
+- sparseData->nir = scilabSparse.nel;
+- sparseData->ir = rowIndexes;
+- /* sparseData->njc = scilabSparse.nel + 1; */
+- sparseData->njc = scilabSparse.m + 1;
+- sparseData->jc = colIndexes;
+- sparseData->ndata = scilabSparse.nel;
+- sparseData->data = (void*) data;
+-
+- if (scilabSparse.it == 0)
++ /* Create Matlab Sparse matrix data */
++ sparseData->nzmax = scilabSparse.nel;
++ sparseData->nir = scilabSparse.nel;
++ sparseData->ir = rowIndexes;
++ /* sparseData->njc = scilabSparse.nel + 1; */
++ sparseData->njc = scilabSparse.m + 1;
++ sparseData->jc = colIndexes;
++ sparseData->ndata = scilabSparse.nel;
++ sparseData->data = (void*) data;
++
++ if (scilabSparse.it == 0)
+ {
+- createdVar = Mat_VarCreate(name, MAT_C_SPARSE, MAT_T_DOUBLE, rank, dims, sparseData, 0 | MEM_CONSERVE);
++ createdVar = Mat_VarCreate(name, MAT_C_SPARSE, MAT_T_DOUBLE, rank, dims, sparseData, 0 | MAT_F_DONT_COPY_DATA);
+ }
+- else
++ else
+ {
+- createdVar = Mat_VarCreate(name, MAT_C_SPARSE, MAT_T_DOUBLE, rank, dims, sparseData, MAT_F_COMPLEX | MEM_CONSERVE);
+- if (data) FREE(data);
++ createdVar = Mat_VarCreate(name, MAT_C_SPARSE, MAT_T_DOUBLE, rank, dims, sparseData, MAT_F_COMPLEX | MAT_F_DONT_COPY_DATA);
++
++ if (data) FREE(data);
+ }
+
+- if (dims) FREE(dims);
++ if (dims) FREE(dims);
+ }
+- else
++ else
+ {
+- Scierror(999, _("%s: Wrong type for first input argument: Sparse matrix expected.\n"), "GetSparseVariable");
++ Scierror(999, _("%s: Wrong type for first input argument: Sparse matrix expected.\n"), "GetSparseVariable");
+ }
+-
+- if (scilabSparse.it)
++
++ if (scilabSparse.it)
+ {
+- freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
++ freeAllocatedComplexSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R, scilabSparse.I);
+ }
+- else
++ else
+ {
+- freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
++ freeAllocatedSparseMatrix(scilabSparse.mnel, scilabSparse.icol, scilabSparse.R);
+ }
+-
+- return createdVar;
++
++ return createdVar;
+ }
+diff --git a/scilab/modules/matio/src/c/matfile_manager.c b/scilab/modules/matio/src/c/matfile_manager.c
+index 2ba34db..e192f71 100644
+--- a/scilab/modules/matio/src/c/matfile_manager.c
++++ b/scilab/modules/matio/src/c/matfile_manager.c
+@@ -1,12 +1,12 @@
+ /*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+- * Copyright (C) 2008 - INRIA - Vincent COUVERT
++ * Copyright (C) 2008 - INRIA - Vincent COUVERT
+ * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
+- *
++ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+- * are also available at
++ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+@@ -23,88 +23,89 @@ static int numberOfMatfiles = 0;
+
+ /*******************************************************************************
+ This function manages the set of files:
+- - opened using matfile_open
++ - opened using matfile_open
+ - closed using matfile_closed
+ All pointers to opened files are stored in a static variable
+ *******************************************************************************/
+ void matfile_manager(int action, int *fileIndex, mat_t **matfile)
+ {
+- int K = 0; /* Loop index */
+-
+- if (action == MATFILEMANAGER_GETFILE) /* Get the mat_t structure corresponding to the fileIndex (fileIndex is an input) */
++ int K = 0; /* Loop index */
++
++ if (action == MATFILEMANAGER_GETFILE) /* Get the mat_t structure corresponding to the fileIndex (fileIndex is an input) */
+ {
+- if((*fileIndex >= numberOfMatfiles) || (*fileIndex < 0)) /* FileIndex is too big or invalid */
++ if ((*fileIndex >= numberOfMatfiles) || (*fileIndex < 0)) /* FileIndex is too big or invalid */
+ {
+- *matfile = NULL; /* Return NULL */
++ *matfile = NULL; /* Return NULL */
+ }
+- else /* Return corresponding matfile */
++ else /* Return corresponding matfile */
+ {
+- *matfile = openedMatfiles[*fileIndex];
++ *matfile = openedMatfiles[*fileIndex];
+ }
+ }
+- else if(action == MATFILEMANAGER_ADDFILE) /* Add matfile to the list of opened matfiles (fileIndex is an output) */
++ else if (action == MATFILEMANAGER_ADDFILE) /* Add matfile to the list of opened matfiles (fileIndex is an output) */
+ {
+- if(numberOfMatfiles==0) /* No file opened */
++ if (numberOfMatfiles == 0) /* No file opened */
+ {
+- numberOfMatfiles++;
+- if (openedMatfiles)
+- {
+- openedMatfiles = (mat_t**)REALLOC(openedMatfiles, numberOfMatfiles*sizeof(mat_t*));
+- }
+- else
+- {
+- openedMatfiles = (mat_t**)MALLOC(numberOfMatfiles*sizeof(mat_t*));
+- }
+- *fileIndex = numberOfMatfiles-1;
+- openedMatfiles[*fileIndex] = *matfile;
++ numberOfMatfiles++;
++ if (openedMatfiles)
++ {
++ openedMatfiles = (mat_t**)REALLOC(openedMatfiles, numberOfMatfiles * sizeof(mat_t*));
++ }
++ else
++ {
++ openedMatfiles = (mat_t**)MALLOC(numberOfMatfiles * sizeof(mat_t*));
++ }
++ *fileIndex = numberOfMatfiles - 1;
++ openedMatfiles[*fileIndex] = *matfile;
+ }
+- else
++ else
+ {
+- /* Search for an empty space in openedMatfiles */
+- for(K=0;K<numberOfMatfiles;K++)
++ /* Search for an empty space in openedMatfiles */
++ for (K = 0; K < numberOfMatfiles; K++)
+ {
+- if(openedMatfiles[K]==NULL)
++ if (openedMatfiles[K] == NULL)
+ {
+- openedMatfiles[K] = *matfile;
+- *fileIndex = K;
+- return;
++ openedMatfiles[K] = *matfile;
++ *fileIndex = K;
++ return;
+ }
+ }
+- numberOfMatfiles++;
+- openedMatfiles = (mat_t**)REALLOC(openedMatfiles, numberOfMatfiles*sizeof(mat_t*));
+- *fileIndex = numberOfMatfiles-1;
+- openedMatfiles[*fileIndex] = *matfile;
++ numberOfMatfiles++;
++ openedMatfiles = (mat_t**)REALLOC(openedMatfiles, numberOfMatfiles * sizeof(mat_t*));
++ *fileIndex = numberOfMatfiles - 1;
++ openedMatfiles[*fileIndex] = *matfile;
+ }
+ }
+- else if(action == MATFILEMANAGER_DELFILE) /* Close matfile (fileIndex is an input) */
++ else if (action == MATFILEMANAGER_DELFILE) /* Close matfile (fileIndex is an input) */
+ {
+- if((*fileIndex >= numberOfMatfiles) || (*fileIndex < 0)) /* FileIndex is too big or invalid */
++ if ((*fileIndex >= numberOfMatfiles) || (*fileIndex < 0)) /* FileIndex is too big or invalid */
+ {
+- matfile = NULL; /* Return NULL */
++ matfile = NULL; /* Return NULL */
+ }
+- else /* Return corresponding matfile */
++ else /* Return corresponding matfile */
+ {
+- *matfile = openedMatfiles[*fileIndex];
+- //sciprint("Have to Close %s\n", (*matfile)->filename);
+- openedMatfiles[*fileIndex] = NULL;
++ *matfile = openedMatfiles[*fileIndex];
++ //sciprint("Have to Close %s\n", (*matfile)->filename);
++ openedMatfiles[*fileIndex] = NULL;
+ }
+- }
+- else if(action == MATFILEMANAGER_VIEWFILE) /* Display names of opened matfiles */
++ }
++ else if (action == MATFILEMANAGER_VIEWFILE) /* Display names of opened matfiles */
+ {
+- for(K=0;K<numberOfMatfiles;K++)
++ for (K = 0; K < numberOfMatfiles; K++)
+ {
+- if(openedMatfiles[K]!=NULL)
++ if (openedMatfiles[K] != NULL)
+ {
+- sciprint("%d -> %s\n", K, openedMatfiles[K]->filename);
++ /* TODO update this: was openedMatfiles[K]->filename */
++ sciprint("%d -> %s\n", K, "plop");
+ }
+- else
++ else
+ {
+- sciprint("%d -> Empty\n", K);
++ sciprint("%d -> Empty\n", K);
+ }
+ }
+ }
+- else /* Unknown action */
++ else /* Unknown action */
+ {
+- /* Return NULL */
++ /* Return NULL */
+ }
+ }
+--
+1.7.7.6
+
diff --git a/0002-Use-pkcon-to-install-doc-package.patch b/0002-Use-pkcon-to-install-doc-package.patch
new file mode 100644
index 0000000..0fa515b
--- /dev/null
+++ b/0002-Use-pkcon-to-install-doc-package.patch
@@ -0,0 +1,27 @@
+From 24d683c299f6a04362e4b712772daef6b84b2ed0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Cl=C3=A9ment=20DAVID?= <clement.david at scilab-enterprises.com>
+Date: Mon, 23 Jul 2012 21:16:48 +0200
+Subject: [PATCH 2/2] Use pkcon to install doc package
+
+Change-Id: Iba3ab43d280b40300831791c42e1cd4611e2ca9f
+---
+ scilab/modules/helptools/macros/help.sci | 3 ++-
+ 1 files changed, 2 insertions(+), 1 deletions(-)
+
+diff --git a/scilab/modules/helptools/macros/help.sci b/scilab/modules/helptools/macros/help.sci
+index c84983e..48cf4a1 100644
+--- a/scilab/modules/helptools/macros/help.sci
++++ b/scilab/modules/helptools/macros/help.sci
+@@ -48,7 +48,8 @@ if (findfiles('SCI/modules/helptools/jar','*_help.jar') <> []) then
+ error(msprintf(gettext("%s: The help browser is disabled in %s mode.\n"), "help", getscilabmode()));
+ end
+ else
+- error(msprintf(gettext("%s: help file(.jar) is not installed.\n"), "help"));
++ warning(msprintf(gettext("%s: help file(.jar) is not installed.\n"), "help"));
++ unix_w("pkcon install scilab-doc");
+ end
+
+ endfunction
+--
+1.7.7.6
+
diff --git a/scilab.spec b/scilab.spec
index 4b4d1fb..e6ca20f 100644
--- a/scilab.spec
+++ b/scilab.spec
@@ -28,8 +28,12 @@ Source0: http://downloadarea.scilab.org/download/%(date -d%{prerelease_da
%else
Source0: http://www.scilab.org/download/%{version}/scilab-%{version}-src.tar.gz
%endif
-# matio 1.5.0 does not have matioConfig.h, remove from configure check
-Patch0: scilab-matio.patch
+
+# backport matio 1.5 support, see http://codereview.scilab.org/#/c/6680/
+Patch1: 0001-Port-to-matio-1.5.patch
+
+# Bug 767102 - help() should suggest scilab-doc
+Patch2: 0002-Use-pkcon-to-install-doc-package.patch
# Dependencies are extracted from :
# "http://wiki.scilab.org/Dependencies of Scilab 5.X"
@@ -184,7 +188,9 @@ This package provide test files for Scilab.
%else
%setup -q
%endif
-%patch0 -p1 -b .matio
+
+%patch1 -p2 -b .matio
+%patch2 -p2 -b .pkgcon
# Update saxon dependency
# http://bugzilla.scilab.org/show_bug.cgi?id=8479
More information about the scm-commits
mailing list