2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006/2007 - INRIA - Alan LAYEC
4 * Copyright (C) 2007 - INRIA - Allan CORNET
5 * Copyright (C) 2012 - DIGITEO - Allan CORNET
6 * Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
8 * Copyright (C) 2012 - 2016 - Scilab Enterprises
10 * This file is hereby licensed under the terms of the GNU GPL v2.0,
11 * pursuant to article 5.3.4 of the CeCILL v.2.1.
12 * This file was originally licensed under the terms of the CeCILL v2.1,
13 * and continues to be available under such terms.
14 * For more information, see the COPYING file which you should have received
15 * along with this program.
18 /*--------------------------------------------------------------------------*/
20 #include "api_scilab.h"
21 #include "fftw_utilities.h"
22 #include "sci_malloc.h"
24 #include "localization.h"
25 #include "freeArrayOfString.h"
27 #include "os_string.h"
28 /*--------------------------------------------------------------------------*/
29 /* fftw_flags function.
32 * -->[a,b]=fftw_flags();
34 * -->[a,b]=fftw_flags(S);
36 * a is an int scalar. (the int value of
37 * the flag parameter of fftw)
38 * b is a string matrix.(the string values of
39 * the flag parameter of fftw)
40 * S is a string matrix or an int or a double scalar
41 * given the value(s) of the fftw flag parameter.
43 * This function gives and set the flag parameter of fftw
44 * when creating a new plan.
45 * This should be done before calling fftw function.
46 * (default is FFTW_ESTIMATE)
48 /*--------------------------------------------------------------------------*/
49 int sci_fftw_flags(char *fname, void* pvApiCtx)
51 /* declaration of variables to store scilab parameters address */
52 static int m1 = 0, n1 = 0;
57 unsigned int uiVar1 = 0;
58 int* piDataOut = NULL;
63 /* please update me ! */
64 static int nb_flag = 22;
67 /* documented flags */
71 "FFTW_CONSERVE_MEMORY",
73 "FFTW_PRESERVE_INPUT",
77 /* undocumented beyond-guru flags */
78 "FFTW_ESTIMATE_PATIENT",
81 "FFTW_NO_NONTHREADED",
83 "FFTW_NO_INDIRECT_OP",
84 "FFTW_ALLOW_LARGE_GENERIC",
85 "FFTW_NO_RANK_SPLITS",
86 "FFTW_NO_VRANK_SPLITS",
90 "FFTW_NO_FIXED_RADIX_LARGE_N",
94 static unsigned flagt[] =
96 /* documented flags */
100 FFTW_CONSERVE_MEMORY,
106 /* undocumented beyond-guru flags */
107 FFTW_ESTIMATE_PATIENT,
113 FFTW_ALLOW_LARGE_GENERIC,
115 FFTW_NO_VRANK_SPLITS,
119 FFTW_NO_FIXED_RADIX_LARGE_N,
128 CheckInputArgument(pvApiCtx, 0, 1);
130 if (nbInputArgument(pvApiCtx) == 0)
136 //get variable address of the input argument
137 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
140 printError(&sciErr, 0);
144 getVarType(pvApiCtx, piAddr1, &iType);
151 int* pi32Data = NULL;
152 unsigned int* pui32Data = NULL;
154 getMatrixOfIntegerPrecision(pvApiCtx, piAddr1, &iPrecision);
155 if (iPrecision != SCI_INT32 && iPrecision != SCI_UINT32)
157 Scierror(999, _("%s: Wrong type for input argument #%d: A int32 expected.\n"), fname, 1);
161 if (iPrecision == SCI_INT32)
163 sciErr = getMatrixOfInteger32(pvApiCtx, piAddr1, &m1, &n1, &pi32Data);
164 uiVar1 = (unsigned int)pi32Data[0];
168 sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, piAddr1, &m1, &n1, &pui32Data);
169 uiVar1 = pui32Data[0];
174 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
175 printError(&sciErr, 0);
183 double* pdblData = NULL;
184 sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &pdblData);
187 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
188 printError(&sciErr, 0);
192 uiVar1 = (unsigned int)pdblData[0];
198 //fisrt call to retrieve dimensions
199 sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, NULL, NULL);
202 printError(&sciErr, 0);
206 piLen = (int*)MALLOC(sizeof(int) * m1 * n1);
208 //second call to retrieve length of each string
209 sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, NULL);
213 printError(&sciErr, 0);
217 Str1 = (char**)MALLOC(sizeof(char*) * m1 * n1);
218 for (i = 0 ; i < m1 * n1 ; i++)
220 Str1[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
223 //third call to retrieve data
224 sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, Str1);
228 freeArrayOfString(Str1, m1 * n1);
229 printError(&sciErr, 0);
233 for (j = 0; j < m1 * n1; j++)
235 for (i = 0; i < nb_flag; i++)
237 if (strcmp(Str1[j], Str[i]) == 0)
246 freeArrayOfString(Str1, m1 * n1);
247 Scierror(999, _("%s: Wrong values for input argument #%d: FFTW flag expected.\n"), fname, 1);
254 flagv = ( flagv | (1U << (i - 1)) );
259 uiVar1 = (unsigned int)flagv;
261 freeArrayOfString(Str1, m1 * n1);
267 Scierror(53, _("%s: Wrong type for input argument #%d.\n"), fname, 1);
271 if (m1 != 1 || n1 != 1)
273 Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, 1, 1);
277 setCurrentFftwFlags(uiVar1);
280 /* return value of Sci_Plan.flags in position 2 */
281 sciErr = allocMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, 1, &piDataOut);
284 printError(&sciErr, 0);
285 Scierror(999, _("%s: No more memory.\n"), fname);
289 piDataOut[0] = (int) getCurrentFftwFlags();
291 /*Test for only FFTW_MEASURE*/
292 if (getCurrentFftwFlags() == 0)
295 if ((Str3 = (char **)MALLOC(sizeof(char *))) == NULL)
297 Scierror(999, _("%s: No more memory.\n"), fname);
301 Str3[0] = os_strdup(Str[0]);
304 Scierror(999, _("%s: No more memory.\n"), fname);
312 for (i = 1; i < nb_flag; i++)
314 if ((getCurrentFftwFlags() & flagt[i]) == flagt[i])
319 Str3 = (char **)REALLOC(Str3, sizeof(char *) * j);
323 Str3 = (char **)MALLOC(sizeof(char *) * j);
328 Scierror(999, _("%s: No more memory.\n"), fname);
332 Str3[j - 1] = os_strdup(Str[i]);
333 if (Str3[j - 1] == NULL)
335 Scierror(999, _("%s: No more memory.\n"), fname);
336 freeArrayOfString(Str3, j);
345 Scierror(999, _("%s: Failed to generate the planner name.\n"), fname);
349 /* Create the string matrix as return of the function */
350 sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 3, j, 1, Str3);
351 freeArrayOfString(Str3, j); // Data have been copied into Scilab memory
355 printError(&sciErr, 0);
359 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 2;
360 AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 3;
361 ReturnArguments(pvApiCtx);
364 /*--------------------------------------------------------------------------*/