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"
19 #include "elem_common.h"
21 #include "localization.h"
24 /*--------------------------------------------------------------------------*/
26 Signalprocessingfunctions* Signalprocessing::m_Signalprocessingfunctions;
28 void Signalprocessing::addSignalprocessingfunctions(Signalprocessingfunctions* _spFunction)
30 m_Signalprocessingfunctions = _spFunction;
33 void Signalprocessing::removeSignalprocessingfunctions()
35 m_Signalprocessingfunctions = NULL;
38 Signalprocessingfunctions* Signalprocessing::getSignalprocessingfunctions()
40 return m_Signalprocessingfunctions;
43 Signalprocessingfunctions::Signalprocessingfunctions(const std::wstring& callerName)
46 m_wstrCaller = callerName;
51 m_pStringDgetxDyn = NULL;
52 m_pStringDgetyDyn = NULL;
54 m_pStringDgetxStatic = NULL;
55 m_pStringDgetyStatic = NULL;
57 // init static functions
58 if (callerName == L"corr")
60 m_staticFunctionMap[L"corexx"] = (void*)C2F(corexx);
61 m_staticFunctionMap[L"corexy"] = (void*)C2F(corexy);
66 void Signalprocessingfunctions::execFunctionDgetx(double* x, int* siz, int* iss)
71 callDgetx(x, siz, iss);
73 else if (m_pStringDgetxDyn)
75 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringDgetxDyn->get(0));
78 sprintf(errorMsg, _("Undefined function '%ls'.\n"), m_pStringDgetxDyn->get(0));
79 throw ast::InternalError(errorMsg);
81 ((dgetx_f_t)(func->functionPtr))(x, siz, iss);
83 else if (m_pStringDgetxStatic)// function static
85 ((dgetx_f_t)m_staticFunctionMap[m_pStringDgetxStatic->get(0)])(x, siz, iss);
89 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
90 throw ast::InternalError(errorMsg);
94 void Signalprocessingfunctions::setDgetx(types::Callable* _dgetx)
96 m_pCallDgetx = _dgetx;
99 void Signalprocessingfunctions::setDgetx(types::String* _dgetx)
101 m_pStringDgetxStatic = _dgetx;
103 void Signalprocessingfunctions::setDgety(types::Callable* _dgety)
105 m_pCallDgety = _dgety;
107 void Signalprocessingfunctions::setDgety(types::String* _dgety)
109 m_pStringDgetyStatic = _dgety;
112 //param for fortran call
113 void dgetx_f(double* x, int* siz, int* iss)
115 Signalprocessingfunctions* spFunction = NULL;
116 spFunction = Signalprocessing::getSignalprocessingfunctions();
118 if (spFunction == NULL)
120 throw ast::InternalError(_("An error occurred while getting Signalprocessingfunctions object.\n"));
123 spFunction->execFunctionDgetx(x, siz, iss);
126 void Signalprocessingfunctions::execFunctionDgety(double* y, int* siz, int* iss)
131 callDgety(y, siz, iss);
134 else if (m_pStringDgetxDyn)
136 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringDgetyDyn->get(0));
139 sprintf(errorMsg, _("Undefined function '%ls'.\n"), m_pStringDgetyDyn->get(0));
140 throw ast::InternalError(errorMsg);
142 ((dgety_f_t)(func->functionPtr))(y, siz, iss);
144 else if (m_pStringDgetyStatic)// function static
146 ((dgety_f_t)m_staticFunctionMap[m_pStringDgetyStatic->get(0)])(y, siz, iss);
150 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
151 throw ast::InternalError(errorMsg);
155 //param for fortran call
156 void dgety_f(double* y, int* siz, int* iss)
158 Signalprocessingfunctions* spFunction = NULL;
159 spFunction = Signalprocessing::getSignalprocessingfunctions();
161 if (spFunction == NULL)
163 throw ast::InternalError(_("An error occurred while getting Signalprocessingfunctions object.\n"));
166 spFunction->execFunctionDgety(y, siz, iss);
169 void Signalprocessingfunctions::callDgety(double* y, int* siz, int* iss)
175 types::typed_list in;
176 types::typed_list out;
177 types::optional_list opt;
179 types::Double* pDblY = new types::Double(*siz);
182 types::Double* pDblT = new types::Double(*iss);
183 pDblT->IncreaseRef();
184 pDblY->IncreaseRef();
192 for (int i = 0; i < (int)m_FArgs.size(); i++)
194 m_FArgs[i]->IncreaseRef();
195 in.push_back(m_FArgs[i]);
198 bool bOk = m_pCallDgety->call(in, opt, iRetCount, out) == types::Function::OK;
200 for (int i = 0; i < (int)m_FArgs.size(); i++)
202 m_FArgs[i]->DecreaseRef();
207 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallDgety->getName().c_str());
208 throw ast::InternalError(errorMsg);
211 if (out.size() != iRetCount)
213 char* pstrName = wide_string_to_UTF8(m_pCallDgety->getName().c_str());
214 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
216 throw ast::InternalError(errorMsg);
219 out[0]->IncreaseRef();
221 pDblT->DecreaseRef();
222 if (pDblT->isDeletable())
228 pDblY->DecreaseRef();
229 if (pDblY->isDeletable())
235 out[0]->DecreaseRef();
237 if (out[0]->isDouble() == false)
239 char* pstrName = wide_string_to_UTF8(m_pCallDgety->getName().c_str());
240 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
242 throw ast::InternalError(errorMsg);
244 types::Double* pDblOut = out[0]->getAs<types::Double>();
245 if (pDblOut->isComplex())
247 char* pstrName = wide_string_to_UTF8(m_pCallDgety->getName().c_str());
248 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
250 throw ast::InternalError(errorMsg);
253 C2F(dcopy)(siz, pDblOut->get(), &one, y, &one);
256 if (out[0]->isDeletable())
262 void Signalprocessingfunctions::callDgetx(double* x, int* siz, int* iss)
268 types::typed_list in;
269 types::typed_list out;
270 types::optional_list opt;
272 types::Double* pDblX = new types::Double(*siz);
275 types::Double* pDblT = new types::Double(*iss);
276 pDblT->IncreaseRef();
277 pDblX->IncreaseRef();
285 for (int i = 0; i < (int)m_FArgs.size(); i++)
287 m_FArgs[i]->IncreaseRef();
288 in.push_back(m_FArgs[i]);
291 bool bOk = m_pCallDgetx->call(in, opt, iRetCount, out) == types::Function::OK;
293 for (int i = 0; i < (int)m_FArgs.size(); i++)
295 m_FArgs[i]->DecreaseRef();
300 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallDgetx->getName().c_str());
301 throw ast::InternalError(errorMsg);
304 if (out.size() != iRetCount)
306 char* pstrName = wide_string_to_UTF8(m_pCallDgetx->getName().c_str());
307 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
309 throw ast::InternalError(errorMsg);
312 out[0]->IncreaseRef();
314 pDblT->DecreaseRef();
315 if (pDblT->isDeletable())
321 pDblX->DecreaseRef();
322 if (pDblX->isDeletable())
328 out[0]->DecreaseRef();
330 if (out[0]->isDouble() == false)
332 char* pstrName = wide_string_to_UTF8(m_pCallDgetx->getName().c_str());
333 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
335 throw ast::InternalError(errorMsg);
337 types::Double* pDblOut = out[0]->getAs<types::Double>();
338 if (pDblOut->isComplex())
340 char* pstrName = wide_string_to_UTF8(m_pCallDgetx->getName().c_str());
341 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
343 throw ast::InternalError(errorMsg);
346 C2F(dcopy)(siz, pDblOut->get(), &one, x, &one);
349 if (out[0]->isDeletable())