2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Anais AUBERT
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 /*--------------------------------------------------------------------------*/
14 #include "signalprocessingfunctions.hxx"
15 #include "configvariable.hxx"
16 #include "function.hxx"
20 #include "elem_common.h"
22 #include "localization.h"
25 /*--------------------------------------------------------------------------*/
27 Signalprocessingfunctions* Signalprocessing::m_Signalprocessingfunctions;
29 void Signalprocessing::addSignalprocessingfunctions(Signalprocessingfunctions* _spFunction)
31 m_Signalprocessingfunctions = _spFunction;
34 void Signalprocessing::removeSignalprocessingfunctions()
36 m_Signalprocessingfunctions = NULL;
39 Signalprocessingfunctions* Signalprocessing::getSignalprocessingfunctions()
41 return m_Signalprocessingfunctions;
44 Signalprocessingfunctions::Signalprocessingfunctions(const std::wstring& callerName)
47 m_wstrCaller = callerName;
52 m_pStringDgetxDyn = NULL;
53 m_pStringDgetyDyn = NULL;
55 m_pStringDgetxStatic = NULL;
56 m_pStringDgetyStatic = NULL;
58 // init static functions
59 if (callerName == L"corr")
61 m_staticFunctionMap[L"corexx"] = (void*)C2F(corexx);
62 m_staticFunctionMap[L"corexy"] = (void*)C2F(corexy);
67 void Signalprocessingfunctions::execFunctionDgetx(double* x, int* siz, int* iss)
72 callDgetx(x, siz, iss);
74 else if (m_pStringDgetxDyn)
76 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringDgetxDyn->get(0));
79 sprintf(errorMsg, _("Undefined function '%ls'.\n"), m_pStringDgetxDyn->get(0));
80 throw ast::InternalError(errorMsg);
82 ((dgetx_f_t)(func->functionPtr))(x, siz, iss);
84 else if (m_pStringDgetxStatic)// function static
86 ((dgetx_f_t)m_staticFunctionMap[m_pStringDgetxStatic->get(0)])(x, siz, iss);
90 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
91 throw ast::InternalError(errorMsg);
95 void Signalprocessingfunctions::setDgetx(types::Callable* _dgetx)
97 m_pCallDgetx = _dgetx;
100 void Signalprocessingfunctions::setDgetx(types::String* _dgetx)
102 m_pStringDgetxStatic = _dgetx;
104 void Signalprocessingfunctions::setDgety(types::Callable* _dgety)
106 m_pCallDgety = _dgety;
108 void Signalprocessingfunctions::setDgety(types::String* _dgety)
110 m_pStringDgetyStatic = _dgety;
113 //param for fortran call
114 void dgetx_f(double* x, int* siz, int* iss)
116 Signalprocessingfunctions* spFunction = NULL;
117 spFunction = Signalprocessing::getSignalprocessingfunctions();
119 if (spFunction == NULL)
121 throw ast::InternalError(_("An error occurred while getting Signalprocessingfunctions object.\n"));
124 spFunction->execFunctionDgetx(x, siz, iss);
127 void Signalprocessingfunctions::execFunctionDgety(double* y, int* siz, int* iss)
132 callDgety(y, siz, iss);
135 else if (m_pStringDgetxDyn)
137 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringDgetyDyn->get(0));
140 sprintf(errorMsg, _("Undefined function '%ls'.\n"), m_pStringDgetyDyn->get(0));
141 throw ast::InternalError(errorMsg);
143 ((dgety_f_t)(func->functionPtr))(y, siz, iss);
145 else if (m_pStringDgetyStatic)// function static
147 ((dgety_f_t)m_staticFunctionMap[m_pStringDgetyStatic->get(0)])(y, siz, iss);
151 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
152 throw ast::InternalError(errorMsg);
156 //param for fortran call
157 void dgety_f(double* y, int* siz, int* iss)
159 Signalprocessingfunctions* spFunction = NULL;
160 spFunction = Signalprocessing::getSignalprocessingfunctions();
162 if (spFunction == NULL)
164 throw ast::InternalError(_("An error occurred while getting Signalprocessingfunctions object.\n"));
167 spFunction->execFunctionDgety(y, siz, iss);
170 void Signalprocessingfunctions::callDgety(double* y, int* siz, int* iss)
176 types::typed_list in;
177 types::typed_list out;
178 types::optional_list opt;
180 types::Double* pDblY = new types::Double(*siz);
183 types::Double* pDblT = new types::Double(*iss);
184 pDblT->IncreaseRef();
185 pDblY->IncreaseRef();
193 for (int i = 0; i < (int)m_FArgs.size(); i++)
195 m_FArgs[i]->IncreaseRef();
196 in.push_back(m_FArgs[i]);
199 bool bOk = m_pCallDgety->call(in, opt, iRetCount, out) == types::Function::OK;
201 for (int i = 0; i < (int)m_FArgs.size(); i++)
203 m_FArgs[i]->DecreaseRef();
208 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallDgety->getName().c_str());
209 throw ast::InternalError(errorMsg);
212 if (out.size() != iRetCount)
214 char* pstrName = wide_string_to_UTF8(m_pCallDgety->getName().c_str());
215 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
217 throw ast::InternalError(errorMsg);
220 out[0]->IncreaseRef();
222 pDblT->DecreaseRef();
223 if (pDblT->isDeletable())
229 pDblY->DecreaseRef();
230 if (pDblY->isDeletable())
236 out[0]->DecreaseRef();
238 if (out[0]->isDouble() == false)
240 char* pstrName = wide_string_to_UTF8(m_pCallDgety->getName().c_str());
241 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
243 throw ast::InternalError(errorMsg);
245 types::Double* pDblOut = out[0]->getAs<types::Double>();
246 if (pDblOut->isComplex())
248 char* pstrName = wide_string_to_UTF8(m_pCallDgety->getName().c_str());
249 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
251 throw ast::InternalError(errorMsg);
254 C2F(dcopy)(siz, pDblOut->get(), &one, y, &one);
257 if (out[0]->isDeletable())
263 void Signalprocessingfunctions::callDgetx(double* x, int* siz, int* iss)
269 types::typed_list in;
270 types::typed_list out;
271 types::optional_list opt;
273 types::Double* pDblX = new types::Double(*siz);
276 types::Double* pDblT = new types::Double(*iss);
277 pDblT->IncreaseRef();
278 pDblX->IncreaseRef();
286 for (int i = 0; i < (int)m_FArgs.size(); i++)
288 m_FArgs[i]->IncreaseRef();
289 in.push_back(m_FArgs[i]);
292 bool bOk = m_pCallDgetx->call(in, opt, iRetCount, out) == types::Function::OK;
294 for (int i = 0; i < (int)m_FArgs.size(); i++)
296 m_FArgs[i]->DecreaseRef();
301 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallDgetx->getName().c_str());
302 throw ast::InternalError(errorMsg);
305 if (out.size() != iRetCount)
307 char* pstrName = wide_string_to_UTF8(m_pCallDgetx->getName().c_str());
308 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
310 throw ast::InternalError(errorMsg);
313 out[0]->IncreaseRef();
315 pDblT->DecreaseRef();
316 if (pDblT->isDeletable())
322 pDblX->DecreaseRef();
323 if (pDblX->isDeletable())
329 out[0]->DecreaseRef();
331 if (out[0]->isDouble() == false)
333 char* pstrName = wide_string_to_UTF8(m_pCallDgetx->getName().c_str());
334 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
336 throw ast::InternalError(errorMsg);
338 types::Double* pDblOut = out[0]->getAs<types::Double>();
339 if (pDblOut->isComplex())
341 char* pstrName = wide_string_to_UTF8(m_pCallDgetx->getName().c_str());
342 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
344 throw ast::InternalError(errorMsg);
347 C2F(dcopy)(siz, pDblOut->get(), &one, x, &one);
350 if (out[0]->isDeletable())