Xcos blocks: rewrite fromws_c to C++ 14/16214/9
Paul Bignier [Fri, 20 Mar 2015 10:30:47 +0000 (11:30 +0100)]
 * Kept all the "fromws_c" names (instead of renaming to _cpp for backward compatibility)
 * Tests already present xcos/tests/unit_tests/fromws_c.tst & fromws_tows_c.tst, but cannot run yet because of importXcosDiagram()

Change-Id: I752d557106bd5c0a38da702d627a1c4a271f88da

12 files changed:
scilab/modules/scicos/macros/scicos_auto/scicos_simulate.sci
scilab/modules/scicos/macros/scicos_utils/scicos_workspace_init.sci
scilab/modules/scicos_blocks/Makefile.am
scilab/modules/scicos_blocks/Makefile.in
scilab/modules/scicos_blocks/src/c/cli/scicos_blocks-cli.vcxproj
scilab/modules/scicos_blocks/src/c/cli/scicos_blocks-cli.vcxproj.filters
scilab/modules/scicos_blocks/src/c/fromws_c.c [deleted file]
scilab/modules/scicos_blocks/src/c/scicos_blocks.vcxproj
scilab/modules/scicos_blocks/src/c/scicos_blocks.vcxproj.filters
scilab/modules/scicos_blocks/src/cpp/fromws_c.cpp [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/fromws_c.tst
scilab/modules/xcos/tests/unit_tests/fromws_tows_c.tst

index baf780b..2235c86 100644 (file)
@@ -200,8 +200,7 @@ function Info = scicos_simulate(scs_m, Info, updated_vars, flag, Ignb)
 
     //** prepare from and to workspace stuff
     //-------------------------------------
-    // Comment the following line until evstr() passes when applied to Xcos blocks (returning function prototype)
-    //scicos_workspace_init()
+    scicos_workspace_init()
 
     if flag == "nw" then
         Ignore = [Ignore,Ignoreb]
index e3b7008..b79905b 100644 (file)
@@ -32,21 +32,18 @@ function scicos_workspace_init()
     //and which contain 2 variables "x" and "t"
     //
     prt=funcprot(),funcprot(0)
-    varnames = who("get")   ;
-    varnames = varnames(1:$-predef()+1);  //** exclude protected variables
-    varnames(varnames=="ans")=[];
+    varnames = who("get");
+    //varnames = varnames(1:$-predef()+1);  //** exclude protected variables
+    protected = ["ans" "%e" "%eps" "%fftw" "%gui" "%i" "%inf" "%io" "%nan" "%pi" "%s" "%z" "%tk" "PWD" "SCI" "SCIHOME" "TMPDIR" "home" "workingDirectory" "workingfiles"];
+    varnames(members(varnames, protected) <> 0) = [];
     for var=varnames'
         v=evstr(var);
         if typeof(v)=="st" then
-            fn=fieldnames(v)
+            fn=fieldnames(v);
             if and(fn==["values";"time"] | fn==["time";"values"]) then
                 if execstr("x=v.values","errcatch")==0 then
                     if execstr("t=v.time","errcatch") ==0 then
-                        // remove deprecation warning on save, this will be reimplemented on 6.x
-                        warnMode = warning("query");
-                        warning("off");
-                        execstr("save("""+path+var+""",x,t)")
-                        warning(warnMode);
+                        execstr("save("""+path+var+""",""x"",""t"")");
                     end
                 end
             end
index 7f46ef9..741365a 100644 (file)
@@ -128,7 +128,6 @@ SCICOS_BLOCKS_C_SOURCES = \
     src/c/exttriu.c \
     src/c/exttriuz.c \
     src/c/foriterator.c \
-    src/c/fromws_c.c \
     src/c/gainblk.c \
     src/c/gainblk_i16e.c \
     src/c/gainblk_i16n.c \
@@ -329,7 +328,8 @@ SCICOS_BLOCKS_C_SOURCES = \
     src/c/zcross2.c
 
 SCICOS_BLOCKS_CXX_SOURCES = \
-    src/cpp/affich2.cpp
+    src/cpp/affich2.cpp \
+    src/cpp/fromws_c.cpp
 
 NON_BLOCK_C_SOURCES = \
     src/c/scicos_evalhermite.c \
@@ -438,6 +438,7 @@ libsciscicos_blocks_algo_la_CPPFLAGS= \
     -I$(top_srcdir)/modules/fileio/includes/ \
     -I$(top_srcdir)/modules/graphics/includes/ \
     -I$(top_srcdir)/modules/graphic_objects/includes/ \
+    -I$(top_srcdir)/modules/hdf5/includes \
     -I$(top_srcdir)/modules/localization/includes/ \
     -I$(top_srcdir)/modules/output_stream/includes/ \
     -I$(top_srcdir)/modules/renderer/includes/ \
index 3d6e99f..12fadd4 100644 (file)
@@ -290,7 +290,6 @@ am__objects_1 = src/c/libsciscicos_blocks_algo_la-absblk.lo \
        src/c/libsciscicos_blocks_algo_la-exttriu.lo \
        src/c/libsciscicos_blocks_algo_la-exttriuz.lo \
        src/c/libsciscicos_blocks_algo_la-foriterator.lo \
-       src/c/libsciscicos_blocks_algo_la-fromws_c.lo \
        src/c/libsciscicos_blocks_algo_la-gainblk.lo \
        src/c/libsciscicos_blocks_algo_la-gainblk_i16e.lo \
        src/c/libsciscicos_blocks_algo_la-gainblk_i16n.lo \
@@ -489,7 +488,8 @@ am__objects_1 = src/c/libsciscicos_blocks_algo_la-absblk.lo \
        src/c/libsciscicos_blocks_algo_la-writeau.lo \
        src/c/libsciscicos_blocks_algo_la-writec.lo \
        src/c/libsciscicos_blocks_algo_la-zcross2.lo
-am__objects_2 = src/cpp/libsciscicos_blocks_algo_la-affich2.lo
+am__objects_2 = src/cpp/libsciscicos_blocks_algo_la-affich2.lo \
+       src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo
 am__objects_3 = src/fortran/csslti.lo src/fortran/cstblk.lo \
        src/fortran/delay.lo src/fortran/delayv.lo \
        src/fortran/demux.lo src/fortran/diffblk.lo \
@@ -1068,7 +1068,6 @@ SCICOS_BLOCKS_C_SOURCES = \
     src/c/exttriu.c \
     src/c/exttriuz.c \
     src/c/foriterator.c \
-    src/c/fromws_c.c \
     src/c/gainblk.c \
     src/c/gainblk_i16e.c \
     src/c/gainblk_i16n.c \
@@ -1269,7 +1268,8 @@ SCICOS_BLOCKS_C_SOURCES = \
     src/c/zcross2.c
 
 SCICOS_BLOCKS_CXX_SOURCES = \
-    src/cpp/affich2.cpp
+    src/cpp/affich2.cpp \
+    src/cpp/fromws_c.cpp
 
 NON_BLOCK_C_SOURCES = \
     src/c/scicos_evalhermite.c \
@@ -1371,6 +1371,7 @@ libsciscicos_blocks_algo_la_CPPFLAGS = \
     -I$(top_srcdir)/modules/fileio/includes/ \
     -I$(top_srcdir)/modules/graphics/includes/ \
     -I$(top_srcdir)/modules/graphic_objects/includes/ \
+    -I$(top_srcdir)/modules/hdf5/includes \
     -I$(top_srcdir)/modules/localization/includes/ \
     -I$(top_srcdir)/modules/output_stream/includes/ \
     -I$(top_srcdir)/modules/renderer/includes/ \
@@ -1835,8 +1836,6 @@ src/c/libsciscicos_blocks_algo_la-exttriuz.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libsciscicos_blocks_algo_la-foriterator.lo:  \
        src/c/$(am__dirstamp) src/c/$(DEPDIR)/$(am__dirstamp)
-src/c/libsciscicos_blocks_algo_la-fromws_c.lo: src/c/$(am__dirstamp) \
-       src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libsciscicos_blocks_algo_la-gainblk.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libsciscicos_blocks_algo_la-gainblk_i16e.lo:  \
@@ -2241,6 +2240,8 @@ src/cpp/$(DEPDIR)/$(am__dirstamp):
        @: > src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libsciscicos_blocks_algo_la-affich2.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo:  \
+       src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/fortran/$(am__dirstamp):
        @$(MKDIR_P) src/fortran
        @: > src/fortran/$(am__dirstamp)
@@ -2515,7 +2516,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-exttriu.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-exttriuz.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-foriterator.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-gain.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-gainblk.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-gainblk_i16e.Plo@am__quote@
@@ -2717,6 +2717,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-writec.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-zcross2.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-affich2.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-scoUtils.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciscicos_blocks_cli_la-HelpersCLI.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciscicos_blocks_la-HelpersJNI.Plo@am__quote@
@@ -3530,13 +3531,6 @@ src/c/libsciscicos_blocks_algo_la-foriterator.lo: src/c/foriterator.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libsciscicos_blocks_algo_la-foriterator.lo `test -f 'src/c/foriterator.c' || echo '$(srcdir)/'`src/c/foriterator.c
 
-src/c/libsciscicos_blocks_algo_la-fromws_c.lo: src/c/fromws_c.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/c/libsciscicos_blocks_algo_la-fromws_c.lo -MD -MP -MF src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Tpo -c -o src/c/libsciscicos_blocks_algo_la-fromws_c.lo `test -f 'src/c/fromws_c.c' || echo '$(srcdir)/'`src/c/fromws_c.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Tpo src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='src/c/fromws_c.c' object='src/c/libsciscicos_blocks_algo_la-fromws_c.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libsciscicos_blocks_algo_la-fromws_c.lo `test -f 'src/c/fromws_c.c' || echo '$(srcdir)/'`src/c/fromws_c.c
-
 src/c/libsciscicos_blocks_algo_la-gainblk.lo: src/c/gainblk.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/c/libsciscicos_blocks_algo_la-gainblk.lo -MD -MP -MF src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-gainblk.Tpo -c -o src/c/libsciscicos_blocks_algo_la-gainblk.lo `test -f 'src/c/gainblk.c' || echo '$(srcdir)/'`src/c/gainblk.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-gainblk.Tpo src/c/$(DEPDIR)/libsciscicos_blocks_algo_la-gainblk.Plo
@@ -4968,6 +4962,13 @@ src/cpp/libsciscicos_blocks_algo_la-affich2.lo: src/cpp/affich2.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libsciscicos_blocks_algo_la-affich2.lo `test -f 'src/cpp/affich2.cpp' || echo '$(srcdir)/'`src/cpp/affich2.cpp
 
+src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo: src/cpp/fromws_c.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo -MD -MP -MF src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Tpo -c -o src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo `test -f 'src/cpp/fromws_c.cpp' || echo '$(srcdir)/'`src/cpp/fromws_c.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Tpo src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-fromws_c.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/fromws_c.cpp' object='src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libsciscicos_blocks_algo_la-fromws_c.lo `test -f 'src/cpp/fromws_c.cpp' || echo '$(srcdir)/'`src/cpp/fromws_c.cpp
+
 src/cpp/libsciscicos_blocks_algo_la-scoUtils.lo: src/cpp/scoUtils.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_blocks_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libsciscicos_blocks_algo_la-scoUtils.lo -MD -MP -MF src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-scoUtils.Tpo -c -o src/cpp/libsciscicos_blocks_algo_la-scoUtils.lo `test -f 'src/cpp/scoUtils.cpp' || echo '$(srcdir)/'`src/cpp/scoUtils.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-scoUtils.Tpo src/cpp/$(DEPDIR)/libsciscicos_blocks_algo_la-scoUtils.Plo
index 55bdd1a..5797aa6 100644 (file)
@@ -232,6 +232,7 @@ lib /DEF:"$(ProjectDir)../elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS
     <ClCompile Include="..\acos_blk.c" />
     <ClCompile Include="..\acosh_blk.c" />
     <ClCompile Include="..\..\cpp\affich2.cpp" />
+    <ClCompile Include="..\..\cpp\fromws.cpp" />
     <ClCompile Include="..\..\cpp\scoUtils.cpp" />
     <ClCompile Include="..\andlog.c" />
     <ClCompile Include="..\asin_blk.c" />
@@ -342,7 +343,6 @@ lib /DEF:"$(ProjectDir)../elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS
     <ClCompile Include="..\exttriu.c" />
     <ClCompile Include="..\exttriuz.c" />
     <ClCompile Include="..\foriterator.c" />
-    <ClCompile Include="..\fromws_c.c" />
     <ClCompile Include="..\gain.c" />
     <ClCompile Include="..\gainblk.c" />
     <ClCompile Include="..\gainblk_i16e.c" />
@@ -613,4 +613,4 @@ lib /DEF:"$(ProjectDir)../elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 3627eba..09ea085 100644 (file)
@@ -38,6 +38,9 @@
     <ClCompile Include="..\..\cpp\affich2.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\cpp\fromws.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\andlog.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\foriterator.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\fromws_c.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\gain.c">
       <Filter>Source Files</Filter>
     </ClCompile>
       <Filter>Resource Files</Filter>
     </ResourceCompile>
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/scilab/modules/scicos_blocks/src/c/fromws_c.c b/scilab/modules/scicos_blocks/src/c/fromws_c.c
deleted file mode 100644 (file)
index 3de6907..0000000
+++ /dev/null
@@ -1,1582 +0,0 @@
-/*  Scicos
-   *
-   *  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
-   *
-   * This program is free software; you can redistribute it and/or modify
-   * it under the terms of the GNU General Public License as published by
-   * the Free Software Foundation; either version 2 of the License, or
-   * (at your option) any later version.
-   *
-   * This program is distributed in the hope that it will be useful,
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   * GNU General Public License for more details.
-   *
-   * You should have received a copy of the GNU General Public License
-   * along with this program; if not, write to the Free Software
-   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-   *
-   * See the file ./license.txt
-   */
-/*--------------------------------------------------------------------------*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include "stack-c.h"
-#include "scicos.h"
-#include "scicos_print.h"
-#include "cvstr.h"
-#include "sci_malloc.h"
-#include "mopen.h"
-#include "mget.h"
-#include "mclose.h"
-#include "expandPathVariable.h"
-#include "scicos_block4.h"
-#include "scicos_evalhermite.h"
-#include "localization.h"
-#include "scicos_malloc.h"
-#include "scicos_free.h"
-#include "dynlib_scicos_blocks.h"
-/*--------------------------------------------------------------------------*/
-#define Fnlength  block->ipar[0]
-#define FName     block->ipar[1]
-#define Method     block->ipar[1+Fnlength]
-#define ZC        block->ipar[2+Fnlength]
-#define OutEnd    block->ipar[3+Fnlength]
-#define T0        ptr->workt[0]
-#define TNm1      ptr->workt[nPoints-1]
-#define TP        (TNm1-0)
-/*--------------------------------------------------------------------------*/
-static int Mytridiagldltsolve(double *dA, double * lA, double * B, int N);
-/*--------------------------------------------------------------------------*/
-/* function to check and extract data coming from an hypermat */
-static int Ishm(int *fd, int *Ytype, int *nPoints, int *my, int *ny, int *YsubType);
-/*--------------------------------------------------------------------------*/
-static char fmtd[3] = {'d', 'l', '\000'};
-static char fmti[3] = {'i', 'l', '\000'};
-static char fmtl[3] = {'l', 'l', '\000'};
-static char fmts[3] = {'s', 'l', '\000'};
-static char fmtc[3] = {'c', 'l', '\000'};
-static char fmtul[3] = {'u', 'l', '\000'};
-static char fmtus[3] = {'u', 's', '\000'};
-static char fmtuc[3] = {'u', 'c', '\000'};
-/*--------------------------------------------------------------------------*/
-#ifdef hppa
-#undef FILENAME_MAX
-#define FILENAME_MAX 4096
-#endif
-/*--------------------------------------------------------------------------*/
-/* work struct for that block */
-typedef struct
-{
-    int nPoints;
-    int Hmat;
-    int Yt;
-    int Yst;
-    int cnt1;
-    int cnt2;
-    int EVindex;
-    int PerEVcnt;
-    int firstevent;
-    double *D;
-    void *work;
-    double *workt;
-} fromwork_struct ;
-/*--------------------------------------------------------------------------*/
-SCICOS_BLOCKS_IMPEXP void fromws_c(scicos_block *block, int flag)
-{
-#if 0
-    double t = 0., y1 = 0., y2 = 0., t1 = 0., t2 = 0., r = 0.;
-    double *spline = NULL, *A_d = NULL, *A_sd = NULL, *qdy = NULL;
-    /* double  a,b,c,*y;*/
-    double d1 = 0., d2 = 0., h = 0., dh = 0., ddh = 0., dddh = 0.;
-    /* counter and indexes variables */
-    int i = 0, inow = 0;
-    int j = 0, jfirst = 0;
-    int cnt1 = 0, cnt2 = 0, EVindex = 0, PerEVcnt = 0;
-
-    /* variables to handle files of TMPDIR/Workspace */
-    int fd = 0;
-    char *status = NULL;
-    int swap = 1;
-    double res = 0.;
-    char *filename = NULL;
-    char str[100];
-    int ierr = 1;
-
-    /* variables for type and dims of data coming from scilab */
-    int Ytype = 0, YsubType = 0, mY = 0, nY = 0;
-    int nPoints = 0;
-    int Ydim[10];
-
-    /* variables for type and dims of data of the output port block */
-    int ytype = 0, my = 0, ny = 0;
-
-    /* generic pointer */
-    SCSREAL_COP *y_d = NULL, *y_cd = NULL, *ptr_d = NULL, *ptr_T = NULL, *ptr_D = NULL;
-    SCSINT8_COP *y_c = NULL, *ptr_c = NULL;
-    SCSUINT8_COP *y_uc = NULL, *ptr_uc = NULL;
-    SCSINT16_COP *y_s = NULL, *ptr_s = NULL;
-    SCSUINT16_COP *y_us = NULL, *ptr_us = NULL;
-    SCSINT32_COP *y_l = NULL, *ptr_l = NULL;
-    SCSUINT32_COP *y_ul = NULL, *ptr_ul = NULL;
-
-    /* the struct ptr of that block */
-    fromwork_struct** work = (fromwork_struct**) block->work;
-    fromwork_struct *ptr = NULL;
-
-    /* for path of TMPDIR/workspace */
-    char filePrefix[] = "TMPDIR/Workspace/";
-    char* env;
-
-    /*retrieve dimensions of output port*/
-    my       = GetOutPortRows(block, 1); /* number of rows of Outputs*/
-    ny       = GetOutPortCols(block, 1); /* number of cols of Outputs*/
-    ytype    = GetOutType(block, 1);    /* output type */
-
-    /* init */
-    if (flag == 4)
-    {
-        /* convert scilab code of the variable name to C string */
-        for (j = 0; j < Fnlength; ++j)
-        {
-            str[j] = (char) FName + j;
-        }
-
-        str[Fnlength] = '\0';
-
-        /* retrieve path of TMPDIR/workspace */
-        env = (char*) scicos_malloc(sizeof(filePrefix) + Fnlength);
-        if (env == NULL)
-        {
-            set_block_error(-16);
-            return;
-        }
-        memcpy(env, filePrefix, sizeof(filePrefix));
-        memcpy(env + (sizeof(filePrefix) - 1), str, Fnlength + 1);
-
-        /* open tmp file */
-        /* "r" : read */
-        /* "b" : binary format (required for Windows) */
-        status = "rb";
-
-        filename = expandPathVariable(env);
-        scicos_free(env);
-        if (filename)
-        {
-            C2F(mopen)(&fd, filename, status, &swap, &res, &ierr);
-        }
-        FREE(filename);
-        filename = NULL;
-
-        if (ierr != 0)
-        {
-            Coserror(_("The '%s' variable does not exist.\n"), str);
-            return;
-        }
-
-        /* read x */
-        C2F(mgetnc) (&fd, &Ydim[0], (j = nsiz, &j), fmti, &ierr); /* read sci id */
-        C2F(mgetnc) (&fd, &Ydim[6], (j = 1, &j), fmti, &ierr);  /* read sci type */
-        if (Ydim[6] == 17)
-        {
-            if (!Ishm(&fd, &Ytype, &nPoints, &mY, &nY, &YsubType))
-            {
-                Coserror(_("Invalid variable type.\n"));
-                /*scicos_print(_("Invalid variable type.\n"));
-                set_block_error(-3); */
-                C2F(mclose)(&fd, &res);
-                return;
-            }
-            if (!((Ytype == 1) || (Ytype == 8)))
-            {
-                Coserror(_("Invalid variable type.\n"));
-                /*scicos_print(_("Invalid variable type.\n"));
-                set_block_error(-3);*/
-                C2F(mclose)(&fd, &res);
-                return;
-            }
-        }
-        else if ((Ydim[6] == 1) || (Ydim[6] == 8))
-        {
-            C2F(mgetnc) (&fd, &Ydim[7], (j = 3, &j), fmti, &ierr); /* read sci header */
-            Ytype    = Ydim[6]; /* data type        */
-            nPoints  = Ydim[7]; /* number of data   */
-            mY       = Ydim[8]; /* first dimension  */
-            nY       = 1;       /* second dimension */
-            YsubType = Ydim[9]; /* subtype          */
-        }
-        else
-        {
-            Coserror(_("Invalid variable type.\n"));
-            /*scicos_print(_("Invalid variable type.\n"));
-            set_block_error(-3);*/
-            C2F(mclose)(&fd, &res);
-            return;
-        }
-
-        /* check dimension for output port and variable */
-        if ((mY != my) || (nY != ny))
-        {
-            Coserror(_("Data dimensions are inconsistent:\n Variable size=[%d,%d] \nBlock output size=[%d,%d].\n"), mY, nY, my, ny);
-            /*set_block_error(-3);*/
-            C2F(mclose)(&fd, &res);
-            return;
-        }
-
-        /* check variable data type and output block data type */
-        if (Ytype == 1)
-        {
-            /*real/complex cases*/
-            switch (YsubType)
-            {
-                case 0:
-                    if (ytype != 10)
-                    {
-                        Coserror(_("Output should be of Real type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-
-                case 1:
-                    if (ytype != 11)
-                    {
-                        Coserror(_("Output should be of complex type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-            }
-        }
-        else if (Ytype == 8)
-        {
-            /*int cases*/
-            switch (YsubType)
-            {
-                case 1:
-                    if (ytype != 81)
-                    {
-                        scicos_print(_("Output should be of int8 type.\n"));
-                        set_block_error(-3);
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-
-                case 2:
-                    if (ytype != 82)
-                    {
-                        Coserror(_("Output should be of int16 type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-
-                case 4:
-                    if (ytype != 84)
-                    {
-                        Coserror(_("Output should be of int32 type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-
-                case 11:
-                    if (ytype != 811)
-                    {
-                        Coserror(_("Output should be of uint8 type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-
-                case 12:
-                    if (ytype != 812)
-                    {
-                        Coserror(_("Output should be of uint16 type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-
-                case 14:
-                    if (ytype != 814)
-                    {
-                        Coserror(_("Output should be of uint32 type.\n"));
-                        /*set_block_error(-3);*/
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    break;
-            }
-        }
-
-        /* allocation of the work structure of that block */
-        if ((*work = (fromwork_struct*) scicos_malloc(sizeof(fromwork_struct))) == NULL)
-        {
-            set_block_error(-16);
-            C2F(mclose)(&fd, &res);
-            return;
-        }
-        ptr = *work;
-        ptr->D = NULL;
-        ptr->workt = NULL;
-        ptr->work = NULL;
-
-        if (Ytype == 1)
-        {
-            /*real/complex case*/
-            switch (YsubType)
-            {
-                case 0 : /* Real */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(double))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_d = (SCSREAL_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_d, (j = nPoints * mY * nY, &j), fmtd, &ierr); /* read double data */
-                    break;
-                case 1:  /* complex */
-                    if ((ptr->work = (void *) scicos_malloc(2 * nPoints * mY * nY * sizeof(double))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_d = (SCSREAL_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_d, (j = 2 * nPoints * mY * nY, &j), fmtd, &ierr); /* read double data */
-                    break;
-            }
-        }
-        else if (Ytype == 8)
-        {
-            /*int case*/
-            switch (YsubType)
-            {
-                case 1 :/* int8 */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(char))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_c = (SCSINT8_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_c, (j = nPoints * mY * nY, &j), fmtc, &ierr); /* read char data */
-                    break;
-                case 2 :  /* int16 */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(short))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_s = (SCSINT16_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_s, (j = nPoints * mY * nY, &j), fmts, &ierr); /* read short data */
-                    break;
-                case 4 :   /* int32 */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(SCSINT32_COP))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_l = (SCSINT32_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_l, (j = nPoints * mY * nY, &j), fmtl, &ierr); /* read short data */
-                    break;
-                case 11 :   /* uint8 */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(unsigned char))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_uc = (SCSUINT8_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_uc, (j = nPoints * mY * nY, &j), fmtuc, &ierr); /* read short data */
-                    break;
-                case 12 : /* uint16 */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(unsigned short))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_us = (SCSUINT16_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_us, (j = nPoints * mY * nY, &j), fmtus, &ierr); /* read short data */
-                    break;
-                case 14 :  /* uint32 */
-                    if ((ptr->work = (void *) scicos_malloc(nPoints * mY * nY * sizeof(SCSUINT32_COP))) == NULL)
-                    {
-                        set_block_error(-16);
-                        scicos_free(ptr);
-                        *(block->work) = NULL;
-                        C2F(mclose)(&fd, &res);
-                        return;
-                    }
-                    ptr_ul = (SCSUINT32_COP *) ptr->work;
-                    C2F(mgetnc) (&fd, ptr_ul, (j = nPoints * mY * nY, &j), fmtul, &ierr); /* read short data */
-                    break;
-            }
-        }
-
-        /* check Hmat */
-        if (Ydim[6] == 17)
-        {
-            ptr->Hmat = 1;
-        }
-        else
-        {
-            ptr->Hmat = 0;
-        }
-
-        /* read t */
-        C2F(mgetnc) (&fd, &Ydim[0], (j = nsiz, &j), fmti, &ierr); /* read sci id */
-        C2F(mgetnc) (&fd, &Ydim[6], (j = 1, &j), fmti, &ierr); /* read sci type */
-        C2F(mgetnc) (&fd, &Ydim[7], (j = 3, &j), fmti, &ierr); /* read sci header */
-
-        if (nPoints != Ydim[7])
-        {
-            Coserror(_("The Time vector has a wrong size, expecting [%d, %d] and getting [%d, %d].\n"), nPoints, 1, Ydim[7], Ydim[8]);
-            /*set_block_error(-3);*/
-            *work = NULL;
-            scicos_free(ptr->work);
-            scicos_free(ptr);
-            C2F(mclose)(&fd, &res);
-            return;
-        }
-
-        if ((Ydim[6] != 1) | (Ydim[9] != 0))
-        {
-            scicos_print(_("The Time vector type is not ""double"".\n"));
-            set_block_error(-3);
-            *work = NULL;
-            scicos_free(ptr->work);
-            scicos_free(ptr);
-            C2F(mclose)(&fd, &res);
-            return;
-        }
-
-        if ((ptr->workt = (double *) scicos_malloc(nPoints * sizeof(double))) == NULL)
-        {
-            set_block_error(-16);
-            *work = NULL;
-            scicos_free(ptr->work);
-            scicos_free(ptr);
-            C2F(mclose)(&fd, &res);
-            return;
-        }
-        ptr_T = (SCSREAL_COP *) ptr->workt;
-        C2F(mgetnc) (&fd, ptr_T, (j = nPoints, &j), fmtd, &ierr); /* read data of t */
-
-        /* close the file*/
-        C2F(mclose)(&fd, &res);
-
-        /*================================*/
-        /* check for an increasing time data */
-        for (j = 0; j < nPoints - 1; j++)
-        {
-            if (ptr_T[j] > ptr_T[j + 1])
-            {
-                Coserror(_("The time vector should be an increasing vector.\n"));
-                /*set_block_error(-3);*/
-                *work = NULL;
-                scicos_free(ptr->workt);
-                scicos_free(ptr->work);
-                scicos_free(ptr);
-                return;
-            }
-        }
-        /*=================================*/
-        if ((Method > 1) && (Ytype == 1) && (!ptr->Hmat))
-        {
-            /* double or complex */
-            if (YsubType == 0) /*real*/
-            {
-                if ((ptr->D = (double *) scicos_malloc(nPoints * mY * sizeof(double))) == NULL)
-                {
-                    set_block_error(-16);
-                    *work = NULL;
-                    scicos_free(ptr->workt);
-                    scicos_free(ptr->work);
-                    scicos_free(ptr);
-                    return;
-                }
-            }
-            else
-            {
-                /*complex*/
-                if ((ptr->D = (double *) scicos_malloc(2 * nPoints * mY * sizeof(double))) == NULL)
-                {
-                    set_block_error(-16);
-                    *work = NULL;
-                    scicos_free(ptr->workt);
-                    scicos_free(ptr->work);
-                    scicos_free(ptr);
-                    return;
-                }
-            }
-
-            if ((spline = (double *) scicos_malloc((3 * nPoints - 2) * sizeof(double))) == NULL)
-            {
-                Coserror(_("Allocation problem in spline.\n"));
-                /*set_block_error(-16);*/
-                *work = NULL;
-                scicos_free(ptr->D);
-                scicos_free(ptr->workt);
-                scicos_free(ptr->work);
-                scicos_free(ptr);
-                return;
-            }
-
-            A_d  = spline;
-            A_sd = A_d  + nPoints;
-            qdy  = A_sd + nPoints - 1;
-
-            for (j = 0; j < mY; j++)
-            {
-                /* real part */
-                for (i = 0; i <= nPoints - 2; i++)
-                {
-                    A_sd[i] = 1.0 / (ptr_T[i + 1] - ptr_T[i]);
-                    qdy[i]  = (ptr_d[i + 1 + j * nPoints] - ptr_d[i + j * nPoints]) * A_sd[i] * A_sd[i];
-                }
-
-                for (i = 1; i <= nPoints - 2; i++)
-                {
-                    A_d[i] = 2.0 * (A_sd[i - 1] + A_sd[i]);
-                    ptr->D[i + j * nPoints] = 3.0 * (qdy[i - 1] + qdy[i]);
-                }
-
-                if (Method == 2)
-                {
-                    A_d[0] =  2.0 * A_sd[0];
-                    ptr->D[0 + j * nPoints] = 3.0 * qdy[0];
-                    A_d[nPoints - 1] =  2.0 * A_sd[nPoints - 2];
-                    ptr->D[nPoints - 1 + j * nPoints] =  3.0 * qdy[nPoints - 2];
-                    Mytridiagldltsolve(A_d, A_sd, &ptr->D[j * nPoints], nPoints);
-                }
-
-                if (Method == 3)
-                {
-                    /*  s'''(x(2)-) = s'''(x(2)+) */
-                    r = A_sd[1] / A_sd[0];
-                    A_d[0] = A_sd[0] / (1.0 + r);
-                    ptr->D[j * nPoints] = ((3.0 * r + 2.0) * qdy[0] + r * qdy[1]) / ((1.0 + r) * (1.0 + r));
-                    /*  s'''(x(n-1)-) = s'''(x(n-1)+) */
-                    r = A_sd[nPoints - 3] / A_sd[nPoints - 2];
-                    A_d[nPoints - 1] = A_sd[nPoints - 2] / (1.0 + r);
-                    ptr->D[nPoints - 1 + j * nPoints] = \
-                                                        ((3.0 * r + 2.0) * qdy[nPoints - 2] + r * qdy[nPoints - 3]) / ((1.0 + r) * (1.0 + r));
-                    Mytridiagldltsolve(A_d, A_sd, &ptr->D[j * nPoints], nPoints);
-                }
-            }
-
-            if (YsubType == 1)
-            {
-                /* imag part */
-                for (j = 0; j < mY; j++)
-                {
-                    for (i = 0; i <= nPoints - 2; i++)
-                    {
-                        A_sd[i] = 1.0 / (ptr_T[i + 1] - ptr_T[i]);
-                        qdy[i]  = (ptr_d[nPoints + i + 1 + j * nPoints] - ptr_d[nPoints + i + j * nPoints]) * A_sd[i] * A_sd[i];
-                    }
-
-                    for (i = 1; i <= nPoints - 2; i++)
-                    {
-                        A_d[i] = 2.0 * (A_sd[i - 1] + A_sd[i]);
-                        ptr->D[i + j * nPoints + nPoints] = 3.0 * (qdy[i - 1] + qdy[i]);
-                    }
-
-                    if (Method == 2)
-                    {
-                        A_d[0] =  2.0 * A_sd[0];
-                        ptr->D[nPoints + 0 + j * nPoints] = 3.0 * qdy[0];
-                        A_d[nPoints - 1] =  2.0 * A_sd[nPoints - 2];
-                        ptr->D[nPoints + nPoints - 1 + j * nPoints] =  3.0 * qdy[nPoints - 2];
-                        Mytridiagldltsolve(A_d, A_sd, &ptr->D[nPoints + j * nPoints], nPoints);
-                    }
-
-                    if (Method == 3)
-                    {
-                        /*  s'''(x(2)-) = s'''(x(2)+) */
-                        r = A_sd[1] / A_sd[0];
-                        A_d[0] = A_sd[0] / (1.0 + r);
-                        ptr->D[nPoints + j * nPoints] = ((3.0 * r + 2.0) * qdy[0] + r * qdy[1]) / ((1.0 + r) * (1.0 + r));
-                        /*  s'''(x(n-1)-) = s'''(x(n-1)+) */
-                        r = A_sd[nPoints - 3] / A_sd[nPoints - 2];
-                        A_d[nPoints - 1] = A_sd[nPoints - 2] / (1.0 + r);
-                        ptr->D[nPoints + nPoints - 1 + j * nPoints] = \
-                                ((3.0 * r + 2.0) * qdy[nPoints - 2] + r * qdy[nPoints - 3]) / ((1.0 + r) * (1.0 + r));
-                        Mytridiagldltsolve(A_d, A_sd, &ptr->D[nPoints + j * nPoints], nPoints);
-                    }
-                }
-            }
-
-            scicos_free(spline);
-        }
-        /*===================================*/
-        cnt1 = nPoints - 1;
-        cnt2 = nPoints;
-        for (i = 0; i < nPoints; i++)
-        {
-            /* finding the first positive time instant */
-            if (ptr->workt[i] >= 0 )
-            {
-                cnt1 = i - 1;
-                cnt2 = i;
-                break;
-            }
-        }
-        ptr->nPoints = nPoints;
-        ptr->Yt = Ytype;
-        ptr->Yst = YsubType;
-        ptr->cnt1 = cnt1;
-        ptr->cnt2 = cnt2;
-        ptr->EVindex = 0;
-        ptr->PerEVcnt = 0;
-        ptr->firstevent = 1;
-        return;
-        /*******************************************************/
-        /*******************************************************/
-    }
-    else if (flag == 1)
-    {
-        /* output computation */
-
-
-
-        /* retrieve ptr of the structure of that block */
-        ptr = *work;
-        nPoints = ptr->nPoints;
-        cnt1 = ptr->cnt1;
-        cnt2 = ptr->cnt2;
-        EVindex = ptr->EVindex;
-        PerEVcnt = ptr->PerEVcnt;
-
-        /* get current simulation time */
-        t = get_scicos_time();
-        t1 = t;
-
-        if (ZC == 1)
-        {
-            /*zero crossing enable*/
-            if (OutEnd == 2)
-            {
-                if (PerEVcnt > 0)
-                {
-                    // We ran out of value and OutEnd is 2 (Repeat)
-                    // Use fake time within our range.
-                    t -= (PerEVcnt) * TP;
-                }
-                inow = nPoints - 1;
-            }
-            else
-            {
-                inow = nPoints + 1; // Arbitrary value more than nPoints, will be overwritten if needed.
-            }
-            for (i = cnt1 ; i < nPoints ; i++)
-            {
-                if (i == -1)
-                {
-                    continue;
-                }
-                if (t <= ptr->workt[i])
-                {
-                    if (t < ptr->workt[i])
-                    {
-                        inow = i - 1;
-                    }
-                    else
-                    {
-                        inow = i;
-                    }
-                    if (inow < cnt2)
-                    {
-                        cnt2 = inow;
-                    }
-                    else
-                    {
-                        cnt1 = cnt2;
-                        cnt2 = inow;
-                    }
-                    break;
-                }
-            }
-        }
-        else   /*zero crossing disable*/
-        {
-            if (OutEnd == 2)
-            {
-                if (TP != 0)
-                {
-                    r = floor((t / TP));
-                }
-                else
-                {
-                    r = 0;
-                }
-                t -= ((int)r) * TP;
-                inow = nPoints - 1;
-            }
-            else
-            {
-                inow = nPoints + 1; // Arbitrary valuemore than nPoints, will be overwritten if needed.
-            }
-            // Look in time value table a range to have current time in.
-            // take care about exact values.
-            for (i = 0 ; i < nPoints ; i++)
-            {
-                if (t <= ptr->workt[i])
-                {
-                    if (t < ptr->workt[i])
-                    {
-                        inow = i - 1;
-                    }
-                    else
-                    {
-                        inow = i;
-                    }
-                    break;
-                }
-            }
-        }
-
-        ptr->cnt1 = cnt1;
-        ptr->cnt2 = cnt2;
-        ptr->EVindex = EVindex;
-        ptr->PerEVcnt = PerEVcnt;
-
-        /***************************/
-        /* hypermatrix case */
-        if (ptr->Hmat)
-        {
-
-            for (j = 0; j < my * ny; j++)
-            {
-                if (ptr->Yt == 1)
-                {
-                    if (ptr->Yst == 0)
-                    {
-                        /* real case */
-                        y_d = GetRealOutPortPtrs(block, 1);
-                        ptr_d = (double*) ptr->work;
-
-                        if (inow > nPoints)
-                        {
-                            if (OutEnd == 0)
-                            {
-                                y_d[j] = 0.0; /* outputs set to zero */
-                            }
-                            else if (OutEnd == 1)
-                            {
-                                y_d[j] = ptr_d[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                            }
-                        }
-                        else
-                        {
-                            if (inow < 0)
-                            {
-                                y_d[j] = 0.0;
-                            }
-                            else
-                            {
-                                y_d[j] = ptr_d[inow * ny * my + j];
-                            }
-                        }
-                    }
-                    else
-                    {
-                        /* complexe case */
-                        y_d = GetRealOutPortPtrs(block, 1);
-                        y_cd = GetImagOutPortPtrs(block, 1);
-                        ptr_d = (double*) ptr->work;
-
-                        if (inow > nPoints)
-                        {
-                            if (OutEnd == 0)
-                            {
-                                y_d[j] = 0.0; /* outputs set to zero */
-                                y_cd[j] = 0.0; /* outputs set to zero */
-                            }
-                            else if (OutEnd == 1)
-                            {
-                                y_d[j] = ptr_d[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                y_cd[j] = ptr_d[nPoints * my * ny + (nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                            }
-                        }
-                        else
-                        {
-                            if (inow < 0)
-                            {
-                                y_d[j] = 0.0; /* outputs set to zero */
-                                y_cd[j] = 0.0; /* outputs set to zero */
-                            }
-                            else
-                            {
-                                y_d[j] = ptr_d[inow * ny * my + j];
-                                y_cd[j] = ptr_d[nPoints * my * ny + inow * ny * my + j];
-                            }
-                        }
-                    }
-                }
-                else if (ptr->Yt == 8)
-                {
-                    switch (ptr->Yst)
-                    {
-                        case 1:
-                            /* ---------------------int8 char  ---------------------------- */
-                            y_c = Getint8OutPortPtrs(block, 1);
-                            ptr_c = (char*) ptr->work;
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_c[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_c[j] = ptr_c[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                }
-                            }
-                            else
-                            {
-                                if (inow < 0)
-                                {
-                                    y_c[j] = 0;
-                                }
-                                else
-                                {
-                                    y_c[j] = ptr_c[inow * ny * my + j];
-                                }
-                            }
-                            break;
-
-                        case 2:
-                            /* ---------------------int16 short--------------------- */
-                            y_s = Getint16OutPortPtrs(block, 1);
-                            ptr_s = (short*) ptr->work;
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_s[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_s[j] = ptr_s[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                }
-                            }
-                            else
-                            {
-                                if (inow < 0)
-                                {
-                                    y_s[j] = 0;
-                                }
-                                else
-                                {
-                                    y_s[j] = ptr_s[inow * ny * my + j];
-                                }
-                            }
-                            break;
-
-                        case 4:
-                            /* ---------------------int32 long--------------------- */
-                            y_l = Getint32OutPortPtrs(block, 1);
-                            ptr_l = (SCSINT32_COP *) ptr->work;
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_l[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_l[j] = ptr_l[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                }
-                            }
-                            else
-                            {
-                                if (inow < 0)
-                                {
-                                    y_l[j] = 0;
-                                }
-                                else
-                                {
-                                    y_l[j] = ptr_l[inow * ny * my + j];
-                                }
-                            }
-                            break;
-
-                        case 11:
-                            /*--------------------- uint8 uchar---------------------*/
-                            y_uc = Getuint8OutPortPtrs(block, 1);
-                            ptr_uc = (unsigned char*) ptr->work;
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_uc[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_uc[j] = ptr_uc[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                }
-                            }
-                            else
-                            {
-                                if (inow < 0)
-                                {
-                                    y_uc[j] = 0;
-                                }
-                                else
-                                {
-                                    y_uc[j] = ptr_uc[inow * ny * my + j];
-                                }
-                            }
-                            break;
-
-                        case 12:
-                            /* ---------------------uint16 ushort--------------------- */
-                            y_us = Getuint16OutPortPtrs(block, 1);
-                            ptr_us = (unsigned short*) ptr->work;
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_us[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_us[j] = ptr_us[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                }
-                            }
-                            else
-                            {
-                                if (inow < 0)
-                                {
-                                    y_us[j] = 0;
-                                }
-                                else
-                                {
-                                    y_us[j] = ptr_us[inow * ny * my + j];
-                                }
-                            }
-                            break;
-
-                        case 14:
-                            /* ---------------------uint32 ulong--------------------- */
-                            y_ul = Getuint32OutPortPtrs(block, 1);
-                            ptr_ul = (SCSUINT32_COP *) ptr->work;
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_ul[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_ul[j] = ptr_ul[(nPoints - 1) * ny * my + j]; /* hold outputs at the end */
-                                }
-                            }
-                            else
-                            {
-                                if (inow < 0)
-                                {
-                                    y_ul[j] = 0;
-                                }
-                                else
-                                {
-                                    y_ul[j] = ptr_ul[inow * ny * my + j];
-                                }
-                            }
-                            break;
-                    }
-                }
-            } /* for j loop */
-        }
-        /****************************/
-        /* scalar of vectorial case */
-        else
-        {
-            for (j = 0; j < my; j++)
-            {
-                if (ptr->Yt == 1)
-                {
-                    if ((ptr->Yst == 0) || (ptr->Yst == 1))
-                    {
-                        /*  if Real or complex*/
-                        y_d = GetRealOutPortPtrs(block, 1);
-                        ptr_d = (double*) ptr->work;
-                        ptr_D = (double*) ptr->D;
-
-                        if (inow > nPoints)
-                        {
-                            if (OutEnd == 0)
-                            {
-                                y_d[j] = 0.0; /* outputs set to zero */
-                            }
-                            else if (OutEnd == 1)
-                            {
-                                y_d[j] = ptr_d[nPoints - 1 + (j) * nPoints]; /* hold outputs at the end */
-                            }
-                        }
-                        else if (Method == 0)
-                        {
-                            if (inow < 0)
-                            {
-                                y_d[j] = 0.0;
-                            }
-                            else
-                            {
-                                y_d[j] = ptr_d[inow + (j) * nPoints];
-                            }
-                        }
-                        else if (Method == 1)
-                        {
-                            if (inow < 0)
-                            {
-                                inow = 0;
-                            }
-                            t1 = ptr->workt[inow];
-                            t2 = ptr->workt[inow + 1];
-                            y1 = ptr_d[inow + j * nPoints];
-                            y2 = ptr_d[inow + 1 + j * nPoints];
-                            y_d[j] = (y2 - y1) * (t - t1) / (t2 - t1) + y1;
-                        }
-                        else if (Method >= 2)
-                        {
-                            t1 = ptr->workt[inow];
-                            t2 = ptr->workt[inow + 1];
-                            y1 = ptr_d[inow + j * nPoints];
-                            y2 = ptr_d[inow + 1 + j * nPoints];
-                            d1 = ptr_D[inow + j * nPoints];
-                            d2 = ptr_D[inow + 1 + j * nPoints];
-                            scicos_evalhermite(&t, &t1, &t2, &y1, &y2, &d1, &d2, &h, &dh, &ddh, &dddh, &inow);
-                            y_d[j] = h;
-                        }
-                    }
-                    if (ptr->Yst == 1)
-                    {
-                        /*  --------------complex----------------------*/
-                        y_cd = GetImagOutPortPtrs(block, 1);
-                        if (inow > nPoints)
-                        {
-                            if (OutEnd == 0)
-                            {
-                                y_cd[j] = 0.0; /* outputs set to zero*/
-                            }
-                            else if (OutEnd == 1)
-                            {
-                                y_cd[j] = ptr_d[nPoints * my + nPoints - 1 + (j) * nPoints]; // hold outputs at the end
-                            }
-                        }
-                        else if (Method == 0)
-                        {
-                            if (inow < 0)
-                            {
-                                y_cd[j] = 0.0; /* outputs set to zero */
-                            }
-                            else
-                            {
-                                y_cd[j] = ptr_d[nPoints * my + inow + (j) * nPoints];
-                            }
-                        }
-                        else if (Method == 1)
-                        {
-                            if (inow < 0)
-                            {
-                                inow = 0;
-                            } /* extrapolation for 0<t<X(0) */
-                            t1 = ptr->workt[inow];
-                            t2 = ptr->workt[inow + 1];
-                            y1 = ptr_d[nPoints * my + inow + j * nPoints];
-                            y2 = ptr_d[nPoints * my + inow + 1 + j * nPoints];
-                            y_cd[j] = (y2 - y1) * (t - t1) / (t2 - t1) + y1;
-                        }
-                        else if (Method >= 2)
-                        {
-                            t1 = ptr->workt[inow];
-                            t2 = ptr->workt[inow + 1];
-                            y1 = ptr_d[inow + j * nPoints + nPoints];
-                            y2 = ptr_d[inow + 1 + j * nPoints + nPoints];
-                            d1 = ptr_D[inow + j * nPoints + nPoints];
-                            d2 = ptr_D[inow + 1 + j * nPoints + nPoints];
-                            scicos_evalhermite(&t, &t1, &t2, &y1, &y2, &d1, &d2, &h, &dh, &ddh, &dddh, &inow);
-                            y_cd[j] = h;
-                        }
-                    }
-                }
-                else if (ptr->Yt == 8)
-                {
-                    switch (ptr->Yst)
-                    {
-                        case 1: /* ---------------------int8 char  ---------------------------- */
-                            y_c = Getint8OutPortPtrs(block, 1);
-                            ptr_c = (char*) ptr->work;
-                            /*y_c[j]=ptr_c[inow+(j)*nPoints];*/
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_c[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_c[j] = ptr_c[nPoints - 1 + (j) * nPoints]; /* hold outputs at the end */
-                                }
-                            }
-                            else if (Method == 0)
-                            {
-                                if (inow < 0)
-                                {
-                                    y_c[j] = 0;
-                                }
-                                else
-                                {
-                                    y_c[j] = ptr_c[inow + (j) * nPoints];
-                                }
-                            }
-                            else if (Method >= 1)
-                            {
-                                if (inow < 0)
-                                {
-                                    inow = 0;
-                                }
-                                t1 = ptr->workt[inow];
-                                t2 = ptr->workt[inow + 1];
-                                y1 = (double)ptr_c[inow + j * nPoints];
-                                y2 = (double)ptr_c[inow + 1 + j * nPoints];
-                                y_c[j] = (char)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
-                            }
-                            break;
-                        case 2:
-                            /* ---------------------int16 short--------------------- */
-                            y_s = Getint16OutPortPtrs(block, 1);
-                            ptr_s = (short*) ptr->work;
-                            /* y_s[j]=ptr_s[inow+(j)*nPoints]; */
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_s[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_s[j] = ptr_s[nPoints - 1 + (j) * nPoints]; // hold outputs at the end
-                                }
-                            }
-                            else if (Method == 0)
-                            {
-                                if (inow < 0)
-                                {
-                                    y_s[j] = 0;
-                                }
-                                else
-                                {
-                                    y_s[j] = ptr_s[inow + (j) * nPoints];
-                                }
-                            }
-                            else if (Method >= 1)
-                            {
-                                if (inow < 0)
-                                {
-                                    inow = 0;
-                                }
-                                t1 = ptr->workt[inow];
-                                t2 = ptr->workt[inow + 1];
-                                y1 = (double)ptr_s[inow + j * nPoints];
-                                y2 = (double)ptr_s[inow + 1 + j * nPoints];
-                                y_s[j] = (short)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
-                            }
-                            break;
-                        case 4:
-                            /* ---------------------int32 long--------------------- */
-                            y_l = Getint32OutPortPtrs(block, 1);
-                            ptr_l = (SCSINT32_COP *) ptr->work;
-                            /*y_l[j]=ptr_l[inow+(j)*nPoints];*/
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_l[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_l[j] = ptr_l[nPoints - 1 + (j) * nPoints]; /* hold outputs at the end */
-                                }
-                            }
-                            else if (Method == 0)
-                            {
-                                if (inow < 0)
-                                {
-                                    y_l[j] = 0;
-                                }
-                                else
-                                {
-                                    y_l[j] = ptr_l[inow + (j) * nPoints];
-                                }
-                            }
-                            else if (Method >= 1)
-                            {
-                                t1 = ptr->workt[inow];
-                                t2 = ptr->workt[inow + 1];
-                                y1 = (double)ptr_l[inow + j * nPoints];
-                                y2 = (double)ptr_l[inow + 1 + j * nPoints];
-                                y_l[j] = (SCSINT32_COP)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
-                            }
-                            break;
-                        case 11: /*--------------------- uint8 uchar---------------------*/
-                            y_uc = Getuint8OutPortPtrs(block, 1);
-                            ptr_uc = (unsigned char*) ptr->work;
-                            /*y_uc[j]=ptr_uc[inow+(j)*nPoints];*/
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_uc[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_uc[j] = ptr_uc[nPoints - 1 + (j) * nPoints]; /* hold outputs at the end */
-                                }
-                            }
-                            else if (Method == 0)
-                            {
-                                if (inow < 0)
-                                {
-                                    y_uc[j] = 0;
-                                }
-                                else
-                                {
-                                    y_uc[j] = ptr_uc[inow + (j) * nPoints];
-                                }
-                            }
-                            else if (Method >= 1)
-                            {
-                                t1 = ptr->workt[inow];
-                                t2 = ptr->workt[inow + 1];
-                                y1 = (double)ptr_uc[inow + j * nPoints];
-                                y2 = (double)ptr_uc[inow + 1 + j * nPoints];
-                                y_uc[j] = (unsigned char)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
-                            }
-                            break;
-                        case 12:
-                            /* ---------------------uint16 ushort--------------------- */
-                            y_us = Getuint16OutPortPtrs(block, 1);
-                            ptr_us = (unsigned short*) ptr->work;
-                            /* y_us[j]=ptr_us[inow+(j)*nPoints]; */
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_us[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_us[j] = ptr_us[nPoints - 1 + (j) * nPoints]; /* hold outputs at the end */
-                                }
-                            }
-                            else if (Method == 0)
-                            {
-                                if (inow < 0)
-                                {
-                                    y_us[j] = 0;
-                                }
-                                else
-                                {
-                                    y_us[j] = ptr_us[inow + (j) * nPoints];
-                                }
-                            }
-                            else if (Method >= 1)
-                            {
-                                t1 = ptr->workt[inow];
-                                t2 = ptr->workt[inow + 1];
-                                y1 = (double)ptr_us[inow + j * nPoints];
-                                y2 = (double)ptr_us[inow + 1 + j * nPoints];
-                                y_us[j] = (unsigned short)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
-                            }
-                            break;
-                        case 14:
-                            /* ---------------------uint32 ulong--------------------- */
-                            y_ul = Getuint32OutPortPtrs(block, 1);
-                            ptr_ul = (SCSUINT32_COP *) ptr->work;
-                            /* y_ul[j]=ptr_ul[inow+(j)*nPoints]; */
-                            if (inow > nPoints)
-                            {
-                                if (OutEnd == 0)
-                                {
-                                    y_ul[j] = 0; /* outputs set to zero */
-                                }
-                                else if (OutEnd == 1)
-                                {
-                                    y_ul[j] = ptr_ul[nPoints - 1 + (j) * nPoints]; /* hold outputs at the end */
-                                }
-                            }
-                            else if (Method == 0)
-                            {
-                                if (inow < 0)
-                                {
-                                    y_ul[j] = 0;
-                                }
-                                else
-                                {
-                                    y_ul[j] = ptr_ul[inow + (j) * nPoints];
-                                }
-                            }
-                            else if (Method >= 1)
-                            {
-                                t1 = ptr->workt[inow];
-                                t2 = ptr->workt[inow + 1];
-                                y1 = (double)ptr_ul[inow + j * nPoints];
-                                y2 = (double)ptr_ul[inow + 1 + j * nPoints];
-                                y_ul[j] = (SCSUINT32_COP)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
-                            }
-                            break;
-                    }
-                }
-            } /* for j loop */
-        }
-        /********************************************************************/
-    }
-    else if (flag == 3)
-    {
-        /* event date computation */
-        /* retrieve ptr of the structure of that block */
-        ptr = *work;
-        nPoints = ptr->nPoints;
-        cnt1 = ptr->cnt1;
-        cnt2 = ptr->cnt2;
-        EVindex = ptr->EVindex;
-        PerEVcnt = ptr->PerEVcnt;
-
-        /* get current simulation time */
-        t = get_scicos_time();
-
-        if (ZC == 1)
-        {
-            /* generate Events only if ZC is active */
-            if ((Method == 1) || (Method == 0))
-            {
-                /*-------------------------*/
-                if (ptr->firstevent == 1)
-                {
-                    jfirst = nPoints - 1; /* finding first positive time instant */
-                    for (j = 0; j < nPoints; j++)
-                    {
-                        if (ptr->workt[j] > 0)
-                        {
-                            jfirst = j;
-                            break;
-                        }
-                    }
-                    block->evout[0] = ptr->workt[jfirst];
-                    EVindex = jfirst;
-                    ptr->EVindex = EVindex;
-                    ptr->firstevent = 0;
-                    return;
-                }
-                /*------------------------*/
-                i = EVindex;
-                /*------------------------*/
-                if (i < nPoints - 1)
-                {
-                    block->evout[0] = ptr->workt[i + 1] - ptr->workt[i];
-                    EVindex = i + 1;
-                }
-                /*------------------------*/
-                if (i == nPoints - 1)
-                {
-                    if (OutEnd == 2)
-                    {
-                        /*  Periodic*/
-                        cnt1 = -1;
-                        cnt2 = 0;
-                        PerEVcnt++;/* When OutEnd==2 (perodic output)*/
-                        jfirst = nPoints - 1; /* finding first positive time instant */
-                        for (j = 0; j < nPoints; j++)
-                        {
-                            if (ptr->workt[j] >= 0)
-                            {
-                                jfirst = j;
-                                break;
-                            }
-                        }
-                        block->evout[0] = ptr->workt[jfirst];
-                        EVindex = jfirst;
-                    }
-                }
-                /*-------------------------- */
-            }
-            else if (Method <= 3)
-            {
-                if (ptr->firstevent == 1)
-                {
-                    block->evout[0] = TP;
-                    ptr->firstevent = 0;
-                }
-                else
-                {
-                    if (OutEnd == 2)
-                    {
-                        block->evout[0] = TP;
-                    }
-                    PerEVcnt++;
-                }
-                cnt1 = -1;
-                cnt2 = 0;
-            }
-            ptr->cnt1 = cnt1;
-            ptr->cnt2 = cnt2;
-            ptr->EVindex = EVindex;
-            ptr->PerEVcnt = PerEVcnt;
-        }
-        /***********************************************************************/
-    }
-    else if (flag == 5)
-    {
-        /* finish */
-        ptr = *work;
-        if (ptr != NULL)
-        {
-            if (ptr->D != NULL)
-            {
-                scicos_free(ptr->D);
-            }
-            if (ptr->work != NULL)
-            {
-                scicos_free(ptr->work);
-            }
-            if (ptr->workt != NULL)
-            {
-                scicos_free(ptr->workt);
-            }
-            scicos_free(ptr);
-        }
-        /***********************************************************************/
-    }
-    else if (flag == 6)
-    {
-        /* re-init */
-
-        // finish then init
-        fromws_c(block, 5);
-        fromws_c(block, 4);
-    }
-    /*************************************************************************/
-#endif
-}
-/*--------------------------------------------------------------------------*/
-static int Ishm(int *fd, int *Ytype, int *nPoints, int *my, int *ny, int *YsubType)
-{
-    int *ptr_i;
-    int j, ierr;
-
-    /*work array to store header of hypermat*/
-    if ((ptr_i = (int *) scicos_malloc(37 * sizeof(int))) == NULL)
-    {
-        return 0;
-    }
-
-    C2F(mgetnc) (fd, ptr_i, (j = 37, &j), fmti, &ierr); /* read sci id */
-    if (ierr != 0)
-    {
-        return 0;
-    }
-
-    if ((ptr_i[0] != 3)  || \
-            (ptr_i[1] != 1)  || \
-            (ptr_i[5] != 10) || \
-            (ptr_i[6] != 1)  || \
-            (ptr_i[7] != 3)  || \
-            (ptr_i[8] != 0)  || \
-            (ptr_i[9] != 1)  || \
-            (ptr_i[10] != ptr_i[9] + 2)  || \
-            (ptr_i[11] != ptr_i[10] + 4) || \
-            (ptr_i[12] != ptr_i[11] + 7) || \
-            (ptr_i[13] != 17) || \
-            (ptr_i[14] != 22) || \
-            (ptr_i[15] != 13) || \
-            (ptr_i[16] != 18) || \
-            (ptr_i[17] != 22) || \
-            (ptr_i[18] != 28) || \
-            (ptr_i[19] != 14) || \
-            (ptr_i[20] != 23) || \
-            (ptr_i[21] != 29) || \
-            (ptr_i[22] != 27) || \
-            (ptr_i[23] != 18) || \
-            (ptr_i[24] != 14) || \
-            (ptr_i[25] != 28) || \
-            (ptr_i[26] != 8)  || \
-            (ptr_i[27] != 1)  || \
-            (ptr_i[28] != 3)  || \
-            (ptr_i[29] != 4))
-    {
-        Coserror(_("Invalid variable type : error in hypermat scilab coding.\n"));
-        return 0;
-    }
-
-    *my      = ptr_i[30];    /*37*/
-    *ny      = ptr_i[31];    /*38*/
-    *nPoints = ptr_i[32];    /*39*/
-    *Ytype   = ptr_i[33];    /*40*/
-
-    if ((ptr_i[34] != ptr_i[30]*ptr_i[31]*ptr_i[32]) || \
-            (ptr_i[35] != 1))
-    {
-        Coserror(_("Invalid variable type : error in hypermat scilab coding.\n"));
-        scicos_free(ptr_i);
-        return 0;
-    }
-
-    *YsubType = ptr_i[36];   /*43*/
-
-    scicos_free(ptr_i);
-    return 1;
-}
-/*--------------------------------------------------------------------------*/
-static int Mytridiagldltsolve(double *dA, double * lA, double * B, int N)
-{
-    double Temp;
-    int j;
-
-    for (j = 1; j <= N - 1; ++j)
-    {
-        Temp = lA[j - 1];
-        lA[j - 1] /= dA[j - 1];
-        B[j] -= lA[j - 1] * B[j - 1];
-        dA[j] -= Temp * lA[j - 1];
-    }
-
-    B[N - 1] /= dA[N - 1];
-    for (j = N - 2; j >= 0; --j)
-    {
-        B[j] = - lA[j] * B[j + 1] + B[j] / dA[j];
-    }
-
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
index aac1d7f..76e3ca0 100644 (file)
@@ -228,6 +228,7 @@ lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MA
     <ClCompile Include="acos_blk.c" />
     <ClCompile Include="acosh_blk.c" />
     <ClCompile Include="..\cpp\affich2.cpp" />
+    <ClCompile Include="..\cpp\fromws.cpp" />
     <ClCompile Include="..\cpp\scoUtils.cpp" />
     <ClCompile Include="..\jni\AfficheBlock.cpp" />
     <ClCompile Include="andlog.c" />
@@ -339,7 +340,6 @@ lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MA
     <ClCompile Include="exttriu.c" />
     <ClCompile Include="exttriuz.c" />
     <ClCompile Include="foriterator.c" />
-    <ClCompile Include="fromws_c.c" />
     <ClCompile Include="gain.c" />
     <ClCompile Include="gainblk.c" />
     <ClCompile Include="gainblk_i16e.c" />
@@ -615,4 +615,4 @@ lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MA
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 1c2be30..aab5c2d 100644 (file)
@@ -38,6 +38,9 @@
     <ClCompile Include="..\cpp\affich2.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\cpp\fromws.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\jni\AfficheBlock.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="foriterator.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="fromws_c.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="gain.c">
       <Filter>Source Files</Filter>
     </ClCompile>
       <Filter>Resource Files</Filter>
     </ResourceCompile>
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/scilab/modules/scicos_blocks/src/cpp/fromws_c.cpp b/scilab/modules/scicos_blocks/src/cpp/fromws_c.cpp
new file mode 100644 (file)
index 0000000..a8de2e0
--- /dev/null
@@ -0,0 +1,1418 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+ *  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ */
+
+#include <cmath>
+#include <cstring>
+
+#include "Helpers.hxx"
+
+extern "C"
+{
+#include "api_scilab.h"
+#include "dynlib_scicos_blocks.h"
+#include "expandPathVariable.h"
+#include "scicos_block4.h"
+#include "scicos_evalhermite.h"
+#include "scicos.h"
+#include "sci_mem_alloc.h" /* FREE */
+#include "h5_fileManagement.h"
+#include "h5_readDataFromFile.h"
+#include "h5_attributeConstants.h"
+
+#include "localization.h"
+
+    SCICOS_BLOCKS_IMPEXP void fromws_c(scicos_block* block, int flag);
+}
+
+/*--------------------------------------------------------------------------*/
+/* work struct for a block */
+typedef struct
+{
+    int nPoints;
+    int Hmat;
+    int Yt;
+    int Yst;
+    int cnt1;
+    int cnt2;
+    int EVindex;
+    int PerEVcnt;
+    int firstevent;
+    double* D;
+    void* work;
+    double* workt;
+} fromwork_struct;
+/*--------------------------------------------------------------------------*/
+static int Mytridiagldltsolve(double* &dA, double* &lA, double* &B, int N)
+{
+    for (int j = 1; j <= N - 1; ++j)
+    {
+        double Temp = lA[j - 1];
+        lA[j - 1] /= dA[j - 1];
+        B[j] -= lA[j - 1] * B[j - 1];
+        dA[j] -= Temp * lA[j - 1];
+    }
+
+    B[N - 1] /= dA[N - 1];
+    for (int j = N - 2; j >= 0; --j)
+    {
+        B[j] = - lA[j] * B[j + 1] + B[j] / dA[j];
+    }
+
+    return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+using namespace org_scilab_modules_xcos_block;
+
+/*--------------------------------------------------------------------------*/
+SCICOS_BLOCKS_IMPEXP void fromws_c(scicos_block* block, int flag)
+{
+    /* Retrieve dimensions of output port */
+    int my    = GetOutPortRows(block, 1); /* Number of rows of the output */
+    int ny    = GetOutPortCols(block, 1); /* Number of cols of the output */
+    int ytype = GetOutType(block, 1);     /* Output type */
+
+    /* Generic pointers */
+    double *y_d, *y_cd, *ptr_d = nullptr, *ptr_T, *ptr_D;
+    char *y_c, *ptr_c;
+    unsigned char *y_uc, *ptr_uc;
+    short int *y_s, *ptr_s;
+    unsigned short int *y_us, *ptr_us;
+    int *y_l, *ptr_l;
+    unsigned int *y_ul, *ptr_ul;
+
+    /* The struct pointer of the block */
+    fromwork_struct** work = (fromwork_struct**) block->work;
+    fromwork_struct* ptr = nullptr;
+
+    int Fnlength = block->ipar[0];
+    int Method   = block->ipar[1 + Fnlength];
+    int ZC       = block->ipar[2 + Fnlength];
+    int OutEnd   = block->ipar[3 + Fnlength];
+
+    switch (flag)
+    {
+        case 4 :
+        {
+            /* Init */
+
+            /* Convert Scilab code of the variable name to C string */
+
+            /* Path to "TMPDIR/Workspace/" */
+            const char* filePrefix = "TMPDIR/Workspace/";
+            const int prefixSize = strlen(filePrefix);
+
+            char FName[100];
+            for (int i = 0; i < Fnlength; ++i)
+            {
+                FName[i] = static_cast<char>(block->ipar[1 + i]);
+            }
+            FName[Fnlength] = '\0';
+
+            char* env = new char[prefixSize + Fnlength + 1];
+            strcpy(env, filePrefix);
+            strcpy(env + prefixSize, FName);
+            env[prefixSize + Fnlength] = '\0';
+
+            char* filename = expandPathVariable(env);
+            delete[] env;
+            int fd = 0, ierr = 0;
+            if (filename)
+            {
+                /* Open tmp file */
+                fd = openHDF5File(filename, 0);
+            }
+            FREE(filename);
+            filename = nullptr;
+
+            if (fd < 0)
+            {
+                Coserror(_("The '%s' variable does not exist.\n"), FName);
+                return;
+            }
+
+            // Manage version information
+            int iVersion = getSODFormatAttribute(fd);
+            if (iVersion != SOD_FILE_VERSION)
+            {
+                if (iVersion > SOD_FILE_VERSION)
+                {
+                    // Cannot read file with version more recent that me!
+                    Coserror(_("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), "fromws_c", SOD_FILE_VERSION, iVersion);
+                    return;
+                }
+            }
+
+            /* Read the variables contained in the file */
+            char* pstNameList[2];
+            int nbVar = getVariableNames(fd, pstNameList);
+            if (nbVar != 2)
+            {
+                Coserror(_("Erroneous saved file.\n"));
+                return;
+            }
+            if (strcmp(pstNameList[0], "t") != 0 || strcmp(pstNameList[1], "x") != 0)
+            {
+                Coserror(_("Erroneous saved file.\n"));
+                return;
+            }
+
+            /* Read x */
+            int xSetId = getDataSetIdFromName(fd, pstNameList[1]);
+            int xType = getScilabTypeFromDataSet(xSetId);
+
+            int nPoints, mX, nX = 1;
+            int xDims, xSubType;
+            if ((xType == 1) || (xType == 8))
+            {
+                int* pxDims = nullptr;
+                getDatasetInfo(xSetId, &xSubType, &xDims, pxDims);
+                pxDims = new int[xDims];
+                getDatasetInfo(xSetId, &xSubType, &xDims, pxDims);
+                nPoints = pxDims[0]; /* Number of data  */
+                mX = pxDims[1];      /* First dimension  */
+                if (xDims > 3)
+                {
+                    nX = pxDims[2];  /* Second dimension */
+                }
+                delete[] pxDims;
+                if (xType == 8)
+                {
+                    getDatasetPrecision(xSetId, &xSubType); /* For the integer case, overwrite xSubType */
+                }
+            }
+            else
+            {
+                Coserror(_("Invalid variable type.\n"));
+                /*scicos_print(_("Invalid variable type.\n"));
+                set_block_error(-3);*/
+                closeHDF5File(fd);
+                return;
+            }
+
+            /* Check dimension for output port and variable */
+            if ((mX != my) || (nX != ny))
+            {
+                Coserror(_("Data dimensions are inconsistent:\n Variable size=[%d,%d] \nBlock output size=[%d,%d].\n"), mX, nX, my, ny);
+                /*set_block_error(-3);*/
+                closeHDF5File(fd);
+                return;
+            }
+
+            /* Check variable data type and output block data type */
+            if (xType == 1)
+            {
+                /* real/complex cases */
+                switch (xSubType)
+                {
+                    case 0:
+                        if (ytype != 10)
+                        {
+                            Coserror(_("Output should be of Real type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+
+                    case 1:
+                        if (ytype != 11)
+                        {
+                            Coserror(_("Output should be of complex type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+                }
+            }
+            else if (xType == 8)
+            {
+                /* int cases */
+                switch (xSubType)
+                {
+                    case SCI_INT8:
+                        if (ytype != 81)
+                        {
+                            Coserror(_("Output should be of int8 type.\n"));
+                            set_block_error(-3);
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+
+                    case SCI_INT16:
+                        if (ytype != 82)
+                        {
+                            Coserror(_("Output should be of int16 type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+
+                    case SCI_INT32:
+                        if (ytype != 84)
+                        {
+                            Coserror(_("Output should be of int32 type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+
+                    case SCI_UINT8:
+                        if (ytype != 811)
+                        {
+                            Coserror(_("Output should be of uint8 type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+
+                    case SCI_UINT16:
+                        if (ytype != 812)
+                        {
+                            Coserror(_("Output should be of uint16 type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+
+                    case SCI_UINT32:
+                        if (ytype != 814)
+                        {
+                            Coserror(_("Output should be of uint32 type.\n"));
+                            /*set_block_error(-3);*/
+                            closeHDF5File(fd);
+                            return;
+                        }
+                        break;
+                }
+            }
+
+            /* Allocation of the work structure of that block */
+
+            *work = new fromwork_struct[sizeof(fromwork_struct)];
+            ptr = *work;
+            ptr->D = nullptr;
+            ptr->workt = nullptr;
+            ptr->work = nullptr;
+
+            if (xType == 1)
+            {
+                /* real/complex case */
+                switch (xSubType)
+                {
+                    case 0 : /* Real */
+                        ptr->work = new double[nPoints * mX * nX];
+                        ptr_d = (double*) ptr->work;
+                        ierr = readDoubleMatrix(xSetId, ptr_d);
+                        break;
+                    case 1 :  /* Complex */
+                        ptr->work = new double[nPoints * mX * nX];
+                        ptr_d = (double*) ptr->work;
+                        ierr = readDoubleComplexMatrix(xSetId, ptr_d, ptr_d + nPoints * mX * nX);
+                        break;
+                }
+            }
+            else if (xType == 8)
+            {
+                /* int case */
+                switch (xSubType)
+                {
+                    case SCI_INT8 :
+                        ptr->work = new char[nPoints * mX * nX];
+                        ptr_c = (char*) ptr->work;
+                        ierr = readInteger8Matrix(xSetId, ptr_c);
+                        break;
+                    case SCI_INT16 :
+                        ptr->work = new short int[nPoints * mX * nX];
+                        ptr_s = (short int*) ptr->work;
+                        ierr = readInteger16Matrix(xSetId, ptr_s);
+                        break;
+                    case SCI_INT32 :
+                        ptr->work = new int[nPoints * mX * nX];
+                        ptr_l = (int*) ptr->work;
+                        ierr = readInteger32Matrix(xSetId, ptr_l);
+                        break;
+                    case SCI_UINT8 :
+                        ptr->work = new unsigned char[nPoints * mX * nX];
+                        ptr_uc = (unsigned char*) ptr->work;
+                        ierr = readUnsignedInteger8Matrix(xSetId, ptr_uc);
+                        break;
+                    case SCI_UINT16 :
+                        ptr->work = new unsigned short int[nPoints * mX * nX];
+                        ptr_us = (unsigned short int*) ptr->work;
+                        ierr = readUnsignedInteger16Matrix(xSetId, ptr_us);
+                        break;
+                    case SCI_UINT32 :
+                        ptr->work = new unsigned int[nPoints * mX * nX];
+                        ptr_ul = (unsigned int*) ptr->work;
+                        ierr = readUnsignedInteger32Matrix(xSetId, ptr_ul);
+                        break;
+                }
+            }
+            if (ierr != 0)
+            {
+                Coserror(_("Cannot read the values field.\n"));
+                delete[] (char*) ptr->work;
+                delete[] ptr;
+                closeHDF5File(fd);
+            }
+
+            /* Check Hmat */
+            if (xDims > 2)
+            {
+                ptr->Hmat = 1;
+            }
+            else
+            {
+                ptr->Hmat = 0;
+            }
+
+            /* Read t */
+            int tSetId = getDataSetIdFromName(fd, pstNameList[0]);
+            int tType = getScilabTypeFromDataSet(tSetId);
+            if (tType != 1)
+            {
+                Coserror(_("The Time vector type is not ""double"".\n"));
+                set_block_error(-3);
+                *work = nullptr;
+                delete[] (char*) ptr->work;
+                delete[] ptr;
+                closeHDF5File(fd);
+                return;
+            }
+
+            int tDims, tComplex, *ptDims = nullptr;
+            getDatasetInfo(tSetId, &tComplex, &tDims, ptDims);
+            ptDims = new int[tDims];
+            getDatasetInfo(tSetId, &tComplex, &tDims, ptDims);
+            if (tComplex != 0)
+            {
+                Coserror(_("The Time vector type is complex.\n"));
+                set_block_error(-3);
+                *work = nullptr;
+                delete[] (char*) ptr->work;
+                delete[] ptr;
+                closeHDF5File(fd);
+                return;
+            }
+            if (nPoints != ptDims[0])
+            {
+                Coserror(_("The Time vector has a wrong size, expecting [%d, %d] and getting [%d, %d].\n"), nPoints, 1, ptDims[0], ptDims[1]);
+                /*set_block_error(-3);*/
+                *work = nullptr;
+                delete[] (char*) ptr->work;
+                delete[] ptr;
+                closeHDF5File(fd);
+                return;
+            }
+            delete[] ptDims;
+
+            ptr->workt = new double[nPoints];
+            ptr_T = (double*) ptr->workt;
+            ierr = readDoubleMatrix(tSetId, ptr_T); /* Read t data */
+            if (ierr != 0)
+            {
+                Coserror(_("Cannot read the time field.\n"));
+                delete[] ptr->workt;
+                delete[] (char*) ptr->work;
+                delete[] ptr;
+                closeHDF5File(fd);
+            }
+
+            /* Close the file */
+            closeHDF5File(fd);
+
+            /*================================*/
+            /* Check for an increasing time data */
+            for (int j = 0; j < nPoints - 1; ++j)
+            {
+                if (ptr_T[j] > ptr_T[j + 1])
+                {
+                    Coserror(_("The time vector should be an increasing vector.\n"));
+                    /*set_block_error(-3);*/
+                    *work = nullptr;
+                    delete[] ptr->workt;
+                    delete[] (char*) ptr->work;
+                    delete[] ptr;
+                    return;
+                }
+            }
+            /*=================================*/
+            if ((Method > 1) && (xType == 1) && (!ptr->Hmat))
+            {
+                /* double or complex */
+                if (xSubType == 0) /* real */
+                {
+                    ptr->D = new double[nPoints * mX];
+                }
+                else /* complex */
+                {
+                    ptr->D = new double[2 * nPoints * mX];
+                }
+
+                double* spline = new double[3 * nPoints - 2];
+
+                double* A_d  = spline;
+                double* A_sd = A_d  + nPoints;
+                double* qdy  = A_sd + nPoints - 1;
+
+                for (int j = 0; j < mX; ++j)
+                {
+                    /* real part */
+                    for (int i = 0; i <= nPoints - 2; ++i)
+                    {
+                        A_sd[i] = 1 / (ptr_T[i + 1] - ptr_T[i]);
+                        qdy[i]  = (ptr_d[i + 1 + j * nPoints] - ptr_d[i + j * nPoints]) * A_sd[i] * A_sd[i];
+                    }
+
+                    for (int i = 1; i <= nPoints - 2; ++i)
+                    {
+                        A_d[i] = 2 * (A_sd[i - 1] + A_sd[i]);
+                        ptr->D[i + j * nPoints] = 3 * (qdy[i - 1] + qdy[i]);
+                    }
+
+                    if (Method == 2)
+                    {
+                        A_d[0] =  2 * A_sd[0];
+                        ptr->D[0 + j * nPoints] = 3 * qdy[0];
+                        A_d[nPoints - 1] =  2 * A_sd[nPoints - 2];
+                        ptr->D[nPoints - 1 + j * nPoints] =  3 * qdy[nPoints - 2];
+                        double* res = &ptr->D[j * nPoints];
+                        Mytridiagldltsolve(A_d, A_sd, res, nPoints);
+                    }
+
+                    if (Method == 3)
+                    {
+                        /*  s'''(x(2)-) = s'''(x(2)+) */
+                        double r = A_sd[1] / A_sd[0];
+                        A_d[0] = A_sd[0] / (1 + r);
+                        ptr->D[j * nPoints] = ((3 * r + 2) * qdy[0] + r * qdy[1]) / ((1 + r) * (1 + r));
+                        /*  s'''(x(n-1)-) = s'''(x(n-1)+) */
+                        r = A_sd[nPoints - 3] / A_sd[nPoints - 2];
+                        A_d[nPoints - 1] = A_sd[nPoints - 2] / (1 + r);
+                        ptr->D[nPoints - 1 + j * nPoints] = ((3 * r + 2) * qdy[nPoints - 2] + r * qdy[nPoints - 3]) / ((1 + r) * (1 + r));
+                        double* res = &ptr->D[j * nPoints];
+                        Mytridiagldltsolve(A_d, A_sd, res, nPoints);
+                    }
+                }
+
+                if (xSubType == 1)
+                {
+                    /* imag part */
+                    for (int j = 0; j < mX; ++j)
+                    {
+                        for (int i = 0; i <= nPoints - 2; ++i)
+                        {
+                            A_sd[i] = 1 / (ptr_T[i + 1] - ptr_T[i]);
+                            qdy[i]  = (ptr_d[nPoints + i + 1 + j * nPoints] - ptr_d[nPoints + i + j * nPoints]) * A_sd[i] * A_sd[i];
+                        }
+
+                        for (int i = 1; i <= nPoints - 2; ++i)
+                        {
+                            A_d[i] = 2 * (A_sd[i - 1] + A_sd[i]);
+                            ptr->D[i + j * nPoints + nPoints] = 3 * (qdy[i - 1] + qdy[i]);
+                        }
+
+                        if (Method == 2)
+                        {
+                            A_d[0] =  2 * A_sd[0];
+                            ptr->D[nPoints + 0 + j * nPoints] = 3 * qdy[0];
+                            A_d[nPoints - 1] =  2 * A_sd[nPoints - 2];
+                            ptr->D[nPoints + nPoints - 1 + j * nPoints] =  3 * qdy[nPoints - 2];
+                            double* res = &ptr->D[nPoints + j * nPoints];
+                            Mytridiagldltsolve(A_d, A_sd, res, nPoints);
+                        }
+
+                        if (Method == 3)
+                        {
+                            /*  s'''(x(2)-) = s'''(x(2)+) */
+                            double r = A_sd[1] / A_sd[0];
+                            A_d[0] = A_sd[0] / (1 + r);
+                            ptr->D[nPoints + j * nPoints] = ((3 * r + 2) * qdy[0] + r * qdy[1]) / ((1 + r) * (1 + r));
+                            /*  s'''(x(n-1)-) = s'''(x(n-1)+) */
+                            r = A_sd[nPoints - 3] / A_sd[nPoints - 2];
+                            A_d[nPoints - 1] = A_sd[nPoints - 2] / (1 + r);
+                            ptr->D[nPoints + nPoints - 1 + j * nPoints] = ((3 * r + 2) * qdy[nPoints - 2] + r * qdy[nPoints - 3]) / ((1 + r) * (1 + r));
+                            double* res = &ptr->D[nPoints + j * nPoints];
+                            Mytridiagldltsolve(A_d, A_sd, res, nPoints);
+                        }
+                    }
+                }
+
+                delete[] spline;
+            }
+            /*===================================*/
+            int cnt1 = nPoints - 1;
+            int cnt2 = nPoints;
+            for (int i = 0; i < nPoints; ++i)
+            {
+                /* finding the first positive time instant */
+                if (ptr->workt[i] >= 0)
+                {
+                    cnt1 = i - 1;
+                    cnt2 = i;
+                    break;
+                }
+            }
+            ptr->nPoints = nPoints;
+            ptr->Yt = xType;
+            ptr->Yst = xSubType;
+            ptr->cnt1 = cnt1;
+            ptr->cnt2 = cnt2;
+            ptr->EVindex = 0;
+            ptr->PerEVcnt = 0;
+            ptr->firstevent = 1;
+            break;
+            /*******************************************************/
+            /*******************************************************/
+        }
+        case 1 :
+        {
+            /* Output computation */
+
+            /* Retrieve 'ptr' of the structure of the block */
+            ptr = *work;
+            int nPoints = ptr->nPoints;
+            int cnt1 = ptr->cnt1;
+            int cnt2 = ptr->cnt2;
+            int EVindex = ptr->EVindex;
+            int PerEVcnt = ptr->PerEVcnt;
+
+            /* Get current simulation time */
+            double t = get_scicos_time();
+            double t1 = t, t2;
+
+            double TNm1  = ptr->workt[nPoints - 1];
+            double TP    = TNm1 - 0;
+
+            int inow;
+            if (ZC == 1)
+            {
+                /* Zero-crossing enabled */
+                if (OutEnd == 2)
+                {
+                    if (PerEVcnt > 0)
+                    {
+                        // We ran out of value and OutEnd is 2 (Repeat)
+                        // Use fake time within our range.
+                        t -= (PerEVcnt) * TP;
+                    }
+                    inow = nPoints - 1;
+                }
+                else
+                {
+                    inow = nPoints + 1; // Arbitrary value more than nPoints, will be overwritten if needed.
+                }
+                for (int i = cnt1 ; i < nPoints ; ++i)
+                {
+                    if (i == -1)
+                    {
+                        continue;
+                    }
+                    if (t <= ptr->workt[i])
+                    {
+                        if (t < ptr->workt[i])
+                        {
+                            inow = i - 1;
+                        }
+                        else
+                        {
+                            inow = i;
+                        }
+                        if (inow < cnt2)
+                        {
+                            cnt2 = inow;
+                        }
+                        else
+                        {
+                            cnt1 = cnt2;
+                            cnt2 = inow;
+                        }
+                        break;
+                    }
+                }
+            }
+            else   /* Zero-crossing disabled */
+            {
+                if (OutEnd == 2)
+                {
+                    double r = 0;
+                    if (TP != 0)
+                    {
+                        r = floor((t / TP));
+                    }
+                    t -= static_cast<int>(r) * TP;
+                    inow = nPoints - 1;
+                }
+                else
+                {
+                    inow = nPoints + 1; // Arbitrary value more than nPoints, will be overwritten if needed.
+                }
+                // Look in time value table a range to have current time in.
+                // Beware exact values.
+                for (int i = 0 ; i < nPoints ; ++i)
+                {
+                    if (t <= ptr->workt[i])
+                    {
+                        if (t < ptr->workt[i])
+                        {
+                            inow = i - 1;
+                        }
+                        else
+                        {
+                            inow = i;
+                        }
+                        break;
+                    }
+                }
+            }
+
+            ptr->cnt1 = cnt1;
+            ptr->cnt2 = cnt2;
+            ptr->EVindex = EVindex;
+            ptr->PerEVcnt = PerEVcnt;
+
+            /***************************/
+            /* Hypermatrix case */
+            if (ptr->Hmat)
+            {
+                for (int j = 0; j < my * ny; ++j)
+                {
+                    if (ptr->Yt == 1)
+                    {
+                        if (ptr->Yst == 0)
+                        {
+                            /* real case */
+                            y_d = GetRealOutPortPtrs(block, 1);
+                            ptr_d = (double*) ptr->work;
+
+                            if (inow > nPoints)
+                            {
+                                if (OutEnd == 0)
+                                {
+                                    y_d[j] = 0; /* Outputs set to zero */
+                                }
+                                else if (OutEnd == 1)
+                                {
+                                    y_d[j] = ptr_d[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                }
+                            }
+                            else
+                            {
+                                if (inow < 0)
+                                {
+                                    y_d[j] = 0;
+                                }
+                                else
+                                {
+                                    y_d[j] = ptr_d[inow * ny * my + j];
+                                }
+                            }
+                        }
+                        else
+                        {
+                            /* complexe case */
+                            y_d = GetRealOutPortPtrs(block, 1);
+                            y_cd = GetImagOutPortPtrs(block, 1);
+                            ptr_d = (double*) ptr->work;
+
+                            if (inow > nPoints)
+                            {
+                                if (OutEnd == 0)
+                                {
+                                    y_d[j] = 0; /* Outputs set to zero */
+                                    y_cd[j] = 0; /* Outputs set to zero */
+                                }
+                                else if (OutEnd == 1)
+                                {
+                                    y_d[j] = ptr_d[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    y_cd[j] = ptr_d[nPoints * my * ny + (nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                }
+                            }
+                            else
+                            {
+                                if (inow < 0)
+                                {
+                                    y_d[j] = 0; /* Outputs set to zero */
+                                    y_cd[j] = 0; /* Outputs set to zero */
+                                }
+                                else
+                                {
+                                    y_d[j] = ptr_d[inow * ny * my + j];
+                                    y_cd[j] = ptr_d[nPoints * my * ny + inow * ny * my + j];
+                                }
+                            }
+                        }
+                    }
+                    else if (ptr->Yt == 8)
+                    {
+                        switch (ptr->Yst)
+                        {
+                            case 1:
+                                /* --------------------- int8 char  ----------------------------*/
+                                y_c = Getint8OutPortPtrs(block, 1);
+                                ptr_c = (char*) ptr->work;
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_c[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_c[j] = ptr_c[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_c[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_c[j] = ptr_c[inow * ny * my + j];
+                                    }
+                                }
+                                break;
+
+                            case 2:
+                                /* --------------------- int16 short int ---------------------*/
+                                y_s = Getint16OutPortPtrs(block, 1);
+                                ptr_s = (short int*) ptr->work;
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_s[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_s[j] = ptr_s[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_s[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_s[j] = ptr_s[inow * ny * my + j];
+                                    }
+                                }
+                                break;
+
+                            case 4:
+                                /* --------------------- int32 long ---------------------*/
+                                y_l = Getint32OutPortPtrs(block, 1);
+                                ptr_l = (int*) ptr->work;
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_l[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_l[j] = ptr_l[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_l[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_l[j] = ptr_l[inow * ny * my + j];
+                                    }
+                                }
+                                break;
+
+                            case 11:
+                                /*--------------------- uint8 uchar ---------------------*/
+                                y_uc = Getuint8OutPortPtrs(block, 1);
+                                ptr_uc = (unsigned char*) ptr->work;
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_uc[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_uc[j] = ptr_uc[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_uc[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_uc[j] = ptr_uc[inow * ny * my + j];
+                                    }
+                                }
+                                break;
+
+                            case 12:
+                                /* --------------------- uint16 ushort ---------------------*/
+                                y_us = Getuint16OutPortPtrs(block, 1);
+                                ptr_us = (unsigned short int*) ptr->work;
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_us[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_us[j] = ptr_us[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_us[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_us[j] = ptr_us[inow * ny * my + j];
+                                    }
+                                }
+                                break;
+
+                            case 14:
+                                /* --------------------- uint32 ulong ---------------------*/
+                                y_ul = Getuint32OutPortPtrs(block, 1);
+                                ptr_ul = (unsigned int*) ptr->work;
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_ul[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_ul[j] = ptr_ul[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_ul[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_ul[j] = ptr_ul[inow * ny * my + j];
+                                    }
+                                }
+                                break;
+                        }
+                    }
+                } /* for j loop */
+            }
+            /****************************/
+            /* Scalar or vectorial case */
+            else
+            {
+                for (int j = 0; j < my; ++j)
+                {
+                    double y1, y2, d1, d2, h, dh, ddh, dddh;
+                    if (ptr->Yt == 1)
+                    {
+                        if ((ptr->Yst == 0) || (ptr->Yst == 1))
+                        {
+                            /*  If real or complex*/
+                            y_d = GetRealOutPortPtrs(block, 1);
+                            ptr_d = (double*) ptr->work;
+                            ptr_D = (double*) ptr->D;
+
+                            if (inow > nPoints)
+                            {
+                                if (OutEnd == 0)
+                                {
+                                    y_d[j] = 0.0; /* Outputs set to zero */
+                                }
+                                else if (OutEnd == 1)
+                                {
+                                    y_d[j] = ptr_d[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
+                                }
+                            }
+                            else if (Method == 0)
+                            {
+                                if (inow < 0)
+                                {
+                                    y_d[j] = 0.0;
+                                }
+                                else
+                                {
+                                    y_d[j] = ptr_d[inow + (j) * nPoints];
+                                }
+                            }
+                            else if (Method == 1)
+                            {
+                                if (inow < 0)
+                                {
+                                    inow = 0;
+                                }
+                                t1 = ptr->workt[inow];
+                                t2 = ptr->workt[inow + 1];
+                                y1 = ptr_d[inow + j * nPoints];
+                                y2 = ptr_d[inow + 1 + j * nPoints];
+                                y_d[j] = (y2 - y1) * (t - t1) / (t2 - t1) + y1;
+                            }
+                            else if (Method >= 2)
+                            {
+                                t1 = ptr->workt[inow];
+                                t2 = ptr->workt[inow + 1];
+                                y1 = ptr_d[inow + j * nPoints];
+                                y2 = ptr_d[inow + 1 + j * nPoints];
+                                d1 = ptr_D[inow + j * nPoints];
+                                d2 = ptr_D[inow + 1 + j * nPoints];
+                                scicos_evalhermite(&t, &t1, &t2, &y1, &y2, &d1, &d2, &h, &dh, &ddh, &dddh, &inow);
+                                y_d[j] = h;
+                            }
+                        }
+                        if (ptr->Yst == 1)
+                        {
+                            /*  -------------- complex ----------------------*/
+                            y_cd = GetImagOutPortPtrs(block, 1);
+                            if (inow > nPoints)
+                            {
+                                if (OutEnd == 0)
+                                {
+                                    y_cd[j] = 0.0; /* Outputs set to zero*/
+                                }
+                                else if (OutEnd == 1)
+                                {
+                                    y_cd[j] = ptr_d[nPoints * my + nPoints - 1 + (j) * nPoints]; // Hold outputs at the end
+                                }
+                            }
+                            else if (Method == 0)
+                            {
+                                if (inow < 0)
+                                {
+                                    y_cd[j] = 0.0; /* Outputs set to zero */
+                                }
+                                else
+                                {
+                                    y_cd[j] = ptr_d[nPoints * my + inow + (j) * nPoints];
+                                }
+                            }
+                            else if (Method == 1)
+                            {
+                                if (inow < 0)
+                                {
+                                    inow = 0;
+                                } /* Extrapolation for 0<t<X(0) */
+                                t1 = ptr->workt[inow];
+                                t2 = ptr->workt[inow + 1];
+                                y1 = ptr_d[nPoints * my + inow + j * nPoints];
+                                y2 = ptr_d[nPoints * my + inow + 1 + j * nPoints];
+                                y_cd[j] = (y2 - y1) * (t - t1) / (t2 - t1) + y1;
+                            }
+                            else if (Method >= 2)
+                            {
+                                t1 = ptr->workt[inow];
+                                t2 = ptr->workt[inow + 1];
+                                y1 = ptr_d[inow + j * nPoints + nPoints];
+                                y2 = ptr_d[inow + 1 + j * nPoints + nPoints];
+                                d1 = ptr_D[inow + j * nPoints + nPoints];
+                                d2 = ptr_D[inow + 1 + j * nPoints + nPoints];
+                                scicos_evalhermite(&t, &t1, &t2, &y1, &y2, &d1, &d2, &h, &dh, &ddh, &dddh, &inow);
+                                y_cd[j] = h;
+                            }
+                        }
+                    }
+                    else if (ptr->Yt == 8)
+                    {
+                        switch (ptr->Yst)
+                        {
+                            case 1: /* --------------------- int8 char  ----------------------------*/
+                                y_c = Getint8OutPortPtrs(block, 1);
+                                ptr_c = (char*) ptr->work;
+                                /* y_c[j]=ptr_c[inow+(j)*nPoints]; */
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_c[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_c[j] = ptr_c[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else if (Method == 0)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_c[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_c[j] = ptr_c[inow + (j) * nPoints];
+                                    }
+                                }
+                                else if (Method >= 1)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        inow = 0;
+                                    }
+                                    t1 = ptr->workt[inow];
+                                    t2 = ptr->workt[inow + 1];
+                                    y1 = (double)ptr_c[inow + j * nPoints];
+                                    y2 = (double)ptr_c[inow + 1 + j * nPoints];
+                                    y_c[j] = (char)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
+                                }
+                                break;
+                            case 2:
+                                /* --------------------- int16 short ---------------------*/
+                                y_s = Getint16OutPortPtrs(block, 1);
+                                ptr_s = (short int*) ptr->work;
+                                /* y_s[j]=ptr_s[inow+(j)*nPoints]; */
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_s[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_s[j] = ptr_s[nPoints - 1 + (j) * nPoints]; // Hold outputs at the end
+                                    }
+                                }
+                                else if (Method == 0)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_s[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_s[j] = ptr_s[inow + (j) * nPoints];
+                                    }
+                                }
+                                else if (Method >= 1)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        inow = 0;
+                                    }
+                                    t1 = ptr->workt[inow];
+                                    t2 = ptr->workt[inow + 1];
+                                    y1 = (double)ptr_s[inow + j * nPoints];
+                                    y2 = (double)ptr_s[inow + 1 + j * nPoints];
+                                    y_s[j] = (short int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
+                                }
+                                break;
+                            case 4:
+                                /* --------------------- int32 long ---------------------*/
+                                y_l = Getint32OutPortPtrs(block, 1);
+                                ptr_l = (int*) ptr->work;
+                                /* y_l[j]=ptr_l[inow+(j)*nPoints]; */
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_l[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_l[j] = ptr_l[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else if (Method == 0)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_l[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_l[j] = ptr_l[inow + (j) * nPoints];
+                                    }
+                                }
+                                else if (Method >= 1)
+                                {
+                                    t1 = ptr->workt[inow];
+                                    t2 = ptr->workt[inow + 1];
+                                    y1 = (double)ptr_l[inow + j * nPoints];
+                                    y2 = (double)ptr_l[inow + 1 + j * nPoints];
+                                    y_l[j] = (int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
+                                }
+                                break;
+                            case 11: /*--------------------- uint8 uchar ---------------------*/
+                                y_uc = Getuint8OutPortPtrs(block, 1);
+                                ptr_uc = (unsigned char*) ptr->work;
+                                /* y_uc[j]=ptr_uc[inow+(j)*nPoints]; */
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_uc[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_uc[j] = ptr_uc[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else if (Method == 0)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_uc[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_uc[j] = ptr_uc[inow + (j) * nPoints];
+                                    }
+                                }
+                                else if (Method >= 1)
+                                {
+                                    t1 = ptr->workt[inow];
+                                    t2 = ptr->workt[inow + 1];
+                                    y1 = (double)ptr_uc[inow + j * nPoints];
+                                    y2 = (double)ptr_uc[inow + 1 + j * nPoints];
+                                    y_uc[j] = (unsigned char)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
+                                }
+                                break;
+                            case 12:
+                                /* --------------------- uint16 ushort int ---------------------*/
+                                y_us = Getuint16OutPortPtrs(block, 1);
+                                ptr_us = (unsigned short int*) ptr->work;
+                                /* y_us[j]=ptr_us[inow+(j)*nPoints]; */
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_us[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_us[j] = ptr_us[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else if (Method == 0)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_us[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_us[j] = ptr_us[inow + (j) * nPoints];
+                                    }
+                                }
+                                else if (Method >= 1)
+                                {
+                                    t1 = ptr->workt[inow];
+                                    t2 = ptr->workt[inow + 1];
+                                    y1 = (double)ptr_us[inow + j * nPoints];
+                                    y2 = (double)ptr_us[inow + 1 + j * nPoints];
+                                    y_us[j] = (unsigned short int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
+                                }
+                                break;
+                            case 14:
+                                /* --------------------- uint32 ulong ---------------------*/
+                                y_ul = Getuint32OutPortPtrs(block, 1);
+                                ptr_ul = (unsigned int*) ptr->work;
+                                /* y_ul[j]=ptr_ul[inow+(j)*nPoints]; */
+                                if (inow > nPoints)
+                                {
+                                    if (OutEnd == 0)
+                                    {
+                                        y_ul[j] = 0; /* Outputs set to zero */
+                                    }
+                                    else if (OutEnd == 1)
+                                    {
+                                        y_ul[j] = ptr_ul[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
+                                    }
+                                }
+                                else if (Method == 0)
+                                {
+                                    if (inow < 0)
+                                    {
+                                        y_ul[j] = 0;
+                                    }
+                                    else
+                                    {
+                                        y_ul[j] = ptr_ul[inow + (j) * nPoints];
+                                    }
+                                }
+                                else if (Method >= 1)
+                                {
+                                    t1 = ptr->workt[inow];
+                                    t2 = ptr->workt[inow + 1];
+                                    y1 = (double)ptr_ul[inow + j * nPoints];
+                                    y2 = (double)ptr_ul[inow + 1 + j * nPoints];
+                                    y_ul[j] = (unsigned int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
+                                }
+                                break;
+                        }
+                    }
+                } /* for j loop */
+            }
+            /********************************************************************/
+            break;
+        }
+        case 3 :
+        {
+            /* Event date computation */
+            /* Retrieve 'ptr' of the structure of the block */
+            ptr = *work;
+            int nPoints = ptr->nPoints;
+            int cnt1 = ptr->cnt1;
+            int cnt2 = ptr->cnt2;
+            int EVindex = ptr->EVindex;
+            int PerEVcnt = ptr->PerEVcnt;
+
+            /* Get current simulation time */
+            //double t = get_scicos_time();
+
+            double TNm1  = ptr->workt[nPoints - 1];
+            double TP    = TNm1 - 0;
+
+            int jfirst;
+            if (ZC == 1)
+            {
+                /* Generate Events only if ZC is active */
+                if ((Method == 1) || (Method == 0))
+                {
+                    /*-------------------------*/
+                    if (ptr->firstevent == 1)
+                    {
+                        jfirst = nPoints - 1; /* Finding first positive time instant */
+                        for (int j = 0; j < nPoints; ++j)
+                        {
+                            if (ptr->workt[j] > 0)
+                            {
+                                jfirst = j;
+                                break;
+                            }
+                        }
+                        block->evout[0] = ptr->workt[jfirst];
+                        EVindex = jfirst;
+                        ptr->EVindex = EVindex;
+                        ptr->firstevent = 0;
+                        return;
+                    }
+                    /*------------------------*/
+                    int i = EVindex;
+                    /*------------------------*/
+                    if (i < nPoints - 1)
+                    {
+                        block->evout[0] = ptr->workt[i + 1] - ptr->workt[i];
+                        EVindex = i + 1;
+                    }
+                    /*------------------------*/
+                    if (i == nPoints - 1)
+                    {
+                        if (OutEnd == 2)
+                        {
+                            /*  Periodic */
+                            cnt1 = -1;
+                            cnt2 = 0;
+                            PerEVcnt++; /* When OutEnd==2 (perodic output) */
+                            jfirst = nPoints - 1; /* Finding first positive time instant */
+                            for (int j = 0; j < nPoints; ++j)
+                            {
+                                if (ptr->workt[j] >= 0)
+                                {
+                                    jfirst = j;
+                                    break;
+                                }
+                            }
+                            block->evout[0] = ptr->workt[jfirst];
+                            EVindex = jfirst;
+                        }
+                    }
+                    /*-------------------------- */
+                }
+                else if (Method <= 3)
+                {
+                    if (ptr->firstevent == 1)
+                    {
+                        block->evout[0] = TP;
+                        ptr->firstevent = 0;
+                    }
+                    else
+                    {
+                        if (OutEnd == 2)
+                        {
+                            block->evout[0] = TP;
+                        }
+                        PerEVcnt++;
+                    }
+                    cnt1 = -1;
+                    cnt2 = 0;
+                }
+                ptr->cnt1 = cnt1;
+                ptr->cnt2 = cnt2;
+                ptr->EVindex = EVindex;
+                ptr->PerEVcnt = PerEVcnt;
+            }
+            /***********************************************************************/
+            break;
+        }
+        case 5 :
+        {
+            /* Finish */
+            ptr = *work;
+            if (ptr != nullptr)
+            {
+                if (ptr->D != nullptr)
+                {
+                    delete[] ptr->D;
+                }
+                if (ptr->work != nullptr)
+                {
+                    delete[] (char*) ptr->work;
+                }
+                if (ptr->workt != nullptr)
+                {
+                    delete[] ptr->workt;
+                }
+                delete[] ptr;
+            }
+            break;
+            /***********************************************************************/
+        }
+        case 6 :
+        {
+            /* Re-init */
+
+            // Finish then init
+            fromws_c(block, 5);
+            fromws_c(block, 4);
+            break;
+        }
+        /*************************************************************************/
+        default :
+            return;
+    }
+}
index acaa6e5..25e94fc 100644 (file)
@@ -1,14 +1,22 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
 // Copyright (C) 2012 - Scilab Enterprises - ClĂ©ment DAVID
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-
+//
 // <-- XCOS TEST -->
 
-
 assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/tests/unit_tests/fromws_c.zcos"));
 
-V = struct('time', (1:100)', 'values', sin((0:0.1:9.9)'));
+V = struct("time", (1:100)', "values", sin((0:0.1:9.9)'));
+scicos_simulate(scs_m, list());
+
+assert_checkequal(scs_m.objs(4).gui, "GAINBLK_f");
+
+scs_m.objs(4).graphics.exprs = "[1 1 1]";
+scs_m.objs(4).model.rpar = [1 1 1];
+
+V.values = [V.values V.values V.values];
 scicos_simulate(scs_m, list());
index 934883e..d8928d4 100644 (file)
@@ -4,35 +4,34 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-
+//
 // <-- XCOS TEST -->
-
-
 //
 // Test Diagram with fromws after end behavior
 // Input random values
 //
-assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/tests/unit_tests/fromws_tows_c.zcos"));
+
+assert_checktrue(importXcosDiagram(SCI+"/modules/xcos/tests/unit_tests/fromws_tows_c.zcos"));
 
 // V_in size feat simulation final time and asked values
-V_in = struct('time', (0:0.5:5000)', 'values', rand(10001, 1));
+V_in = struct("time", (0:0.5:5000)', "values", rand(10001, 1));
 scicos_simulate(scs_m, list());
-assert_checkequal(V_in.time, V_out_zero.time);
+assert_checkequal(V_in.time,   V_out_zero.time);
 assert_checkequal(V_in.values, V_out_zero.values);
-assert_checkequal(V_in.time, V_out_hold.time);
+assert_checkequal(V_in.time,   V_out_hold.time);
 assert_checkequal(V_in.values, V_out_hold.values);
-assert_checkequal(V_in.time, V_out_repeat.time);
+assert_checkequal(V_in.time,   V_out_repeat.time);
 assert_checkequal(V_in.values, V_out_repeat.values);
 
 // V_in is shorter than simulation time
-V_in = struct('time', (0:0.5:1000)', 'values', rand(2001, 1));
+V_in = struct("time", (0:0.5:1000)', "values", rand(2001, 1));
 scicos_simulate(scs_m, list());
-assert_checkequal(V_in.time, V_out_zero.time(1:2001));
+assert_checkequal(V_in.time,   V_out_zero.time(1:2001));
 assert_checkequal(V_in.values, V_out_zero.values(1:2001));
 assert_checkequal(V_out_zero.values(2002:10001), zeros(10001 - 2002 + 1, 1));
-assert_checkequal(V_in.time, V_out_hold.time(1:2001));
+assert_checkequal(V_in.time,   V_out_hold.time(1:2001));
 assert_checkequal(V_in.values, V_out_hold.values(1:2001));
-assert_checkequal(V_out_hold.values(2002:10001), ones(10001 - 2002 + 1, 1) .* V_in.values($));
-assert_checkequal(V_in.time, V_out_repeat.time(1:2001));
+assert_checkequal(V_out_hold.values(2002:10001), ones(10001 - 2002 + 1, 1).*V_in.values($));
+assert_checkequal(V_in.time,   V_out_repeat.time(1:2001));
 assert_checkequal(V_in.values, V_out_repeat.values(1:2001));
-//assert_checkequal(V_in.values, V_out_repeat.values(2002:4002));
\ No newline at end of file
+//assert_checkequal(V_in.values, V_out_repeat.values(2002:4002));