889af62113681482946a5a1ecd680360399e10bb
[scilab.git] / scilab / modules / scicos_blocks / src / c / convert.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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * See the file ./license.txt
20 */
21 /*--------------------------------------------------------------------------*/ 
22 #include <math.h>
23 #include <memory.h>
24 #include "scicos_block4.h"
25 #include "sciprint.h"
26 #include "localization.h"
27 /*--------------------------------------------------------------------------*/ 
28 void convert(scicos_block *block,int flag)
29 {
30  int m,n,i;
31  int *ipar;
32  double v,w,k;
33  
34  m=GetInPortRows(block,1);
35  n=GetInPortCols(block,1);
36  ipar=GetIparPtrs(block);
37  
38  if ((flag==1)|(flag==6))
39     {
40      switch (*ipar){
41             case 1:{ 
42                    void *u,*y;
43                    int so;
44                    so=GetSizeOfOut(block,1);
45                    u=GetInPortPtrs(block,1);
46                    y=GetOutPortPtrs(block,1);
47                    memcpy(y,u,m*n*so);
48                    break;}
49             case 2:{
50                    double *u;
51                    long *y;
52                    u=GetRealInPortPtrs(block,1);
53                    y=Getint32OutPortPtrs(block,1);
54                    k=pow(2,32);
55                    for (i=0;i<m*n;i++) 
56                         {v=(double)u[i];
57                          w=v-(double)((int)(v/k))*k;
58                          if (fabs(w)>k/2-1)
59                              {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
60                              else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
61                              }
62                          y[i]=(long)w;}
63                    break;}
64             case 3:{
65                    double *u;
66                    short *y;
67                    u=GetRealInPortPtrs(block,1);
68                    y=Getint16OutPortPtrs(block,1);
69                    k=pow(2,16);
70                    for (i=0;i<m*n;i++) 
71                         {v=(double)u[i];
72                          w=v-(double)((int)(v/k))*k;
73                          if (fabs(w)>k/2-1)
74                              {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
75                              else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
76                              }
77                          y[i]=(short)w;}
78                    break;}
79             case 4:{
80                    double *u;
81                    char *y;
82                    u=GetRealInPortPtrs(block,1);
83                    y=Getint8OutPortPtrs(block,1);
84                    k=pow(2,8);
85                    for (i=0;i<m*n;i++) 
86                         {v=(double)u[i];
87                          w=v-(double)((int)(v/k))*k;
88                          if (fabs(w)>k/2-1)
89                              {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
90                              else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
91                              }
92                          y[i]=(char)w;}
93                    break;}
94             case 5:{
95                    double *u;
96                    unsigned long *y;
97                    u=GetRealInPortPtrs(block,1);
98                    y=Getuint32OutPortPtrs(block,1);
99                    k=pow(2,32);
100                    for (i=0;i<m*n;i++) 
101                         {v=(double)u[i];
102                          w=v-(double)((int)(v/k))*k;
103                          y[i]=(unsigned long)w;}
104                    break;}
105             case 6:{
106                    double *u;
107                    unsigned short *y;
108                    u=GetRealInPortPtrs(block,1);
109                    y=Getuint16OutPortPtrs(block,1);
110                    k=pow(2,16);
111                    for (i=0;i<m*n;i++) 
112                         {v=(double)u[i];
113                          w=v-(double)((int)(v/k))*k;
114                          y[i]=(unsigned short)w;}
115                    break;}
116             case 7:{
117                    double *u;
118                    unsigned char *y;
119                    u=GetRealInPortPtrs(block,1);
120                    y=Getuint8OutPortPtrs(block,1);
121                    k=pow(2,8);
122                    for (i=0;i<m*n;i++) 
123                         {v=(double)u[i];
124                          w=v-(double)((int)(v/k))*k;
125                          y[i]=(unsigned char)w;}
126                    break;}
127             case 8:{
128                    long *u;
129                    double *y;
130                    u=Getint32InPortPtrs(block,1);
131                    y=GetRealOutPortPtrs(block,1);
132                    for (i=0;i<m*n;i++) y[i]=(double) u[i];
133                    break;}
134             case 9:{
135                    long *u;
136                    short *y;
137                    u=Getint32InPortPtrs(block,1);
138                    y=Getint16OutPortPtrs(block,1);
139                    k=pow(2,16);
140                    for (i=0;i<m*n;i++) 
141                         {v=(double)u[i];
142                          w=v-(double)((int)(v/k))*k;
143                          if (fabs(w)>k/2-1)
144                              {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
145                              else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
146                              }
147                          y[i]=(short)w;}
148                    break;}
149             case 10:{
150                    long *u;
151                    char *y;
152                    u=Getint32InPortPtrs(block,1);
153                    y=Getint8OutPortPtrs(block,1);
154                    k=pow(2,8);
155                    for (i=0;i<m*n;i++) 
156                         {v=(double)u[i];
157                          w=v-(double)((int)(v/k))*k;
158                          if (fabs(w)>k/2-1)
159                              {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
160                              else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
161                              }
162                          y[i]=(char)w;}
163                    break;}
164             case 11:{
165                    long *u;
166                    unsigned short *y;
167                    u=Getint32InPortPtrs(block,1);
168                    y=Getuint16OutPortPtrs(block,1);
169                    k=pow(2,16);
170                    for (i=0;i<m*n;i++) 
171                         {v=(double)u[i];
172                          w=v-(double)((int)(v/k))*k;
173                          y[i]=(unsigned short)w;}
174                    break;}
175             case 12:{
176                    long *u;
177                    unsigned char *y;
178                    u=Getint32InPortPtrs(block,1);
179                    y=Getuint8OutPortPtrs(block,1);
180                    k=pow(2,8);
181                    for (i=0;i<m*n;i++) 
182                         {v=(double)u[i];
183                          w=v-(double)((int)(v/k))*k;
184                          y[i]=(unsigned char)w;}
185                    break;}
186             case 13:{
187                    short *u;
188                    double *y;
189                    u=Getint16InPortPtrs(block,1);
190                    y=GetRealOutPortPtrs(block,1);
191                    for (i=0;i<m*n;i++) y[i]=(double) u[i];
192                    break;}
193             case 14:{
194                    short *u;
195                    long *y;
196                    u=Getint16InPortPtrs(block,1);
197                    y=Getint32OutPortPtrs(block,1);
198                    for (i=0;i<m*n;i++) 
199                         {y[i]=(long)u[i];}
200                    break;}
201             case 15:{
202                    short *u;
203                    char *y;
204                    u=Getint16InPortPtrs(block,1);
205                    y=Getint8OutPortPtrs(block,1);
206                    k=pow(2,8);
207                    for (i=0;i<m*n;i++) 
208                         {v=(double)u[i];
209                          w=v-(double)((int)(v/k))*k;
210                          if (fabs(w)>k/2-1)
211                              {if (w>=0) w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
212                              else w=-(-(k/2)+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
213                              }
214                          y[i]=(char)w;}
215                    break;}
216             case 16:{
217                    short *u;
218                    unsigned long *y;
219                    u=Getint16InPortPtrs(block,1);
220                    y=Getuint32OutPortPtrs(block,1);
221                    for (i=0;i<m*n;i++) 
222                         {y[i]=(unsigned long)u[i];}
223                    break;}
224             case 17:{
225                    short *u;
226                    unsigned char *y;
227                    u=Getint16InPortPtrs(block,1);
228                    y=Getuint8OutPortPtrs(block,1);
229                    k=pow(2,8);
230                    for (i=0;i<m*n;i++) 
231                         {v=(double)u[i];
232                          w=v-(double)((int)(v/k))*k;
233                          y[i]=(unsigned char)w;}
234                    break;}
235             case 18:{
236                    char *u;
237                    double *y;
238                    u=Getint8InPortPtrs(block,1);
239                    y=GetRealOutPortPtrs(block,1);
240                    for (i=0;i<m*n;i++) y[i]=(double) u[i];
241                    break;}
242             case 19:{
243                    char *u;
244                    long *y;
245                    u=Getint8InPortPtrs(block,1);
246                    y=Getint32OutPortPtrs(block,1);
247                    for (i=0;i<m*n;i++) 
248                         {y[i]=(long)u[i];}
249                    break;}
250             case 20:{
251                    char *u;
252                    short *y;
253                    u=Getint8InPortPtrs(block,1);
254                    y=Getint16OutPortPtrs(block,1);
255                    for (i=0;i<m*n;i++) 
256                         {y[i]=(short)u[i];}
257                    break;}
258             case 21:{
259                    char *u;
260                    unsigned long *y;
261                    u=Getint8InPortPtrs(block,1);
262                    y=Getuint32OutPortPtrs(block,1);
263                    for (i=0;i<m*n;i++) 
264                         {y[i]=(unsigned long)u[i];}
265                    break;}
266             case 22:{
267                    char *u;
268                    unsigned short *y;
269                    u=Getint8InPortPtrs(block,1);
270                    y=Getuint16OutPortPtrs(block,1);
271                    for (i=0;i<m*n;i++) 
272                         {y[i]=(unsigned short)u[i];}
273                    break;}
274             case 23:{
275                    unsigned long *u;
276                    double *y;
277                    u=Getuint32InPortPtrs(block,1);
278                    y=GetRealOutPortPtrs(block,1);
279                    for (i=0;i<m*n;i++) y[i]=(double) u[i];
280                    break;}
281             case 24:{
282                    unsigned long *u;
283                    short *y;
284                    u=Getuint32InPortPtrs(block,1);
285                    y=Getint16OutPortPtrs(block,1);
286                    k=pow(2,16);
287                    for (i=0;i<m*n;i++) 
288                         {v=(double)u[i];
289                          w=v-(double)((int)(v/k))*k;
290                          if ((w)>k/2-1)
291                              { w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
292                              }
293                          y[i]=(short)w;}
294                    break;}
295             case 25:{
296                    unsigned long *u;
297                    char *y;
298                    u=Getuint32InPortPtrs(block,1);
299                    y=Getint8OutPortPtrs(block,1);
300                    k=pow(2,8);
301                    for (i=0;i<m*n;i++) 
302                         {v=(double)u[i];
303                          w=v-(double)((int)(v/k))*k;
304                          if ((w)>k/2-1)
305                              {w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
306                              }
307                          y[i]=(char)w;}
308                    break;}
309             case 26:{
310                    unsigned long *u;
311                    unsigned short *y;
312                    u=Getuint32InPortPtrs(block,1);
313                    y=Getuint16OutPortPtrs(block,1);
314                    k=pow(2,16);
315                    for (i=0;i<m*n;i++) 
316                         {v=(double)u[i];
317                          w=v-(double)((int)(v/k))*k;
318                          y[i]=(unsigned short)w;}
319                    break;}
320             case 27:{
321                    unsigned long *u;
322                    unsigned char *y;
323                    u=Getuint32InPortPtrs(block,1);
324                    y=Getuint8OutPortPtrs(block,1);
325                    k=pow(2,8);
326                    for (i=0;i<m*n;i++) 
327                         {v=(double)u[i];
328                          w=v-(double)((int)(v/k))*k;
329                          y[i]=(unsigned char)w;}
330                    break;}
331             case 28:{
332                    unsigned short *u;
333                    double *y;
334                    u=Getuint16InPortPtrs(block,1);
335                    y=GetRealOutPortPtrs(block,1);
336                    for (i=0;i<m*n;i++) y[i]=(double) u[i];
337                    break;}
338             case 29:{
339                    unsigned short *u;
340                    long *y;
341                    u=Getuint16InPortPtrs(block,1);
342                    y=Getint32OutPortPtrs(block,1);
343                    for (i=0;i<m*n;i++) 
344                         {y[i]=(long)u[i];}
345                    break;}
346             case 30:{
347                    unsigned short *u;
348                    char *y;
349                    u=Getuint16InPortPtrs(block,1);
350                    y=Getint8OutPortPtrs(block,1);
351                    k=pow(2,8);
352                    for (i=0;i<m*n;i++) 
353                         {v=(double)u[i];
354                          w=v-(double)((int)(v/k))*k;
355                          if (w>k/2-1)
356                              {w=(-k/2+fabs(w-(double)((int)(w/(k/2)))*(k/2)));
357                              }
358                          y[i]=(char)w;}
359                    break;}
360             case 31:{
361                    unsigned short *u;
362                    unsigned long *y;
363                    u=Getuint16InPortPtrs(block,1);
364                    y=Getuint32OutPortPtrs(block,1);
365                    for (i=0;i<m*n;i++) 
366                         {y[i]=(unsigned long)u[i];}
367                    break;}
368             case 32:{
369                    unsigned short *u;
370                    unsigned char *y;
371                    u=Getuint16InPortPtrs(block,1);
372                    y=Getuint8OutPortPtrs(block,1);
373                    k=pow(2,8);
374                    for (i=0;i<m*n;i++) 
375                         {v=(double)u[i];
376                          w=v-(double)((int)(v/k))*k;
377                          y[i]=(unsigned char)w;}
378                    break;}
379             case 33:{
380                    unsigned char *u;
381                    double *y;
382                    u=Getuint8InPortPtrs(block,1);
383                    y=GetRealOutPortPtrs(block,1);
384                    for (i=0;i<m*n;i++) y[i]=(double) u[i];
385                    break;}
386             case 34:{
387                    unsigned char *u;
388                    long *y;
389                    u=Getuint8InPortPtrs(block,1);
390                    y=Getint32OutPortPtrs(block,1);
391                    for (i=0;i<m*n;i++) 
392                         {y[i]=(long)u[i];}
393                    break;}
394             case 35:{
395                    unsigned char *u;
396                    short *y;
397                    u=Getuint8InPortPtrs(block,1);
398                    y=Getint16OutPortPtrs(block,1);
399                    for (i=0;i<m*n;i++) 
400                         {y[i]=(short)u[i];}
401                    break;}
402             case 36:{
403                    unsigned char *u;
404                    unsigned long *y;
405                    u=Getuint8InPortPtrs(block,1);
406                    y=Getuint32OutPortPtrs(block,1);
407                    for (i=0;i<m*n;i++) 
408                         {y[i]=(unsigned long)u[i];}
409                    break;}
410             case 37:{
411                    unsigned char *u;
412                    unsigned short *y;
413                    u=Getuint8InPortPtrs(block,1);
414                    y=Getuint16OutPortPtrs(block,1);
415                    for (i=0;i<m*n;i++) 
416                         {y[i]=(unsigned short)u[i];}
417                    break;}
418             case 38:{
419                    double *u;
420                    long *y;
421                    u=GetRealInPortPtrs(block,1);
422                    y=Getint32OutPortPtrs(block,1);
423                    k=pow(2,32);
424                    for (i=0;i<m*n;i++)
425                        {if (u[i]>k/2-1)
426                            {y[i]=(long)(k/2-1);}
427                         else if (u[i]<-(k/2))
428                            {y[i]=-(long)(k/2);}
429                         else {y[i]=(long)(u[i]);}
430                        }
431                    break;}
432             case 39:{
433                    double *u;
434                    short *y;
435                    u=GetRealInPortPtrs(block,1);
436                    y=Getint16OutPortPtrs(block,1);
437                    k=pow(2,16);
438                    for (i=0;i<m*n;i++) 
439                         {if (u[i]>k/2-1)
440                            {y[i]=(short)(k/2-1);}
441                         else if (u[i]<-(k/2))
442                            {y[i]=-(short)(k/2);}
443                         else {y[i]=(short)(u[i]);}
444                        }
445                    break;}
446             case 40:{
447                    double *u;
448                    char *y;
449                    u=GetRealInPortPtrs(block,1);
450                    y=Getint8OutPortPtrs(block,1);
451                    k=pow(2,8);
452                    for (i=0;i<m*n;i++) 
453                         {if (u[i]>k/2-1)
454                            {y[i]=(char)(k/2-1);}
455                         else if (u[i]<-(k/2))
456                            {y[i]=-(char)(k/2);}
457                         else {y[i]=(char)(u[i]);}
458                        }
459                    break;}
460             case 41:{
461                    double *u;
462                    unsigned long *y;
463                    u=GetRealInPortPtrs(block,1);
464                    y=Getuint32OutPortPtrs(block,1);
465                    k=pow(2,32);
466                    for (i=0;i<m*n;i++) 
467                         {if (u[i]>=k)
468                              {y[i]=(unsigned long)(k-1);}
469                         else if (u[i]<0)
470                              {y[i]=0;}
471                         else {y[i]=(unsigned long)(u[i]);}
472                         }
473                    break;}
474             case 42:{
475                    double *u;
476                    unsigned short *y;
477                    u=GetRealInPortPtrs(block,1);
478                    y=Getuint16OutPortPtrs(block,1);
479                    k=pow(2,16);
480                    for (i=0;i<m*n;i++) 
481                         {if (u[i]>=k)
482                              {y[i]=(unsigned short)(k-1);}
483                         else if (u[i]<0)
484                              {y[i]=0;}
485                         else {y[i]=(unsigned short)(u[i]);}
486                         }
487                    break;}
488             case 43:{
489                    double *u;
490                    unsigned char *y;
491                    u=GetRealInPortPtrs(block,1);
492                    y=Getuint8OutPortPtrs(block,1);
493                    k=pow(2,8);
494                    for (i=0;i<m*n;i++) 
495                         {if (u[i]>=k)
496                              {y[i]=(unsigned char)(k-1);}
497                         else if (u[i]<0)
498                              {y[i]=0;}
499                         else {y[i]=(unsigned char)(u[i]);}
500                         }
501                    break;}
502             case 44:{
503                    long *u;
504                    short *y;
505                    u=Getint32InPortPtrs(block,1);
506                    y=Getint16OutPortPtrs(block,1);
507                    k=pow(2,16);
508                    for (i=0;i<m*n;i++) 
509                         {if (u[i]>(long)(k/2-1))
510                            {y[i]=(short)(k/2-1);}
511                         else if (u[i]<-(long)(k/2))
512                            {y[i]=-(short)(k/2);}
513                         else {y[i]=(short)(u[i]);}
514                        }
515                    break;}
516             case 45:{
517                    long *u;
518                    char *y;
519                    u=Getint32InPortPtrs(block,1);
520                    y=Getint8OutPortPtrs(block,1);
521                    k=pow(2,8);
522                    for (i=0;i<m*n;i++) 
523                         {if (u[i]>(long)(k/2-1))
524                            {y[i]=(char)(k/2-1);}
525                         else if (u[i]<-(long)(k/2))
526                            {y[i]=-(char)(k/2);}
527                         else {y[i]=(char)(u[i]);}
528                        }
529                    break;}
530             case 46:{
531                    long *u;
532                    unsigned long *y;
533                    u=Getint32InPortPtrs(block,1);
534                    y=Getuint32OutPortPtrs(block,1);
535                    for (i=0;i<m*n;i++) 
536                         {if (u[i]<0)
537                              {y[i]=0;}
538                         else {y[i]=(unsigned long)(u[i]);}
539                         }
540                    break;}
541             case 47:{
542                    long *u;
543                    unsigned short *y;
544                    u=Getint32InPortPtrs(block,1);
545                    y=Getuint16OutPortPtrs(block,1);
546                    k=pow(2,16);
547                    for (i=0;i<m*n;i++) 
548                         {if (u[i]>=(long)(k))
549                              {y[i]=(unsigned short)(k-1);}
550                         else if (u[i]<0)
551                              {y[i]=0;}
552                         else {y[i]=(unsigned short)(u[i]);}
553                         }
554                    break;}
555             case 48:{
556                    long *u;
557                    unsigned char *y;
558                    u=Getint32InPortPtrs(block,1);
559                    y=Getuint8OutPortPtrs(block,1);
560                    k=pow(2,8);
561                    for (i=0;i<m*n;i++) 
562                         {if (u[i]>=(long)k)
563                              {y[i]=(unsigned char)(k-1);}
564                         else if (u[i]<0)
565                              {y[i]=0;}
566                         else {y[i]=(unsigned char)(u[i]);}
567                         }
568                    break;}
569             case 49:{
570                    short *u;
571                    char *y;
572                    u=Getint16InPortPtrs(block,1);
573                    y=Getint8OutPortPtrs(block,1);
574                    k=pow(2,8);
575                    for (i=0;i<m*n;i++) 
576                         {if (u[i]>(short)(k/2-1))
577                            {y[i]=(char)(k/2-1);}
578                         else if (u[i]<-(short)(k/2))
579                            {y[i]=-(char)(k/2);}
580                         else {y[i]=(char)(u[i]);}
581                        }
582                    break;}
583             case 50:{
584                    short *u;
585                    unsigned long *y;
586                    u=Getint16InPortPtrs(block,1);
587                    y=Getuint32OutPortPtrs(block,1);
588                    for (i=0;i<m*n;i++) 
589                         {if (u[i]<0)  y[i]=0;
590                          else y[i]=(unsigned long)u[i];}
591                    break;}
592             case 51:{
593                    short *u;
594                    unsigned short *y;
595                    u=Getint16InPortPtrs(block,1);
596                    y=Getuint16OutPortPtrs(block,1);
597                    for (i=0;i<m*n;i++) 
598                         {if (u[i]<0)
599                              {y[i]=0;}
600                         else {y[i]=(unsigned short)(u[i]);}
601                         }
602                    break;}
603             case 52:{
604                    short *u;
605                    unsigned char *y;
606                    u=Getint16InPortPtrs(block,1);
607                    y=Getuint8OutPortPtrs(block,1);
608                    k=pow(2,8);
609                    for (i=0;i<m*n;i++) 
610                         {if (u[i]>=(short)k)
611                              {y[i]=(unsigned char)(k-1);}
612                         else if (u[i]<0)
613                              {y[i]=0;}
614                         else {y[i]=(unsigned char)(u[i]);}
615                         }
616                    break;}
617             case 53:{
618                    char *u;
619                    unsigned long *y;
620                    u=Getint8InPortPtrs(block,1);
621                    y=Getuint32OutPortPtrs(block,1);
622                    for (i=0;i<m*n;i++) 
623                         {if (u[i]<0)  y[i]=0;
624                          else y[i]=(unsigned long)u[i];}
625                    break;}
626             case 54:{
627                    char *u;
628                    unsigned short *y;
629                    u=Getint8InPortPtrs(block,1);
630                    y=Getuint16OutPortPtrs(block,1);
631                    for (i=0;i<m*n;i++) 
632                         {if (u[i]<0)
633                              {y[i]=0;}
634                         else {y[i]=(unsigned short)(u[i]);}
635                         }
636                    break;}
637             case 55:{
638                    char *u;
639                    unsigned char *y;
640                    u=Getint8InPortPtrs(block,1);
641                    y=Getuint8OutPortPtrs(block,1);
642                    for (i=0;i<m*n;i++) 
643                         {if (u[i]<0)
644                              {y[i]=0;}
645                         else {y[i]=(unsigned char)(u[i]);}
646                         }
647                    break;}
648             case 56:{
649                    long *y;
650                    unsigned long *u;
651                    u=Getuint32InPortPtrs(block,1);
652                    y=Getint32OutPortPtrs(block,1);
653                    k=pow(2,32);
654                    for (i=0;i<m*n;i++) 
655                         {if (u[i]>(unsigned long)(k/2-1))
656                              {y[i]=(long)(k/2-1);}
657                         else {y[i]=(long)(u[i]);}
658                         }
659                    break;}
660             case 57:{
661                    unsigned long *u;
662                    short *y;
663                    u=Getuint32InPortPtrs(block,1);
664                    y=Getint16OutPortPtrs(block,1);
665                    k=pow(2,16);
666                    for (i=0;i<m*n;i++) 
667                         {if (u[i]>(unsigned long)(k/2-1))
668                              {y[i]=(short)(k/2-1);}
669                         else {y[i]=(short)(u[i]);}
670                         }
671                    break;}
672             case 58:{
673                    unsigned long *u;
674                    char *y;
675                    u=Getuint32InPortPtrs(block,1);
676                    y=Getint8OutPortPtrs(block,1);
677                    k=pow(2,8);
678                    for (i=0;i<m*n;i++) 
679                         {if (u[i]>(unsigned long)(k/2-1))
680                              {y[i]=(char)(k/2-1);}
681                         else {y[i]=(char)(u[i]);}
682                         }
683                    break;}
684             case 59:{
685                    unsigned long *u;
686                    unsigned short *y;
687                    u=Getuint32InPortPtrs(block,1);
688                    y=Getuint16OutPortPtrs(block,1);
689                    k=pow(2,16);
690                    for (i=0;i<m*n;i++) 
691                         {if (u[i]>(unsigned long)(k/2-1))
692                              {y[i]=(unsigned short)(k/2-1);}
693                         else {y[i]=(unsigned short)(u[i]);}
694                         }
695                    break;}
696             case 60:{
697                    unsigned long *u;
698                    unsigned char *y;
699                    u=Getuint32InPortPtrs(block,1);
700                    y=Getuint8OutPortPtrs(block,1);
701                    k=pow(2,8);
702                    for (i=0;i<m*n;i++) 
703                         {if (u[i]>(unsigned long)(k/2-1))
704                              {y[i]=(unsigned char)(k/2-1);}
705                         else {y[i]=(unsigned char)(u[i]);}
706                         }
707                    break;}
708             case 61:{
709                    unsigned short *u;
710                    short *y;
711                    u=Getuint16InPortPtrs(block,1);
712                    y=Getint16OutPortPtrs(block,1);
713                    k=pow(2,16);
714                    for (i=0;i<m*n;i++) 
715                         {if (u[i]>(unsigned short)(k/2-1))
716                              {y[i]=(short)(k/2-1);}
717                         else {y[i]=(short)(u[i]);}
718                         }
719                    break;}
720             case 62:{
721                    unsigned short *u;
722                    char *y;
723                    u=Getuint16InPortPtrs(block,1);
724                    y=Getint8OutPortPtrs(block,1);
725                    k=pow(2,8);
726                    for (i=0;i<m*n;i++) 
727                         {if (u[i]>(unsigned short)(k/2-1))
728                              {y[i]=(char)(k/2-1);}
729                         else {y[i]=(char)(u[i]);}
730                         }
731                    break;}
732             case 63:{
733                    unsigned short *u;
734                    unsigned char *y;
735                    u=Getuint16InPortPtrs(block,1);
736                    y=Getuint8OutPortPtrs(block,1);
737                    k=pow(2,8);
738                    for (i=0;i<m*n;i++) 
739                         {if (u[i]>(unsigned short)(k/2-1))
740                              {y[i]=(unsigned char)k/2-1;}
741                         else {y[i]=(unsigned char)(u[i]);}
742                         }
743                    break;}
744             case 64:{
745                    unsigned char *u;
746                    char *y;
747                    u=Getuint8InPortPtrs(block,1);
748                    y=Getint8OutPortPtrs(block,1);
749                    k=pow(2,8);
750                    for (i=0;i<m*n;i++) 
751                         {if (u[i]>(unsigned char)(k/2-1))
752                              {y[i]=(char)(k/2-1);}
753                         else {y[i]=(char)(u[i]);}
754                         }
755                    break;}
756             case 65:{
757                    double *u;
758                    long *y;
759                    u=GetRealInPortPtrs(block,1);
760                    y=Getint32OutPortPtrs(block,1);
761                    k=pow(2,32);
762                    for (i=0;i<m*n;i++)
763                    {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
764                            {if (flag==1)
765                                {sciprint(_("overflow error"));
766                                 set_block_error(-4);
767                                 return;}}
768                         else {y[i]=(long)(u[i]);}
769                        }
770                    break;}
771             case 66:{
772                    double *u;
773                    short *y;
774                    u=GetRealInPortPtrs(block,1);
775                    y=Getint16OutPortPtrs(block,1);
776                    k=pow(2,16);
777                    for (i=0;i<m*n;i++) 
778                         {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
779                            {if (flag==1)
780                                {sciprint(_("overflow error"));
781                                 set_block_error(-4);
782                                 return;}}
783                         else {y[i]=(short)(u[i]);}
784                        }
785                    break;}
786             case 67:{
787                    double *u;
788                    char *y;
789                    u=GetRealInPortPtrs(block,1);
790                    y=Getint8OutPortPtrs(block,1);
791                    k=pow(2,8);
792                    for (i=0;i<m*n;i++) 
793                         {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
794                            {if (flag==1)
795                                {sciprint(_("overflow error"));
796                                 set_block_error(-4);
797                                 return;}}
798                         else {y[i]=(char)(u[i]);}
799                        }
800                    break;}
801             case 68:{
802                    double *u;
803                    unsigned long *y;
804                    u=GetRealInPortPtrs(block,1);
805                    y=Getuint32OutPortPtrs(block,1);
806                    k=pow(2,32);
807                    for (i=0;i<m*n;i++) 
808                         {if ((u[i]>=k) | (u[i]<0))
809                            {if (flag==1)
810                                {sciprint(_("overflow error"));
811                                 set_block_error(-4);
812                                 return;}}
813                         else {y[i]=(unsigned long)(u[i]);}
814                         }
815                    break;}
816             case 69:{
817                    double *u;
818                    unsigned short *y;
819                    u=GetRealInPortPtrs(block,1);
820                    y=Getuint16OutPortPtrs(block,1);
821                    k=pow(2,16);
822                    for (i=0;i<m*n;i++) 
823                         {if ((u[i]>=k) | (u[i]<0))
824                             {if (flag==1)
825                                {sciprint(_("overflow error"));
826                                 set_block_error(-4);
827                                 return;}}
828                         else {y[i]=(unsigned short)(u[i]);}
829                         }
830                    break;}
831             case 70:{
832                    double *u;
833                    unsigned char *y;
834                    u=GetRealInPortPtrs(block,1);
835                    y=Getuint8OutPortPtrs(block,1);
836                    k=pow(2,8);
837                    for (i=0;i<m*n;i++) 
838                         {if ((u[i]>=k) | (u[i]<0))
839                             {if (flag==1)
840                                {sciprint(_("overflow error"));
841                                 set_block_error(-4);
842                                 return;}}
843                         else {y[i]=(unsigned char)(u[i]);}
844                         }
845                    break;}
846             case 71:{
847                    long *u;
848                    short *y;
849                    u=Getint32InPortPtrs(block,1);
850                    y=Getint16OutPortPtrs(block,1);
851                    k=pow(2,16);
852                    for (i=0;i<m*n;i++) 
853                         {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
854                             {if (flag==1)
855                                {sciprint(_("overflow error"));
856                                 set_block_error(-4);
857                                 return;}}
858                         else {y[i]=(short)(u[i]);}
859                        }
860                    break;}
861             case 72:{
862                    long *u;
863                    char *y;
864                    u=Getint32InPortPtrs(block,1);
865                    y=Getint8OutPortPtrs(block,1);
866                    k=pow(2,8);
867                    for (i=0;i<m*n;i++) 
868                         {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
869                             {if (flag==1)
870                                {sciprint(_("overflow error"));
871                                 set_block_error(-4);
872                                 return;}}
873                         else {y[i]=(char)(u[i]);}
874                        }
875                    break;}
876             case 73:{
877                    long *u;
878                    unsigned long *y;
879                    u=Getint32InPortPtrs(block,1);
880                    y=Getuint32OutPortPtrs(block,1);
881                    for (i=0;i<m*n;i++) 
882                         {if (u[i]<0)
883                             {if (flag==1)
884                                {sciprint(_("overflow error"));
885                                 set_block_error(-4);
886                                 return;}}
887                         else {y[i]=(unsigned long)(u[i]);}
888                         }
889                    break;}
890             case 74:{
891                    long *u;
892                    unsigned short *y;
893                    u=Getint32InPortPtrs(block,1);
894                    y=Getuint16OutPortPtrs(block,1);
895                    k=pow(2,16);
896                    for (i=0;i<m*n;i++) 
897                         {if ((u[i]>=k) | (u[i]<0))
898                             {if (flag==1)
899                                {sciprint(_("overflow error"));
900                                 set_block_error(-4);
901                                 return;}}
902                         else {y[i]=(unsigned short)(u[i]);}
903                         }
904                    break;}
905             case 75:{
906                    long *u;
907                    unsigned char *y;
908                    u=Getint32InPortPtrs(block,1);
909                    y=Getuint8OutPortPtrs(block,1);
910                    k=pow(2,8);
911                    for (i=0;i<m*n;i++) 
912                         {if ((u[i]>=k) | (u[i]<0))
913                             {if (flag==1)
914                                {sciprint(_("overflow error"));
915                                 set_block_error(-4);
916                                 return;}}
917                         else {y[i]=(unsigned char)(u[i]);}
918                         }
919                    break;}
920             case 76:{
921                    short *u;
922                    char *y;
923                    u=Getint16InPortPtrs(block,1);
924                    y=Getint8OutPortPtrs(block,1);
925                    k=pow(2,8);
926                    for (i=0;i<m*n;i++) 
927                         {if ((u[i]>k/2-1) | (u[i]<-(k/2)))
928                             {if (flag==1)
929                                {sciprint(_("overflow error"));
930                                 set_block_error(-4);
931                                 return;}}
932                         else {y[i]=(char)(u[i]);}
933                        }
934                    break;}
935             case 77:{
936                    short *u;
937                    unsigned long *y;
938                    u=Getint16InPortPtrs(block,1);
939                    y=Getuint32OutPortPtrs(block,1);
940                    for (i=0;i<m*n;i++) 
941                         {if (u[i]<0)  
942                             {if (flag==1)
943                                {sciprint(_("overflow error"));
944                                 set_block_error(-4);
945                                 return;}}
946                          else y[i]=(unsigned long)u[i];}
947                    break;}
948             case 78:{
949                    short *u;
950                    unsigned short *y;
951                    u=Getint16InPortPtrs(block,1);
952                    y=Getuint16OutPortPtrs(block,1);
953                    for (i=0;i<m*n;i++) 
954                         {if (u[i]<0)
955                             {if (flag==1) 
956                                 {sciprint(_("overflow error"));
957                                  set_block_error(-4);
958                                  return;}}
959                         else {y[i]=(unsigned short)(u[i]);}
960                         }
961                    break;}
962             case 79:{
963                    short *u;
964                    unsigned char *y;
965                    u=Getint16InPortPtrs(block,1);
966                    y=Getuint8OutPortPtrs(block,1);
967                    k=pow(2,8);
968                    for (i=0;i<m*n;i++) 
969                         {if (((u[i]>=k) | (u[i]<0))& (flag==1))
970                             {if (flag==1) 
971                                  {sciprint(_("overflow error"));
972                                   set_block_error(-4);
973                                   return;}}
974                         else {y[i]=(unsigned char)(u[i]);}
975                         }
976                    break;}
977             case 80:{
978                    char *u;
979                    unsigned long *y;
980                    u=Getint8InPortPtrs(block,1);
981                    y=Getuint32OutPortPtrs(block,1);
982                    for (i=0;i<m*n;i++) 
983                         {if (u[i]<0)
984                             {if (flag==1)
985                                {sciprint(_("overflow error"));
986                                 set_block_error(-4);
987                                 return;}}
988                          else y[i]=(unsigned long)u[i];}
989                    break;}
990             case 81:{
991                    char *u;
992                    unsigned short *y;
993                    u=Getint8InPortPtrs(block,1);
994                    y=Getuint16OutPortPtrs(block,1);
995                    for (i=0;i<m*n;i++) 
996                         {if (u[i]<0)
997                             {if (flag==1)
998                                {sciprint(_("overflow error"));
999                                 set_block_error(-4);
1000                                 return;}}
1001                         else {y[i]=(unsigned short)(u[i]);}
1002                         }
1003                    break;}
1004             case 82:{
1005                    char *u;
1006                    unsigned char *y;
1007                    u=Getint8InPortPtrs(block,1);
1008                    y=Getuint8OutPortPtrs(block,1);
1009                    for (i=0;i<m*n;i++) 
1010                         {if (u[i]<0)
1011                             {if (flag==1)
1012                                {sciprint(_("overflow error"));
1013                                 set_block_error(-4);
1014                                 return;}}
1015                         else {y[i]=(unsigned char)(u[i]);}
1016                         }
1017                    break;}
1018             case 83:{
1019                    long *y;
1020                    unsigned long *u;
1021                    u=Getuint32InPortPtrs(block,1);
1022                    y=Getint32OutPortPtrs(block,1);
1023                    k=pow(2,32);
1024                    for (i=0;i<m*n;i++) 
1025                         {if (u[i]>(k/2-1))
1026                             {if (flag==1)
1027                                {sciprint(_("overflow error"));
1028                                 set_block_error(-4);
1029                                 return;}}
1030                         else {y[i]=(long)(u[i]);}
1031                         }
1032                    break;}
1033             case 84:{
1034                    unsigned long *u;
1035                    short *y;
1036                    u=Getuint32InPortPtrs(block,1);
1037                    y=Getint16OutPortPtrs(block,1);
1038                    k=pow(2,16);
1039                    for (i=0;i<m*n;i++) 
1040                         {if (u[i]>(k/2-1))
1041                             {if (flag==1)
1042                                {sciprint(_("overflow error"));
1043                                 set_block_error(-4);
1044                                 return;}}
1045                         else {y[i]=(short)(u[i]);}
1046                         }
1047                    break;}
1048             case 85:{
1049                    unsigned long *u;
1050                    char *y;
1051                    u=Getuint32InPortPtrs(block,1);
1052                    y=Getint8OutPortPtrs(block,1);
1053                    k=pow(2,8);
1054                    for (i=0;i<m*n;i++) 
1055                         {if (u[i]>(k/2-1))
1056                             {if (flag==1)
1057                                {sciprint(_("overflow error"));
1058                                 set_block_error(-4);
1059                                 return;}}
1060                         else {y[i]=(char)(u[i]);}
1061                         }
1062                    break;}
1063             case 86:{
1064                    unsigned long *u;
1065                    unsigned short *y;
1066                    u=Getuint32InPortPtrs(block,1);
1067                    y=Getuint16OutPortPtrs(block,1);
1068                    k=pow(2,16);
1069                    for (i=0;i<m*n;i++) 
1070                         {if (u[i]>(k/2-1))
1071                             {if (flag==1)
1072                                {sciprint(_("overflow error"));
1073                                 set_block_error(-4);
1074                                 return;}}
1075                         else {y[i]=(unsigned short)(u[i]);}
1076                         }
1077                    break;}
1078             case 87:{
1079                    unsigned long *u;
1080                    unsigned char *y;
1081                    u=Getuint32InPortPtrs(block,1);
1082                    y=Getuint8OutPortPtrs(block,1);
1083                    k=pow(2,8);
1084                    for (i=0;i<m*n;i++) 
1085                         {if (u[i]>(k/2-1))
1086                             {if (flag==1)
1087                                {sciprint(_("overflow error"));
1088                                 set_block_error(-4);
1089                                 return;}}
1090                         else {y[i]=(unsigned char)(u[i]);}
1091                         }
1092                    break;}
1093             case 88:{
1094                    unsigned short *u;
1095                    short *y;
1096                    u=Getuint16InPortPtrs(block,1);
1097                    y=Getint16OutPortPtrs(block,1);
1098                    k=pow(2,16);
1099                    for (i=0;i<m*n;i++) 
1100                         {if (u[i]>(k/2-1))
1101                             {if (flag==1)
1102                                {sciprint(_("overflow error"));
1103                                 set_block_error(-4);
1104                                 return;}}
1105                         else {y[i]=(short)(u[i]);}
1106                         }
1107                    break;}
1108             case 89:{
1109                    unsigned short *u;
1110                    char *y;
1111                    u=Getuint16InPortPtrs(block,1);
1112                    y=Getint8OutPortPtrs(block,1);
1113                    k=pow(2,8);
1114                    for (i=0;i<m*n;i++) 
1115                         {if (u[i]>(k/2-1))
1116                             {if (flag==1)
1117                                {sciprint(_("overflow error"));
1118                                 set_block_error(-4);
1119                                 return;}}
1120                         else {y[i]=(char)(u[i]);}
1121                         }
1122                    break;}
1123             case 90:{
1124                    unsigned short *u;
1125                    unsigned char *y;
1126                    u=Getuint16InPortPtrs(block,1);
1127                    y=Getuint8OutPortPtrs(block,1);
1128                    k=pow(2,8);
1129                    for (i=0;i<m*n;i++) 
1130                         {if (u[i]>(k/2-1))
1131                             {if (flag==1)
1132                                {sciprint(_("overflow error"));
1133                                 set_block_error(-4);
1134                                 return;}}
1135                         else {y[i]=(unsigned char)(u[i]);}
1136                         }
1137                    break;}
1138             case 91:{
1139                    unsigned char *u;
1140                    char *y;
1141                    u=Getuint8InPortPtrs(block,1);
1142                    y=Getint8OutPortPtrs(block,1);
1143                    k=pow(2,8);
1144                    for (i=0;i<m*n;i++) 
1145                         {if (u[i]>(k/2-1))
1146                             {if (flag==1)
1147                                {sciprint(_("overflow error"));
1148                                 set_block_error(-4);
1149                                 return;}}
1150                         else {y[i]=(char)(u[i]);}
1151                         }
1152                    break;}
1153            }
1154         }
1155  }
1156 /*--------------------------------------------------------------------------*/