2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
4 * Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
19 #include "Helpers.hxx"
23 #include "api_scilab.h"
24 #include "dynlib_scicos_blocks.h"
25 #include "expandPathVariable.h"
26 #include "scicos_block4.h"
27 #include "scicos_evalhermite.h"
29 #include "sci_malloc.h"
30 #include "h5_fileManagement.h"
31 #include "h5_readDataFromFile.h"
32 #include "h5_attributeConstants.h"
34 #include "localization.h"
36 SCICOS_BLOCKS_IMPEXP void fromws_c(scicos_block* block, int flag);
39 /*--------------------------------------------------------------------------*/
40 /* work struct for a block */
56 /*--------------------------------------------------------------------------*/
57 static int Mytridiagldltsolve(double* &dA, double* &lA, double* &B, int N)
59 for (int j = 1; j <= N - 1; ++j)
61 double Temp = lA[j - 1];
62 lA[j - 1] /= dA[j - 1];
63 B[j] -= lA[j - 1] * B[j - 1];
64 dA[j] -= Temp * lA[j - 1];
67 B[N - 1] /= dA[N - 1];
68 for (int j = N - 2; j >= 0; --j)
70 B[j] = - lA[j] * B[j + 1] + B[j] / dA[j];
76 /*--------------------------------------------------------------------------*/
77 using namespace org_scilab_modules_xcos_block;
79 /*--------------------------------------------------------------------------*/
80 SCICOS_BLOCKS_IMPEXP void fromws_c(scicos_block* block, int flag)
82 /* Retrieve dimensions of output port */
83 int my = GetOutPortRows(block, 1); /* Number of rows of the output */
84 int ny = GetOutPortCols(block, 1); /* Number of cols of the output */
85 int ytype = GetOutType(block, 1); /* Output type */
87 /* Generic pointers */
88 double *y_d, *y_cd, *ptr_d = nullptr, *ptr_T, *ptr_D;
90 unsigned char *y_uc, *ptr_uc;
91 short int *y_s, *ptr_s;
92 unsigned short int *y_us, *ptr_us;
94 unsigned int *y_ul, *ptr_ul;
96 /* The struct pointer of the block */
97 fromwork_struct** work = (fromwork_struct**) block->work;
98 fromwork_struct* ptr = nullptr;
100 int Fnlength = block->ipar[0];
101 int Method = block->ipar[1 + Fnlength];
102 int ZC = block->ipar[2 + Fnlength];
103 int OutEnd = block->ipar[3 + Fnlength];
111 /* Convert Scilab code of the variable name to C string */
113 /* Path to "TMPDIR/Workspace/" */
114 const char* filePrefix = "TMPDIR/Workspace/";
115 const int prefixSize = static_cast<int>(strlen(filePrefix));
118 for (int i = 0; i < Fnlength; ++i)
120 FName[i] = static_cast<char>(block->ipar[1 + i]);
122 FName[Fnlength] = '\0';
124 char* env = new char[prefixSize + Fnlength + 1];
125 strcpy(env, filePrefix);
126 strcpy(env + prefixSize, FName);
127 env[prefixSize + Fnlength] = '\0';
129 char* filename = expandPathVariable(env);
131 int fd = 0, ierr = 0;
135 fd = openHDF5File(filename, 0);
142 Coserror(_("The '%s' variable does not exist.\n"), FName);
146 // Manage version information
147 int iVersion = getSODFormatAttribute(fd);
148 if (iVersion != SOD_FILE_VERSION)
150 if (iVersion > SOD_FILE_VERSION)
152 // Cannot read file with version more recent that me!
153 Coserror(_("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), "fromws_c", SOD_FILE_VERSION, iVersion);
158 /* Read the variables contained in the file */
159 char* pstNameList[2];
160 int nbVar = getVariableNames(fd, pstNameList);
163 Coserror(_("Erroneous saved file.\n"));
166 if (strcmp(pstNameList[0], "t") != 0 || strcmp(pstNameList[1], "x") != 0)
168 Coserror(_("Erroneous saved file.\n"));
173 int xSetId = getDataSetIdFromName(fd, pstNameList[1]);
174 int xType = getScilabTypeFromDataSet(xSetId);
176 int nPoints, mX, nX = 1;
178 if ((xType == 1) || (xType == 8))
180 int* pxDims = nullptr;
181 getDatasetInfo(xSetId, &xSubType, &xDims, pxDims);
182 pxDims = new int[xDims];
183 getDatasetInfo(xSetId, &xSubType, &xDims, pxDims);
184 nPoints = pxDims[0]; /* Number of data */
185 mX = pxDims[1]; /* First dimension */
188 nX = pxDims[2]; /* Second dimension */
193 getDatasetPrecision(xSetId, &xSubType); /* For the integer case, overwrite xSubType */
198 Coserror(_("Invalid variable type.\n"));
199 /*scicos_print(_("Invalid variable type.\n"));
200 set_block_error(-3);*/
205 /* Check dimension for output port and variable */
206 if ((mX != my) || (nX != ny))
208 Coserror(_("Data dimensions are inconsistent:\n Variable size=[%d,%d] \nBlock output size=[%d,%d].\n"), mX, nX, my, ny);
209 /*set_block_error(-3);*/
214 /* Check variable data type and output block data type */
217 /* real/complex cases */
223 Coserror(_("Output should be of Real type.\n"));
224 /*set_block_error(-3);*/
233 Coserror(_("Output should be of complex type.\n"));
234 /*set_block_error(-3);*/
249 Coserror(_("Output should be of int8 type.\n"));
259 Coserror(_("Output should be of int16 type.\n"));
260 /*set_block_error(-3);*/
269 Coserror(_("Output should be of int32 type.\n"));
270 /*set_block_error(-3);*/
279 Coserror(_("Output should be of uint8 type.\n"));
280 /*set_block_error(-3);*/
289 Coserror(_("Output should be of uint16 type.\n"));
290 /*set_block_error(-3);*/
299 Coserror(_("Output should be of uint32 type.\n"));
300 /*set_block_error(-3);*/
308 /* Allocation of the work structure of that block */
310 *work = new fromwork_struct[sizeof(fromwork_struct)];
313 ptr->workt = nullptr;
318 /* real/complex case */
322 ptr->work = new double[nPoints * mX * nX];
323 ptr_d = (double*) ptr->work;
324 ierr = readDoubleMatrix(xSetId, ptr_d);
326 case 1 : /* Complex */
327 ptr->work = new double[nPoints * mX * nX];
328 ptr_d = (double*) ptr->work;
329 ierr = readDoubleComplexMatrix(xSetId, ptr_d, ptr_d + nPoints * mX * nX);
339 ptr->work = new char[nPoints * mX * nX];
340 ptr_c = (char*) ptr->work;
341 ierr = readInteger8Matrix(xSetId, ptr_c);
344 ptr->work = new short int[nPoints * mX * nX];
345 ptr_s = (short int*) ptr->work;
346 ierr = readInteger16Matrix(xSetId, ptr_s);
349 ptr->work = new int[nPoints * mX * nX];
350 ptr_l = (int*) ptr->work;
351 ierr = readInteger32Matrix(xSetId, ptr_l);
354 ptr->work = new unsigned char[nPoints * mX * nX];
355 ptr_uc = (unsigned char*) ptr->work;
356 ierr = readUnsignedInteger8Matrix(xSetId, ptr_uc);
359 ptr->work = new unsigned short int[nPoints * mX * nX];
360 ptr_us = (unsigned short int*) ptr->work;
361 ierr = readUnsignedInteger16Matrix(xSetId, ptr_us);
364 ptr->work = new unsigned int[nPoints * mX * nX];
365 ptr_ul = (unsigned int*) ptr->work;
366 ierr = readUnsignedInteger32Matrix(xSetId, ptr_ul);
372 Coserror(_("Cannot read the values field.\n"));
373 delete[] (char*) ptr->work;
389 int tSetId = getDataSetIdFromName(fd, pstNameList[0]);
390 int tType = getScilabTypeFromDataSet(tSetId);
393 Coserror(_("The Time vector type is not ""double"".\n"));
396 delete[] (char*) ptr->work;
402 int tDims, tComplex, *ptDims = nullptr;
403 getDatasetInfo(tSetId, &tComplex, &tDims, ptDims);
404 ptDims = new int[tDims];
405 getDatasetInfo(tSetId, &tComplex, &tDims, ptDims);
408 Coserror(_("The Time vector type is complex.\n"));
411 delete[] (char*) ptr->work;
417 if (nPoints != ptDims[0])
419 Coserror(_("The Time vector has a wrong size, expecting [%d, %d] and getting [%d, %d].\n"), nPoints, 1, ptDims[0], ptDims[1]);
420 /*set_block_error(-3);*/
422 delete[] (char*) ptr->work;
430 ptr->workt = new double[nPoints];
431 ptr_T = (double*) ptr->workt;
432 ierr = readDoubleMatrix(tSetId, ptr_T); /* Read t data */
435 Coserror(_("Cannot read the time field.\n"));
437 delete[] (char*) ptr->work;
446 /*================================*/
447 /* Check for an increasing time data */
448 for (int j = 0; j < nPoints - 1; ++j)
450 if (ptr_T[j] > ptr_T[j + 1])
452 Coserror(_("The time vector should be an increasing vector.\n"));
453 /*set_block_error(-3);*/
456 delete[] (char*) ptr->work;
461 /*=================================*/
462 if ((Method > 1) && (xType == 1) && (!ptr->Hmat))
464 /* double or complex */
465 if (xSubType == 0) /* real */
467 ptr->D = new double[nPoints * mX];
471 ptr->D = new double[2 * nPoints * mX];
474 double* spline = new double[3 * nPoints - 2];
476 double* A_d = spline;
477 double* A_sd = A_d + nPoints;
478 double* qdy = A_sd + nPoints - 1;
480 for (int j = 0; j < mX; ++j)
483 for (int i = 0; i <= nPoints - 2; ++i)
485 A_sd[i] = 1 / (ptr_T[i + 1] - ptr_T[i]);
486 qdy[i] = (ptr_d[i + 1 + j * nPoints] - ptr_d[i + j * nPoints]) * A_sd[i] * A_sd[i];
489 for (int i = 1; i <= nPoints - 2; ++i)
491 A_d[i] = 2 * (A_sd[i - 1] + A_sd[i]);
492 ptr->D[i + j * nPoints] = 3 * (qdy[i - 1] + qdy[i]);
497 A_d[0] = 2 * A_sd[0];
498 ptr->D[0 + j * nPoints] = 3 * qdy[0];
499 A_d[nPoints - 1] = 2 * A_sd[nPoints - 2];
500 ptr->D[nPoints - 1 + j * nPoints] = 3 * qdy[nPoints - 2];
501 double* res = &ptr->D[j * nPoints];
502 Mytridiagldltsolve(A_d, A_sd, res, nPoints);
507 /* s'''(x(2)-) = s'''(x(2)+) */
508 double r = A_sd[1] / A_sd[0];
509 A_d[0] = A_sd[0] / (1 + r);
510 ptr->D[j * nPoints] = ((3 * r + 2) * qdy[0] + r * qdy[1]) / ((1 + r) * (1 + r));
511 /* s'''(x(n-1)-) = s'''(x(n-1)+) */
512 r = A_sd[nPoints - 3] / A_sd[nPoints - 2];
513 A_d[nPoints - 1] = A_sd[nPoints - 2] / (1 + r);
514 ptr->D[nPoints - 1 + j * nPoints] = ((3 * r + 2) * qdy[nPoints - 2] + r * qdy[nPoints - 3]) / ((1 + r) * (1 + r));
515 double* res = &ptr->D[j * nPoints];
516 Mytridiagldltsolve(A_d, A_sd, res, nPoints);
523 for (int j = 0; j < mX; ++j)
525 for (int i = 0; i <= nPoints - 2; ++i)
527 A_sd[i] = 1 / (ptr_T[i + 1] - ptr_T[i]);
528 qdy[i] = (ptr_d[nPoints + i + 1 + j * nPoints] - ptr_d[nPoints + i + j * nPoints]) * A_sd[i] * A_sd[i];
531 for (int i = 1; i <= nPoints - 2; ++i)
533 A_d[i] = 2 * (A_sd[i - 1] + A_sd[i]);
534 ptr->D[i + j * nPoints + nPoints] = 3 * (qdy[i - 1] + qdy[i]);
539 A_d[0] = 2 * A_sd[0];
540 ptr->D[nPoints + 0 + j * nPoints] = 3 * qdy[0];
541 A_d[nPoints - 1] = 2 * A_sd[nPoints - 2];
542 ptr->D[nPoints + nPoints - 1 + j * nPoints] = 3 * qdy[nPoints - 2];
543 double* res = &ptr->D[nPoints + j * nPoints];
544 Mytridiagldltsolve(A_d, A_sd, res, nPoints);
549 /* s'''(x(2)-) = s'''(x(2)+) */
550 double r = A_sd[1] / A_sd[0];
551 A_d[0] = A_sd[0] / (1 + r);
552 ptr->D[nPoints + j * nPoints] = ((3 * r + 2) * qdy[0] + r * qdy[1]) / ((1 + r) * (1 + r));
553 /* s'''(x(n-1)-) = s'''(x(n-1)+) */
554 r = A_sd[nPoints - 3] / A_sd[nPoints - 2];
555 A_d[nPoints - 1] = A_sd[nPoints - 2] / (1 + r);
556 ptr->D[nPoints + nPoints - 1 + j * nPoints] = ((3 * r + 2) * qdy[nPoints - 2] + r * qdy[nPoints - 3]) / ((1 + r) * (1 + r));
557 double* res = &ptr->D[nPoints + j * nPoints];
558 Mytridiagldltsolve(A_d, A_sd, res, nPoints);
565 /*===================================*/
566 int cnt1 = nPoints - 1;
568 for (int i = 0; i < nPoints; ++i)
570 /* finding the first positive time instant */
571 if (ptr->workt[i] >= 0)
578 ptr->nPoints = nPoints;
587 /*******************************************************/
588 /*******************************************************/
592 /* Output computation */
594 /* Retrieve 'ptr' of the structure of the block */
596 int nPoints = ptr->nPoints;
597 int cnt1 = ptr->cnt1;
598 int cnt2 = ptr->cnt2;
599 int EVindex = ptr->EVindex;
600 int PerEVcnt = ptr->PerEVcnt;
602 /* Get current simulation time */
603 double t = get_scicos_time();
606 double TNm1 = ptr->workt[nPoints - 1];
607 double TP = TNm1 - 0;
612 /* Zero-crossing enabled */
617 // We ran out of value and OutEnd is 2 (Repeat)
618 // Use fake time within our range.
619 t -= (PerEVcnt) * TP;
625 inow = nPoints + 1; // Arbitrary value more than nPoints, will be overwritten if needed.
627 for (int i = cnt1 ; i < nPoints ; ++i)
633 if (t <= ptr->workt[i])
635 if (t < ptr->workt[i])
656 else /* Zero-crossing disabled */
665 t -= static_cast<int>(r) * TP;
670 inow = nPoints + 1; // Arbitrary value more than nPoints, will be overwritten if needed.
672 // Look in time value table a range to have current time in.
673 // Beware exact values.
674 for (int i = 0 ; i < nPoints ; ++i)
676 if (t <= ptr->workt[i])
678 if (t < ptr->workt[i])
693 ptr->EVindex = EVindex;
694 ptr->PerEVcnt = PerEVcnt;
696 /***************************/
697 /* Hypermatrix case */
700 for (int j = 0; j < my * ny; ++j)
707 y_d = GetRealOutPortPtrs(block, 1);
708 ptr_d = (double*) ptr->work;
714 y_d[j] = 0; /* Outputs set to zero */
716 else if (OutEnd == 1)
718 y_d[j] = ptr_d[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
729 y_d[j] = ptr_d[inow * ny * my + j];
736 y_d = GetRealOutPortPtrs(block, 1);
737 y_cd = GetImagOutPortPtrs(block, 1);
738 ptr_d = (double*) ptr->work;
744 y_d[j] = 0; /* Outputs set to zero */
745 y_cd[j] = 0; /* Outputs set to zero */
747 else if (OutEnd == 1)
749 y_d[j] = ptr_d[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
750 y_cd[j] = ptr_d[nPoints * my * ny + (nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
757 y_d[j] = 0; /* Outputs set to zero */
758 y_cd[j] = 0; /* Outputs set to zero */
762 y_d[j] = ptr_d[inow * ny * my + j];
763 y_cd[j] = ptr_d[nPoints * my * ny + inow * ny * my + j];
768 else if (ptr->Yt == 8)
773 /* --------------------- int8 char ----------------------------*/
774 y_c = Getint8OutPortPtrs(block, 1);
775 ptr_c = (char*) ptr->work;
780 y_c[j] = 0; /* Outputs set to zero */
782 else if (OutEnd == 1)
784 y_c[j] = ptr_c[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
795 y_c[j] = ptr_c[inow * ny * my + j];
801 /* --------------------- int16 short int ---------------------*/
802 y_s = Getint16OutPortPtrs(block, 1);
803 ptr_s = (short int*) ptr->work;
808 y_s[j] = 0; /* Outputs set to zero */
810 else if (OutEnd == 1)
812 y_s[j] = ptr_s[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
823 y_s[j] = ptr_s[inow * ny * my + j];
829 /* --------------------- int32 long ---------------------*/
830 y_l = Getint32OutPortPtrs(block, 1);
831 ptr_l = (int*) ptr->work;
836 y_l[j] = 0; /* Outputs set to zero */
838 else if (OutEnd == 1)
840 y_l[j] = ptr_l[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
851 y_l[j] = ptr_l[inow * ny * my + j];
857 /*--------------------- uint8 uchar ---------------------*/
858 y_uc = Getuint8OutPortPtrs(block, 1);
859 ptr_uc = (unsigned char*) ptr->work;
864 y_uc[j] = 0; /* Outputs set to zero */
866 else if (OutEnd == 1)
868 y_uc[j] = ptr_uc[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
879 y_uc[j] = ptr_uc[inow * ny * my + j];
885 /* --------------------- uint16 ushort ---------------------*/
886 y_us = Getuint16OutPortPtrs(block, 1);
887 ptr_us = (unsigned short int*) ptr->work;
892 y_us[j] = 0; /* Outputs set to zero */
894 else if (OutEnd == 1)
896 y_us[j] = ptr_us[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
907 y_us[j] = ptr_us[inow * ny * my + j];
913 /* --------------------- uint32 ulong ---------------------*/
914 y_ul = Getuint32OutPortPtrs(block, 1);
915 ptr_ul = (unsigned int*) ptr->work;
920 y_ul[j] = 0; /* Outputs set to zero */
922 else if (OutEnd == 1)
924 y_ul[j] = ptr_ul[(nPoints - 1) * ny * my + j]; /* Hold outputs at the end */
935 y_ul[j] = ptr_ul[inow * ny * my + j];
943 /****************************/
944 /* Scalar or vectorial case */
947 for (int j = 0; j < my; ++j)
949 double y1, y2, d1, d2, h, dh, ddh, dddh;
952 if ((ptr->Yst == 0) || (ptr->Yst == 1))
954 /* If real or complex*/
955 y_d = GetRealOutPortPtrs(block, 1);
956 ptr_d = (double*) ptr->work;
957 ptr_D = (double*) ptr->D;
963 y_d[j] = 0.0; /* Outputs set to zero */
965 else if (OutEnd == 1)
967 y_d[j] = ptr_d[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
970 else if (Method == 0)
978 y_d[j] = ptr_d[inow + (j) * nPoints];
981 else if (Method == 1)
987 t1 = ptr->workt[inow];
988 t2 = ptr->workt[inow + 1];
989 y1 = ptr_d[inow + j * nPoints];
990 y2 = ptr_d[inow + 1 + j * nPoints];
991 y_d[j] = (y2 - y1) * (t - t1) / (t2 - t1) + y1;
993 else if (Method >= 2)
995 t1 = ptr->workt[inow];
996 t2 = ptr->workt[inow + 1];
997 y1 = ptr_d[inow + j * nPoints];
998 y2 = ptr_d[inow + 1 + j * nPoints];
999 d1 = ptr_D[inow + j * nPoints];
1000 d2 = ptr_D[inow + 1 + j * nPoints];
1001 scicos_evalhermite(&t, &t1, &t2, &y1, &y2, &d1, &d2, &h, &dh, &ddh, &dddh, &inow);
1007 /* -------------- complex ----------------------*/
1008 y_cd = GetImagOutPortPtrs(block, 1);
1013 y_cd[j] = 0.0; /* Outputs set to zero*/
1015 else if (OutEnd == 1)
1017 y_cd[j] = ptr_d[nPoints * my + nPoints - 1 + (j) * nPoints]; // Hold outputs at the end
1020 else if (Method == 0)
1024 y_cd[j] = 0.0; /* Outputs set to zero */
1028 y_cd[j] = ptr_d[nPoints * my + inow + (j) * nPoints];
1031 else if (Method == 1)
1036 } /* Extrapolation for 0<t<X(0) */
1037 t1 = ptr->workt[inow];
1038 t2 = ptr->workt[inow + 1];
1039 y1 = ptr_d[nPoints * my + inow + j * nPoints];
1040 y2 = ptr_d[nPoints * my + inow + 1 + j * nPoints];
1041 y_cd[j] = (y2 - y1) * (t - t1) / (t2 - t1) + y1;
1043 else if (Method >= 2)
1045 t1 = ptr->workt[inow];
1046 t2 = ptr->workt[inow + 1];
1047 y1 = ptr_d[inow + j * nPoints + nPoints];
1048 y2 = ptr_d[inow + 1 + j * nPoints + nPoints];
1049 d1 = ptr_D[inow + j * nPoints + nPoints];
1050 d2 = ptr_D[inow + 1 + j * nPoints + nPoints];
1051 scicos_evalhermite(&t, &t1, &t2, &y1, &y2, &d1, &d2, &h, &dh, &ddh, &dddh, &inow);
1056 else if (ptr->Yt == 8)
1060 case 1: /* --------------------- int8 char ----------------------------*/
1061 y_c = Getint8OutPortPtrs(block, 1);
1062 ptr_c = (char*) ptr->work;
1063 /* y_c[j]=ptr_c[inow+(j)*nPoints]; */
1068 y_c[j] = 0; /* Outputs set to zero */
1070 else if (OutEnd == 1)
1072 y_c[j] = ptr_c[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
1075 else if (Method == 0)
1083 y_c[j] = ptr_c[inow + (j) * nPoints];
1086 else if (Method >= 1)
1092 t1 = ptr->workt[inow];
1093 t2 = ptr->workt[inow + 1];
1094 y1 = (double)ptr_c[inow + j * nPoints];
1095 y2 = (double)ptr_c[inow + 1 + j * nPoints];
1096 y_c[j] = (char)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
1100 /* --------------------- int16 short ---------------------*/
1101 y_s = Getint16OutPortPtrs(block, 1);
1102 ptr_s = (short int*) ptr->work;
1103 /* y_s[j]=ptr_s[inow+(j)*nPoints]; */
1108 y_s[j] = 0; /* Outputs set to zero */
1110 else if (OutEnd == 1)
1112 y_s[j] = ptr_s[nPoints - 1 + (j) * nPoints]; // Hold outputs at the end
1115 else if (Method == 0)
1123 y_s[j] = ptr_s[inow + (j) * nPoints];
1126 else if (Method >= 1)
1132 t1 = ptr->workt[inow];
1133 t2 = ptr->workt[inow + 1];
1134 y1 = (double)ptr_s[inow + j * nPoints];
1135 y2 = (double)ptr_s[inow + 1 + j * nPoints];
1136 y_s[j] = (short int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
1140 /* --------------------- int32 long ---------------------*/
1141 y_l = Getint32OutPortPtrs(block, 1);
1142 ptr_l = (int*) ptr->work;
1143 /* y_l[j]=ptr_l[inow+(j)*nPoints]; */
1148 y_l[j] = 0; /* Outputs set to zero */
1150 else if (OutEnd == 1)
1152 y_l[j] = ptr_l[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
1155 else if (Method == 0)
1163 y_l[j] = ptr_l[inow + (j) * nPoints];
1166 else if (Method >= 1)
1168 t1 = ptr->workt[inow];
1169 t2 = ptr->workt[inow + 1];
1170 y1 = (double)ptr_l[inow + j * nPoints];
1171 y2 = (double)ptr_l[inow + 1 + j * nPoints];
1172 y_l[j] = (int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
1175 case 11: /*--------------------- uint8 uchar ---------------------*/
1176 y_uc = Getuint8OutPortPtrs(block, 1);
1177 ptr_uc = (unsigned char*) ptr->work;
1178 /* y_uc[j]=ptr_uc[inow+(j)*nPoints]; */
1183 y_uc[j] = 0; /* Outputs set to zero */
1185 else if (OutEnd == 1)
1187 y_uc[j] = ptr_uc[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
1190 else if (Method == 0)
1198 y_uc[j] = ptr_uc[inow + (j) * nPoints];
1201 else if (Method >= 1)
1203 t1 = ptr->workt[inow];
1204 t2 = ptr->workt[inow + 1];
1205 y1 = (double)ptr_uc[inow + j * nPoints];
1206 y2 = (double)ptr_uc[inow + 1 + j * nPoints];
1207 y_uc[j] = (unsigned char)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
1211 /* --------------------- uint16 ushort int ---------------------*/
1212 y_us = Getuint16OutPortPtrs(block, 1);
1213 ptr_us = (unsigned short int*) ptr->work;
1214 /* y_us[j]=ptr_us[inow+(j)*nPoints]; */
1219 y_us[j] = 0; /* Outputs set to zero */
1221 else if (OutEnd == 1)
1223 y_us[j] = ptr_us[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
1226 else if (Method == 0)
1234 y_us[j] = ptr_us[inow + (j) * nPoints];
1237 else if (Method >= 1)
1239 t1 = ptr->workt[inow];
1240 t2 = ptr->workt[inow + 1];
1241 y1 = (double)ptr_us[inow + j * nPoints];
1242 y2 = (double)ptr_us[inow + 1 + j * nPoints];
1243 y_us[j] = (unsigned short int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
1247 /* --------------------- uint32 ulong ---------------------*/
1248 y_ul = Getuint32OutPortPtrs(block, 1);
1249 ptr_ul = (unsigned int*) ptr->work;
1250 /* y_ul[j]=ptr_ul[inow+(j)*nPoints]; */
1255 y_ul[j] = 0; /* Outputs set to zero */
1257 else if (OutEnd == 1)
1259 y_ul[j] = ptr_ul[nPoints - 1 + (j) * nPoints]; /* Hold outputs at the end */
1262 else if (Method == 0)
1270 y_ul[j] = ptr_ul[inow + (j) * nPoints];
1273 else if (Method >= 1)
1275 t1 = ptr->workt[inow];
1276 t2 = ptr->workt[inow + 1];
1277 y1 = (double)ptr_ul[inow + j * nPoints];
1278 y2 = (double)ptr_ul[inow + 1 + j * nPoints];
1279 y_ul[j] = (unsigned int)((y2 - y1) * (t - t1) / (t2 - t1) + y1);
1286 /********************************************************************/
1291 /* Event date computation */
1292 /* Retrieve 'ptr' of the structure of the block */
1294 int nPoints = ptr->nPoints;
1295 int cnt1 = ptr->cnt1;
1296 int cnt2 = ptr->cnt2;
1297 int EVindex = ptr->EVindex;
1298 int PerEVcnt = ptr->PerEVcnt;
1300 /* Get current simulation time */
1301 //double t = get_scicos_time();
1303 double TNm1 = ptr->workt[nPoints - 1];
1304 double TP = TNm1 - 0;
1309 /* Generate Events only if ZC is active */
1310 if ((Method == 1) || (Method == 0))
1312 /*-------------------------*/
1313 if (ptr->firstevent == 1)
1315 jfirst = nPoints - 1; /* Finding first positive time instant */
1316 for (int j = 0; j < nPoints; ++j)
1318 if (ptr->workt[j] > 0)
1324 block->evout[0] = ptr->workt[jfirst];
1326 ptr->EVindex = EVindex;
1327 ptr->firstevent = 0;
1330 /*------------------------*/
1332 /*------------------------*/
1333 if (i < nPoints - 1)
1335 block->evout[0] = ptr->workt[i + 1] - ptr->workt[i];
1338 /*------------------------*/
1339 if (i == nPoints - 1)
1346 PerEVcnt++; /* When OutEnd==2 (perodic output) */
1347 jfirst = nPoints - 1; /* Finding first positive time instant */
1348 for (int j = 0; j < nPoints; ++j)
1350 if (ptr->workt[j] >= 0)
1356 block->evout[0] = ptr->workt[jfirst];
1360 /*-------------------------- */
1362 else if (Method <= 3)
1364 if (ptr->firstevent == 1)
1366 block->evout[0] = TP;
1367 ptr->firstevent = 0;
1373 block->evout[0] = TP;
1382 ptr->EVindex = EVindex;
1383 ptr->PerEVcnt = PerEVcnt;
1385 /***********************************************************************/
1394 if (ptr->D != nullptr)
1398 if (ptr->work != nullptr)
1400 delete[] (char*) ptr->work;
1402 if (ptr->workt != nullptr)
1404 delete[] ptr->workt;
1409 /***********************************************************************/
1420 /*************************************************************************/