summaryrefslogtreecommitdiff
path: root/modules/scicos_blocks/src/c/mswitch.c
blob: 5ec8b5fb8aec5a837008fd178d69277721beb96f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*  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 <string.h>
#include <math.h>
#include "core_math.h"
#include "scicos_block4.h"
#include "MALLOC.h"
#include "dynlib_scicos_blocks.h"
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void  mswitch(scicos_block *block, int flag)
{
    if ((flag == 1) || (flag == 6))
    {
        int i = 0, j = 0, nin = 0, so = 0, my = 0, ny = 0;
        int mu = 0, nu = 0;
        int *ipar = NULL;
        double *u1 = NULL;
        void *uj = NULL;
        void *y = NULL;

        y = GetOutPortPtrs(block, 1);
        so = GetSizeOfOut(block, 1);
        my = GetOutPortRows(block, 1);
        ny = GetOutPortCols(block, 1);
        u1 = GetRealInPortPtrs(block, 1);
        ipar = GetIparPtrs(block);
        nin = GetNin(block);
        i = *(ipar + 1);
        if (i == 0)
        {
            if (*u1 > 0)
            {
                j = (int)floor(*u1);
            }
            else
            {
                j = (int)ceil(*u1);
            }
        }
        else if (i == 1)
        {
            if (*u1 > 0)
            {
                j = (int)floor(*u1 + .5);
            }
            else
            {
                j = (int)ceil(*u1 - .5);
            }
        }
        else if (i == 2)
        {
            j = (int)ceil(*u1);
        }
        else if (i == 3)
        {
            j = (int)floor(*u1);
        }
        j = j + 1 - *ipar;
        j = Max(j, 1);
        if (nin == 2)
        {
            mu = GetInPortRows(block, 2);
            nu = GetInPortCols(block, 2);
            uj = GetInPortPtrs(block, 2);
            j = Min(j, mu * nu);
            memcpy(y, (char *)uj + (j - 1)*my * ny * so, my * ny * so);
        }
        else
        {
            j = Min(j, nin - 1);
            uj = GetInPortPtrs(block, j + 1);
            memcpy(y, uj, my * ny * so);
        }
    }
}
/*--------------------------------------------------------------------------*/