From: Paul Bignier Date: Thu, 30 Apr 2015 09:59:48 +0000 (+0200) Subject: Xcos blocks: make scifunc_block_m work X-Git-Tag: 6.0.0-alpha-1~193 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=cc1487534e68dd9e26c2f79947ffea072ef5ffe8 Xcos blocks: make scifunc_block_m work * "Inverted pendulum" demo contains that block Change-Id: Ifea2c72b6de1a1068a41c387ae5a262aea677e3b --- diff --git a/scilab/modules/scicos/macros/scicos_scicos/genmac.sci b/scilab/modules/scicos/macros/scicos_scicos/genmac.sci index d838c2a..dcaf84a 100644 --- a/scilab/modules/scicos/macros/scicos_scicos/genmac.sci +++ b/scilab/modules/scicos/macros/scicos_scicos/genmac.sci @@ -86,5 +86,5 @@ function mac=genmac(tt,nin,nout) set_y "end";] - deff("[y,x,z,t_evo,xd]=mac(%_flag,n_evi,t,x,z,rpar,ipar,u)",mac_txt) + deff("[xd,t_evo,z,x,y]=mac(%_flag,n_evi,t,x,z,rpar,ipar,u)",mac_txt) endfunction diff --git a/scilab/modules/scicos/src/cpp/sciblk2.cpp b/scilab/modules/scicos/src/cpp/sciblk2.cpp index 55e842e..f454628 100644 --- a/scilab/modules/scicos/src/cpp/sciblk2.cpp +++ b/scilab/modules/scicos/src/cpp/sciblk2.cpp @@ -101,7 +101,7 @@ void sciblk2(int* flag, int* nevprt, double* t, double xd[], double x[], int* nx // Treating 'ipar' differently because it is an int tab, unlike the other double ones types::Double* Ipar = new types::Double(*nipar, 1); - std::transform(ipar, ipar + *nipar, Ipar, toDouble); + std::transform(ipar, ipar + *nipar, Ipar->get(), toDouble); in[6] = Ipar; types::List* Nin = new types::List(); @@ -171,35 +171,44 @@ void sciblk2(int* flag, int* nevprt, double* t, double xd[], double x[], int* nx types::Double* Xout = out[3]->getAs(); memcpy(x, Xout->get(), *nx * sizeof(double)); - if (*nout != 0) + if (*flag == 1 || *flag == 6) { - if (!out[4]->isList()) + if (*nout != 0) { - setErrAndFree(-1, out); - return; - } - types::List* Yout = out[4]->getAs(); - if (Yout->getSize() < *nout) - { - // Consider that 'outptr' has not been defined in the macro: do not update the current 'outptr' - break; - } - for (int k = *nout - 1; k >= 0; --k) - { - if (!Yout->get(k)->isDouble()) + if (!out[4]->isList()) { setErrAndFree(-1, out); return; } - types::Double* KthElement = Yout->get(k)->getAs(); - double* y = (double*)outptr[k]; - int ny = outsz[k]; - int ny2 = 1; - if (*flag == 1) + types::List* Yout = out[4]->getAs(); + if (Yout->getSize() < *nout) + { + // Consider that 'outptr' has not been defined in the macro: do not update the current 'outptr' + break; + } + for (int k = *nout - 1; k >= 0; --k) { - ny2 = outsz[*nout + k]; + if (!Yout->get(k)->isDouble()) + { + setErrAndFree(-1, out); + return; + } + types::Double* KthElement = Yout->get(k)->getAs(); + double* y = (double*)outptr[k]; + int ny = outsz[k]; + int ny2 = 1; + if (*flag == 1) + { + ny2 = outsz[*nout + k]; + } + if (KthElement->getSize() != ny * ny2) + { + // At initialization (flag 6), the 'y' returned by the macro is not necessarily properly initialized. + // In this case, do nothing to avoid copying corrupt data + break; + } + memcpy(y, KthElement->get(), ny * ny2 * sizeof(double)); } - memcpy(y, KthElement->get(), ny * ny2 * sizeof(double)); } } break;