Api: handle hypermatrices 81/11481/1
Calixte DENIZET [Mon, 6 May 2013 15:58:16 +0000 (17:58 +0200)]
Change-Id: I51e7cec3063d80a153a95bbf1dfc9627cb909f63

16 files changed:
scilab/modules/api_scilab/Makefile.am
scilab/modules/api_scilab/Makefile.in
scilab/modules/api_scilab/api_scilab.vcxproj
scilab/modules/api_scilab/api_scilab.vcxproj.filters
scilab/modules/api_scilab/help/en_US/hypermat/A_isHypermatType.xml [new file with mode: 0644]
scilab/modules/api_scilab/help/en_US/hypermat/B_getHypermatOfDouble.xml [new file with mode: 0644]
scilab/modules/api_scilab/help/en_US/hypermat/C_getHypermatOfInt.xml [new file with mode: 0644]
scilab/modules/api_scilab/includes/api_hypermat.h [new file with mode: 0644]
scilab/modules/api_scilab/includes/api_scilab.h
scilab/modules/api_scilab/src/cpp/api_hypermat.cpp [new file with mode: 0644]
scilab/modules/api_scilab/tests/unit_tests/hypermatExample.c [new file with mode: 0644]
scilab/modules/api_scilab/tests/unit_tests/hypermatExample.dia.ref [new file with mode: 0644]
scilab/modules/api_scilab/tests/unit_tests/hypermatExample.tst [new file with mode: 0644]
scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.c [new file with mode: 0644]
scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.dia.ref [new file with mode: 0644]
scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.tst [new file with mode: 0644]

index 81ae046..5559076 100644 (file)
@@ -18,7 +18,8 @@ src/cpp/api_string.cpp \
 src/cpp/api_pointer.cpp \
 src/cpp/api_handle.cpp \
 src/cpp/api_error.cpp \
-src/cpp/api_optional.cpp
+src/cpp/api_optional.cpp \
+src/cpp/api_hypermat.cpp
 
 
 libsciapi_scilab_la_CPPFLAGS=-I$(srcdir)/includes/ \
index 7a27afe..e435280 100644 (file)
@@ -149,7 +149,8 @@ am__objects_1 = libsciapi_scilab_la-api_boolean.lo \
        libsciapi_scilab_la-api_pointer.lo \
        libsciapi_scilab_la-api_handle.lo \
        libsciapi_scilab_la-api_error.lo \
-       libsciapi_scilab_la-api_optional.lo
+       libsciapi_scilab_la-api_optional.lo \
+       libsciapi_scilab_la-api_hypermat.lo
 am_libsciapi_scilab_la_OBJECTS = $(am__objects_1)
 libsciapi_scilab_la_OBJECTS = $(am_libsciapi_scilab_la_OBJECTS)
 @MAINTAINER_MODE_FALSE@am_libsciapi_scilab_la_rpath =
@@ -451,7 +452,8 @@ src/cpp/api_string.cpp \
 src/cpp/api_pointer.cpp \
 src/cpp/api_handle.cpp \
 src/cpp/api_error.cpp \
-src/cpp/api_optional.cpp
+src/cpp/api_optional.cpp \
+src/cpp/api_hypermat.cpp
 
 libsciapi_scilab_la_CPPFLAGS = -I$(srcdir)/includes/ \
 -I$(srcdir)/src/cpp/ \
@@ -664,6 +666,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_double.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_error.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_handle.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_hypermat.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_int.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_list.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciapi_scilab_la-api_optional.Plo@am__quote@
@@ -784,6 +787,13 @@ libsciapi_scilab_la-api_optional.lo: src/cpp/api_optional.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciapi_scilab_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciapi_scilab_la-api_optional.lo `test -f 'src/cpp/api_optional.cpp' || echo '$(srcdir)/'`src/cpp/api_optional.cpp
 
+libsciapi_scilab_la-api_hypermat.lo: src/cpp/api_hypermat.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciapi_scilab_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciapi_scilab_la-api_hypermat.lo -MD -MP -MF $(DEPDIR)/libsciapi_scilab_la-api_hypermat.Tpo -c -o libsciapi_scilab_la-api_hypermat.lo `test -f 'src/cpp/api_hypermat.cpp' || echo '$(srcdir)/'`src/cpp/api_hypermat.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciapi_scilab_la-api_hypermat.Tpo $(DEPDIR)/libsciapi_scilab_la-api_hypermat.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/api_hypermat.cpp' object='libsciapi_scilab_la-api_hypermat.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciapi_scilab_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciapi_scilab_la-api_hypermat.lo `test -f 'src/cpp/api_hypermat.cpp' || echo '$(srcdir)/'`src/cpp/api_hypermat.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 79effb0..776135d 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
@@ -258,6 +258,7 @@ lib /DEF:"$(ProjectDir)linpack_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     <ClCompile Include="src\cpp\api_double.cpp" />
     <ClCompile Include="src\cpp\api_error.cpp" />
     <ClCompile Include="src\cpp\api_handle.cpp" />
+    <ClCompile Include="src\cpp\api_hypermat.cpp" />
     <ClCompile Include="src\cpp\api_int.cpp" />
     <ClCompile Include="src\cpp\api_list.cpp" />
     <ClCompile Include="src\cpp\api_optional.cpp" />
