2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Vincent COUVERT
4 * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14 #include "CreateMatlabVariable.h"
15 #include "api_scilab.h"
17 #include "localization.h"
22 int CreateHyperMatrixVariable(int iVar, const char *type, int *iscomplex, int * rank, int *dims, double *realdata, double *complexdata, int * parent, int item_position)
24 static const char *tlistFields[] = {"hm", "dims","entries"};
25 int nbRow = 0, nbCol = 0;
30 /* Used for integer hypermatrices */
31 char * tmp_int8 = NULL;
32 short * tmp_int16 = NULL;
33 int * tmp_int32 = NULL;
34 unsigned char * tmp_uint8 = NULL;
35 unsigned short * tmp_uint16 = NULL;
36 unsigned int * tmp_uint32 = NULL;
37 #ifdef __SCILAB_INT64__
38 long long * tmp_int64 = NULL;
39 unsigned long long * tmp_uint64 = NULL;
44 sciErr = createMList(pvApiCtx, iVar, 3, &hm_addr);
47 printError(&sciErr, 0);
53 sciErr = createMListInList(pvApiCtx, iVar, parent, item_position, 3, &hm_addr);
56 printError(&sciErr, 0);
64 sciErr = createMatrixOfStringInList(pvApiCtx, iVar, hm_addr, 1, nbRow, nbCol, (const char **)tlistFields);
67 printError(&sciErr, 0);
72 sciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, hm_addr, 2, 1, *rank, dims);
75 printError(&sciErr, 0);
82 for (K=0; K<*rank; K++)
87 if (strcmp(type,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE) == 0)
92 tmp_int8 = (char *)MALLOC(nbRow*nbCol*sizeof(char));
95 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
98 for(i=0; i<nbRow*nbCol; i++)
100 tmp_int8[i] = ((char *)realdata)[i];
102 sciErr = createMatrixOfInteger8InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_int8);
105 printError(&sciErr, 0);
112 tmp_int16 = (short *)MALLOC(nbRow*nbCol*sizeof(short));
113 if (tmp_int16 == NULL)
115 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
118 for(i=0; i<nbRow*nbCol; i++)
120 tmp_int16[i] = ((short *)realdata)[i];
122 sciErr = createMatrixOfInteger16InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_int16);
125 printError(&sciErr, 0);
133 tmp_int32 = (int *)MALLOC(nbRow*nbCol*sizeof(int));
134 if (tmp_int32 == NULL)
136 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
139 for(i=0; i<nbRow*nbCol; i++)
141 tmp_int32[i] = ((int *)realdata)[i];
143 sciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_int32);
146 printError(&sciErr, 0);
152 #ifdef __SCILAB_INT64__
154 tmp_int64 = (long long *)MALLOC(nbRow*nbCol*sizeof(long long));
155 if (tmp_int64 == NULL)
157 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
160 for(i=0; i<nbRow*nbCol; i++)
162 tmp_int64[i] = ((long long *)realdata)[i];
164 qciErr = createMatrixOfInteger64InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_int64);
167 printError(&sciErr, 0);
175 tmp_uint8 = (unsigned char *)MALLOC(nbRow*nbCol*sizeof(unsigned char));
176 if (tmp_uint8 == NULL)
178 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
181 for(i=0; i<nbRow*nbCol; i++)
183 tmp_uint8[i] = ((unsigned char *)realdata)[i];
185 sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_uint8);
188 printError(&sciErr, 0);
195 tmp_uint16 = (unsigned short *)MALLOC(nbRow*nbCol*sizeof(unsigned short));
196 if (tmp_uint16 == NULL)
198 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
201 for(i=0; i<nbRow*nbCol; i++)
203 tmp_uint16[i] = ((unsigned short *)realdata)[i];
205 sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_uint16);
208 printError(&sciErr, 0);
215 tmp_uint32 = (unsigned int *)MALLOC(nbRow*nbCol*sizeof(unsigned int));
216 if (tmp_uint32 == NULL)
218 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
221 for(i=0;i<nbRow*nbCol; i++)
223 tmp_uint32[i] = ((unsigned int *)realdata)[i];
225 sciErr = createMatrixOfUnsignedInteger32InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_uint32);
228 printError(&sciErr, 0);
234 #ifdef __SCILAB_INT64__
236 tmp_uint64 = (unsigned long long *)MALLOC(nbRow*nbCol*sizeof(unsigned long long));
237 if (tmp_uint64 == NULL)
239 Scierror(999, _("%s: No more memory.\n"), "CreateHyperMatrixVariable");
242 for(i=0; i<nbRow*nbCol; i++)
244 tmp_uint64[i] = ((unsigned long long *)realdata)[i];
246 sciErr = createMatrixOfUnsignedInteger64InList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, tmp_uint64);
249 printError(&sciErr, 0);
258 else if (strcmp(type, MATRIX_OF_BOOLEAN_DATATYPE) == 0)
260 sciErr = createMatrixOfDoubleInList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, realdata);
263 printError(&sciErr, 0);
271 sciErr = createMatrixOfDoubleInList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, realdata);
274 printError(&sciErr, 0);
280 sciErr = createComplexMatrixOfDoubleInList(pvApiCtx, iVar, hm_addr, 3, nbRow, nbCol, realdata, complexdata);
283 printError(&sciErr, 0);