summaryrefslogtreecommitdiff
path: root/modules/scicos_blocks/src/c/matbyscal.c
blob: b30d16712a58ec6a6c577a5cadd43ce5d00c4835 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*  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 <math.h>
#include "scicos.h"
#include "scicos_block4.h"
#include "dynlib_scicos_blocks.h"
/*--------------------------------------------------------------------------*/
#define matbscal_n(y1,u1,u2,mu,nu)  {for (i=0;i<mu*nu;i++) y1[i]=u1[i]*u2[0];}
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void matbyscal(scicos_block *block, int flag)
{
    if (flag == 1)
    {
        int i = 0;

        int ut = GetInType(block, 1);
        int mu = GetOutPortRows(block, 1);
        int nu = GetOutPortCols(block, 1);

        switch (ut)
        {
            case SCSREAL_N :
            {
                SCSREAL_COP *u1 = GetRealInPortPtrs(block, 1);
                SCSREAL_COP *u2 = GetRealInPortPtrs(block, 2);
                SCSREAL_COP *y1 = GetRealOutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSINT32_N :
            {
                SCSINT32_COP *u1 = Getint32InPortPtrs(block, 1);
                SCSINT32_COP *u2 = Getint32InPortPtrs(block, 2);
                SCSINT32_COP *y1 = Getint32OutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSINT16_N :
            {
                SCSINT16_COP *u1 = Getint16InPortPtrs(block, 1);
                SCSINT16_COP *u2 = Getint16InPortPtrs(block, 2);
                SCSINT16_COP *y1 = Getint16OutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSINT8_N :
            {
                SCSINT8_COP *u1 = Getint8InPortPtrs(block, 1);
                SCSINT8_COP *u2 = Getint8InPortPtrs(block, 2);
                SCSINT8_COP *y1 = Getint8OutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSUINT32_N :
            {
                SCSUINT32_COP *u1 = Getuint32InPortPtrs(block, 1);
                SCSUINT32_COP *u2 = Getuint32InPortPtrs(block, 2);
                SCSUINT32_COP *y1 = Getuint32OutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSUINT16_N :
            {
                SCSUINT16_COP *u1 = Getuint16InPortPtrs(block, 1);
                SCSUINT16_COP *u2 = Getuint16InPortPtrs(block, 2);
                SCSUINT16_COP *y1 = Getuint16OutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSUINT8_N :
            {
                SCSUINT8_COP *u1 = Getuint8InPortPtrs(block, 1);
                SCSUINT8_COP *u2 = Getuint8InPortPtrs(block, 2);
                SCSUINT8_COP *y1 = Getuint8OutPortPtrs(block, 1);
                matbscal_n(y1, u1, u2, mu, nu);
                break;
            }

            case SCSCOMPLEX_N :
            {
                SCSREAL_COP *u1r = GetRealInPortPtrs(block, 1);
                SCSREAL_COP *u2r = GetRealInPortPtrs(block, 2);
                SCSREAL_COP *y1r = GetRealOutPortPtrs(block, 1);
                SCSREAL_COP *u1i = GetImagInPortPtrs(block, 1);
                SCSREAL_COP *u2i = GetImagInPortPtrs(block, 2);
                SCSREAL_COP *y1i = GetImagOutPortPtrs(block, 1);
                for (i = 0; i < mu * nu; i++)
                {
                    y1r[i] = (u1r[i] * u2r[0]) - (u1i[i] * u2i[0]);
                    y1i[i] = (u1r[i] * u2i[0]) + (u1i[i] * u2r[0]);
                }
                break;
            }

            default :
            {
                set_block_error(-4);
                return;
            }
        }
    }

}
/*--------------------------------------------------------------------------*/