@@ -274,6 +275,7 @@ lib /DEF:"$(ProjectDir)linpack_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     <ClInclude Include="includes\api_double.h" />
     <ClInclude Include="includes\api_error.h" />
     <ClInclude Include="includes\api_handle.h" />
+    <ClInclude Include="includes\api_hypermat.h" />
     <ClInclude Include="includes\api_int.h" />
     <ClInclude Include="includes\api_internal_handle.h" />
     <ClInclude Include="includes\api_optional.h" />
index 2f3d2fa..3f2f650 100644 (file)
@@ -69,6 +69,9 @@
     <ClCompile Include="src\cpp\api_optional.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\api_hypermat.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\api_boolean.h">
     <ClInclude Include="includes\api_optional.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="includes\api_hypermat.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="src\c\api_scilab.rc">
diff --git a/scilab/modules/api_scilab/help/en_US/hypermat/A_isHypermatType.xml b/scilab/modules/api_scilab/help/en_US/hypermat/A_isHypermatType.xml
new file mode 100644 (file)
index 0000000..0f93f19
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013  - Scilab Enterprises - Calixte DENIZET
+ * 
+ * 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    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="isHypermatType" xml:lang="en">
+    <refnamediv>
+        <refname>isHypermatType</refname>
+        <refpurpose>
+            Check if it is a hypermatrix variable.
+        </refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>int isHypermatType(void* _pvCtx, int* _piAddress)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>_pvCtx</term>
+                <listitem>
+                    <para>
+                        Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_piAddress</term>
+                <listitem>
+                    <para>
+                        Position in the Scilab memory where you want to put the variable.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Return value</title>
+        <para>1 if variable is a double type, otherwise 0</para>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/api_scilab/help/en_US/hypermat/B_getHypermatOfDouble.xml b/scilab/modules/api_scilab/help/en_US/hypermat/B_getHypermatOfDouble.xml
new file mode 100644 (file)
index 0000000..86b3192
--- /dev/null
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013  - Scilab Enterprises - Calixte DENIZET
+ * 
+ * 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    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="getHypermatOfDouble" xml:lang="en">
+    <refnamediv>
+        <refname>getHypermatOfDouble</refname>
+        <refpurpose>
+            Get a hypermatrix of double variable.
+        </refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>SciErr getHypermatOfDouble(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, double* _pdblReal)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>_pvCtx</term>
+                <listitem>
+                    <para>
+                        Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_piAddress</term>
+                <listitem>
+                    <para>
+                        Address of the Scilab variable.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_dims</term>
+                <listitem>
+                    <para>
+                        the hypermatrix dimensions.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_ndims</term>
+                <listitem>
+                    <para>
+                        the number of dimensions.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_pdblReal</term>
+                <listitem>
+                    <para>
+                        Double values.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Return value</title>
+        <para>A SciErr struct, the field iErr would contain the error number (0 if no error).</para>
+    </refsection>
+    <refsection>
+        <title>Gateway Source</title>
+        <programlisting role="code_gateway">
+            <![CDATA[ 
+#include "api_scilab.h"
+
+int hypermatExample(char *fname,unsigned long fname_len)
+{
+    SciErr sciErr;
+    int* piAddr = NULL;
+    int iType   = 0;
+    int iRet    = 0;
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 0, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (isEmptyMatrix(pvApiCtx, piAddr))
+    {
+        iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1);
+        if (iRet)
+        {
+            return iRet;
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = 0;
+    }
+    else if (isHypermatType(pvApiCtx, piAddr))
+    {
+        int * dims = NULL;
+        int ndims;
+        double* pdblReal = NULL;
+        double* pdblImg = NULL;
+
+        if (isHypermatComplex(pvApiCtx, piAddr))
+        {
+            sciErr = getComplexHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal, &pdblImg);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+
+            sciErr = createComplexHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal, pdblImg);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+        }
+        else
+        {
+            sciErr = getHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+
+            sciErr = createHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+    }
+
+    return 0;
+}]]>
+        </programlisting>
+    </refsection>
+    <refsection>
+        <title>Scilab test script</title>
+        <programlisting role="code_scilab"><![CDATA[ 
+a = hypermat([1 2 3], ones(1,6));
+b = a + %i*hypermat([1 2 3], 1:6);
+
+hypermatExample(a) == a
+hypermatExample(b) == b
+ ]]></programlisting>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/api_scilab/help/en_US/hypermat/C_getHypermatOfInt.xml b/scilab/modules/api_scilab/help/en_US/hypermat/C_getHypermatOfInt.xml
new file mode 100644 (file)
index 0000000..4b43e49
--- /dev/null
@@ -0,0 +1,264 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013  - Scilab Enterprises - Calixte DENIZET
+ * 
+ * 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    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="getHypermatOfInt" xml:lang="en">
+    <refnamediv>
+        <refname>getHypermatOfInt</refname>
+        <refpurpose>
+            Get a hypermatrix of integer variable.
+        </refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>SciErr getHypermatOfInt8(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, char* _pcData)</synopsis>
+        <synopsis>SciErr getHypermatOfUnsignedInt8(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned char* _pucData)</synopsis>
+        <synopsis>SciErr getHypermatOfInt16(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, short* _psData)</synopsis>
+        <synopsis>SciErr getHypermatOfUnsignedInt16(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned short* _pusData)</synopsis>
+        <synopsis>SciErr getHypermatOfInt32(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piData)</synopsis>
+        <synopsis>SciErr getHypermatOfUnsignedInt32(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned int* _puiData)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>_pvCtx</term>
+                <listitem>
+                    <para>
+                        Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_piAddress</term>
+                <listitem>
+                    <para>
+                        Address of the Scilab variable.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_dims</term>
+                <listitem>
+                    <para>
+                        the hypermatrix dimensions.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_ndims</term>
+                <listitem>
+                    <para>
+                        the number of dimensions.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>_p*Data</term>
+                <listitem>
+                    <para>
+                        the data.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Return value</title>
+        <para>A SciErr struct, the field iErr would contain the error number (0 if no error).</para>
+    </refsection>
+    <refsection>
+        <title>Gateway Source</title>
+        <programlisting role="code_gateway">
+            <![CDATA[ 
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+#include "MALLOC.h"
+
+int hypermatIntExample(char *fname,unsigned long fname_len)
+{
+    SciErr sciErr;
+    int* piAddr = NULL;
+    int iType   = 0;
+    int iRet    = 0;
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 0, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (isEmptyMatrix(pvApiCtx, piAddr))
+    {
+        iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1);
+        if (iRet)
+        {
+            return iRet;
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = 0;
+    }
+    else if (isHypermatType(pvApiCtx, piAddr))
+    {
+        int * dims = NULL;
+        int ndims;
+        void * data = NULL;
+        int htype = 0;
+        int precision;
+
+        sciErr = getHypermatType(pvApiCtx, piAddr, &htype);
+        if (sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return sciErr.iErr;
+        }
+
+        if (htype == sci_ints)
+        {
+            sciErr = getHypermatOfIntegerPrecision(pvApiCtx, piAddr, &precision);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+
+            switch (precision)
+            {
+            case SCI_INT8:
+                sciErr = getHypermatOfInteger8(pvApiCtx, piAddr, &dims, &ndims, (char*)&data);
+                if(sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+
+                sciErr = createHypermatOfInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const char*)data);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+                break;
+            case SCI_UINT8:
+                sciErr = getHypermatOfUnsignedInteger8(pvApiCtx, piAddr, &dims, &ndims, (unsigned char*)&data);
+                if(sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+
+                sciErr = createHypermatOfUnsignedInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned char*)data);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+                break;
+            case SCI_INT16:
+                sciErr = getHypermatOfInteger16(pvApiCtx, piAddr, &dims, &ndims, (short*)&data);
+                if(sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+
+                sciErr = createHypermatOfInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const short*)data);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+                break;
+            case SCI_UINT16:
+                sciErr = getHypermatOfUnsignedInteger16(pvApiCtx, piAddr, &dims, &ndims, (unsigned short*)&data);
+                if(sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+
+                sciErr = createHypermatOfUnsignedInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned short*)data);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+                break;
+            case SCI_INT32:
+                sciErr = getHypermatOfInteger32(pvApiCtx, piAddr, &dims, &ndims, (int*)&data);
+                if(sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+
+                sciErr = createHypermatOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const int*)data);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+                break;
+            case SCI_UINT32:
+                sciErr = getHypermatOfUnsignedInteger32(pvApiCtx, piAddr, &dims, &ndims, (unsigned int*)&data);
+                if(sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+
+                sciErr = createHypermatOfUnsignedInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned int*)data);
+                if (sciErr.iErr)
+                {
+                    printError(&sciErr, 0);
+                    return sciErr.iErr;
+                }
+                break;
+            }
+        }
+        else
+        {
+            Scierror(999, _("%s: Wrong type for argument %d: An integer expected.\n"), fname, 1);
+            return 1;
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+    }
+
+    return 0;
+}]]>
+        </programlisting>
+    </refsection>
+    <refsection>
+        <title>Scilab test script</title>
+        <programlisting role="code_scilab"><![CDATA[ 
+a = hypermat([1 2 3], int8(1:6));
+b = hypermat([1 2 3], uint8(1:6));
+c = hypermat([1 2 3], int16(1:6));
+d = hypermat([1 2 3], uint16(1:6));
+e = hypermat([1 2 3], int32(1:6));
+f = hypermat([1 2 3], uint32(1:6));
+
+hypermatExampleInt(a) == a
+hypermatExampleInt(b) == b
+hypermatExampleInt(c) == c
+hypermatExampleInt(d) == d
+hypermatExampleInt(e) == e
+hypermatExampleInt(f) == f
+ ]]></programlisting>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/api_scilab/includes/api_hypermat.h b/scilab/modules/api_scilab/includes/api_hypermat.h
new file mode 100644 (file)
index 0000000..f399890
--- /dev/null
@@ -0,0 +1,332 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
+ *
+ * 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
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ */
+
+#ifndef __HYPERMAT_API__
+#define __HYPERMAT_API__
+
+#if !defined(__INTERNAL_API_SCILAB__)
+#error Do not include api_hypermat.h. Include api_scilab.h instead.
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "doublecomplex.h"
+
+    /**************************************/
+    /*   Hypermatrices matrix functions   */
+    /**************************************/
+
+    /**
+     * Check if the variable type is double
+     * @param[in] _piAddress variable address
+     * @return 1 for true and 0 for false
+     */
+    int isHypermatType(void* _pvCtx, int* _piAddress);
+
+    /**
+     * Check if the variable is complex
+     * @param[in] _piAddress variable address
+     * @return 1 for true and 0 for false
+     */
+    int isHypermatComplex(void* _pvCtx, int* _piAddress);
+
+    /**
+     * Get the base type
+     * @param[in] _piAddress variable address
+     * @param[out] _piType return the base type
+     */
+    SciErr getHypermatType(void *_pvCtx, int *_piAddress, int *_piType);
+
+    /**
+     * Get integer precision ( SCI_xINTx )
+     * @param[in] _piAddress variable address
+     * @param[out] _piPrecison return integer precision ( SCI_xINTx )
+     */
+    SciErr getHypermatOfIntegerPrecision(void *_pvCtx, int *_piAddress, int *_piPrecision);
+
+    /**
+     * Get the hypermatrix dimensions
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     */
+    SciErr getHypermatDimensions(void *_pvCtx, int *_piAddress, int **_dims, int *_ndims);
+
+    /**
+     * Get the hypermatrix entries address
+     * @param[in] _piAddress variable address
+     * @param[out] return _piEntriesAddress entries address
+     */
+    SciErr getHypermatEntries(void* _pvCtx, int* _piAddress, int ** _piEntriesAddress);
+
+    /**
+     * Get polynomial variable name
+     * @param[in] _piAddress variable address
+     * @param[out] _pstVarName return variable name of polynomials
+     * @param[out] _piVarNameLen return length of _pstVarName
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr getHypermatPolyVariableName(void* _pvCtx, int* _piAddress, char* _pstVarName, int* _piVarNameLen);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _piNbCoef return number of polynomial coefficients for each element
+     * @param[out] _pdblReal return real coefficients
+     */
+    SciErr getHypermatOfPoly(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piNbCoef, double** _pdblReal);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _piNbCoef return number of polynomial coefficients for each element
+     * @param[out] _pdblReal return real coefficients
+     * @param[out] _pdblImg return imaginary coefficients
+     */
+    SciErr getComplexHypermatOfPoly(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piNbCoef, double** _pdblReal, double** _pdblImg);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _piLength return strings lengths
+     * @param[out] _pstStrings return the strings data
+     */
+    SciErr getHypermatOfString(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piLength, char** _pstStrings);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _piLength return strings lengths
+     * @param[out] _pwstStrings return the strings data
+     */
+    SciErr getHypermatOfWideString(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piLength, wchar_t** _pwstStrings);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _pdblReal return the double data
+     */
+    SciErr getHypermatOfDouble(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, double** _pdblReal);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _pdblReal return the real data
+     * @param[out] _pdblImg return the imaginary data
+     */
+    SciErr getComplexHypermatOfDouble(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, double** _pdblReal, double** _pdblImg);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _pucData8 return the unsigned char data
+     */
+    SciErr getHypermatOfUnsignedInteger8(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned char** _pucData8);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _pcData8 return the char data
+     */
+    SciErr getHypermatOfInteger8(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, char** _pcData8);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _pusData16 return the unsigned short data
+     */
+    SciErr getHypermatOfUnsignedInteger16(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned short** _pusData16);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _psData16 return the short data
+     */
+    SciErr getHypermatOfInteger16(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, short** _psData16);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _puiData32 return the unsigned int data
+     */
+    SciErr getHypermatOfUnsignedInteger32(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned int** _puiData32);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _piData32 return the int data
+     */
+    SciErr getHypermatOfInteger32(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int** _piData32);
+
+    /**
+     * Get the hypermatrix dimensions and data
+     * @param[in] _piAddress variable address
+     * @param[out] _dims return the dimensions
+     * @param[out] _ndims return the number of dimensions
+     * @param[out] _piBool return the boolean data
+     */
+    SciErr getHypermatOfBoolean(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int** _piBool);
+
+    /**
+     * Create a polynomial hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _pstVarName polynomial variable name
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _piNbCoef number of polynomial coefficients for each element
+     * @param[in] _pdblReal pointer to real coefficients
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfPoly(void* _pvCtx, int _iVar, char* _pstVarName, int *_dims, int _ndims, const int* _piNbCoef, const double* const* _pdblReal);
+
+    /**
+     * Create a complex polynomial hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _pstVarName polynomial variable name
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _piNbCoef number of polynomial coefficients for each element
+     * @param[in] _pdblReal pointer to real coefficients
+     * @param[in] _pdblImg pointer to imaginary coefficients
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createComplexHypermatOfPoly(void* _pvCtx, int _iVar, char* _pstVarName, int *_dims, int _ndims, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg);
+
+    /**
+     * Create a double hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _pdblReal pointer to real data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfDouble(void* _pvCtx, int _iVar, int *_dims, int _ndims, const double* _pdblReal);
+
+    /**
+     * Create a complex hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _pdblReal pointer to real data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createComplexHypermatOfDouble(void* _pvCtx, int _iVar, int *_dims, int _ndims, const double* _pdblReal, const double* _pdblImg);
+
+    /**
+     * Create a boolean hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _piBool pointer to boolean data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfBoolean(void* _pvCtx, int _iVar, int *_dims, int _ndims, const int* _piBool);
+
+    /**
+     * Create a string hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _pstStrings pointer to string data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfString(void* _pvCtx, int _iVar, int *_dims, int _ndims, const char* const* _pstStrings);
+
+    /**
+     * Create a int8 hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _pcData8 pointer to char data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfInteger8(void* _pvCtx, int _iVar, int *_dims, int _ndims, const char* _pcData8);
+
+    /**
+     * Create a uint8 hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _pucData8 pointer to unsigned char data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfUnsignedInteger8(void* _pvCtx, int _iVar, int *_dims, int _ndims, const unsigned char* _pucData8);
+
+    /**
+     * Create a int16 hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _psData16 pointer to short data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfInteger16(void* _pvCtx, int _iVar, int *_dims, int _ndims, const short* _psData16);
+
+    /**
+     * Create a uint16 hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _pusData16 pointer to unsigned short data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfUnsignedInteger16(void* _pvCtx, int _iVar, int *_dims, int _ndims, const unsigned short* _pusData16);
+
+    /**
+     * Create a int32 hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _piData32 pointer to int data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfInteger32(void* _pvCtx, int _iVar, int *_dims, int _ndims, const int* _piData32);
+
+    /**
+     * Create a uint32 hypermatrix
+     * @param[in] _iVar variable number
+     * @param[in] _dims the dimensions
+     * @param[in] _ndims the number of dimensions
+     * @param[in] _puiData32 pointer to unsigned int data
+     * @return if the operation succeeded ( 0 ) or not ( !0 )
+     */
+    SciErr createHypermatOfUnsignedInteger32(void* _pvCtx, int _iVar, int *_dims, int _ndims, const unsigned int* _puiData32);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HYPERMAT_API__ */
index 1af6a54..523bf0e 100644 (file)
@@ -47,6 +47,7 @@
 #include "api_error.h"
 #include "api_handle.h"
 #include "api_optional.h"
