2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Paul Bignier
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
21 #include "gw_scicos.hxx"
23 #include "internal.hxx"
25 #include "context.hxx"
27 #include "function.hxx"
34 #include "il_state.hxx"
39 #include "machine.h" /* C2F */
41 #include "sci_malloc.h"
42 #include "scicos.h" /* funnum2() */
43 #include "scicos-def.h"
44 #include "charEncoding.h"
46 #include "localization.h"
49 COSIM_struct C2F(cosim);
50 /*--------------------------------------------------------------------------*/
51 // Variables defined in scicos.c
52 extern COSERR_struct coserr;
53 extern CURBLK_struct C2F(curblk);
54 /*--------------------------------------------------------------------------*/
58 #define snprintf _snprintf
61 // anonymous namespace for helper functions
64 void delete_strings(char** l_sim_lab, int len)
66 for (int i = 0; i < len; i++)
76 /*--------------------------------------------------------------------------*/
77 /* intsicosimc scicosim interface routine.
79 * [state,t] = scicosim(state,tcur,tf,sim,str,tol)
82 * - 1 : state(1) : !xcs x z oz iz tevts evtspt pointi outtb !
83 * - 2 : state.x : column vector of real
84 * - 3 : state.z : column vector of real
85 * - 4 : state.oz : list of scilab object
86 * - 5 : state.iz : column vector of real (empty object with flag "finish")
87 * - 6 : state.tevts : column vector of real
88 * - 7 : state.evtspt : column vector of real
89 * - 8 : state.pointi : real scalar
90 * - 9 : state.outtb : list of scilab object
91 * rhs 2 tcur : real scalar
92 * rhs 3 tf : real scalar
94 * - 1 : sim(1) : !scs funs xptr zptr ozptr zcptr inpptr
95 * outptr inplnk outlnk rpar rpptr ipar ipptr
96 * opar opptr clkptr ordptr execlk ordclk cord
97 * oord zord critev nb ztyp nblk ndcblk
98 * subscr funtyp iord labels modptr uids !
99 * - 2 : sim.funs : list of strings and/or scilab function
100 * - 3 : sim.xptr : column vector of real
101 * - 4 : sim.zptr : column vector of real
102 * - 5 : sim.ozptr : column vector of real
103 * - 6 : sim.zcptr : column vector of real
104 * - 7 : sim.inpptr : column vector of real
105 * - 8 : sim.outptr : column vector of real
106 * - 9 : sim.inplnk : column vector of real
107 * - 10 : sim.outlnk : column vector of real
108 * - 11 : sim.rpar : column vector of real
109 * - 12 : sim.rpptr : column vector of real
110 * - 13 : sim.ipar : column vector of real
111 * - 14 : sim.ipptr : column vector of real
112 * - 15 : sim.opar : list of scilab object
113 * - 16 : sim.opptr : column vector of real
114 * - 17 : sim.clkptr : column vector of real
115 * - 18 : sim.ordptr : column vector of real
116 * - 19 : sim.execlk : matrix of real
117 * - 20 : sim.ordclk : matrix of real
118 * - 21 : sim.cord : matrix of real
119 * - 22 : sim.oord : matrix of real
120 * - 23 : sim.zord : column vector ? of real
121 * - 24 : sim.critev : column vector of real
122 * - 25 : sim.nb : real scalar
123 * - 26 : sim.ztyp : column vector of real
124 * - 27 : sim.nblk : real scalar
125 * - 28 : sim.ndcblk : real scalar
126 * - 29 : sim.subscr : column vector of real
127 * - 30 : sim.funtyp : column vector of real
128 * - 31 : sim.iord : column vector of real
129 * - 32 : sim.labels : column vector of strings
130 * - 33 : sim.modptr : column vector of real
131 * - 34 : sim.uids : column vector of strings
133 * rhs 5 str : string flag : 'start','run','finish','linear'
134 * rhs 6 tol : real vector of size (7,1) minimum (4,1)
135 * [atol rtol ttol [deltat realtimescale solver hmax]]'
137 * 16/03/06, A.Layec : Rewritten from original fortran
138 * source code intsscicos in intcos.f.
140 * 29/03/06, Alan : Improvement in accordance to c_pass2
141 * (int32 parameters).
143 * 31/05/06, Alan : Add global variable int *il_state_save
144 * and int *il_sim_save in intcscicos.h to store
145 * stack address of list %cpr.state and %cpr.sim
146 * (to use with get/setscicosvars).
148 * 14/06/06, Alan : Save common intersci before calling scicos
149 * (to disable scilab crash with scifunc.f).
151 * 13/11/06, Alan : Get back to double parameters for sim and state
152 * (for better compatibility with scilab-4.x families).
153 * Remove il_sim_save global variable.
155 * 15/12/06, Alan : Warnings compilation removed.
156 * This can crash scilab/scicos.
159 * xx/02/07, Alan : Add opar/odstate : scilab lists of arbitrary object
162 * 08/12/14, Paul : Rewrite to C++.
165 /*--------------------------------------------------------------------------*/
167 static const std::string funname = "scicosim";
169 types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount, types::typed_list &out)
171 /************************************
172 * Variables and constants definition
173 ************************************/
176 BOOL allocatedError = FALSE;
177 const int MAX_ERROR_LEN = 512;
181 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), funname.data(), 6);
182 return types::Function::Error;
187 Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), funname.data(), 1, 2);
188 return types::Function::Error;
194 if (in[0]->isTList() == false)
196 Scierror(999, _("%s: Wrong type for input argument #%d : A tlist expected.\n"), funname.data(), 1);
197 return types::Function::Error;
199 types::TList* il_state_input = in[0]->getAs<types::TList>();
200 types::TList* il_state = new types::TList();
202 if (il_state_input->getSize() < 9)
204 Scierror(999, _("%s: Wrong size for input argument #%d : %d elements expected.\n"), funname.data(), 1, 9);
205 il_state->DecreaseRef();
207 return types::Function::Error;
210 // Make a copy of 'il_state' in a global variabe
211 set_il_state(il_state_input);
213 types::String* header_state = il_state_input->get(0)->getAs<types::String>();
214 il_state->append(header_state->clone());
217 if (il_state_input->get(1)->isDouble() == false)
219 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 2, 1);
220 il_state->DecreaseRef();
222 return types::Function::Error;
224 types::Double* il_state_x_input = il_state_input->get(1)->getAs<types::Double>();
225 il_state->append(il_state_x_input->clone());
226 types::Double* il_state_x = il_state->get(1)->getAs<types::Double>();
227 double* l_state_x = il_state_x->get();
230 if (il_state_input->get(2)->isDouble() == false)
232 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 3, 1);
233 il_state->DecreaseRef();
235 return types::Function::Error;
237 types::Double* il_state_z_input = il_state_input->get(2)->getAs<types::Double>();
238 il_state->append(il_state_z_input->clone());
239 types::Double* il_state_z = il_state->get(2)->getAs<types::Double>();
240 double* l_state_z = il_state_z->get();
243 types::List* il_state_oz_input = il_state_input->get(3)->getAs<types::List>();
244 types::List* il_state_oz = new types::List();
245 for (int i = 0; i < il_state_oz_input->getSize(); ++i)
247 types::InternalType* l_state_oz_input = il_state_oz_input->get(i);
248 il_state_oz->append(l_state_oz_input->clone());
250 il_state->append(il_state_oz);
251 int noz = il_state_oz->getSize(); // 'nlnk' is the dimension of the list 'state.oz'
254 if (il_state_input->get(4)->isDouble() == false)
256 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 5, 1);
257 return types::Function::Error;
259 types::Double* il_state_iz_input = il_state_input->get(4)->getAs<types::Double>();
260 il_state->append(il_state_iz_input->clone());
261 types::Double* il_state_iz = il_state->get(4)->getAs<types::Double>();
262 void** l_state_iz = (void**) il_state_iz->get();
263 int m1e5 = il_state_iz->getRows();
266 if (il_state_input->get(5)->isDouble() == false)
268 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 6, 1);
269 il_state->DecreaseRef();
271 return types::Function::Error;
273 types::Double* il_state_tevts_input = il_state_input->get(5)->getAs<types::Double>();
274 il_state->append(il_state_tevts_input->clone());
275 types::Double* il_state_tevts = il_state->get(5)->getAs<types::Double>();
276 double* l_state_tevts = il_state_tevts->get();
277 int m1e6 = il_state_tevts->getRows();
279 /*7 : state.evtspt */
280 if (il_state_input->get(6)->isDouble() == false)
282 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 7, 1);
283 il_state->DecreaseRef();
285 return types::Function::Error;
287 types::Double* il_state_evtspt_input = il_state_input->get(6)->getAs<types::Double>();
288 il_state->append(il_state_evtspt_input->clone());
289 types::Double* il_state_evtspt = il_state->get(6)->getAs<types::Double>();
290 il_state_evtspt->convertToInteger();
291 int* l_state_evtspt = (int*) il_state_evtspt->get();
292 int m1e7 = il_state_evtspt->getRows();
294 /*8 : state.pointi */
295 if (il_state_input->get(7)->isDouble() == false)
297 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 8, 1);
298 il_state->DecreaseRef();
300 return types::Function::Error;
302 types::Double* il_pointi_input = il_state_input->get(7)->getAs<types::Double>();
303 il_state->append(il_pointi_input->clone());
304 types::Double* il_pointi = il_state->get(7)->getAs<types::Double>();
305 il_pointi->convertToInteger();
306 int* l_pointi = (int*) il_pointi->get();
309 if (il_state_input->get(8)->isList() == false)
311 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A list expected.\n"), funname.data(), 9, 1);
312 il_state->DecreaseRef();
314 return types::Function::Error;
316 types::List* il_state_outtb_input = il_state_input->get(8)->getAs<types::List>();
317 types::List* il_state_outtb = new types::List();
318 for (int i = 0; i < il_state_outtb_input->getSize(); ++i)
320 types::InternalType* l_state_outtb_input = il_state_outtb_input->get(i);
321 il_state_outtb->append(l_state_outtb_input->clone());
323 il_state->append(il_state_outtb);
324 int nlnk = il_state_outtb->getSize(); // 'nlnk' is the dimension of the list 'state.outtb'
329 if (in[1]->isDouble() == false)
331 Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), funname.data(), 2);
332 il_state->DecreaseRef();
334 return types::Function::Error;
336 types::Double* il_tcur_input = in[1]->getAs<types::Double>();
337 types::Double* il_tcur = il_tcur_input->clone()->getAs<types::Double>();
338 if (il_tcur->isScalar() == false)
340 Scierror(999, _("%s: Wrong size for input argument #%d : A scalar expected.\n"), funname.data(), 2);
341 il_state->DecreaseRef();
343 il_tcur->DecreaseRef();
345 return types::Function::Error;
347 double* l_tcur = il_tcur->get();
352 if (in[2]->isDouble() == false)
354 Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), funname.data(), 3);
355 il_state->DecreaseRef();
357 il_tcur->DecreaseRef();
359 return types::Function::Error;
361 types::Double* il_tf = in[2]->getAs<types::Double>();
362 if (il_tf->isScalar() == false)
364 Scierror(999, _("%s: Wrong size for input argument #%d : A scalar expected.\n"), funname.data(), 3);
365 il_state->DecreaseRef();
367 il_tcur->DecreaseRef();
369 return types::Function::Error;
371 double* l_tf = il_tf->get();
376 if (in[3]->isTList() == false)
378 Scierror(999, _("%s: Wrong type for input argument #%d : A tlist expected.\n"), funname.data(), 4);
379 il_state->DecreaseRef();
381 il_tcur->DecreaseRef();
383 return types::Function::Error;
385 types::TList* il_sim_input = in[3]->getAs<types::TList>();
386 types::TList* il_sim = new types::TList();
388 // Make a copy of 'il_sim' in a global variabe
389 set_il_sim(il_sim_input);
391 if (il_sim_input->getSize() < 34)
393 Scierror(999, _("%s: Wrong size for input argument #%d : %d elements expected.\n"), funname.data(), 4, 34);
394 il_state->DecreaseRef();
396 il_tcur->DecreaseRef();
398 il_sim->DecreaseRef();
400 return types::Function::Error;
403 types::String* header_sim = il_sim_input->get(0)->getAs<types::String>();
404 il_sim->append(header_sim->clone());
407 if (il_sim_input->get(1)->isList() == false)
409 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A list expected.\n"), funname.data(), 2, 4);
410 il_state->DecreaseRef();
412 il_tcur->DecreaseRef();
414 il_sim->DecreaseRef();
416 return types::Function::Error;
418 types::List* il_sim_fun_input = il_sim_input->get(1)->getAs<types::List>();
419 types::List* il_sim_fun = new types::List();
420 for (int i = 0; i < il_sim_fun_input->getSize(); ++i)
422 types::InternalType* l_sim_fun_input = il_sim_fun_input->get(i);
423 il_sim_fun->append(l_sim_fun_input->clone());
425 il_sim->append(il_sim_fun);
426 int nblk = il_sim_fun->getSize(); // 'nblk' is the dimension of the list 'sim.funs'
429 if (il_sim_input->get(2)->isDouble() == false)
431 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 3, 4);
432 il_state->DecreaseRef();
434 il_tcur->DecreaseRef();
436 il_sim->DecreaseRef();
438 return types::Function::Error;
440 types::Double* il_sim_xptr_input = il_sim_input->get(2)->getAs<types::Double>();
441 il_sim->append(il_sim_xptr_input->clone());
442 types::Double* il_sim_xptr = il_sim->get(2)->getAs<types::Double>();
443 il_sim_xptr->convertToInteger();
444 int* l_sim_xptr = (int*) il_sim_xptr->get();
445 int m_xptr = il_sim_xptr->getRows();
448 if (il_sim_input->get(3)->isDouble() == false)
450 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 4, 4);
451 il_state->DecreaseRef();
453 il_tcur->DecreaseRef();
455 il_sim->DecreaseRef();
457 return types::Function::Error;
459 types::Double* il_sim_zptr_input = il_sim_input->get(3)->getAs<types::Double>();
460 il_sim->append(il_sim_zptr_input->clone());
461 types::Double* il_sim_zptr = il_sim->get(3)->getAs<types::Double>();
462 il_sim_zptr->convertToInteger();
463 int* l_sim_zptr = (int*) il_sim_zptr->get();
464 int m_zptr = il_sim_zptr->getRows();
467 if (il_sim_input->get(4)->isDouble() == false)
469 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 5, 4);
470 il_state->DecreaseRef();
472 il_tcur->DecreaseRef();
474 il_sim->DecreaseRef();
476 return types::Function::Error;
478 types::Double* il_sim_ozptr_input = il_sim_input->get(4)->getAs<types::Double>();
479 il_sim->append(il_sim_ozptr_input->clone());
480 types::Double* il_sim_ozptr = il_sim->get(4)->getAs<types::Double>();
481 il_sim_ozptr->convertToInteger();
482 int* l_sim_ozptr = (int*) il_sim_ozptr->get();
483 int m_ozptr = il_sim_ozptr->getRows();
486 if (il_sim_input->get(5)->isDouble() == false)
488 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 6, 4);
489 il_state->DecreaseRef();
491 il_tcur->DecreaseRef();
493 il_sim->DecreaseRef();
495 return types::Function::Error;
497 types::Double* il_sim_zcptr_input = il_sim_input->get(5)->getAs<types::Double>();
498 il_sim->append(il_sim_zcptr_input->clone());
499 types::Double* il_sim_zcptr = il_sim->get(5)->getAs<types::Double>();
500 il_sim_zcptr->convertToInteger();
501 int* l_sim_zcptr = (int*) il_sim_zcptr->get();
502 int m_zcptr = il_sim_zcptr->getRows();
505 if (il_sim_input->get(6)->isDouble() == false)
507 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 7, 4);
508 il_state->DecreaseRef();
510 il_tcur->DecreaseRef();
512 il_sim->DecreaseRef();
514 return types::Function::Error;
516 types::Double* il_sim_inpptr_input = il_sim_input->get(6)->getAs<types::Double>();
517 il_sim->append(il_sim_inpptr_input->clone());
518 types::Double* il_sim_inpptr = il_sim->get(6)->getAs<types::Double>();
519 il_sim_inpptr->convertToInteger();
520 int* l_sim_inpptr = (int*) il_sim_inpptr->get();
521 int m_inpptr = il_sim_inpptr->getRows();
524 if (il_sim_input->get(7)->isDouble() == false)
526 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 8, 4);
527 il_state->DecreaseRef();
529 il_tcur->DecreaseRef();
531 il_sim->DecreaseRef();
533 return types::Function::Error;
535 types::Double* il_sim_outpptr_input = il_sim_input->get(7)->getAs<types::Double>();
536 il_sim->append(il_sim_outpptr_input->clone());
537 types::Double* il_sim_outptr = il_sim->get(7)->getAs<types::Double>();
538 il_sim_outptr->convertToInteger();
539 int* l_sim_outptr = (int*) il_sim_outptr->get();
540 int m_outptr = il_sim_outptr->getRows();
543 if (il_sim_input->get(8)->isDouble() == false)
545 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 9, 4);
546 il_state->DecreaseRef();
548 il_tcur->DecreaseRef();
550 il_sim->DecreaseRef();
552 return types::Function::Error;
554 types::Double* il_sim_inplnk_input = il_sim_input->get(8)->getAs<types::Double>();
555 il_sim->append(il_sim_inplnk_input->clone());
556 types::Double* il_sim_inplnk = il_sim->get(8)->getAs<types::Double>();
557 il_sim_inplnk->convertToInteger();
558 int* l_sim_inplnk = (int*) il_sim_inplnk->get();
561 if (il_sim_input->get(9)->isDouble() == false)
563 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 10, 4);
564 il_state->DecreaseRef();
566 il_tcur->DecreaseRef();
568 il_sim->DecreaseRef();
570 return types::Function::Error;
572 types::Double* il_sim_outlnk_input = il_sim_input->get(9)->getAs<types::Double>();
573 il_sim->append(il_sim_outlnk_input->clone());
574 types::Double* il_sim_outlnk = il_sim->get(9)->getAs<types::Double>();
575 il_sim_outlnk->convertToInteger();
576 int* l_sim_outlnk = (int*) il_sim_outlnk->get();
579 if (il_sim_input->get(10)->isDouble() == false)
581 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 11, 4);
582 il_state->DecreaseRef();
584 il_tcur->DecreaseRef();
586 il_sim->DecreaseRef();
588 return types::Function::Error;
590 types::Double* il_sim_rpar_input = il_sim_input->get(10)->getAs<types::Double>();
591 il_sim->append(il_sim_rpar_input->clone());
592 types::Double* il_sim_rpar = il_sim->get(10)->getAs<types::Double>();
593 double* l_sim_rpar = il_sim_rpar->get();
596 if (il_sim_input->get(11)->isDouble() == false)
598 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 12, 4);
599 il_state->DecreaseRef();
601 il_tcur->DecreaseRef();
603 il_sim->DecreaseRef();
605 return types::Function::Error;
607 types::Double* il_sim_rpptr_input = il_sim_input->get(11)->getAs<types::Double>();
608 il_sim->append(il_sim_rpptr_input->clone());
609 types::Double* il_sim_rpptr = il_sim->get(11)->getAs<types::Double>();
610 il_sim_rpptr->convertToInteger();
611 int* l_sim_rpptr = (int*) il_sim_rpptr->get();
612 int m_rpptr = il_sim_rpptr->getRows();
615 if (il_sim_input->get(12)->isDouble() == false)
617 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 13, 4);
618 il_state->DecreaseRef();
620 il_tcur->DecreaseRef();
622 il_sim->DecreaseRef();
624 return types::Function::Error;
626 types::Double* il_sim_ipar_input = il_sim_input->get(12)->getAs<types::Double>();
627 il_sim->append(il_sim_ipar_input->clone());
628 types::Double* il_sim_ipar = il_sim->get(12)->getAs<types::Double>();
629 il_sim_ipar->convertToInteger();
630 int* l_sim_ipar = (int*) il_sim_ipar->get();
633 if (il_sim_input->get(13)->isDouble() == false)
635 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 14, 4);
636 il_state->DecreaseRef();
638 il_tcur->DecreaseRef();
640 il_sim->DecreaseRef();
642 return types::Function::Error;
644 types::Double* il_sim_ipptr_input = il_sim_input->get(13)->getAs<types::Double>();
645 il_sim->append(il_sim_ipptr_input->clone());
646 types::Double* il_sim_ipptr = il_sim->get(13)->getAs<types::Double>();
647 il_sim_ipptr->convertToInteger();
648 int* l_sim_ipptr = (int*) il_sim_ipptr->get();
649 int m_ipptr = il_sim_ipptr->getRows();
652 if (il_sim_input->get(14)->isList() == false)
654 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A list expected.\n"), funname.data(), 15, 4);
655 il_state->DecreaseRef();
657 il_tcur->DecreaseRef();
659 il_sim->DecreaseRef();
661 return types::Function::Error;
663 types::List* il_sim_opar_input = il_sim_input->get(14)->getAs<types::List>();
664 types::List* il_sim_opar = new types::List();
665 for (int i = 0; i < il_sim_opar_input->getSize(); ++i)
667 types::InternalType* l_sim_opar_input = il_sim_opar_input->get(i);
668 il_sim_opar->append(l_sim_opar_input->clone());
670 il_sim->append(il_sim_opar);
671 int nopar = il_sim_opar->getSize(); // 'nopar' is the dimension of the list 'sim.opar'
674 if (il_sim_input->get(15)->isDouble() == false)
676 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 16, 4);
677 il_state->DecreaseRef();
679 il_tcur->DecreaseRef();
681 il_sim->DecreaseRef();
683 return types::Function::Error;
685 types::Double* il_sim_opptr_input = il_sim_input->get(15)->getAs<types::Double>();
686 il_sim->append(il_sim_opptr_input->clone());
687 types::Double* il_sim_opptr = il_sim->get(15)->getAs<types::Double>();
688 il_sim_opptr->convertToInteger();
689 int* l_sim_opptr = (int*) il_sim_opptr->get();
690 int m_opptr = il_sim_opptr->getRows();
693 if (il_sim_input->get(16)->isDouble() == false)
695 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 17, 4);
696 il_state->DecreaseRef();
698 il_tcur->DecreaseRef();
700 il_sim->DecreaseRef();
702 return types::Function::Error;
704 types::Double* il_sim_clkptr_input = il_sim_input->get(16)->getAs<types::Double>();
705 il_sim->append(il_sim_clkptr_input->clone());
706 types::Double* il_sim_clkptr = il_sim->get(16)->getAs<types::Double>();
707 il_sim_clkptr->convertToInteger();
708 int* l_sim_clkptr = (int*) il_sim_clkptr->get();
709 int m_clkptr = il_sim_clkptr->getRows();
712 if (il_sim_input->get(17)->isDouble() == false)
714 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 18, 4);
715 il_state->DecreaseRef();
717 il_tcur->DecreaseRef();
719 il_sim->DecreaseRef();
721 return types::Function::Error;
723 types::Double* il_sim_ordptr_input = il_sim_input->get(17)->getAs<types::Double>();
724 il_sim->append(il_sim_ordptr_input->clone());
725 types::Double* il_sim_ordptr = il_sim->get(17)->getAs<types::Double>();
726 il_sim_ordptr->convertToInteger();
727 int* l_sim_ordptr = (int*) il_sim_ordptr->get();
728 int m_ordptr = il_sim_ordptr->getRows();
731 if (il_sim_input->get(18)->isDouble() == false)
733 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 19, 4);
734 il_state->DecreaseRef();
736 il_tcur->DecreaseRef();
738 il_sim->DecreaseRef();
740 return types::Function::Error;
742 types::Double* il_sim_execlk_input = il_sim_input->get(18)->getAs<types::Double>();
743 il_sim->append(il_sim_execlk_input->clone());
746 if (il_sim_input->get(19)->isDouble() == false)
748 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 20, 4);
749 il_state->DecreaseRef();
751 il_tcur->DecreaseRef();
753 il_sim->DecreaseRef();
755 return types::Function::Error;
757 types::Double* il_sim_ordclk_input = il_sim_input->get(19)->getAs<types::Double>();
758 il_sim->append(il_sim_ordclk_input->clone());
759 types::Double* il_sim_ordclk = il_sim->get(19)->getAs<types::Double>();
760 il_sim_ordclk->convertToInteger();
761 int* l_sim_ordclk = (int*) il_sim_ordclk->get();
762 int m_ordclk = il_sim_ordclk->getRows();
763 int n_ordclk = il_sim_ordclk->getCols();
766 if (il_sim_input->get(20)->isDouble() == false)
768 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 21, 4);
769 il_state->DecreaseRef();
771 il_tcur->DecreaseRef();
773 il_sim->DecreaseRef();
775 return types::Function::Error;
777 types::Double* il_sim_cord_input = il_sim_input->get(20)->getAs<types::Double>();
778 il_sim->append(il_sim_cord_input->clone());
779 types::Double* il_sim_cord = il_sim->get(20)->getAs<types::Double>();
780 il_sim_cord->convertToInteger();
781 int* l_sim_cord = (int*) il_sim_cord->get();
782 int m_cord = il_sim_cord->getRows();
783 int n_cord = il_sim_cord->getCols();
786 if (il_sim_input->get(21)->isDouble() == false)
788 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 22, 4);
789 il_state->DecreaseRef();
791 il_tcur->DecreaseRef();
793 il_sim->DecreaseRef();
795 return types::Function::Error;
797 types::Double* il_sim_oord_input = il_sim_input->get(21)->getAs<types::Double>();
798 il_sim->append(il_sim_oord_input->clone());
799 types::Double* il_sim_oord = il_sim->get(21)->getAs<types::Double>();
800 il_sim_oord->convertToInteger();
801 int* l_sim_oord = (int*) il_sim_oord->get();
802 int m_oord = il_sim_oord->getRows();
803 int n_oord = il_sim_oord->getCols();
806 if (il_sim_input->get(22)->isDouble() == false)
808 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 23, 4);
809 il_state->DecreaseRef();
811 il_tcur->DecreaseRef();
813 il_sim->DecreaseRef();
815 return types::Function::Error;
817 types::Double* il_sim_zord_input = il_sim_input->get(22)->getAs<types::Double>();
818 il_sim->append(il_sim_zord_input->clone());
819 types::Double* il_sim_zord = il_sim->get(22)->getAs<types::Double>();
820 il_sim_zord->convertToInteger();
821 int* l_sim_zord = (int*) il_sim_zord->get();
822 int m_zord = il_sim_zord->getRows();
823 int n_zord = il_sim_zord->getCols();
826 if (il_sim_input->get(23)->isDouble() == false)
828 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 24, 4);
829 il_state->DecreaseRef();
831 il_tcur->DecreaseRef();
833 il_sim->DecreaseRef();
835 return types::Function::Error;
837 types::Double* il_sim_critev_input = il_sim_input->get(23)->getAs<types::Double>();
838 il_sim->append(il_sim_critev_input->clone());
839 types::Double* il_sim_critev = il_sim->get(23)->getAs<types::Double>();
840 il_sim_critev->convertToInteger();
841 int* l_sim_critev = (int*) il_sim_critev->get();
844 if (il_sim_input->get(24)->isDouble() == false)
846 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 25, 4);
847 il_state->DecreaseRef();
849 il_tcur->DecreaseRef();
851 il_sim->DecreaseRef();
853 return types::Function::Error;
855 types::Double* il_sim_nb_input = il_sim_input->get(24)->getAs<types::Double>();
856 il_sim->append(il_sim_nb_input->clone());
857 types::Double* il_sim_nb = il_sim->get(24)->getAs<types::Double>();
858 double* l_sim_nb = il_sim_nb->get();
860 if (static_cast<int>(l_sim_nb[0]) != nblk) // Value of 'nb' must be equal to 'nblk'
862 Scierror(42, _("%s : Incompatible sim.nb RHS parameter.\n"), funname.data());
863 il_state->DecreaseRef();
865 il_tcur->DecreaseRef();
867 il_sim->DecreaseRef();
869 return types::Function::Error;
873 if (il_sim_input->get(25)->isDouble() == false)
875 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 26, 4);
876 il_state->DecreaseRef();
878 il_tcur->DecreaseRef();
880 il_sim->DecreaseRef();
882 return types::Function::Error;
884 types::Double* il_sim_ztyp_input = il_sim_input->get(25)->getAs<types::Double>();
885 il_sim->append(il_sim_ztyp_input->clone());
886 types::Double* il_sim_ztyp = il_sim->get(25)->getAs<types::Double>();
887 il_sim_ztyp->convertToInteger();
888 int* l_sim_ztyp = (int*) il_sim_ztyp->get();
891 if (il_sim_input->get(26)->isDouble() == false)
893 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 27, 4);
894 il_state->DecreaseRef();
896 il_tcur->DecreaseRef();
898 il_sim->DecreaseRef();
900 return types::Function::Error;
902 types::Double* il_sim_nblk_input = il_sim_input->get(26)->getAs<types::Double>();
903 il_sim->append(il_sim_nblk_input->clone());
906 if (il_sim_input->get(27)->isDouble() == false)
908 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 28, 4);
909 il_state->DecreaseRef();
911 il_tcur->DecreaseRef();
913 il_sim->DecreaseRef();
915 return types::Function::Error;
917 types::Double* il_sim_ndcblk_input = il_sim_input->get(27)->getAs<types::Double>();
918 il_sim->append(il_sim_ndcblk_input->clone());
921 if (il_sim_input->get(28)->isDouble() == false)
923 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 29, 4);
924 il_state->DecreaseRef();
926 il_tcur->DecreaseRef();
928 il_sim->DecreaseRef();
930 return types::Function::Error;
932 types::Double* il_sim_subscr_input = il_sim_input->get(28)->getAs<types::Double>();
933 il_sim->append(il_sim_subscr_input->clone());
934 types::Double* il_sim_subscr = il_sim->get(28)->getAs<types::Double>();
935 il_sim_subscr->convertToInteger();
936 int* l_sim_subscr = (int*) il_sim_subscr->get();
937 int m_subscr = il_sim_subscr->getRows();
940 if (il_sim_input->get(29)->isDouble() == false)
942 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 30, 4);
943 il_state->DecreaseRef();
945 il_tcur->DecreaseRef();
947 il_sim->DecreaseRef();
949 return types::Function::Error;
951 types::Double* il_sim_funtyp_input = il_sim_input->get(29)->getAs<types::Double>();
952 il_sim->append(il_sim_funtyp_input->clone());
953 types::Double* il_sim_funtyp = il_sim->get(29)->getAs<types::Double>();
954 il_sim_funtyp->convertToInteger();
955 int* l_sim_funtyp = (int*) il_sim_funtyp->get();
958 if (il_sim_input->get(30)->isDouble() == false)
960 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 31, 4);
961 il_state->DecreaseRef();
963 il_tcur->DecreaseRef();
965 il_sim->DecreaseRef();
967 return types::Function::Error;
969 types::Double* il_sim_iord_input = il_sim_input->get(30)->getAs<types::Double>();
970 il_sim->append(il_sim_iord_input->clone());
971 types::Double* il_sim_iord = il_sim->get(30)->getAs<types::Double>();
972 il_sim_iord->convertToInteger();
973 int* l_sim_iord = (int*) il_sim_iord->get();
974 int m_iord = il_sim_iord->getRows();
975 int n_iord = il_sim_iord->getCols();
978 if (il_sim_input->get(31)->isString() == false)
980 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A string matrix expected.\n"), funname.data(), 32, 4);
981 il_state->DecreaseRef();
983 il_tcur->DecreaseRef();
985 il_sim->DecreaseRef();
987 return types::Function::Error;
989 types::String* il_sim_lab_input = il_sim_input->get(31)->getAs<types::String>();
990 il_sim->append(il_sim_lab_input->clone());
991 types::String* il_sim_lab = il_sim->get(31)->getAs<types::String>();
995 il_sim_labptr = new int[il_sim_lab->getSize()];
997 catch (const std::bad_alloc& /*e*/)
999 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1000 il_state->DecreaseRef();
1002 il_tcur->DecreaseRef();
1004 il_sim->DecreaseRef();
1006 return types::Function::Error;
1011 l_sim_lab = new char*[il_sim_lab->getSize()];
1013 catch (const std::bad_alloc& /*e*/)
1015 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1016 il_state->DecreaseRef();
1018 il_tcur->DecreaseRef();
1020 delete[] il_sim_labptr;
1021 il_sim->DecreaseRef();
1023 return types::Function::Error;
1025 for (int i = 0; i < il_sim_lab->getSize(); ++i)
1027 l_sim_lab[i] = wide_string_to_UTF8(il_sim_lab->get(i));
1028 il_sim_labptr[i] = static_cast<int>(strlen(l_sim_lab[i]));
1031 /*33 : sim.modptr */
1032 if (il_sim_input->get(32)->isDouble() == false)
1034 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A matrix expected.\n"), funname.data(), 33, 4);
1035 il_state->DecreaseRef();
1037 il_tcur->DecreaseRef();
1039 delete[] il_sim_labptr;
1040 delete_strings(l_sim_lab, il_sim_lab->getSize());
1041 il_sim->DecreaseRef();
1043 return types::Function::Error;
1045 types::Double* il_sim_modptr_input = il_sim_input->get(32)->getAs<types::Double>();
1046 il_sim->append(il_sim_modptr_input->clone());
1047 types::Double* il_sim_modptr = il_sim->get(32)->getAs<types::Double>();
1048 il_sim_modptr->convertToInteger();
1049 int* l_sim_modptr = (int*) il_sim_modptr->get();
1052 if (il_sim_input->get(33)->isString() == false)
1054 Scierror(999, _("%s: Wrong type for element #%d of argument #%d : A string matrix expected.\n"), funname.data(), 34, 4);
1055 il_state->DecreaseRef();
1057 il_tcur->DecreaseRef();
1059 delete[] il_sim_labptr;
1060 delete_strings(l_sim_lab, il_sim_lab->getSize());
1061 il_sim->DecreaseRef();
1063 return types::Function::Error;
1065 types::String* il_sim_uid_input = il_sim_input->get(33)->getAs<types::String>();
1066 il_sim->append(il_sim_uid_input->clone());
1067 types::String* il_sim_uid = il_sim->get(33)->getAs<types::String>();
1071 il_sim_uidptr = new int[il_sim_uid->getSize()];
1073 catch (const std::bad_alloc& /*e*/)
1075 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1076 il_state->DecreaseRef();
1078 il_tcur->DecreaseRef();
1080 delete[] il_sim_labptr;
1081 delete_strings(l_sim_lab, il_sim_lab->getSize());
1082 il_sim->DecreaseRef();
1084 return types::Function::Error;
1089 l_sim_uid = new char*[il_sim_uid->getSize()];
1091 catch (const std::bad_alloc& /*e*/)
1093 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1094 il_state->DecreaseRef();
1096 il_tcur->DecreaseRef();
1098 delete[] il_sim_labptr;
1099 delete_strings(l_sim_lab, il_sim_lab->getSize());
1100 delete[] il_sim_uidptr;
1101 il_sim->DecreaseRef();
1103 return types::Function::Error;
1105 for (int i = 0; i < il_sim_uid->getSize(); ++i)
1107 l_sim_uid[i] = wide_string_to_UTF8(il_sim_uid->get(i));
1108 il_sim_uidptr[i] = static_cast<int>(strlen(l_sim_uid[i]));
1114 if (in[4]->isString() == false)
1116 Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), funname.data(), 5);
1117 il_state->DecreaseRef();
1119 il_tcur->DecreaseRef();
1121 delete[] il_sim_labptr;
1122 delete_strings(l_sim_lab, il_sim_lab->getSize());
1123 delete[] il_sim_uidptr;
1124 delete_strings(l_sim_uid, il_sim_uid->getSize());
1125 il_sim->DecreaseRef();
1127 return types::Function::Error;
1129 types::String* il_str = in[4]->getAs<types::String>();
1130 if (il_str->isScalar() == false)
1132 Scierror(999, _("%s: Wrong size for input argument #%d : A scalar expected.\n"), funname.data(), 5);
1133 il_state->DecreaseRef();
1135 il_tcur->DecreaseRef();
1137 delete[] il_sim_labptr;
1138 delete_strings(l_sim_lab, il_sim_lab->getSize());
1139 delete[] il_sim_uidptr;
1140 delete_strings(l_sim_uid, il_sim_uid->getSize());
1141 il_sim->DecreaseRef();
1143 return types::Function::Error;
1146 const std::wstring start (L"start");
1147 const std::wstring run (L"run");
1148 const std::wstring finish (L"finish");
1149 const std::wstring linear (L"linear");
1150 const std::wstring Kinsol (L"Kinsol");
1152 if (il_str->get(0) == start)
1156 else if (il_str->get(0) == run)
1160 else if (il_str->get(0) == finish)
1164 else if (il_str->get(0) == linear)
1168 else if (il_str->get(0) == Kinsol)
1174 Scierror(44, _("%s: Wrong value for input argument #%d : ""%s"", ""%s"" ""%s"" ""%s"" or ""%s"" expected.\n"), funname.data(), 5,
1175 "start", "run", "finish", "linear", "Kinsol");
1176 il_state->DecreaseRef();
1178 il_tcur->DecreaseRef();
1180 delete[] il_sim_labptr;
1181 delete_strings(l_sim_lab, il_sim_lab->getSize());
1182 delete[] il_sim_uidptr;
1183 delete_strings(l_sim_uid, il_sim_uid->getSize());
1184 il_sim->DecreaseRef();
1186 return types::Function::Error;
1192 if (in[5]->isDouble() == false)
1194 Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), funname.data(), 6);
1195 il_state->DecreaseRef();
1197 il_tcur->DecreaseRef();
1199 delete[] il_sim_labptr;
1200 delete_strings(l_sim_lab, il_sim_lab->getSize());
1201 delete[] il_sim_uidptr;
1202 delete_strings(l_sim_uid, il_sim_uid->getSize());
1203 il_sim->DecreaseRef();
1205 return types::Function::Error;
1207 types::Double* il_tol = in[5]->getAs<types::Double>();
1208 int m6 = il_tol->getSize();
1209 if (m6 < 4 || m6 > 7) // Check if 'tol' has 4 to 7 elements
1211 Scierror(999, _("%s: Wrong size for input argument #%d : %d to %d elements expected.\n"), funname.data(), 6, 4, 7);
1212 il_state->DecreaseRef();
1214 il_tcur->DecreaseRef();
1216 delete[] il_sim_labptr;
1217 delete_strings(l_sim_lab, il_sim_lab->getSize());
1218 delete[] il_sim_uidptr;
1219 delete_strings(l_sim_uid, il_sim_uid->getSize());
1220 il_sim->DecreaseRef();
1222 return types::Function::Error;
1226 * Set 'simpar' array
1228 for (int i = 0; i < m6; ++i)
1230 simpar[i] = il_tol->get(i);
1232 for (int i = m6; i < 7; ++i)
1237 /******************************
1238 * Cross variable size checking
1239 ******************************/
1243 err_check = 1; // tevts vs evtspt
1245 else if (m_xptr != m_zptr)
1247 err_check = 2; // xptr vs zptr
1249 else if (m_xptr != m_ozptr)
1251 err_check = 3; // xptr vs ozptr
1253 else if (m_xptr != m_zcptr)
1255 err_check = 4; // xptr vs zcptr
1257 else if (m_xptr != m_inpptr)
1259 err_check = 5; // xptr vs inpptr
1261 else if (m_xptr != m_outptr)
1263 err_check = 6; // xptr vs outptr
1265 else if (m_xptr != m_rpptr)
1267 err_check = 7; // xptr vs rpptr
1269 else if (m_xptr != m_ipptr)
1271 err_check = 8; // xptr vs ipptr
1273 else if (m_xptr != m_opptr)
1275 err_check = 8; // xptr vs opptr
1277 else if (m_xptr != m_clkptr)
1279 err_check = 10; // xptr vs clkptr
1281 else if ((n_ordclk != 2) & (m_ordclk != 0))
1283 err_check = 11; // sim.ordclk
1285 else if ((n_cord != 2) & (m_cord != 0))
1287 err_check = 12; // sim.cord
1289 else if ((n_oord != 2) & (m_oord != 0))
1291 err_check = 13; // sim.oord
1293 else if ((n_zord != 2) & (m_zord != 0))
1295 err_check = 14; // sim.zord
1297 else if ((n_iord != 2) & (m_iord != 0))
1299 err_check = 15; // sim.iord
1303 // Please write an error table here
1304 Scierror(42, _("%s : error in cross variable size checking : %d\n"), funname.data(), err_check);
1305 il_state->DecreaseRef();
1307 il_tcur->DecreaseRef();
1309 delete[] il_sim_labptr;
1310 delete_strings(l_sim_lab, il_sim_lab->getSize());
1311 delete[] il_sim_uidptr;
1312 delete_strings(l_sim_uid, il_sim_uid->getSize());
1313 il_sim->DecreaseRef();
1315 return types::Function::Error;
1318 /*******************************
1319 * Set function table for blocks
1320 *******************************/
1321 // Define new variable 'lfunpt'
1325 lfunpt = new void*[nblk];
1327 catch (const std::bad_alloc& /*e*/)
1329 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1330 il_state->DecreaseRef();
1332 il_tcur->DecreaseRef();
1334 delete[] il_sim_labptr;
1335 delete_strings(l_sim_lab, il_sim_lab->getSize());
1336 delete[] il_sim_uidptr;
1337 delete_strings(l_sim_uid, il_sim_uid->getSize());
1338 il_sim->DecreaseRef();
1340 return types::Function::Error;
1344 for (int i = 0; i < nblk; ++i) // For each block
1346 types::InternalType* pIT = il_sim_fun->get(i);
1347 // Block is defined by a Scilab function
1348 if (pIT->isCallable())
1350 lfunpt[i] = (void*)pIT;
1351 // Keep 'l_sim_funtyp' negative for Scilab macros
1352 if (l_sim_funtyp[i] > 0)
1354 l_sim_funtyp[i] *= -1;
1357 // Block is defined by a function described by a string
1358 else if (pIT->isString())
1360 types::String* funStr = pIT->getAs<types::String>();
1361 if (funStr->isScalar() == false)
1363 Scierror(999, _("%s: Wrong size for element #%d of input argument #%d : A scalar expected.\n"), funname.data(), i + 1, 4);
1364 il_state->DecreaseRef();
1366 il_tcur->DecreaseRef();
1368 delete[] il_sim_labptr;
1369 delete_strings(l_sim_lab, il_sim_lab->getSize());
1370 delete[] il_sim_uidptr;
1371 delete_strings(l_sim_uid, il_sim_uid->getSize());
1373 il_sim->DecreaseRef();
1375 return types::Function::Error;
1378 wchar_t* w_str = funStr->get(0);
1379 char* c_str = wide_string_to_UTF8(w_str);
1380 if (strcmp(c_str, "ifthel") == 0)
1382 l_sim_funtyp[i] = 11; // Magic value for "if-then-else" block
1384 else if (strcmp(c_str, "eselect") == 0)
1386 l_sim_funtyp[i] = 12; // Magic value for "eselect" block
1390 void *f = funnum2(c_str); // Search associated function number of function name
1391 // Block is defined by a C or Fortran function
1394 // C interface from "tabsim" defined in blocks.h
1396 if (l_sim_funtyp[i] < 0)
1398 // Keep 'l_sim_funtyp' positive for Fortran functions
1399 l_sim_funtyp[i] *= -1;
1402 // Block is defined by a predefined scilab function
1405 ConfigVariable::EntryPointStr* pEP = ConfigVariable::getEntryPoint(w_str);
1409 lfunpt[i] = (void*)pEP->functionPtr;
1413 types::InternalType* pMacro = symbol::Context::getInstance()->get(symbol::Symbol(w_str));
1414 if (pMacro && pMacro->isCallable())
1417 lfunpt[i] = (void*)pMacro;
1418 l_sim_funtyp[i] *= -1;
1422 Scierror(888, _("%s : unknown block : %s\n"), funname.data(), c_str);
1423 il_state->DecreaseRef();
1425 il_tcur->DecreaseRef();
1427 delete[] il_sim_labptr;
1428 delete_strings(l_sim_lab, il_sim_lab->getSize());
1429 delete[] il_sim_uidptr;
1430 delete_strings(l_sim_uid, il_sim_uid->getSize());
1433 il_sim->DecreaseRef();
1435 return types::Function::Error;
1444 Scierror(999, _("%s: Wrong type for element #%d of input argument #%d : string or macro expected.\n"), funname.data(), i + 1, 4);
1445 il_state->DecreaseRef();
1447 il_tcur->DecreaseRef();
1449 delete[] il_sim_labptr;
1450 delete_strings(l_sim_lab, il_sim_lab->getSize());
1451 delete[] il_sim_uidptr;
1452 delete_strings(l_sim_uid, il_sim_uid->getSize());
1454 il_sim->DecreaseRef();
1456 return types::Function::Error;
1460 /**********************
1461 * Set oz, ozsz, oztyp
1462 **********************/
1463 void** oz = nullptr;
1464 int* ozsz = nullptr;
1465 int* oztyp = nullptr;
1468 // Allocation of 'oz'
1471 oz = new void*[noz];
1473 catch (const std::bad_alloc& /*e*/)
1475 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1476 il_state->DecreaseRef();
1478 il_tcur->DecreaseRef();
1480 delete[] il_sim_labptr;
1481 delete_strings(l_sim_lab, il_sim_lab->getSize());
1482 delete[] il_sim_uidptr;
1483 delete_strings(l_sim_uid, il_sim_uid->getSize());
1485 il_sim->DecreaseRef();
1487 return types::Function::Error;
1489 // Allocation of 'ozsz'
1492 ozsz = new int[2 * noz];
1494 catch (const std::bad_alloc& /*e*/)
1496 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1497 il_state->DecreaseRef();
1499 il_tcur->DecreaseRef();
1501 delete[] il_sim_labptr;
1502 delete_strings(l_sim_lab, il_sim_lab->getSize());
1503 delete[] il_sim_uidptr;
1504 delete_strings(l_sim_uid, il_sim_uid->getSize());
1507 il_sim->DecreaseRef();
1509 return types::Function::Error;
1511 // Allocation of 'oztyp'
1514 oztyp = new int[noz];
1516 catch (const std::bad_alloc& /*e*/)
1518 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1519 il_state->DecreaseRef();
1521 il_tcur->DecreaseRef();
1523 delete[] il_sim_labptr;
1524 delete_strings(l_sim_lab, il_sim_lab->getSize());
1525 delete[] il_sim_uidptr;
1526 delete_strings(l_sim_uid, il_sim_uid->getSize());
1530 il_sim->DecreaseRef();
1532 return types::Function::Error;
1535 // Set vectors of 'oz'
1536 for (int j = 0; j < noz; ++j)
1538 int subtype = il_state_oz->get(j)->getType();
1540 switch (subtype) // Store type and address
1542 case types::InternalType::ScilabDouble :
1544 types::Double* ozDouble = il_state_oz->get(j)->getAs<types::Double>();
1545 if (ozDouble->isComplex() == false)
1547 oztyp[j] = SCSREAL_N; // Double real matrix
1548 oz[j] = (SCSREAL_COP *) ozDouble->get();
1552 oztyp[j] = SCSCOMPLEX_N; // Double complex matrix
1553 oz[j] = (SCSCOMPLEX_COP *) ozDouble->get();
1555 ozsz[j] = ozDouble->getRows();
1556 ozsz[j + noz] = ozDouble->getCols();
1559 case types::InternalType::ScilabInt8 :
1561 types::Int8* ozInt8 = il_state_oz->get(j)->getAs<types::Int8>();
1562 oztyp[j] = SCSINT8_N; // int8
1563 ozsz[j] = ozInt8->getRows();
1564 ozsz[j + noz] = ozInt8->getCols();
1565 oz[j] = (SCSINT8_COP *) ozInt8->get();
1568 case types::InternalType::ScilabInt16 :
1570 types::Int16* ozInt16 = il_state_oz->get(j)->getAs<types::Int16>();
1571 oztyp[j] = SCSINT16_N; // int16
1572 ozsz[j] = ozInt16->getRows();
1573 ozsz[j + noz] = ozInt16->getCols();
1574 oz[j] = (SCSINT16_COP *) ozInt16->get();
1577 case types::InternalType::ScilabInt32 :
1579 types::Int32* ozInt32 = il_state_oz->get(j)->getAs<types::Int32>();
1580 oztyp[j] = SCSINT32_N; // int32
1581 ozsz[j] = ozInt32->getRows();
1582 ozsz[j + noz] = ozInt32->getCols();
1583 oz[j] = (SCSINT32_COP *) ozInt32->get();
1586 case types::InternalType::ScilabUInt8 :
1588 types::UInt8* ozUInt8 = il_state_oz->get(j)->getAs<types::UInt8>();
1589 oztyp[j] = SCSUINT8_N; // uint8
1590 ozsz[j] = ozUInt8->getRows();
1591 ozsz[j + noz] = ozUInt8->getCols();
1592 oz[j] = (SCSUINT8_COP *) ozUInt8->get();
1595 case types::InternalType::ScilabUInt16 :
1597 types::UInt16* ozUInt16 = il_state_oz->get(j)->getAs<types::UInt16>();
1598 oztyp[j] = SCSUINT16_N; // uint16
1599 ozsz[j] = ozUInt16->getRows();
1600 ozsz[j + noz] = ozUInt16->getCols();
1601 oz[j] = (SCSUINT16_COP *) ozUInt16->get();
1604 case types::InternalType::ScilabUInt32 :
1606 types::UInt32* ozUInt32 = il_state_oz->get(j)->getAs<types::UInt32>();
1607 oztyp[j] = SCSUINT32_N; // uint32
1608 ozsz[j] = ozUInt32->getRows();
1609 ozsz[j + noz] = ozUInt32->getCols();
1610 oz[j] = (SCSUINT32_COP *) ozUInt32->get();
1615 oztyp[j] = SCSUNKNOW_N;
1616 oz[j] = il_sim_opar->get(j);
1617 ozsz[j] = 0; // rows
1618 ozsz[j + nopar] = 0; // cols
1625 /****************************
1626 * Set opar, oparsz, opartyp
1627 ****************************/
1628 void** opar = nullptr;
1629 int* oparsz = nullptr;
1630 int* opartyp = nullptr;
1633 // Allocation of 'opar'
1636 opar = new void*[nopar];
1638 catch (const std::bad_alloc& /*e*/)
1640 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1641 il_state->DecreaseRef();
1643 il_tcur->DecreaseRef();
1645 delete[] il_sim_labptr;
1646 delete_strings(l_sim_lab, il_sim_lab->getSize());
1647 delete[] il_sim_uidptr;
1648 delete_strings(l_sim_uid, il_sim_uid->getSize());
1653 il_sim->DecreaseRef();
1655 return types::Function::Error;
1657 // Allocation of 'oparsz'
1660 oparsz = new int[2 * nopar];
1662 catch (const std::bad_alloc& /*e*/)
1664 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1665 il_state->DecreaseRef();
1667 il_tcur->DecreaseRef();
1669 delete[] il_sim_labptr;
1670 delete_strings(l_sim_lab, il_sim_lab->getSize());
1671 delete[] il_sim_uidptr;
1672 delete_strings(l_sim_uid, il_sim_uid->getSize());
1678 il_sim->DecreaseRef();
1680 return types::Function::Error;
1682 // Allocation of 'opartyp'
1685 opartyp = new int[nopar];
1687 catch (const std::bad_alloc& /*e*/)
1689 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1690 il_state->DecreaseRef();
1692 il_tcur->DecreaseRef();
1694 delete[] il_sim_labptr;
1695 delete_strings(l_sim_lab, il_sim_lab->getSize());
1696 delete[] il_sim_uidptr;
1697 delete_strings(l_sim_uid, il_sim_uid->getSize());
1704 il_sim->DecreaseRef();
1706 return types::Function::Error;
1709 // Set vectors of 'opar'
1710 for (int j = 0; j < nopar; ++j)
1712 int subtype = il_sim_opar->get(j)->getType();
1714 switch (subtype) // Store type and address
1716 case types::InternalType::ScilabDouble :
1718 types::Double* oparDouble = il_sim_opar->get(j)->getAs<types::Double>();
1719 if (oparDouble->isComplex() == false)
1721 opartyp[j] = SCSREAL_N; // Double real matrix
1722 opar[j] = (SCSREAL_COP *) oparDouble->get();
1726 opartyp[j] = SCSCOMPLEX_N; // Double complex matrix
1727 // Allocate a long array in order to make the real and complex parts contiguous (oparDouble->get() and oparDouble->getImg())
1730 opar[j] = new double[2 * oparDouble->getSize()];
1732 catch (const std::bad_alloc& /*e*/)
1734 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1735 il_state->DecreaseRef();
1737 il_tcur->DecreaseRef();
1739 delete[] il_sim_labptr;
1740 delete_strings(l_sim_lab, il_sim_lab->getSize());
1741 delete[] il_sim_uidptr;
1742 delete_strings(l_sim_uid, il_sim_uid->getSize());
1750 il_sim->DecreaseRef();
1752 return types::Function::Error;
1754 memcpy(opar[j], oparDouble->get(), oparDouble->getSize() * sizeof(double)); // Real part
1755 memcpy((double*)(opar[j]) + oparDouble->getSize(), oparDouble->getImg(), oparDouble->getSize() * sizeof(double)); // Complex part
1756 // FIXME: delete oparDouble because we copied it instead of using it?
1758 oparsz[j] = oparDouble->getRows();
1759 oparsz[j + nopar] = oparDouble->getCols();
1762 case types::InternalType::ScilabInt8 :
1764 types::Int8* oparInt8 = il_sim_opar->get(j)->getAs<types::Int8>();
1765 opartyp[j] = SCSINT8_N; // int8
1766 oparsz[j] = oparInt8->getRows();
1767 oparsz[j + nopar] = oparInt8->getCols();
1768 opar[j] = (SCSINT8_COP *) oparInt8->get();
1771 case types::InternalType::ScilabInt16:
1773 types::Int16 *oparInt16 =
1774 il_sim_opar->get(j)->getAs<types::Int16>();
1775 opartyp[j] = SCSINT16_N; // int16
1776 oparsz[j] = oparInt16->getRows();
1777 oparsz[j + nopar] = oparInt16->getCols();
1778 opar[j] = (SCSINT16_COP *)oparInt16->get();
1781 case types::InternalType::ScilabInt32 :
1783 types::Int32* oparInt32 = il_sim_opar->get(j)->getAs<types::Int32>();
1784 opartyp[j] = SCSINT32_N; // int32
1785 oparsz[j] = oparInt32->getRows();
1786 oparsz[j + nopar] = oparInt32->getCols();
1787 opar[j] = (SCSINT32_COP *) oparInt32->get();
1790 case types::InternalType::ScilabUInt8 :
1792 types::UInt8* oparUInt8 = il_sim_opar->get(j)->getAs<types::UInt8>();
1793 opartyp[j] = SCSUINT8_N; // uint8
1794 oparsz[j] = oparUInt8->getRows();
1795 oparsz[j + nopar] = oparUInt8->getCols();
1796 opar[j] = (SCSUINT8_COP *) oparUInt8->get();
1799 case types::InternalType::ScilabUInt16 :
1801 types::UInt16* oparUInt16 = il_sim_opar->get(j)->getAs<types::UInt16>();
1802 opartyp[j] = SCSUINT16_N; // uint16
1803 oparsz[j] = oparUInt16->getRows();
1804 oparsz[j + nopar] = oparUInt16->getCols();
1805 opar[j] = (SCSUINT16_COP *)oparUInt16->get();
1808 case types::InternalType::ScilabUInt32 :
1810 types::UInt32* oparUInt32 = il_sim_opar->get(j)->getAs<types::UInt32>();
1811 opartyp[j] = SCSUINT32_N; // uint32
1812 oparsz[j] = oparUInt32->getRows();
1813 oparsz[j + nopar] = oparUInt32->getCols();
1814 opar[j] = (SCSUINT32_COP *) oparUInt32->get();
1819 opartyp[j] = SCSUNKNOW_N;
1820 opar[j] = il_sim_opar->get(j);
1821 oparsz[j] = 0; // rows
1822 oparsz[j + nopar] = 0; // cols
1829 // Declaration of 'outtb_elem'
1830 outtb_el* outtb_elem = nullptr;
1833 /*******************************
1834 * Set outtbptr, outtbsz, outtbtyp
1835 *******************************/
1836 void** outtbptr = nullptr;
1837 int* outtbsz = nullptr;
1838 int* outtbtyp = nullptr;
1841 // Allocation of 'outtbptr'
1844 outtbptr = new void*[nlnk];
1846 catch (const std::bad_alloc& /*e*/)
1848 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1849 il_state->DecreaseRef();
1851 il_tcur->DecreaseRef();
1853 delete[] il_sim_labptr;
1854 delete_strings(l_sim_lab, il_sim_lab->getSize());
1855 delete[] il_sim_uidptr;
1856 delete_strings(l_sim_uid, il_sim_uid->getSize());
1864 il_sim->DecreaseRef();
1866 return types::Function::Error;
1868 // Allocation of 'outtbptrsz'
1871 outtbsz = new int[2 * nlnk];
1873 catch (const std::bad_alloc& /*e*/)
1875 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1876 il_state->DecreaseRef();
1878 il_tcur->DecreaseRef();
1880 delete[] il_sim_labptr;
1881 delete_strings(l_sim_lab, il_sim_lab->getSize());
1882 delete[] il_sim_uidptr;
1883 delete_strings(l_sim_uid, il_sim_uid->getSize());
1892 il_sim->DecreaseRef();
1894 return types::Function::Error;
1896 // Allocation of 'outtbtyp'
1899 outtbtyp = new int[nlnk];
1901 catch (const std::bad_alloc& /*e*/)
1903 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1904 il_state->DecreaseRef();
1906 il_tcur->DecreaseRef();
1908 delete[] il_sim_labptr;
1909 delete_strings(l_sim_lab, il_sim_lab->getSize());
1910 delete[] il_sim_uidptr;
1911 delete_strings(l_sim_uid, il_sim_uid->getSize());
1921 il_sim->DecreaseRef();
1923 return types::Function::Error;
1926 // Set vectors of 'outtbptr'
1927 for (int j = 0; j < nlnk; ++j)
1929 int subtype = il_state_outtb->get(j)->getType();
1931 switch (subtype) // Store type and address
1933 case types::InternalType::ScilabDouble :
1935 types::Double* outtbDouble = il_state_outtb->get(j)->getAs<types::Double>();
1936 if (outtbDouble->isComplex() == false)
1938 outtbtyp[j] = SCSREAL_N; // Double real matrix
1939 outtbptr[j] = (SCSREAL_COP *) outtbDouble->get();
1943 outtbtyp[j] = SCSCOMPLEX_N; // Double complex matrix
1944 // Allocate a long array in order to make the real and complex parts contiguous (outtbDouble->get() and outtbDouble->getImg())
1947 outtbptr[j] = new double[2 * outtbDouble->getSize()];
1949 catch (const std::bad_alloc& /*e*/)
1951 Scierror(999, _("%s: Memory allocation error.\n"), funname.data());
1952 il_state->DecreaseRef();
1954 il_tcur->DecreaseRef();
1956 delete[] il_sim_labptr;
1957 delete_strings(l_sim_lab, il_sim_lab->getSize());
1958 delete[] il_sim_uidptr;
1959 delete_strings(l_sim_uid, il_sim_uid->getSize());
1969 il_sim->DecreaseRef();
1971 return types::Function::Error;
1973 memcpy(outtbptr[j], outtbDouble->get(), outtbDouble->getSize() * sizeof(double)); // Real part
1974 memcpy((double*)(outtbptr[j]) + outtbDouble->getSize(), outtbDouble->getImg(), outtbDouble->getSize() * sizeof(double)); // Complex part
1975 // FIXME: delete outtbDouble because we copied it instead of using it?
1977 outtbsz[j] = outtbDouble->getRows();
1978 outtbsz[j + nlnk] = outtbDouble->getCols();
1981 case types::InternalType::ScilabInt8 :
1983 types::Int8* outtbInt8 = il_state_outtb->get(j)->getAs<types::Int8>();
1984 outtbtyp[j] = SCSINT8_N; // int8
1985 outtbsz[j] = outtbInt8->getRows();
1986 outtbsz[j + nlnk] = outtbInt8->getCols();
1987 outtbptr[j] = (SCSINT8_COP *) outtbInt8->get();
1990 case types::InternalType::ScilabInt16 :
1992 types::Int16* outtbInt16 = il_state_outtb->get(j)->getAs<types::Int16>();
1993 outtbtyp[j] = SCSINT16_N; // int16
1994 outtbsz[j] = outtbInt16->getRows();
1995 outtbsz[j + nlnk] = outtbInt16->getCols();
1996 outtbptr[j] = (SCSINT16_COP *) outtbInt16->get();
1999 case types::InternalType::ScilabInt32 :
2001 types::Int32* outtbInt32 = il_state_outtb->get(j)->getAs<types::Int32>();
2002 outtbtyp[j] = SCSINT32_N; // int32
2003 outtbsz[j] = outtbInt32->getRows();
2004 outtbsz[j + nlnk] = outtbInt32->getCols();
2005 outtbptr[j] = (SCSINT32_COP *) outtbInt32->get();
2008 case types::InternalType::ScilabUInt8 :
2010 types::UInt8* outtbUInt8 = il_state_outtb->get(j)->getAs<types::UInt8>();
2011 outtbtyp[j] = SCSUINT8_N; // uint8
2012 outtbsz[j] = outtbUInt8->getRows();
2013 outtbsz[j + nlnk] = outtbUInt8->getCols();
2014 outtbptr[j] = (SCSUINT8_COP *) outtbUInt8->get();
2017 case types::InternalType::ScilabUInt16 :
2019 types::UInt16* outtbUInt16 = il_state_outtb->get(j)->getAs<types::UInt16>();
2020 outtbtyp[j] = SCSUINT16_N; // uint16
2021 outtbsz[j] = outtbUInt16->getRows();
2022 outtbsz[j + nlnk] = outtbUInt16->getCols();
2023 outtbptr[j] = (SCSUINT16_COP *) outtbUInt16->get();
2026 case types::InternalType::ScilabUInt32 :
2028 types::UInt32* outtbUInt32 = il_state_outtb->get(j)->getAs<types::UInt32>();
2029 outtbtyp[j] = SCSUINT32_N; // uint32
2030 outtbsz[j] = outtbUInt32->getRows();
2031 outtbsz[j + nlnk] = outtbUInt32->getCols();
2032 outtbptr[j] = (SCSUINT32_COP *) outtbUInt32->get();
2037 Scierror(999, _("%s: Wrong type for element #%d of element #%d of argument #%d : A matrix expected.\n"), funname.data(), j + 1, 9, 1);
2038 il_state->DecreaseRef();
2040 il_tcur->DecreaseRef();
2042 delete[] il_sim_labptr;
2043 delete_strings(l_sim_lab, il_sim_lab->getSize());
2044 delete[] il_sim_uidptr;
2045 delete_strings(l_sim_uid, il_sim_uid->getSize());
2057 il_sim->DecreaseRef();
2059 return types::Function::Error;
2063 // Store 'lnk' and 'pos' in 'outtb_elem'
2065 nelem += outtbsz[j] * outtbsz[j + nlnk];
2066 if ((outtb_elem = (outtb_el *) REALLOC(outtb_elem, nelem * sizeof(outtb_el))) == nullptr)
2068 Scierror(999, _("%s : No more free memory.\n"), funname.data());
2069 il_state->DecreaseRef();
2071 il_tcur->DecreaseRef();
2073 delete[] il_sim_labptr;
2074 delete_strings(l_sim_lab, il_sim_lab->getSize());
2075 delete[] il_sim_uidptr;
2076 delete_strings(l_sim_uid, il_sim_uid->getSize());
2088 il_sim->DecreaseRef();
2090 return types::Function::Error;
2092 for (int i = 0; i < outtbsz[j]*outtbsz[j + nlnk]; ++i)
2094 outtb_elem[k + i].lnk = j;
2095 outtb_elem[k + i].pos = i;
2100 /************************
2101 * Call scicos simulator
2102 ************************/
2104 * int C2F(scicos)(double *x_in, int *xptr_in, double *z__,
2105 * void **work,int *zptr,int *modptr_in,
2106 * void **oz,int *ozsz,int *oztyp,int *ozptr,
2107 * char **iz,int *izptr,double *t0_in,
2108 * double *tf_in,double *tevts_in,int *evtspt_in,
2109 * int *nevts,int *pointi_in,void **outtbptr_in,
2110 * int *outtbsz_in,int *outtbtyp_in,
2111 * outtb_el *outtb_elem_in,int *nelem1,int *nlnk1,
2112 * int *funptr,int *funtyp_in,int *inpptr_in,
2113 * int *outptr_in, int *inplnk_in,int *outlnk_in,
2114 * double *rpar,int *rpptr,int *ipar,int *ipptr,
2115 * void **opar,int *oparsz,int *opartyp,int *opptr,
2116 * int *clkptr_in,int *ordptr_in,int *nordptr1,
2117 * int *ordclk_in,int *cord_in,int *ncord1,
2118 * int *iord_in,int *niord1,int *oord_in,
2119 * int *noord1,int *zord_in,int *nzord1,
2120 * int *critev_in,int *nblk1,int *ztyp,
2121 * int *zcptr_in,int *subscr,int *nsubs,
2122 * double *simpar,int *flag__,int *ierr_out)
2126 C2F(scicos)(l_state_x, l_sim_xptr, l_state_z,
2127 l_state_iz, l_sim_zptr, l_sim_modptr,
2128 oz, ozsz, oztyp, l_sim_ozptr,
2129 l_sim_lab, il_sim_labptr, l_sim_uid, il_sim_uidptr, l_tcur,
2130 l_tf, l_state_tevts, l_state_evtspt,
2131 &m1e5, l_pointi, outtbptr,
2133 outtb_elem, &nelem, &nlnk,
2134 lfunpt, l_sim_funtyp, l_sim_inpptr,
2135 l_sim_outptr, l_sim_inplnk, l_sim_outlnk,
2136 l_sim_rpar, l_sim_rpptr, l_sim_ipar, l_sim_ipptr,
2137 opar, oparsz, opartyp, l_sim_opptr,
2138 l_sim_clkptr, l_sim_ordptr, &m_ordptr,
2139 l_sim_ordclk, l_sim_cord, &m_cord,
2140 l_sim_iord, &m_iord, l_sim_oord,
2141 &m_oord, l_sim_zord, &m_zord,
2142 l_sim_critev, &nblk, l_sim_ztyp,
2143 l_sim_zcptr, l_sim_subscr, &m_subscr,
2144 simpar, &flag, &ierr);
2146 /**********************
2147 * Free allocated arrays
2148 **********************/
2161 /*************************************
2162 * Switch to appropriate message error
2163 *************************************/
2170 error = _("scheduling problem");
2171 C2F(curblk).kfun = 0;
2175 error = _("input to zero-crossing stuck on zero");
2176 C2F(curblk).kfun = 0;
2180 error = _("event conflict");
2181 C2F(curblk).kfun = 0;
2185 error = _("algebraic loop detected");
2186 C2F(curblk).kfun = 0;
2190 error = _("cannot allocate memory");
2191 C2F(curblk).kfun = 0;
2197 error = new char[MAX_ERROR_LEN];
2198 allocatedError = TRUE;
2199 snprintf(error, MAX_ERROR_LEN, _("the block %d has been called with input out of its domain"), C2F(curblk).kfun);
2201 catch (const std::bad_alloc& /*e*/)
2203 error = _("cannot allocate memory");
2208 error = _("singularity in a block");
2212 error = _("block produces an internal error");
2220 error = _("initial conditions not converging");
2226 error = new char[MAX_ERROR_LEN];
2227 allocatedError = TRUE;
2228 snprintf(error, MAX_ERROR_LEN, _("cannot allocate memory in block=%d"), C2F(curblk).kfun);
2230 catch (const std::bad_alloc& /*e*/)
2232 error = _("cannot allocate memory");
2237 error = _("sliding mode condition, cannot integrate");
2241 error = _("Cannot find the initial mode, maybe there is a sliding mode condition");
2244 error = _("You have changed a parameter in your model, but the "
2245 "model has been compiled to use an XML file containing "
2246 "initial values and parameters. So you should either "
2247 "recompile your Scicos diagram or [re]launch the "
2248 "initialization interface to regenerate the XML file "
2249 "with new parameters.");
2253 error = _("Undefined data type.");
2256 error = _("The number of parameter provided by Scicos blocks is different from what expected by the code generated by the Modelica compiler. You might have relaxed a parameter using FIXED property (i.e., fixed=false) in a Modelica model. This will be corrected in the next version");
2258 // In this case, you need to turn off the parameter embedded code generation mode by setting 'Modelica_ParEmb=%f' in the Scilab command window, and recompile the Scicos diagram
2263 error = _("unknown or erroneous block");
2265 else if (ierr >= 201 && ierr <= 416) // Sundials error messages, stored in coserr.buf
2269 else if (ierr >= 100)
2271 int istate = -(ierr - 100);
2274 error = new char[MAX_ERROR_LEN];
2275 allocatedError = TRUE;
2276 snprintf(error, MAX_ERROR_LEN, _("integration problem istate=%d"), istate);
2278 catch (const std::bad_alloc& /*e*/)
2280 error = _("cannot allocate memory");
2282 C2F(curblk).kfun = 0;
2286 error = _("scicos unexpected error, please report...");
2287 C2F(curblk).kfun = 0;
2292 Scierror(888, "%s\n", error);
2293 il_state->DecreaseRef();
2295 il_tcur->DecreaseRef();
2297 delete[] il_sim_labptr;
2298 delete_strings(l_sim_lab, il_sim_lab->getSize());
2299 delete[] il_sim_uidptr;
2300 delete_strings(l_sim_uid, il_sim_uid->getSize());
2305 il_sim->DecreaseRef();
2307 return types::Function::Error;
2310 /*********************
2311 * Return Lhs variables
2312 *********************/
2313 // Convert integer parameters of 'il_state' into double parameters
2314 il_state_evtspt->convertFromInteger();
2315 il_pointi->convertFromInteger();
2317 out.push_back(il_state);
2318 out.push_back(il_tcur);
2321 delete[] il_sim_labptr;
2322 delete_strings(l_sim_lab, il_sim_lab->getSize());
2323 delete[] il_sim_uidptr;
2324 delete_strings(l_sim_uid, il_sim_uid->getSize());
2325 il_sim->DecreaseRef();
2327 return types::Function::OK;