2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - INRIA - Serge STEER
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 /*--------------------------------------------------------------------------*/
13 #include "core_math.h"
15 #include "gw_signal.h"
17 #include "api_scilab.h"
18 #include "localization.h"
21 /*--------------------------------------------------------------------------*/
22 int sci_conv2(char *fname,unsigned long fname_len)
28 double *Outr = NULL,*Outi = NULL;
29 int mOut = 0, nOut = 0;
31 int edgM = 0, edgN = 0;
34 /* Check if last argument is one of the string "full", "same","valid" */
35 sciErr = getVarAddressFromPosition(pvApiCtx, Rhs, &piAddr);
38 printError(&sciErr, 0);
39 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, Rhs);
43 if (isStringType(pvApiCtx, piAddr))
46 if(isScalar(pvApiCtx, piAddr))
48 if (getAllocatedSingleString(pvApiCtx, piAddr, &option)==0)
50 if (strcmp("full", option) == 0)
54 else if (strcmp("same", option) == 0)
58 else if (strcmp("valid", option) == 0)
64 Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),
65 fname, Rhs, "\"full\", \"same\"","\"valid\"");
66 freeAllocatedSingleString(option);
70 freeAllocatedSingleString(option);
76 Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),
77 fname, Rhs, "\"full\", \"same\"","\"valid\"");
89 /*separable conv2(C,R,A)*/
90 double *Cr = NULL,*Ci = NULL;
91 double *Rr = NULL,*Ri = NULL;
92 double *Ar = NULL,*Ai = NULL;
93 int mC = 0, nC = 0, mR = 0, nR = 0, mA = 0, nA = 0;
96 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
99 printError(&sciErr, 0);
100 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
105 sciErr = getVarType(pvApiCtx, piAddr, &iType);
108 printError(&sciErr, 0);
109 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
113 if(iType != sci_matrix)
115 Scierror(999,_("%s: Wrong type for argument %d: Real vector expected.\n"),
121 if (isVarComplex(pvApiCtx, piAddr))
123 sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mC, &nC, &Cr, &Ci);
126 printError(&sciErr, 0);
127 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
134 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mC, &nC, &Cr);
137 printError(&sciErr, 0);
138 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
146 Scierror(999,_("%s: Wrong type for argument %d: Real or complex vector expected.\n"),
152 /* get and check R */
153 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
156 printError(&sciErr, 0);
157 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
162 sciErr = getVarType(pvApiCtx, piAddr, &iType);
165 printError(&sciErr, 0);
166 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
170 if(iType != sci_matrix)
172 Scierror(999,_("%s: Wrong type for argument %d: Real or complex vector expected.\n"),
178 if (isVarComplex(pvApiCtx, piAddr))
180 sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mR, &nR, &Rr, &Ri);
183 printError(&sciErr, 0);
184 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
191 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mR, &nR, &Rr);
194 printError(&sciErr, 0);
195 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
204 Scierror(999,_("%s: Wrong type for argument %d: Real vector expected.\n"),
210 /* get and check A */
211 sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
214 printError(&sciErr, 0);
215 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
220 sciErr = getVarType(pvApiCtx, piAddr, &iType);
223 printError(&sciErr, 0);
224 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
228 if(iType != sci_matrix)
230 Scierror(999,_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"),
236 if (isVarComplex(pvApiCtx, piAddr))
238 sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar, &Ai);
241 printError(&sciErr, 0);
242 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
249 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar);
252 printError(&sciErr, 0);
253 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
259 //Compute result sizes
275 else if ( iopt == 2 )
291 mOut= Max(0,mA - mC + 1);
292 nOut= Max(0,nA - nR + 1);
297 if (Ri==NULL&&Ci==NULL&&Ai==NULL)
302 sciErr = allocMatrixOfDouble(pvApiCtx,Rhs+1,mOut,nOut,&Outr);
305 printError(&sciErr, 0);
309 sciErr = allocMatrixOfDouble(pvApiCtx,Rhs+2,1,nA,&Tr);
312 printError(&sciErr, 0);
313 Scierror(999,_("%s: Memory allocation error.\n"), fname);
317 conv2_separable_R(Rr,nR,Cr,mC,Ar,mA,nA,Outr,mOut,nOut,edgM,edgN,Tr);
321 double *Tr = NULL,*Ti = NULL;
323 sciErr = allocComplexMatrixOfDouble(pvApiCtx,Rhs+1,mOut,nOut,&Outr,&Outi);
326 printError(&sciErr, 0);
327 Scierror(999,_("%s: Memory allocation error.\n"), fname);
331 sciErr = allocComplexMatrixOfDouble(pvApiCtx,Rhs+2,1,nA,&Tr,&Ti);
334 printError(&sciErr, 0);
335 Scierror(999,_("%s: Memory allocation error.\n"), fname);
339 conv2_separable_C(Rr,Ri,nR,Cr,Ci,mC,Ar,Ai,mA,nA,Outr,Outi,mOut,nOut,edgM,edgN,Tr,Ti);
345 double *Ar = NULL,*Ai = NULL;
346 double *Br = NULL,*Bi = NULL;
349 /* get and check A */
350 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
353 printError(&sciErr, 0);
354 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
359 sciErr = getVarType(pvApiCtx, piAddr, &iType);
362 printError(&sciErr, 0);
363 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
367 if(iType != sci_matrix)
369 Scierror(999,_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"),
375 if (isVarComplex(pvApiCtx, piAddr))
377 sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar, &Ai);
380 printError(&sciErr, 0);
381 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
388 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar);
391 printError(&sciErr, 0);
392 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
398 /* get and check B */
399 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
402 printError(&sciErr, 0);
403 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
408 sciErr = getVarType(pvApiCtx, piAddr, &iType);
411 printError(&sciErr, 0);
412 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
416 if(iType != sci_matrix)
418 Scierror(999,_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"),
424 if (isVarComplex(pvApiCtx, piAddr))
426 sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mB, &nB, &Br, &Bi);
429 printError(&sciErr, 0);
430 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
437 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mB, &nB, &Br);
440 printError(&sciErr, 0);
441 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
461 mOut= mA + Max(0,mB - 1);
462 nOut= nA + Max(0,nB - 1);
483 mOut= Max(0,mA - mB + 1);
484 nOut= Max(0,nA - nB + 1);
489 if (Ai==NULL&&Bi==NULL)
493 sciErr = allocMatrixOfDouble(pvApiCtx, Rhs+1,mOut,nOut,&Outr);
496 printError(&sciErr, 0);
497 Scierror(999,_("%s: Memory allocation error.\n"), fname);
501 conv2_R(Ar,mA,nA,Br,mB,nB,Outr,mOut,nOut,edgM,edgN);
506 sciErr = allocComplexMatrixOfDouble(pvApiCtx,Rhs+1,mOut,nOut,&Outr,&Outi);
509 printError(&sciErr, 0);
510 Scierror(999,_("%s: Memory allocation error.\n"), fname);
514 conv2_C(Ar,Ai,mA,nA,Br,Bi,mB,nB,Outr,Outi,mOut,nOut,edgM,edgN);
522 /*--------------------------------------------------------------------------*/