+#include "api_hypermat.h"
 #undef __INTERNAL_API_SCILAB__
 
 #include "core_math.h"
diff --git a/scilab/modules/api_scilab/src/cpp/api_hypermat.cpp b/scilab/modules/api_scilab/src/cpp/api_hypermat.cpp
new file mode 100644 (file)
index 0000000..85775fc
--- /dev/null
@@ -0,0 +1,771 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
+ *
+ * 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
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ * Please note that piece of code will be rewrited for the Scilab 6 family
+ * However, the API (profile of the functions in the header files) will be
+ * still available and supported in Scilab 6.
+ */
+
+#include <stdio.h>
+#include "api_scilab.h"
+#include "api_internal_common.h"
+#include "api_internal_double.h"
+#include "localization.h"
+
+#include "call_scilab.h"
+
+int isHypermatType(void* _pvCtx, int* _piAddress)
+{
+    if (_piAddress[0] != sci_mlist || _piAddress[1] != 3)
+    {
+        // not a mlist or not containing 3 fields
+        return 0;
+    }
+
+    if (_piAddress[6] != sci_strings || _piAddress[7] != 1 || _piAddress[8] != 3)
+    {
+        // first field is not a matrix 1x3 of strings
+        return 0;
+    }
+
+    if (_piAddress[11] - 1 != 2 || _piAddress[14] != 17 || _piAddress[15] != 22)
+    {
+        // mlist type is not of length 2 or type is not "hm" ("hm" == [17 22])
+        return 0;
+    }
+
+    return 1;
+}
+
+int isHypermatComplex(void* _pvCtx, int* _piAddress)
+{
+    int * _piItemAddress = NULL;
+    SciErr sciErr;
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &_piItemAddress);
+    if (sciErr.iErr)
+    {
+        return 0;
+    }
+
+    return isVarComplex(_pvCtx, _piItemAddress);
+}
+
+SciErr getHypermatType(void *_pvCtx, int *_piAddress, int *_piType)
+{
+    int * _piItemAddress = NULL;
+    SciErr sciErr;
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &_piItemAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getVarType(_pvCtx, _piItemAddress, _piType);
+}
+
+SciErr getHypermatOfIntegerPrecision(void *_pvCtx, int *_piAddress, int *_piPrecision)
+{
+    int * _piItemAddress = NULL;
+    SciErr sciErr;
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &_piItemAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfIntegerPrecision(_pvCtx, _piItemAddress, _piPrecision);
+}
+
+SciErr getHypermatDimensions(void *_pvCtx, int *_piAddress, int **_dims, int *_ndims)
+{
+    int * _piItemAddress = NULL;
+    SciErr sciErr;
+    int _rows = 0;
+
+    sciErr = getListItemAddress(_pvCtx, _piAddress, 2, &_piItemAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfInteger32(_pvCtx, _piItemAddress, &_rows, _ndims, _dims);
+}
+
+SciErr getHypermatEntries(void* _pvCtx, int* _piAddress, int ** _piEntriesAddress)
+{
+    return getListItemAddress(_pvCtx, _piAddress, 3, _piEntriesAddress);
+}
+
+SciErr getHypermatOfDouble(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, double** _pdblReal)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfDouble(_pvCtx, entries, &_rows, &_cols, _pdblReal);
+}
+
+SciErr getComplexHypermatOfDouble(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, double** _pdblReal, double** _pdblImg)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getComplexMatrixOfDouble(_pvCtx, entries, &_rows, &_cols, _pdblReal, _pdblImg);
+}
+
+SciErr getHypermatPolyVariableName(void* _pvCtx, int* _piAddress, char* _pstVarName, int* _piVarNameLen)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getPolyVariableName(_pvCtx, entries, _pstVarName, _piVarNameLen);
+}
+
+SciErr getHypermatOfPoly(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piNbCoef, double** _pdblReal)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfPoly(_pvCtx, entries, &_rows, &_cols, _piNbCoef, _pdblReal);
+}
+
+SciErr getComplexHypermatOfPoly(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piNbCoef, double** _pdblReal, double** _pdblImg)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getComplexMatrixOfPoly(_pvCtx, entries, &_rows, &_cols, _piNbCoef, _pdblReal, _pdblImg);
+}
+
+SciErr getHypermatOfString(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piLength, char** _pstStrings)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfString(_pvCtx, entries, &_rows, &_cols, _piLength, _pstStrings);
+}
+
+SciErr getHypermatOfWideString(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piLength, wchar_t** _pwstStrings)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfWideString(_pvCtx, entries, &_rows, &_cols, _piLength, _pwstStrings);
+}
+
+SciErr getHypermatOfInteger8(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, char** _pcData8)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfInteger8(_pvCtx, entries, &_rows, &_cols, _pcData8);
+}
+
+SciErr getHypermatOfUnsignedInteger8(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned char** _pucData8)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfUnsignedInteger8(_pvCtx, entries, &_rows, &_cols, _pucData8);
+}
+
+SciErr getHypermatOfInteger16(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, short** _psData16)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfInteger16(_pvCtx, entries, &_rows, &_cols, _psData16);
+}
+
+SciErr getHypermatOfUnsignedInteger16(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned short** _pusData16)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfUnsignedInteger16(_pvCtx, entries, &_rows, &_cols, _pusData16);
+}
+
+SciErr getHypermatOfInteger32(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int** _piData32)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfInteger32(_pvCtx, entries, &_rows, &_cols, _piData32);
+}
+
+SciErr getHypermatOfUnsignedInteger32(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned int** _puiData32)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfUnsignedInteger32(_pvCtx, entries, &_rows, &_cols, _puiData32);
+}
+
+SciErr getHypermatOfBoolean(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int** _piBool)
+{
+    SciErr sciErr;
+    int * entries = NULL;
+    int _rows = 0;
+    int _cols = 0;
+
+    sciErr = getHypermatDimensions(_pvCtx, _piAddress, _dims, _ndims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = getHypermatEntries(_pvCtx, _piAddress, &entries);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return getMatrixOfBoolean(_pvCtx, entries, &_rows, &_cols, _piBool);
+}
+
+SciErr createEmptyHypermat(void *_pvCtx, int _iVar, const int * _dims, int _ndims, int ** _piAddress)
+{
+    static const char * fields[3] = {"hm", "dims", "entries"};
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createMList(_pvCtx, _iVar, 3, _piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = createMatrixOfStringInList(_pvCtx, _iVar, *_piAddress, 1, 1, 3, fields);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    sciErr = createMatrixOfInteger32InList(_pvCtx, _iVar, *_piAddress, 2, 1, _ndims, _dims);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfString(void *_pvCtx, int _iVar, int * _dims, int _ndims, const char* const* _pstStrings)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfStringInList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _pstStrings);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfPoly(void *_pvCtx, int _iVar, char* _pstVarName, int * _dims, int _ndims, const int* _piNbCoef, const double* const* _pdblReal)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfPolyInList(_pvCtx, _iVar, _piAddress, 3, _pstVarName, iNbElements, 1, _piNbCoef, _pdblReal);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createComplexHypermatOfPoly(void *_pvCtx, int _iVar, char* _pstVarName, int * _dims, int _ndims, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createComplexMatrixOfPolyInList(_pvCtx, _iVar, _piAddress, 3, _pstVarName, iNbElements, 1, _piNbCoef, _pdblReal, _pdblImg);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfDouble(void *_pvCtx, int _iVar, int * _dims, int _ndims, const double * _pdblReal)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfDoubleInList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _pdblReal);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createComplexHypermatOfDouble(void *_pvCtx, int _iVar, int * _dims, int _ndims, const double * _pdblReal, const double * _pdblImg)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createComplexMatrixOfDoubleInList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _pdblReal, _pdblImg);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfBoolean(void *_pvCtx, int _iVar, int * _dims, int _ndims, const int * _piBool)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfBooleanInList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _piBool);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfInteger8(void *_pvCtx, int _iVar, int * _dims, int _ndims, const char * _pcData8)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfInteger8InList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _pcData8);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfUnsignedInteger8(void *_pvCtx, int _iVar, int * _dims, int _ndims, const unsigned char * _pucData8)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfUnsignedInteger8InList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _pucData8);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfInteger16(void *_pvCtx, int _iVar, int * _dims, int _ndims, const short * _psData16)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfInteger16InList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _psData16);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfUnsignedInteger16(void *_pvCtx, int _iVar, int * _dims, int _ndims, const unsigned short * _pusData16)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfUnsignedInteger16InList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _pusData16);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfInteger32(void *_pvCtx, int _iVar, int * _dims, int _ndims, const int * _piData32)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfInteger32InList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _piData32);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
+
+SciErr createHypermatOfUnsignedInteger32(void *_pvCtx, int _iVar, int * _dims, int _ndims, const unsigned int * _puiData32)
+{
+    int * _piAddress = NULL;
+    int iNbElements = 1;
+    SciErr sciErr;
+    sciErr.iErr = 0;
+    sciErr.iMsgCount = 0;
+
+    sciErr = createEmptyHypermat(_pvCtx, _iVar, _dims, _ndims, &_piAddress);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    for (int i = 0; i < _ndims; i++)
+    {
+        iNbElements *= _dims[i];
+    }
+
+    sciErr = createMatrixOfUnsignedInteger32InList(_pvCtx, _iVar, _piAddress, 3, iNbElements, 1, _puiData32);
+    if (sciErr.iErr)
+    {
+        return sciErr;
+    }
+
+    return sciErr;
+}
diff --git a/scilab/modules/api_scilab/tests/unit_tests/hypermatExample.c b/scilab/modules/api_scilab/tests/unit_tests/hypermatExample.c
new file mode 100644 (file)
index 0000000..224f2a4
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises
+ *
+ * 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
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+#include "MALLOC.h"
+
+int hypermatExample(char *fname, unsigned long fname_len)
+{
+    SciErr sciErr;
+    int* piAddr = NULL;
+    int iType   = 0;
+    int iRet    = 0;
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 0, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (isEmptyMatrix(pvApiCtx, piAddr))
+    {
+        iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1);
+        if (iRet)
+        {
+            return iRet;
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = 0;
+    }
+    else if (isHypermatType(pvApiCtx, piAddr))
+    {
+        int * dims = NULL;
+        int ndims;
+        double* pdblReal = NULL;
+        double* pdblImg = NULL;
+
+        if (isHypermatComplex(pvApiCtx, piAddr))
+        {
+            sciErr = getComplexHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal, &pdblImg);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+
+            sciErr = createComplexHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal, pdblImg);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+        }
+        else
+        {
+            sciErr = getHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+
+            sciErr = createHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+    }
+
+    return 0;
+}
diff --git a/scilab/modules/api_scilab/tests/unit_tests/hypermatExample.dia.ref b/scilab/modules/api_scilab/tests/unit_tests/hypermatExample.dia.ref
new file mode 100644 (file)
index 0000000..e18c6c3
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises 
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+ilib_verbose(0);
+mkdir(pathconvert(TMPDIR+"/hypermatExample"));
+cd(pathconvert(TMPDIR+"/hypermatExample"));
+copyfile(SCI+"/modules/api_scilab/tests/unit_tests/hypermatExample.c",pathconvert(TMPDIR+"/hypermatExample/hypermatExample.c",%F));
+cflags = "-I"+SCI+"/modules/localization/includes";
+ilib_build("gw_hypermatExample",["hypermatExample","hypermatExample"],"hypermatExample.c",[],"","",cflags);
+exec("loader.sce");
+a = hypermat([1 2 3], ones(1,6));
+b = a + %i*hypermat([1 2 3], 1:6);
+assert_checkequal(hypermatExample(a), a);
+assert_checkequal(hypermatExample(b), b);
diff --git a/scilab/modules/api_scilab/tests/unit_tests/hypermatExample.tst b/scilab/modules/api_scilab/tests/unit_tests/hypermatExample.tst
new file mode 100644 (file)
index 0000000..fb4d195
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises 
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+ilib_verbose(0);
+mkdir(pathconvert(TMPDIR+"/hypermatExample"));
+cd(pathconvert(TMPDIR+"/hypermatExample"));
+copyfile(SCI+"/modules/api_scilab/tests/unit_tests/hypermatExample.c",pathconvert(TMPDIR+"/hypermatExample/hypermatExample.c",%F));
+cflags = "-I"+SCI+"/modules/localization/includes";
+ilib_build("gw_hypermatExample",["hypermatExample","hypermatExample"],"hypermatExample.c",[],"","",cflags);
+exec("loader.sce");
+
+a = hypermat([1 2 3], ones(1,6));
+b = a + %i*hypermat([1 2 3], 1:6);
+
+assert_checkequal(hypermatExample(a), a);
+assert_checkequal(hypermatExample(b), b);
diff --git a/scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.c b/scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.c
new file mode 100644 (file)
index 0000000..57fdb77
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises
+ *
+ * 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
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+#include "MALLOC.h"
+
+int hypermatIntExample(char *fname, unsigned long fname_len)
+{
+    SciErr sciErr;
+    int* piAddr = NULL;
+    int iType   = 0;
+    int iRet    = 0;
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 0, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (isEmptyMatrix(pvApiCtx, piAddr))
+    {
+        iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1);
+        if (iRet)
+        {
+            return iRet;
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = 0;
+    }
+    else if (isHypermatType(pvApiCtx, piAddr))
+    {
+        int * dims = NULL;
+        int ndims;
+        void * data = NULL;
+        int htype = 0;
+        int precision;
+
+        sciErr = getHypermatType(pvApiCtx, piAddr, &htype);
+        if (sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return sciErr.iErr;
+        }
+
+        if (htype == sci_ints)
+        {
+            sciErr = getHypermatOfIntegerPrecision(pvApiCtx, piAddr, &precision);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return sciErr.iErr;
+            }
+
+            switch (precision)
+            {
+                case SCI_INT8:
+                    sciErr = getHypermatOfInteger8(pvApiCtx, piAddr, &dims, &ndims, (char*)&data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+
+                    sciErr = createHypermatOfInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const char*)data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+                    break;
+                case SCI_UINT8:
+                    sciErr = getHypermatOfUnsignedInteger8(pvApiCtx, piAddr, &dims, &ndims, (unsigned char*)&data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+
+                    sciErr = createHypermatOfUnsignedInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned char*)data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+                    break;
+                case SCI_INT16:
+                    sciErr = getHypermatOfInteger16(pvApiCtx, piAddr, &dims, &ndims, (short*)&data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+
+                    sciErr = createHypermatOfInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const short*)data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+                    break;
+                case SCI_UINT16:
+                    sciErr = getHypermatOfUnsignedInteger16(pvApiCtx, piAddr, &dims, &ndims, (unsigned short*)&data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+
+                    sciErr = createHypermatOfUnsignedInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned short*)data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+                    break;
+                case SCI_INT32:
+                    sciErr = getHypermatOfInteger32(pvApiCtx, piAddr, &dims, &ndims, (int*)&data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+
+                    sciErr = createHypermatOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const int*)data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+                    break;
+                case SCI_UINT32:
+                    sciErr = getHypermatOfUnsignedInteger32(pvApiCtx, piAddr, &dims, &ndims, (unsigned int*)&data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+
+                    sciErr = createHypermatOfUnsignedInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, (const unsigned int*)data);
+                    if (sciErr.iErr)
+                    {
+                        printError(&sciErr, 0);
+                        return sciErr.iErr;
+                    }
+                    break;
+            }
+        }
+        else
+        {
+            Scierror(999, _("%s: Wrong type for argument %d: An integer expected.\n"), fname, 1);
+            return 1;
+        }
+
+        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+    }
+
+    return 0;
+}
diff --git a/scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.dia.ref b/scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.dia.ref
new file mode 100644 (file)
index 0000000..5446f89
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises 
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+ilib_verbose(0);
+mkdir(pathconvert(TMPDIR+"/hypermatIntExample"));
+cd(pathconvert(TMPDIR+"/hypermatIntExample"));
+copyfile(SCI+"/modules/api_scilab/tests/unit_tests/hypermatIntExample.c",pathconvert(TMPDIR+"/hypermatIntExample/hypermatIntExample.c",%F));
+cflags = "-I"+SCI+"/modules/localization/includes";
+ilib_build("gw_hypermatIntExample",["hypermatIntExample","hypermatIntExample"],"hypermatIntExample.c",[],"","",cflags);
+exec("loader.sce");
+a = hypermat([1 2 3], int8(1:6));
+b = hypermat([1 2 3], uint8(1:6));
+c = hypermat([1 2 3], int16(1:6));
+d = hypermat([1 2 3], uint16(1:6));
+e = hypermat([1 2 3], int32(1:6));
+f = hypermat([1 2 3], uint32(1:6));
+assert_checkequal(hypermatIntExample(a), a);
+assert_checkequal(hypermatIntExample(b), b);
+assert_checkequal(hypermatIntExample(c), c);
+assert_checkequal(hypermatIntExample(d), d);
+assert_checkequal(hypermatIntExample(e), e);
+assert_checkequal(hypermatIntExample(f), f);
diff --git a/scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.tst b/scilab/modules/api_scilab/tests/unit_tests/hypermatIntExample.tst
new file mode 100644 (file)
index 0000000..abb1421
--- /dev/null
@@ -0,0 +1,29 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises 
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+ilib_verbose(0);
+mkdir(pathconvert(TMPDIR+"/hypermatIntExample"));
+cd(pathconvert(TMPDIR+"/hypermatIntExample"));
+copyfile(SCI+"/modules/api_scilab/tests/unit_tests/hypermatIntExample.c",pathconvert(TMPDIR+"/hypermatIntExample/hypermatIntExample.c",%F));
+cflags = "-I"+SCI+"/modules/localization/includes";
+ilib_build("gw_hypermatIntExample",["hypermatIntExample","hypermatIntExample"],"hypermatIntExample.c",[],"","",cflags);
+exec("loader.sce");
+
+a = hypermat([1 2 3], int8(1:6));
+b = hypermat([1 2 3], uint8(1:6));
+c = hypermat([1 2 3], int16(1:6));
+d = hypermat([1 2 3], uint16(1:6));
+e = hypermat([1 2 3], int32(1:6));
+f = hypermat([1 2 3], uint32(1:6));
+
+assert_checkequal(hypermatIntExample(a), a);
+assert_checkequal(hypermatIntExample(b), b);
+assert_checkequal(hypermatIntExample(c), c);
+assert_checkequal(hypermatIntExample(d), d);
+assert_checkequal(hypermatIntExample(e), e);
+assert_checkequal(hypermatIntExample(f), f);