1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
|
/*
* Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2006/2007 - INRIA - Alan LAYEC
* Copyright (C) 2007 - INRIA - Allan CORNET
* Copyright (C) 2012 - DIGITEO - Allan CORNET
* Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
*
*/
/*--------------------------------------------------------------------------*/
#include <string.h>
#include "api_scilab.h"
#include "fftw_utilities.h"
#include "sci_malloc.h"
#include "gw_fftw.h"
#include "localization.h"
#include "freeArrayOfString.h"
#include "Scierror.h"
#include "os_string.h"
/*--------------------------------------------------------------------------*/
/* fftw_flags function.
*
* Scilab Syntax :
* -->[a,b]=fftw_flags();
* or
* -->[a,b]=fftw_flags(S);
*
* a is an int scalar. (the int value of
* the flag parameter of fftw)
* b is a string matrix.(the string values of
* the flag parameter of fftw)
* S is a string matrix or an int or a double scalar
* given the value(s) of the fftw flag parameter.
*
* This function gives and set the flag parameter of fftw
* when creating a new plan.
* This should be done before calling fftw function.
* (default is FFTW_ESTIMATE)
*/
/*--------------------------------------------------------------------------*/
int sci_fftw_flags(char *fname, void* pvApiCtx)
{
/* declaration of variables to store scilab parameters address */
static int m1 = 0, n1 = 0;
char **Str1 = NULL;
char **Str3 = NULL;
unsigned int uiVar1 = 0;
int* piDataOut = NULL;
int* piAddr1 = NULL;
int* piLen = NULL;
int iType = 0;
/* please update me ! */
static int nb_flag = 22;
static char *Str[] =
{
/* documented flags */
"FFTW_MEASURE",
"FFTW_DESTROY_INPUT",
"FFTW_UNALIGNED",
"FFTW_CONSERVE_MEMORY",
"FFTW_EXHAUSTIVE",
"FFTW_PRESERVE_INPUT",
"FFTW_PATIENT",
"FFTW_ESTIMATE",
/* undocumented beyond-guru flags */
"FFTW_ESTIMATE_PATIENT",
"FFTW_BELIEVE_PCOST",
"FFTW_NO_DFT_R2HC",
"FFTW_NO_NONTHREADED",
"FFTW_NO_BUFFERING",
"FFTW_NO_INDIRECT_OP",
"FFTW_ALLOW_LARGE_GENERIC",
"FFTW_NO_RANK_SPLITS",
"FFTW_NO_VRANK_SPLITS",
"FFTW_NO_VRECURSE",
"FFTW_NO_SIMD",
"FFTW_NO_SLOW",
"FFTW_NO_FIXED_RADIX_LARGE_N",
"FFTW_ALLOW_PRUNING"
};
static unsigned flagt[] =
{
/* documented flags */
FFTW_MEASURE,
FFTW_DESTROY_INPUT,
FFTW_UNALIGNED,
FFTW_CONSERVE_MEMORY,
FFTW_EXHAUSTIVE,
FFTW_PRESERVE_INPUT,
FFTW_PATIENT,
FFTW_ESTIMATE,
/* undocumented beyond-guru flags */
FFTW_ESTIMATE_PATIENT,
FFTW_BELIEVE_PCOST,
FFTW_NO_DFT_R2HC,
FFTW_NO_NONTHREADED,
FFTW_NO_BUFFERING,
FFTW_NO_INDIRECT_OP,
FFTW_ALLOW_LARGE_GENERIC,
FFTW_NO_RANK_SPLITS,
FFTW_NO_VRANK_SPLITS,
FFTW_NO_VRECURSE,
FFTW_NO_SIMD,
FFTW_NO_SLOW,
FFTW_NO_FIXED_RADIX_LARGE_N,
FFTW_ALLOW_PRUNING
};
unsigned flagv = 0;
int i = 0, j = 0;
SciErr sciErr;
CheckInputArgument(pvApiCtx, 0, 1);
if (nbInputArgument(pvApiCtx) == 0)
{
// nothing
}
else
{
//get variable address of the input argument
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 1;
}
getVarType(pvApiCtx, piAddr1, &iType);
switch (iType)
{
case sci_ints:
{
/* int */
int iPrecision = 0;
int* pi32Data = NULL;
unsigned int* pui32Data = NULL;
getMatrixOfIntegerPrecision(pvApiCtx, piAddr1, &iPrecision);
if (iPrecision != SCI_INT32 && iPrecision != SCI_UINT32)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A int32 expected.\n"), fname, 1);
return 1;
}
if (iPrecision == SCI_INT32)
{
sciErr = getMatrixOfInteger32(pvApiCtx, piAddr1, &m1, &n1, &pi32Data);
uiVar1 = (unsigned int)pi32Data[0];
}
else
{
sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, piAddr1, &m1, &n1, &pui32Data);
uiVar1 = pui32Data[0];
}
if (sciErr.iErr)
{
Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
printError(&sciErr, 0);
return 1;
}
break;
}
case sci_matrix:
{
/* double */
double* pdblData = NULL;
sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &pdblData);
if (sciErr.iErr)
{
Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
printError(&sciErr, 0);
return 1;
}
uiVar1 = (unsigned int)pdblData[0];
break;
}
case sci_strings:
{
/* string */
//fisrt call to retrieve dimensions
sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, NULL, NULL);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 1;
}
piLen = (int*)MALLOC(sizeof(int) * m1 * n1);
//second call to retrieve length of each string
sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, NULL);
if (sciErr.iErr)
{
FREE(piLen);
printError(&sciErr, 0);
return 1;
}
Str1 = (char**)MALLOC(sizeof(char*) * m1 * n1);
for (i = 0 ; i < m1 * n1 ; i++)
{
Str1[i] = (char*)MALLOC(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
}
//third call to retrieve data
sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, Str1);
if (sciErr.iErr)
{
FREE(piLen);
freeArrayOfString(Str1, m1 * n1);
printError(&sciErr, 0);
return 1;
}
for (j = 0; j < m1 * n1; j++)
{
for (i = 0; i < nb_flag; i++)
{
if (strcmp(Str1[j], Str[i]) == 0)
{
break;
}
}
if (i == nb_flag)
{
FREE(piLen);
freeArrayOfString(Str1, m1 * n1);
Scierror(999, _("%s: Wrong values for input argument #%d: FFTW flag expected.\n"), fname, 1);
return 0;
}
else
{
if (i > 0)
{
flagv = ( flagv | (1U << (i - 1)) );
}
}
}
uiVar1 = (unsigned int)flagv;
FREE(piLen);
freeArrayOfString(Str1, m1 * n1);
m1 = 1;
n1 = 1;
break;
}
default:
Scierror(53, _("%s: Wrong type for input argument #%d.\n"), fname, 1);
return 1;
}
if (m1 != 1 || n1 != 1)
{
Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, 1, 1);
return 1;
}
setCurrentFftwFlags(uiVar1);
}
/* return value of Sci_Plan.flags in position 2 */
sciErr = allocMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, 1, &piDataOut);
if (sciErr.iErr)
{
printError(&sciErr, 0);
Scierror(999, _("%s: No more memory.\n"), fname);
return 1;
}
piDataOut[0] = (int) getCurrentFftwFlags();
/*Test for only FFTW_MEASURE*/
if (getCurrentFftwFlags() == 0)
{
j = 1;
if ((Str3 = (char **)MALLOC(sizeof(char *))) == NULL)
{
Scierror(999, _("%s: No more memory.\n"), fname);
return 1;
}
Str3[0] = os_strdup(Str[0]);
if (Str3[0] == NULL)
{
Scierror(999, _("%s: No more memory.\n"), fname);
FREE(Str3);
return 1;
}
}
else
{
j = 0;
for (i = 1; i < nb_flag; i++)
{
if ((getCurrentFftwFlags() & flagt[i]) == flagt[i])
{
j++;
if (Str3)
{
Str3 = (char **)REALLOC(Str3, sizeof(char *) * j);
}
else
{
Str3 = (char **)MALLOC(sizeof(char *) * j);
}
if (Str3 == NULL)
{
Scierror(999, _("%s: No more memory.\n"), fname);
return 1;
}
Str3[j - 1] = os_strdup(Str[i]);
if (Str3[j - 1] == NULL)
{
Scierror(999, _("%s: No more memory.\n"), fname);
freeArrayOfString(Str3, j);
return 1;
}
}
}
}
if (Str3 == NULL)
{
Scierror(999, _("%s: Failed to generate the planner name.\n"), fname);
return 1;
}
/* Create the string matrix as return of the function */
sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 3, j, 1, (const char**)(Str3));
freeArrayOfString(Str3, j); // Data have been copied into Scilab memory
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 1;
}
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 2;
AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 3;
ReturnArguments(pvApiCtx);
return 0;
}
/*--------------------------------------------------------------------------*/
|