Use scicos_block4 typedef and avoid long use instead of int.
[scilab.git] / scilab / modules / scicos_blocks / src / c / matmul2_s.c
1 /*  Scicos
2 *
3 *  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * See the file ./license.txt
20 */
21 /*--------------------------------------------------------------------------*/
22 #include <math.h>
23 #include "scicos.h"
24 #include "scicos_block4.h"
25 #include "dynlib_scicos_blocks.h"
26 /*--------------------------------------------------------------------------*/
27 SCICOS_BLOCKS_IMPEXP void matmul2_s(scicos_block *block, int flag)
28 {
29     if (flag == 1)
30     {
31         int i = 0;
32         double v = 0.;
33         int ut = GetInType(block, 1);
34         int mu = GetOutPortRows(block, 1);
35         int nu = GetOutPortCols(block, 1);
36         double *rpar = GetRparPtrs(block);
37
38         switch (ut)
39         {
40             case SCSINT32_N :
41             {
42
43                 SCSINT32_COP *u1 = Getint32InPortPtrs(block, 1);
44                 SCSINT32_COP *u2 = Getint32InPortPtrs(block, 2);
45                 SCSINT32_COP *y1 = Getint32OutPortPtrs(block, 1);
46                 for (i = 0; i < mu * nu; i++)
47                 {
48                     v = (double)u1[i] * (double)u2[i];
49                     if (v < rpar[0])
50                     {
51                         v = rpar[0];
52                     }
53                     else if (v > rpar[1])
54                     {
55                         v = rpar[1];
56                     }
57                     y1[i] = (SCSINT32_COP)v;
58                 }
59                 break;
60             }
61
62             case SCSINT16_N :
63             {
64
65                 SCSINT16_COP *u1 = Getint16InPortPtrs(block, 1);
66                 SCSINT16_COP *u2 = Getint16InPortPtrs(block, 2);
67                 SCSINT16_COP *y1 = Getint16OutPortPtrs(block, 1);
68                 for (i = 0; i < mu * nu; i++)
69                 {
70                     v = (double)u1[i] * (double)u2[i];
71                     if (v < rpar[0])
72                     {
73                         v = rpar[0];
74                     }
75                     else if (v > rpar[1])
76                     {
77                         v = rpar[1];
78                     }
79                     y1[i] = (SCSINT16_COP)v;
80                 }
81                 break;
82             }
83
84             case SCSINT8_N :
85             {
86
87                 SCSINT8_COP *u1 = Getint8InPortPtrs(block, 1);
88                 SCSINT8_COP *u2 = Getint8InPortPtrs(block, 2);
89                 SCSINT8_COP *y1 = Getint8OutPortPtrs(block, 1);
90                 for (i = 0; i < mu * nu; i++)
91                 {
92                     v = (double)u1[i] * (double)u2[i];
93                     if (v < rpar[0])
94                     {
95                         v = rpar[0];
96                     }
97                     else if (v > rpar[1])
98                     {
99                         v = rpar[1];
100                     }
101                     y1[i] = (SCSINT8_COP)v;
102                 }
103                 break;
104             }
105
106             case SCSUINT32_N :
107             {
108
109                 SCSUINT32_COP *u1 = Getuint32InPortPtrs(block, 1);
110                 SCSUINT32_COP *u2 = Getuint32InPortPtrs(block, 2);
111                 SCSUINT32_COP *y1 = Getuint32OutPortPtrs(block, 1);
112                 for (i = 0; i < mu * nu; i++)
113                 {
114                     v = (double)u1[i] * (double)u2[i];
115                     if (v < rpar[0])
116                     {
117                         v = rpar[0];
118                     }
119                     else if (v > rpar[1])
120                     {
121                         v = rpar[1];
122                     }
123                     y1[i] = (SCSUINT32_COP)v;
124                 }
125                 break;
126             }
127
128             case SCSUINT16_N :
129             {
130
131                 SCSUINT16_COP *u1 = Getuint16InPortPtrs(block, 1);
132                 SCSUINT16_COP *u2 = Getuint16InPortPtrs(block, 2);
133                 SCSUINT16_COP *y1 = Getuint16OutPortPtrs(block, 1);
134                 for (i = 0; i < mu * nu; i++)
135                 {
136                     v = (double)u1[i] * (double)u2[i];
137                     if (v < rpar[0])
138                     {
139                         v = rpar[0];
140                     }
141                     else if (v > rpar[1])
142                     {
143                         v = rpar[1];
144                     }
145                     y1[i] = (SCSUINT16_COP)v;
146                 }
147                 break;
148             }
149
150             case SCSUINT8_N :
151             {
152
153                 SCSUINT8_COP *u1 = Getuint8InPortPtrs(block, 1);
154                 SCSUINT8_COP *u2 = Getuint8InPortPtrs(block, 2);
155                 SCSUINT8_COP *y1 = Getuint8OutPortPtrs(block, 1);
156                 for (i = 0; i < mu * nu; i++)
157                 {
158                     v = (double)u1[i] * (double)u2[i];
159                     if (v < rpar[0])
160                     {
161                         v = rpar[0];
162                     }
163                     else if (v > rpar[1])
164                     {
165                         v = rpar[1];
166                     }
167                     y1[i] = (SCSUINT8_COP)v;
168                 }
169                 break;
170             }
171
172             default :
173             {
174                 set_block_error(-4);
175                 return;
176             }
177         }
178     }
179
180 }
181 /*--------------------------------------------------------------------------*/