2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011 - DIGITEO - Cedric DELAMARRE
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 "execvisitor.hxx"
16 #include "differentialequationfunctions.hxx"
20 #include "elem_common.h"
21 #include "scifunctions.h"
25 #include "localization.h"
29 ** differential equation functions
33 // need the current thread, not the last running thread.
35 std::map<__threadId, DifferentialEquationFunctions*> DifferentialEquation::m_mapDifferentialEquationFunctions;
37 void DifferentialEquation::addDifferentialEquationFunctions(DifferentialEquationFunctions* _deFunction)
39 types::ThreadId* pThread = ConfigVariable::getLastRunningThread();
40 m_mapDifferentialEquationFunctions[pThread->getThreadId()] = _deFunction;
43 void DifferentialEquation::removeDifferentialEquationFunctions()
45 types::ThreadId* pThread = ConfigVariable::getLastRunningThread();
46 m_mapDifferentialEquationFunctions.erase(pThread->getThreadId());
49 DifferentialEquationFunctions* DifferentialEquation::getDifferentialEquationFunctions()
51 types::ThreadId* pThread = ConfigVariable::getLastRunningThread();
52 return m_mapDifferentialEquationFunctions[pThread->getThreadId()];
62 /*--------------------------------------------------------------------------*/
63 DifferentialEquationFunctions::DifferentialEquationFunctions(std::wstring callerName)
75 m_wstrCaller = callerName;
78 m_pCallFFunction = NULL;
79 m_pCallJacFunction = NULL;
80 m_pCallGFunction = NULL;
81 m_pCallPjacFunction = NULL;
82 m_pCallPsolFunction = NULL;
85 m_pStringFFunctionDyn = NULL;
86 m_pStringJacFunctionDyn = NULL;
87 m_pStringGFunctionDyn = NULL;
88 m_pStringPjacFunctionDyn = NULL;
89 m_pStringPsolFunctionDyn = NULL;
92 m_pStringFFunctionStatic = NULL;
93 m_pStringJacFunctionStatic = NULL;
94 m_pStringGFunctionStatic = NULL;
95 m_pStringPjacFunctionStatic = NULL;
96 m_pStringPsolFunctionStatic = NULL;
99 m_pCallFsubFunction = NULL;
100 m_pCallDfsubFunction = NULL;
101 m_pCallGsubFunction = NULL;
102 m_pCallDgsubFunction = NULL;
103 m_pCallGuessFunction = NULL;
105 m_pStringFsubFunctionDyn = NULL;
106 m_pStringDfsubFunctionDyn = NULL;
107 m_pStringGsubFunctionDyn = NULL;
108 m_pStringDgsubFunctionDyn = NULL;
109 m_pStringGuessFunctionDyn = NULL;
111 m_pStringFsubFunctionStatic = NULL;
112 m_pStringDfsubFunctionStatic = NULL;
113 m_pStringGsubFunctionStatic = NULL;
114 m_pStringDgsubFunctionStatic = NULL;
115 m_pStringGuessFunctionStatic = NULL;
117 // init static functions
118 if (callerName == L"ode")
120 m_staticFunctionMap[L"arnol"] = (void*) C2F(arnol);
121 m_staticFunctionMap[L"fex"] = (void*) fex;
122 m_staticFunctionMap[L"fex2"] = (void*) fex2;
123 m_staticFunctionMap[L"fex3"] = (void*) fex3;
124 m_staticFunctionMap[L"fexab"] = (void*) fexab;
125 m_staticFunctionMap[L"loren"] = (void*) C2F(loren);
126 m_staticFunctionMap[L"bcomp"] = (void*) C2F(bcomp);
127 m_staticFunctionMap[L"lcomp"] = (void*) C2F(lcomp);
129 m_staticFunctionMap[L"jex"] = (void*) jex;
131 else if (callerName == L"odedc")
133 m_staticFunctionMap[L"fcd"] = (void*) fcd;
134 m_staticFunctionMap[L"fcd1"] = (void*) fcd1;
135 m_staticFunctionMap[L"fexcd"] = (void*) fexcd;
136 m_staticFunctionMap[L"phis"] = (void*) phis;
137 m_staticFunctionMap[L"phit"] = (void*) phit;
139 m_staticFunctionMap[L"jex"] = (void*) jex;
141 else if (callerName == L"intg")
143 m_staticFunctionMap[L"intgex"] = (void*) C2F(intgex);
145 else if (callerName == L"int2d")
147 m_staticFunctionMap[L"int2dex"] = (void*) C2F(int2dex);
149 else if (callerName == L"int3d")
151 m_staticFunctionMap[L"int3dex"] = (void*) C2F(int3dex);
153 else if (callerName == L"feval")
155 m_staticFunctionMap[L"parab"] = (void*) C2F(parab);
156 m_staticFunctionMap[L"parabc"] = (void*) C2F(parabc);
158 else if (callerName == L"bvode")
160 m_staticFunctionMap[L"cndg"] = (void*) C2F(cndg);
161 m_staticFunctionMap[L"cng"] = (void*) C2F(cng);
162 m_staticFunctionMap[L"cnf"] = (void*) C2F(cnf);
163 m_staticFunctionMap[L"cndf"] = (void*) C2F(cndf);
164 m_staticFunctionMap[L"cngu"] = (void*) C2F(cngu);
166 else if (callerName == L"impl")
168 m_staticFunctionMap[L"resid"] = (void*) C2F(resid); // res
169 m_staticFunctionMap[L"aplusp"] = (void*) C2F(aplusp); // adda
170 m_staticFunctionMap[L"dgbydy"] = (void*) C2F(dgbydy); // jac
172 else if (callerName == L"dassl" ||
173 callerName == L"dasrt" ||
174 callerName == L"daskr")
177 m_staticFunctionMap[L"res1"] = (void*) C2F(res1);
178 m_staticFunctionMap[L"res2"] = (void*) C2F(res2);
179 m_staticFunctionMap[L"dres1"] = (void*) C2F(dres1);
180 m_staticFunctionMap[L"dres2"] = (void*) C2F(dres2);
183 m_staticFunctionMap[L"jac2"] = (void*) C2F(jac2);
184 m_staticFunctionMap[L"djac2"] = (void*) C2F(djac2);
185 m_staticFunctionMap[L"djac1"] = (void*) C2F(djac1);
188 if (callerName == L"dasrt" || callerName == L"daskr")
190 m_staticFunctionMap[L"gr1"] = (void*) C2F(gr1);
191 m_staticFunctionMap[L"gr2"] = (void*) C2F(gr2);
195 if (callerName == L"daskr")
197 m_staticFunctionMap[L"pjac1"] = (void*) pjac1;
198 m_staticFunctionMap[L"psol1"] = (void*) psol1;
203 DifferentialEquationFunctions::~DifferentialEquationFunctions()
205 m_staticFunctionMap.clear();
208 /*------------------------------- public -------------------------------------------*/
209 void DifferentialEquationFunctions::execDasrtG(int* ny, double* t, double* y, int* ng, double* gout, double* rpar, int* ipar)
212 if (m_pCallGFunction)
214 callDasrtMacroG(ny, t, y, ng, gout, rpar, ipar);
216 else if (m_pStringGFunctionDyn)
218 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringGFunctionDyn->get(0));
221 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringGFunctionDyn->get(0));
222 throw ast::ScilabError(errorMsg);
224 ((dasrt_g_t)(func->functionPtr))(ny, t, y, ng, gout, rpar, ipar);
226 else if (m_pStringGFunctionStatic)
228 ((dasrt_g_t)m_staticFunctionMap[m_pStringGFunctionStatic->get(0)])(ny, t, y, ng, gout, rpar, ipar);
232 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
233 throw ast::ScilabError(errorMsg);
237 void DifferentialEquationFunctions::execDasslF(double* t, double* y, double* ydot, double* delta, int* ires, double* rpar, int* ipar)
240 if (m_pCallFFunction)
242 callDasslMacroF(t, y, ydot, delta, ires, rpar, ipar);
244 else if (m_pStringFFunctionDyn)
246 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
249 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
250 throw ast::ScilabError(errorMsg);
252 ((dassl_f_t)(func->functionPtr))(t, y, ydot, delta, ires, rpar, ipar);
254 else if (m_pStringFFunctionStatic)
256 ((dassl_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(t, y, ydot, delta, ires, rpar, ipar);
260 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
261 throw ast::ScilabError(errorMsg);
265 void DifferentialEquationFunctions::execDasslJac(double* t, double* y, double* ydot, double* pd, double* cj, double* rpar, int* ipar)
268 if (m_pCallJacFunction)
270 callDasslMacroJac(t, y, ydot, pd, cj, rpar, ipar);
272 else if (m_pStringJacFunctionDyn)
274 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringJacFunctionDyn->get(0));
277 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringJacFunctionDyn->get(0));
278 throw ast::ScilabError(errorMsg);
280 ((dassl_jac_t)(func->functionPtr))(t, y, ydot, pd, cj, rpar, ipar);
282 else if (m_pStringJacFunctionStatic)
284 ((dassl_jac_t)m_staticFunctionMap[m_pStringJacFunctionStatic->get(0)])(t, y, ydot, pd, cj, rpar, ipar);
288 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "jacobian");
289 throw ast::ScilabError(errorMsg);
293 void DifferentialEquationFunctions::execDaskrPjac(double* res, int* ires, int* neq, double* t, double* y, double* ydot,
294 double* rewt, double* savr, double* wk, double* h, double* cj,
295 double* wp, int* iwp, int* ier, double* rpar, int* ipar)
298 if (m_pCallPjacFunction)
300 callDaskrMacroPjac(res, ires, neq, t, y, ydot, rewt, savr,
301 wk, h, cj, wp, iwp, ier, rpar, ipar);
303 else if (m_pStringPjacFunctionDyn)
305 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringPjacFunctionDyn->get(0));
308 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringPjacFunctionDyn->get(0));
309 throw ast::ScilabError(errorMsg);
311 ((daskr_pjac_t)(func->functionPtr))(res, ires, neq, t, y, ydot, rewt, savr,
312 wk, h, cj, wp, iwp, ier, rpar, ipar);
314 else if (m_pStringPjacFunctionStatic)
316 ((daskr_pjac_t)m_staticFunctionMap[m_pStringPjacFunctionStatic->get(0)])(res, ires, neq, t, y, ydot, rewt, savr,
317 wk, h, cj, wp, iwp, ier, rpar, ipar);
321 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "pjac");
322 throw ast::ScilabError(errorMsg);
326 void DifferentialEquationFunctions::execDaskrPsol(int* neq, double* t, double* y, double* ydot, double* savr, double* wk,
327 double* cj, double* wght, double* wp, int* iwp, double* b, double* eplin,
328 int* ier, double* rpar, int* ipar)
331 if (m_pCallPsolFunction)
333 callDaskrMacroPsol(neq, t, y, ydot, savr, wk, cj, wght,
334 wp, iwp, b, eplin, ier, rpar, ipar);
336 else if (m_pStringPsolFunctionDyn)
338 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringPsolFunctionDyn->get(0));
341 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringPsolFunctionDyn->get(0));
342 throw ast::ScilabError(errorMsg);
344 ((daskr_psol_t)(func->functionPtr))(neq, t, y, ydot, savr, wk, cj, wght,
345 wp, iwp, b, eplin, ier, rpar, ipar);
347 else if (m_pStringPsolFunctionStatic)
349 ((daskr_psol_t)m_staticFunctionMap[m_pStringPsolFunctionStatic->get(0)])(neq, t, y, ydot, savr, wk, cj, wght,
350 wp, iwp, b, eplin, ier, rpar, ipar);
354 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "psol");
355 throw ast::ScilabError(errorMsg);
359 void DifferentialEquationFunctions::execImplF(int* neq, double* t, double* y, double* s, double* r, int* ires)
362 if (m_pCallFFunction)
364 callImplMacroF(neq, t, y, s, r, ires);
366 else if (m_pStringFFunctionDyn)
368 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
371 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
372 throw ast::ScilabError(errorMsg);
374 ((impl_f_t)(func->functionPtr))(neq, t, y, s, r, ires);
376 else if (m_pStringFFunctionStatic)
378 ((impl_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(neq, t, y, s, r, ires);
382 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
383 throw ast::ScilabError(errorMsg);
387 void DifferentialEquationFunctions::execImplG(int* neq, double* t, double* y, double* ml, double* mu, double* p, int* nrowp)
390 if (m_pCallGFunction)
392 callImplMacroG(neq, t, y, ml, mu, p, nrowp);
394 else if (m_pStringGFunctionDyn)
396 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringGFunctionDyn->get(0));
399 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringGFunctionDyn->get(0));
400 throw ast::ScilabError(errorMsg);
402 ((impl_g_t)(func->functionPtr))(neq, t, y, ml, mu, p, nrowp);
404 else if (m_pStringGFunctionStatic)
406 ((impl_g_t)m_staticFunctionMap[m_pStringGFunctionStatic->get(0)])(neq, t, y, ml, mu, p, nrowp);
410 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
411 throw ast::ScilabError(errorMsg);
415 void DifferentialEquationFunctions::execImplJac(int* neq, double* t, double* y, double* s, double* ml, double* mu, double* p, int* nrowp)
418 if (m_pCallJacFunction)
420 callImplMacroJac(neq, t, y, s, ml, mu, p, nrowp);
422 else if (m_pStringJacFunctionDyn)
424 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringJacFunctionDyn->get(0));
427 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringJacFunctionDyn->get(0));
428 throw ast::ScilabError(errorMsg);
430 ((impl_jac_t)(func->functionPtr))(neq, t, y, s, ml, mu, p, nrowp);
432 else if (m_pStringJacFunctionStatic)
434 ((impl_jac_t)m_staticFunctionMap[m_pStringJacFunctionStatic->get(0)])(neq, t, y, s, ml, mu, p, nrowp);
438 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "jacobian");
439 throw ast::ScilabError(errorMsg);
443 void DifferentialEquationFunctions::execBvodeGuess(double *x, double *z, double *d)
446 if (m_pCallGuessFunction)
448 callBvodeMacroGuess(x, z, d);
450 else if (m_pStringGuessFunctionDyn)
452 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringGuessFunctionDyn->get(0));
455 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringGuessFunctionDyn->get(0));
456 throw ast::ScilabError(errorMsg);
458 ((bvode_ddd_t)(func->functionPtr))(x, z, d);
460 else if (m_pStringGuessFunctionStatic)
462 ((bvode_ddd_t)m_staticFunctionMap[m_pStringGuessFunctionStatic->get(0)])(x, z, d);
466 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "guess");
467 throw ast::ScilabError(errorMsg);
471 void DifferentialEquationFunctions::execBvodeDfsub(double *x, double *z, double *d)
474 if (m_pCallDfsubFunction)
476 callBvodeMacroDfsub(x, z, d);
478 else if (m_pStringDfsubFunctionDyn)
480 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringDfsubFunctionDyn->get(0));
483 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringDfsubFunctionDyn->get(0));
484 throw ast::ScilabError(errorMsg);
486 ((bvode_ddd_t)(func->functionPtr))(x, z, d);
488 else if (m_pStringDfsubFunctionStatic)// function static
490 ((bvode_ddd_t)m_staticFunctionMap[m_pStringDfsubFunctionStatic->get(0)])(x, z, d);
494 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "fsub");
495 throw ast::ScilabError(errorMsg);
499 void DifferentialEquationFunctions::execBvodeFsub(double *x, double *z, double *d)
502 if (m_pCallFsubFunction)
504 callBvodeMacroFsub(x, z, d);
506 else if (m_pStringFsubFunctionDyn)
508 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFsubFunctionDyn->get(0));
511 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFsubFunctionDyn->get(0));
512 throw ast::ScilabError(errorMsg);
514 ((bvode_ddd_t)(func->functionPtr))(x, z, d);
516 else if (m_pStringFsubFunctionStatic) // function static
518 ((bvode_ddd_t)m_staticFunctionMap[m_pStringFsubFunctionStatic->get(0)])(x, z, d);
522 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "fsub");
523 throw ast::ScilabError(errorMsg);
527 void DifferentialEquationFunctions::execBvodeDgsub(int *i, double *z, double *g)
530 if (m_pCallDgsubFunction)
532 callBvodeMacroDgsub(i, z, g);
534 else if (m_pStringDgsubFunctionDyn)
536 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringDgsubFunctionDyn->get(0));
539 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringDgsubFunctionDyn->get(0));
540 throw ast::ScilabError(errorMsg);
542 ((bvode_idd_t)(func->functionPtr))(i, z, g);
544 else if (m_pStringDgsubFunctionStatic) // function static
546 ((bvode_idd_t)m_staticFunctionMap[m_pStringDgsubFunctionStatic->get(0)])(i, z, g);
550 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "gsub");
551 throw ast::ScilabError(errorMsg);
555 void DifferentialEquationFunctions::execBvodeGsub(int *i, double *z, double *g)
558 if (m_pCallGsubFunction)
560 callBvodeMacroGsub(i, z, g);
562 else if (m_pStringGsubFunctionDyn)
564 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringGsubFunctionDyn->get(0));
567 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringGsubFunctionDyn->get(0));
568 throw ast::ScilabError(errorMsg);
570 ((bvode_idd_t)(func->functionPtr))(i, z, g);
572 else if (m_pStringGsubFunctionStatic) // function static
574 ((bvode_idd_t)m_staticFunctionMap[m_pStringGsubFunctionStatic->get(0)])(i, z, g);
578 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "gsub");
579 throw ast::ScilabError(errorMsg);
583 void DifferentialEquationFunctions::execFevalF(int *nn, double *x1, double *x2, double *xres, int *itype)
586 if (m_pCallFFunction)
588 callFevalMacroF(nn, x1, x2, xres, itype);
590 else if (m_pStringFFunctionDyn)
592 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
595 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
596 throw ast::ScilabError(errorMsg);
599 ((feval_f_t)(func->functionPtr))(nn, x1, x2, xres, itype);
601 else if (m_pStringFFunctionStatic) // function static
603 ((feval_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(nn, x1, x2, xres, itype);
607 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
608 throw ast::ScilabError(errorMsg);
612 void DifferentialEquationFunctions::execInt3dF(double* x, int* numfun, double* funvls)
615 if (m_pCallFFunction)
617 callInt3dMacroF(x, numfun, funvls);
619 else if (m_pStringFFunctionDyn)
621 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
624 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
625 throw ast::ScilabError(errorMsg);
627 ((int3d_f_t)(func->functionPtr))(x, numfun, funvls);
629 else if (m_pStringFFunctionStatic) // function static
631 ((int3d_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(x, numfun, funvls);
635 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
636 throw ast::ScilabError(errorMsg);
640 double DifferentialEquationFunctions::execInt2dF(double* x, double* y)
643 if (m_pCallFFunction)
645 return callInt2dMacroF(x, y);
647 else if (m_pStringFFunctionDyn)
649 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
652 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
653 throw ast::ScilabError(errorMsg);
655 return ((int2d_f_t)(func->functionPtr))(x, y);
657 else if (m_pStringFFunctionStatic) // function static
659 return ((int2d_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(x, y);
663 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
664 throw ast::ScilabError(errorMsg);
668 double DifferentialEquationFunctions::execIntgF(double* x)
671 if (m_pCallFFunction)
673 return callIntgMacroF(x);
675 else if (m_pStringFFunctionDyn)
677 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
680 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
681 throw ast::ScilabError(errorMsg);
683 return ((intg_f_t)(func->functionPtr))(x);
685 else if (m_pStringFFunctionStatic) // function static
687 return ((intg_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(x);
691 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
692 throw ast::ScilabError(errorMsg);
696 void DifferentialEquationFunctions::execOdeF(int* n, double* t, double* y, double* yout)
699 if (m_pCallFFunction)
701 callOdeMacroF(n, t, y, yout);
703 else if (m_pStringFFunctionDyn)
705 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringFFunctionDyn->get(0));
708 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringFFunctionDyn->get(0));
709 throw ast::ScilabError(errorMsg);
711 ((ode_f_t)(func->functionPtr))(n, t, y, yout);
713 else if (m_pStringFFunctionStatic) // function static
715 if (m_wstrCaller == L"ode")
717 ((ode_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(n, t, y, yout);
719 else // if (m_wstrCaller == L"odedc")
721 ((odedc_f_t)m_staticFunctionMap[m_pStringFFunctionStatic->get(0)])(&m_odedcFlag, n, &m_odedcYDSize, t, y, yout);
726 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "f");
727 throw ast::ScilabError(errorMsg);
731 void DifferentialEquationFunctions::execFunctionJac(int *n, double *t, double *y, int *ml, int *mu, double *J, int *nrpd)
734 if (m_pCallJacFunction)
736 callMacroJac(n, t, y, ml, mu, J, nrpd);
738 else if (m_pStringJacFunctionDyn)
740 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringJacFunctionDyn->get(0));
743 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringJacFunctionDyn->get(0));
744 throw ast::ScilabError(errorMsg);
746 ((func_jac_t)(func->functionPtr))(n, t, y, ml, mu, J, nrpd);
748 else if (m_pStringJacFunctionStatic) // function static
750 ((func_jac_t)m_staticFunctionMap[m_pStringJacFunctionStatic->get(0)])(n, t, y, ml, mu, J, nrpd);
754 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "jacobian");
755 throw ast::ScilabError(errorMsg);
759 void DifferentialEquationFunctions::execFunctionG(int* n, double* t, double* y, int* ng, double* gout)
762 if (m_pCallGFunction)
764 callMacroG(n, t, y, ng, gout);
766 else if (m_pStringGFunctionDyn)
768 ConfigVariable::EntryPointStr* func = ConfigVariable::getEntryPoint(m_pStringGFunctionDyn->get(0));
771 sprintf(errorMsg, _("Undefined fonction '%ls'.\n"), m_pStringGFunctionDyn->get(0));
772 throw ast::ScilabError(errorMsg);
774 ((func_g_t)(func->functionPtr))(n, t, y, ng, gout);
776 else if (m_pStringGFunctionStatic)// function static
778 ((func_g_t)m_staticFunctionMap[m_pStringGFunctionStatic->get(0)])(n, t, y, ng, gout);
782 sprintf(errorMsg, _("User function '%s' have not been setted.\n"), "g");
783 throw ast::ScilabError(errorMsg);
789 void DifferentialEquationFunctions::setOdeYRows(int rows)
794 void DifferentialEquationFunctions::setOdeYCols(int cols)
800 void DifferentialEquationFunctions::setOdedcYDSize(int size)
802 m_odedcYDSize = size;
806 void DifferentialEquationFunctions::setOdedcFlag()
812 void DifferentialEquationFunctions::resetOdedcFlag()
817 void DifferentialEquationFunctions::setBvodeM(int _m)
822 void DifferentialEquationFunctions::setBvodeN(int _n)
827 //set function f, jac, g, psol, pjac as types::Callable
828 void DifferentialEquationFunctions::setFFunction(types::Callable* _odeFFunc)
830 m_pCallFFunction = _odeFFunc;
833 void DifferentialEquationFunctions::setJacFunction(types::Callable* _odeJacFunc)
835 m_pCallJacFunction = _odeJacFunc;
838 void DifferentialEquationFunctions::setGFunction(types::Callable* _odeGFunc)
840 m_pCallGFunction = _odeGFunc;
843 void DifferentialEquationFunctions::setPsolFunction(types::Callable* _pSolFunc)
845 m_pCallPsolFunction = _pSolFunc;
848 void DifferentialEquationFunctions::setPjacFunction(types::Callable* _pJacFunc)
850 m_pCallPjacFunction = _pJacFunc;
853 //set function f, jac, g, psol, pjac as types::String
854 bool DifferentialEquationFunctions::setFFunction(types::String* _odeFFunc)
856 if (ConfigVariable::getEntryPoint(_odeFFunc->get(0)))
858 m_pStringFFunctionDyn = _odeFFunc;
863 if (m_staticFunctionMap.find(_odeFFunc->get(0)) != m_staticFunctionMap.end())
865 m_pStringFFunctionStatic = _odeFFunc;
872 bool DifferentialEquationFunctions::setJacFunction(types::String* _odeJacFunc)
874 if (ConfigVariable::getEntryPoint(_odeJacFunc->get(0)))
876 m_pStringJacFunctionDyn = _odeJacFunc;
881 if (m_staticFunctionMap.find(_odeJacFunc->get(0)) != m_staticFunctionMap.end())
883 m_pStringJacFunctionStatic = _odeJacFunc;
890 bool DifferentialEquationFunctions::setGFunction(types::String* _odeGFunc)
892 if (ConfigVariable::getEntryPoint(_odeGFunc->get(0)))
894 m_pStringGFunctionDyn = _odeGFunc;
899 if (m_staticFunctionMap.find(_odeGFunc->get(0)) != m_staticFunctionMap.end())
901 m_pStringGFunctionStatic = _odeGFunc;
908 bool DifferentialEquationFunctions::setPsolFunction(types::String* _pSolFunc)
910 if (ConfigVariable::getEntryPoint(_pSolFunc->get(0)))
912 m_pStringPsolFunctionDyn = _pSolFunc;
917 if (m_staticFunctionMap.find(_pSolFunc->get(0)) != m_staticFunctionMap.end())
919 m_pStringPsolFunctionStatic = _pSolFunc;
926 bool DifferentialEquationFunctions::setPjacFunction(types::String* _pJacFunc)
928 if (ConfigVariable::getEntryPoint(_pJacFunc->get(0)))
930 m_pStringPjacFunctionDyn = _pJacFunc;
935 if (m_staticFunctionMap.find(_pJacFunc->get(0)) != m_staticFunctionMap.end())
937 m_pStringPjacFunctionStatic = _pJacFunc;
944 // set args for f, jac, g, pjac and psol functions
945 void DifferentialEquationFunctions::setFArgs(types::InternalType* _odeFArg)
947 m_FArgs.push_back(_odeFArg);
950 void DifferentialEquationFunctions::setJacArgs(types::InternalType* _odeJacArg)
952 m_JacArgs.push_back(_odeJacArg);
955 void DifferentialEquationFunctions::setGArgs(types::InternalType* _odeGArg)
957 m_odeGArgs.push_back(_odeGArg);
960 void DifferentialEquationFunctions::setPsolArgs(types::InternalType* _pSolArg)
962 m_pSolArgs.push_back(_pSolArg);
965 void DifferentialEquationFunctions::setPjacArgs(types::InternalType* _pJacArg)
967 m_pJacArgs.push_back(_pJacArg);
970 // bvode set function as types::Callable gsub, dgsub, fsub, dfsub, guess
971 void DifferentialEquationFunctions::setGsubFunction(types::Callable* _func)
973 m_pCallGsubFunction = _func;
976 void DifferentialEquationFunctions::setDgsubFunction(types::Callable* _func)
978 m_pCallDgsubFunction = _func;
981 void DifferentialEquationFunctions::setFsubFunction(types::Callable* _func)
983 m_pCallFsubFunction = _func;
986 void DifferentialEquationFunctions::setDfsubFunction(types::Callable* _func)
988 m_pCallDfsubFunction = _func;
991 void DifferentialEquationFunctions::setGuessFunction(types::Callable* _func)
993 m_pCallGuessFunction = _func;
996 // bvode set function as types::String gsub, dgsub, fsub, dfsub, guess
997 bool DifferentialEquationFunctions::setGsubFunction(types::String* _func)
999 if (ConfigVariable::getEntryPoint(_func->get(0)))
1001 m_pStringGsubFunctionDyn = _func;
1006 if (m_staticFunctionMap.find(_func->get(0)) != m_staticFunctionMap.end())
1008 m_pStringGsubFunctionStatic = _func;
1015 bool DifferentialEquationFunctions::setDgsubFunction(types::String* _func)
1017 if (ConfigVariable::getEntryPoint(_func->get(0)))
1019 m_pStringDgsubFunctionDyn = _func;
1024 if (m_staticFunctionMap.find(_func->get(0)) != m_staticFunctionMap.end())
1026 m_pStringDgsubFunctionStatic = _func;
1033 bool DifferentialEquationFunctions::setFsubFunction(types::String* _func)
1035 if (ConfigVariable::getEntryPoint(_func->get(0)))
1037 m_pStringFsubFunctionDyn = _func;
1042 if (m_staticFunctionMap.find(_func->get(0)) != m_staticFunctionMap.end())
1044 m_pStringFsubFunctionStatic = _func;
1051 bool DifferentialEquationFunctions::setDfsubFunction(types::String* _func)
1053 if (ConfigVariable::getEntryPoint(_func->get(0)))
1055 m_pStringDfsubFunctionDyn = _func;
1060 if (m_staticFunctionMap.find(_func->get(0)) != m_staticFunctionMap.end())
1062 m_pStringDfsubFunctionStatic = _func;
1069 bool DifferentialEquationFunctions::setGuessFunction(types::String* _func)
1071 if (ConfigVariable::getEntryPoint(_func->get(0)))
1073 m_pStringGuessFunctionDyn = _func;
1078 if (m_staticFunctionMap.find(_func->get(0)) != m_staticFunctionMap.end())
1080 m_pStringGuessFunctionStatic = _func;
1087 // bvode set set args for gsub, dgsub, fsub, dfsub, guess functions
1088 void DifferentialEquationFunctions::setGsubArgs(types::InternalType* _arg)
1090 m_GsubArgs.push_back(_arg);
1093 void DifferentialEquationFunctions::setDgsubArgs(types::InternalType* _arg)
1095 m_DgsubArgs.push_back(_arg);
1098 void DifferentialEquationFunctions::setFsubArgs(types::InternalType* _arg)
1100 m_FsubArgs.push_back(_arg);
1103 void DifferentialEquationFunctions::setDfsubArgs(types::InternalType* _arg)
1105 m_DfsubArgs.push_back(_arg);
1108 void DifferentialEquationFunctions::setGuessArgs(types::InternalType* _arg)
1110 m_GuessArgs.push_back(_arg);
1114 void DifferentialEquationFunctions::setMu(int mu)
1120 void DifferentialEquationFunctions::setMl(int ml)
1128 int DifferentialEquationFunctions::getOdeYRows()
1133 int DifferentialEquationFunctions::getOdeYCols()
1138 // get odedc yd size
1139 int DifferentialEquationFunctions::getOdedcYDSize()
1141 return m_odedcYDSize;
1145 int DifferentialEquationFunctions::getOdedcFlag()
1150 /*------------------------------- private -------------------------------------------*/
1151 void DifferentialEquationFunctions::callOdeMacroF(int* n, double* t, double* y, double* ydot)
1159 types::optional_list opt;
1160 ast::ExecVisitor execFunc;
1162 types::Double* pDblY = NULL;
1163 types::Double* pDblYC = NULL;
1164 types::Double* pDblYD = NULL;
1165 types::Double* pDblFlag = NULL;
1167 // create input args
1168 types::Double* pDblT = new types::Double(*t);
1169 pDblT->IncreaseRef();
1171 if (m_odedcYDSize) // odedc
1173 pDblYC = new types::Double(*n, 1);
1175 pDblYC->IncreaseRef();
1176 pDblYD = new types::Double(m_odedcYDSize, 1);
1177 pDblYD->set(y + *n);
1178 pDblYD->IncreaseRef();
1179 pDblFlag = new types::Double(m_odedcFlag);
1180 pDblFlag->IncreaseRef();
1184 pDblY = new types::Double(m_odeYRows, m_odeYCols);
1186 pDblY->IncreaseRef();
1190 in.push_back(pDblT);
1191 if (m_odedcYDSize) // odedc
1193 in.push_back(pDblYC);
1194 in.push_back(pDblYD);
1195 in.push_back(pDblFlag);
1199 in.push_back(pDblY);
1202 for (int i = 0; i < (int)m_FArgs.size(); i++)
1204 m_FArgs[i]->IncreaseRef();
1205 in.push_back(m_FArgs[i]);
1208 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1210 for (int i = 0; i < (int)m_FArgs.size(); i++)
1212 m_FArgs[i]->DecreaseRef();
1217 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
1218 throw ast::ScilabError(errorMsg);
1221 if (out.size() != iRetCount)
1223 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1224 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1226 throw ast::ScilabError(errorMsg);
1229 out[0]->IncreaseRef();
1231 pDblT->DecreaseRef();
1232 if (pDblT->isDeletable())
1237 if (m_odedcYDSize) // odedc
1239 pDblYC->DecreaseRef();
1240 if (pDblYC->isDeletable())
1244 pDblYD->DecreaseRef();
1245 if (pDblYD->isDeletable())
1249 pDblFlag->DecreaseRef();
1250 if (pDblFlag->isDeletable())
1257 pDblY->DecreaseRef();
1258 if (pDblY->isDeletable())
1264 out[0]->DecreaseRef();
1266 if (out[0]->isDouble() == false)
1268 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1269 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1271 throw ast::ScilabError(errorMsg);
1273 types::Double* pDblOut = out[0]->getAs<types::Double>();
1274 if (pDblOut->isComplex())
1276 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1277 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1279 throw ast::ScilabError(errorMsg);
1282 if (m_odedcFlag && m_odedcYDSize)
1284 C2F(dcopy)(&m_odedcYDSize, pDblOut->get(), &one, ydot, &one);
1288 C2F(dcopy)(n, pDblOut->get(), &one, ydot, &one);
1291 if (out[0]->isDeletable())
1297 void DifferentialEquationFunctions::callMacroJac(int* n, double* t, double* y, int* ml, int* mu, double* J, int* nrpd)
1302 int size = (*n) * (*nrpd);
1306 types::optional_list opt;
1307 ast::ExecVisitor execFunc;
1309 types::Double* pDblY = new types::Double(m_odeYRows, m_odeYCols);
1311 types::Double* pDblT = new types::Double(*t);
1313 pDblT->IncreaseRef();
1314 pDblY->IncreaseRef();
1316 in.push_back(pDblT);
1317 in.push_back(pDblY);
1319 for (int i = 0; i < (int)m_JacArgs.size(); i++)
1321 in.push_back(m_JacArgs[i]);
1324 bool bOk = m_pCallJacFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1328 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallJacFunction->getName().c_str());
1329 throw ast::ScilabError(errorMsg);
1332 out[0]->IncreaseRef();
1333 pDblT->DecreaseRef();
1334 pDblY->DecreaseRef();
1336 if (pDblT->isDeletable())
1341 if (pDblY->isDeletable())
1346 if (out.size() != iRetCount)
1348 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
1349 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1351 throw ast::ScilabError(errorMsg);
1354 out[0]->DecreaseRef();
1355 if (out[0]->isDouble() == false)
1357 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
1358 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1360 throw ast::ScilabError(errorMsg);
1363 // dimension y(*), pd(nrowpd,*)
1364 C2F(dcopy)(&size, out[0]->getAs<types::Double>()->get(), &one, J, &one);
1367 void DifferentialEquationFunctions::callMacroG(int* n, double* t, double* y, int* ng, double* gout)
1375 types::optional_list opt;
1376 ast::ExecVisitor execFunc;
1378 types::Double* pDblY = new types::Double(m_odeYRows, m_odeYCols);
1380 types::Double* pDblT = new types::Double(*t);
1382 pDblT->IncreaseRef();
1383 pDblY->IncreaseRef();
1385 in.push_back(pDblT);
1386 in.push_back(pDblY);
1388 for (int i = 0; i < (int)m_odeGArgs.size(); i++)
1390 in.push_back(m_odeGArgs[i]);
1393 bool bOk = m_pCallGFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1397 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallGFunction->getName().c_str());
1398 throw ast::ScilabError(errorMsg);
1401 if (out.size() != iRetCount)
1403 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
1404 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1406 throw ast::ScilabError(errorMsg);
1409 out[0]->IncreaseRef();
1411 pDblT->DecreaseRef();
1412 pDblY->DecreaseRef();
1414 if (pDblT->isDeletable())
1419 if (pDblY->isDeletable())
1424 out[0]->DecreaseRef();
1425 if (out[0]->isDouble() == false)
1427 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
1428 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1430 throw ast::ScilabError(errorMsg);
1433 C2F(dcopy)(ng, out[0]->getAs<types::Double>()->get(), &one, gout, &one);
1434 if (out[0]->isDeletable())
1440 double DifferentialEquationFunctions::callIntgMacroF(double* t)
1448 types::optional_list opt;
1449 ast::ExecVisitor execFunc;
1451 // create input args
1452 types::Double* pDblT = new types::Double(*t);
1453 pDblT->IncreaseRef();
1456 in.push_back(pDblT);
1458 for (int i = 0; i < (int)m_FArgs.size(); i++)
1460 m_FArgs[i]->IncreaseRef();
1461 in.push_back(m_FArgs[i]);
1464 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1466 for (int i = 0; i < (int)m_FArgs.size(); i++)
1468 m_FArgs[i]->DecreaseRef();
1473 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
1474 throw ast::ScilabError(errorMsg);
1477 if (out.size() != iRetCount)
1479 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1480 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1482 throw ast::ScilabError(errorMsg);
1485 out[0]->IncreaseRef();
1487 pDblT->DecreaseRef();
1488 if (pDblT->isDeletable())
1493 out[0]->DecreaseRef();
1494 if (out[0]->isDouble() == false)
1496 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1497 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1499 throw ast::ScilabError(errorMsg);
1503 types::Double* pDblOut = out[0]->getAs<types::Double>();
1504 if (pDblOut->getSize() != 1)
1506 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1507 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 1);
1509 throw ast::ScilabError(errorMsg);
1512 double res = pDblOut->get(0);
1513 if (out[0]->isDeletable())
1521 double DifferentialEquationFunctions::callInt2dMacroF(double* x, double* y)
1529 types::optional_list opt;
1530 ast::ExecVisitor execFunc;
1532 // create input args
1533 types::Double* pDblX = new types::Double(*x);
1534 pDblX->IncreaseRef();
1535 types::Double* pDblY = new types::Double(*y);
1536 pDblY->IncreaseRef();
1539 in.push_back(pDblX);
1540 in.push_back(pDblY);
1542 for (int i = 0; i < (int)m_FArgs.size(); i++)
1544 m_FArgs[i]->IncreaseRef();
1545 in.push_back(m_FArgs[i]);
1548 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1550 for (int i = 0; i < (int)m_FArgs.size(); i++)
1552 m_FArgs[i]->DecreaseRef();
1557 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
1558 throw ast::ScilabError(errorMsg);
1561 if (out.size() != iRetCount)
1563 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1564 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1566 throw ast::ScilabError(errorMsg);
1569 out[0]->IncreaseRef();
1571 pDblX->DecreaseRef();
1572 if (pDblX->isDeletable())
1577 pDblY->DecreaseRef();
1578 if (pDblY->isDeletable())
1583 out[0]->DecreaseRef();
1584 if (out[0]->isDouble() == false)
1586 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1587 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1589 throw ast::ScilabError(errorMsg);
1592 types::Double* pDblOut = out[0]->getAs<types::Double>();
1593 if (pDblOut->getSize() != 1)
1595 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1596 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 1);
1598 throw ast::ScilabError(errorMsg);
1601 double res = pDblOut->get(0);
1602 if (out[0]->isDeletable())
1610 void DifferentialEquationFunctions::callInt3dMacroF(double* xyz, int* numfun, double* funvls)
1618 types::optional_list opt;
1619 ast::ExecVisitor execFunc;
1621 // create input args
1622 types::Double* pDblXYZ = new types::Double(3, 1);
1624 pDblXYZ->IncreaseRef();
1625 types::Double* pDblNumfun = new types::Double(*numfun);
1626 pDblNumfun->IncreaseRef();
1629 in.push_back(pDblXYZ);
1630 in.push_back(pDblNumfun);
1632 for (int i = 0; i < (int)m_FArgs.size(); i++)
1634 m_FArgs[i]->IncreaseRef();
1635 in.push_back(m_FArgs[i]);
1638 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1640 for (int i = 0; i < (int)m_FArgs.size(); i++)
1642 m_FArgs[i]->DecreaseRef();
1647 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
1648 throw ast::ScilabError(errorMsg);
1651 if (out.size() != iRetCount)
1653 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1654 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1656 throw ast::ScilabError(errorMsg);
1659 out[0]->IncreaseRef();
1661 pDblXYZ->DecreaseRef();
1662 if (pDblXYZ->isDeletable())
1667 pDblNumfun->DecreaseRef();
1668 if (pDblNumfun->isDeletable())
1673 out[0]->DecreaseRef();
1674 if (out[0]->isDouble() == false)
1676 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1677 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1679 throw ast::ScilabError(errorMsg);
1682 types::Double* pDblOut = out[0]->getAs<types::Double>();
1683 if (pDblOut->getSize() != *numfun)
1685 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1686 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: Matrix of size %d expected.\n"), pstrName, 1, *numfun);
1688 throw ast::ScilabError(errorMsg);
1691 C2F(dcopy)(numfun, pDblOut->get(), &one, funvls, &one);
1692 if (out[0]->isDeletable())
1698 void DifferentialEquationFunctions::callFevalMacroF(int* nn, double* x1, double* x2, double* xres, int* itype)
1706 types::optional_list opt;
1707 ast::ExecVisitor execFunc;
1709 types::Double* pDblX = NULL;
1710 types::Double* pDblY = NULL;
1712 // create input args
1714 pDblX = new types::Double(*x1);
1715 pDblX->IncreaseRef();
1716 in.push_back(pDblX);
1720 pDblY = new types::Double(*x2);
1721 pDblY->IncreaseRef();
1722 in.push_back(pDblY);
1725 for (int i = 0; i < (int)m_FArgs.size(); i++)
1727 m_FArgs[i]->IncreaseRef();
1728 in.push_back(m_FArgs[i]);
1731 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1733 for (int i = 0; i < (int)m_FArgs.size(); i++)
1735 m_FArgs[i]->DecreaseRef();
1740 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
1741 throw ast::ScilabError(errorMsg);
1744 if (out.size() != iRetCount)
1746 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1747 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1749 throw ast::ScilabError(errorMsg);
1752 out[0]->IncreaseRef();
1754 pDblX->DecreaseRef();
1755 if (pDblX->isDeletable())
1762 pDblY->DecreaseRef();
1763 if (pDblY->isDeletable())
1769 out[0]->DecreaseRef();
1770 if (out[0]->isDouble() == false)
1772 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1773 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1775 throw ast::ScilabError(errorMsg);
1779 types::Double* pDblOut = out[0]->getAs<types::Double>();
1780 if (pDblOut->getSize() != 1)
1782 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
1783 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 1);
1785 throw ast::ScilabError(errorMsg);
1788 if (pDblOut->isComplex())
1791 xres[0] = pDblOut->get(0);
1792 xres[1] = pDblOut->getImg(0);
1797 xres[0] = pDblOut->get(0);
1800 if (out[0]->isDeletable())
1806 void DifferentialEquationFunctions::callBvodeMacroGsub(int* i, double* z, double* g)
1814 types::optional_list opt;
1815 ast::ExecVisitor execFunc;
1817 types::Double* pDblI = NULL;
1818 types::Double* pDblZ = NULL;
1820 pDblI = new types::Double(*i);
1821 pDblI->IncreaseRef();
1822 in.push_back(pDblI);
1824 pDblZ = new types::Double(m_bvodeM, 1);
1826 pDblZ->IncreaseRef();
1827 in.push_back(pDblZ);
1830 for (int i = 0; i < (int)m_GsubArgs.size(); i++)
1832 in.push_back(m_GsubArgs[i]);
1835 bool bOk = m_pCallGsubFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1839 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallGsubFunction->getName().c_str());
1840 throw ast::ScilabError(errorMsg);
1843 if (out.size() != iRetCount)
1845 char* pstrName = wide_string_to_UTF8(m_pCallGsubFunction->getName().c_str());
1846 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1848 throw ast::ScilabError(errorMsg);
1851 out[0]->IncreaseRef();
1853 pDblI->DecreaseRef();
1854 if (pDblI->isDeletable())
1859 pDblZ->DecreaseRef();
1860 if (pDblZ->isDeletable())
1865 out[0]->DecreaseRef();
1866 if (out[0]->isDouble() == false)
1868 char* pstrName = wide_string_to_UTF8(m_pCallGsubFunction->getName().c_str());
1869 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1871 throw ast::ScilabError(errorMsg);
1874 types::Double* pDblOut = out[0]->getAs<types::Double>();
1875 if (pDblOut->getSize() != 1)
1877 char* pstrName = wide_string_to_UTF8(m_pCallGsubFunction->getName().c_str());
1878 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 1);
1880 throw ast::ScilabError(errorMsg);
1883 *g = pDblOut->get(0);
1884 if (out[0]->isDeletable())
1890 void DifferentialEquationFunctions::callBvodeMacroDgsub(int* i, double* z, double* g)
1898 types::optional_list opt;
1899 ast::ExecVisitor execFunc;
1901 types::Double* pDblI = NULL;
1902 types::Double* pDblZ = NULL;
1904 pDblI = new types::Double(*i);
1905 pDblI->IncreaseRef();
1906 in.push_back(pDblI);
1908 pDblZ = new types::Double(m_bvodeM, 1);
1910 pDblZ->IncreaseRef();
1911 in.push_back(pDblZ);
1913 for (int i = 0; i < (int)m_DgsubArgs.size(); i++)
1915 in.push_back(m_DgsubArgs[i]);
1918 bool bOk = m_pCallDgsubFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
1922 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallDgsubFunction->getName().c_str());
1923 throw ast::ScilabError(errorMsg);
1926 if (out.size() != iRetCount)
1928 char* pstrName = wide_string_to_UTF8(m_pCallDgsubFunction->getName().c_str());
1929 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
1931 throw ast::ScilabError(errorMsg);
1934 out[0]->IncreaseRef();
1936 pDblI->DecreaseRef();
1937 if (pDblI->isDeletable())
1942 pDblZ->DecreaseRef();
1943 if (pDblZ->isDeletable())
1948 out[0]->DecreaseRef();
1949 if (out[0]->isDouble() == false)
1951 char* pstrName = wide_string_to_UTF8(m_pCallDgsubFunction->getName().c_str());
1952 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
1954 throw ast::ScilabError(errorMsg);
1957 types::Double* pDblOut = out[0]->getAs<types::Double>();
1958 if (pDblOut->getSize() != m_bvodeM)
1960 char* pstrName = wide_string_to_UTF8(m_pCallDgsubFunction->getName().c_str());
1961 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Matrix of size %d expected.\n"), pstrName, 1, m_bvodeM);
1963 throw ast::ScilabError(errorMsg);
1966 C2F(dcopy)(&m_bvodeM, pDblOut->get(), &one, g, &one);
1967 if (out[0]->isDeletable())
1973 void DifferentialEquationFunctions::callBvodeMacroFsub(double* x, double* z, double* d)
1981 types::optional_list opt;
1982 ast::ExecVisitor execFunc;
1984 types::Double* pDblX = NULL;
1985 types::Double* pDblZ = NULL;
1987 pDblX = new types::Double(*x);
1988 pDblX->IncreaseRef();
1989 in.push_back(pDblX);
1991 pDblZ = new types::Double(m_bvodeM, 1);
1993 pDblZ->IncreaseRef();
1994 in.push_back(pDblZ);
1997 for (int i = 0; i < (int)m_FsubArgs.size(); i++)
1999 in.push_back(m_FsubArgs[i]);
2002 bool bOk = m_pCallFsubFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2006 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFsubFunction->getName().c_str());
2007 throw ast::ScilabError(errorMsg);
2010 if (out.size() != iRetCount)
2012 char* pstrName = wide_string_to_UTF8(m_pCallFsubFunction->getName().c_str());
2013 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2015 throw ast::ScilabError(errorMsg);
2018 out[0]->IncreaseRef();
2020 pDblX->DecreaseRef();
2021 if (pDblX->isDeletable())
2026 pDblZ->DecreaseRef();
2027 if (pDblZ->isDeletable())
2032 out[0]->DecreaseRef();
2033 if (out[0]->isDouble() == false)
2035 char* pstrName = wide_string_to_UTF8(m_pCallFsubFunction->getName().c_str());
2036 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2038 throw ast::ScilabError(errorMsg);
2041 types::Double* pDblOut = out[0]->getAs<types::Double>();
2042 if (pDblOut->getSize() != m_bvodeN)
2044 char* pstrName = wide_string_to_UTF8(m_pCallFsubFunction->getName().c_str());
2045 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, m_bvodeN);
2047 throw ast::ScilabError(errorMsg);
2050 C2F(dcopy)(&m_bvodeN, pDblOut->get(), &one, d, &one);
2051 if (out[0]->isDeletable())
2057 void DifferentialEquationFunctions::callBvodeMacroDfsub(double* x, double* z, double* d)
2065 types::optional_list opt;
2066 ast::ExecVisitor execFunc;
2068 types::Double* pDblX = NULL;
2069 types::Double* pDblZ = NULL;
2071 pDblX = new types::Double(*x);
2072 pDblX->IncreaseRef();
2073 in.push_back(pDblX);
2075 pDblZ = new types::Double(m_bvodeM, 1);
2077 pDblZ->IncreaseRef();
2078 in.push_back(pDblZ);
2081 for (int i = 0; i < (int)m_DfsubArgs.size(); i++)
2083 in.push_back(m_DfsubArgs[i]);
2086 bool bOk = m_pCallDfsubFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2090 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallDfsubFunction->getName().c_str());
2091 throw ast::ScilabError(errorMsg);
2094 if (out.size() != iRetCount)
2096 char* pstrName = wide_string_to_UTF8(m_pCallDfsubFunction->getName().c_str());
2097 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2099 throw ast::ScilabError(errorMsg);
2102 out[0]->IncreaseRef();
2104 pDblX->DecreaseRef();
2105 if (pDblX->isDeletable())
2110 pDblZ->DecreaseRef();
2111 if (pDblZ->isDeletable())
2116 out[0]->DecreaseRef();
2117 if (out[0]->isDouble() == false)
2119 char* pstrName = wide_string_to_UTF8(m_pCallDfsubFunction->getName().c_str());
2120 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2122 throw ast::ScilabError(errorMsg);
2125 types::Double* pDblOut = out[0]->getAs<types::Double>();
2126 int size = m_bvodeN * m_bvodeM;
2127 if (pDblOut->getSize() != size)
2129 char* pstrName = wide_string_to_UTF8(m_pCallDfsubFunction->getName().c_str());
2130 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, size);
2132 throw ast::ScilabError(errorMsg);
2135 C2F(dcopy)(&size, pDblOut->get(), &one, d, &one);
2136 if (out[0]->isDeletable())
2142 void DifferentialEquationFunctions::callBvodeMacroGuess(double* x, double* z, double* d)
2150 types::optional_list opt;
2151 ast::ExecVisitor execFunc;
2153 types::Double* pDblX = NULL;
2155 pDblX = new types::Double(*x);
2156 pDblX->IncreaseRef();
2157 in.push_back(pDblX);
2159 for (int i = 0; i < (int)m_GuessArgs.size(); i++)
2161 in.push_back(m_GuessArgs[i]);
2164 bool bOk = m_pCallGuessFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2168 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallGuessFunction->getName().c_str());
2169 throw ast::ScilabError(errorMsg);
2172 if (out.size() != iRetCount)
2174 char* pstrName = wide_string_to_UTF8(m_pCallGuessFunction->getName().c_str());
2175 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2177 throw ast::ScilabError(errorMsg);
2180 out[0]->IncreaseRef();
2181 out[1]->IncreaseRef();
2183 pDblX->DecreaseRef();
2184 if (pDblX->isDeletable())
2189 out[0]->DecreaseRef();
2190 if (out[0]->isDouble() == false)
2192 char* pstrName = wide_string_to_UTF8(m_pCallGuessFunction->getName().c_str());
2193 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2195 throw ast::ScilabError(errorMsg);
2198 out[1]->DecreaseRef();
2199 if (out[1]->isDouble() == false)
2201 char* pstrName = wide_string_to_UTF8(m_pCallGuessFunction->getName().c_str());
2202 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 2);
2204 throw ast::ScilabError(errorMsg);
2207 types::Double* pDblOutZ = out[0]->getAs<types::Double>();
2208 if (pDblOutZ->getSize() != m_bvodeM)
2210 char* pstrName = wide_string_to_UTF8(m_pCallGuessFunction->getName().c_str());
2211 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, m_bvodeM);
2213 throw ast::ScilabError(errorMsg);
2216 types::Double* pDblOutD = out[1]->getAs<types::Double>();
2217 if (pDblOutD->getSize() != m_bvodeN)
2219 char* pstrName = wide_string_to_UTF8(m_pCallGuessFunction->getName().c_str());
2220 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, m_bvodeN);
2222 throw ast::ScilabError(errorMsg);
2225 C2F(dcopy)(&m_bvodeM, pDblOutZ->get(), &one, z, &one);
2226 C2F(dcopy)(&m_bvodeN, pDblOutD->get(), &one, d, &one);
2227 if (out[0]->isDeletable())
2232 if (out[1]->isDeletable())
2238 void DifferentialEquationFunctions::callImplMacroF(int* neq, double* t, double* y, double*s, double* r, int* ires)
2247 types::optional_list opt;
2248 ast::ExecVisitor execFunc;
2250 types::Double* pDblT = new types::Double(*t);
2251 pDblT->IncreaseRef();
2252 in.push_back(pDblT);
2254 types::Double* pDblY = new types::Double(*neq, 1);
2256 pDblY->IncreaseRef();
2257 in.push_back(pDblY);
2259 types::Double* pDblS = new types::Double(*neq, 1);
2261 pDblS->IncreaseRef();
2262 in.push_back(pDblS);
2264 for (int i = 0; i < (int)m_FArgs.size(); i++)
2266 m_FArgs[i]->IncreaseRef();
2267 in.push_back(m_FArgs[i]);
2270 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2272 for (int i = 0; i < (int)m_FArgs.size(); i++)
2274 m_FArgs[i]->DecreaseRef();
2279 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
2280 throw ast::ScilabError(errorMsg);
2283 if (out.size() != iRetCount)
2285 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2286 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2288 throw ast::ScilabError(errorMsg);
2291 out[0]->IncreaseRef();
2293 pDblT->DecreaseRef();
2294 if (pDblT->isDeletable())
2299 pDblY->DecreaseRef();
2300 if (pDblY->isDeletable())
2305 pDblS->DecreaseRef();
2306 if (pDblS->isDeletable())
2311 out[0]->DecreaseRef();
2312 if (out[0]->isDouble() == false)
2314 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2315 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Matrix expected.\n"), pstrName, 1);
2317 throw ast::ScilabError(errorMsg);
2320 types::Double* pDblOutR = out[0]->getAs<types::Double>();
2321 if (pDblOutR->getSize() != *neq)
2323 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2324 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Matrix of size %d expected.\n"), pstrName, 1, *neq);
2326 throw ast::ScilabError(errorMsg);
2329 C2F(dcopy)(neq, pDblOutR->get(), &one, r, &one);
2331 if (out[0]->isDeletable())
2337 void DifferentialEquationFunctions::callImplMacroG(int* neq, double* t, double* y, double* ml, double* mu, double* p, int* nrowp)
2345 types::optional_list opt;
2346 ast::ExecVisitor execFunc;
2348 types::Double* pDblT = new types::Double(*t);
2349 pDblT->IncreaseRef();
2350 in.push_back(pDblT);
2352 types::Double* pDblY = new types::Double(*neq, 1);
2354 pDblY->IncreaseRef();
2355 in.push_back(pDblY);
2357 types::Double* pDblP = new types::Double(*nrowp, *neq);
2359 pDblP->IncreaseRef();
2360 in.push_back(pDblP);
2362 for (int i = 0; i < (int)m_odeGArgs.size(); i++)
2364 m_odeGArgs[i]->IncreaseRef();
2365 in.push_back(m_odeGArgs[i]);
2368 bool bOk = m_pCallGFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2370 for (int i = 0; i < (int)m_FArgs.size(); i++)
2372 m_FArgs[i]->DecreaseRef();
2377 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallGFunction->getName().c_str());
2378 throw ast::ScilabError(errorMsg);
2381 if (out.size() != iRetCount)
2383 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
2384 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2386 throw ast::ScilabError(errorMsg);
2389 out[0]->IncreaseRef();
2391 pDblT->DecreaseRef();
2392 if (pDblT->isDeletable())
2397 pDblY->DecreaseRef();
2398 if (pDblY->isDeletable())
2403 out[0]->DecreaseRef();
2404 if (out[0]->isDouble() == false)
2406 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
2407 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2409 throw ast::ScilabError(errorMsg);
2412 types::Double* pDblOutP = out[0]->getAs<types::Double>();
2413 if (pDblOutP->getCols() != *neq || pDblOutP->getRows() != *nrowp)
2415 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
2416 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d x %d expected.\n"), pstrName, 1, *neq, *nrowp);
2418 throw ast::ScilabError(errorMsg);
2421 int size = *neq **nrowp;
2422 C2F(dcopy)(&size, pDblOutP->get(), &one, p, &one);
2423 if (out[0]->isDeletable())
2429 void DifferentialEquationFunctions::callImplMacroJac(int* neq, double* t, double* y, double* s, double* ml, double* mu, double* p, int* nrowp)
2437 types::optional_list opt;
2438 ast::ExecVisitor execFunc;
2440 types::Double* pDblT = new types::Double(*t);
2441 pDblT->IncreaseRef();
2442 in.push_back(pDblT);
2444 types::Double* pDblY = new types::Double(*neq, 1);
2446 pDblY->IncreaseRef();
2447 in.push_back(pDblY);
2449 types::Double* pDblS = new types::Double(*neq, 1);
2451 pDblS->IncreaseRef();
2452 in.push_back(pDblS);
2454 for (int i = 0; i < (int)m_JacArgs.size(); i++)
2456 m_JacArgs[i]->IncreaseRef();
2457 in.push_back(m_JacArgs[i]);
2460 bool bOk = m_pCallJacFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2462 for (int i = 0; i < (int)m_FArgs.size(); i++)
2464 m_FArgs[i]->DecreaseRef();
2469 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallJacFunction->getName().c_str());
2470 throw ast::ScilabError(errorMsg);
2473 if (out.size() != iRetCount)
2475 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
2476 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2478 throw ast::ScilabError(errorMsg);
2481 out[0]->IncreaseRef();
2483 pDblT->DecreaseRef();
2484 if (pDblT->isDeletable())
2489 pDblY->DecreaseRef();
2490 if (pDblY->isDeletable())
2495 pDblS->DecreaseRef();
2496 if (pDblS->isDeletable())
2501 out[0]->DecreaseRef();
2502 if (out[0]->isDouble() == false)
2504 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
2505 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2507 throw ast::ScilabError(errorMsg);
2510 types::Double* pDblOutP = out[0]->getAs<types::Double>();
2511 if (pDblOutP->getCols() != *neq || pDblOutP->getRows() != *nrowp)
2513 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
2514 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d x %d expected.\n"), pstrName, 1, *neq, *nrowp);
2516 throw ast::ScilabError(errorMsg);
2519 int size = *neq **nrowp;
2520 C2F(dcopy)(&size, pDblOutP->get(), &one, p, &one);
2521 if (out[0]->isDeletable())
2527 void DifferentialEquationFunctions::callDasslMacroF(double* t, double* y, double* ydot, double* delta, int* ires, double* rpar, int* ipar)
2535 types::optional_list opt;
2536 ast::ExecVisitor execFunc;
2538 types::Double* pDblT = new types::Double(*t);
2539 pDblT->IncreaseRef();
2540 in.push_back(pDblT);
2542 types::Double* pDblY = new types::Double(m_odeYRows, 1);
2544 pDblY->IncreaseRef();
2545 in.push_back(pDblY);
2547 types::Double* pDblYdot = new types::Double(m_odeYRows, 1);
2548 pDblYdot->set(ydot);
2549 pDblYdot->IncreaseRef();
2550 in.push_back(pDblYdot);
2552 for (int i = 0; i < (int)m_FArgs.size(); i++)
2554 m_FArgs[i]->IncreaseRef();
2555 in.push_back(m_FArgs[i]);
2558 bool bOk = m_pCallFFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2560 for (int i = 0; i < (int)m_FArgs.size(); i++)
2562 m_FArgs[i]->DecreaseRef();
2567 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallFFunction->getName().c_str());
2568 throw ast::ScilabError(errorMsg);
2571 if (out.size() != iRetCount)
2573 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2574 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2576 throw ast::ScilabError(errorMsg);
2579 out[0]->IncreaseRef();
2580 out[1]->IncreaseRef();
2582 pDblT->DecreaseRef();
2583 if (pDblT->isDeletable())
2588 pDblY->DecreaseRef();
2589 if (pDblY->isDeletable())
2594 pDblYdot->DecreaseRef();
2595 if (pDblYdot->isDeletable())
2600 out[0]->DecreaseRef();
2601 if (out[0]->isDouble() == false)
2603 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2604 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2606 throw ast::ScilabError(errorMsg);
2609 out[1]->DecreaseRef();
2610 if (out[1]->isDouble() == false)
2612 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2613 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 2);
2615 throw ast::ScilabError(errorMsg);
2618 types::Double* pDblOutDelta = out[0]->getAs<types::Double>();
2619 if (pDblOutDelta->getSize() != m_odeYRows)
2621 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2622 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, m_odeYRows);
2624 throw ast::ScilabError(errorMsg);
2627 types::Double* pDblOutIres = out[1]->getAs<types::Double>();
2628 if (pDblOutIres->getSize() != 1)
2630 char* pstrName = wide_string_to_UTF8(m_pCallFFunction->getName().c_str());
2631 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 2);
2633 throw ast::ScilabError(errorMsg);
2636 C2F(dcopy)(&m_odeYRows, pDblOutDelta->get(), &one, delta, &one);
2637 *ires = (int)pDblOutIres->get(0);
2638 if (out[0]->isDeletable())
2644 void DifferentialEquationFunctions::callDasslMacroJac(double* t, double* y, double* ydot, double* pd, double* cj, double* rpar, int* ipar)
2652 types::optional_list opt;
2653 ast::ExecVisitor execFunc;
2655 types::Double* pDblT = new types::Double(*t);
2656 pDblT->IncreaseRef();
2657 in.push_back(pDblT);
2659 types::Double* pDblY = new types::Double(m_odeYRows, 1);
2661 pDblY->IncreaseRef();
2662 in.push_back(pDblY);
2664 types::Double* pDblYdot = new types::Double(m_odeYRows, 1);
2665 pDblYdot->set(ydot);
2666 pDblYdot->IncreaseRef();
2667 in.push_back(pDblYdot);
2669 types::Double* pDblCj = new types::Double(*cj);
2670 pDblCj->IncreaseRef();
2671 in.push_back(pDblCj);
2673 for (int i = 0; i < (int)m_JacArgs.size(); i++)
2675 m_JacArgs[i]->IncreaseRef();
2676 in.push_back(m_JacArgs[i]);
2679 bool bOk = m_pCallJacFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2681 for (int i = 0; i < (int)m_FArgs.size(); i++)
2683 m_FArgs[i]->DecreaseRef();
2688 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallJacFunction->getName().c_str());
2689 throw ast::ScilabError(errorMsg);
2692 if (out.size() != iRetCount)
2694 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
2695 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2697 throw ast::ScilabError(errorMsg);
2700 out[0]->IncreaseRef();
2702 pDblT->DecreaseRef();
2703 if (pDblT->isDeletable())
2708 pDblY->DecreaseRef();
2709 if (pDblY->isDeletable())
2714 pDblYdot->DecreaseRef();
2715 if (pDblYdot->isDeletable())
2720 pDblCj->DecreaseRef();
2721 if (pDblCj->isDeletable())
2726 out[0]->DecreaseRef();
2727 if (out[0]->isDouble() == false)
2729 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
2730 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2732 throw ast::ScilabError(errorMsg);
2735 types::Double* pDblOutPd = out[0]->getAs<types::Double>();
2736 if ( (pDblOutPd->getCols() != m_odeYRows) ||
2737 (!m_bandedJac && pDblOutPd->getRows() != m_odeYRows) ||
2738 (m_bandedJac && pDblOutPd->getRows() != (2 * m_ml + m_mu + 1)))
2740 char* pstrName = wide_string_to_UTF8(m_pCallJacFunction->getName().c_str());
2741 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d x %d expected.\n"), pstrName, 1, m_odeYRows, (2 * m_ml + m_mu + 1));
2743 throw ast::ScilabError(errorMsg);
2746 int size = pDblOutPd->getSize();
2747 C2F(dcopy)(&size, pDblOutPd->get(), &one, pd, &one);
2748 if (out[0]->isDeletable())
2754 void DifferentialEquationFunctions::callDasrtMacroG(int* ny, double* t, double* y, int* ng, double* gout, double* rpar, int* ipar)
2762 types::optional_list opt;
2763 ast::ExecVisitor execFunc;
2765 types::Double* pDblT = new types::Double(*t);
2766 pDblT->IncreaseRef();
2767 in.push_back(pDblT);
2769 types::Double* pDblY = new types::Double(*ny, 1);
2771 pDblY->IncreaseRef();
2772 in.push_back(pDblY);
2774 for (int i = 0; i < (int)m_odeGArgs.size(); i++)
2776 m_odeGArgs[i]->IncreaseRef();
2777 in.push_back(m_odeGArgs[i]);
2780 bool bOk = m_pCallGFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2782 for (int i = 0; i < (int)m_FArgs.size(); i++)
2784 m_FArgs[i]->DecreaseRef();
2789 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallGFunction->getName().c_str());
2790 throw ast::ScilabError(errorMsg);
2793 if (out.size() != iRetCount)
2795 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
2796 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2798 throw ast::ScilabError(errorMsg);
2801 out[0]->IncreaseRef();
2803 pDblT->DecreaseRef();
2804 if (pDblT->isDeletable())
2809 pDblY->DecreaseRef();
2810 if (pDblY->isDeletable())
2815 out[0]->DecreaseRef();
2816 if (out[0]->isDouble() == false)
2818 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
2819 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2821 throw ast::ScilabError(errorMsg);
2824 types::Double* pDblOutGout = out[0]->getAs<types::Double>();
2825 if (pDblOutGout->getSize() != *ng)
2827 char* pstrName = wide_string_to_UTF8(m_pCallGFunction->getName().c_str());
2828 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, *ng);
2830 throw ast::ScilabError(errorMsg);
2833 C2F(dcopy)(ng, pDblOutGout->get(), &one, gout, &one);
2834 if (out[0]->isDeletable())
2840 void DifferentialEquationFunctions::callDaskrMacroPjac(double* res, int* ires, int* neq, double* t, double* y, double* ydot,
2841 double* rewt, double* savr, double* wk, double* h, double* cj,
2842 double* wp, int* iwp, int* ier, double* rpar, int* ipar)
2844 // macro : [R, iR, ier] = psol(neq, t, y, ydot, h, cj, rewt, savr)
2851 types::optional_list opt;
2852 ast::ExecVisitor execFunc;
2854 types::Double* pDblNeq = new types::Double((double)(*neq));
2855 pDblNeq->IncreaseRef();
2856 in.push_back(pDblNeq);
2858 types::Double* pDblT = new types::Double(*t);
2859 pDblT->IncreaseRef();
2860 in.push_back(pDblT);
2862 types::Double* pDblY = new types::Double(m_odeYRows, 1);
2864 pDblY->IncreaseRef();
2865 in.push_back(pDblY);
2867 types::Double* pDblYdot = new types::Double(m_odeYRows, 1);
2868 pDblYdot->set(ydot);
2869 pDblYdot->IncreaseRef();
2870 in.push_back(pDblYdot);
2872 types::Double* pDblH = new types::Double(*h);
2873 pDblH->IncreaseRef();
2874 in.push_back(pDblH);
2876 types::Double* pDblCj = new types::Double(*cj);
2877 pDblCj->IncreaseRef();
2878 in.push_back(pDblCj);
2880 types::Double* pDblRewt = new types::Double(m_odeYRows, 1);
2881 pDblRewt->set(rewt);
2882 pDblRewt->IncreaseRef();
2883 in.push_back(pDblRewt);
2885 types::Double* pDblSavr = new types::Double(m_odeYRows, 1);
2886 pDblSavr->set(savr);
2887 pDblSavr->IncreaseRef();
2888 in.push_back(pDblSavr);
2890 for (int i = 0; i < (int)m_pJacArgs.size(); i++)
2892 in.push_back(m_pJacArgs[i]);
2895 bool bOk = m_pCallPjacFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
2899 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallPjacFunction->getName().c_str());
2900 throw ast::ScilabError(errorMsg);
2903 if (out.size() != iRetCount)
2905 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
2906 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
2908 throw ast::ScilabError(errorMsg);
2911 out[0]->IncreaseRef();
2913 pDblNeq->DecreaseRef();
2914 if (pDblNeq->isDeletable())
2919 pDblT->DecreaseRef();
2920 if (pDblT->isDeletable())
2925 pDblY->DecreaseRef();
2926 if (pDblY->isDeletable())
2931 pDblYdot->DecreaseRef();
2932 if (pDblYdot->isDeletable())
2937 pDblH->DecreaseRef();
2938 if (pDblH->isDeletable())
2943 pDblCj->DecreaseRef();
2944 if (pDblCj->isDeletable())
2949 pDblRewt->DecreaseRef();
2950 if (pDblRewt->isDeletable())
2955 pDblSavr->DecreaseRef();
2956 if (pDblSavr->isDeletable())
2961 // check type of output arguments
2962 if (out[0]->isDouble() == false)
2964 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
2965 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
2967 throw ast::ScilabError(errorMsg);
2970 if (out[1]->isDouble() == false)
2972 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
2973 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 2);
2975 throw ast::ScilabError(errorMsg);
2978 if (out[2]->isDouble() == false)
2980 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
2981 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 3);
2983 throw ast::ScilabError(errorMsg);
2986 // return [R, iR, ier]
2987 types::Double* pDblOutWp = out[0]->getAs<types::Double>();
2988 types::Double* pDblOutIwp = out[1]->getAs<types::Double>();
2989 types::Double* pDblOutIer = out[2]->getAs<types::Double>();
2991 // check size of output argument
2992 if (pDblOutWp->getSize() != *neq **neq)
2994 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
2995 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, *neq **neq);
2997 throw ast::ScilabError(errorMsg);
3000 if (pDblOutIwp->getSize() != 2 * *neq **neq)
3002 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
3003 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 2, 2 * *neq **neq);
3005 throw ast::ScilabError(errorMsg);
3008 if (pDblOutIer->isScalar() == false)
3010 char* pstrName = wide_string_to_UTF8(m_pCallPjacFunction->getName().c_str());
3011 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 3);
3013 throw ast::ScilabError(errorMsg);
3016 // copy output macro results in output variables
3017 int size = pDblOutWp->getSize();
3018 C2F(dcopy)(&size, pDblOutWp->get(), &one, wp, &one);
3020 double* pdblIwp = pDblOutIwp->get();
3021 for (int i = 0; i < pDblOutIwp->getSize(); i++)
3023 iwp[i] = (int)pdblIwp[i];
3026 *ier = (int)(pDblOutIer->get(0));
3028 // delete output macro result
3029 out[0]->DecreaseRef();
3030 if (out[0]->isDeletable())
3035 out[1]->DecreaseRef();
3036 if (out[1]->isDeletable())
3041 out[2]->DecreaseRef();
3042 if (out[2]->isDeletable())
3048 void DifferentialEquationFunctions::callDaskrMacroPsol(int* neq, double* t, double* y, double* ydot, double* savr, double* wk,
3049 double* cj, double* wght, double* wp, int* iwp, double* b, double* eplin,
3050 int* ier, double* rpar, int* ipar)
3052 // macro : [b, ier] = psol(R, iR, b)
3059 types::optional_list opt;
3060 ast::ExecVisitor execFunc;
3062 // input arguments psol(R, iR, b)
3063 types::Double* pDblR = new types::Double(1, *neq **neq);
3065 pDblR->IncreaseRef();
3066 in.push_back(pDblR);
3068 types::Double* pDblIR = new types::Double(1, 2 * *neq **neq);
3069 double* pdblIR = pDblIR->get();
3070 for (int i = 0; i < pDblIR->getSize(); i++)
3072 pdblIR[i] = (double)iwp[i];
3074 pDblIR->IncreaseRef();
3075 in.push_back(pDblIR);
3077 types::Double* pDblB = new types::Double(1, *neq);
3079 pDblB->IncreaseRef();
3080 in.push_back(pDblB);
3082 // optional arguments
3083 for (int i = 0; i < (int)m_pSolArgs.size(); i++)
3085 in.push_back(m_pSolArgs[i]);
3089 bool bOk = m_pCallPsolFunction->call(in, opt, iRetCount, out, &execFunc) == types::Function::OK;
3093 sprintf(errorMsg, _("%ls: error while calling user function.\n"), m_pCallPsolFunction->getName().c_str());
3094 throw ast::ScilabError(errorMsg);
3098 if (out.size() != iRetCount)
3100 char* pstrName = wide_string_to_UTF8(m_pCallPsolFunction->getName().c_str());
3101 sprintf(errorMsg, _("%s: Wrong number of input argument(s): %d expected.\n"), pstrName, iRetCount);
3103 throw ast::ScilabError(errorMsg);
3106 out[0]->IncreaseRef();
3108 // free input arguments
3109 pDblR->DecreaseRef();
3110 if (pDblR->isDeletable())
3115 pDblIR->DecreaseRef();
3116 if (pDblIR->isDeletable())
3121 pDblB->DecreaseRef();
3122 if (pDblB->isDeletable())
3127 // check output result
3128 if (out[0]->isDouble() == false)
3130 char* pstrName = wide_string_to_UTF8(m_pCallPsolFunction->getName().c_str());
3131 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 1);
3133 throw ast::ScilabError(errorMsg);
3136 if (out[1]->isDouble() == false)
3138 char* pstrName = wide_string_to_UTF8(m_pCallPsolFunction->getName().c_str());
3139 sprintf(errorMsg, _("%s: Wrong type for output argument #%d: Real matrix expected.\n"), pstrName, 2);
3141 throw ast::ScilabError(errorMsg);
3144 // return arguments [b, ier] = psol()
3145 types::Double* pDblOutB = out[0]->getAs<types::Double>();
3146 if (pDblOutB->getSize() != *neq) // size of b is neq
3148 char* pstrName = wide_string_to_UTF8(m_pCallPsolFunction->getName().c_str());
3149 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A matrix of size %d expected.\n"), pstrName, 1, *neq);
3151 throw ast::ScilabError(errorMsg);
3155 types::Double* pDblOutIer = out[1]->getAs<types::Double>();
3156 if (pDblOutIer->isScalar() == false)
3158 char* pstrName = wide_string_to_UTF8(m_pCallPsolFunction->getName().c_str());
3159 sprintf(errorMsg, _("%s: Wrong size for output argument #%d: A Scalar expected.\n"), pstrName, 2);
3161 throw ast::ScilabError(errorMsg);
3164 // copy output macro results in output variables
3165 C2F(dcopy)(neq, pDblOutB->get(), &one, b, &one);
3166 *ier = (int)(pDblOutIer->get(0));
3168 // free output arguments
3169 out[0]->DecreaseRef();
3170 if (out[0]->isDeletable())
3175 out[1]->DecreaseRef();
3176 if (out[1]->isDeletable())