99dd0cbf2ffe186178e32c9df201a788ba08d89e
[scilab.git] / scilab / modules / scicos_blocks / src / c / matmul2_e.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 <stdio.h>
24 #include "scicos.h"
25 #include "scicos_block4.h"
26 #include "sciprint.h"
27 #include "localization.h"
28 #include "dynlib_scicos_blocks.h"
29 /*--------------------------------------------------------------------------*/
30 SCICOS_BLOCKS_IMPEXP void matmul2_e(scicos_block *block, int flag)
31 {
32     if (flag == 1)
33     {
34         int i = 0;
35         double v = 0.;
36         int ut = GetInType(block, 1);
37         int mu = GetOutPortRows(block, 1);
38         int nu = GetOutPortCols(block, 1);
39         double *rpar = GetRparPtrs(block);
40
41         switch (ut)
42         {
43             case SCSINT32_N :
44             {
45
46                 long *u1 = Getint32InPortPtrs(block, 1);
47                 long *u2 = Getint32InPortPtrs(block, 2);
48                 long *y1 = Getint32OutPortPtrs(block, 1);
49                 for (i = 0; i < mu * nu; i++)
50                 {
51                     v = (double)u1[i] * (double)u2[i];
52                     if ((v < rpar[0]) | (v > rpar[1]))
53                     {
54                         sciprint(_("overflow error"));
55                         set_block_error(-4);
56                         return;
57                     }
58                     else
59                     {
60                         y1[i] = (long)v;
61                     }
62                 }
63                 break;
64             }
65
66             case SCSINT16_N :
67             {
68
69                 short *u1 = Getint16InPortPtrs(block, 1);
70                 short *u2 = Getint16InPortPtrs(block, 2);
71                 short *y1 = Getint16OutPortPtrs(block, 1);
72                 for (i = 0; i < mu * nu; i++)
73                 {
74                     v = (double)u1[i] * (double)u2[i];
75                     if ((v < rpar[0]) | (v > rpar[1]))
76                     {
77                         sciprint(_("overflow error"));
78                         set_block_error(-4);
79                         return;
80                     }
81                     else
82                     {
83                         y1[i] = (short)v;
84                     }
85                 }
86                 break;
87             }
88
89             case SCSINT8_N :
90             {
91
92                 char *u1 = Getint8InPortPtrs(block, 1);
93                 char *u2 = Getint8InPortPtrs(block, 2);
94                 char *y1 = Getint8OutPortPtrs(block, 1);
95                 for (i = 0; i < mu * nu; i++)
96                 {
97                     v = (double)u1[i] * (double)u2[i];
98                     if ((v < rpar[0]) | (v > rpar[1]))
99                     {
100                         sciprint(_("overflow error"));
101                         set_block_error(-4);
102                         return;
103                     }
104                     else
105                     {
106                         y1[i] = (char)v;
107                     }
108                 }
109                 break;
110             }
111
112             case SCSUINT32_N :
113             {
114
115                 unsigned long *u1 = Getuint32InPortPtrs(block, 1);
116                 unsigned long *u2 = Getuint32InPortPtrs(block, 2);
117                 unsigned long *y1 = Getuint32OutPortPtrs(block, 1);
118                 for (i = 0; i < mu * nu; i++)
119                 {
120                     v = (double)u1[i] * (double)u2[i];
121                     if ((v < rpar[0]) | (v > rpar[1]))
122                     {
123                         sciprint(_("overflow error"));
124                         set_block_error(-4);
125                         return;
126                     }
127                     else
128                     {
129                         y1[i] = (unsigned long)v;
130                     }
131                 }
132                 break;
133             }
134
135             case SCSUINT16_N :
136             {
137
138                 unsigned short *u1 = Getuint16InPortPtrs(block, 1);
139                 unsigned short *u2 = Getuint16InPortPtrs(block, 2);
140                 unsigned short *y1 = Getuint16OutPortPtrs(block, 1);
141                 for (i = 0; i < mu * nu; i++)
142                 {
143                     v = (double)u1[i] * (double)u2[i];
144                     if ((v < rpar[0]) | (v > rpar[1]))
145                     {
146                         sciprint(_("overflow error"));
147                         set_block_error(-4);
148                         return;
149                     }
150                     else
151                     {
152                         y1[i] = (unsigned short)v;
153                     }
154                 }
155                 break;
156             }
157
158             case SCSUINT8_N :
159             {
160
161                 unsigned char *u1 = Getuint8InPortPtrs(block, 1);
162                 unsigned char *u2 = Getuint8InPortPtrs(block, 2);
163                 unsigned char *y1 = Getuint8OutPortPtrs(block, 1);
164                 for (i = 0; i < mu * nu; i++)
165                 {
166                     v = (double)u1[i] * (double)u2[i];
167                     if ((v < rpar[0]) | (v > rpar[1]))
168                     {
169                         sciprint(_("overflow error"));
170                         set_block_error(-4);
171                         return;
172                     }
173                     else
174                     {
175                         y1[i] = (unsigned char)v;
176                     }
177                 }
178                 break;
179             }
180
181             default :
182             {
183                 set_block_error(-4);
184                 return;
185             }
186         }
187     }
188 }
189 /*--------------------------------------------------------------------------*/